private IMesh BuildChunkMesh(Point2 offset, Point2 size) { IMesh batch = new RAMMesh(); size.ForEach(p => { var v = world.GetVoxel(p + new Point2(offset)); if (v == null) { return; } var mesh = meshProvider.GetMesh(v); if (mesh == null) { return; } var vWorld = Matrix.Scaling(new Vector3(world.VoxelSize.X)) * Matrix.Translation(((p.ToVector2() + new Vector2(0.5f)) * world.VoxelSize.X).ToXZ(v.Data.Height)); MeshBuilder.AppendMeshTo(meshProvider.GetMesh(v), batch, vWorld); }); var optimizer = new MeshOptimizer(); batch = optimizer.CreateOptimized(batch); return(batch); }
public void TestOptimizeMeshManyParts() { var b = new MeshBuilder(); b.AddBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)); var partMesh = b.CreateMesh(); var unoptimized = new RAMMesh(); for (int i = 0; i < 1000; i++) { MeshBuilder.AppendMeshTo(partMesh, unoptimized, Matrix.Translation(i, 0, 0)); } var optimizer = new MeshOptimizer(); var watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 10; i++) { var optimized = optimizer.CreateOptimized(unoptimized); Assert.AreEqual(1, optimized.GetCoreData().Parts.Count); } watch.Stop(); Console.WriteLine(watch.Elapsed.TotalMilliseconds / 10); }
public void TestOptimizeMesh() { //TODO: better test //var fileName = TWDir.GameData + "\\Core\\TileSet\\ts001sg001.obj"; var fileName = TWDir.GameData + "\\TileSet01\\GreyBrick_RoofX_01\\GreyBrick_RoofX_01.obj"; var mesh = MeshLoader.LoadMeshFromObj(new System.IO.FileInfo(fileName)); var optimizer = new MeshOptimizer(); var optimized = optimizer.CreateOptimized(mesh); }
public void Build() { IMesh mesh = new RAMMesh(); foreach (var ent in entities) { MeshBuilder.AppendMeshTo(ent.Mesh, mesh, ent.WorldMatrix); ent.Batched = true; ent.get <BatchInfo>().Batch = this; } var optimizer = new MeshOptimizer(); mesh = optimizer.CreateOptimized(mesh); element = TW.Graphics.AcquireRenderer().CreateMeshElement(mesh); }
public IMesh loadMeshFromFile(string objFile, string matFile, string matName) { var fsMat = new FileStream(matFile, FileMode.Open); var importer = new ObjImporter(); importer.AddMaterialFileStream(matName, fsMat); importer.ImportObjFile(objFile); var meshes = converter.CreateMesh(importer); fsMat.Close(); return(optimizer.CreateOptimized(meshes)); // Optimize the mesh }