Class GameObjectInstantiator
Generates a GameObject hierarchy from a glTF scene
Implements
Inherited Members
Namespace: GLTFast
Assembly: glTFast.dll
Syntax
public class GameObjectInstantiator : IInstantiator
Constructors
GameObjectInstantiator(IGltfReadable, Transform, ICodeLogger, InstantiationSettings)
Constructs a GameObjectInstantiator
Declaration
public GameObjectInstantiator(IGltfReadable gltf, Transform parent, ICodeLogger logger = null, InstantiationSettings settings = null)
Parameters
Type | Name | Description |
---|---|---|
IGltfReadable | gltf | glTF to instantiate from |
Transform | parent | Generated GameObjects will get parented to this Transform |
ICodeLogger | logger | Custom logger |
InstantiationSettings | settings | Instantiation settings |
Fields
m_Gltf
glTF to instantiate from
Declaration
protected IGltfReadable m_Gltf
Field Value
Type | Description |
---|---|
IGltfReadable |
m_Logger
Instantiation logger
Declaration
protected ICodeLogger m_Logger
Field Value
Type | Description |
---|---|
ICodeLogger |
m_Nodes
glTF node index to instantiated GameObject dictionary
Declaration
protected Dictionary<uint, GameObject> m_Nodes
Field Value
Type | Description |
---|---|
Dictionary<uint, GameObject> |
m_Parent
Generated GameObjects will get parented to this Transform
Declaration
protected Transform m_Parent
Field Value
Type | Description |
---|---|
Transform |
m_Settings
Instantiation settings
Declaration
protected InstantiationSettings m_Settings
Field Value
Type | Description |
---|---|
InstantiationSettings |
Properties
SceneInstance
Contains information about the latest instance of a glTF scene
Declaration
public GameObjectSceneInstance SceneInstance { get; protected set; }
Property Value
Type | Description |
---|---|
GameObjectSceneInstance |
SceneTransform
Transform representing the scene. Root nodes will get parented to it.
Declaration
public Transform SceneTransform { get; protected set; }
Property Value
Type | Description |
---|---|
Transform |
Methods
AddAnimation(AnimationClip[])
Adds animation clips to the current scene. Only available if the built-in Animation module is enabled.
Declaration
public void AddAnimation(AnimationClip[] animationClips)
Parameters
Type | Name | Description |
---|---|---|
AnimationClip[] | animationClips | Animation clips |
AddCamera(uint, uint)
Called when a node has a camera assigned
Declaration
public virtual void AddCamera(uint nodeIndex, uint cameraIndex)
Parameters
Type | Name | Description |
---|---|---|
uint | nodeIndex | Index of the node |
uint | cameraIndex | Index of the assigned camera |
AddLightPunctual(uint, uint)
Called when a node has a punctual light assigned (KHR_lights_punctual)
Declaration
public void AddLightPunctual(uint nodeIndex, uint lightIndex)
Parameters
Type | Name | Description |
---|---|---|
uint | nodeIndex | Index of the node |
uint | lightIndex | Index of the punctual light |
AddPrimitive(uint, string, MeshResult, uint[], uint?, float[], int)
Called for adding a Primitive/Mesh to a Node.
Declaration
public virtual void AddPrimitive(uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int primitiveNumeration = 0)
Parameters
Type | Name | Description |
---|---|---|
uint | nodeIndex | Index of the node |
string | meshName | Mesh's name |
MeshResult | meshResult | The converted Mesh |
uint[] | joints | If a skin was attached, the joint indices. Null otherwise |
uint? | rootJoint | Root joint node index, if present |
float[] | morphTargetWeights | Morph target weights, if present |
int | primitiveNumeration | Primitives are numerated per Node, starting with 0 |
AddPrimitiveInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int)
Called for adding a Primitive/Mesh to a Node that uses GPU instancing (EXT_mesh_gpu_instancing) to render the same mesh/material combination many times. Similar to/called instead of AddPrimitive(uint, string, MeshResult, uint[], uint?, float[], int), without joints/skin support.
Declaration
public virtual void AddPrimitiveInstanced(uint nodeIndex, string meshName, MeshResult meshResult, uint instanceCount, NativeArray<Vector3>? positions, NativeArray<Quaternion>? rotations, NativeArray<Vector3>? scales, int primitiveNumeration = 0)
Parameters
Type | Name | Description |
---|---|---|
uint | nodeIndex | Index of the node |
string | meshName | Mesh's name |
MeshResult | meshResult | The converted Mesh |
uint | instanceCount | Number of instances |
NativeArray<Vector3>? | positions | Instance positions |
NativeArray<Quaternion>? | rotations | Instance rotations |
NativeArray<Vector3>? | scales | Instance scales |
int | primitiveNumeration | Primitives are numerated per Node, starting with 0 |
BeginScene(string, uint[])
Starts creating a scene instance. Has to be called at first and concluded by calling EndScene(uint[]).
Declaration
public virtual void BeginScene(string name, uint[] rootNodeIndices)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name of the scene |
uint[] | rootNodeIndices | Indices of root level nodes in scene |
CreateNode(uint, uint?, Vector3, Quaternion, Vector3)
Called for every Node in the glTF file
Declaration
public void CreateNode(uint nodeIndex, uint? parentIndex, Vector3 position, Quaternion rotation, Vector3 scale)
Parameters
Type | Name | Description |
---|---|---|
uint | nodeIndex | Index of node. Serves as identifier. |
uint? | parentIndex | Index of the parent's node. If it's null, the node's a root-level node |
Vector3 | position | Node's local position in hierarchy |
Quaternion | rotation | Node's local rotation in hierarchy |
Vector3 | scale | Node's local scale in hierarchy |
EndScene(uint[])
Is called at last, after all scene content has been created. Immediately afterwards the scene will be rendered, so use it to finally prepare the instance.
Declaration
public virtual void EndScene(uint[] rootNodeIndices)
Parameters
Type | Name | Description |
---|---|---|
uint[] | rootNodeIndices | Indices of root level nodes in scene |
SetNodeName(uint, string)
Sets the name of a node. If a node has no name it falls back to the first valid mesh name. Null otherwise.
Declaration
public virtual void SetNodeName(uint nodeIndex, string name)
Parameters
Type | Name | Description |
---|---|---|
uint | nodeIndex | Index of the node to be named. |
string | name | Valid name or null |
Events
EndSceneCompleted
Invoked after a scene has been instantiated.
Declaration
public event Action EndSceneCompleted
Event Type
Type | Description |
---|---|
Action |
MeshAdded
Invoked after a mesh was added to a node GameObject
Declaration
public event GameObjectInstantiator.MeshAddedDelegate MeshAdded
Event Type
Type | Description |
---|---|
GameObjectInstantiator.MeshAddedDelegate |
NodeCreated
Invoked when a node's GameObject has been created.
Declaration
public event GameObjectInstantiator.NodeCreatedDelegate NodeCreated
Event Type
Type | Description |
---|---|
GameObjectInstantiator.NodeCreatedDelegate |