Ejemplo n.º 1
0
    public void Populate(TiltBrush.GeometryPool pool)
    {
        pool.EnsureGeometryResident();

        if (primitives.Count > 0)
        {
            // Vertex data is shared among all the primitives in the mesh, so only do [0]
            primitives[0].attributes.Populate(pool);
            primitives[0].Populate(pool);

            // I guess someone might want to map Unity submeshes -> gltf primitives.
            // - First you'd want to make sure that consuming tools won't freak out about that,
            //   since it doesn't seem to be the intended use for the mesh/primitive distinction.
            //   See https://github.com/KhronosGroup/glTF/issues/1278
            // - Then you'd want Populate() to take multiple GeometryPools, one per MeshSubset.
            // - Then you'd want those GeometryPools to indicate somehow whether their underlying
            //   vertex data is or can be shared -- maybe do this in GeometryPool.FromMesh()
            //   by having them point to the same Lists.
            // - Then you'd want to make GlTF_attributes.Populate() smart enough to understand that
            //   sharing (ie, memoizing on the List<Vector3> pointer)
            // None of that is implemented, which is okay since our current gltf generation
            // code doesn't add more than one GlTF_Primitive per GlTF_Mesh.
            if (primitives.Count > 1)
            {
                Debug.LogError("More than one primitive per mesh is unimplemented and unsupported");
            }
        }


        // The mesh data is only ever needed once (because it only goes into the .bin
        // file once), but ExportMeshGeomPool still uses bits of data like pool.NumTris
        // so we can't destroy it.
        //
        // We could MakeNotResident(filename) again, but that's wasteful and I'd need to
        // add an API to get the cache filename. So this "no coming back" API seems like
        // the most expedient solution.
        // TODO: replace this hack with something better? eg, a way to reload from
        // file without destroying the file?
        // pool.Destroy();
        pool.MakeGeometryPermanentlyNotResident();
    }