Ogre::Skeleton *ESKOgre::createOgreSkeleton(Ogre::SceneManager *mSceneMgr) { Ogre::SkeletonPtr mSkel = Ogre::SkeletonManager::getSingleton().create(name, XENOVIEWER_RESOURCE_GROUP, true); if (bones.size()) { buildBone(0, mSkel.getPointer(), NULL); } resources_created = true; createFakeEntity(mSceneMgr); skeleton = mSkel.getPointer(); return mSkel.getPointer(); }
void CMonster3D::setupSkeleton(std::string skeletonFile) { Ogre::SkeletonPtr pSkeletonBody = Ogre::SkeletonManager::getSingleton().getByName(m_meshName + ".skeleton"); Ogre::Skeleton::BoneHandleMap boneHandleMap; Ogre::SkeletonPtr pNewSkeleton = Ogre::SkeletonManager::getSingleton().load(skeletonFile, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Animation *pSrcAnimation = pNewSkeleton->getAnimation(0); std::string newAnimationName = pSrcAnimation->getName() + "::" + m_pMonsterNode->getName(); Ogre::Animation *pNewAnimation = pNewSkeleton->createAnimation(newAnimationName, pSrcAnimation->getLength()); Ogre::Animation *pCloneAnimation = pNewSkeleton->getAnimation(0)->clone(newAnimationName); *pNewAnimation = *pCloneAnimation; pNewSkeleton->removeAnimation(pSrcAnimation->getName()); pNewSkeleton->_buildMapBoneByHandle(pNewSkeleton.getPointer(), boneHandleMap); pSkeletonBody->_mergeSkeletonAnimations(pNewSkeleton.getPointer(), boneHandleMap); Ogre::SkeletonManager::getSingleton().remove(skeletonFile); m_pBodyEntity->getSkeleton()->_refreshAnimationState(m_pBodyEntity->getAllAnimationStates()); }
Ogre::Entity* ModelFile::GetModel( const ModelInfo& info ) { VectorTexForGen textures; Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create( info.data.name + "export", "General" ); Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create( info.data.name + "export", "General" ); int number_of_bones = GetU8( 0x02 ); int number_of_parts = GetU8( 0x03 ); int offset_to_bones = GetU32LE( 0x0c ); int offset_to_parts = GetU32LE( 0x10 ); Ogre::Bone* root1 = skeleton->createBone( "0", 0 ); Ogre::Bone* root2 = skeleton->createBone( "1", 1 ); root1->addChild( root2 ); for( int i = 0; i < number_of_bones; ++i ) { Bone bone; bone.parent_id = ( i != 0 ) ? ( s8 )GetU8( offset_to_bones + i * 0x04 + 0x03 ) : -1; bone.length = ( s16 )GetU16LE( offset_to_bones + i * 0x04 + 0x00 ); m_Skeleton.push_back(bone); Ogre::Bone* bone1 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 2 ), i * 2 + 2 ); Ogre::Bone* bone2 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 3 ), i * 2 + 3 ); LOGGER->Log( "Add skeleton bone: bone_id = " + Ogre::StringConverter::toString( i ) + ", length = " + Ogre::StringConverter::toString( bone.length ) + ", parent = " + Ogre::StringConverter::toString( bone.parent_id ) + ".\n" ); if( bone.parent_id == -1 ) { skeleton->getBone( 1 )->addChild( bone1 ); } else { skeleton->getBone( bone.parent_id * 2 + 3 )->addChild( bone1 ); } bone1->addChild( bone2 ); } AnimationExtractor( skeleton, info, m_Skeleton ); // draw skeleton { //DrawSkeleton( m_Skeleton, mesh ); } for( int i = 0; i < number_of_parts; ++i ) { MeshExtractor( info.data, "ffix/field_model/" + info.data.name, this, offset_to_parts + i * 0x28, textures, mesh ); } // <OGRE> /////////////////////////////// skeleton->optimiseAllAnimations(); Ogre::SkeletonSerializer skeleton_serializer; skeleton_serializer.exportSkeleton( skeleton.getPointer(), "exported/models/field/units/" + info.data.name + ".skeleton" ); // Update bounds Ogre::AxisAlignedBox aabb( -999, -999, -999, 999, 999, 999 ); mesh->_setBounds( aabb, false ); mesh->_setBoundingSphereRadius( 999 ); mesh->setSkeletonName( "models/field/units/" + info.data.name + ".skeleton" ); Ogre::MeshSerializer ser; ser.exportMesh( mesh.getPointer(), "exported/models/field/units/" + info.data.name + ".mesh" ); // create and export textures for model //if (textures.size() > 0) { Vram* vram = new Vram(); File* tex = new File( "./data/field/5/1b/2/4/1.tim" ); LoadTimFileToVram( tex, 0, vram ); delete tex; tex = new File( "./data/field/5/1b/2/4/2.tim" ); LoadTimFileToVram( tex, 0, vram ); delete tex; vram->Save( "1.jpg" ); CreateTexture( vram, info.data, "exported/models/field/units/" + info.data.name + ".png", textures ); delete vram; } CreateMaterial( "ffix/field_model/" + info.data.name, "exported/models/field/units/" + info.data.name + ".material", ( textures.size() > 0 ) ? "models/field/units/" + info.data.name + ".png" : "", "", "" ); Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" ); Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/field/units/" + info.data.name + ".mesh" ); //thisEntity->setDisplaySkeleton(true); //thisEntity->setDebugDisplayEnabled(true); thisEntity->setVisible( false ); thisEntity->getAnimationState( info.animations_name[ 0 ] )->setEnabled(true); thisEntity->getAnimationState( info.animations_name[ 0 ] )->setLoop(true); Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode(); thisSceneNode->setPosition( 0, 0, 0 ); thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) ); thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) ); thisSceneNode->pitch( Ogre::Radian( Ogre::Degree(90.0f ) ) ); thisSceneNode->attachObject( thisEntity ); return thisEntity; }
Ogre::SkeletonPtr MilkshapePlugin::doExportSkeleton(msModel* pModel, Ogre::MeshPtr& mesh) { Ogre::LogManager &logMgr = Ogre::LogManager::getSingleton(); Ogre::String msg; // // choose filename // OPENFILENAME ofn; memset (&ofn, 0, sizeof (OPENFILENAME)); char szFile[MS_MAX_PATH]; char szFileTitle[MS_MAX_PATH]; char szDefExt[32] = "skeleton"; char szFilter[128] = "OGRE .skeleton Files (*.skeleton)\0*.skeleton\0All Files (*.*)\0*.*\0\0"; szFile[0] = '\0'; szFileTitle[0] = '\0'; ofn.lStructSize = sizeof (OPENFILENAME); ofn.lpstrDefExt = szDefExt; ofn.lpstrFilter = szFilter; ofn.lpstrFile = szFile; ofn.nMaxFile = MS_MAX_PATH; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MS_MAX_PATH; ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; ofn.lpstrTitle = "Export to OGRE Skeleton"; if (!::GetSaveFileName (&ofn)) return Ogre::SkeletonPtr(); // Strip off the path Ogre::String skelName = szFile; size_t lastSlash = skelName.find_last_of("\\"); skelName = skelName.substr(lastSlash+1); // Set up logMgr.logMessage("Trying to create Skeleton object"); Ogre::SkeletonPtr ogreskel = Ogre::SkeletonManager::getSingleton().create(skelName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); logMgr.logMessage("Skeleton object created"); // Complete the details // Do the bones int numBones = msModel_GetBoneCount(pModel); msg = "Number of bones: " + Ogre::StringConverter::toString(numBones); logMgr.logMessage(msg); int i; // Create all the bones in turn for (i = 0; i < numBones; ++i) { msBone* bone = msModel_GetBoneAt(pModel, i); Ogre::Bone* ogrebone = ogreskel->createBone(bone->szName); msVec3 msBonePos, msBoneRot; msBone_GetPosition(bone, msBonePos); msBone_GetRotation(bone, msBoneRot); Ogre::Vector3 bonePos(msBonePos[0], msBonePos[1], msBonePos[2]); ogrebone->setPosition(bonePos); // Hmm, Milkshape has chosen a Euler angle representation of orientation which is not smart // Rotation Matrix or Quaternion would have been the smarter choice // Might we have Gimbal lock here? What order are these 3 angles supposed to be applied? // Grr, we'll try our best anyway... Ogre::Quaternion qx, qy, qz, qfinal; qx.FromAngleAxis(Ogre::Radian(msBoneRot[0]), Ogre::Vector3::UNIT_X); qy.FromAngleAxis(Ogre::Radian(msBoneRot[1]), Ogre::Vector3::UNIT_Y); qz.FromAngleAxis(Ogre::Radian(msBoneRot[2]), Ogre::Vector3::UNIT_Z); // Assume rotate by x then y then z qfinal = qz * qy * qx; ogrebone->setOrientation(qfinal); Ogre::LogManager::getSingleton().stream() << "Bone #" << i << ": " << "Name='" << bone->szName << "' " << "Position: " << bonePos << " " << "Ms3d Rotation: {" << msBoneRot[0] << ", " << msBoneRot[1] << ", " << msBoneRot[2] << "} " << "Orientation: " << qfinal; } // Now we've created all the bones, link them up logMgr.logMessage("Establishing bone hierarchy.."); for (i = 0; i < numBones; ++i) { msBone* bone = msModel_GetBoneAt(pModel, i); if (strlen(bone->szParentName) == 0) { // Root bone msg = "Root bone detected: Name='" + Ogre::String(bone->szName) + "' Index=" + Ogre::StringConverter::toString(i); logMgr.logMessage(msg); } else { Ogre::Bone* ogrechild = ogreskel->getBone(bone->szName); Ogre::Bone* ogreparent = ogreskel->getBone(bone->szParentName); if (ogrechild == 0) { msg = "Error: could not locate child bone '" + Ogre::String(bone->szName) + "'"; logMgr.logMessage(msg); continue; } if (ogreparent == 0) { msg = "Error: could not locate parent bone '" + Ogre::String(bone->szParentName) + "'"; logMgr.logMessage(msg); continue; } // Make child ogreparent->addChild(ogrechild); } } logMgr.logMessage("Bone hierarchy established."); // Create the Animation(s) doExportAnimations(pModel, ogreskel); // Create skeleton serializer & export Ogre::SkeletonSerializer serializer; msg = "Exporting skeleton to " + Ogre::String(szFile); logMgr.logMessage(msg); serializer.exportSkeleton(ogreskel.getPointer(), szFile); logMgr.logMessage("Skeleton exported"); msg = "Linking mesh to skeleton file '" + skelName + "'"; Ogre::LogManager::getSingleton().logMessage(msg); mesh->_notifySkeleton(ogreskel); return ogreskel; }
void CSceletalAnimationView::EngineSetup(void) { Ogre::Root *Root = ((CSceletalAnimationApp*)AfxGetApp())->m_Engine->GetRoot(); Ogre::SceneManager *SceneManager = NULL; SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "Animation"); // // Create a render window // This window should be the current ChildView window using the externalWindowHandle // value pair option. // Ogre::NameValuePairList parms; parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd); parms["vsync"] = "true"; CRect rect; GetClientRect(&rect); Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Mouse Input"); if (RenderWindow == NULL) { try { m_RenderWindow = Root->createRenderWindow("Mouse Input", rect.Width(), rect.Height(), false, &parms); } catch(...) { MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP); exit(EXIT_SUCCESS); } } // Load resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Create the camera m_Camera = SceneManager->createCamera("Camera"); m_Camera->setNearClipDistance(0.5); m_Camera->setFarClipDistance(5000); m_Camera->setCastShadows(false); m_Camera->setUseRenderingDistance(true); m_Camera->setPosition(Ogre::Vector3(5.0, 5.0, 10.0)); Ogre::SceneNode *CameraNode = NULL; CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode"); Ogre::Viewport* Viewport = NULL; if (0 == m_RenderWindow->getNumViewports()) { Viewport = m_RenderWindow->addViewport(m_Camera); Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f)); } // Alter the camera aspect ratio to match the viewport m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height())); m_Camera->lookAt(Ogre::Vector3(0.5, 0.5, 0.5)); m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME); Ogre::ManualObject* ManualObject = NULL; ManualObject = SceneManager->createManualObject("Animation"); ManualObject->setDynamic(false); ManualObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST); //face 1 ManualObject->position(0, 0, 0);//0 ManualObject->position(1, 0, 0);//1 ManualObject->position(1, 1, 0);//2 ManualObject->triangle(0, 1, 2);//3 ManualObject->position(0, 0, 0);//4 ManualObject->position(1, 1, 0);//5 ManualObject->position(0, 1, 0);//6 ManualObject->triangle(3, 4, 5);//7 //face 2 ManualObject->position(0, 0, 1);//8 ManualObject->position(1, 0, 1);//9 ManualObject->position(1, 1, 1);//10 ManualObject->triangle(6, 7, 8);//11 ManualObject->position(0, 0, 1);//12 ManualObject->position(1, 1, 1);//13 ManualObject->position(0, 1, 1);//14 ManualObject->triangle(9, 10, 11);//15 //face 3 ManualObject->position(0, 0, 0);//16 ManualObject->position(1, 0, 0);//17 ManualObject->position(1, 0, 1);//18 ManualObject->triangle(12, 13, 14);//19 ManualObject->position(0, 0, 0); ManualObject->position(1, 0, 1); ManualObject->position(0, 1, 1); ManualObject->triangle(15, 16, 17); //face 4 ManualObject->position(1, 0, 0); ManualObject->position(1, 1, 0); ManualObject->position(1, 1, 1); ManualObject->triangle(18, 19, 20); ManualObject->position(1, 0, 0); ManualObject->position(1, 1, 1); ManualObject->position(1, 0, 1); ManualObject->triangle(21, 22, 23); //face 5 ManualObject->position(0, 1, 0); ManualObject->position(1, 1, 0); ManualObject->position(0, 1, 1); ManualObject->triangle(24, 25, 26); ManualObject->position(1, 1, 0); ManualObject->position(1, 1, 1); ManualObject->position(0, 1, 1); ManualObject->triangle(27, 28, 29); //face 6 ManualObject->position(0, 0, 0); ManualObject->position(0, 1, 1); ManualObject->position(0, 0, 1); ManualObject->triangle(30, 31, 32); ManualObject->position(0, 0, 0); ManualObject->position(0, 1, 0); ManualObject->position(0, 1, 1); ManualObject->triangle(33, 34, 35); ManualObject->end(); Ogre::MeshPtr MeshPtr = ManualObject->convertToMesh("Animation"); Ogre::SubMesh* sub = MeshPtr->getSubMesh(0); Ogre::SkeletonPtr Skeleton = Ogre::SkeletonManager::getSingleton().create("Skeleton", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); MeshPtr.getPointer()->_notifySkeleton(Skeleton); Ogre::Bone *Root1 = NULL; Ogre::Bone *Child1 = NULL; Ogre::Bone *Child2 = NULL; Root1 = Skeleton.getPointer()->createBone("Root"); Root1->setPosition(Ogre::Vector3(0.0, 0.0, 0.0)); Root1->setOrientation(Ogre::Quaternion::IDENTITY); Child1 = Root1->createChild(1); Child1->setPosition(Ogre::Vector3(4.0, 0.0, 0.0)); Child1->setOrientation(Ogre::Quaternion::IDENTITY); Child2 = Root1->createChild(2); Child2->setPosition(Ogre::Vector3(5.0, 0.0, 0.0)); Child2->setOrientation(Ogre::Quaternion::IDENTITY); Ogre::VertexBoneAssignment Assignment; Assignment.boneIndex = 0; Assignment.vertexIndex = 0; Assignment.weight = 1.0; Skeleton->setBindingPose(); sub->addBoneAssignment(Assignment); Assignment.vertexIndex = 1; sub->addBoneAssignment(Assignment); Assignment.vertexIndex = 2; sub->addBoneAssignment(Assignment); Ogre::Animation *Animation = MeshPtr->createAnimation("HandAnimation", 100.0); Ogre::NodeAnimationTrack *Track = Animation->createNodeTrack(0, Root1); Ogre::TransformKeyFrame *KeyFrame = NULL; for (float FrameTime = 0.0; FrameTime < 100.0; FrameTime += 0.1) { KeyFrame = Track->createNodeKeyFrame(FrameTime); KeyFrame->setTranslate(Ogre::Vector3(10.0, 0.0, 0.0)); } Root1->setManuallyControlled(true); Child1->setManuallyControlled(true); Child2->setManuallyControlled(true); MeshPtr->load(); MeshPtr.getPointer()->_notifySkeleton(Skeleton); // Ogre::SkeletonSerializer skeletonSerializer; // skeletonSerializer.exportSkeleton(Skeleton.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.skeleton"); // Ogre::MeshSerializer ser; // ser.exportMesh(MeshPtr.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.mesh"); Ogre::Entity *Entity = SceneManager->createEntity("Animation", "Animation"/*"testskeleton.mesh"*/); Ogre::SceneNode *SceneNode = SceneManager->getRootSceneNode()->createChildSceneNode(); SceneNode->attachObject(Entity); Entity->setDisplaySkeleton(true); m_AnimationState = Entity->getAnimationState("HandAnimation"); m_AnimationState->setEnabled(true); m_AnimationState->setLoop(true); m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME); Root->renderOneFrame(); }
Ogre::Entity* StageFile::GetModel( const StageInfo& info ) { //DumpSettings("exported/" + info.data.name + ".lua"); VectorTexForGen textures; Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create(info.data.name + "export", "General"); Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create(info.data.name + "export", "General"); u32 number_of_files = GetU32LE(0); LOGGER->Log("Number of file " + IntToString(number_of_files) + "\n"); Ogre::Bone* root1 = skeleton->createBone( "0", 0 ); Ogre::Bone* root2 = skeleton->createBone( "1", 1 ); root1->addChild( root2 ); Ogre::Animation* anim = skeleton->createAnimation( "Idle", 1 ); Ogre::NodeAnimationTrack* track1 = anim->createNodeTrack( 0, root1 ); track1->removeAllKeyFrames(); Ogre::TransformKeyFrame* frame1 = track1->createNodeKeyFrame( 0 ); Ogre::Matrix3 matrix; matrix.FromEulerAnglesYXZ( Ogre::Radian( Ogre::Degree( 0 ) ), Ogre::Radian( Ogre::Degree( -90 ) ), Ogre::Radian( Ogre::Degree( 0 ) ) ); Ogre::Quaternion rot; rot.FromRotationMatrix( matrix ); frame1->setRotation( rot ); for (u32 i = 1; i < number_of_files - 1; ++i) { int offset_to_vertex = GetU32LE(0x04 + i * 0x04); MeshExtractor(info.data, "ffvii/battle_stage/" + info.data.name, this, offset_to_vertex, textures, mesh, Ogre::StringConverter::toString(i), 1); } // <OGRE> /////////////////////////////// skeleton->optimiseAllAnimations(); Ogre::SkeletonSerializer skeleton_serializer; skeleton_serializer.exportSkeleton(skeleton.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".skeleton"); // Update bounds Ogre::AxisAlignedBox aabb(-999, -999, -999, 999, 999, 999); mesh->_setBounds(aabb, false); mesh->_setBoundingSphereRadius(999); mesh->setSkeletonName( "models/ffvii/battle/stages/" + info.data.name + ".skeleton" ); Ogre::MeshSerializer ser; ser.exportMesh(mesh.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".mesh"); // create and export textures for model if( textures.size() > 0 ) { int number_of_files = GetU32LE( 0x00 ); int offset_to_texture = GetU32LE( number_of_files * 0x04 ); Vram* vram = Vram::MakeInstance().release(); LoadTimFileToVram( this, offset_to_texture, vram ); //vram->Save( "qqq" ); CreateTexture( vram, info.data, "exported/models/ffvii/battle/stages/" + info.data.name + ".png", textures ); delete vram; } CreateMaterial("ffvii/battle_stage/" + info.data.name, "exported/models/ffvii/battle/stages/" + info.data.name + ".material", "models/ffvii/battle/stages/" + info.data.name + ".png", "", ""); Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" ); Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/ffvii/battle/stages/" + info.data.name + ".mesh" ); //thisEntity->setDisplaySkeleton(true); //thisEntity->setDebugDisplayEnabled(true); thisEntity->setVisible(false); thisEntity->getAnimationState( "Idle" )->setEnabled( true ); thisEntity->getAnimationState( "Idle" )->setLoop( true ); Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode(); thisSceneNode->setPosition( 0, 0, 0 ); thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) ); thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) ); thisSceneNode->pitch( Ogre::Radian( Ogre::Degree( 90.0f ) ) ); thisSceneNode->attachObject( thisEntity ); return thisEntity; }