private void Simplify(object obj) { if (!CanSimplify(null)) { return; } Busy = true; int size = Model.Indices.Count / 3 / 2; CalculationTime = 0; Task.Factory.StartNew(() => { var sw = Stopwatch.StartNew(); var model = simHelper.Simplify(size, 7, true, Lossless); sw.Stop(); CalculationTime = sw.ElapsedMilliseconds; model.Normals = model.CalculateNormals(); return(model); }).ContinueWith(x => { Busy = false; Model = x.Result; CommandManager.InvalidateRequerySuggested(); }, TaskScheduler.FromCurrentSynchronizationContext()); }
private void OnWorldGenerated(object sender, EventArgs args) { var world = (World)sender; WorldMeshes = new GroupModel3D(); world.Voxels.ToList().ForEach(vox => { var voxel = (Voxel)vox; CubeFace face; MeshBuilder b = new MeshBuilder(); voxel.GetVisibleCubeFaces().ForEach(f => { if (voxel.Faces.TryGetValue(f, out face)) { b.AddCubeFace(face.CubeCenter, face.Normal, face.Up, face.Distance, face.Width, face.Height); } }); var mm = b.ToMesh(); var simHelper = new MeshSimplification(mm); int size = mm.Indices.Count / 3 / 2; var m = simHelper.Simplify(size, 7, true, true); var mesh = new MeshGeometryModel3D { Geometry = mm, CullMode = SharpDX.Direct3D11.CullMode.Back }; var scale = new ScaleTransform3D(1, 1, 1); var translate = new TranslateTransform3D(0, 0, 0); var group = new Transform3DGroup(); group.Children.Add(scale); group.Children.Add(translate); mesh.Transform = group; mesh.Material = voxel.PhysicalMaterial; if (((Engine.Core.World.Material)voxel.Material).PhysicalMaterial.DiffuseColor.Alpha < 1) { mesh.IsTransparent = true; } WorldMeshes.Children.Add(mesh); voxel.Mesh = mesh; }); //Viewport = InitializeViewport(); //while (Viewport == null) { Debug.WriteLine($"Waiting for Viewport..."); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); MeshSimplification editorObj = target as MeshSimplification; if (editorObj == null) { return; } if (GUILayout.Button("Simplify")) { editorObj.Simplify(); } if (GUILayout.Button("Simplify Step-by-step")) { MeshFilter meshFilter = editorObj.GetComponent <MeshFilter>(); int currentVertices = meshFilter.sharedMesh.vertices.Length; editorObj.targetVertices = currentVertices - 1; editorObj.Simplify(); } if (editorObj.debugMode) { index1 = EditorGUILayout.IntField("Index1:", index1); index2 = EditorGUILayout.IntField("Index2:", index2); if (GUILayout.Button("Test Collapse")) { editorObj.TestCollapse(index1, index2); } } }