Problems binding skinner

Problems binding skinner

I am trying to implement an animation outside of the demo framework. I am having problems binding the skinner to the two buffers:

hkaFPUSkinningDeformer* AnimatedMesh::BindSkinner(hkxMeshSection* MeshSection ,hkxVertexBuffer* DeformedVertexBuffer)
{
	hkaVertexDeformerInput vdi;
	vdi.m_deformPosition = true;
	//vdi.m_deformNormal = true;

	hkaFPUSkinningDeformer* NewDeformer = new hkaFPUSkinningDeformer;

	hkBool bound = NewDeformer->bind(vdi, MeshSection->m_vertexBuffer, DeformedVertexBuffer);
	//cout << "Errors Go here" << endl;
	HK_ASSERT2(0x7af71fb2, bound, "Could not bind to skin..");
	return NewDeformer;
	//Skinners.push_back(NewSkinner);
}

I have a valid hkxMeshSection* and I am able to render it inside my own graphics engine. The user guide has this to say about the bind function:

The input format is assumed to have (at least) vertex weights. The output buffer should be preallocated. Returns false if the deformer does not support the input or output buffer format.

I have a few questions:

1)How exactly can I check for vertex weights in the input vertex buffer? I am pretty certain that it should have weights because I am using the same mesh from the demo (havok girl).
2)Can I get some example code(or a location in the demo) on how to preallocate a vertex buffer to be bound by a deformer like this?
3)How can I copy an existing vertex buffer to a new one. I would like to be able to copy the input buffer and use the copy as the output buffer. I have tried this:

hkxVertexBuffer* AnimatedMesh::AllocateDeformedVertexBuffer(hkxMeshSection* MeshSection)
{
	hkxVertexBuffer* newVertexBuffer = new hkxVertexBuffer;
	hkxVertexBuffer* VertexBuffer = MeshSection->m_vertexBuffer;
	const hkInt32 NumVertices = VertexBuffer->getNumVertices();

	newVertexBuffer->setVertexDesc(VertexBuffer->getVertexDesc());  

	//data
	/*
	hkVector4* dest;
	{
		dest = new hkVector4[NumVertices];  
		const char* src = VertexBuffer->getVertexData();  
		const int srcStride = VertexBuffer->getVertexDesc()->m_stride;  

		for(hkInt32 nVert=0; nVert		{
			memcpy(dest + nVert, src + nVert*srcStride, sizeof(hkVector4));
		}
	}

	newVertexBuffer->setVertexDataPtr(dest, NumVertices); 
	*/

	hkVector4* dest = new hkVector4[NumVertices];
	newVertexBuffer->setVertexDataClass(VertexBuffer->getVertexDataClass());

	return newVertexBuffer;
}

But the bind function still returns false.

Thank you in advance for any insights.

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi jchmack,

There are 3 real reasons why the bind() function would return false:

1. The number of vertices in the input buffer and output buffer don't match.
2. The properties of the input compared to both the properties of the input buffer and output buffer don't match. It checks that the m_deformPosition, m_deformNormal, m_deformTangent, and m_deformBinormal all match. It does this by checking the inputBuffer->getVertexDesc()->getMask() against a bit flag made up of those settings. The bitfield definition for those is under hkxVertexDescription.h, the DataUsage enumeration.
3. The input buffer has no weights. The check is done using the following if-statement:

hkUint32 iProps = inputBuffer->getVertexDesc()->getMask();
if ((iProps & hkxVertexDescription::HKX_DU_BLENDWEIGHTS) == 0)
{
return false;
}

Those are the conditions that you need to check for. Let me know if you have any questions on those. You should check out the Animation/Api/MeshAndDeformation/Skinning/SkinningDemo for a good example of how to get this working. I think that will have all the information you need on setting up buffers and calling things correctly.

One last thing, typically people do not use our skinning solution in their final application. Skinning is mostly in place for demo reasons. It will be perfect for prototyping, but in the long run, there might be better solutions for skinning out there.

Thanks,
Sean

Developer Support Engineer Havok www.havok.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today