// SPDX-FileCopyrightText: 2023 Unity Technologies and the Draco for Unity authors
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
namespace Draco.Sample.SceneEncodeDecode
{
///
/// Lets you assigns Draco data (in form of a ) to one or more
/// targets and decode them at runtime.
///
///
public class DecodeInstance : ScriptableObject
{
[SerializeField]
TextAsset dracoAsset;
[SerializeField]
Bounds bounds;
[SerializeField]
List targets;
///
/// Decodes the Draco data and assigns it to all targets.
///
/// A
public async Task Decode()
{
var mesh = await DracoDecoder.DecodeMesh(dracoAsset.bytes);
mesh.bounds = bounds;
#if DEBUG
mesh.name = dracoAsset.name;
#endif
foreach (var meshFilter in targets)
{
meshFilter.mesh = mesh;
}
}
///
/// Sets the Draco data asset and its bounds.
///
/// Draco data.
/// Bounds of the decoded Draco mesh.
public void SetAsset(TextAsset newDracoAsset, Bounds newBounds)
{
dracoAsset = newDracoAsset;
bounds = newBounds;
}
///
/// Adds a target that the Draco mesh will be assigned to when is
/// invoked.
///
/// New target to be added
public void AddTarget(MeshFilter meshFilter)
{
if (targets == null) targets = new List();
targets.Add(meshFilter);
}
}
}