Exemplo n.º 1
0
    async void Start()
    {
        Debug.Log($"Loading model from: '{ModelPath}'");
        byte[] modelBytes = File.ReadAllBytes(ModelPath);

        using (ObjectModel model = await ObjectModel.LoadAsync((modelBytes)))
        {
            Numerics.Vector3[] modelVertices = new Numerics.Vector3[model.VertexCount];
            model.GetVertexPositions(modelVertices);

            // Counter clock wise
            uint[] modelIndicesCcw = new uint[model.TriangleIndexCount];
            model.GetTriangleIndices(modelIndicesCcw);

            Numerics.Vector3[] modelNormals = new Numerics.Vector3[model.VertexCount];
            model.GetVertexNormals(modelNormals);

            gameObject.AddComponent <MeshFilter>().mesh = LoadMesh(modelVertices, modelNormals, modelIndicesCcw);
        }
    }