problem with manual bone-vertex-assignment...

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
big_I
Kobold
Posts: 38
Joined: Wed Sep 05, 2007 3:02 pm

problem with manual bone-vertex-assignment...

Post by big_I »

Hi,

I'm trying to create a simple quad and attach it to a skeleton.

These are the steps:
1. I create a manual mesh.
2. Populate it with geometry (vertices and ndices)
3. Create a skeleton
4. Create bones.
5. Attach skeleton to mesh.
6. Create a scene node and attach the mesh to it.
7. If I modify the positions of the bone, it's not affecting the mesh at all.

Can somebody point out what is wrong.....
I'm eagerly waiting for a solution.

Even setting the position of the root node is not affecting the mesh.


Following is the code:

Code: Select all

static void CreateSkel()
{
	// Create the mesh via the MeshManager
	Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual("Plane1234", "General");
	// Create one submesh
	Ogre::SubMesh*	sub = msh->createSubMesh();
	int vCnt = 4 ;
	const int vbufCount = 3*4 ;


	float vertices[vbufCount] = 
	{
		-5.0, 2.0, -10.0,
		5.0, 2.0, -10.0,
		5.0, 2.0, 10.0, 
		-5.0, 2.0, 10.0,        
	} ;

	const oVector3 a(15, 0.0, 0.0) , b(20, 0, 0) ;

	vertices[0] += a.x ;	vertices[1] += a.y ;	vertices[2] += a.z ;
	vertices[3] += b.x ;	vertices[4] += b.y ;	vertices[5] += b.z ;
	vertices[6] += b.x ;	vertices[7] += b.y ;	vertices[8] += b.z ;
	vertices[9] += a.x ;	vertices[10] += a.y ;	vertices[11] += a.z ;

	const int iCnt = 6 ;
	unsigned short indices[iCnt] = {0, 2, 1, 0, 3, 2} ;

	msh->sharedVertexData = new Ogre::VertexData() ;
	msh->sharedVertexData->vertexCount = vCnt ;

	Ogre::VertexDeclaration		*pDecl = msh->sharedVertexData->vertexDeclaration ;
	size_t						offset = 0;
	pDecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION) ; 

	offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3) ;

	/// Allocate vertex buffer of the requested number of vertices (vertexCount) 
	/// and bytes per vertex (offset)
	Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(offset, 
		msh->sharedVertexData->vertexCount, 
		Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY) ;
	/// Upload the vertex data to the card
	vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true) ;

	/// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
	Ogre::VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding ; 
	bind->setBinding(0, vbuf) ;

	/// Allocate index buffer of the requested number of vertices (ibufCount) 
	Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, 
		iCnt, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY) ;

	/// Upload the index data to the card
	ibuf->writeData(0, ibuf->getSizeInBytes(), indices, true) ;

	/// Set parameters of the submesh
	sub->useSharedVertices = true ;
	sub->indexData->indexBuffer = ibuf ;
	sub->indexData->indexCount = iCnt ;
	sub->indexData->indexStart = 0 ;

	/// Set bounding information (for culling)
	msh->_setBounds(Ogre::AxisAlignedBox(-100,-100,-100,100,100,100)) ;
	msh->_setBoundingSphereRadius(1000.0) ;

	/// Notify Mesh object that it has been loaded
	msh->load();
	msh->_setLodInfo(1, true) ;

	msh->clearBoneAssignments();


	////////// create the skeleton here /////////////////
	Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create("skel123", "General", true) ; 
	skeleton->setBindingPose() ;
	Ogre::Bone* pRootBone = skeleton->createBone(0) ;
	pRootBone->resetOrientation() ;
	pRootBone->setPosition(0,0,0) ;
	pRootBone->setManuallyControlled(true) ;

	Ogre::Bone* b0 = pRootBone->createChild(1,oVector3(50.0, 0.0, 0.0)) ;
	Ogre::Bone* b1 = pRootBone->createChild(2,oVector3(50.0, 50.0, 0.0)) ;


	sub = msh->getSubMesh(0) ;

	Ogre::VertexBoneAssignment	vba ;
	vba.vertexIndex = 0 ; 
	vba.boneIndex = 0 ; 
	vba.weight = 1 ;
	msh->addBoneAssignment(vba) ;
	vba.vertexIndex = 3 ; 
	msh->addBoneAssignment(vba) ;

	vba.vertexIndex = 1 ; 
	vba.boneIndex = 1 ; 
	vba.weight = 1 ;
	msh->addBoneAssignment(vba) ;
	vba.vertexIndex = 2 ; 
	msh->addBoneAssignment(vba) ;
	

//	msh->_compileBoneAssignments() ;
//	msh->_notifySkeleton(skeleton) ;
//	msh->_compileBoneAssignments() ;


	msh->_notifySkeleton(skeleton) ;

	if(!msh->hasSkeleton())
	{
		assert(0) ;
	}

	skeleton->_updateTransforms() ;

	// set manual control over the bones 
	msh->getSkeleton()->getBone(1)->setManuallyControlled(true); 
	msh->getSkeleton()->getBone(2)->setManuallyControlled(true); 

	Ogre::SceneNode *pnode = g_pParticleSystemRootSceneNode->createChildSceneNode("asdasdasdfdfsfdsfdsd", oVector3(0,50,0)) ;
	Ogre::Entity *pccEntity = g_pSceneMgr->createEntity("WQeweqwe", "Plane1234") ;
	pnode->attachObject(pccEntity) ;


	msh->getSkeleton()->getBone(1)->setPosition(0,0,0) ;
	msh->getSkeleton()->getBone(2)->setPosition(50,0,0) ;

	pRootBone->setPosition(0,-50,0) ;
}
Thanks.
Post Reply