// Model will be scaled/translated to fit voxel map size (X, Y and Z) MyVoxelImport(MyVoxelMap voxelMap, MyModelObj model, MyVoxelImportOptions importOptions) { // Load model, get triangles LoadModel(model); // Rescale the model so it fits voxelMap (three directions!!!) RescaleModel(voxelMap, importOptions); // Fill lookup array with triangles located at specified voxel positions. Array is 2D. FillTrianglesLookup(voxelMap); // Create XZ map where every voxel center gets list of triangles that lie on its Y line // Do this by iterating over all triangles and making references to them from XZ map Import(voxelMap); }
void LoadModel(MyModelObj model) { m_minCoord = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); m_maxCoord = new Vector3(float.MinValue, float.MinValue, float.MinValue); Vector3[] vertices = model.Vertexes.ToArray(); MyTriangleVertexIndices[] triangles = model.Triangles.ToArray(); m_triangles = new List<MyImportTriangle>(triangles.Length); for (int i = 0; i < triangles.Length; i++) { Vector3 vertex0 = vertices[triangles[i].I0]; Vector3 vertex1 = vertices[triangles[i].I1]; Vector3 vertex2 = vertices[triangles[i].I2]; MyImportTriangle triangle = new MyImportTriangle(vertex0, vertex1, vertex2); // Ignore triangles that lie in XZ plane if (triangle.Normal.Y != 0) { m_triangles.Add(triangle); CheckMinMaxCoords(vertex0); CheckMinMaxCoords(vertex1); CheckMinMaxCoords(vertex2); } } }
// Use this static method do one-time import of a voxel map public static void Run(MyVoxelMap voxelMap, MyModelObj model, MyVoxelImportOptions importOptions) { MyVoxelImport voxelMapImport = new MyVoxelImport(voxelMap, model, importOptions); }