VRAY/VRAY_DemoVolumeSphere.C
#include "VRAY_DemoVolumeSphere.h"
#include <UT/UT_Vector3.h>
#include <UT/UT_FloatArray.h>
#include <UT/UT_IntArray.h>
#include <UT/UT_RefArray.h>
#include <UT/UT_StringArray.h>
#include <VRAY/VRAY_Volume.h>
namespace HDK_Sample {
class vray_VolumeSphere : public VRAY_Volume {
public:
virtual void getWeightedBoxes(UT_RefArray<UT_BoundingBox> &boxes,
UT_FloatArray &weights,
fpreal radius, fpreal dbound) const;
virtual void getAttributeBinding(UT_StringArray &names,
UT_IntArray &sizes) const;
virtual void evaluate(const UT_Vector3 &pos,
const UT_Filter &filter,
fpreal radius, fpreal time,
int idx, fpreal *data) const;
virtual UT_Vector3 gradient(const UT_Vector3 &pos,
const UT_Filter &filter,
fpreal radius, fpreal time,
int idx) const;
};
}
using namespace HDK_Sample;
void
vray_VolumeSphere::getWeightedBoxes(UT_RefArray<UT_BoundingBox> &boxes,
UT_FloatArray &weights,
fpreal, fpreal dbound) const
{
boxes.append(UT_BoundingBox(-1-dbound, -1-dbound, -1-dbound,
1+dbound, 1+dbound, 1+dbound));
weights.append(1.0F);
}
void
vray_VolumeSphere::getAttributeBinding(UT_StringArray &names,
UT_IntArray &sizes) const
{
names.append("density");
sizes.append(1);
names.append("radius");
sizes.append(1);
}
void
vray_VolumeSphere::evaluate(const UT_Vector3 &pos,
const UT_Filter &,
fpreal, fpreal,
int idx, fpreal *data) const
{
switch (idx)
{
case 0: data[0] = (pos.length2() < 1.0F) ? 1.0F : 0.0F; break;
case 1: data[0] = pos.length(); break;
default: UT_ASSERT(0 && "Invalid attribute evaluation");
}
}
UT_Vector3
vray_VolumeSphere::gradient(const UT_Vector3 &,
const UT_Filter &,
fpreal, fpreal,
int) const
{
return UT_Vector3(0, 0, 0);
}
static VRAY_ProceduralArg theArgs[] = {
VRAY_ProceduralArg()
};
VRAY_Procedural *
allocProcedural(const char *)
{
return new VRAY_DemoVolumeSphere();
}
const VRAY_ProceduralArg *
getProceduralArgs(const char *)
{
return theArgs;
}
VRAY_DemoVolumeSphere::VRAY_DemoVolumeSphere()
{
}
VRAY_DemoVolumeSphere::~VRAY_DemoVolumeSphere()
{
}
int
VRAY_DemoVolumeSphere::initialize(const UT_BoundingBox *box)
{
myBox = UT_BoundingBox(-1, -1, -1, 1, 1, 1);
if (box)
myBox.enlargeBounds(*box);
return 1;
}
void
VRAY_DemoVolumeSphere::getBoundingBox(UT_BoundingBox &box)
{
box = myBox;
}
void
VRAY_DemoVolumeSphere::render()
{
openVolumeObject();
addVolume(new vray_VolumeSphere, 0.0F);
closeObject();
}