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
00041 namespace HDK_Sample {
00042 class GR_BaryCenter : public GR_RenderHook
00043 {
00044 public:
00045 GR_BaryCenter() {}
00046 virtual ~GR_BaryCenter() {}
00047
00048 virtual void renderWire(GU_Detail *gdp,
00049 RE_Render &ren,
00050 const GR_AttribOffset &ptinfo,
00051 const GR_DisplayOption *dopt,
00052 float lod,
00053 const GU_PrimGroupClosure *hidden_geometry);
00054
00055 virtual void renderShaded(GU_Detail *gdp,
00056 RE_Render &ren,
00057 const GR_AttribOffset &ptinfo,
00058 const GR_DisplayOption *dopt,
00059 float lod,
00060 const GU_PrimGroupClosure *hidden_geometry);
00061
00062 virtual const char *getName() const { return "GR_BaryCenter"; }
00063 };
00064 }
00065 using namespace HDK_Sample;
00066
00067 void
00068 GR_BaryCenter::renderWire(GU_Detail *gdp,
00069 RE_Render &ren,
00070 const GR_AttribOffset & ,
00071 const GR_DisplayOption * ,
00072 float ,
00073 const GU_PrimGroupClosure *hidden_geometry)
00074 {
00075 int i, nprim;
00076 GEO_Primitive *prim;
00077 UT_Vector3 v3;
00078
00079 ren.beginPoint();
00080
00081 nprim = gdp->primitives().entries();
00082 for (i = 0; i < nprim; i++)
00083 {
00084 prim = gdp->primitives()(i);
00085
00086
00087 if (hidden_geometry && hidden_geometry->containsPrim(prim))
00088 continue;
00089
00090 v3 = prim->baryCenter();
00091 ren.vertex3DW(v3.x(), v3.y(), v3.z());
00092 }
00093
00094 ren.endPoint();
00095 }
00096
00097 void
00098 GR_BaryCenter::renderShaded(GU_Detail *gdp,
00099 RE_Render &ren,
00100 const GR_AttribOffset &ptinfo,
00101 const GR_DisplayOption *dopt,
00102 float lod,
00103 const GU_PrimGroupClosure *hidden_geometry)
00104 {
00105
00106 GR_Detail::toggleLightShading(ren, 0);
00107 renderWire(gdp, ren, ptinfo, dopt, lod, hidden_geometry);
00108 GR_Detail::toggleLightShading(ren, 1);
00109 }
00110
00111 void
00112 newRenderHook(GR_RenderTable *table)
00113 {
00114 GR_BaryCenter *hook = new GR_BaryCenter;
00115
00116 table->addHook(hook);
00117 }