namespace HDK_Sample {
const char *vert_shader =
"#version 150 \n"
"uniform mat4 glH_ProjectMatrix; \n"
"uniform mat4 glH_ViewMatrix; \n"
"in vec3 P; \n"
"in vec4 Cd; \n"
"out vec4 clr; \n"
"void main() \n"
"{ \n"
" clr = Cd; \n"
" gl_Position = glH_ProjectMatrix * glH_ViewMatrix * vec4(P, 1.0); \n"
"} \n";
const char *frag_shader =
"#version 150 \n"
"in vec4 clr; \n"
"out vec4 color; \n"
"void main() \n"
"{ \n"
" color = clr; \n"
"} \n";
{
public:
myShader(NULL),
myGeo(NULL),
myStartFrame(0),
myEndFrame(0),
myNormalScale(0.0),
myVectorScale(0.0)
{}
~DM_ObjectPathRenderHook() override
{
delete myShader;
delete myGeo;
}
void viewportClosed() override;
int start_frame,
int end_frame,
private:
int myStartFrame;
int myEndFrame;
int myCurrentObjId;
};
{
public:
DM_ObjectPathHook() :
DM_SceneHook(
"Object path display", 0,
{}
{
return new DM_ObjectPathRenderHook(vport);
}
{
delete hook;
}
};
}
using namespace HDK_Sample;
bool
{
return false;
if(cur_obj)
{
if(!pos || !col ||
obj_id != myCurrentObjId ||
start_fr != myStartFrame ||
end_fr != myEndFrame ||
{
rebuildPathGeometry(r, cur_obj, start_fr, end_fr, version,
vec_scale, nml_scale);
myStartFrame = start_fr;
myEndFrame = end_fr;
myCurrentObjId = obj_id;
myNormalScale = nml_scale;
myVectorScale = vec_scale;
}
if(myGeo)
drawPathGeometry(r);
}
else
{
if(myGeo)
{
myGeo->purgeBuffers();
delete myGeo;
myGeo = NULL;
}
}
return false;
}
DM_ObjectPathRenderHook::getCurrentObject() const
{
int i;
for(i=0; i<viewport().getNumOpaqueObjects() && !cur_obj.
isValid(); i++)
{
itr = viewport().getOpaqueObject(i);
cur_obj = itr;
}
for(i=0; i<viewport().getNumTransparentObjects() && !cur_obj.
isValid(); i++)
{
itr = viewport().getTransparentObject(i);
cur_obj = itr;
}
for(i=0; i<viewport().getNumUnlitObjects() && !cur_obj.
isValid(); i++)
{
itr = viewport().getUnlitObject(i);
cur_obj = itr;
}
if(obj)
{
return obj;
}
return NULL;
}
void
DM_ObjectPathRenderHook::rebuildPathGeometry(
RE_Render *r,
int start_frame,
int end_frame,
{
cachename += "-obj-path";
if(!myGeo)
else
myGeo->cacheBuffers(cachename);
int n = (end_frame-start_frame) * 4 + 2;
myGeo->setNumPoints( n );
for(int fr = start_frame; fr<=end_frame; fr++)
{
p.homogenize();
pn.homogenize();
p3.
assign(p.x(), p.y(), p.z());
pn3.
assign(pn.x(), pn.y(), pn.z());
pos.append(p3);
if(fr % 10 == 0)
point_index.
append( pos.entries() -1 );
pos.append(pn3);
if(!first)
{
clr_tip = clr;
col.append(clr);
col.append(clr_tip);
if(fr == start_frame + 1)
{
col.append(clr);
col.append(clr_tip);
}
pos.append(prev_pos);
col.append(prev_clr);
pos.append(p3);
col.append(clr);
prev_clr = clr;
}
else
first = false;
prev_pos = p3;
}
if(pa)
if(ca)
if(ca && pa)
{
true );
true );
}
else
{
myGeo->purgeBuffers();
delete myGeo;
myGeo = NULL;
}
}
void
DM_ObjectPathRenderHook::drawPathGeometry(
RE_Render *r)
{
if(!myShader)
{
"vertex", 0);
"fragment", 0);
myShader->linkShaders(r);
}
myGeo->draw(r, 1);
myGeo->draw(r, 0);
}
void
DM_ObjectPathRenderHook::viewportClosed()
{
if(myGeo)
{
myGeo->purgeBuffers();
delete myGeo;
myGeo = NULL;
}
}
void
{
}