Class GltfWriter
Provides glTF export independent of workflow (GameObjects/Entities)
Implements
Inherited Members
Namespace: GLTFast.Export
Assembly: glTFast.Export.dll
Syntax
public class GltfWriter : IGltfWritable
Constructors
GltfWriter(ExportSettings, IDeferAgent, ICodeLogger)
Provides glTF export independent of workflow (GameObjects/Entities)
Declaration
public GltfWriter(ExportSettings exportSettings = null, IDeferAgent deferAgent = null, ICodeLogger logger = null)
Parameters
Type | Name | Description |
---|---|---|
ExportSettings | exportSettings | Export settings |
IDeferAgent | deferAgent | Defer agent (IDeferAgent); decides when/if to preempt export to preserve a stable frame rate. |
ICodeLogger | logger | Interface for logging (error) messages. |
Methods
AddCamera(Camera, out int)
Creates a glTF camera based on a Unity camera
Declaration
public bool AddCamera(Camera uCamera, out int cameraId)
Parameters
Type | Name | Description |
---|---|---|
Camera | uCamera | Unity camera |
int | cameraId | glTF camera index |
Returns
Type | Description |
---|---|
bool | True if camera was successfully created, false otherwise |
AddCameraToNode(int, int)
Assigns a camera to a previously added node
Declaration
public void AddCameraToNode(int nodeId, int cameraId)
Parameters
Type | Name | Description |
---|---|---|
int | nodeId | Index of the node to add the mesh to |
int | cameraId | glTF camera ID to be assigned |
AddImage(ImageExportBase)
Adds an ImageExport to the glTF and returns the resulting image index
Declaration
public int AddImage(ImageExportBase imageExport)
Parameters
Type | Name | Description |
---|---|---|
ImageExportBase | imageExport | Image to be exported |
Returns
Type | Description |
---|---|
int | glTF image index |
AddLight(Light, out int)
Creates a glTF light based on a Unity light Uses the KHR_lights_punctual extension.
Declaration
public bool AddLight(Light uLight, out int lightId)
Parameters
Type | Name | Description |
---|---|---|
Light | uLight | Unity light |
int | lightId | glTF light index |
Returns
Type | Description |
---|---|
bool | True if light was successfully created, false otherwise |
AddLightToNode(int, int)
Assigns a light to a previously added node
Declaration
public void AddLightToNode(int nodeId, int lightId)
Parameters
Type | Name | Description |
---|---|---|
int | nodeId | Index of the node to add the mesh to |
int | lightId | glTF light ID to be assigned |
AddMaterial(Material, out int, IMaterialExport)
Adds a Unity material
Declaration
public bool AddMaterial(Material uMaterial, out int materialId, IMaterialExport materialExport)
Parameters
Type | Name | Description |
---|---|---|
Material | uMaterial | Unity material |
int | materialId | glTF material index |
IMaterialExport | materialExport | Material converter |
Returns
Type | Description |
---|---|
bool | True if converting and adding material was successful, false otherwise |
AddMeshToNode(int, Mesh, int[])
Assigns a mesh to a previously added node
Declaration
[Obsolete("Use overload with skinning parameter.")]
public void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds)
Parameters
Type | Name | Description |
---|---|---|
int | nodeId | Index of the node to add the mesh to |
Mesh | uMesh | Unity mesh to be assigned and exported |
int[] | materialIds | glTF materials IDs to be assigned (multiple in case of sub-meshes) |
AddMeshToNode(int, Mesh, int[], bool)
Assigns a mesh to a previously added node
Declaration
[Obsolete("Use overload with skinning parameter.")]
public void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds, bool skinning)
Parameters
Type | Name | Description |
---|---|---|
int | nodeId | Index of the node to add the mesh to |
Mesh | uMesh | Unity mesh to be assigned and exported |
int[] | materialIds | glTF materials IDs to be assigned (multiple in case of sub-meshes) |
bool | skinning | Skinning has been applied (e.g. SkinnedMeshRenderer). |
AddMeshToNode(int, Mesh, int[], uint[])
Assigns a mesh to a previously added node
Declaration
public void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds, uint[] joints)
Parameters
Type | Name | Description |
---|---|---|
int | nodeId | Index of the node to add the mesh to |
Mesh | uMesh | Unity mesh to be assigned and exported |
int[] | materialIds | glTF materials IDs to be assigned (multiple in case of sub-meshes) |
uint[] | joints | Node indices representing the joints of a skin. |
AddNode(float3?, quaternion?, float3?, uint[], string)
Adds a node to the glTF
Declaration
public uint AddNode(float3? translation = null, quaternion? rotation = null, float3? scale = null, uint[] children = null, string name = null)
Parameters
Type | Name | Description |
---|---|---|
float3? | translation | Local translation of the node (in Unity-space) |
quaternion? | rotation | Local rotation of the node (in Unity-space) |
float3? | scale | Local scale of the node (in Unity-space) |
uint[] | children | Array of node indices that are parented to this newly created node |
string | name | Name of the node |
Returns
Type | Description |
---|---|
uint | glTF node index |
AddSampler(FilterMode, TextureWrapMode, TextureWrapMode)
Creates a glTF sampler based on Unity filter and wrap settings
Declaration
public int AddSampler(FilterMode filterMode, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV)
Parameters
Type | Name | Description |
---|---|---|
FilterMode | filterMode | Texture filter mode |
TextureWrapMode | wrapModeU | Texture wrap mode in U direction |
TextureWrapMode | wrapModeV | Texture wrap mode in V direction |
Returns
Type | Description |
---|---|
int | glTF sampler index or -1 if no sampler is required |
AddScene(uint[], string)
Adds a scene to the glTF
Declaration
public uint AddScene(uint[] nodes, string name = null)
Parameters
Type | Name | Description |
---|---|---|
uint[] | nodes | Root level nodes |
string | name | Name of the scene |
Returns
Type | Description |
---|---|
uint | glTF scene index |
AddTexture(int, int)
Creates a glTF texture from with a given image index
Declaration
public int AddTexture(int imageId, int samplerId)
Parameters
Type | Name | Description |
---|---|---|
int | imageId | glTF image index returned by AddImage(ImageExportBase) |
int | samplerId | glTF sampler index returned by AddSampler(FilterMode, TextureWrapMode, TextureWrapMode) |
Returns
Type | Description |
---|---|
int | glTF texture index |
RegisterExtensionUsage(Extension, bool)
Registers the use of a glTF extension
Declaration
public void RegisterExtensionUsage(Extension extension, bool required = true)
Parameters
Type | Name | Description |
---|---|---|
Extension | extension | Extension's name |
bool | required | True if extension is required and used. False if it's used only |
SaveToFileAndDispose(string)
Exports the collected scenes/content as glTF, writes it to a file and disposes this object. After the export this instance cannot be re-used!
Declaration
public Task<bool> SaveToFileAndDispose(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | glTF destination file path |
Returns
Type | Description |
---|---|
Task<bool> | True if the glTF file was created successfully, false otherwise |
SaveToStreamAndDispose(Stream)
Exports the collected scenes/content as glTF, writes it to a Stream and disposes this object. Only works for self-contained glTF-Binary. After the export this instance cannot be re-used!
Declaration
public Task<bool> SaveToStreamAndDispose(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | glTF destination stream |
Returns
Type | Description |
---|---|
Task<bool> | True if the glTF file was created successfully, false otherwise |