786 ro.depthWrite =
true;
792 Pose *pose = skeleton_.pose(hAni_);
793 typename SkeletonType::Iterator it;
799 const int numJoints = skeleton_.jointCount();
802 for (
unsigned int i = 0; i < _drawMode.
getNumLayers(); ++i)
806 switch (props->primitive())
809 case DrawModes::PRIMITIVE_POINT:
811 ro.debugName =
"SkeletonNode.point";
823 const int instanceDataSize = 4*3*4 + 4;
824 const int instanceBufSize = numJoints * instanceDataSize;
827 const int numFloats = instanceBufSize/4;
828 std::vector<float> instanceData(numFloats);
831 int instanceDataOffset = 0;
833 for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
839 if ( (*it)->selected() )
840 vcolor =
Vec4f(1.0f, 0.0f, 0.0f, 1.0f);
844 if ( (*it)->isRoot() )
845 vcolor =
Vec4f(1.0f,0.66f, 0.0f, 1.0f);
850 Vec3d globalPosD = pose->globalTranslation( (*it)->id() );
852 float sphereSize = float(unprojectPointSize((
double)_state.
point_size(),
857 modelview.
translate(
static_cast<float>(globalPosD[0]),
static_cast<float>(globalPosD[1]),
static_cast<float>(globalPosD[2]));
858 modelview.
scale(sphereSize, sphereSize, sphereSize);
861 for (
int r = 0; r < 3; ++r)
862 for (
int c = 0; c < 4; ++c)
863 instanceData[instanceDataOffset++] = modelview(r,c);
866 unsigned int uicolor = 0xff000000;
867 uicolor |= (
unsigned int)(vcolor[0] * 255.0f) & 0x000000ff;
868 uicolor |= ((
unsigned int)(vcolor[1] * 255.0f) << 8) & 0x0000ff00;
869 uicolor |= ((
unsigned int)(vcolor[2] * 255.0f) << 16) & 0x00ff0000;
878 uitofloat.u = uicolor;
880 instanceData[instanceDataOffset++] = uitofloat.f;
884 pointInstanceData_.bind();
885 pointInstanceData_.upload(instanceBufSize, &instanceData[0], GL_DYNAMIC_DRAW);
886 pointInstanceData_.unbind();
890 if (!pointInstanceDecl_.getNumElements())
892 pointInstanceDecl_ = *sphere_->getVertexDecl();
894 pointInstanceDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_SHADER_INPUT,
size_t(0),
"inModelView0", 1, pointInstanceData_.id());
895 pointInstanceDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_SHADER_INPUT,
size_t(0),
"inModelView1", 1, pointInstanceData_.id());
896 pointInstanceDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_SHADER_INPUT,
size_t(0),
"inModelView2", 1, pointInstanceData_.id());
897 pointInstanceDecl_.addElement(GL_UNSIGNED_BYTE, 4,
VERTEX_USAGE_COLOR,
size_t(0), 0, 1, pointInstanceData_.id());
901 ro.
shaderDesc.vertexTemplateFile =
"Skeleton/instanced_vs.glsl";
905 ro.glDrawInstancedArrays(GL_TRIANGLES, 0, sphere_->getNumTriangles() * 3, numJoints);
918 for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
922 if ( (*it)->selected() )
923 ro.emissive =
Vec3f(1.0f, 0.0f, 0.0f);
927 if ( (*it)->isRoot() )
928 ro.emissive =
Vec3f(1.0f,0.66f, 0.0f);
930 ro.emissive =
Vec3f(jointColor[0], jointColor[1] , jointColor[2]);
936 const double sphereSize = unprojectPointSize((
double)_state.
point_size(), pose->globalTranslation( (*it)->id() ), _state);
938 sphere_->addToRenderer(_renderer, &ro, sphereSize,
ACG::Vec3f(pose->globalTranslation( (*it)->id() )));
946 case DrawModes::PRIMITIVE_POLYGON:
948 ro.debugName =
"SkeletonNode.bone";
952 ro.setMaterial(_mat);
954 ro.emissive =
ACG::Vec3f(baseColor[0],baseColor[1],baseColor[2]);
967 const int instanceDataFloats = 3*4 + 3*3;
968 const int instanceDataSize = instanceDataFloats * 4;
969 const int instanceBufSize = 2 * numJoints * instanceDataSize;
972 const int numFloats = instanceBufSize/4;
973 std::vector<float> instanceData(numFloats);
976 int instanceDataOffset = 0;
977 GLMatrixf cone0, cone1, cone0IT, cone1IT;
979 for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
990 Vec3d parentPos = pose->globalTranslation(parent->
id());
991 Vec3d jointPos = pose->globalTranslation(joint->
id());
993 Vec3d boneVector = (jointPos - parentPos);
996 computeConeMatrices(ro.
modelview, parentPos, boneVector, &cone0, &cone1);
1005 for (
int r = 0; r < 3; ++r)
1006 for (
int c = 0; c < 4; ++c)
1007 instanceData[instanceDataOffset++] = cone0(r,c);
1009 for (
int r = 0; r < 3; ++r)
1010 for (
int c = 0; c < 3; ++c)
1011 instanceData[instanceDataOffset++] = cone0IT(c,r);
1013 for (
int r = 0; r < 3; ++r)
1014 for (
int c = 0; c < 4; ++c)
1015 instanceData[instanceDataOffset++] = cone1(r,c);
1017 for (
int r = 0; r < 3; ++r)
1018 for (
int c = 0; c < 3; ++c)
1019 instanceData[instanceDataOffset++] = cone1IT(c,r);
1022 const int numBones = instanceDataOffset / instanceDataFloats;
1025 boneInstanceData_.bind();
1026 boneInstanceData_.upload(instanceDataOffset * 4, &instanceData[0], GL_DYNAMIC_DRAW);
1027 boneInstanceData_.unbind();
1032 if (!boneInstanceDecl_.getNumElements())
1034 boneInstanceDecl_ = *cone_->getVertexDecl();
1036 boneInstanceDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_SHADER_INPUT,
static_cast<size_t>(0),
"inModelView0", 1, boneInstanceData_.id());
1037 boneInstanceDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_SHADER_INPUT,
static_cast<size_t>(0),
"inModelView1", 1, boneInstanceData_.id());
1038 boneInstanceDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_SHADER_INPUT,
static_cast<size_t>(0),
"inModelView2", 1, boneInstanceData_.id());
1039 boneInstanceDecl_.addElement(GL_FLOAT, 3,
VERTEX_USAGE_SHADER_INPUT,
static_cast<size_t>(0),
"inModelViewIT0", 1, boneInstanceData_.id());
1040 boneInstanceDecl_.addElement(GL_FLOAT, 3,
VERTEX_USAGE_SHADER_INPUT,
static_cast<size_t>(0),
"inModelViewIT1", 1, boneInstanceData_.id());
1041 boneInstanceDecl_.addElement(GL_FLOAT, 3,
VERTEX_USAGE_SHADER_INPUT,
static_cast<size_t>(0),
"inModelViewIT2", 1, boneInstanceData_.id());
1046 ro.glDrawInstancedArrays(GL_TRIANGLES, 0, cone_->getNumTriangles() * 3, numBones);
1048 ro.
shaderDesc.vertexTemplateFile =
"Skeleton/instanced_wvit_vs.glsl";
1060 for(it = skeleton_.begin(); it != skeleton_.end(); ++it) {
1071 Vec3d parentPos = pose->globalTranslation(parent->
id());
1072 Vec3d jointPos = pose->globalTranslation(joint->
id());
1074 Vec3d boneVector = (jointPos - parentPos);
1076 addBoneToRenderer(_renderer, ro, parentPos, boneVector);
1089 if (bCoordFramesVisible_)
1093 for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
1095 unsigned int index = (*it)->id();
1096 typename SkeletonType::Matrix global = pose->globalMatrix(index);
1097 NormalizeCoordinateFrame(global);
1101 Vec3f(0.8f, 0.2f, 0.2f),
1102 Vec3f(0.2f, 0.8f, 0.2f),
1103 Vec3f(0.2f, 0.2f, 0.8f)
1107 Point(fFrameSize_, 0, 0),
1108 Point(0, fFrameSize_, 0),
1109 Point(0, 0, fFrameSize_)
1114 float lineWidth = (float)unprojectPointSize(3.0f, pose->globalTranslation(index), _state);
1117 float sphereSize = (float)unprojectPointSize(6.0f, pose->globalTranslation(index), _state);
1120 for (
int i = 0; i < 3; ++i)
1122 ro.emissive = colors[i];
1125 Vec3f vstart = (
Vec3f)pose->globalTranslation(index);
1126 Vec3f vend = (
Vec3f)global.transform_point(points[i]);
1128 Vec3f vdir = vend - vstart;
1129 float height = vdir.
length();
1131 cylinder_->addToRenderer(_renderer, &ro, height, vstart, vdir, lineWidth);
1132 sphere_->addToRenderer(_renderer, &ro, sphereSize, vend);