Example #1
0
            internal static U[] Array <T, U>(Conversion <T, U> conv, Interface.DynamicArray <T> assimp) where T : System.IDisposable
            {
                U[] unity = null;

                if (conv != null)
                {
                    uint size = assimp.Size();

                    unity = new U[size];

                    for (uint i = 0; i < size; i++)
                    {
                        using (T assimp_element = assimp.Get(i))
                        {
                            unity[i] = conv(assimp_element);
                        }
                    }
                }

                return(unity);
            }
Example #2
0
            //-------------------------------------------------------------------------------
            internal static int[] Face(Interface.DynamicArray <aiFace> assimp, out MeshTopology topology)
            {
                uint size = assimp.Size();

                topology = MeshTopology.Triangles;
                uint nb_faces = 3;

                if (size > 0)
                {
                    // Get the topology from the first face (because option aiProcess_SortByPType is mandatory, all faces have the same topology)
                    using (aiFace face = assimp.Get(0))
                    {
                        using (aiUIntArray indices = face.Indices)
                        {
                            switch (indices.Size())
                            {
                            case 1:
                                topology = MeshTopology.Points;
                                nb_faces = 1;
                                break;

                            case 2:
                                topology = MeshTopology.Lines;
                                nb_faces = 2;
                                break;

                            default:
                                // Because option aiProcess_Triangulate is mandatory
                                topology = MeshTopology.Triangles;
                                nb_faces = 3;
                                break;
                            }
                        }
                    }
                }

                int[] unity = new int[size * nb_faces];

                for (uint i = 0; i < size; i++)
                {
                    using (aiFace face = assimp.Get(i))
                    {
                        using (aiUIntArray indices = face.Indices)
                        {
                            if (indices.Size() >= nb_faces)
                            {
                                for (uint j = 0; j < nb_faces; j++)
                                {
                                    unity[i * nb_faces + j] = (int)indices.Get(j);
                                }

                                if (indices.Size() > nb_faces)
                                {
                                    Debug.LogError("Too many vertices to compose a face. Some data is lost.");
                                }
                            }
                            else
                            {
                                Debug.LogError("Not enough vertices to compose a face.");
                            }
                        }
                    }
                }

                return(unity);
            }