Class FilamentAsset


  • public class FilamentAsset
    extends java.lang.Object
    Owns a bundle of Filament objects that have been created by AssetLoader.

    For usage instructions, see the documentation for AssetLoader.

    This class owns a hierarchy of entities that have been loaded from a glTF asset. Every entity has a TransformManager component, and some entities also have NameComponentManager and/or RenderableManager components.

    In addition to the aforementioned entities, an asset has strong ownership over a list of VertexBuffer, IndexBuffer, MaterialInstance, and Texture.

    Clients can use ResourceLoader to create textures, compute tangent quaternions, and upload data into vertex buffers and index buffers.

    See Also:
    ResourceLoader, Animator, AssetLoader
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyMaterialVariant​(int variantIndex)
      Applies the given material variant to all primitives that it affects.
      Animator getAnimator()
      Retrieves the Animator interface for this asset.
      com.google.android.filament.Box getBoundingBox()
      Gets the bounding box computed from the supplied min / max values in glTF accessors.
      int[] getCameraEntities()
      Gets only the entities that have camera components.
      int[] getEntities()
      Gets the list of entities, one for each glTF node.
      int[] getEntitiesByName​(java.lang.String name)
      Gets a list of entities with the given name.
      int[] getEntitiesByPrefix​(java.lang.String prefix)
      Gets a list of entities whose names start with the given prefix.
      java.lang.String getExtras​(int entity)
      Gets the glTF extras string for the asset or a specific node.
      int getFirstEntityByName​(java.lang.String name)
      Returns the first entity with the given name, or 0 if none exist.
      int[] getLightEntities()
      Gets only the entities that have light components.
      com.google.android.filament.MaterialInstance[] getMaterialInstances()  
      java.lang.String[] getMaterialVariantNames()
      Returns the names of all material variants.
      java.lang.String[] getMorphTargetNames​(int entity)
      Gets the names of all morph targets in the given entity.
      java.lang.String getName​(int entity)
      Gets the NameComponentManager label for the given entity, if it exists.
      java.lang.String[] getResourceUris()
      Gets resource URIs for all externally-referenced buffers.
      int getRoot()
      Gets the transform root for the asset, which has no matching glTF node.
      int popRenderable()
      Pops a ready renderable off the queue, or returns 0 if no renderables have become ready.
      int popRenderables​(int[] entities)
      Pops one or more renderables off the queue, or returns the available number.
      void releaseSourceData()
      Reclaims CPU-side memory for URI strings, binding lists, and raw animation data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getRoot

        public int getRoot()
        Gets the transform root for the asset, which has no matching glTF node.
      • popRenderable

        public int popRenderable()
        Pops a ready renderable off the queue, or returns 0 if no renderables have become ready. NOTE: To determine the progress percentage or completion status, please use ResourceLoader#asyncGetLoadProgress. This helper method allows clients to progressively add renderables to the scene as textures gradually become ready through asynchronous loading. See also ResourceLoader#asyncBeginLoad.
      • popRenderables

        public int popRenderables​(@Nullable
                                  int[] entities)
        Pops one or more renderables off the queue, or returns the available number. Returns the number of entities written into the given array. If the given array is null, returns the number of available renderables.
      • getEntities

        @NonNull
        public int[] getEntities()
        Gets the list of entities, one for each glTF node.

        All of these have a transform component. Some of the returned entities may also have a renderable or light component.

      • getLightEntities

        @NonNull
        public int[] getLightEntities()
        Gets only the entities that have light components.
      • getCameraEntities

        @NonNull
        public int[] getCameraEntities()
        Gets only the entities that have camera components.

        Note about aspect ratios:
        gltfio always uses an aspect ratio of 1.0 when setting the projection matrix for perspective cameras. gltfio then sets the camera's scaling matrix with the aspect ratio specified in the glTF file (if present).
        The camera's scaling matrix allows clients to adjust the aspect ratio independently from the camera's projection.

        See Also:
        Camera.setScaling(double, double)
      • getFirstEntityByName

        public int getFirstEntityByName​(java.lang.String name)
        Returns the first entity with the given name, or 0 if none exist.
      • getEntitiesByName

        @NonNull
        public int[] getEntitiesByName​(java.lang.String name)
        Gets a list of entities with the given name.
      • getEntitiesByPrefix

        @NonNull
        public int[] getEntitiesByPrefix​(java.lang.String prefix)
        Gets a list of entities whose names start with the given prefix.
      • getMaterialInstances

        @NonNull
        public com.google.android.filament.MaterialInstance[] getMaterialInstances()
      • getBoundingBox

        @NonNull
        public com.google.android.filament.Box getBoundingBox()
        Gets the bounding box computed from the supplied min / max values in glTF accessors.
      • getName

        public java.lang.String getName​(int entity)
        Gets the NameComponentManager label for the given entity, if it exists.
      • getExtras

        @Nullable
        public java.lang.String getExtras​(int entity)
        Gets the glTF extras string for the asset or a specific node.
        Parameters:
        entity - the entity corresponding to the glTF node, or 0 to get the asset-level string.
        Returns:
        the requested extras string, or null if it does not exist.
      • getMorphTargetNames

        @NonNull
        public java.lang.String[] getMorphTargetNames​(int entity)
        Gets the names of all morph targets in the given entity.
      • getResourceUris

        @NonNull
        public java.lang.String[] getResourceUris()
        Gets resource URIs for all externally-referenced buffers.
      • getMaterialVariantNames

        @NonNull
        public java.lang.String[] getMaterialVariantNames()
        Returns the names of all material variants.
      • applyMaterialVariant

        public void applyMaterialVariant​(@IntRange(from=0L)
                                         int variantIndex)
        Applies the given material variant to all primitives that it affects. This is efficient because it merely swaps around persistent MaterialInstances. If you change a material parameter while a certain variant is active, the updated value will be remembered after you re-apply that variant. If the asset is instanced, this affects all instances in the same way. To set the variant on an individual instance, use FilamentInstance#applyMaterialVariant. Ignored if variantIndex is out of bounds.
      • releaseSourceData

        public void releaseSourceData()
        Reclaims CPU-side memory for URI strings, binding lists, and raw animation data. This should only be called after ResourceLoader#loadResources() or ResourceLoader#asyncBeginLoad(). If this is an instanced asset, this prevents creation of new instances.