//--------------------------------------------------------------------- void PlayPen_testPoseAnimationWithoutNormals::setupContent() { mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); Vector3 dir(-1, -1, 0.5); dir.normalise(); Light* l = mSceneMgr->createLight("light1"); l->setType(Light::LT_DIRECTIONAL); l->setDirection(dir); MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); String newName = "testposenonormals.mesh"; mesh = mesh->clone(newName); SubMesh* sm = mesh->getSubMesh(0); // Re-organise geometry since this mesh has no animation and all // vertex elements are packed into one buffer VertexDeclaration* newDecl = sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, false); sm->vertexData->reorganiseBuffers(newDecl); // create 2 poses Pose* pose = mesh->createPose(1, "pose1"); // Pose1 moves vertices 0, 1, 2 and 3 upward Vector3 offset1(0, 50, 0); pose->addVertex(0, offset1); pose->addVertex(1, offset1); pose->addVertex(2, offset1); pose->addVertex(3, offset1); pose = mesh->createPose(1, "pose2"); // Pose2 moves vertices 3, 4, and 5 to the right // Note 3 gets affected by both Vector3 offset2(100, 0, 0); pose->addVertex(3, offset2); pose->addVertex(4, offset2); pose->addVertex(5, offset2); Animation* anim = mesh->createAnimation("poseanim", 20.0f); VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE); // Frame 0 - no effect VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(0); // Frame 1 - bring in pose 1 (index 0) kf = vt->createVertexPoseKeyFrame(3); kf->addPoseReference(0, 1.0f); // Frame 2 - remove all kf = vt->createVertexPoseKeyFrame(6); // Frame 3 - bring in pose 2 (index 1) kf = vt->createVertexPoseKeyFrame(9); kf->addPoseReference(1, 1.0f); // Frame 4 - remove all kf = vt->createVertexPoseKeyFrame(12); // Frame 5 - bring in pose 1 at 50%, pose 2 at 100% kf = vt->createVertexPoseKeyFrame(15); kf->addPoseReference(0, 0.5f); kf->addPoseReference(1, 1.0f); // Frame 6 - bring in pose 1 at 100%, pose 2 at 50% kf = vt->createVertexPoseKeyFrame(18); kf->addPoseReference(0, 1.0f); kf->addPoseReference(1, 0.5f); // Frame 7 - reset kf = vt->createVertexPoseKeyFrame(20); // Export the mesh DataStreamPtr stream = Root::getSingleton().createFileStream(newName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); MeshSerializer ser; ser.exportMesh(mesh.get(), stream); stream->close(); // Unload old mesh to force reload MeshManager::getSingleton().remove(mesh->getHandle()); mesh->unload(); mesh.setNull(); Entity* e; AnimationState* animState; // software pose e = mSceneMgr->createEntity("test2", newName); mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e); animState = e->getAnimationState("poseanim"); animState->setEnabled(true); animState->setWeight(1.0f); mAnimStateList.push_back(animState); // test hardware pose e = mSceneMgr->createEntity("test", newName); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); e->setMaterialName("Examples/HardwarePoseAnimation"); animState = e->getAnimationState("poseanim"); animState->setEnabled(true); animState->setWeight(1.0f); mAnimStateList.push_back(animState); mCamera->setNearClipDistance(0.5); Plane plane; plane.normal = Vector3::UNIT_Y; plane.d = 200; MeshManager::getSingleton().createPlane("Myplane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); pPlaneEnt->setMaterialName("2 - Default"); pPlaneEnt->setCastShadows(false); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); mCamera->setPosition(0,-200,-300); mCamera->lookAt(0,0,0); }