You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
porcus
Posts: 149 Joined: Sun May 27, 2007 6:24 pm
Location: Germany
Post
by porcus » Sun Nov 02, 2008 2:49 pm
Hello,
I tried to copy a SJoint with his weights into another ISkinnedMesh.
Copying the appropriate vertices and indices was succesful (and they were displayed correctly too)
but when I tried to create a new SJoint and to copy all stuff from the old one to
the new one it didn't work: If I try to get the IBoneSceneNode (after adding the IAnimatedMeshSceneNode
of course) via node->getJointNode("Joint23") it's not succesful and node is still Null.
Why???
Code: Select all
m->createJoint(parentjoint);
m->getAllJoints().getLast()->Animatedposition=joint->Animatedposition;
m->getAllJoints().getLast()->Animatedrotation=joint->Animatedrotation;
m->getAllJoints().getLast()->Animatedscale=joint->Animatedscale;
m->getAllJoints().getLast()->GlobalAnimatedMatrix=joint->GlobalAnimatedMatrix;
m->getAllJoints().getLast()->GlobalInversedMatrix=joint->GlobalInversedMatrix;
m->getAllJoints().getLast()->GlobalMatrix=joint->GlobalMatrix;
m->getAllJoints().getLast()->LocalAnimatedMatrix=joint->LocalAnimatedMatrix;
m->getAllJoints().getLast()->LocalMatrix=joint->LocalMatrix;
m->getAllJoints().getLast()->Name=joint->Name;
int i;
for(i=0;i<joint->PositionKeys.size();i++){
m->createPositionKey(m->getAllJoints().getLast());
m->getAllJoints().getLast()->PositionKeys.getLast().frame=joint->PositionKeys[i].frame;
m->getAllJoints().getLast()->PositionKeys.getLast().position=joint->PositionKeys[i].position;
}
for(i=0;i<joint->RotationKeys.size();i++){
m->createRotationKey(m->getAllJoints().getLast());
m->getAllJoints().getLast()->RotationKeys.getLast().frame=joint->RotationKeys[i].frame;
m->getAllJoints().getLast()->RotationKeys.getLast().rotation=joint->RotationKeys[i].rotation;
}
for(i=0;i<joint->ScaleKeys.size();i++){
m->createScaleKey(m->getAllJoints().getLast());
m->getAllJoints().getLast()->ScaleKeys.getLast().frame=joint->ScaleKeys[i].frame;
m->getAllJoints().getLast()->ScaleKeys.getLast().scale=joint->ScaleKeys[i].scale;
}
m->getAllJoints().getLast()->Weights=joint->Weights;
for(i=0;i<joint->Weights.size();i++){
m->getAllJoints().getLast()->Weights[i].buffer_id=0;//all vertices are in m->getMeshBuffers()[0]
m->getAllJoints().getLast()->Weights[i].vertex_id=verticesbefore+i;//add all new vertices to the weigths
}
m->finalize();
Luke
Admin
Posts: 449 Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:
Post
by Luke » Sun Nov 02, 2008 11:37 pm
vertex_id=verticesbefore+i; seems odd, are the weights really in order? more then one weight could be on a vertex you know, this wouldn't let that happen.
could you show some more code, like where is verticesbefore, parentjoint, and joint from, etc.
btw what is this for?
porcus
Posts: 149 Joined: Sun May 27, 2007 6:24 pm
Location: Germany
Post
by porcus » Mon Nov 03, 2008 11:19 pm
OK, here's the full code:
Code: Select all
//mesh = targetmesh; skm = Sourcemesh, joint = joint which shall be copied, parentjoint = parent of the joint
ISkinnedMesh::SJoint* CopyJointIntoMesh(IAnimatedMesh* mesh, ISkinnedMesh* skm, ISkinnedMesh::SJoint* joint, ISkinnedMesh::SJoint* parentjoint=0)
{
ISkinnedMesh* m = (ISkinnedMesh*)mesh;
int verticesbefore=m->getMeshBuffers()[0]->Vertices_Standard.size();
int i;
int b;
int vorh;
int v1;
int v2;
int v3;
core::array<u32> buffers;
//Copy vertices and find used buffer
for(i=0;i<joint->Weights.size();i++)
{
m->getMeshBuffers()[0]->VertexType=skm->getMeshBuffers()[joint->Weights[i].buffer_id]->getVertexType();
if(m->getMeshBuffers()[0]->VertexType==EVT_STANDARD){
m->getMeshBuffers()[0]->Vertices_Standard.push_back(skm->getMeshBuffers()[joint->Weights[i].buffer_id]->Vertices_Standard[joint->Weights[i].vertex_id]);
}else if(m->getMeshBuffers()[0]->VertexType==EVT_2TCOORDS){
m->getMeshBuffers()[0]->Vertices_2TCoords.push_back(skm->getMeshBuffers()[joint->Weights[i].buffer_id]->Vertices_2TCoords[joint->Weights[i].vertex_id]);
}else if(m->getMeshBuffers()[0]->VertexType==EVT_TANGENTS){
m->getMeshBuffers()[0]->Vertices_Tangents.push_back(skm->getMeshBuffers()[joint->Weights[i].buffer_id]->Vertices_Tangents[joint->Weights[i].vertex_id]);
}
vorh=0;
for(b=0;b<buffers.size();b++)
{
if(buffers[b]==joint->Weights[i].buffer_id){
vorh=1;
}}
if(vorh==0){
buffers.push_back(joint->Weights[i].buffer_id);
}
}
//find triangles and copy
for(b=0;b<buffers.size();b++){
for(i=0;i<skm->getMeshBuffers()[buffers[b]]->Indices.size();i=i+3){
v1=instrjointweight(joint,skm->getMeshBuffers()[buffers[b]]->Indices[i],buffers[b]);
if(v1!=-1){
v2=instrjointweight(joint,skm->getMeshBuffers()[buffers[b]]->Indices[i+1],buffers[b]);
if(v2!=-1){
v3=instrjointweight(joint,skm->getMeshBuffers()[buffers[b]]->Indices[i+2],buffers[b]);
if(v3!=-1){
m->getMeshBuffers()[0]->Indices.push_back(verticesbefore+v1);
m->getMeshBuffers()[0]->Indices.push_back(verticesbefore+v2);
m->getMeshBuffers()[0]->Indices.push_back(verticesbefore+v3);
}}}
}
}
m->createJoint(parentjoint);
m->getAllJoints().getLast()->Animatedposition=joint->Animatedposition;
m->getAllJoints().getLast()->Animatedrotation=joint->Animatedrotation;
m->getAllJoints().getLast()->Animatedscale=joint->Animatedscale;
m->getAllJoints().getLast()->GlobalAnimatedMatrix=joint->GlobalAnimatedMatrix;
m->getAllJoints().getLast()->GlobalInversedMatrix=joint->GlobalInversedMatrix;
m->getAllJoints().getLast()->GlobalMatrix=joint->GlobalMatrix;
m->getAllJoints().getLast()->LocalAnimatedMatrix=joint->LocalAnimatedMatrix;
m->getAllJoints().getLast()->LocalMatrix=joint->LocalMatrix;
m->getAllJoints().getLast()->Name=joint->Name;
for(i=0;i<joint->PositionKeys.size();i++){
m->createPositionKey(m->getAllJoints().getLast());
m->getAllJoints().getLast()->PositionKeys.getLast().frame=joint->PositionKeys[i].frame;
m->getAllJoints().getLast()->PositionKeys.getLast().position=joint->PositionKeys[i].position;
}
for(i=0;i<joint->RotationKeys.size();i++){
m->createRotationKey(m->getAllJoints().getLast());
m->getAllJoints().getLast()->RotationKeys.getLast().frame=joint->RotationKeys[i].frame;
m->getAllJoints().getLast()->RotationKeys.getLast().rotation=joint->RotationKeys[i].rotation;
}
for(i=0;i<joint->ScaleKeys.size();i++){
m->createScaleKey(m->getAllJoints().getLast());
m->getAllJoints().getLast()->ScaleKeys.getLast().frame=joint->ScaleKeys[i].frame;
m->getAllJoints().getLast()->ScaleKeys.getLast().scale=joint->ScaleKeys[i].scale;
}
m->getAllJoints().getLast()->Weights=joint->Weights;
for(i=0;i<joint->Weights.size();i++){
m->getAllJoints().getLast()->Weights[i].buffer_id=0;//all vertices are in m->getMeshBuffers()[0]
m->getAllJoints().getLast()->Weights[i].vertex_id=verticesbefore+i;//add all new vertices to the weigths
}
m->finalize();
return m->getAllJoints().getLast();
}
//finds out on which index(in the JointWeigthsarray) the vertex(int ges) and the buffer(int buffer) is
s32 instrjointweight(ISkinnedMesh::SJoint* joint, int ges, int buffer)
{
int i;
for(i=0;i<joint->Weights.size();i++)
{
if(joint->Weights[i].vertex_id==ges){
if(joint->Weights[i].buffer_id==buffer){
return i;
}}}
return -1;
}
verticesbefore is the vertexcount before adding the new vertices, so this
should be correct or not?
Heres an image (all triangles and vertices seem to be correct (as you
can see) so the onliest problem is the joint stuff I posted before):
porcus
Posts: 149 Joined: Sun May 27, 2007 6:24 pm
Location: Germany
Post
by porcus » Fri Nov 07, 2008 6:49 pm
Does nobody know an answer ???