// SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
using System;
using System.IO;
using System.Threading.Tasks;
using Unity.Mathematics;
using UnityEngine;
namespace GLTFast.Export
{
///
/// Is able to receive asset resources and export them to glTF
///
public interface IGltfWritable
{
///
/// Adds a node to the glTF
///
/// Local translation of the node (in Unity-space)
/// Local rotation of the node (in Unity-space)
/// Local scale of the node (in Unity-space)
/// Array of node indices that are parented to
/// this newly created node
/// Name of the node
/// glTF node index
uint AddNode(
float3? translation = null,
quaternion? rotation = null,
float3? scale = null,
uint[] children = null,
string name = null
);
///
/// Assigns a mesh to a previously added node
///
/// Index of the node to add the mesh to
/// Unity mesh to be assigned and exported
/// glTF materials IDs to be assigned
/// (multiple in case of sub-meshes)
[Obsolete("Use overload with skinning parameter.")]
void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds);
///
/// Assigns a mesh to a previously added node
///
/// Index of the node to add the mesh to
/// Unity mesh to be assigned and exported
/// glTF materials IDs to be assigned
/// (multiple in case of sub-meshes)
/// Skinning has been applied (e.g. ).
[Obsolete("Use overload with joints parameter.")]
void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds, bool skinning);
///
/// Assigns a mesh to a previously added node
///
/// Index of the node to add the mesh to
/// Unity mesh to be assigned and exported
/// glTF materials IDs to be assigned
/// (multiple in case of sub-meshes)
/// Node indices representing the joints of a skin.
void AddMeshToNode(int nodeId, Mesh uMesh, int[] materialIds, uint[] joints);
///
/// Assigns a camera to a previously added node
///
/// Index of the node to add the mesh to
/// glTF camera ID to be assigned
void AddCameraToNode(int nodeId, int cameraId);
///
/// Assigns a light to a previously added node
///
/// Index of the node to add the mesh to
/// glTF light ID to be assigned
void AddLightToNode(int nodeId, int lightId);
///
/// Adds a Unity material
///
/// Unity material
/// glTF material index
/// Material converter
/// True if converting and adding material was successful, false otherwise
bool AddMaterial(Material uMaterial, out int materialId, IMaterialExport materialExport);
///
/// Adds an ImageExport to the glTF and returns the resulting image index
///
/// Image to be exported
/// glTF image index
int AddImage(ImageExportBase imageExport);
///
/// Creates a glTF texture from with a given image index
///
/// glTF image index returned by
/// glTF sampler index returned by
/// glTF texture index
int AddTexture(int imageId, int samplerId);
///
/// Creates a glTF sampler based on Unity filter and wrap settings
///
/// Texture filter mode
/// Texture wrap mode in U direction
/// Texture wrap mode in V direction
/// glTF sampler index or -1 if no sampler is required
int AddSampler(FilterMode filterMode, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV);
///
/// Creates a glTF camera based on a Unity camera
///
/// Unity camera
/// glTF camera index
/// True if camera was successfully created, false otherwise
bool AddCamera(Camera uCamera, out int cameraId);
///
/// Creates a glTF light based on a Unity light
/// Uses the KHR_lights_punctual extension.
///
/// Unity light
/// glTF light index
/// True if light was successfully created, false otherwise
bool AddLight(Light uLight, out int lightId);
///
/// Adds a scene to the glTF
///
/// Root level nodes
/// Name of the scene
/// glTF scene index
uint AddScene(uint[] nodes, string name = null);
///
/// Registers the use of a glTF extension
///
/// Extension's name
/// True if extension is required and used. False if it's used only
void RegisterExtensionUsage(Extension extension, bool required = true);
///
/// 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!
///
/// glTF destination file path
/// True if the glTF file was created successfully, false otherwise
Task SaveToFileAndDispose(string path);
///
/// 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!
///
/// glTF destination stream
/// True if the glTF file was created successfully, false otherwise
Task SaveToStreamAndDispose(Stream stream);
}
}