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 #include <UT/UT_DSOVersion.h>
00029
00030 #include <RE/RE_Render.h>
00031
00032 #include <GEO/GEO_Primitive.h>
00033
00034 #include <GU/GU_Detail.h>
00035 #include <GU/GU_PrimGroupClosure.h>
00036
00037 #include <GR/GR_Detail.h>
00038 #include <GR/GR_RenderHook.h>
00039 #include <GR/GR_RenderTable.h>
00040 #include <GR/GR_DisplayOption.h>
00041
00042 namespace HDK_Sample {
00043 class GR_BoundingBox : public GR_RenderHook
00044 {
00045 public:
00046 GR_BoundingBox() {}
00047 virtual ~GR_BoundingBox() {}
00048
00049 int getWireMask(GU_Detail * ,
00050 const GR_DisplayOption *dopt) const
00051 {
00052
00053 if (dopt->drawPrimHulls())
00054 return 0;
00055 else
00056 return GEOPRIMALL;
00057 }
00058
00059 virtual void renderWire(GU_Detail *gdp,
00060 RE_Render &ren,
00061 const GR_AttribOffset &ptinfo,
00062 const GR_DisplayOption *dopt,
00063 float lod,
00064 const GU_PrimGroupClosure *hidden_geometry);
00065
00066 int getShadedMask(GU_Detail * ,
00067 const GR_DisplayOption *dopt) const
00068 {
00069
00070 if (dopt->drawPrimHulls())
00071 return 0;
00072 else
00073 return GEOPRIMALL;
00074 }
00075
00076 virtual void renderShaded(GU_Detail *gdp,
00077 RE_Render &ren,
00078 const GR_AttribOffset &ptinfo,
00079 const GR_DisplayOption *dopt,
00080 float lod,
00081 const GU_PrimGroupClosure *hidden_geometry);
00082
00083 virtual const char *getName() const { return "GR_BoundingBox"; }
00084 };
00085 }
00086 using namespace HDK_Sample;
00087
00088 void
00089 GR_BoundingBox::renderWire(GU_Detail *gdp,
00090 RE_Render &ren,
00091 const GR_AttribOffset & ,
00092 const GR_DisplayOption *dopt,
00093 float ,
00094 const GU_PrimGroupClosure *hidden_geometry)
00095 {
00096 if (!dopt->drawPrimHulls())
00097 return;
00098
00099 UT_BoundingBox bbox;
00100
00101
00102 gdp->getBBox(&bbox, 0, hidden_geometry);
00103
00104
00105 ren.beginLine();
00106
00107 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
00108 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
00109 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
00110 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
00111 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
00112 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
00113 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
00114 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
00115 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
00116 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
00117
00118 ren.endLine();
00119
00120
00121 ren.beginLine();
00122
00123 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
00124 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
00125
00126 ren.endLine();
00127
00128 ren.beginLine();
00129
00130 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
00131 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
00132
00133 ren.endLine();
00134
00135 ren.beginLine();
00136
00137 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
00138 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
00139
00140 ren.endLine();
00141 }
00142
00143 void
00144 GR_BoundingBox::renderShaded(GU_Detail *gdp,
00145 RE_Render &ren,
00146 const GR_AttribOffset & ,
00147 const GR_DisplayOption *dopt,
00148 float ,
00149 const GU_PrimGroupClosure *hidden_geometry)
00150 {
00151
00152 if (!dopt->drawPrimHulls())
00153 return;
00154
00155 UT_BoundingBox bbox;
00156 float nml[3];
00157 float cd[3];
00158
00159
00160 gdp->getBBox(&bbox, 0, hidden_geometry);
00161
00162
00163 dopt->wireColor().getRGB(&cd[0], &cd[1], &cd[2]);
00164
00165
00166 ren.pushMaterialDiffuse();
00167
00168
00169
00170 nml[0] = 0.0f;
00171 nml[1] = 0.0f;
00172 nml[2] = -1.0f;
00173
00174 ren.beginPolygon(0);
00175 ren.n3DW(nml);
00176 ren.c3DW(cd);
00177 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
00178 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
00179 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
00180 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
00181 ren.endPolygon();
00182
00183 nml[0] = 0.0f;
00184 nml[1] = 0.0f;
00185 nml[2] = 1.0f;
00186
00187 ren.beginPolygon(0);
00188 ren.n3DW(nml);
00189 ren.c3DW(cd);
00190 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
00191 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
00192 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
00193 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
00194 ren.endPolygon();
00195
00196 nml[0] = 0.0f;
00197 nml[1] = -1.0f;
00198 nml[2] = 0.0f;
00199
00200 ren.beginPolygon(0);
00201 ren.n3DW(nml);
00202 ren.c3DW(cd);
00203 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
00204 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
00205 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
00206 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
00207 ren.endPolygon();
00208
00209 nml[0] = 0.0f;
00210 nml[1] = 1.0f;
00211 nml[2] = 0.0f;
00212
00213 ren.beginPolygon(0);
00214 ren.n3DW(nml);
00215 ren.c3DW(cd);
00216 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
00217 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
00218 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
00219 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
00220 ren.endPolygon();
00221
00222 nml[0] = -1.0f;
00223 nml[1] = 0.0f;
00224 nml[2] = 0.0f;
00225
00226 ren.beginPolygon(0);
00227 ren.n3DW(nml);
00228 ren.c3DW(cd);
00229 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
00230 ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
00231 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
00232 ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
00233 ren.endPolygon();
00234
00235 nml[0] = 1.0f;
00236 nml[1] = 0.0f;
00237 nml[2] = 0.0f;
00238
00239 ren.beginPolygon(0);
00240 ren.n3DW(nml);
00241 ren.c3DW(cd);
00242 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
00243 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
00244 ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
00245 ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
00246 ren.endPolygon();
00247
00248 ren.popMaterialDiffuse();
00249 }
00250
00251 void
00252 newRenderHook(GR_RenderTable *table)
00253 {
00254 GR_BoundingBox *hook = new GR_BoundingBox;
00255
00256 table->addHook(hook);
00257 }