Class GltfWriter
Provides glTF export independent of workflow (GameObjects/Entities)
Implements
Inherited Members
Namespace: Unity.Cloud.Gltfast.Export
Assembly: Unity.Cloud.Gltfast.Export.dll
Syntax
[MovedFrom(true, "GLTFast.Export", "glTFast.Export", null)]
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 | Custom logger for reporting messages. Defaults to the shared Instance (writes to Unity's Console) when |
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(uint, int)
Assigns a camera to a previously added node
Declaration
public void AddCameraToNode(uint nodeId, int cameraId)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | nodeId | Index of the node to add the camera 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(uint, int)
Assigns a light to a previously added node
Declaration
public void AddLightToNode(uint nodeId, int lightId)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | nodeId | Index of the node to add the light 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(uint, Mesh, int[], List<uint>)
Assigns a mesh to a previously added node
Declaration
public void AddMeshToNode(uint nodeId, Mesh uMesh, int[] materialIds, List<uint> joints)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | 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) |
| List<uint> | joints | Node indices representing the joints of a skin. Ownership of the list is transferred to the writer; the caller must not modify it after the call. |
AddNode(double3?, double4?, double3?, List<uint>, string)
Adds a node to the glTF
Declaration
public uint AddNode(double3? translation = null, double4? rotation = null, double3? scale = null, List<uint> children = null, string name = null)
Parameters
| Type | Name | Description |
|---|---|---|
| double3? | translation | Local translation of the node (in Unity-space) |
| double4? | rotation | Local rotation of the node (in Unity-space) |
| double3? | scale | Local scale of the node (in Unity-space) |
| List<uint> | children | Node indices that are parented to this newly created node. Ownership of the list is transferred to the writer; the caller must not modify it after the call. |
| 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(List<uint>, string)
Adds a scene to the glTF
Declaration
public uint AddScene(List<uint> nodes, string name = null)
Parameters
| Type | Name | Description |
|---|---|---|
| List<uint> | nodes | Root level nodes. Ownership of the list is transferred to the writer; the caller must not modify it after the call. |
| 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 |
SaveToFileAndDisposeAsync(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> SaveToFileAndDisposeAsync(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 |
SaveToStreamAndDisposeAsync(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> SaveToStreamAndDisposeAsync(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 |