Page 1 of 1

Problem with void createWeight() for joints

Posted: Wed Aug 27, 2008 12:46 pm
by StunterLiZaRd89
Hi Everyone, on begining, I wont excuse for my english ;)

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];
			}
		}
	}
}

Posted: Wed Aug 27, 2008 1:24 pm
by rogerborg
You don't appear to be checking that mesh->getAllJoints(); returns an array of at least 6 joints. What makes you think that it is?

Posted: Wed Aug 27, 2008 5:37 pm
by StunterLiZaRd89
rogerborg wrote:You don't appear to be checking that mesh->getAllJoints(); returns an array of at least 6 joints. What makes you think that it is?
I think the problem must be somewhere else.
I still have problem, even if I do

Code: Select all

mesh = smgr->getMesh(filename);
mesh->createWeight(mesh->getAllJoints()[5]);
just close application and throw: error in irrlicht.dll, as if can't realocate array or return 0 to main program...
similar problem I have when I use function createBuffer();

Posted: Wed Aug 27, 2008 8:20 pm
by rogerborg
StunterLiZaRd89 wrote:
rogerborg wrote:You don't appear to be checking that mesh->getAllJoints(); returns an array of at least 6 joints. What makes you think that it is?
I think the problem must be somewhere else.
Why think when you could find out for sure?

Posted: Fri Aug 29, 2008 10:08 am
by StunterLiZaRd89
rogerborg wrote:Why think when you could find out for sure?
I tryed everything ways. How you think, how you do this(add vertex to meshbuffer, and apply this vertex to list of weights in joint)?