// //ORIGINAL LINE: Ogre::MeshPtr transformToMesh(const string& name, const Ogre::String& group = "General") const // public MeshPtr transformToMesh(string name, string group) { //Mogre.SceneManager sceneMgr = Root.Singleton.GetSceneManagerIterator().Current; Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator(); item.MoveNext(); Mogre.SceneManager sceneMgr = item.Current; item.Dispose(); Mogre.ManualObject manual = sceneMgr.CreateManualObject(name); manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); foreach (var it in mVertices) { manual.Position(it.mPosition); manual.TextureCoord(it.mUV); manual.Normal(it.mNormal); } foreach (var it in mIndices) { manual.Index((ushort)it); } manual.End(); Mogre.MeshPtr mesh = manual.ConvertToMesh(name, group); sceneMgr.DestroyManualObject(manual); return(mesh); }
ManualObject chunkMesh(Chunk c) { Mogre.ManualObject MeshChunk = mSceneMgr.CreateManualObject("MeshManChunk" + c.x + "_" + c.z); MeshChunk.Begin("BoxColor", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); uint iVertex = 0; Block Block; Block Block1; float bo = 1f / 16f; //Console.WriteLine(bo); float U1, U2, V1, V2; for (int z = 0; z < 16; ++z) { for (int y = 0; y < 256; ++y) { for (int x = 0; x < 16; ++x) { Block = c.blocks[x, y, z]; if (Block == null) { continue; } if (Block.ID == 0) { continue; } //Compute the block's texture coordinates U1 = bo * (float)(Block.U()); U2 = U1 + bo; V1 = bo * (float)(Block.V()); V2 = V1 + bo; //x-1 Block1 = new Block(x, y, z, 0, 0); if (x > 0) { Block1 = c.blocks[x - 1, y, z]; } //if (x == 0) Block1 = chunks[(c.x - 1) + "_" + c.z].blocks[15, y, z]; if (Block1.ID == 0) { MeshChunk.Position(x, y, z + 1); MeshChunk.Normal(-1, 0, 0); MeshChunk.TextureCoord(U2, V2); MeshChunk.Position(x, y + 1, z + 1); MeshChunk.Normal(-1, 0, 0); MeshChunk.TextureCoord(U2, V1); MeshChunk.Position(x, y + 1, z); MeshChunk.Normal(-1, 0, 0); MeshChunk.TextureCoord(U1, V1); MeshChunk.Position(x, y, z); MeshChunk.Normal(-1, 0, 0); MeshChunk.TextureCoord(U1, V2); //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2); //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex); MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //x+1 Block1 = new Block(x, y, z, 0, 0); if (x < 15) { Block1 = c.blocks[x + 1, y, z]; } //if (x == 15) Block1 = chunks[(c.x + 1) + "_" + c.z].blocks[0, y, z]; if (Block1.ID == 0) { MeshChunk.Position(x + 1, y, z); MeshChunk.Normal(1, 0, 0); MeshChunk.TextureCoord(U2, V2); MeshChunk.Position(x + 1, y + 1, z); MeshChunk.Normal(1, 0, 0); MeshChunk.TextureCoord(U2, V1); MeshChunk.Position(x + 1, y + 1, z + 1); MeshChunk.Normal(1, 0, 0); MeshChunk.TextureCoord(U1, V1); MeshChunk.Position(x + 1, y, z + 1); MeshChunk.Normal(1, 0, 0); MeshChunk.TextureCoord(U1, V2); //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2); //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex); MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //y-1 Block1 = new Block(x, y, z, 0, 0); if (y > 0) { Block1 = c.blocks[x, y - 1, z]; } //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0); if (Block1.ID == 0) { MeshChunk.Position(x, y, z); MeshChunk.Normal(0, -1, 0); MeshChunk.TextureCoord(U1, V2); MeshChunk.Position(x + 1, y, z); MeshChunk.Normal(0, -1, 0); MeshChunk.TextureCoord(U2, V2); MeshChunk.Position(x + 1, y, z + 1); MeshChunk.Normal(0, -1, 0); MeshChunk.TextureCoord(U2, V1); MeshChunk.Position(x, y, z + 1); MeshChunk.Normal(0, -1, 0); MeshChunk.TextureCoord(U1, V1); //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2); //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex); MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //y+1 Block1 = new Block(x, y, z, 0, 0); if (y < 256 - 1) { Block1 = c.blocks[x, y + 1, z]; } //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0); if (Block1.ID == 0) { MeshChunk.Position(x, y + 1, z + 1); MeshChunk.Normal(0, 1, 0); MeshChunk.TextureCoord(U1, V2); MeshChunk.Position(x + 1, y + 1, z + 1); MeshChunk.Normal(0, 1, 0); MeshChunk.TextureCoord(U2, V2); MeshChunk.Position(x + 1, y + 1, z); MeshChunk.Normal(0, 1, 0); MeshChunk.TextureCoord(U2, V1); MeshChunk.Position(x, y + 1, z); MeshChunk.Normal(0, 1, 0); MeshChunk.TextureCoord(U1, V1); //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2); //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex); MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //z-1 Block1 = new Block(x, y, z, 0, 0); if (z > 0) { Block1 = c.blocks[x, y, z - 1]; } //if (x == 0) Block1 = chunks[c.x + "_" + (c.z - 1)].blocks[x, y, 15]; //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0); if (Block1.ID == 0) { MeshChunk.Position(x, y + 1, z); MeshChunk.Normal(0, 0, -1); MeshChunk.TextureCoord(U2, V1); MeshChunk.Position(x + 1, y + 1, z); MeshChunk.Normal(0, 0, -1); MeshChunk.TextureCoord(U1, V1); MeshChunk.Position(x + 1, y, z); MeshChunk.Normal(0, 0, -1); MeshChunk.TextureCoord(U1, V2); MeshChunk.Position(x, y, z); MeshChunk.Normal(0, 0, -1); MeshChunk.TextureCoord(U2, V2); //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2); //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex); MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //z+1 Block1 = new Block(x, y, z, 0, 0); if (z < 15) { Block1 = c.blocks[x, y, z + 1]; } //if (x == 15) Block1 = chunks[c.x+"_"+(c.z + 1)].blocks[x, y, 0]; //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0); if (Block1.ID == 0) { MeshChunk.Position(x, y, z + 1); MeshChunk.Normal(0, 0, 1); MeshChunk.TextureCoord(U1, V2); MeshChunk.Position(x + 1, y, z + 1); MeshChunk.Normal(0, 0, 1); MeshChunk.TextureCoord(U2, V2); MeshChunk.Position(x + 1, y + 1, z + 1); MeshChunk.Normal(0, 0, 1); MeshChunk.TextureCoord(U2, V1); MeshChunk.Position(x, y + 1, z + 1); MeshChunk.Normal(0, 0, 1); MeshChunk.TextureCoord(U1, V1); //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2); //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex); MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } } } } MeshChunk.End(); return(MeshChunk); }