public static IPrimitive Convert(PolygonMesh.Mesh simpleMesh, MaterialAbstract partMaterial = null) { List <IPrimitive> renderCollection = new List <IPrimitive>(); if (partMaterial == null) { partMaterial = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0); } int index = 0; Vector3[] triangle = new Vector3[3]; foreach (PolygonMesh.Face face in simpleMesh.Faces) { foreach (PolygonMesh.Vertex vertex in face.Vertices()) { triangle[index++] = vertex.Position; if (index == 3) { index = 0; renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial)); } } } return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection)); }
public static IPrimitive Convert(Mesh mesh, MaterialAbstract partMaterial = null) { return(Convert(new Object3D() { Mesh = mesh })); }
public static IPrimitive Convert(IObject3D item, MaterialAbstract partMaterial = null) { List <IPrimitive> renderCollection = new List <IPrimitive>(); if (partMaterial == null) { partMaterial = new SolidMaterial(new ColorF(.9, .2, .1), .01, 0.0, 2.0); } int index = 0; Vector3[] triangle = new Vector3[3]; foreach (Mesh mesh in item.VisibleMeshes().Select(i => i.Mesh)) { foreach (Face face in mesh.Faces) { foreach (Vertex vertex in face.Vertices()) { triangle[index++] = vertex.Position; if (index == 3) { index = 0; renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial)); } } } } return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection)); }
public static ITraceable Convert(IObject3D item, MaterialAbstract partMaterial = null) { var renderCollection = new List <ITraceable>(); if (partMaterial == null) { partMaterial = new SolidMaterial(new ColorF(.9, .2, .1), .01, 0.0, 2.0); } int index = 0; var triangle = new Vector3[3]; foreach (Mesh mesh in item.VisibleMeshes().Select(i => i.Mesh)) { throw new NotImplementedException(); //foreach (Face face in mesh.Faces) //{ // foreach (Vertex vertex in face.Vertices()) // { // triangle[index++] = vertex.Position; // if (index == 3) // { // index = 0; // renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial)); // } // } //} } return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection)); }
/// <summary> /// Create a bounding volume hierarchy for the give mesh. /// </summary> /// <param name="mesh">The mesh to add the BVH to.</param> /// <param name="material">The tracing material to use.</param> /// <param name="matrix">A transformation to apply to the trace data</param> /// <param name="maxRecursion">The max depth to create the BVH tree.</param> /// <returns>The created BVH tree.</returns> public static ITraceable CreateBVHData(this Mesh mesh, MaterialAbstract material, Matrix4X4 matrix, int maxRecursion = int.MaxValue) { var allPolys = new List <ITraceable>(); mesh.AddTraceables(material, matrix, allPolys); return(BoundingVolumeHierarchy.CreateNewHierachy(allPolys, maxRecursion)); }
public MeshFaceTraceable(Face face, MaterialAbstract material, Matrix4X4 worldMatrix) { this.face = face; this.Material = material; this.worldMatrix = worldMatrix; aabb = face.GetAxisAlignedBoundingBox(worldMatrix); }
public static IPrimitive Convert(List <PolygonMesh.MeshGroup> meshGroups, MaterialAbstract partMaterial = null) { List <IPrimitive> renderCollection = new List <IPrimitive>(); foreach (MeshGroup meshGroup in meshGroups) { renderCollection.Add(Convert(meshGroup, partMaterial)); } return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection)); }
public static IPrimitive Convert(PolygonMesh.MeshGroup meshGroup, MaterialAbstract partMaterial = null) { List <IPrimitive> renderCollection = new List <IPrimitive>(); SolidMaterial otherMaterial = new SolidMaterial(new RGBA_Floats(.1, .2, .9), .01, 0.0, 2.0); if (partMaterial == null) { partMaterial = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0); } int index = 0; Vector3[] triangle = new Vector3[3]; foreach (PolygonMesh.Mesh mesh in meshGroup.Meshes) { int materialIntdex = MeshMaterialData.Get(mesh).MaterialIndex; foreach (PolygonMesh.Face face in mesh.Faces) { foreach (PolygonMesh.Vertex vertex in face.Vertices()) { triangle[index++] = vertex.Position; if (index == 3) { index = 0; if (materialIntdex == 1) { renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial)); } else { renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], otherMaterial)); } } } } } return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection)); }
public static void AddTraceables(this Mesh mesh, MaterialAbstract material, Matrix4X4 matrix, List <ITraceable> tracePrimitives) { for (int faceIndex = 0; faceIndex < mesh.Faces.Count; faceIndex++) { var face = mesh.Faces[faceIndex]; ITraceable triangle; if (material != null) { triangle = new TriangleShape( mesh.Vertices[face.v0].Transform(matrix), mesh.Vertices[face.v1].Transform(matrix), mesh.Vertices[face.v2].Transform(matrix), material, faceIndex); } else { triangle = new MinimalTriangle((fi, vi) => { switch (vi) { case 0: return(mesh.Vertices[mesh.Faces[fi].v0]); case 1: return(mesh.Vertices[mesh.Faces[fi].v1]); default: return(mesh.Vertices[mesh.Faces[fi].v2]); } }, faceIndex); } tracePrimitives.Add(triangle); } }