#include <UT/UT_DSOVersion.h>
#include <RE/RE_Render.h>
#include <GEO/GEO_Primitive.h>
#include <GU/GU_Detail.h>
#include <GU/GU_PrimGroupClosure.h>
#include <GR/GR_Detail.h>
#include <GR/GR_RenderHook.h>
#include <GR/GR_RenderTable.h>
#include <GR/GR_DisplayOption.h>
namespace HDK_Sample {
class GR_BoundingBox : public GR_RenderHook
{
public:
GR_BoundingBox() {}
virtual ~GR_BoundingBox() {}
int getWireMask(GU_Detail * ,
const GR_DisplayOption *dopt) const
{
if (dopt->drawPrimHulls())
return 0;
else
return GEOPRIMALL;
}
virtual void renderWire(GU_Detail *gdp,
RE_Render &ren,
const GR_AttribOffset &ptinfo,
const GR_DisplayOption *dopt,
float lod,
const GU_PrimGroupClosure *hidden_geometry);
int getShadedMask(GU_Detail * ,
const GR_DisplayOption *dopt) const
{
if (dopt->drawPrimHulls())
return 0;
else
return GEOPRIMALL;
}
virtual void renderShaded(GU_Detail *gdp,
RE_Render &ren,
const GR_AttribOffset &ptinfo,
const GR_DisplayOption *dopt,
float lod,
const GU_PrimGroupClosure *hidden_geometry);
virtual const char *getName() const { return "GR_BoundingBox"; }
};
}
using namespace HDK_Sample;
void
GR_BoundingBox::renderWire(GU_Detail *gdp,
RE_Render &ren,
const GR_AttribOffset & ,
const GR_DisplayOption *dopt,
float ,
const GU_PrimGroupClosure *hidden_geometry)
{
if (!dopt->drawPrimHulls())
return;
UT_BoundingBox bbox;
gdp->getBBox(&bbox, 0, hidden_geometry);
ren.beginLine();
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
ren.endLine();
ren.beginLine();
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
ren.endLine();
ren.beginLine();
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
ren.endLine();
ren.beginLine();
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
ren.endLine();
}
void
GR_BoundingBox::renderShaded(GU_Detail *gdp,
RE_Render &ren,
const GR_AttribOffset & ,
const GR_DisplayOption *dopt,
float ,
const GU_PrimGroupClosure *hidden_geometry)
{
if (!dopt->drawPrimHulls())
return;
UT_BoundingBox bbox;
float nml[3];
float cd[3];
gdp->getBBox(&bbox, 0, hidden_geometry);
dopt->wireColor().getRGB(&cd[0], &cd[1], &cd[2]);
ren.pushMaterialDiffuse();
nml[0] = 0.0f;
nml[1] = 0.0f;
nml[2] = -1.0f;
ren.beginPolygon(0);
ren.n3DW(nml);
ren.c3DW(cd);
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
ren.endPolygon();
nml[0] = 0.0f;
nml[1] = 0.0f;
nml[2] = 1.0f;
ren.beginPolygon(0);
ren.n3DW(nml);
ren.c3DW(cd);
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
ren.endPolygon();
nml[0] = 0.0f;
nml[1] = -1.0f;
nml[2] = 0.0f;
ren.beginPolygon(0);
ren.n3DW(nml);
ren.c3DW(cd);
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
ren.endPolygon();
nml[0] = 0.0f;
nml[1] = 1.0f;
nml[2] = 0.0f;
ren.beginPolygon(0);
ren.n3DW(nml);
ren.c3DW(cd);
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
ren.endPolygon();
nml[0] = -1.0f;
nml[1] = 0.0f;
nml[2] = 0.0f;
ren.beginPolygon(0);
ren.n3DW(nml);
ren.c3DW(cd);
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 0), bbox(1, 0), bbox(2, 1));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 0), bbox(1, 1), bbox(2, 0));
ren.endPolygon();
nml[0] = 1.0f;
nml[1] = 0.0f;
nml[2] = 0.0f;
ren.beginPolygon(0);
ren.n3DW(nml);
ren.c3DW(cd);
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 0));
ren.vertex3DW(bbox(0, 1), bbox(1, 1), bbox(2, 1));
ren.vertex3DW(bbox(0, 1), bbox(1, 0), bbox(2, 1));
ren.endPolygon();
ren.popMaterialDiffuse();
}
void
newRenderHook(GR_RenderTable *table)
{
GR_BoundingBox *hook = new GR_BoundingBox;
table->addHook(hook, GR_RENDER_HOOK_VERSION);
}