예제 #1
0
        public StaticMesh(Context context, Scene scene, Vector3[] vertices, Triangle[] triangles, int[] materialIndices, Material[] materials)
        {
            mContext = context;

            var verticesBuffer        = Marshal.AllocHGlobal(vertices.Length * Marshal.SizeOf(typeof(Vector3)));
            var trianglesBuffer       = Marshal.AllocHGlobal(triangles.Length * Marshal.SizeOf(typeof(Triangle)));
            var materialIndicesBuffer = Marshal.AllocHGlobal(materialIndices.Length * Marshal.SizeOf(typeof(int)));
            var materialsBuffer       = Marshal.AllocHGlobal(materials.Length * Marshal.SizeOf(typeof(Material)));

            for (var i = 0; i < vertices.Length; ++i)
            {
                Marshal.StructureToPtr(vertices[i], new IntPtr(verticesBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Vector3))), false);
            }

            for (var i = 0; i < triangles.Length; ++i)
            {
                Marshal.StructureToPtr(triangles[i], new IntPtr(trianglesBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Triangle))), false);
            }

            Marshal.Copy(materialIndices, 0, materialIndicesBuffer, triangles.Length);

            for (var i = 0; i < materials.Length; ++i)
            {
                Marshal.StructureToPtr(materials[i], new IntPtr(materialsBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Material))), false);
            }

            var staticMeshSettings = new StaticMeshSettings {
            };

            staticMeshSettings.numVertices     = vertices.Length;
            staticMeshSettings.numTriangles    = triangles.Length;
            staticMeshSettings.numMaterials    = materials.Length;
            staticMeshSettings.vertices        = verticesBuffer;
            staticMeshSettings.triangles       = trianglesBuffer;
            staticMeshSettings.materialIndices = materialIndicesBuffer;
            staticMeshSettings.materials       = materialsBuffer;

            var status = API.iplStaticMeshCreate(scene.Get(), ref staticMeshSettings, out mStaticMesh);

            if (status != Error.Success)
            {
                throw new Exception(string.Format("Unable to create static mesh for export ({0} vertices, {1} triangles, {2} materials): [{3}]",
                                                  staticMeshSettings.numVertices.ToString(), staticMeshSettings.numTriangles.ToString(), staticMeshSettings.numMaterials.ToString(),
                                                  status.ToString()));
            }

            Marshal.FreeHGlobal(verticesBuffer);
            Marshal.FreeHGlobal(trianglesBuffer);
            Marshal.FreeHGlobal(materialIndicesBuffer);
            Marshal.FreeHGlobal(materialsBuffer);
        }
예제 #2
0
 public static extern Error iplStaticMeshCreate(IntPtr scene, ref StaticMeshSettings settings, out IntPtr staticMesh);