public int Add(MeshPtr o) { lock (allMeshes) { return allMeshes.Add(((MeshPtr)o)); } }
public int Add(string pathRelFile) { MeshPtr mesh = MeshManager.Singleton.CreateManual(pathRelFile, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, loader); //mesh.Load(); lock (allMeshes) { return(allMeshes.Add(mesh)); } }
public virtual MeshPtr convertToMesh(string meshName) { MeshPtr ret = new MeshPtr(OgrePINVOKE.ManualObject_convertToMesh__SWIG_1(swigCPtr, meshName), true); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public MeshPtr clone(string newName) { MeshPtr ret = new MeshPtr(OgrePINVOKE.Mesh_clone__SWIG_1(swigCPtr, newName), true); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public MeshPtr getMesh() { MeshPtr ret = new MeshPtr(OgrePINVOKE.Entity_getMesh(swigCPtr), false); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
// creates a single Y plane public static Entity MakePlane(SceneManager mgr, float size, float tile) { MeshPtr mesh = MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, new Plane(Vector3.UNIT_Y, 0), size, size, 1, 1, true, 1, tile, tile, Vector3.UNIT_Z); // Create a ground plane return(mgr.CreateEntity("plane", "ground")); }
public Boolean Contains(MeshPtr a) { foreach (MeshPtr tex in allMeshes) { if (tex.Name == a.Name) { return(true); } } return(false); }
private bool CheckSubMeshOpType(MeshPtr mesh, RenderOperation.OperationTypes opType) { for (ushort i = 0; i < mesh.NumSubMeshes; i++) { if (mesh.GetSubMesh(i).operationType != opType) { return(false); } } return(true); }
public override void CreateScene() { SceneNode node1 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Tutorial10Node"); // Create a point light Light l = base.sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // Add light to the scene node SceneNode lightNode = base.sceneMgr.RootSceneNode.CreateChildSceneNode(); lightNode.CreateChildSceneNode(new Vector3(10, 10, 10)).AttachObject(l); MeshPtr pMesh = MeshManager.Singleton.Load("knot.mesh", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, HardwareBuffer.Usage.HBU_DYNAMIC_WRITE_ONLY, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY, true, true);//can still read it //ushort src, dest; //if (!pMesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest)) // pMesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest); //create entity Entity entity = sceneMgr.CreateEntity("Tutorial10Entity", "knot.mesh"); entity.SetMaterialName("CgTutorials/C5E2_Material"); //attach to main node node1.AttachObject(entity); // set up spline animation of node Animation anim = sceneMgr.CreateAnimation("LightTrack", 10F); // Spline it for nice curves anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, lightNode); // Setup keyframes TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition key = track.CreateNodeKeyFrame(2.5F); key.Translate = new Vector3(500F, 500F, -1000F); key = track.CreateNodeKeyFrame(5F); key.Translate = new Vector3(-1500F, 1000F, -600F); key = track.CreateNodeKeyFrame(7.5F); key.Translate = new Vector3(0F, 100F, 0F); key = track.CreateNodeKeyFrame(10F); key.Translate = new Vector3(0F, 0F, 0F); // Create a new animation state to track this animState = sceneMgr.CreateAnimationState("LightTrack"); animState.Enabled = true; }
private void createSphere(string strName, float r, SceneManager sceneMgr, int nRings = 16, int nSegments = 16) { ManualObject manual = sceneMgr.CreateManualObject(strName); manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); float fDeltaRingAngle = (Mogre.Math.PI / nRings); float fDeltaSegAngle = (2 * Mogre.Math.PI / nSegments); ushort wVerticeIndex = 0; // Generate the group of rings for the sphere for (int ring = 0; ring <= nRings; ring++) { float r0 = r * Mogre.Math.Sin(ring * fDeltaRingAngle); float y0 = r * Mogre.Math.Cos(ring * fDeltaRingAngle); // Generate the group of segments for the current ring for (int seg = 0; seg <= nSegments; seg++) { float x0 = r0 * Mogre.Math.Sin(seg * fDeltaSegAngle); float z0 = r0 * Mogre.Math.Cos(seg * fDeltaSegAngle); // Add one vertex to the strip which makes up the sphere manual.Position(x0, y0, z0); manual.Normal(new Mogre.Vector3(x0, y0, z0).NormalisedCopy); manual.TextureCoord((float)seg / (float)nSegments, (float)ring / (float)nRings); if (ring != nRings) { // each vertex (except the last) has six indicies pointing to it manual.Index((uint)(wVerticeIndex + nSegments + 1)); manual.Index(wVerticeIndex); manual.Index((uint)(wVerticeIndex + nSegments)); manual.Index((uint)(wVerticeIndex + nSegments + 1)); manual.Index((uint)(wVerticeIndex + 1)); manual.Index(wVerticeIndex); wVerticeIndex++; } } ; // end for seg } // end for ring manual.End(); MeshPtr mesh = manual.ConvertToMesh(strName); mesh._setBounds(new AxisAlignedBox(new Mogre.Vector3(-r, -r, -r), new Mogre.Vector3(r, r, r)), false); mesh._setBoundingSphereRadius(r); ushort src, dest; if (!mesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest)) { mesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest); } }
/// <summary> /// This method generates a plane in an Entity which will be used as a ground /// </summary> private void GroundPlane() { plane = new Plane(Vector3.UNIT_Y, 0); MeshPtr groundMeshPtr = MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, groundXSegs, groundZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Z); groundEntity = mSceneMgr.CreateEntity("ground"); groundEntity.SetMaterialName("Ground"); }
public void Load() { plane = new Plane(Vector3.UNIT_Y, 0); MeshPtr groundMeshPtr = MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, grounXSegs, grounZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Z); groundEntity = mSceneMgr.CreateEntity("ground"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Floor"); groundEntity.GetMesh().BuildEdgeList(); groundNode.Position = new Vector3(0, 0, 0); }
/// <summary> /// This method generate a plane in an Entity which will be used as ground plane /// </summary> private void GroundPlane() { //plane should be initialized to a plane object in the same fashion of the plane used for the sky plane plane = new Plane(Vector3.UNIT_Y, 0); //set to height zero //groundMeshPtr should be initialized using the MeshManager.Singleton.CreatePlane groundMeshPtr = MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, groundXSegs, groundZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Z); groundEntity = mSceneMgr.CreateEntity("ground"); groundEntity.SetMaterialName("Ground"); }
/// <summary> /// This method set up the mesh for the ground and atthach it to the scenegraph /// </summary> private void CreateGround() { plane = new Plane(Vector3.UNIT_Y, 0); MeshPtr groundMeshPtr = MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_Z); groundEntity = mSceneMgr.CreateEntity("ground"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Ground"); }
/// <summary> /// Save the model in binary format. /// </summary> /// <param name="filename">The name of the file to save.</param> public void saveModel(String filename) { if (entity != null) { using (MeshSerializer meshSerializer = new MeshSerializer()) { using (MeshPtr mesh = entity.getMesh()) { meshSerializer.exportMesh(mesh.Value, filename); } } } }
/// <summary> /// Recalculate the binormal vectors as the cross product between the tangents and the normals. /// </summary> public unsafe void buildBinormalVectors() { using (MeshPtr mesh = entity.getMesh()) { SubMesh subMesh = mesh.Value.getSubMesh(0); VertexData vertexData = subMesh.vertexData; VertexDeclaration vertexDeclaration = vertexData.vertexDeclaration; VertexBufferBinding vertexBinding = vertexData.vertexBufferBinding; VertexElement normalElement = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_NORMAL); VertexElement tangentElement = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_TANGENT); VertexElement binormalElement = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_BINORMAL); int numVertices = vertexData.vertexCount.ToInt32(); HardwareVertexBufferSharedPtr normalHardwareBuffer = vertexBinding.getBuffer(normalElement.getSource()); int normalVertexSize = normalHardwareBuffer.Value.getVertexSize().ToInt32(); byte *normalBuffer = (byte *)normalHardwareBuffer.Value.lockBuf(HardwareBuffer.LockOptions.HBL_READ_ONLY); HardwareVertexBufferSharedPtr tangentHardwareBuffer = vertexBinding.getBuffer(tangentElement.getSource()); int tangetVertexSize = tangentHardwareBuffer.Value.getVertexSize().ToInt32(); byte *tangentBuffer = (byte *)tangentHardwareBuffer.Value.lockBuf(HardwareBuffer.LockOptions.HBL_READ_ONLY); HardwareVertexBufferSharedPtr binormalHardwareBuffer = vertexBinding.getBuffer(binormalElement.getSource()); int binormalVertexSize = binormalHardwareBuffer.Value.getVertexSize().ToInt32(); byte *binormalBuffer = (byte *)binormalHardwareBuffer.Value.lockBuf(HardwareBuffer.LockOptions.HBL_NORMAL); Vector3 *normal; Vector3 *tangent; Vector3 *binormal; for (int i = 0; i < numVertices; ++i) { normalElement.baseVertexPointerToElement(normalBuffer, (float **)&normal); tangentElement.baseVertexPointerToElement(tangentBuffer, (float **)&tangent); binormalElement.baseVertexPointerToElement(binormalBuffer, (float **)&binormal); *binormal = normal->cross(ref *tangent) * -1.0f; normalBuffer += normalVertexSize; tangentBuffer += tangetVertexSize; binormalBuffer += binormalVertexSize; } normalHardwareBuffer.Value.unlock(); tangentHardwareBuffer.Value.unlock(); binormalHardwareBuffer.Value.unlock(); normalHardwareBuffer.Dispose(); tangentHardwareBuffer.Dispose(); binormalHardwareBuffer.Dispose(); } }
protected void processPlane(XmlElement XMLNode, SceneNode pParent) { string name = getAttrib(XMLNode, "name"); float distance = getAttribReal(XMLNode, "distance"); float width = getAttribReal(XMLNode, "width"); float height = getAttribReal(XMLNode, "height"); int xSegments = (int)getAttribReal(XMLNode, "xSegments"); int ySegments = (int)getAttribReal(XMLNode, "ySegments"); int numTexCoordSets = (int)getAttribReal(XMLNode, "numTexCoordSets"); float uTile = getAttribReal(XMLNode, "uTile"); float vTile = getAttribReal(XMLNode, "vTile"); string material = getAttrib(XMLNode, "material"); bool normals = getAttribBool(XMLNode, "normals"); bool movablePlane = getAttribBool(XMLNode, "movablePlane"); bool castShadows = getAttribBool(XMLNode, "castShadows"); bool receiveShadows = getAttribBool(XMLNode, "receiveShadows"); Vector3 normal = Vector3.ZERO; XmlElement pElement = (XmlElement)XMLNode.SelectSingleNode("normal"); if (pElement != null) { normal = parseVector3(pElement); } Vector3 upVector = Vector3.UNIT_Y; pElement = (XmlElement)XMLNode.SelectSingleNode("upVector"); if (pElement != null) { upVector = parseVector3(pElement); } Plane pPlane = new Plane(normal, upVector); Entity pEntity = null; try { MeshPtr ptr = MeshManager.Singleton.CreatePlane(name, m_sGroupName, pPlane, width, height, xSegments, ySegments, normals, (ushort)numTexCoordSets, uTile, vTile, upVector); pEntity = mSceneMgr.CreateEntity(name, name); pParent.AttachObject(pEntity); } catch (Exception e) { LogManager.Singleton.LogMessage("[DotSceneLoader] Error loading an entity!" + e.Message); } }
public void Load() { plane = new Plane(Vector3.UNIT_X, 0); MeshPtr groundMeshPtr = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, grounXSegs, grounZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Y); groundEntity = mSceneMgr.CreateEntity("wall"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Floor"); groundEntity.GetMesh().BuildEdgeList(); groundNode.Position = new Vector3(-2000, 350, 0); plane2 = new Plane(Vector3.UNIT_X, 0); MeshPtr groundMeshPtr2 = MeshManager.Singleton.CreatePlane("wall1", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, grounXSegs, grounZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Y); groundEntity = mSceneMgr.CreateEntity("wall1"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Floor"); groundEntity.GetMesh().BuildEdgeList(); groundNode.Position = new Vector3(2000, 350, 0); groundNode.Yaw(3.14f); plane3 = new Plane(Vector3.UNIT_X, 0); MeshPtr groundMeshPtr3 = MeshManager.Singleton.CreatePlane("wall2", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, grounXSegs, grounZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Y); groundEntity = mSceneMgr.CreateEntity("wall2"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Floor"); groundEntity.GetMesh().BuildEdgeList(); groundNode.Position = new Vector3(0, 350, 1996); groundNode.Yaw(1.57f); plane4 = new Plane(Vector3.UNIT_X, 0); MeshPtr groundMeshPtr4 = MeshManager.Singleton.CreatePlane("wall3", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, grounXSegs, grounZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Y); groundEntity = mSceneMgr.CreateEntity("wall3"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Floor"); groundEntity.GetMesh().BuildEdgeList(); groundNode.Position = new Vector3(0, 350, -1996); groundNode.Yaw(-1.57f); }
public static ConvexHullShape ConvertToHull(MeshPtr mesh, Vector3 pos, Quaternion orientation, Vector3 scale) { Launch.Log("[Loading] Converting " + mesh.Name + " to a BulletSharp.ConvexHull"); uint vertex_count = default(uint); Vector3[] vertices = default(Vector3[]); uint index_count = default(uint); uint[] indices = default(uint[]); GetMeshInformation(mesh, ref vertex_count, ref vertices, ref index_count, ref indices, pos, orientation, scale); ConvexHullShape hull = new ConvexHullShape(vertices.Distinct().ToArray()); return hull; }
/// <summary> /// This method generates a plane in an Entity which will be used as a wall /// </summary> private void WallPlane3() { plane3 = new Plane(Vector3.UNIT_Z, -0); MeshPtr wallMeshPtr = MeshManager.Singleton.CreatePlane("wall3", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane3, wallWidth, wallHeight, wallXSegs, wallZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_X); wallEntity3 = mSceneMgr.CreateEntity("wall3"); wallNode3 = mSceneMgr.CreateSceneNode(); wallNode3.Translate(new Vector3(000, 000, -500)); wallNode3.AttachObject(wallEntity3); mSceneMgr.RootSceneNode.AddChild(wallNode3); //wallEntity.SetMaterialName("Meteor"); }
private void Initiliase(MeshPtr meshPtr, bool autodispose_meshPtr, Vector3 scale, Quaternion qua, Vector3 pos, bool readtextcroodnitas) { this._scale = scale; //this._meshPtr = meshPtr; this.meshName = meshPtr.Name; this.opType = meshPtr.GetSubMesh(0).operationType; this._readTextureCoordinate = readtextcroodnitas; this._quaoffset = qua; this._posoffset = pos; PrepareBuffers(meshPtr); ReadData(meshPtr); if (autodispose_meshPtr) { meshPtr.Dispose(); meshPtr = null; } }
// //ORIGINAL LINE: Ogre::MeshPtr realizeMesh(const string& name = "", const Ogre::String& group = "General") public MeshPtr realizeMesh(string name, string group) { TriangleBuffer tbuffer = new TriangleBuffer(); addToTriangleBuffer(ref tbuffer); MeshPtr mesh = null;// MeshManager.Singleton.CreateManual(name, group); //new MeshPtr(); if (name == "") { mesh = tbuffer.transformToMesh(Utils.getName("mesh_procedural_"), group); } else { mesh = tbuffer.transformToMesh(name, group); } return(mesh); }
private void CreateWall1() { plane1 = new Plane(Vector3.UNIT_X, -500); //plane = new Plane(Vector3.UNIT_Z, 0); MeshPtr wallMeshPtr = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane1, wallWidth, wallHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_Z); //MeshPtr wallMeshPtrZ = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, planeZ, wallWidth, wallHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_Z); wallEntity1 = mSceneMgr.CreateEntity("wall"); wallNode1 = mSceneMgr.CreateSceneNode(); wallNode1.AttachObject(wallEntity1); wallEntity1.SetMaterialName("Ground"); wallNode1.Rotate(new Quaternion(Mogre.Math.Sqrt(0.5f), -Mogre.Math.Sqrt(0.5f), 0, 0)); // Rotate -90 degrees around X axis wallMainNode.AddChild(wallNode1); }
/// <summary> /// Creates a wall /// </summary> private void SetWall() { wall = new Wall(mSceneMgr); MeshPtr wlptr = wall.getCube("wall", "Wall", 1500, 70, 1500); wallentitiy = mSceneMgr.CreateEntity("wall_entity", "wall"); wallnode = mSceneMgr.RootSceneNode.CreateChildSceneNode("wall_node"); wallnode.AttachObject(wallentitiy); //using (MaterialPtr wallmat = MaterialManager.Singleton.Create("wallMaterial", // ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)) //{ // using(TextureUnitState walltxt = wallmat.GetTechnique(0).GetPass(0).CreateTextureUnitState("Purple.png")) // { // wallentitiy.SetMaterialName("wallMaterial"); // } //} }
public void LoadScene() { IEnumerable <IEntity> renderableEntities = _entityManager.GetEntitiesWithComponents <RenderableComponent>(); renderableEntities.ForEach(SetupRenderableEntity); IEnumerable <IEntity> cameraEntities = _entityManager.GetEntitiesWithComponents <CameraComponent>(); cameraEntities.ForEach(SetupCamera); _entityManager.GetEntities().ForEach(entity => { entity.GetComponents().ForEach(component => { component.OnLoaded(); }); }); if (!_context.IsEditor) { // Set the current Active Camera _entityManager.GetEntitiesWithComponents <CameraComponent>().ForEach(entity => { CameraComponent cameraComponent = entity.GetComponent <CameraComponent>(); if (cameraComponent.ActiveCamera) { var vp = _context.GetRenderWindow().addViewport(cameraComponent.Camera); vp.setBackgroundColour(new ColourValue(.1f, .3f, .3f)); } }); } MeshPtr meshPtr = MeshManager.getSingleton().createPlane("background", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, new Plane(VectorUtils.Vector3.UNIT_Y, 0f), 800, 600, 4, 4, true, 1, 4, 4, VectorUtils.Vector3.UNIT_Z); var floorEnt = _sceneManager.createEntity("background", "background"); floorEnt.setMaterial(MaterialManager.getSingleton().getByName("Color_009")); var floorNode = _sceneManager.getRootSceneNode().createChildSceneNode(); floorNode.setPosition(new Vector3(0f, -3f, 0f)); floorNode.attachObject(floorEnt); meshPtr.Dispose(); }
public MeshPtr buildMesh(string name, string group) { System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(name)); if (string.IsNullOrEmpty(name)) { name = Utils.getName("debugrender_procedural"); } //SceneManager sceneMgr = Root.Singleton.GetSceneManagerIterator().Current; Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator(); item.MoveNext(); Mogre.SceneManager sceneMgr = item.Current; item.Dispose(); ManualObject mo = buildManualObject(); MeshPtr mesh = mo.ConvertToMesh(name, group); sceneMgr.DestroyManualObject(mo); return(mesh); }
public void CreateWall3() { plane3 = new Plane(Vector3.UNIT_Z, -500); MeshPtr wallMeshPtr = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane3, wallWidth, wallHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_X); wallEntity3 = mSceneMgr.CreateEntity("wall"); wallNode3 = mSceneMgr.CreateSceneNode(); wallNode3.AttachObject(wallEntity3); wallEntity3.SetMaterialName("Ground"); wallNode3.SetPosition(0, 0, 0); wallNode3.Rotate(new Quaternion(Mogre.Math.Sqrt(0.5f), 0, Mogre.Math.Sqrt(0.5f), 0)); wallNode3.Rotate(new Quaternion(Mogre.Math.Sqrt(0.5f), Mogre.Math.Sqrt(0.5f), 0, 0)); //wallNode3.SetPosition(500, 0, 0); wallMainNode.AddChild(wallNode3); }
public void removeBinormals() { //This code makes the editor crash and is currently not being called. Being left for reference. using (MeshPtr mesh = entity.getMesh()) { SubMesh subMesh = mesh.Value.getSubMesh(0); VertexData vertexData = subMesh.vertexData; VertexDeclaration vertexDeclaration = vertexData.vertexDeclaration; //VertexBufferBinding vertexBinding = vertexData.vertexBufferBinding; //VertexElement normalElement = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_NORMAL); //VertexElement tangentElement = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_TANGENT); VertexElement binormalElement = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_BINORMAL); if (binormalElement != null) { vertexDeclaration.removeElement(VertexElementSemantic.VES_BINORMAL); vertexData.reorganizeBuffers(vertexDeclaration); } } Log.Info("Binormals Removed"); }
public MeshBuilderHelper(String name, String resourcegroup, bool usesharedvertices, uint vertexstart, uint vertexcount) { mName = name; mResourceGroup = resourcegroup; mVertextStart = vertexstart; mVertexCount = vertexcount; if (MeshManager.Singleton.ResourceExists(name)) throw (new ArgumentNullException("mesh name already used")); mMeshPtr = MeshManager.Singleton.CreateManual(mName, mResourceGroup); mSubMesh = mMeshPtr.CreateSubMesh(); mSubMesh.useSharedVertices = usesharedvertices; mSubMesh.vertexData = new VertexData(); mSubMesh.vertexData.vertexStart = mVertextStart; mSubMesh.vertexData.vertexCount = mVertexCount; offset = 0; mIndexType = HardwareIndexBuffer.IndexType.IT_16BIT; }
public void CreateWall2() { plane2 = new Plane(Vector3.NEGATIVE_UNIT_X, -500); MeshPtr wallMeshPtr = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane2, wallWidth, wallHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_Z); wallEntity2 = mSceneMgr.CreateEntity("wall"); wallNode2 = mSceneMgr.CreateSceneNode(); wallNode2.AttachObject(wallEntity2); wallEntity2.SetMaterialName("Ground"); wallNode2.SetPosition(0, 0, 0); wallNode2.Rotate(new Quaternion(0, 0, 0, Mogre.Math.Sqrt(0.5f))); //wallNode2.Rotate(new Quaternion(0, 0, Mogre.Math.Sqrt(0.5f), 0)); // Rotate -90 degrees around X axis wallNode2.Rotate(new Quaternion(Mogre.Math.Sqrt(0.5f), Mogre.Math.Sqrt(0.5f), 0, 0)); //wallNode2.Rotate(new Quaternion(Mogre.Math.Sqrt(0.5f), 0, Mogre.Math.Sqrt(0.5f), 0));//wallNode2.Rotate(new Quaternion(1, -Mogre.Math.Sqrt(0.5f), 0, 0)); // Rotate -90 degrees around X axis wallMainNode.AddChild(wallNode2); }
public void setSkeleton(Entity entity) { SkeletonInstance skeleton = entity.getSkeleton(); skeletonTree.Nodes.clear(); for (ushort i = 0; i < skeleton.getNumBones(); i++) { Bone bone = skeleton.getBone(i); TreeNode skeletonNode = new TreeNode(bone.getName()); skeletonNode.UserData = bone; TreeNode positionNode = new TreeNode("Position " + bone.getPosition()); skeletonNode.Children.add(positionNode); TreeNode rotationNode = new TreeNode("Rotation" + bone.getOrientation()); skeletonNode.Children.add(rotationNode); skeletonTree.Nodes.add(skeletonNode); } using (MeshPtr mesh = entity.getMesh()) { mesh.Value._updateCompiledBoneAssignments(); if (mesh.Value.SharedVertexData != null) { //Logging.Log.Debug("Shared Bone Assignments {0}", mesh.Value.SharedBoneAssignmentCount); } else { ushort numSubMeshes = mesh.Value.getNumSubMeshes(); for (ushort i = 0; i < numSubMeshes; ++i) { SubMesh subMesh = mesh.Value.getSubMesh(i); VertexData vertexData = subMesh.vertexData; VertexDeclaration vertexDeclaration = vertexData.vertexDeclaration; VertexElement elem = vertexDeclaration.findElementBySemantic(VertexElementSemantic.VES_BLEND_WEIGHTS); if (elem != null) { Logging.Log.Debug("Sub Mesh {0} Bone Assignments {1}", i, VertexElement.getTypeCount(elem.getType())); } } } } skeletonTree.layout(); }
private void delPluginSphere(string pluginName) { OgreWindow.Instance.pause(); try { MaterialPtr ptrMat = MaterialManager.Singleton.GetByName(sphereNamePrefix + "_SphereMaterial_" + pluginName); ptrMat.Unload(); MaterialManager.Singleton.Remove(ptrMat.Handle); ptrMat.Dispose(); MeshPtr ptrMesh = MeshManager.Singleton.GetByName(sphereNamePrefix + "_SphereMesh_" + pluginName); ptrMesh.Unload(); MeshManager.Singleton.Remove(ptrMesh.Handle); ptrMesh.Dispose(); OgreWindow.Instance.mSceneMgr.DestroyEntity(sphereNamePrefix + "_SphereEntity_" + pluginName); OgreWindow.Instance.mSceneMgr.DestroySceneNode(sphereNamePrefix + "_SphereSceneNode_" + pluginName); } catch (Exception ex) { log("error deleting plugin sphere: " + ex.ToString()); } OgreWindow.Instance.unpause(); }
/// <summary> /// Constructor /// </summary> /// <param name="mSceneMgr">A reference of the scene manager</param> public Ground(SceneManager mSceneMgr) { this.mSceneMgr = mSceneMgr; groundWidth = 2000; groundHeight = 2000; plane = new Plane(Vector3.UNIT_Y, -10); groundMeshPtr = MeshManager.Singleton.CreatePlane("floor", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, 100, 100, true, 0, 10, 10, Vector3.UNIT_Z); //Console.WriteLine(groundMeshPtr.) GroundMaterial(); groundEntity = mSceneMgr.CreateEntity("floor"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Ground"); //this.plane = new Plane(Vector3.UNIT_Y, 0); }
/// <summary> /// Give it a mesh and it'll create a BulletSharp.TriangleMesh out of it /// </summary> /// <param name="mesh">The mesh you're converting</param> /// <returns>A bullet trimesh</returns> public static TriangleMesh Convert(MeshPtr mesh, Vector3 pos, Quaternion orientation, Vector3 scale) { // get our two main objects TriangleMesh BulletMesh = new TriangleMesh(true, false); Launch.Log("[Loading] Converting " + mesh.Name + " to a BulletSharp.TriangleMesh"); uint vertex_count = default(uint); Vector3[] vertices = default(Vector3[]); uint index_count = default(uint); uint[] indices = default(uint[]); GetMeshInformation(mesh, ref vertex_count, ref vertices, ref index_count, ref indices, pos, orientation, scale); BulletMesh.PreallocateIndexes((int) index_count); BulletMesh.PreallocateVertices((int) vertex_count); //BulletMesh.WeldingThreshold = 0.1f; for (int a = 0; a < index_count; a += 3) { BulletMesh.AddTriangle(vertices[indices[a]], vertices[indices[a + 1]], vertices[indices[a + 2]], true); } return BulletMesh; }
public OgreMeshData(MeshPtr meshPtr,bool autodispose_meshPtr, float unitScale) { Initiliase(meshPtr,autodispose_meshPtr, Vector3.UNIT_SCALE * unitScale); }
// Get the mesh information for the given mesh. // Code found on this forum link: http://www.ogre3d.org/wiki/index.php/RetrieveVertexData private static unsafe void GetMeshInformation(MeshPtr mesh, out Vector3[] vertices, out int[] indices, Vector3 position, Quaternion orient, Vector3 scale) { bool addedShared = false; int currentOffset = 0, sharedOffset = 0, nextOffset = 0, indexOffset = 0; int vertexCount = 0, indexCount = 0; // Calculate how many vertices and indices we're going to need for (ushort i = 0; i < mesh.NumSubMeshes; ++i) { SubMesh submesh = mesh.GetSubMesh(i); // We only need to add the shared vertices once if (submesh.useSharedVertices) { if (!addedShared) { vertexCount += (int)mesh.sharedVertexData.vertexCount; addedShared = true; } } else { vertexCount += (int)submesh.vertexData.vertexCount; } // Add the indices indexCount += (int)submesh.indexData.indexCount; } // Allocate space for the vertices and indices vertices = new Vector3[vertexCount]; indices = new int[indexCount]; addedShared = false; // Run through the submeshes again, adding the data into the arrays for (ushort i = 0; i < mesh.NumSubMeshes; ++i) { SubMesh submesh = mesh.GetSubMesh(i); VertexData vertexData = submesh.useSharedVertices ? mesh.sharedVertexData : submesh.vertexData; if ((!submesh.useSharedVertices) || (submesh.useSharedVertices && !addedShared)) { if (submesh.useSharedVertices) { addedShared = true; sharedOffset = currentOffset; } VertexElement posElem = vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION); System.Diagnostics.Debug.Assert(posElem.Type == VertexElementType.VET_FLOAT3); using (HardwareVertexBufferSharedPtr vbuf = vertexData.vertexBufferBinding.GetBuffer(posElem.Source)) { byte* vertex = (byte*)vbuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY); float* preal; for (uint j = 0; j < vertexData.vertexCount; ++j, vertex += vbuf.VertexSize) { posElem.BaseVertexPointerToElement(vertex, &preal); Vector3 pt = new Vector3(preal[0], preal[1], preal[2]); vertices[currentOffset + j] = (orient * (pt * scale)) + position; } vbuf.Unlock(); } nextOffset += (int)vertexData.vertexCount; } IndexData indexData = submesh.indexData; using (HardwareIndexBufferSharedPtr ibuf = indexData.indexBuffer) { bool use32bitindexes = ibuf.Type == HardwareIndexBuffer.IndexType.IT_32BIT; int* plong = (int*)ibuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY); ushort* pshort = (ushort*)plong; int offset = submesh.useSharedVertices ? sharedOffset : currentOffset; if (use32bitindexes) { for (uint k = 0; k < indexData.indexCount; ++k) { indices[indexOffset++] = plong[k] + offset; } } else { for (uint k = 0; k < indexData.indexCount; ++k) { indices[indexOffset++] = pshort[k] + offset; } } ibuf.Unlock(); } currentOffset = nextOffset; } }
public OgreMeshData(MeshPtr meshPtr, bool autodispose_meshPtr, Vector3 scale) { Initiliase(meshPtr,autodispose_meshPtr, scale); }
private bool CheckSubMeshOpType(MeshPtr mesh, RenderOperation.OperationTypes opType) { for (ushort i = 0; i < mesh.NumSubMeshes; i++) { if (mesh.GetSubMesh(i).operationType != opType) { return false; } } return true; }
public Boolean Contains(MeshPtr a) { foreach (MeshPtr tex in allMeshes) { if (tex.Name == a.Name) { return true; } } return false; }
public OgreMeshData(MeshPtr meshPtr, bool autodispose_meshPtr, Vector3 scale, Quaternion qua, Vector3 pos, bool readtexturecoord) { Initiliase(meshPtr,autodispose_meshPtr, scale, qua,pos, readtexturecoord); }
private void ReadData(MeshPtr _meshPtr) { int indexOffset = 0; uint vertexOffset = 0; // read the index and vertex data from the mesh for (ushort i = 0; i < _meshPtr.NumSubMeshes; i++) { SubMesh subMesh = _meshPtr.GetSubMesh(i); //index int indexOffset2 = ReadIndexData(indexOffset, vertexOffset, subMesh.indexData); _index_Submesh.Add(i, new KeyValuePair<uint, uint>((uint)indexOffset, (uint)indexOffset2)); indexOffset = indexOffset2; //vertex if (subMesh.useSharedVertices == false) { vertexOffset = ReadVertexData(vertexOffset, subMesh.vertexData); } } // add the shared vertex data if (_meshPtr.sharedVertexData != null) { vertexOffset = ReadVertexData(vertexOffset, _meshPtr.sharedVertexData); } }
public StaticMeshData(MeshPtr meshPtr, float unitScale) { Initiliase(meshPtr, Mogre.Vector3.UNIT_SCALE * unitScale); }
public StaticMeshData(MeshPtr meshPtr, Mogre.Vector3 scale) { Initiliase(meshPtr, scale); }
public StaticMeshData(MeshPtr meshPtr) { Initiliase(meshPtr, Mogre.Vector3.UNIT_SCALE); }
private void Initiliase(MeshPtr meshPtr, Mogre.Vector3 scale) { this.scale = scale; this.meshPtr = meshPtr; PrepareBuffers(); ReadData(); }
private void Initiliase(MeshPtr meshPtr, bool autodispose_meshPtr, Vector3 scale) { Initiliase(meshPtr,autodispose_meshPtr, scale, Quaternion.IDENTITY,Vector3.ZERO,false); }
public static unsafe void GetMeshInformation(MeshPtr mesh, ref uint vertex_count, ref Vector3[] vertices, ref uint index_count, ref uint[] indices, Vector3 position, Quaternion orientation, Vector3 scale) { bool added_shared = false; uint current_offset = 0; uint shared_offset = 0; uint next_offset = 0; uint index_offset = 0; vertex_count = index_count = 0; for (ushort i = 0; i < mesh.NumSubMeshes; ++i) { SubMesh submesh = mesh.GetSubMesh(i); if (submesh.useSharedVertices) { if (!added_shared) { vertex_count += mesh.sharedVertexData.vertexCount; added_shared = true; } } else { vertex_count += submesh.vertexData.vertexCount; } index_count += submesh.indexData.indexCount; } vertices = new Vector3[vertex_count]; indices = new uint[index_count]; added_shared = false; for (ushort i = 0; i < mesh.NumSubMeshes; ++i) { SubMesh submesh = mesh.GetSubMesh(i); VertexData vertex_data = submesh.useSharedVertices ? mesh.sharedVertexData : submesh.vertexData; if (!submesh.useSharedVertices || (submesh.useSharedVertices && !added_shared)) { if (submesh.useSharedVertices) { added_shared = true; shared_offset = current_offset; } VertexElement posElem = vertex_data.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION); HardwareVertexBufferSharedPtr vbuf = vertex_data.vertexBufferBinding.GetBuffer(posElem.Source); byte* vertex = (byte*) vbuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY); float* pReal; for (int j = 0; j < vertex_data.vertexCount; ++j, vertex += vbuf.VertexSize) { posElem.BaseVertexPointerToElement(vertex, &pReal); Vector3 pt = new Vector3(pReal[0], pReal[1], pReal[2]); vertices[current_offset + j] = (orientation * (pt * scale)) + position; } vbuf.Unlock(); vbuf.Dispose(); next_offset += vertex_data.vertexCount; } IndexData index_data = submesh.indexData; uint numTris = index_data.indexCount / 3; HardwareIndexBufferSharedPtr ibuf = index_data.indexBuffer; bool use32bitindexes = (ibuf.Type == HardwareIndexBuffer.IndexType.IT_32BIT); uint* pLong = (uint*) ibuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY); ushort* pShort = (ushort*) pLong; uint offset = submesh.useSharedVertices ? shared_offset : current_offset; if (use32bitindexes) { for (int k = 0; k < index_data.indexCount; ++k) { indices[index_offset++] = pLong[k] + offset; } } else { for (int k = 0; k < index_data.indexCount; ++k) { indices[index_offset++] = (uint) pShort[k] + (uint) offset; } } ibuf.Unlock(); ibuf.Dispose(); current_offset = next_offset; } }
public OgreMeshData(MeshPtr meshPtr, bool autodispose_meshPtr, Vector3 scale, bool readtexturecoord) { Initiliase(meshPtr,autodispose_meshPtr, scale, this._quaoffset,this._posoffset, readtexturecoord); }
private void PrepareBuffers(MeshPtr _meshPtr) { uint indexCount = 0; uint vertexCount = 0; // Add any shared vertices if (_meshPtr.sharedVertexData != null) vertexCount = _meshPtr.sharedVertexData.vertexCount; // Calculate the number of vertices and indices in the sub meshes for (ushort i = 0; i < _meshPtr.NumSubMeshes; i++) { SubMesh subMesh = _meshPtr.GetSubMesh(i); // we have already counted the vertices that are shared if (subMesh.useSharedVertices == false) vertexCount += subMesh.vertexData.vertexCount; indexCount += subMesh.indexData.indexCount; } // Allocate space for the vertices and indices _vertices = new Vector3[vertexCount]; _indices = new uint[indexCount]; _index_Submesh = new Dictionary<uint, KeyValuePair<uint, uint>>(); if (_readTextureCoordinate) { _textureCroodnitas = new Vector2[vertexCount]; } }
public OgreMeshData(MeshPtr meshPtr, bool autodispose_meshPtr) { Initiliase(meshPtr, autodispose_meshPtr,Vector3.UNIT_SCALE); }
public unsafe void GetSubMeshInformation(MeshPtr mesh, ref uint vertex_count, ref Mogre.Vector3[] vertices, ref uint index_count, ref UInt64[] indices, Mogre.Vector3 position, Quaternion orientation, Mogre.Vector3 scale, ushort subMeshIndex) { bool added_shared = false; uint current_offset = 0; uint shared_offset = 0; uint next_offset = 0; uint index_offset = 0; vertex_count = index_count = 0; SubMesh submesh = mesh.GetSubMesh(subMeshIndex); // We only need to add the shared vertices once if (submesh.useSharedVertices) { if (!added_shared) { vertex_count += mesh.sharedVertexData.vertexCount; added_shared = true; } } else { vertex_count += submesh.vertexData.vertexCount; } // Add the indices index_count += submesh.indexData.indexCount; // Allocate space for the vertices and indices vertices = new Mogre.Vector3[vertex_count]; indices = new UInt64[index_count]; added_shared = false; // Run through the submesh again, adding the data into the arrays VertexData vertex_data = submesh.useSharedVertices ? mesh.sharedVertexData : submesh.vertexData; if (!submesh.useSharedVertices || (submesh.useSharedVertices && !added_shared)) { if (submesh.useSharedVertices) { added_shared = true; shared_offset = current_offset; } VertexElement posElem = vertex_data.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION); HardwareVertexBufferSharedPtr vbuf = vertex_data.vertexBufferBinding.GetBuffer(posElem.Source); byte* vertex = (byte*)vbuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY); float* pReal; // There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double // as second argument. So make it float, to avoid trouble when Ogre::Real will // be comiled/typedefed as double: // Ogre::Real* pReal; for (int j = 0; j < vertex_data.vertexCount; ++j, vertex += vbuf.VertexSize) { posElem.BaseVertexPointerToElement(vertex, &pReal); Mogre.Vector3 pt = new Mogre.Vector3(pReal[0], pReal[1], pReal[2]); vertices[current_offset + j] = (orientation * (pt * scale)) + position; } // |!| Important: VertexBuffer Unlock() + Dispose() avoids memory corruption vbuf.Unlock(); vbuf.Dispose(); next_offset += vertex_data.vertexCount; } IndexData index_data = submesh.indexData; uint numTris = index_data.indexCount / 3; HardwareIndexBufferSharedPtr ibuf = index_data.indexBuffer; // UNPORTED line of C++ code (because ibuf.IsNull() doesn't exist in C#) // if( ibuf.isNull() ) continue // need to check if index buffer is valid (which will be not if the mesh doesn't have triangles like a pointcloud) bool use32bitindexes = (ibuf.Type == HardwareIndexBuffer.IndexType.IT_32BIT); uint* pLong = (uint*)ibuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY); ushort* pShort = (ushort*)pLong; uint offset = submesh.useSharedVertices ? shared_offset : current_offset; if (use32bitindexes) { for (int k = 0; k < index_data.indexCount; ++k) indices[index_offset++] = (UInt64)pLong[k] + (UInt64)offset; } else { for (int k = 0; k < index_data.indexCount; ++k) indices[index_offset++] = (UInt64)pShort[k] + (UInt64)offset; } // |!| Important: IndexBuffer Unlock() + Dispose() avoids memory corruption ibuf.Unlock(); ibuf.Dispose(); current_offset = next_offset; // |!| Important: MeshPtr Dispose() avoids memory corruption mesh.Dispose(); // This dispose the MeshPtr, not the Mesh }