Class GltfWriter
Provides glTF export independent of workflow (GameObjects/Entities)
Inherited Members
Namespace: GLTFast.Export
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; decides when/if to preempt export to preserve a stable frame rate IDeferAgent |
ICodeLogger | logger | Interface for logging (error) messages ConsoleLogger |
Methods
AddCamera(Camera, out Int32)
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 |
Int32 | cameraId | glTF camera index |
Returns
Type | Description |
---|---|
Boolean | True if camera was successfully created, false otherwise |
Implements
AddCameraToNode(Int32, Int32)
Assigns a camera to a previously added node
Declaration
public void AddCameraToNode(int nodeId, int cameraId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | nodeId | Index of the node to add the mesh to |
Int32 | cameraId | glTF camera ID to be assigned |
Implements
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 |
---|---|
Int32 | glTF image index |
Implements
AddLight(Light, out Int32)
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 |
Int32 | lightId | glTF light index |
Returns
Type | Description |
---|---|
Boolean | True if light was successfully created, false otherwise |
Implements
AddLightToNode(Int32, Int32)
Assigns a light to a previously added node
Declaration
public void AddLightToNode(int nodeId, int lightId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | nodeId | Index of the node to add the mesh to |
Int32 | lightId | glTF light ID to be assigned |
Implements
AddMaterial(Material, out Int32, IMaterialExport)
Adds a Unity material
Declaration
public bool AddMaterial(Material uMaterial, out int materialId, IMaterialExport materialExport)
Parameters
Type | Name | Description |
---|---|---|
Material | uMaterial | Unity material |
Int32 | materialId | glTF material index |
IMaterialExport | materialExport | Material converter |
Returns
Type | Description |
---|---|
Boolean | True if converting and adding material was successful, false otherwise |
Implements
AddMeshToNode(Int32, Mesh, Int32[])
Assigns a mesh to a previously added node
Declaration
public void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds)
Parameters
Type | Name | Description |
---|---|---|
Int32 | nodeId | Index of the node to add the mesh to |
Mesh | uMesh | Unity mesh to be assigned and exported |
Int32[] | materialIds | glTF materials IDs to be assigned (multiple in case of sub-meshes) |
Implements
AddNode(Nullable<float3>, Nullable<quaternion>, Nullable<float3>, UInt32[], 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 |
---|---|---|
Nullable<float3> | translation | Local translation of the node (in Unity-space) |
Nullable<quaternion> | rotation | Local rotation of the node (in Unity-space) |
Nullable<float3> | scale | Local scale of the node (in Unity-space) |
UInt32[] | children | Array of node indices that are parented to this newly created node |
String | name | Name of the node |
Returns
Type | Description |
---|---|
UInt32 | glTF node index |
Implements
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 |
---|---|
Int32 | glTF sampler index or -1 if no sampler is required |
Implements
AddScene(UInt32[], String)
Adds a scene to the glTF
Declaration
public uint AddScene(uint[] nodes, string name = null)
Parameters
Type | Name | Description |
---|---|---|
UInt32[] | nodes | Root level nodes |
String | name | Name of the scene |
Returns
Type | Description |
---|---|
UInt32 | glTF scene index |
Implements
AddTexture(Int32, Int32)
Creates a glTF texture from with a given image index
Declaration
public int AddTexture(int imageId, int samplerId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | imageId | glTF image index returned by AddImage(ImageExportBase) |
Int32 | samplerId | glTF sampler index returned by AddSampler(FilterMode, TextureWrapMode, TextureWrapMode) |
Returns
Type | Description |
---|---|
Int32 | glTF texture index |
Implements
RegisterExtensionUsage(Extension, Boolean)
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 |
Boolean | required | True if extension is required and used. False if it's used only |
Implements
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 async Task<bool> SaveToFileAndDispose(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | glTF destination file path |
Returns
Type | Description |
---|---|
Task<Boolean> | True if the glTF file was created successfully, false otherwise |
Implements
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 async Task<bool> SaveToStreamAndDispose(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | glTF destination stream |
Returns
Type | Description |
---|---|
Task<Boolean> | True if the glTF file was created successfully, false otherwise |