// SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors // SPDX-License-Identifier: Apache-2.0 using Unity.Collections; using UnityEngine; namespace GLTFast { /// /// 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. /// public interface IInstantiator { /// /// Starts creating a scene instance. /// Has to be called at first and concluded by calling /// . /// /// Name of the scene /// Indices of root level nodes in scene void BeginScene( string name , uint[] rootNodeIndices ); #if UNITY_ANIMATION /// /// Adds animation clips to the current scene. /// Only available if the built-in Animation module is enabled. /// /// Animation clips void AddAnimation(AnimationClip[] animationClips); #endif /// /// Called for every Node in the glTF file /// /// Index of node. Serves as identifier. /// Index of the parent's node. If it's null, /// the node's a root-level node /// Node's local position in hierarchy /// Node's local rotation in hierarchy /// Node's local scale in hierarchy void CreateNode( uint nodeIndex, uint? parentIndex, Vector3 position, Quaternion rotation, Vector3 scale ); /// /// Sets the name of a node. /// If a node has no name it falls back to the first valid mesh name. /// Null otherwise. /// /// Index of the node to be named. /// Valid name or null void SetNodeName(uint nodeIndex, string name); /// /// Adds a Mesh/MeshResult to a Node for rendering purpose. /// /// Index of the node /// Mesh's name /// The converted Mesh /// If a skin was attached, the joint indices. Null otherwise /// Root joint node index, if present /// Morph target weights, if present /// Per glTF mesh numeration. A glTF mesh is converted /// into one or more MeshResults which are numbered consecutively. is called once /// for each of those MeshResults. void AddPrimitive( uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int meshNumeration = 0 ); /// /// 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 it lacks joints/skin support. /// /// Index of the node /// Mesh's name /// The converted Mesh /// Number of instances /// Instance positions /// Instance rotations /// Instance scales /// Per glTF mesh numeration. A glTF mesh is converted /// into one or more MeshResults which are numbered consecutively. is called once /// for each of those MeshResults. void AddPrimitiveInstanced( uint nodeIndex, string meshName, MeshResult meshResult, uint instanceCount, NativeArray? positions, NativeArray? rotations, NativeArray? scales, int meshNumeration = 0 ); /// /// Called when a node has a camera assigned /// /// Index of the node /// Index of the assigned camera void AddCamera( uint nodeIndex, uint cameraIndex ); /// /// Called when a node has a punctual light assigned (KHR_lights_punctual) /// /// Index of the node /// Index of the punctual light void AddLightPunctual( uint nodeIndex, uint lightIndex ); /// /// 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. /// /// Indices of root level nodes in scene void EndScene( uint[] rootNodeIndices ); } }