Original content Reprint Please specify: Http://weibo.com/gdexqin
The basis of program code in http://blog.sina.com.cn/s/blog_7c03dc6f01012um2.html
First look at the effect after import.
Animated models are uploaded to the Web by others (as if the character shouting truth the name code, not quite, but thanks to the uploader), we have completed the effect of importing static scenes through OgreMax, we need to make some changes to the export options of OgreMax.
Let's look at some basic options for OgreMax (go from the network):
-------------I'm a split line----------------------------------------------------------------------
The properties of the exported object can be set in the Ogremax->object settings. Here are some of the more important options.
General
Type This determines the types of objects that are exported in the. scene file. The most common is entity/mesh, which generates a node and the entity attached to the node after the export, and the 3DS
The object in Max is exported as a. mesh file. Then the more commonly used is empty, this type will be exported to a non-hanging anything of node. For example, if I use a box to represent the location of the NPC, the box can be set to the empty type.
Rendering here to set the object visibility, rendering order, shader parameters, etc.
Node Animation
Here you set the object's node animation, that is, the position, rotation, zoom on the animation. The animation of the change in the object model itself is set in the mesh animation. The specific usage has not been studied carefully.
User Data
The custom data you need for your game is set here. Dot Configure ... button to add the Userdatatypes.xml file described above, a custom data type will appear in the User data class. This allows you to direct the 3DS
Max is used as a level editor. Although there is no special editor so convenient, but most of the situation is enough.
Mesh
Mesh name and skeleton name can make the output model and the file name of the skeleton, and if not specified, it will be named after the object in 3ds Max.
Mesh Animation
This is used to set vertex animation or skeletal animation. You can animate any part of an object in the entire scene to make a name for the program to call. Click Add. The Animation Settings window will pop up. Usually the track type is set, the skeletal animation is physicue,
Fixed-point animations are morph. You only need to set the starting frame number of the action. Note that the skeletal animation of an object in a scene can only be exported as a skeleton file, and if you need to export different actions to different animations, you need to save the skeletal animation as a different max file and then fly it.
Read a custom file
OgreMax provides a mechanism for exporting from 3ds Max to a. scene file, but we still lack a program to read it. Although OgreMax comes with a viewer program, it is clear that you have to write one yourself to handle the custom data. Here you can refer to Ogre
An example of a. scene file Reader in a wiki that is modified on its basis:
Http://www.ogre3d.org/wiki/index.php/New_DotScene_Loader
But this program in many places just wrote a function name and did not implement, and the scene file processing and OgreMax export format is still different, you need to make a lot of changes.
-------------I'm a split line----------------------------------------------------------------------
In the previous work, we have completed the. scene file read work, so what we need to do now is just export, there are some differences in the options for different OgreMax, my version is OgreMaxSceneExporter2.4.1 is currently the latest version.
First read into the model,
Make some settings in the mesh animation, note that the animation type is selected for the
If there is an error in the exported animation map,
On the hook.
Then add the exported file to our resource folder, add the corresponding path in the program's resources.cfg, and read the model and skeletal animation we imported into the program.
The code is here, as it was last time, based on the previous code, and only one file was modified.
Code here: EnvMapping.h
#include "ogremaxscene.hpp" #include "BaseApplication.h" #include "SinbadCharacterController.h" Class Envmapapplication:public Baseapplication{public:envmapapplication () {}ogremax::ogremaxscene *m_ Maxscene; Animationstate * manimationstate; Animationstateset *manimationstateset;bool framerenderingqueued (const frameevent& evt) {//Let character update Animations and Cameramchara->addtime (evt.timesincelastframe); Manimationstate->addtime ( Evt.timesincelastframe); return baseapplication::framerenderingqueued (EVT);} BOOL Keypressed (const ois::keyevent& evt) {//Relay input events to character Controllerif (!mtraymgr-> Isdialogvisible ()) Mchara->injectkeydown (evt); return baseapplication::keypressed (EVT); BOOL Keyreleased (const ois::keyevent& evt) {//Relay input events to character Controllerif (!mtraymgr-> Isdialogvisible ()) Mchara->injectkeyup (evt); return baseapplication::keyreleased (EVT); #if Ogre_platform = = Ogre_platform_iphonebool TouchPressed (const ois::multitouchevent& evt) {//Relay input events to character Controllerif (!mtraymgr-> Isdialogvisible ()) Mchara->injectmousedown (evt); return sdksample::touchpressed (EVT); bool touchmoved (const ois::multitouchevent& evt) {//Relay input events to character Controllerif (!mtraymgr-& Gt;isdialogvisible ()) Mchara->injectmousemove (evt); return sdksample::touchmoved (EVT); #elsebool mousemoved (const ois::mouseevent& evt) {//Relay input events to character Controllerif (!mtraymgr-> Isdialogvisible ()) Mchara->injectmousemove (evt); return baseapplication::mousemoved (EVT); bool mousepressed (const ois::mouseevent& EVT, Ois::mousebuttonid ID) {//Relay input events to character control Lerif (!mtraymgr->isdialogvisible ()) Mchara->injectmousedown (evt, id); return baseapplication::mousepressed ( EVT, id);} #endifprotected: //Just Override the mandatory create scene methodvoid createscene (void) { m_maxscene = new Ogr Emax::ogremaxscene (); //1.scene is the OgreMax exported scene file name, of course you can also use absolute path, but it is not recommended to do so. m_maxscene->load ("123.scene", mwindow,ogremax::ogremaxscene::no_options, 0, 0); // Read the settings in the Maxscene file in the scene manager mscenemgr = M_maxscene->getscenemanager () //read the settings in the max file camera// Mcamera = Mscenemgr->getcamera ("Camera02"); The camera name specified in the 1.scene file mcamera = Mscenemgr->ogre::scenemanager::createcamera ("Chara"); ogre::viewport * VP = Mwindow->addviewport (Mcamera); vp->setbackgroundcolour (Ogre::colourvalue (0,0,0)); mCamera- >setaspectratio (Ogre::real (Vp->getactualwidth ())/ogre::real (Vp->getactualheight ())); mSceneMgr- >setambientlight (Ogre::colourvalue (0.5, 0.5, 0.5)); // mcameraman = new Ogrebites::sdkcameraman ( Mcamera); //Gets the node//entity *ent= mscenemgr->getentity ("Teapot01"); //ent->setmaterialname (" Examples/envmappedrustysteel "); setupcontent () ogre::entity* girl = mscenemgr->createentity (" Girl ", "Ms_01_4.mesh"); Ogre::scenenode* Girlnode = Mscenemgr->getrootscenenode ()->createchildscenenode ("Girlnode", Ogre::vector3 ( 100, 0, 50) ); Girlnode->attachobject (girl); Girlnode->scale (. 3,. 3,. 3); skeletonptr Skel = Skeletonmanager:: Getsingleton (). Load ("Ms_01_4.skeleton", Resourcegroupmanager::D efault_resource_group_name); //Animation* Anim = Skel->getanimation ("Girlkk"); manimationstateset = Girl->getallanimationstates (); Manimationstate = Girl->getanimationstate ("123"); Manimationstate->setloop (True);manimationstate-> SetEnabled (TRUE); //set the light source //Create a point lightogre::light* L = mscenemgr- >createlight ("Mainlight");//Accept default Settings:point light, white diffuse, just set position//NB I could attach The light to a scenenode if I wanted it to move automatically with// other objects, but I don ' tl->setposition (20, 20,50); }void setupcontent () {//Set shadow Propertiesmscenemgr->Setshadowtechnique (shadowtype_texture_modulative); Mscenemgr->setshadowcolour (ColourValue (0.5, 0.5, 0.5)); Mscenemgr->setshadowtexturesize (1024x768); Mscenemgr->setshadowtexturecount (1); //use a small amount of Ambient lightingmscenemgr->setambientlight (Colourvalue (0.3, 0.3, 0.3)); //Add a bright light above the scenelight* light = Mscenemgr->createlight (); Light->settype (Light::lt_point); Light->setposition (-10, 40, Light->setspecularcolour (colourvalue::white);//Create a floor mesh resourcemeshmanager::getsingleton (). Createplane ("Floor", Resourcegroupmanager::D efault_resource_group_name,plane (vector3::unit_y, 0), 100, 100, 10, 10, True, 1, ten, vector3::unit_z); //create a floor entity, give it a material, and place it at the originentity* FL Oor = mscenemgr->createentity ("Floorchara", "floor"), Floor->setmaterialname ("Examples/rockwall");floor-> Setcastshadows (false); Mscenemgr->getrootscenenode ()->attachobject (floor); //create our character Controllermchara = new Sinbadcharactercontroller (Mcamera);} void cleanupcontent () {//clean up character controllers and the floor Meshif (Mchara) Delete Mchara; Meshmanager::getsingleton (). Remove ("floor"); sinbadcharactercontroller* mchara; };
Go to import animations from 3DMAX through OgreMax into ogre and generate corresponding skeletal animations