I wont do effect pull out(dismember) limbs; cuted skin (example by the saw,axe or knife) IN RAGDOLL,
and I have problem with void createWeight() for joint in model,
becacuse if I aded new vertices(representing meat under skin) and append them to joint.weight by this function, the program throw error in irrlicht.dll.
the code is still WIP.
used irrlicht ver. 1.4.1.
Code: Select all
ISkinnedMesh*mesh = (ISkinnedMesh*)Game.smgr->getMesh(nameMeshSkeleton);
array<ISkinnedMesh::SJoint*> joint = mesh->getAllJoints();
u16 cMeshBuffer=0;
SSkinMeshBuffer * meshBuffer = 0;
array<ISkinnedMesh::SWeight>& weights = joint[5]->Weights; //joint[5] is forerArm
int count = 0;
for(int i=0; i<weights.size()-count; i++)
{
if(weights[i].strength >= 0.5f)
meshBuffer =(SSkinMeshBuffer * ) mesh->getMeshBuffer(weights[i].buffer_id);
u16* ind = meshBuffer->getIndices();
array<s16> indexMoved;// id of vertex what was moved
array<u16> indexMovedTo;// id of new place where vertex must to be move
s16 jC=-1;
for(u16 j=0; j<meshBuffer->getIndexCount(); j++)
{
jC++;
if(jC==3)
jC=0;
bool doSplit = true;
if(ind[j] != weights[i].vertex_id)
doSplit = false;
//this is temp code searching connected vertex. Only for check how work appending weights to joints
int w =0;
for(w=0; w<weights.size()-count && doSplit == true; w++)
{
if(w!=i && weights[w].strength < 0.5f)
{
if(jC == 0)
{
if(ind[j+1] == weights[w].vertex_id ||
ind[j+2] == weights[w].vertex_id)
doSplit = false;
}
else if(jC == 1)
{
if(ind[j-1] == weights[w].vertex_id ||
ind[j+1] == weights[w].vertex_id)
doSplit = false;
}
else if(jC == 2)
{
if(ind[j-1] == weights[w].vertex_id ||
ind[j-2] == weights[w].vertex_id)
doSplit = false;
}
}
}
if(doSplit==true)
{
s32 s = indexMoved.linear_search(ind[j]);
if(s==-1)
{
//meshBuffer->append(meshBuffer->getVertex(ind[j]), 1, 0, 0);
//****i do this becauce append don't work (can't add a vertex);*********************
meshBuffer->Vertices_Standard.reallocate(meshBuffer->getVertexCount()+1);
meshBuffer->Vertices_Standard.push_back(*meshBuffer->getVertex(ind[j]));
//******************************************************************************************
indexMoved.push_back(ind[j]);
ind[j] = meshBuffer->getVertexCount()-1;
indexMovedTo.push_back(meshBuffer->getVertexCount()-1);
//if i do createWeight() , application show error in irrlicht.dll ...
/* ISkinnedMesh::SWeight* wei = mesh->createWeight(joint[5]);
wei->vertex_id = ind[j];
wei->buffer_id = weights[i].buffer_id;
wei->strength = 1.0f;
count++;
*/
//... so i try add weight by push_back, but cannot access private member (moved,StaticPos,StaticNormal), to change them
ISkinnedMesh::SWeight wei = weights[i];
wei.vertex_id = ind[j];
wei.buffer_id = weights[i].buffer_id;
wei.strength = 1.0f;
weights.push_back(wei);
count++;
// and the main problem is that: when i create model for ragdoll with new vertices added and assigned by weight (wei.vertex_id = ind[j])...
// ... then thats vertices.Pos are chenging in every frame (vertices.Pos += weight.StaticPos), and joint can't transform them.
}
else
{
ind[j] = indexMovedTo[s];
}
}
}
}