public ActorDesc CreateActorDesc(EntityWorldEntity entityNode, Entity entity, Vector3 position, Quaternion orientation, Vector3 scale) { ActorDesc actorDesc = new ActorDesc(); actorDesc.GlobalPosition = position; actorDesc.GlobalOrientation = orientation.ToRotationMatrix(); if (entityNode.CollisionMode == CollisionMode.ConvexHull || entityNode.CollisionMode == CollisionMode.TriangleMesh) { StaticMeshData meshData = new StaticMeshData(entity.GetMesh(), scale); if (entityNode.CollisionMode == CollisionMode.TriangleMesh) actorDesc.Shapes.Add(Engine.Physics.CreateTriangleMesh(meshData)); else actorDesc.Shapes.Add(Engine.Physics.CreateConvexHull(meshData)); } else { switch (entityNode.CollisionMode) { case CollisionMode.BoundingBox: actorDesc.Shapes.Add(new BoxShapeDesc(entity.BoundingBox.HalfSize * scale, entity.BoundingBox.Center * scale)); break; case CollisionMode.BoundingSphere: actorDesc.Shapes.Add(new SphereShapeDesc(Engine.MaxAxis(entity.BoundingBox.HalfSize), entity.BoundingBox.Center * scale)); break; case CollisionMode.Shapes: foreach (ShapeDesc shapeDesc in entityNode.Shapes) actorDesc.Shapes.Add(shapeDesc); break; default: throw new Exception(entityNode.CollisionMode.ToString() + " not implemented"); } } return actorDesc; }
public List<String> SetViewModel(String _model) { String nameOnly = Path.GetFileNameWithoutExtension(_model); String filename = Path.GetFileName(_model); String modelDir = Path.GetDirectoryName(_model); AddResourcesDirectory(nameOnly, modelDir); if (sceneMgr.HasEntity(nameOnly)) sceneMgr.DestroyEntity(nameOnly); modelEntity = sceneMgr.CreateEntity(nameOnly, filename, nameOnly); if (sceneMgr.HasSceneNode(MODEL_NODE)) sceneMgr.DestroySceneNode(MODEL_NODE); modelNode = sceneMgr.RootSceneNode.CreateChildSceneNode(MODEL_NODE); modelNode.SetInitialState(); modelNode.DetachAllObjects(); modelNode.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(); } //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, modelNode); 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); }
/// <summary> /// This method loads the nodes and entities needed by the compound model /// </summary> protected override void LoadModelElements() { hullGroup = mSceneMgr.CreateSceneNode(); wheelGroup = mSceneMgr.CreateSceneNode(); gunGroup = mSceneMgr.CreateSceneNode(); mainHull = mSceneMgr.CreateSceneNode(); hullEntity = mSceneMgr.CreateEntity("Main.mesh"); hullEntity.GetMesh().BuildEdgeList(); sphere = mSceneMgr.CreateSceneNode(); sphereEntity = mSceneMgr.CreateEntity("Sphere.mesh"); sphereEntity.GetMesh().BuildEdgeList(); powerCells = mSceneMgr.CreateSceneNode(); powerCellsEntity = mSceneMgr.CreateEntity("PowerCells.mesh"); powerCellsEntity.GetMesh().BuildEdgeList(); model = mSceneMgr.CreateSceneNode(); float radius = 50; model.Position += radius * Vector3.UNIT_Y; hullGroup.Position -= radius * Vector3.UNIT_Y; physObj = new PhysObj(radius, "PlayerModel", 0.1f, 0.21f, 0.1f); physObj.SceneNode = model; physObj.Position = model.Position; physObj.AddForceToList(new WeightForce(physObj.InvMass)); physObj.AddForceToList(new FrictionForce(physObj)); Physics.AddPhysObj(physObj); }
public void FillData(string _filename, ref Entity _entity) { filename = _filename; entity = _entity; components = new List<ModelComponent>(); ModelComponent m; Pass p; String foundPath = ""; FileInfoListPtr fileInfos; FileInfoList.Iterator it; Mesh.Const_SubMeshNameMap map = entity.GetMesh().GetSubMeshNameMap(); for (uint i = 0; i < map.Count; i++) { for (Mesh.Const_SubMeshNameMap.ConstIterator start = map.Begin(); start != map.End(); start++) { if (start.Value == i) { // Name m = new ModelComponent(start.Key); // SubEntity m.SubEntity = entity.GetSubEntity(start.Key); // Type (Button, Joystick, Body?) if(start.Key.Contains("Button") || start.Key.Contains("Plunger") || start.Key.Contains("Cylinder")) m.Type = FragmentType.BUTTON; else if(start.Key.Contains("Balltop") || start.Key.Contains("Shaft") || start.Key.Contains("Dust")) m.Type = FragmentType.JOYSTICK; else m.Type = FragmentType.MODEL; //m.Parent =; // Texture p = m.SubEntity.GetMaterial().GetBestTechnique().GetPass(0); if(p.NumTextureUnitStates > 0) { // Set the texture m.Texture = TextureManager.Singleton.GetByName(p.GetTextureUnitState(0).TextureName); // Get a bitmap version to display foundPath = m.Texture.Name; fileInfos = ResourceGroupManager.Singleton.FindResourceFileInfo("General", foundPath ); it = fileInfos.Begin(); if(it != fileInfos.End()) foundPath = it.Value.archive.Name + "/" + foundPath; else foundPath = ""; m.TextureImage = new Bitmap(foundPath); } else { m.Texture = null; // TODO: Put in a no texture image m.TextureImage = null; } // Color m.Color = Color.White; components.Add(m); break; } } } }
public bool LoadModel(string modelPath) { mainStick = sceneMgr.CreateEntity("Stick", modelPath); mainStick.CastShadows = true; SceneNode node = sceneMgr.RootSceneNode.CreateChildSceneNode("StickNode"); node.AttachObject(mainStick); node.Position = new Mogre.Vector3(0, 10, 0); //node.Rotate(Mogre.Vector3.UNIT_X, Mogre.Math.PI); //node.Rotate(Mogre.Vector3.UNIT_Y, Mogre.Math.PI); ArcadeStickData.Instance.FillData(modelPath, ref mainStick); Mesh.Const_SubMeshNameMap map = mainStick.GetMesh().GetSubMeshNameMap(); ModelComponent frag; for (uint i = 0; i < map.Count; i++) { for (Mesh.Const_SubMeshNameMap.ConstIterator start = map.Begin(); start != map.End(); start++) { if (start.Value == i) { frag = new ModelComponent(start.Key); Messenger<ModelComponent>.Broadcast("AddFragment", frag); break; } } } return true; }