示例#1
0
        public void SetEquipModel(string theModel, EquipWeaponSlot theSlot)
        {
            if (ModelEntity != null && ModelEntity.HasSkeleton)
            {
                string boneName = theSlot.ToString();

                string nameOnly = "Equip" + 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);
                }

                var EquipedModel = sceneMgr.CreateEntity(nameOnly, filename, nameOnly);
                if (EquipEntities[(int)theSlot] != null)
                {
                    ModelEntity.DetachObjectFromBone(EquipEntities[(int)theSlot]);
                    // TODO: destroy
                    EquipEntities[(int)theSlot] = null;
                }

                EquipEntities[(int)theSlot] = EquipedModel;

                ModelEntity.AttachObjectToBone(boneName, EquipedModel);
                //ModelEntity.Skeleton.GetBone(boneName).

                // check for material textures
                foreach (var subMesh in EquipedModel.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();
                    }
                }
            }
        }
示例#2
0
 public bool HasWeaponSlot(EquipWeaponSlot theEqSlot)
 {
     if (ModelEntity != null && ModelEntity.HasSkeleton)
     {
         if (ModelEntity.Skeleton.HasBone(theEqSlot.ToString()))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
 public bool HasWeaponSlot(EquipWeaponSlot theEqSlot)
 {
     if (ModelEntity != null && ModelEntity.HasSkeleton)
     {
         if(ModelEntity.Skeleton.HasBone(theEqSlot.ToString())) return true;
         else return false;
     }
     else return false;
 }
        public void SetEquipModel(string theModel, EquipWeaponSlot theSlot)
        {
            if (ModelEntity!=null && ModelEntity.HasSkeleton)
            {
                string boneName = theSlot.ToString();

                string nameOnly = "Equip" + 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);
                }
                
                var EquipedModel = sceneMgr.CreateEntity(nameOnly, filename, nameOnly);
                if (EquipEntities[(int)theSlot] != null)
                {
                    ModelEntity.DetachObjectFromBone(EquipEntities[(int)theSlot]);
                    // TODO: destroy
                    EquipEntities[(int)theSlot] = null;
                }

                EquipEntities[(int)theSlot] = EquipedModel;

                ModelEntity.AttachObjectToBone(boneName, EquipedModel);
                //ModelEntity.Skeleton.GetBone(boneName).

                // check for material textures
                foreach (var subMesh in EquipedModel.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();
                }
            }
        }