00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "VRAY_DemoVolumeSphere.h"
00030 #include <UT/UT_Vector3.h>
00031 #include <UT/UT_FloatArray.h>
00032 #include <UT/UT_IntArray.h>
00033 #include <UT/UT_RefArray.h>
00034 #include <UT/UT_StringArray.h>
00035 #include <VRAY/VRAY_Volume.h>
00036
00037
00038
00039
00040
00041 namespace HDK_Sample {
00042
00043
00044 class vray_VolumeSphere : public VRAY_Volume {
00045 public:
00046 virtual void getWeightedBoxes(UT_RefArray<UT_BoundingBox> &boxes,
00047 UT_FloatArray &weights,
00048 fpreal radius, fpreal dbound) const;
00049 virtual void getAttributeBinding(UT_StringArray &names,
00050 UT_IntArray &sizes) const;
00051 virtual void evaluate(const UT_Vector3 &pos,
00052 const UT_Filter &filter,
00053 fpreal radius, float time,
00054 int idx, float *data) const;
00055 virtual UT_Vector3 gradient(const UT_Vector3 &pos,
00056 const UT_Filter &filter,
00057 fpreal radius, fpreal time,
00058 int idx) const;
00059 };
00060
00061 }
00062
00063 using namespace HDK_Sample;
00064
00065 void
00066 vray_VolumeSphere::getWeightedBoxes(UT_RefArray<UT_BoundingBox> &boxes,
00067 UT_FloatArray &weights,
00068 fpreal, fpreal dbound) const
00069 {
00070
00071
00072
00073 boxes.append(UT_BoundingBox(-1-dbound, -1-dbound, -1-dbound,
00074 1+dbound, 1+dbound, 1+dbound));
00075 weights.append(1.0F);
00076 }
00077
00078 void
00079 vray_VolumeSphere::getAttributeBinding(UT_StringArray &names,
00080 UT_IntArray &sizes) const
00081 {
00082
00083
00084
00085
00086
00087
00088 names.append("density");
00089 sizes.append(1);
00090 names.append("radius");
00091 sizes.append(1);
00092 }
00093
00094 void
00095 vray_VolumeSphere::evaluate(const UT_Vector3 &pos,
00096 const UT_Filter &,
00097 fpreal, float,
00098 int idx, float *data) const
00099 {
00100 switch (idx)
00101 {
00102
00103 case 0: data[0] = (pos.length2() < 1.0F) ? 1.0F : 0.0F; break;
00104
00105 case 1: data[0] = pos.length(); break;
00106
00107 default: UT_ASSERT(0 && "Invalid attribute evaluation");
00108 }
00109 }
00110
00111 UT_Vector3
00112 vray_VolumeSphere::gradient(const UT_Vector3 &,
00113 const UT_Filter &,
00114 fpreal, fpreal,
00115 int) const
00116 {
00117 return UT_Vector3(0, 0, 0);
00118 }
00119
00120
00121
00122
00123
00124 static VRAY_ProceduralArg theArgs[] = {
00125 VRAY_ProceduralArg()
00126 };
00127
00128 VRAY_Procedural *
00129 allocProcedural(const char *)
00130 {
00131 return new VRAY_DemoVolumeSphere();
00132 }
00133
00134 const VRAY_ProceduralArg *
00135 getProceduralArgs(const char *)
00136 {
00137 return theArgs;
00138 }
00139
00140 VRAY_DemoVolumeSphere::VRAY_DemoVolumeSphere()
00141 {
00142 }
00143
00144 VRAY_DemoVolumeSphere::~VRAY_DemoVolumeSphere()
00145 {
00146 }
00147
00148 int
00149 VRAY_DemoVolumeSphere::initialize(const UT_BoundingBox *box)
00150 {
00151 myBox = UT_BoundingBox(-1, -1, -1, 1, 1, 1);
00152 if (box)
00153 myBox.enlargeBounds(*box);
00154
00155 return 1;
00156 }
00157
00158 void
00159 VRAY_DemoVolumeSphere::getBoundingBox(UT_BoundingBox &box)
00160 {
00161 box = myBox;
00162 }
00163
00164 void
00165 VRAY_DemoVolumeSphere::render()
00166 {
00167 openVolumeObject();
00168 addVolume(new vray_VolumeSphere, 0.0F);
00169 closeObject();
00170 }