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 <GU/GU_Detail.h>
00030 #include "VRAY_DemoFile.h"
00031
00032 using namespace HDK_Sample;
00033
00034 static VRAY_ProceduralArg theArgs[] = {
00035 VRAY_ProceduralArg("file", "string", ""),
00036 VRAY_ProceduralArg("blurfile", "string", ""),
00037 VRAY_ProceduralArg("velocityblur", "int", "0"),
00038 VRAY_ProceduralArg("shutter", "real", "1"),
00039 VRAY_ProceduralArg()
00040 };
00041
00042 VRAY_Procedural *
00043 allocProcedural(const char *)
00044 {
00045 return new VRAY_DemoFile();
00046 }
00047
00048 const VRAY_ProceduralArg *
00049 getProceduralArgs(const char *)
00050 {
00051 return theArgs;
00052 }
00053
00054 VRAY_DemoFile::VRAY_DemoFile()
00055 : myShutter(1),
00056 myVelocityScale(0)
00057 {
00058 myBox.initBounds(0, 0, 0);
00059 }
00060
00061 VRAY_DemoFile::~VRAY_DemoFile()
00062 {
00063 }
00064
00065 const char *
00066 VRAY_DemoFile::getClassName()
00067 {
00068 return "VRAY_DemoFile";
00069 }
00070
00071 int
00072 VRAY_DemoFile::initialize(const UT_BoundingBox *box)
00073 {
00074 int ival;
00075
00076
00077
00078
00079 if (!box)
00080 {
00081 fprintf(stderr, "The %s procedural needs a bounding box specified\n",
00082 getClassName());
00083 return 0;
00084 }
00085
00086
00087 myBox = *box;
00088
00089
00090 if (!import("shutter", &myShutter, 1))
00091 myShutter = 1;
00092
00093
00094
00095 if (import("velocityblur", &ival, 1))
00096 myVelocityBlur = (ival != 0);
00097 else
00098 myVelocityBlur = false;
00099
00100
00101 import("file", myFile);
00102 import("blurfile", myBlurFile);
00103
00104
00105
00106
00107 if (!import("object:velocityscale", &myVelocityScale, 1))
00108 myVelocityScale = 0;
00109
00110 return 1;
00111 }
00112
00113 void
00114 VRAY_DemoFile::getBoundingBox(UT_BoundingBox &box)
00115 {
00116 box = myBox;
00117 }
00118
00119 void
00120 VRAY_DemoFile::render()
00121 {
00122 GU_Detail *g0, *g1;
00123
00124
00125
00126
00127 g0 = allocateGeometry();
00128
00129
00130 if (g0->load(myFile, 0) < 0)
00131 {
00132 fprintf(stderr, "Unable to load geometry[0]: '%s'\n",
00133 (const char *)myFile);
00134 freeGeometry(g0);
00135 return;
00136 }
00137
00138
00139 if (myVelocityBlur)
00140 {
00141
00142 openGeometryObject();
00143 addGeometry(g0, 0);
00144 addVelocityBlurGeometry(g0, myShutter * myVelocityScale);
00145 closeObject();
00146 }
00147 else
00148 {
00149
00150 g1 = 0;
00151 if (myBlurFile.isstring())
00152 {
00153 g1 = allocateGeometry();
00154 if (g1->load(myBlurFile, 0) < 0)
00155 {
00156 fprintf(stderr, "Unable to load geometry[1]: '%s'\n",
00157 (const char *)myFile);
00158 freeGeometry(g1);
00159 g1 = 0;
00160 }
00161 }
00162
00163 openGeometryObject();
00164 addGeometry(g0, 0);
00165 if (g1)
00166 addGeometry(g1, myShutter);
00167 closeObject();
00168 }
00169 }