public MeshPtr LoadStaticBrfMeshIntoOgre(SceneManager sceneManager, MBBrfMesh brfMesh, int frame = 0) { //Convert Vertex and Faces to Ogre Mesh Format if (brfMesh == null) { return(null); } if (meshes.ContainsKey(brfMesh.Name)) { return(meshes[brfMesh.Name]); } ManualObject mo = sceneManager.CreateManualObject(brfMesh.Name + "-" + Guid.NewGuid().ToString()); mo.Begin(brfMesh.Material); int np = 0, nv = 0; for (int i = 0; i < brfMesh.Frames[frame].pos.Count; i++) { mo.Position( brfMesh.Frames[frame].pos[i].x, brfMesh.Frames[frame].pos[i].y, brfMesh.Frames[frame].pos[i].z ); np++; } for (int i = 0; i < brfMesh.Frames[frame].norm.Count; i++) { mo.Normal( -brfMesh.Frames[frame].norm[i].x, brfMesh.Frames[frame].norm[i].y, brfMesh.Frames[frame].norm[i].z ); mo.TextureCoord( brfMesh.Vertex[i].ta.X, brfMesh.Vertex[i].ta.Y ); nv++; } for (int i = 0; i < brfMesh.Faces.Count; i++) { for (int j = 0; j < 3; j++) { mo.Triangle( (uint)(brfMesh.Vertex[brfMesh.Faces[i].index[j]].index + 1 + cp), (uint)(brfMesh.Faces[i].index[j] + 1 + cv), (uint)(brfMesh.Faces[i].index[j] + 1 + cv) ); } } mo.End(); cp += np; cv += nv; return(mo.ConvertToMesh(brfMesh.Name + "-" + Guid.NewGuid().ToString())); }
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); } }
/* * @param the block's location */ public void addBlock(Vector3 loc, BlockFace face) { Vector3 displayCoord = this.mWorld.getDisplayCoords(this.mIsland.getPosition(), loc); for (int i = 0; i < 4; i++) { block.Position(displayCoord + getBlockPointsCoord((int)face * 4 + i)); block.TextureCoord(getTextureCoord((int)face * 4 + i)); block.Normal(this.getNormals((int)face)); this.faceNumber++; } block.Quad((uint)this.faceNumber - 4, (uint)this.faceNumber - 3, (uint)this.faceNumber - 2, (uint)this.faceNumber - 1); }
// creates a simple box with specified material public static MovableObject MakeBox(SceneManager mgr, String materialName, Vector3 dims, Vector2 coord) { ManualObject mo = mgr.CreateManualObject(); mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); float w = dims.x * 0.5f; float h = dims.y * 0.5f; float d = dims.z * 0.5f; Vector3[] norm = { new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f) }; Vector3[] geom = // 6 faces x 4 vertexes { new Vector3(+w, -h, +d), new Vector3(+w, -h, -d), new Vector3(+w, +h, -d), new Vector3(+w, +h, +d), new Vector3(+w, +h, +d), new Vector3(+w, +h, -d), new Vector3(-w, +h, -d), new Vector3(-w, +h, +d), new Vector3(+w, +h, +d), new Vector3(-w, +h, +d), new Vector3(-w, -h, +d), new Vector3(+w, -h, +d), new Vector3(-w, -h, +d), new Vector3(-w, +h, +d), new Vector3(-w, +h, -d), new Vector3(-w, -h, -d), new Vector3(-w, -h, +d), new Vector3(-w, -h, -d), new Vector3(+w, -h, -d), new Vector3(+w, -h, +d), new Vector3(-w, -h, -d), new Vector3(-w, +h, -d), new Vector3(+w, +h, -d), new Vector3(+w, -h, -d) }; // texcoords Vector2[] uvs = { new Vector2(0, 0), new Vector2(0, coord.y), coord, new Vector2(coord.x, 0) }; for (int i = 0; i < 6; i++) // 6 faces { uint k = (uint)(i * 4); for (int j = 0; j < 4; j++) // 4 verts { mo.Position(geom[k + j]); mo.Normal(norm[i]); mo.TextureCoord(uvs[j]); } mo.Quad(k, k + 1, k + 2, k + 3); } mo.End(); return(mo); }
public static void generateFace() { string defaultMaterial = "Default"; ManualObject block = new ManualObject("frontFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[0]); block.Position(new Vector3(0, Cst.CUBE_SIDE, 0)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[0]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[0]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[0]); block.Quad(3, 2, 1, 0); block.End(); block.ConvertToMesh("frontFace"); block = new ManualObject("underFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[1]); block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[1]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[1]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[1]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("underFace"); block = new ManualObject("rightFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[2]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[2]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[2]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[2]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("rightFace"); block = new ManualObject("upperFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[3]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[3]); block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[3]); block.Position(new Vector3(0, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[3]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("upperFace"); block = new ManualObject("leftFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[4]); block.Position(new Vector3(0, Cst.CUBE_SIDE, 0)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[4]); block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[4]); block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[4]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("leftFace"); block = new ManualObject("backFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[5]); block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[5]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[5]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[5]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("backFace"); }
/// <summary> /// This method contructs the mesh for the cube /// </summary> /// <param name="cubeName"></param> /// <returns>cubeMesh object</returns> public MeshPtr getCube(string cubeName) { // Console.Write("getCube: "+count); manualObj = mSceneMgr.CreateManualObject("manualObjQuad" + count); manualObj.Begin("void", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); // Starts filling the manual object as a triangle list // ---- Vertex Buffer ---- manualObj.Position(new Vector3(30, 30, 0)); // --- Vertex 0 --- manualObj.TextureCoord(new Vector2(0, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, 30, 0)); // --- Vertex 1 --- manualObj.TextureCoord(new Vector2(1, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, -30, 0)); // --- Vertex 2 --- manualObj.TextureCoord(new Vector2(0, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, -30, 0)); // --- Vertex 3 --- manualObj.TextureCoord(new Vector2(1, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, 30, -60)); // --- Vertex 4 --- manualObj.TextureCoord(new Vector2(0, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, -30, -60)); // --- Vertex 5 --- manualObj.TextureCoord(new Vector2(1, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, 30, -60)); // --- Vertex 6 --- manualObj.TextureCoord(new Vector2(0, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, -30, -60)); // --- Vertex 7 --- manualObj.TextureCoord(new Vector2(1, 1)); manualObj.Normal(1, 1, 1); // ---- Index Buffer ---- // --- Triangle 0 --- manualObj.Index(0); manualObj.Index(1); manualObj.Index(2); // --- Triangle 1 --- manualObj.Index(1); manualObj.Index(3); manualObj.Index(2); // --- Triangle 8 --- manualObj.Index(4); manualObj.Index(5); manualObj.Index(6); // --- Triangle 9 --- manualObj.Index(5); manualObj.Index(7); manualObj.Index(6); manualObj.Position(new Vector3(30, 30, -60)); // --- Vertex 8 --- manualObj.TextureCoord(new Vector2(1, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, 30, 0)); // --- Vertex 9 --- manualObj.TextureCoord(new Vector2(0, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, -30, -60)); // --- Vertex 10 --- manualObj.TextureCoord(new Vector2(1, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, -30, 0)); // --- Vertex 11 --- manualObj.TextureCoord(new Vector2(0, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, 30, 0)); // --- Vertex 12 --- manualObj.TextureCoord(new Vector2(0, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, 30, -60)); // --- Vertex 13 --- manualObj.TextureCoord(new Vector2(0, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, -30, 0)); // ---Vertex 14 --- manualObj.TextureCoord(new Vector2(1, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, -30, -60)); // ---Vertex 15 --- manualObj.TextureCoord(new Vector2(1, 1)); manualObj.Normal(1, 1, 1); // ---Triangle 12-- - manualObj.Index(8); manualObj.Index(9); manualObj.Index(10); // ---Triangle 13-- - manualObj.Index(9); manualObj.Index(11); manualObj.Index(10); // ---Triangle 14-- - manualObj.Index(12); manualObj.Index(13); manualObj.Index(14); // ---Triangle 15-- - manualObj.Index(13); manualObj.Index(15); manualObj.Index(14); manualObj.Position(new Vector3(30, 30, -60)); // --- Vertex 16 --- manualObj.TextureCoord(new Vector2(1, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, 30, -60)); // --- Vertex 17 --- manualObj.TextureCoord(new Vector2(0, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, 30, 0)); // --- Vertex 18 --- manualObj.TextureCoord(new Vector2(1, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, 30, 0)); // --- Vertex 19 --- manualObj.TextureCoord(new Vector2(0, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, -30, 0)); // --- Vertex 20 --- manualObj.TextureCoord(new Vector2(0, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, -30, 0)); // --- Vertex 21 --- manualObj.TextureCoord(new Vector2(0, 1)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(30, -30, -60)); // ---Vertex 22 --- manualObj.TextureCoord(new Vector2(1, 0)); manualObj.Normal(1, 1, 1); manualObj.Position(new Vector3(-30, -30, -60)); // ---Vertex 23 --- manualObj.TextureCoord(new Vector2(1, 1)); manualObj.Normal(1, 1, 1); // ---Triangle 12-- - manualObj.Index(16); manualObj.Index(17); manualObj.Index(18); // ---Triangle 13-- - manualObj.Index(17); manualObj.Index(19); manualObj.Index(18); // ---Triangle 14-- - manualObj.Index(20); manualObj.Index(21); manualObj.Index(22); // ---Triangle 15-- - manualObj.Index(21); manualObj.Index(23); manualObj.Index(22); manualObj.End(); // Closes the manual objet return(manualObj.ConvertToMesh(cubeName)); // Prepares the data to be sent to the GPU }
public static void generateFace() { string defaultMaterial = "Default"; ManualObject block = new ManualObject("frontFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[0]); block.Position(new Vector3(0, Cst.CUBE_SIDE, 0)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[0]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[0]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[0]); block.Quad(3, 2, 1, 0); block.End(); block.ConvertToMesh("frontFace"); block = new ManualObject("underFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[1]); block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[1]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[1]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[1]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("underFace"); block = new ManualObject("rightFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[2]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[2]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[2]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[2]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("rightFace"); block = new ManualObject("upperFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[3]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[3]); block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[3]); block.Position(new Vector3(0, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[3]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("upperFace"); block = new ManualObject("leftFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, 0)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[4]); block.Position(new Vector3(0, Cst.CUBE_SIDE, 0)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[4]); block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[4]); block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[4]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("leftFace"); block = new ManualObject("backFace"); block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE)); block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[5]); block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[5]); block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[5]); block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[5]); block.Quad(0, 1, 2, 3); block.End(); block.ConvertToMesh("backFace"); }
public MeshPtr LoadWorldMap(string worldMapID, SceneManager sceneManager, MBWorldMap worldMap, bool faceted = false) { //Convert Vertex and Faces to Ogre Mesh Format if (worldMap == null) { return(null); } if (meshes.ContainsKey(worldMapID)) { return(meshes[worldMapID]); } ManualObject worldMapTerrain = sceneManager.CreateManualObject("WORLDMAP-MANUAL-OBJECT-" + worldMapID); worldMapTerrain.Begin("", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); calculateNormal(worldMapTerrain, worldMap); for (int i = 0; i < worldMap.Faces.Count; i++) { int vindex1 = worldMap.Faces[i].indexFirst; int vindex2 = worldMap.Faces[i].indexSecond; int vindex3 = worldMap.Faces[i].indexThird; float[] vnindex1 = worldMap.fcn[i]; float[] vnindex2 = worldMap.fcn[i]; float[] vnindex3 = worldMap.fcn[i]; worldMapTerrain.Position( worldMap.Vertics[vindex1].x, worldMap.Vertics[vindex1].z, worldMap.Vertics[vindex1].y ); worldMapTerrain.Normal(vnindex1[0], vnindex1[1], vnindex1[2]); worldMapTerrain.Colour(worldMap.Color[worldMap.Faces[i].TerrainType]); worldMapTerrain.Position( worldMap.Vertics[vindex2].x, worldMap.Vertics[vindex2].z, worldMap.Vertics[vindex2].y ); worldMapTerrain.Normal(vnindex2[0], vnindex2[1], vnindex2[2]); worldMapTerrain.Colour(worldMap.Color[worldMap.Faces[i].TerrainType]); worldMapTerrain.Position( worldMap.Vertics[vindex3].x, worldMap.Vertics[vindex3].z, worldMap.Vertics[vindex3].y ); worldMapTerrain.Normal(vnindex3[0], vnindex3[1], vnindex3[2]); worldMapTerrain.Colour(worldMap.Color[worldMap.Faces[i].TerrainType]); worldMapTerrain.Triangle( (uint)(vindex1), (uint)(vindex2), (uint)(vindex3) ); } worldMapTerrain.End(); var mesh = worldMapTerrain.ConvertToMesh("WORLDMAP-" + worldMapID); meshes.Add(worldMapID, mesh); return(mesh); }
private static ManualObject GenerateCubeHelper(float x, float y, float z, String name, Material frontFace, Material backFace, Material leftFace, Material rightFace, Material topFace, Material bottomFace, Vector3 positionOffset) { float xOffset = positionOffset.x; float yOffset = positionOffset.y; float zOffset = positionOffset.z; x /= 2; y /= 2; z /= 2; ManualObject cube = Engine.Renderer.Scene.CreateManualObject(name); cube.Dynamic = true; //START GENERATION cube.Begin(bottomFace.Name); cube.Position(x + xOffset, -y + yOffset, z + zOffset); cube.Normal(0.408248f, -0.816497f, 0.408248f); cube.TextureCoord(1, 0); //1 cube.Position(-x + xOffset, -y + yOffset, -z + zOffset); cube.Normal(-0.408248f, -0.816497f, -0.408248f); cube.TextureCoord(0, 1); //2 cube.Position(x + xOffset, -y + yOffset, -z + zOffset); cube.Normal(0.666667f, -0.333333f, -0.666667f); cube.TextureCoord(1, 1); //3 cube.Position(-x + xOffset, -y + yOffset, z + zOffset); cube.Normal(-0.666667f, -0.333333f, 0.666667f); cube.TextureCoord(0, 0); cube.Triangle(0, 1, 2); cube.Triangle(3, 1, 0); cube.End(); cube.Begin(backFace.Name); //4 cube.Position(x + xOffset, y + yOffset, z + zOffset); cube.Normal(0.666667f, 0.333333f, 0.666667f); cube.TextureCoord(1, 0); //5 cube.Position(-x + xOffset, -y + yOffset, z + zOffset); cube.Normal(-0.666667f, -0.333333f, 0.666667f); cube.TextureCoord(0, 1); //6 cube.Position(x + xOffset, -y + yOffset, z + zOffset); cube.Normal(0.408248f, -0.816497f, 0.408248f); cube.TextureCoord(1, 1); //7 cube.Position(-x + xOffset, y + yOffset, z + zOffset); cube.Normal(-0.408248f, 0.816497f, 0.408248f); cube.TextureCoord(0, 0); cube.Triangle(0, 1, 2); cube.Triangle(0, 3, 1); cube.End(); cube.Begin(leftFace.Name); //7 cube.Position(-x + xOffset, y + yOffset, z + zOffset); cube.Normal(-0.408248f, 0.816497f, 0.408248f); cube.TextureCoord(0, 0); //8 cube.Position(-x + xOffset, y + yOffset, -z + zOffset); cube.Normal(-0.666667f, 0.333333f, -0.666667f); cube.TextureCoord(0, 1); //9 cube.Position(-x + xOffset, -y + yOffset, -z + zOffset); cube.Normal(-0.408248f, -0.816497f, -0.408248f); cube.TextureCoord(1, 1); //10 cube.Position(-x + xOffset, -y + yOffset, z + zOffset); cube.Normal(-0.666667f, -0.333333f, 0.666667f); cube.TextureCoord(1, 0); cube.Triangle(1, 2, 3); cube.Triangle(3, 0, 1); cube.End(); cube.Begin(rightFace.Name); //4 cube.Position(x + xOffset, y + yOffset, z + zOffset); cube.Normal(0.666667f, 0.333333f, 0.666667f); cube.TextureCoord(1, 0); //11 cube.Position(x + xOffset, -y + yOffset, -z + zOffset); cube.Normal(0.666667f, -0.333333f, -0.666667f); cube.TextureCoord(0, 1); //12 cube.Position(x + xOffset, y + yOffset, -z + zOffset); cube.Normal(0.408248f, 0.816497f, -0.408248f); cube.TextureCoord(1, 1); //13 cube.Position(x + xOffset, -y + yOffset, z + zOffset); cube.Normal(0.408248f, -0.816497f, 0.408248f); cube.TextureCoord(0, 0); cube.Triangle(0, 1, 2); cube.Triangle(0, 3, 1); cube.End(); cube.Begin(frontFace.Name); //8 cube.Position(-x + xOffset, y + yOffset, -z + zOffset); cube.Normal(-0.666667f, 0.333333f, -0.666667f); cube.TextureCoord(0, 1); //12 cube.Position(x + xOffset, y + yOffset, -z + zOffset); cube.Normal(0.408248f, 0.816497f, -0.408248f); cube.TextureCoord(1, 1); //14 cube.Position(x + xOffset, -y + yOffset, -z + zOffset); cube.Normal(0.666667f, -0.333333f, -0.666667f); cube.TextureCoord(1, 0); //15 cube.Position(-x + xOffset, -y + yOffset, -z + zOffset); cube.Normal(-0.408248f, -0.816497f, -0.408248f); cube.TextureCoord(0, 0); cube.Triangle(2, 0, 1); cube.Triangle(2, 3, 0); cube.End(); cube.Begin(topFace.Name); //16 cube.Position(-x + xOffset, y + yOffset, z + zOffset); cube.Normal(-0.408248f, 0.816497f, 0.408248f); cube.TextureCoord(1, 0); //17 cube.Position(x + xOffset, y + yOffset, -z + zOffset); cube.Normal(0.408248f, 0.816497f, -0.408248f); cube.TextureCoord(0, 1); //18 cube.Position(-x + xOffset, y + yOffset, -z + zOffset); cube.Normal(-0.666667f, 0.333333f, -0.666667f); cube.TextureCoord(1, 1); //19 cube.Position(x + xOffset, y + yOffset, z + zOffset); cube.Normal(0.666667f, 0.333333f, 0.666667f); cube.TextureCoord(0, 0); cube.Triangle(0, 1, 2); cube.Triangle(0, 3, 1); cube.End(); return(cube); }
private static ManualObject UpdateCubeHelper(ManualObject updating, float x, float y, float z, Material frontFace, Material backFace, Material leftFace, Material rightFace, Material topFace, Material bottomFace, Face updatedFaces, Vector3 positionOffset) { float xOffset = positionOffset.x; float yOffset = positionOffset.y; float zOffset = positionOffset.z; x /= 2; y /= 2; z /= 2; //START GENERATION updating.BeginUpdate(0); updating.Position(x + xOffset, -y + yOffset, z + zOffset); updating.Normal(0.408248f, -0.816497f, 0.408248f); updating.TextureCoord(1, 0); //1 updating.Position(-x + xOffset, -y + yOffset, -z + zOffset); updating.Normal(-0.408248f, -0.816497f, -0.408248f); updating.TextureCoord(0, 1); //2 updating.Position(x + xOffset, -y + yOffset, -z + zOffset); updating.Normal(0.666667f, -0.333333f, -0.666667f); updating.TextureCoord(1, 1); //3 updating.Position(-x + xOffset, -y + yOffset, z + zOffset); updating.Normal(-0.666667f, -0.333333f, 0.666667f); updating.TextureCoord(0, 0); updating.Triangle(0, 1, 2); updating.Triangle(3, 1, 0); updating.End(); updating.BeginUpdate(1); //4 updating.Position(x + xOffset, y + yOffset, z + zOffset); updating.Normal(0.666667f, 0.333333f, 0.666667f); updating.TextureCoord(1, 0); //5 updating.Position(-x + xOffset, -y + yOffset, z + zOffset); updating.Normal(-0.666667f, -0.333333f, 0.666667f); updating.TextureCoord(0, 1); //6 updating.Position(x + xOffset, -y + yOffset, z + zOffset); updating.Normal(0.408248f, -0.816497f, 0.408248f); updating.TextureCoord(1, 1); //7 updating.Position(-x + xOffset, y + yOffset, z + zOffset); updating.Normal(-0.408248f, 0.816497f, 0.408248f); updating.TextureCoord(0, 0); updating.Triangle(0, 1, 2); updating.Triangle(0, 3, 1); updating.End(); updating.BeginUpdate(2); //7 updating.Position(-x + xOffset, y + yOffset, z + zOffset); updating.Normal(-0.408248f, 0.816497f, 0.408248f); updating.TextureCoord(0, 0); //8 updating.Position(-x + xOffset, y + yOffset, -z + zOffset); updating.Normal(-0.666667f, 0.333333f, -0.666667f); updating.TextureCoord(0, 1); //9 updating.Position(-x + xOffset, -y + yOffset, -z + zOffset); updating.Normal(-0.408248f, -0.816497f, -0.408248f); updating.TextureCoord(1, 1); //10 updating.Position(-x + xOffset, -y + yOffset, z + zOffset); updating.Normal(-0.666667f, -0.333333f, 0.666667f); updating.TextureCoord(1, 0); updating.Triangle(1, 2, 3); updating.Triangle(3, 0, 1); updating.End(); updating.BeginUpdate(3); //4 updating.Position(x + xOffset, y + yOffset, z + zOffset); updating.Normal(0.666667f, 0.333333f, 0.666667f); updating.TextureCoord(1, 0); //11 updating.Position(x + xOffset, -y + yOffset, -z + zOffset); updating.Normal(0.666667f, -0.333333f, -0.666667f); updating.TextureCoord(0, 1); //12 updating.Position(x + xOffset, y + yOffset, -z + zOffset); updating.Normal(0.408248f, 0.816497f, -0.408248f); updating.TextureCoord(1, 1); //13 updating.Position(x + xOffset, -y + yOffset, z + zOffset); updating.Normal(0.408248f, -0.816497f, 0.408248f); updating.TextureCoord(0, 0); updating.Triangle(0, 1, 2); updating.Triangle(0, 3, 1); updating.End(); updating.BeginUpdate(4); //8 updating.Position(-x + xOffset, y + yOffset, -z + zOffset); updating.Normal(-0.666667f, 0.333333f, -0.666667f); updating.TextureCoord(0, 1); //12 updating.Position(x + xOffset, y + yOffset, -z + zOffset); updating.Normal(0.408248f, 0.816497f, -0.408248f); updating.TextureCoord(1, 1); //14 updating.Position(x + xOffset, -y + yOffset, -z + zOffset); updating.Normal(0.666667f, -0.333333f, -0.666667f); updating.TextureCoord(1, 0); //15 updating.Position(-x + xOffset, -y + yOffset, -z + zOffset); updating.Normal(-0.408248f, -0.816497f, -0.408248f); updating.TextureCoord(0, 0); updating.Triangle(2, 0, 1); updating.Triangle(2, 3, 0); updating.End(); updating.BeginUpdate(5); //16 updating.Position(-x + xOffset, y + yOffset, z + zOffset); updating.Normal(-0.408248f, 0.816497f, 0.408248f); updating.TextureCoord(1, 0); //17 updating.Position(x + xOffset, y + yOffset, -z + zOffset); updating.Normal(0.408248f, 0.816497f, -0.408248f); updating.TextureCoord(0, 1); //18 updating.Position(-x + xOffset, y + yOffset, -z + zOffset); updating.Normal(-0.666667f, 0.333333f, -0.666667f); updating.TextureCoord(1, 1); //19 updating.Position(x + xOffset, y + yOffset, z + zOffset); updating.Normal(0.666667f, 0.333333f, 0.666667f); updating.TextureCoord(0, 0); updating.Triangle(0, 1, 2); updating.Triangle(0, 3, 1); updating.End(); updating.BoundingBox = new AxisAlignedBox( new Vector3( -x + xOffset, -y + yOffset, -z + zOffset), new Vector3( x + xOffset, y + yOffset, z + zOffset)); return(updating); }