Exemple #1
0
 public void Reset()
 {
     if (HasModelSceneNode)
     {
         ModelSceneNode.ResetToInitialState();
         if (HasModelEntity)
         {
             SetInitialCamera(ModelEntity, ModelSceneNode);
         }
     }
 }
Exemple #2
0
        bool MogreFrameStarted(FrameEvent evt)
        {
            if (AutoRotateModel)
            {
                if (HasModelSceneNode)
                {
                    ModelSceneNode.Rotate(new Vector3(0f, 1f, 0f),
                                          new Radian(AutoRotateSpeed * evt.timeSinceLastFrame));
                }
            }

            if (Animate)
            {
                UpdateAnimation(evt.timeSinceLastFrame);
            }

            return(true);
        }
Exemple #3
0
        public List <string> SetViewModel(string theModel)
        {
            string nameOnly = Path.GetFileNameWithoutExtension(theModel);
            string filename = Path.GetFileName(theModel);
            string modelDir = Path.GetDirectoryName(theModel);

            AddResourcesDirectory(nameOnly, modelDir);

            //Entity ent = null;
            if (sceneMgr.HasEntity(nameOnly))
            {
                sceneMgr.DestroyEntity(nameOnly);
            }
            ModelEntity = sceneMgr.CreateEntity(nameOnly, filename, nameOnly);

            //SceneNode node = null;
            if (sceneMgr.HasSceneNode(MODEL_NODE))
            {
                sceneMgr.DestroySceneNode(MODEL_NODE);
            }
            ModelSceneNode = sceneMgr.RootSceneNode.CreateChildSceneNode(MODEL_NODE);
            ModelSceneNode.SetInitialState();

            ModelSceneNode.DetachAllObjects();
            ModelSceneNode.AttachObject(ModelEntity);

            // check for material textures
            foreach (var subMesh in ModelEntity.GetMesh().GetSubMeshIterator())
            {
                bool needsReload = false;
                var  matPtr      = (MaterialPtr)MaterialManager.Singleton.GetByName(subMesh.MaterialName);
                if (matPtr != null)
                {
                    foreach (var mtrPass in matPtr.GetTechnique(0).GetPassIterator())
                    {
                        foreach (var mtrTex in mtrPass.GetTextureUnitStateIterator())
                        {
                            if (mtrTex.IsTextureLoadFailing)
                            {
                                mtrTex.SetTextureName(mtrTex.TextureName.Replace(".png", ".dds"));
                                needsReload = true;
                            }
                        }
                    }
                }
                if (needsReload)
                {
                    matPtr.Reload();
                }
            }

            // gather information about wardrobe
            IsWardrobed      = false;
            WardrobeTextures = new string[Enum.GetValues(typeof(Wardrobe)).Length];

            if (ModelEntity.GetMesh().NumSubMeshes > 0)
            {
                foreach (var subMesh in ModelEntity.GetMesh().GetSubMeshIterator())
                {
                    var matPtr = (MaterialPtr)MaterialManager.Singleton.GetByName(subMesh.MaterialName);

                    foreach (Wardrobe suit in Enum.GetValues(typeof(Wardrobe)))
                    {
                        string suitStr = suit.ToString();
                        if (subMesh.MaterialName.IndexOf(suitStr, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            IsWardrobed = true;
                            string wardrobeTex = "none";
                            foreach (var mtrPass in matPtr.GetTechnique(0).GetPassIterator())
                            {
                                foreach (var mtrTex in mtrPass.GetTextureUnitStateIterator())
                                {
                                    if (!string.IsNullOrEmpty(mtrTex.TextureName))
                                    {
                                        wardrobeTex = mtrTex.TextureName;
                                    }
                                }
                            }

                            WardrobeTextures[(int)suit] = wardrobeTex;
                            break;
                        }
                    }
                }
            }

            //// 2nd pass
            //// check for material wardrobe textures
            //if (ModelEntity.GetMesh().NumSubMeshes > 0)
            //{
            //    foreach (var subMesh in ModelEntity.GetMesh().GetSubMeshIterator())
            //    {
            //        bool needsReload = false;
            //        var matPtr = (MaterialPtr)MaterialManager.Singleton.GetByName(subMesh.MaterialName);
            //        foreach (var mtrPass in matPtr.GetTechnique(0).GetPassIterator())
            //        {
            //            foreach (var mtrTex in mtrPass.GetTextureUnitStateIterator())
            //            {
            //                foreach (var wardrobe in allWadrobe)
            //                {
            //                    if (subMesh.MaterialName.IndexOf(wardrobe, StringComparison.OrdinalIgnoreCase) >= 0)
            //                    {
            //                        var fl = Directory.GetFiles(modelDir, string.Format("*{0}*", wardrobe));
            //                        // get the first that matches
            //                        if (fl.Length > 0)
            //                            mtrTex.SetTextureName(Path.GetFileName(fl[0]));
            //                        needsReload = true;
            //                    }
            //                }
            //            }
            //        }
            //        if (needsReload) matPtr.Reload();
            //    }
            //}
            // check for skeleton and animations
            if (ModelEntity.HasSkeleton)
            {
                foreach (string skltFiles in Directory.GetFiles(modelDir, "*.skeleton"))
                {
                    try
                    {
                        SkeletonPtr            source        = SkeletonManager.Singleton.Load(Path.GetFileName(skltFiles), "General");
                        Skeleton.BoneHandleMap boneHandleMap = new Skeleton.BoneHandleMap();
                        source._buildMapBoneByHandle(source, boneHandleMap);
                        ModelEntity.Skeleton._mergeSkeletonAnimations(source, boneHandleMap);
                        ModelEntity.Skeleton._refreshAnimationState(ModelEntity.AllAnimationStates);
                    }
                    catch
                    {
                    }
                }
                //ModelEntity.DisplaySkeleton = true;
            }

            SetInitialCamera(ModelEntity, ModelSceneNode);

            if (sceneMgr.HasLight("SimpleLight"))
            {
                sceneMgr.DestroyLight("SimpleLight");
            }
            Light light = sceneMgr.CreateLight("SimpleLight");

            sceneMgr.RootSceneNode.AttachObject(light);
            light.DiffuseColour = new ColourValue(1f, 1f, 1f);
            light.Position      = this.camera.Position;
            light.Direction     = this.camera.Direction;

            return(GetAnimationNames(ModelEntity));
        }