Skip to content

Commit

Permalink
Merge pull request #2473 from ousttrue/fix/vrm10_asset_import_flag
Browse files Browse the repository at this point in the history
[vrm10][Importer引数] ScriptedImpoter からの Import で SpringBone の初期化を回避する
  • Loading branch information
ousttrue authored Oct 25, 2024
2 parents 3b4f72e + 0d8849e commit 7dc74ea
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 7 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Threading.Tasks;
using UniGLTF;
using UniGLTF.SpringBoneJobs.Blittables;
using UnityEngine;

namespace UniVRM10
{
/// <summary>
/// SpcriptedImporter 経由の import 向け。
/// NativeArray の確保や DontDestroyOnLoad を回避。
/// </summary>
public class Vrm10NopSpringboneRuntime : IVrm10SpringBoneRuntime
{
public void Dispose()
{
}

public Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCaller)
{
return Task.CompletedTask;
}

public void Process()
{
}

public bool ReconstructSpringBone()
{
return false;
}

public void RestoreInitialTransform()
{
}

public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings)
{
}

public void SetModelLevel(Transform modelRoot, BlittableModelLevel modelSettings)
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 29 additions & 5 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 All @@ -53,7 +54,24 @@ public Vrm10Importer(
m_externalMap = new Dictionary<SubAssetKey, UnityEngine.Object>();
}

m_springboneRuntime = springboneRuntime ?? new Vrm10FastSpringboneRuntime();
m_springboneRuntime = MakeDefaultRuntime(springboneRuntime, isAssetImport);
}

static IVrm10SpringBoneRuntime MakeDefaultRuntime(IVrm10SpringBoneRuntime runtime, bool isAssetImport)
{
if (runtime != null)
{
return runtime;
}

if (isAssetImport)
{
// 何もしない dummy
return new Vrm10NopSpringboneRuntime();
}

// Vrm10Instance.MakeRuntime に移譲
return null;
}

static void AssignHumanoid(List<VrmLib.Node> nodes, UniGLTF.Extensions.VRMC_vrm.HumanBone humanBone, VrmLib.HumanoidBones key)
Expand Down Expand Up @@ -288,9 +306,15 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller)
await LoadSpringBoneAsync(awaitCaller, controller, springBone);
}

if (Application.isPlaying)
if (IsAssetImport)
{
// ScriptedImpoter から発動された。
// SpringBone のリソース確保を回避する。
// Application.isPlaying == true がありえる。
}
else
{
// EditorImport では呼ばない
// ScriptedImpoter 経由でない。
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
// RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128
// VRMC_springBone が無くても初期化する v0.127.2
Expand Down
1 change: 1 addition & 0 deletions ProjectSettings/QualitySettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ QualitySettings:
PSM: 5
PSP2: 2
Samsung TV: 2
Server: 0
Standalone: 5
Switch: 5
Tizen: 2
Expand Down

0 comments on commit 7dc74ea

Please sign in to comment.