Most visited

Recently visited

Object3D

public class Object3D
extends Node

java.lang.Object
   ↳ com.viro.core.Node
     ↳ com.viro.core.Object3D


Object3D defines a Node that can load FBX, OBJ, GLTF, or GLB models. These file formats may contain not just single Geometry instances but entire subgraphs of Nodes. This Node acts as the parent to the generated subgraph.

OBJ loading supports MTL files, for loading material properties and textures. For OBJ files, Materials can also be manually injected by invoking setMaterials(List).

FBX loading supports Blinn/Phong material properties, diffuse, specular, and normal maps, skeletal and keyframe animation, and PBR material properties (roughness, metalness, ambient occlusion) through Stingray.

GLTF and GLB loading similarly support all material properties including PBR properties. Skeletal and keyframe animation however is currently not supported by GLTF/GLB. This support is forthcoming.

For an extended discussion on 3D model loading, refer to the 3D Objects Guide.

Summary

Nested classes

enum Object3D.Type

Supported model formats for loading into an Object3D

Public constructors

Object3D()

Construct a new Object3D.

Public methods

void dispose()

Release native resources associated with this Object3D.

void disposeModel()

Remove and dispose the model that was loaded in this Object3D.

List<Material> getMaterials()

Get a list of unique Material objects used by this 3D model.

void loadModel(ViroContext viroContext, Uri uri, Object3D.Type type, AsyncObject3DListener asyncListener)

Load the model at the given URI into this Node.

void setLightReceivingBitMask(int bitMask)

Set the bit mask that determines what lights will illuminate this Node.

void setShadowCastingBitMask(int bitMask)

Set the bit mask that determines for which lights the contents of this Node will cast shadows.

Public constructors

Object3D

Object3D ()

Construct a new Object3D. To load 3D model data into this Node, use loadModel(ViroContext, Uri, Type, AsyncObject3DListener).

Public methods

dispose

void dispose ()

Release native resources associated with this Object3D.

disposeModel

void disposeModel ()

Remove and dispose the model that was loaded in this Object3D. This will remove and delete all the Node, Geometry, Material, and Texture objects created during the last call to loadModel(ViroContext, Uri, Type, AsyncObject3DListener).

This is especially useful when removing models with a large memory footprint, to ensure they're deleted quickly without having to wait for GC. Note this method does not dispose of this Node; you can still load a new model into this Node via loadModel(ViroContext, Uri, Type, AsyncObject3DListener).

getMaterials

List<Material> getMaterials ()

Get a list of unique Material objects used by this 3D model. These may be modified at runtime to change the textures and/or other material properties of the model. Materials can often be identified by their name, which is set by the 3D model loader.

Note that if a model file contains multiple geometries, this list will contain all the materials across all geometries.

Returns
List<Material> A list containing each Material used by this 3D model.

loadModel

void loadModel (ViroContext viroContext, 
                Uri uri, 
                Object3D.Type type, 
                AsyncObject3DListener asyncListener)

Load the model at the given URI into this Node. The model will load asynchronously, and the provided listener will receive a notification when model loading is completed. To load Android assets, use URI's of the form file:///android_asset/[asset-name].

If the model requires other resources (e.g. textures), then for FBX and OBJ models those resources are expected to be found at the same base path as the model URI. For GLTB and GLB models, resources are expected at the relative paths specified in the GLTF JSON.

If another model is already loaded into this Object3D, that model will be immediately removed. If the Object3D is currently loading another model, that model will be disposed.

Parameters
viroContext ViroContext: The ViroContext is required to load models.

uri Uri: The URI of the model to load.

type Object3D.Type: The model input format.

asyncListener AsyncObject3DListener: Listener to respond to model loading status.

setLightReceivingBitMask

void setLightReceivingBitMask (int bitMask)

Set the bit mask that determines what lights will illuminate this Node. This bit mask is bitwise and-ed (&) with each Light's influenceBitMask. If the result is > 0, then the Light will illuminate this Node. The default value is 0x1.

Parameters
bitMask int: The bit mask to set.

setShadowCastingBitMask

void setShadowCastingBitMask (int bitMask)

Set the bit mask that determines for which lights the contents of this Node will cast shadows. This bit mask is bitwise and-ed (&) with each Light's influenceBitMask. If the result is > 0, then this Node will cast shadows from the light. The default value is 0x1.

Parameters
bitMask int: The bit mask to set.

Hooray!