public void SetModel(Mesh3D mesh) { // Add the mesh. myGeometryModel = new GeometryModel3D(); MeshGeometry3D myMeshGeometry3D = new MeshGeometry3D(); Point3DCollection myPositionCollection = new Point3DCollection(); Int32Collection myTriangleIndicesCollection = new Int32Collection(); try { for (int i = 0; i < mesh.Vertices.Length; i++) { myPositionCollection.Add(new Point3D(mesh.Vertices[i].x, mesh.Vertices[i].y, mesh.Vertices[i].z)); } myTriangleIndicesCollection = new Int32Collection(mesh.Triangles); } catch (Exception ex) { } myMeshGeometry3D.Positions = myPositionCollection; myMeshGeometry3D.TriangleIndices = myTriangleIndicesCollection; // Apply the mesh to the geometry model. myGeometryModel.Geometry = myMeshGeometry3D; // Define material and apply to the mesh geometries. Material myMaterial; //if (this.renderType == RenderAspectEnum.GreenLimeYellow) // myMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.LimeGreen)); //else myMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.White)); myGeometryModel.Material = myMaterial; Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(new ScaleTransform3D(mesh.Scale, mesh.Scale, mesh.Scale)); transformGroup.Children.Add(new TranslateTransform3D(new Vector3D(-mesh.OffsetX * mesh.Scale, -mesh.OffsetY * mesh.Scale, -mesh.OffsetZ * mesh.Scale))); myModel3DGroup.Transform = transformGroup; // Add the geometry model to the model group. myModel3DGroup.Children.Add(myGeometryModel); float newScale = mesh.Scale < 0.001 ? mesh.Scale * 10 : (mesh.Scale > 0.1 ? mesh.Scale * 0.1f : mesh.Scale); myGridLines.Width = 5000 * newScale; myGridLines.Thickness = myGridLines.Width / 7000; myGridLines.Length = myGridLines.Width; myGridLines.MajorDistance = myGridLines.Width / 30; myGridLines.MinorDistance = myGridLines.MajorDistance / 10; myGridLines.Center = new Point3D(-3f * mesh.Scale + myGridLines.MajorDistance / 2f, 3f * mesh.Scale + myGridLines.MajorDistance / 2f, -27.5f * mesh.Scale); }
public void SetModel(Mesh3D mesh) { this.mesh = mesh; // Create buffers { GL.GenBuffers(1, out modelVertexBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, modelVertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, mesh.Vertices.Length * Mesh3D.Vertexh.SizeInBytes, mesh.Vertices.ToArray(), BufferUsageHint.StaticDraw); GL.GenBuffers(1, out modelIndexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, modelIndexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, mesh.Triangles.Length * sizeof(int), mesh.Triangles.ToArray(), BufferUsageHint.StaticDraw); GL.VertexPointer(3, VertexPointerType.HalfFloat, 0, new IntPtr(0)); GL.GenBuffers(1, out modelNormalBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, modelNormalBuffer); GL.BufferData(BufferTarget.ArrayBuffer, mesh.vertexNormals.Length * Shared.Extensions.Half.SizeInBytes, mesh.vertexNormals, BufferUsageHint.StaticDraw); GL.NormalPointer(NormalPointerType.HalfFloat, 0, new IntPtr(0)); } }
public void RemoveModel() { this.mesh = null; }