Example #1
0
    /// Returns the index of the specified top-level gltf object.
    /// Raises KeyNotFoundException if the desired object is not found, or it has no index
    /// (meaning that it is not marked to be exported).
    private int LookupIndex(RefObj gltfObject)
    {
        RefObj obj = Lookup(gltfObject);

        if (obj.Index == null)
        {
            throw new KeyNotFoundException("Index " + gltfObject.name);
        }
        return(obj.Index.Value);
    }
Example #2
0
    /// Performs a LookupIndex() and formats the result as a gltf-style reference.
    /// If gltf1, this is a string name.
    /// If gltf2, this is a small integer index into the specified type's top-level object array.
    /// Raises KeyNotFoundException if the desired object is not found.
    public string SerializeReference(RefObj gltfObject)
    {
        // Always look it up, so we get good sanity checking even in gltf1 mode.
        int id = LookupIndex(gltfObject);

        m_emittedRefs.Add(gltfObject);
        if (Gltf2)
        {
            return(id.ToString());
        }
        else
        {
            return($"\"{gltfObject.name}\"");
        }
    }
Example #3
0
 /// Returns the specified top-level gltf object.
 /// This may seem like a silly no-op, but it performs some validation
 /// to ensure Lookup(obj) === Lookup<T>(obj.name)
 public RefObj Lookup(RefObj gltfObject)
 {
     if (!m_nameToObject.TryGetValue(gltfObject.name, out RefObj gltfObject2))
     {
         Debug.LogError($"Object {gltfObject.name} was not registered");
         throw new KeyNotFoundException(gltfObject.name);
     }
     if (ReferenceEquals(gltfObject2, gltfObject))
     {
         return(gltfObject);
     }
     else
     {
         Debug.LogError($"Two objects are named {gltfObject.name}: {gltfObject} and {gltfObject2}");
         throw new KeyNotFoundException(gltfObject.name);
     }
 }