public void SetContent(Mesh3d mesh) { m_mesh3d = mesh; Vector3L[] vertices = mesh.GetVertices(); Vector3L min = vertices[0]; Vector3L max = vertices[0]; for (int i = 1; i < mesh.m_triangleList.Count * 3; ++i) { min.x = FixPointMath.Min(vertices[i].x, min.x); min.y = FixPointMath.Min(vertices[i].y, min.y); min.z = FixPointMath.Min(vertices[i].z, min.z); max.x = FixPointMath.Max(vertices[i].x, max.x); max.y = FixPointMath.Max(vertices[i].y, max.y); max.z = FixPointMath.Max(vertices[i].z, max.z); } m_aabb = Mesh3d.FromMinMax(min, max); }
public static void AccelerateMesh(Mesh3d mesh) { if (mesh.m_accelerator != null) { return; } Vector3L[] vertices = mesh.GetVertices(); Vector3L min = vertices[0]; Vector3L max = vertices[0]; for (int i = 1; i < mesh.m_triangleList.Count * 3; ++i) { min.x = FixPointMath.Min(vertices[i].x, min.x); min.y = FixPointMath.Min(vertices[i].y, min.y); min.z = FixPointMath.Min(vertices[i].z, min.z); max.x = FixPointMath.Max(vertices[i].x, max.x); max.y = FixPointMath.Max(vertices[i].y, max.y); max.z = FixPointMath.Max(vertices[i].z, max.z); } mesh.m_accelerator = new BVHNode(); mesh.m_accelerator.m_bounds = FromMinMax(min, max); mesh.m_accelerator.m_children = null; // this.m_accelerator.m_triangles = this.m_triangleList.Count; // this.m_accelerator->triangles = new int[mesh.numTriangles]; // for (int i = 0; i < mesh.numTriangles; ++i) { // mesh.accelerator->triangles[i] = i; // } //this.m_accelerator.m_triangles = this.m_triangleList; // for (int i = 0; i < mesh.m_triangleList.Count; ++i) // { // mesh.m_accelerator.m_triangles.Add(mesh.m_triangleList); // } mesh.m_accelerator.m_triangles.AddRange(mesh.m_triangleList); SplitBVHNode(mesh.m_accelerator, mesh, 3); }