Skip to content

Commit

Permalink
if IsAssetImport, Prevent runtime resource allocation.
Browse files Browse the repository at this point in the history
Or temporary object when export.
  • Loading branch information
ousttrue committed Oct 23, 2024
1 parent 675bb7b commit a4af90c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace UniGLTF
/// </summary>
public class ImporterContext : IResponsibilityForDestroyObjects
{
public readonly bool IsAssetImport;
private readonly ImporterContextSettings _settings;

public ITextureDescriptorGenerator TextureDescriptorGenerator { get; protected set; }
Expand All @@ -37,8 +38,10 @@ public ImporterContext(
IReadOnlyDictionary<SubAssetKey, UnityEngine.Object> externalObjectMap = null,
ITextureDeserializer textureDeserializer = null,
IMaterialDescriptorGenerator materialGenerator = null,
ImporterContextSettings settings = null)
ImporterContextSettings settings = null,
bool isAssetImport = false)
{
IsAssetImport = isAssetImport;
_settings = settings ?? new ImporterContextSettings();
Data = data;
TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetIm

var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline);

using (var loader = new Vrm10Importer(result, externalObjectMap: extractedObjects, materialGenerator: materialGenerator))
using (var loader = new Vrm10Importer(result,
externalObjectMap: extractedObjects,
materialGenerator: materialGenerator,
isAssetImport: true))
{
// settings TextureImporters
foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable())
Expand Down
1 change: 1 addition & 0 deletions Assets/VRM10/Editor/Vrm10ExportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ protected override void ExportPath(string path)
{
Debug.Log("vrm-1.0 FreezeMesh");
var copy = GameObject.Instantiate(root);
copy.GetComponent<Vrm10Instance>().UpdateType = Vrm10Instance.UpdateTypes.None;
disposer.Push(copy);
root = copy;

Expand Down
11 changes: 8 additions & 3 deletions Assets/VRM10/Runtime/IO/Vrm10Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public Vrm10Importer(
IMaterialDescriptorGenerator materialGenerator = null,
bool useControlRig = false,
ImporterContextSettings settings = null,
IVrm10SpringBoneRuntime springboneRuntime = null
IVrm10SpringBoneRuntime springboneRuntime = null,
bool isAssetImport = false
)
: base(vrm.Data, externalObjectMap, textureDeserializer, settings: settings)
: base(vrm.Data, externalObjectMap, textureDeserializer, settings: settings, isAssetImport: isAssetImport)
{
if (vrm == null)
{
Expand Down Expand Up @@ -288,7 +289,11 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller)
await LoadSpringBoneAsync(awaitCaller, controller, springBone);
}

if (Application.isPlaying)
if (IsAssetImport)
{
controller.UpdateType = Vrm10Instance.UpdateTypes.None;
}
else
{
// EditorImport では呼ばない
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
Expand Down

0 comments on commit a4af90c

Please sign in to comment.