//------------------------------------------------------------------------------- internal static void Face(int[] unity, MeshTopology topology, Interface.Array <aiFace> assimp) { uint nb_faces = 0; switch (topology) { case MeshTopology.Points: nb_faces = 1; break; case MeshTopology.Lines: nb_faces = 2; break; case MeshTopology.Triangles: nb_faces = 3; break; case MeshTopology.Quads: nb_faces = 4; break; default: Debug.LogErrorFormat("Unsupported topology '{0}' in assimp export.", topology); break; } assimp.Clear(); if (nb_faces > 0) { long size = unity.Length / nb_faces; uint i = 0; for (; i < size; i++) { using (aiFace face = new aiFace()) { using (aiUIntArray indices = face.Indices) { for (uint j = 0; j < nb_faces; j++) { indices.Set(j, (uint)unity[i * nb_faces + j]); } assimp.Set(i, face.Unmanaged()); } } } if (i * nb_faces != unity.Length) { Debug.LogError("Invalid number of vertices to compose the faces."); } } }
public aiNode ToAssimp(Module.Export.Assimp.Context context, Scene scene, aiNode parent) { uint index = 0; aiNode node_object = new aiNode(name); // Set parent node_object.mParent = parent; // Set transform using (aiVector3D assimp_scale = Assimp.Convert.UnityToAssimp.Vector3(scale)) { using (aiQuaternion assimp_rotation = Assimp.Convert.UnityToAssimp.Quaternion(rotation)) { using (aiVector3D assimp_position = Assimp.Convert.UnityToAssimp.Vector3(position)) { using (aiMatrix4x4 matrix = new aiMatrix4x4(assimp_scale, assimp_rotation, assimp_position)) { node_object.mTransformation = matrix.Unmanaged(); } } } } // Parse the children nodes if (children != null && children.Length > 0) { using (aiNodeArray assimp_children = node_object.Children) { assimp_children.Reserve((uint)children.Length, true); index = 0; foreach (Node child in children) { using (aiNode assimp_child = child.ToAssimp(context, scene, node_object)) { if (assimp_child != null) { assimp_children.Set(index++, assimp_child.Unmanaged()); } } } } } // Parse the mesh objects if (meshes != null && meshes.Length > 0) { using (aiUIntArray assimp_meshes = node_object.Meshes) { assimp_meshes.Reserve((uint)meshes.Length, true); index = 0; foreach (GraphicMesh graphic_mesh in meshes) { Mesh mesh = scene.meshes[graphic_mesh.meshIndex]; int nb_materials = (graphic_mesh.materialsIndexes != null ? graphic_mesh.materialsIndexes.Length : 0); // Handle unity submeshes by creating new meshes for each submesh for (int i = 0; i < mesh.SubMeshesCount; i++) { // Assimp meshes can only have one material. Therefore, mutliple instances of one mesh // using different materials must be detected and replaced by different output meshes. uint assimp_mesh_index; int mat_index = (i < nb_materials ? graphic_mesh.materialsIndexes[i] : 0 /*Assimp default*/); Module.Export.Assimp.Mesh key = new Module.Export.Assimp.Mesh(graphic_mesh.meshIndex, i, mat_index); if (!context.meshes.TryGetValue(key, out assimp_mesh_index)) { assimp_mesh_index = (uint)context.meshes.Count; context.meshes.Add(key, assimp_mesh_index); } assimp_meshes.Set(index++, assimp_mesh_index); } } } } // Parse the node metadata if (components != null) { foreach (UnityComponent component in components) { aiMetadata assimp_meta = component.ToAssimpMetadata(); if (assimp_meta != null) { node_object.mMetaData = assimp_meta.Unmanaged(); break; } } } context.progress.Update(ASSIMP_PROGRESS_FACTOR); return(node_object); }