Interface IInstantiator
After parsing and loading a glTF's content and converting its content into Unity resources,the second step is instantiation. Implementors of this interface can convert glTF resources into scene objects.
Namespace: GLTFast
Assembly: glTFast.dll
Syntax
public interface IInstantiator
Methods
AddAnimation(AnimationClip[])
Adds animation clips to the current scene. Only available if the built-in Animation module is enabled.
Declaration
void AddAnimation(AnimationClip[] animationClips)
Parameters
| Type | Name | Description |
|---|---|---|
| AnimationClip[] | animationClips | Animation clips |
AddCamera(uint, uint)
Called when a node has a camera assigned
Declaration
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
void AddLightPunctual(uint nodeIndex, uint lightIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | nodeIndex | Index of the node |
| uint | lightIndex | Index of the punctual light |
AddMesh(uint, string, MeshResult, uint[], uint?, float[], int)
Adds a Mesh/MeshResult to a Node for rendering purpose.
Declaration
void AddMesh(uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int meshNumeration = 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 | meshNumeration | Per glTF mesh MeshResult numeration. A glTF mesh is converted into one or more MeshResults which are numbered consecutively. AddMesh(uint, string, MeshResult, uint[], uint?, float[], int) is called once for each of those MeshResults. |
Remarks
This is the method the importer calls, so implementing it is preferred, but implementors still have to declare the obsolete AddPrimitive(uint, string, MeshResult, uint[], uint?, float[], int) until version 7.0 removes it.
AddMeshInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int)
Adds a Mesh/MeshResult to a Node with the purpose of rendering multiple instances of this MeshResult and material combination (through glTF extension EXT_mesh_gpu_instancing). In contrast to AddMesh(uint, string, MeshResult, uint[], uint?, float[], int) it lacks joints/skin support.
Declaration
void AddMeshInstanced(uint nodeIndex, string meshName, MeshResult meshResult, uint instanceCount, NativeArray<Vector3>? positions, NativeArray<Quaternion>? rotations, NativeArray<Vector3>? scales, int meshNumeration = 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 | meshNumeration | Per glTF mesh MeshResult numeration. A glTF mesh is converted into one or more MeshResults which are numbered consecutively. AddMeshInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int) is called once for each of those MeshResults. |
Remarks
This is the method the importer calls, so implementing it is preferred, but implementors still have to declare the obsolete AddPrimitiveInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int) until version 7.0 removes it.
AddPrimitive(uint, string, MeshResult, uint[], uint?, float[], int)
Obsolete predecessor of AddMesh(uint, string, MeshResult, uint[], uint?, float[], int).
Declaration
[Obsolete("Use AddMesh instead.")]
void AddPrimitive(uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int meshNumeration = 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 | meshNumeration | Per glTF mesh MeshResult numeration. A glTF mesh is converted into one or more MeshResults which are numbered consecutively. AddPrimitive(uint, string, MeshResult, uint[], uint?, float[], int) is called once for each of those MeshResults. |
AddPrimitiveInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int)
Obsolete predecessor of AddMeshInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int).
Declaration
[Obsolete("Use AddMeshInstanced instead.")]
void AddPrimitiveInstanced(uint nodeIndex, string meshName, MeshResult meshResult, uint instanceCount, NativeArray<Vector3>? positions, NativeArray<Quaternion>? rotations, NativeArray<Vector3>? scales, int meshNumeration = 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 | meshNumeration | Per glTF mesh MeshResult numeration. A glTF mesh is converted into one or more MeshResults which are numbered consecutively. AddPrimitiveInstanced(uint, string, MeshResult, uint, NativeArray<Vector3>?, NativeArray<Quaternion>?, NativeArray<Vector3>?, int) is called once for each of those MeshResults. |
BeginScene(string, uint[])
Starts creating a scene instance. Has to be called at first and concluded by calling EndScene(uint[]).
Declaration
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
[Obsolete("Implement the CreateNode overload that takes a name instead.")]
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 |
CreateNode(uint, uint?, Vector3, Quaternion, Vector3, string)
Called for every Node in the glTF file.
Declaration
void CreateNode(uint nodeIndex, uint? parentIndex, Vector3 position, Quaternion rotation, Vector3 scale, string name)
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 |
| string | name | Node's name. Falls back to the first valid mesh name. Null otherwise. |
Remarks
All three of this method, the parameterless-name CreateNode(uint, uint?, Vector3, Quaternion, Vector3) overload and SetNodeName(uint, string) have default implementations, so an implementation that overrides none of them compiles but creates no nodes.
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
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
[Obsolete("Implement the CreateNode overload that takes a name instead.")]
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 |