protected override void destroy() { if (mesh != null) { mesh.Dispose(); } AnimationManipulatorController.removeAnimationManipulator(this); }
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; } }
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(); }
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(); }
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 }