diff --git a/Assets/UniGLTF_Samples.meta b/Assets/UniGLTF_Samples.meta new file mode 100644 index 000000000..014e1e456 --- /dev/null +++ b/Assets/UniGLTF_Samples.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 185b23fa4ec696042983ff7d4d034c86 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer.meta b/Assets/UniGLTF_Samples/GltfViewer.meta new file mode 100644 index 000000000..768195a56 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0cbb85f4efc20784db30c6c341cfef73 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.asmdef b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.asmdef new file mode 100644 index 000000000..b200fed37 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.asmdef @@ -0,0 +1,17 @@ +{ + "name": "GltfViewer", + "rootNamespace": "", + "references": [ + "GUID:da3e51d19d51a544fa14d43fee843098", + "GUID:8d76e605759c3f64a957d63ef96ada7c" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.asmdef.meta b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.asmdef.meta new file mode 100644 index 000000000..695425755 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: eb8391ca00913d347a883b6d6e855dd0 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.cs b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.cs new file mode 100644 index 000000000..fcdc21b31 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.cs @@ -0,0 +1,61 @@ +using System; +using UnityEngine; + +namespace UniGLTF.GltfViewer +{ + public class GltfViewer : MonoBehaviour + { + RuntimeGltfInstance _instance; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + public void OnOpenClicked() + { + var path = OpenFileDialog.Show("open gltf", "glb", "gltf", "zip"); + if (!path.Exists) + { + return; + } + Debug.Log($"open: {path}"); + + LoadPathAsync(path); + } + + async void LoadPathAsync(VRMShaders.PathObject path) + { + if (_instance) + { + // clear prev + _instance.Dispose(); + _instance = null; + } + + var sw = System.Diagnostics.Stopwatch.StartNew(); + try + { + _instance = await GltfUtility.LoadAsync(path.FullPath); + if (_instance == null) + { + Debug.LogWarning("LoadAsync: null"); + return; + } + Debug.Log($"LoadAsync: {sw.Elapsed}"); + _instance.ShowMeshes(); + } + catch (Exception ex) + { + Debug.LogException(ex); + } + } + } +} diff --git a/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.cs.meta b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.cs.meta new file mode 100644 index 000000000..240cde7e4 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f3d2f58b1e1adc24e9f8495bca2d9614 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.unity b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.unity new file mode 100644 index 000000000..20d44605d --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.unity @@ -0,0 +1,708 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 12 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &932029772 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 932029775} + - component: {fileID: 932029774} + - component: {fileID: 932029773} + - component: {fileID: 932029776} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &932029773 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 932029772} + m_Enabled: 1 +--- !u!20 &932029774 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 932029772} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &932029775 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 932029772} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &932029776 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 932029772} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e4bd97e0a95b5344a8369face780725d, type: 3} + m_Name: + m_EditorClassIdentifier: + RotateSpeed: 0.7 + GrabSpeed: 0.7 + DollySpeed: 1 +--- !u!1 &1029435554 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1029435555} + - component: {fileID: 1029435557} + - component: {fileID: 1029435556} + m_Layer: 5 + m_Name: Text + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1029435555 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1029435554} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1900577221} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1029435556 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1029435554} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 4 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Open +--- !u!222 &1029435557 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1029435554} + m_CullTransparentMesh: 1 +--- !u!1 &1052394165 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1052394167} + - component: {fileID: 1052394166} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &1052394166 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1052394165} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &1052394167 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1052394165} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &1400164759 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1400164764} + - component: {fileID: 1400164763} + - component: {fileID: 1400164762} + - component: {fileID: 1400164761} + - component: {fileID: 1400164760} + m_Layer: 5 + m_Name: GltfViewer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1400164760 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1400164759} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f3d2f58b1e1adc24e9f8495bca2d9614, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &1400164761 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1400164759} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!114 &1400164762 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1400164759} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} + m_Name: + m_EditorClassIdentifier: + m_UiScaleMode: 0 + m_ReferencePixelsPerUnit: 100 + m_ScaleFactor: 1 + m_ReferenceResolution: {x: 800, y: 600} + m_ScreenMatchMode: 0 + m_MatchWidthOrHeight: 0 + m_PhysicalUnit: 3 + m_FallbackScreenDPI: 96 + m_DefaultSpriteDPI: 96 + m_DynamicPixelsPerUnit: 1 + m_PresetInfoIsWorld: 0 +--- !u!223 &1400164763 +Canvas: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1400164759} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 0 + m_Camera: {fileID: 0} + m_PlaneDistance: 100 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_AdditionalShaderChannelsFlag: 0 + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 +--- !u!224 &1400164764 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1400164759} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0, y: 0, z: 0} + m_Children: + - {fileID: 1900577221} + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} +--- !u!1 &1766091833 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1766091836} + - component: {fileID: 1766091835} + - component: {fileID: 1766091834} + m_Layer: 0 + m_Name: EventSystem + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1766091834 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1766091833} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3} + m_Name: + m_EditorClassIdentifier: + m_HorizontalAxis: Horizontal + m_VerticalAxis: Vertical + m_SubmitButton: Submit + m_CancelButton: Cancel + m_InputActionsPerSecond: 10 + m_RepeatDelay: 0.5 + m_ForceModuleActive: 0 +--- !u!114 &1766091835 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1766091833} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3} + m_Name: + m_EditorClassIdentifier: + m_FirstSelected: {fileID: 0} + m_sendNavigationEvents: 1 + m_DragThreshold: 10 +--- !u!4 &1766091836 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1766091833} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1900577220 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1900577221} + - component: {fileID: 1900577224} + - component: {fileID: 1900577223} + - component: {fileID: 1900577222} + m_Layer: 5 + m_Name: Open + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1900577221 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1900577220} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1029435555} + m_Father: {fileID: 1400164764} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -815.25, y: -335} + m_SizeDelta: {x: 160, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1900577222 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1900577220} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1900577223} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1400164760} + m_TargetAssemblyTypeName: UniGLTF.GltfViewer.GltfViewer, Assembly-CSharp + m_MethodName: OnOpenClicked + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &1900577223 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1900577220} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1900577224 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1900577220} + m_CullTransparentMesh: 1 diff --git a/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.unity.meta b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.unity.meta new file mode 100644 index 000000000..ff7b6918c --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/GltfViewer.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8c138728e9f3ee648909fef7e25df157 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog.meta b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog.meta new file mode 100644 index 000000000..24b6da463 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 44073a3a41740aa4c8ce824d40628209 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/FileDialogForWindows.cs b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/FileDialogForWindows.cs new file mode 100644 index 000000000..a5caab62b --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/FileDialogForWindows.cs @@ -0,0 +1,116 @@ +#if UNITY_STANDALONE_WIN +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; + + +namespace UniGLTF.GltfViewer +{ + public static class FileDialogForWindows + { +#region GetOpenFileName + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public class OpenFileName + { + public int structSize = 0; + public IntPtr dlgOwner = IntPtr.Zero; + public IntPtr instance = IntPtr.Zero; + public String filter = null; + public String customFilter = null; + public int maxCustFilter = 0; + public int filterIndex = 0; + public String file = null; + public int maxFile = 0; + public String fileTitle = null; + public int maxFileTitle = 0; + public String initialDir = null; + public String title = null; + public int flags = 0; + public short fileOffset = 0; + public short fileExtension = 0; + public String defExt = null; + public IntPtr custData = IntPtr.Zero; + public IntPtr hook = IntPtr.Zero; + public String templateName = null; + public IntPtr reservedPtr = IntPtr.Zero; + public int reservedInt = 0; + public int flagsEx = 0; + } + + [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] + public static extern bool GetOpenFileName([In, Out] OpenFileName ofn); + /* + public static bool GetOpenFileName1([In, Out] OpenFileName ofn) + { + return GetOpenFileName(ofn); + } + */ + + [DllImport("Comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)] + private static extern bool GetSaveFileName([In, Out] OpenFileName ofn); + + static string Filter(params string[] filters) + { + return string.Join("\0", filters) + "\0"; + } + public static string FileDialog(string title, params string[] extensions) + { + OpenFileName ofn = new OpenFileName(); + ofn.structSize = Marshal.SizeOf(ofn); + + var filters = new List(); + filters.Add("All Files"); filters.Add("*.*"); + foreach(var ext in extensions) + { + filters.Add(ext); filters.Add("*" + ext); + } + ofn.filter = Filter(filters.ToArray()); + ofn.filterIndex = 2; + ofn.file = new string(new char[256]); + ofn.maxFile = ofn.file.Length; + ofn.fileTitle = new string(new char[64]); + ofn.maxFileTitle = ofn.fileTitle.Length; + ofn.initialDir = UnityEngine.Application.dataPath; + ofn.title = title; + //ofn.defExt = "PNG"; + ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR + if (!GetOpenFileName(ofn)) + { + return null; + } + + return ofn.file; + } + public static string SaveDialog(string title, string path) + { + var extension = Path.GetExtension(path); + OpenFileName ofn = new OpenFileName(); + ofn.structSize = Marshal.SizeOf(ofn); + ofn.filter = Filter("All Files", "*.*", extension, "*" + extension); + ofn.filterIndex = 2; + var chars = new char[256]; + var it = Path.GetFileName(path).GetEnumerator(); + for (int i = 0; i < chars.Length && it.MoveNext(); ++i) + { + chars[i] = it.Current; + } + ofn.file = new string(chars); + ofn.maxFile = ofn.file.Length; + ofn.fileTitle = new string(new char[64]); + ofn.maxFileTitle = ofn.fileTitle.Length; + ofn.initialDir = Path.GetDirectoryName(path); + ofn.title = title; + //ofn.defExt = "PNG"; + ofn.flags = 0x00000002 | 0x00000004; // OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + if (!GetSaveFileName(ofn)) + { + return null; + } + + return ofn.file; + } +#endregion + } +} +#endif diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs.meta b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/FileDialogForWindows.cs.meta similarity index 85% rename from Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs.meta rename to Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/FileDialogForWindows.cs.meta index 01dff5105..8e9481eea 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs.meta +++ b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/FileDialogForWindows.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 649d78dc96acf5b4f83d54cd1859e940 +guid: 130cf24d92d108741b04d52ef7eabe13 timeCreated: 1524038001 licenseType: Free MonoImporter: diff --git a/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/OpenFileDialog.cs b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/OpenFileDialog.cs new file mode 100644 index 000000000..ce69a46af --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/OpenFileDialog.cs @@ -0,0 +1,14 @@ +namespace UniGLTF.GltfViewer +{ + public static class OpenFileDialog + { + public static VRMShaders.PathObject Show(string title, params string[] extensions) + { +#if UNITY_STANDALONE_WIN + return VRMShaders.PathObject.FromFullPath(FileDialogForWindows.FileDialog(title, extensions)); +#else + return default; +#endif + } + } +} diff --git a/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/OpenFileDialog.cs.meta b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/OpenFileDialog.cs.meta new file mode 100644 index 000000000..599b87a90 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/OpenFileDialog/OpenFileDialog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0858a09f3d204dc458e9476faf4693d4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF_Samples/GltfViewer/TurnTableCamera.cs b/Assets/UniGLTF_Samples/GltfViewer/TurnTableCamera.cs new file mode 100644 index 000000000..e9014f880 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/TurnTableCamera.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace UniGLTF.GltfViewer +{ + public class TurnTableCamera : MonoBehaviour + { + [Range(0.1f, 5.0f)] + public float RotateSpeed = 0.7f; + + [Range(0.1f, 5.0f)] + public float GrabSpeed = 0.7f; + + [Range(0.1f, 5.0f)] + public float DollySpeed = 1.0f; + + struct PosRot + { + public Vector3 Position; + public Quaternion Rotation; + } + + class TurnTable + { + public float Yaw; + public float Pitch; + public float ShiftX; + public float ShiftY; + public float Distance = 2.0f; + + public void Rotate(float x, float y) + { + Yaw += x; + Pitch -= y; + Pitch = Mathf.Clamp(Pitch, -90, 90); + } + + public void Grab(float x, float y) + { + ShiftX += x * Distance; + ShiftY += y * Distance; + } + + public void Dolly(float delta) + { + if (delta > 0) + { + Distance *= 0.9f; + } + else if (delta < 0) + { + Distance *= 1.1f; + } + } + + public PosRot Calc() + { + var r = Quaternion.Euler(Pitch, Yaw, 0); + return new PosRot + { + Position = r * new Vector3(-ShiftX, -ShiftY, -Distance), + Rotation = r, + }; + } + } + private TurnTable _currentCamera = new TurnTable(); + + private List _activeCoroutines = new List(); + private void OnEnable() + { + // left mouse drag + _activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(0, diff => + { + _currentCamera.Rotate(diff.x * RotateSpeed, diff.y * RotateSpeed); + }))); + // right mouse drag + _activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(1, diff => + { + _currentCamera.Rotate(diff.x * RotateSpeed, diff.y * RotateSpeed); + }))); + // middle mouse drag + _activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(2, diff => + { + _currentCamera.Grab( + diff.x * GrabSpeed / Screen.height, + diff.y * GrabSpeed / Screen.height + ); + }))); + // mouse wheel + _activeCoroutines.Add(StartCoroutine(MouseScrollOperationCoroutine(diff => + { + _currentCamera.Dolly(diff.y * DollySpeed); + }))); + } + private void OnDisable() + { + foreach (var coroutine in _activeCoroutines) + { + StopCoroutine(coroutine); + } + _activeCoroutines.Clear(); + } + private void Update() + { + var posRot = _currentCamera.Calc(); + + transform.localRotation = posRot.Rotation; + transform.localPosition = posRot.Position; + } + private IEnumerator MouseDragOperationCoroutine(int buttonIndex, Action dragOperation) + { + while (true) + { + while (!Input.GetMouseButtonDown(buttonIndex)) + { + yield return null; + } + var prevPos = Input.mousePosition; + while (Input.GetMouseButton(buttonIndex)) + { + var currPos = Input.mousePosition; + var diff = currPos - prevPos; + dragOperation(diff); + + prevPos = currPos; + yield return null; + } + } + } + private IEnumerator MouseScrollOperationCoroutine(Action scrollOperation) + { + while (true) + { + scrollOperation(Input.mouseScrollDelta); + yield return null; + } + } + } +} diff --git a/Assets/UniGLTF_Samples/GltfViewer/TurnTableCamera.cs.meta b/Assets/UniGLTF_Samples/GltfViewer/TurnTableCamera.cs.meta new file mode 100644 index 000000000..5e9c66859 --- /dev/null +++ b/Assets/UniGLTF_Samples/GltfViewer/TurnTableCamera.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: e4bd97e0a95b5344a8369face780725d +timeCreated: 1523878901 +licenseType: Pro +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/Editor/Format/VRMSampleCopy.cs b/Assets/VRM/Editor/Format/VRMSampleCopy.cs index 3253a7743..028d90ce1 100644 --- a/Assets/VRM/Editor/Format/VRMSampleCopy.cs +++ b/Assets/VRM/Editor/Format/VRMSampleCopy.cs @@ -17,12 +17,16 @@ namespace VRM /// Assets/VRM10/Samples~ /// にコピーする /// - /// 南無 + /// Assets/UniGLTF_Samples + /// を + /// Assets/UniGLTF/Samples~ + /// にコピーする /// public static void Execute() { Copy(Path.Combine(Application.dataPath, "VRM_Samples"), Path.Combine(Application.dataPath, "VRM/Samples~")); Copy(Path.Combine(Application.dataPath, "VRM10_Samples"), Path.Combine(Application.dataPath, "VRM10/Samples~")); + Copy(Path.Combine(Application.dataPath, "UniGLTF_Samples"), Path.Combine(Application.dataPath, "UniGLTF/Samples~")); } static void Copy(string srcDir, string dstDir) diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs new file mode 100644 index 000000000..05824727f --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs @@ -0,0 +1,168 @@ +using System; +using UniGLTF; +using UniGLTF.Utils; +using UnityEngine; + +namespace UniVRM10.VRM10Viewer +{ + class Loaded : IDisposable + { + RuntimeGltfInstance m_instance; + Vrm10Instance m_controller; + + VRM10AIUEO m_lipSync; + bool m_enableLipSyncValue; + public bool EnableLipSyncValue + { + set + { + if (m_enableLipSyncValue == value) return; + m_enableLipSyncValue = value; + if (m_lipSync != null) + { + m_lipSync.enabled = m_enableLipSyncValue; + } + } + } + + VRM10AutoExpression m_autoExpression; + bool m_enableAutoExpressionValue; + public bool EnableAutoExpressionValue + { + set + { + if (m_enableAutoExpressionValue == value) return; + m_enableAutoExpressionValue = value; + if (m_autoExpression != null) + { + m_autoExpression.enabled = m_enableAutoExpressionValue; + } + } + } + + VRM10Blinker m_blink; + bool m_enableBlinkValue; + public bool EnableBlinkValue + { + set + { + if (m_blink == value) return; + m_enableBlinkValue = value; + if (m_blink != null) + { + m_blink.enabled = m_enableBlinkValue; + } + } + } + + public Loaded(RuntimeGltfInstance instance, Transform lookAtTarget) + { + m_instance = instance; + + m_controller = instance.GetComponent(); + if (m_controller != null) + { + // VRM + m_controller.UpdateType = Vrm10Instance.UpdateTypes.LateUpdate; // after HumanPoseTransfer's setPose + { + m_lipSync = instance.gameObject.AddComponent(); + m_blink = instance.gameObject.AddComponent(); + m_autoExpression = instance.gameObject.AddComponent(); + + m_controller.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.CalcYawPitchToGaze; + m_controller.Gaze = lookAtTarget; + } + } + + var animation = instance.GetComponent(); + if (animation && animation.clip != null) + { + // GLTF animation + animation.Play(animation.clip.name); + } + } + + public void Dispose() + { + // destroy GameObject + GameObject.Destroy(m_instance.gameObject); + } + + /// + /// from v0.103 + /// + /// + public void UpdateControlRigExplicit(Animator src) + { + var controlRig = m_controller.Runtime.ControlRig; + + foreach (HumanBodyBones bone in CachedEnum.GetValues()) + { + if (bone == HumanBodyBones.LastBone) + { + continue; + } + + var controlRigBone = controlRig.GetBoneTransform(bone); + if (controlRigBone == null) + { + continue; + } + + var bvhBone = src.GetBoneTransform(bone); + if (bvhBone != null) + { + // set normalized pose + controlRigBone.localRotation = bvhBone.localRotation; + } + + if (bone == HumanBodyBones.Hips) + { + controlRigBone.localPosition = bvhBone.localPosition * controlRig.InitialHipsHeight; + } + } + } + + /// + /// from v0.104 + /// + /// + public void UpdateControlRigImplicit(Animator src) + { + var dst = m_controller.GetComponent(); + + foreach (HumanBodyBones bone in CachedEnum.GetValues()) + { + if (bone == HumanBodyBones.LastBone) + { + continue; + } + + var boneTransform = dst.GetBoneTransform(bone); + if (boneTransform == null) + { + continue; + } + + var bvhBone = src.GetBoneTransform(bone); + if (bvhBone != null) + { + // set normalized pose + boneTransform.localRotation = bvhBone.localRotation; + } + + if (bone == HumanBodyBones.Hips) + { + // TODO: hips position scaling ? + boneTransform.localPosition = bvhBone.localPosition; + } + } + } + + public void TPoseControlRig() + { + var controlRig = m_controller.Runtime.ControlRig; + controlRig.EnforceTPose(); + } + } +} diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs.meta b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs.meta new file mode 100644 index 000000000..c488e4d31 --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0565f187ccc74bf41a4ce6d534422efa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index a400bd797..f298c0d83 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Threading; using UniGLTF; -using UniGLTF.Utils; using UniHumanoid; using UnityEngine; using UnityEngine.UI; @@ -190,127 +189,6 @@ namespace UniVRM10.VRM10Viewer m_target = GameObject.FindObjectOfType().gameObject; } - class Loaded : IDisposable - { - RuntimeGltfInstance m_instance; - Vrm10Instance m_controller; - - VRM10AIUEO m_lipSync; - bool m_enableLipSyncValue; - public bool EnableLipSyncValue - { - set - { - if (m_enableLipSyncValue == value) return; - m_enableLipSyncValue = value; - if (m_lipSync != null) - { - m_lipSync.enabled = m_enableLipSyncValue; - } - } - } - - VRM10AutoExpression m_autoExpression; - bool m_enableAutoExpressionValue; - public bool EnableAutoExpressionValue - { - set - { - if (m_enableAutoExpressionValue == value) return; - m_enableAutoExpressionValue = value; - if (m_autoExpression != null) - { - m_autoExpression.enabled = m_enableAutoExpressionValue; - } - } - } - - VRM10Blinker m_blink; - bool m_enableBlinkValue; - public bool EnableBlinkValue - { - set - { - if (m_blink == value) return; - m_enableBlinkValue = value; - if (m_blink != null) - { - m_blink.enabled = m_enableBlinkValue; - } - } - } - - public Loaded(RuntimeGltfInstance instance, Transform lookAtTarget) - { - m_instance = instance; - - m_controller = instance.GetComponent(); - if (m_controller != null) - { - // VRM - m_controller.UpdateType = Vrm10Instance.UpdateTypes.LateUpdate; // after HumanPoseTransfer's setPose - { - m_lipSync = instance.gameObject.AddComponent(); - m_blink = instance.gameObject.AddComponent(); - m_autoExpression = instance.gameObject.AddComponent(); - - m_controller.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.CalcYawPitchToGaze; - m_controller.Gaze = lookAtTarget; - } - } - - var animation = instance.GetComponent(); - if (animation && animation.clip != null) - { - // GLTF animation - animation.Play(animation.clip.name); - } - } - - public void Dispose() - { - // destroy GameObject - GameObject.Destroy(m_instance.gameObject); - } - - public void UpdatePose(bool useBvh, Animator bvhAnimator) - { - var controlRig = m_controller.Runtime.ControlRig; - - foreach (HumanBodyBones bone in CachedEnum.GetValues()) - { - if (bone == HumanBodyBones.LastBone) - { - continue; - } - - var controlRigBone = controlRig.GetBoneTransform(bone); - if (controlRigBone == null) - { - continue; - } - - if (useBvh && bvhAnimator != null) - { - var bvhBone = bvhAnimator.GetBoneTransform(bone); - if (bvhBone != null) - { - // set normalized pose - controlRigBone.localRotation = bvhBone.localRotation; - } - - if (bone == HumanBodyBones.Hips) - { - controlRigBone.localPosition = bvhBone.localPosition * controlRig.InitialHipsHeight; - } - } - else - { - controlRig.EnforceTPose(); - } - } - } - } Loaded m_loaded; private void Start() @@ -344,7 +222,8 @@ namespace UniVRM10.VRM10Viewer var context = new UniHumanoid.BvhImporterContext(); context.Parse("tmp.bvh", source); context.Load(); - SetMotion(context.Root.GetComponent()); + m_src = context.Root.GetComponent(); + m_ui.IsBvhEnabled = true; } private void Update() @@ -371,14 +250,21 @@ namespace UniVRM10.VRM10Viewer if (m_loaded != null) { - m_loaded.UpdatePose(m_ui.IsBvhEnabled, m_src); + if (m_ui.IsBvhEnabled && m_src != null) + { + m_loaded.UpdateControlRigImplicit(m_src); + } + else + { + m_loaded.TPoseControlRig(); + } } } void OnOpenClicked() { #if UNITY_STANDALONE_WIN - var path = VRM10FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh", "gltf", "zip"); + var path = VRM10FileDialogForWindows.FileDialog("open VRM", "vrm", "bvh"); #elif UNITY_EDITOR var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else @@ -390,19 +276,19 @@ namespace UniVRM10.VRM10Viewer } var ext = Path.GetExtension(path).ToLower(); - switch (ext) + if (ext == ".bvh") { - case ".gltf": - case ".glb": - case ".vrm": - case ".zip": - LoadModel(path); - break; - - case ".bvh": - LoadMotion(path); - break; + LoadMotion(path); + return; } + + if (ext != ".vrm") + { + Debug.LogWarning($"{path} is not vrm"); + return; + } + + LoadModel(path); } static IMaterialDescriptorGenerator GetVrmMaterialDescriptorGenerator(bool useUrp) @@ -431,11 +317,9 @@ namespace UniVRM10.VRM10Viewer async void LoadModel(string path) { - if (!File.Exists(path)) - { - return; - } - + // cleanup + m_loaded?.Dispose(); + m_loaded = null; _cancellationTokenSource?.Dispose(); _cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = _cancellationTokenSource.Token; @@ -450,38 +334,22 @@ namespace UniVRM10.VRM10Viewer materialGenerator: GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn), vrmMetaInformationCallback: m_texts.UpdateMeta, ct: cancellationToken); - if (vrm10Instance != null) + if (cancellationToken.IsCancellationRequested) { - // test. error にならなければよい - vrm10Instance.Runtime.Expression.SetWeight(ExpressionKey.Aa, 0); - - if (cancellationToken.IsCancellationRequested) - { - UnityObjectDestoyer.DestroyRuntimeOrEditor(vrm10Instance.gameObject); - cancellationToken.ThrowIfCancellationRequested(); - } - - SetModel(vrm10Instance.GetComponent()); + UnityObjectDestoyer.DestroyRuntimeOrEditor(vrm10Instance.gameObject); + cancellationToken.ThrowIfCancellationRequested(); } - else + + if (vrm10Instance == null) { - // NOTE: load as glTF model if failed to load as VRM 1.0. - // TODO: Hand over CancellationToken - var gltfModel = await GltfUtility.LoadAsync(path, - awaitCaller: m_useAsync.enabled ? (IAwaitCaller)new RuntimeOnlyAwaitCaller() : (IAwaitCaller)new ImmediateCaller()); - if (gltfModel == null) - { - throw new Exception("Failed to load the file as glTF format."); - } - - if (cancellationToken.IsCancellationRequested) - { - gltfModel.Dispose(); - cancellationToken.ThrowIfCancellationRequested(); - } - - SetModel(gltfModel); + Debug.LogWarning("LoadPathAsync is null"); + return; } + + var instance = vrm10Instance.GetComponent(); + instance.ShowMeshes(); + instance.EnableUpdateWhenOffscreen(); + m_loaded = new Loaded(instance, m_target.transform); } catch (Exception ex) { @@ -496,25 +364,5 @@ namespace UniVRM10.VRM10Viewer } } } - - void SetModel(RuntimeGltfInstance instance) - { - // cleanup - if (m_loaded != null) - { - m_loaded.Dispose(); - m_loaded = null; - } - - instance.ShowMeshes(); - instance.EnableUpdateWhenOffscreen(); - m_loaded = new Loaded(instance, m_target.transform); - } - - void SetMotion(Animator src) - { - m_src = src; - m_ui.IsBvhEnabled = true; - } } } diff --git a/Assets/VRMShaders/GLTF/IO/Editor/PathObject.cs b/Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs similarity index 100% rename from Assets/VRMShaders/GLTF/IO/Editor/PathObject.cs rename to Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs diff --git a/Assets/VRMShaders/GLTF/IO/Editor/PathObject.cs.meta b/Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs.meta similarity index 100% rename from Assets/VRMShaders/GLTF/IO/Editor/PathObject.cs.meta rename to Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs.meta diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog.meta b/Assets/VRM_Samples/SimpleViewer/FileDialog.meta new file mode 100644 index 000000000..54eb02a82 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5b0aac758a2a5ab42aab2ccf5cf5480a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileDialogForWindows.cs similarity index 98% rename from Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs rename to Assets/VRM_Samples/SimpleViewer/FileDialog/FileDialogForWindows.cs index 2979219ae..3313c7e8a 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileDialogForWindows.cs @@ -3,14 +3,13 @@ using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; -#endif namespace VRM.SimpleViewer { public static class FileDialogForWindows { -#if UNITY_STANDALONE_WIN + #region GetOpenFileName [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public class OpenFileName @@ -63,7 +62,7 @@ namespace VRM.SimpleViewer var filters = new List(); filters.Add("All Files"); filters.Add("*.*"); - foreach(var ext in extensions) + foreach (var ext in extensions) { filters.Add(ext); filters.Add("*" + ext); } @@ -113,6 +112,6 @@ namespace VRM.SimpleViewer return ofn.file; } #endregion -#endif } } +#endif diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileDialogForWindows.cs.meta b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileDialogForWindows.cs.meta new file mode 100644 index 000000000..62f148e8b --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileDialogForWindows.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a56b2b48ad6a1a4897d1de96cac39db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs new file mode 100644 index 000000000..949e78810 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs @@ -0,0 +1,25 @@ +namespace VRM.SimpleViewer +{ + public static class FileUtil + { + public static string OpenFileDialog(string title, params string[] extensions) + { +#if UNITY_STANDALONE_WIN + return FileDialogForWindows.FileDialog("open VRM", "vrm", "bvh"); +#elif UNITY_WEBGL + // Open WebGLFileDialog + // see: Assets\VRM_Samples\SimpleViewer\Plugins\OpenFile.jslib + WebGLFileDialog(); + // Control flow does not return here. return empty string with dummy + return ""; +#elif UNITY_EDITOR + // EditorUtility.OpenFilePanel + // TODO: How to specify multiple extensions on OSX? + return UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); +#else + // fall back constant path + return Application.dataPath + "/default.vrm"; +#endif + } + } +} diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs.meta b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs.meta new file mode 100644 index 000000000..35fbbc6c7 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 952ae2eb9c0c59b4ba3ed6344bd867c4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs new file mode 100644 index 000000000..1d94e2de8 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs @@ -0,0 +1,12 @@ +#if UNITY_WEBGL +using System.Runtime.InteropServices; + +namespace VRM.SimpleViewer +{ + public static class WebGLUtil + { + [DllImport("__Internal")] + public static extern void WebGLFileDialog(); + } +} +#endif \ No newline at end of file diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs.meta b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs.meta new file mode 100644 index 000000000..1e02c7954 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b12500e13ead097488e89244d024ed2d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_Samples/SimpleViewer/Loaded.cs b/Assets/VRM_Samples/SimpleViewer/Loaded.cs new file mode 100644 index 000000000..97ee72b13 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/Loaded.cs @@ -0,0 +1,118 @@ +using System; +using UniGLTF; +using UniHumanoid; +using UnityEngine; + +namespace VRM.SimpleViewer +{ + class Loaded : IDisposable + { + RuntimeGltfInstance _instance; + VRMBlendShapeProxy m_proxy; + + Blinker m_blink; + bool m_enableBlinkValue; + public bool EnableBlinkValue + { + set + { + if (m_blink == value) return; + m_enableBlinkValue = value; + if (m_blink != null) + { + m_blink.enabled = m_enableBlinkValue; + } + } + } + + AIUEO m_lipSync; + bool m_enableLipSyncValue; + public bool EnableLipSyncValue + { + set + { + if (m_enableLipSyncValue == value) return; + m_enableLipSyncValue = value; + if (m_lipSync != null) + { + m_lipSync.enabled = m_enableLipSyncValue; + } + } + } + + public Loaded(RuntimeGltfInstance instance, HumanPoseTransfer src, Transform lookAtTarget) + { + _instance = instance; + + var lookAt = instance.GetComponent(); + if (lookAt != null) + { + // vrm + _pose = _instance.gameObject.AddComponent(); + _pose.Source = src; + _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; + + m_lipSync = instance.gameObject.AddComponent(); + m_blink = instance.gameObject.AddComponent(); + + lookAt.Target = lookAtTarget; + lookAt.UpdateType = UpdateType.LateUpdate; // after HumanPoseTransfer's setPose + + m_proxy = instance.GetComponent(); + } + + // not vrm + var animation = instance.GetComponent(); + if (animation && animation.clip != null) + { + animation.Play(animation.clip.name); + } + } + + public void Dispose() + { + // Destroy game object. not RuntimeGltfInstance + GameObject.Destroy(_instance.gameObject); + } + + public void Update() + { + if (m_proxy != null) + { + m_proxy.Apply(); + } + } + + HumanPoseTransfer _pose; + + + public void EnableBvh(HumanPoseTransfer src) + { + if (_pose != null) + { + _pose.Source = src; + _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; + } + } + + public void EnableTPose(HumanPoseClip pose) + { + if (_pose != null) + { + _pose.PoseClip = pose; + _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseClip; + } + } + + public void ResetSpring() + { + if (_pose != null) + { + foreach (var spring in _pose.GetComponentsInChildren()) + { + spring.Setup(); + } + } + } + } +} diff --git a/Assets/VRM_Samples/SimpleViewer/Loaded.cs.meta b/Assets/VRM_Samples/SimpleViewer/Loaded.cs.meta new file mode 100644 index 000000000..0af4b4027 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/Loaded.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd86f9044da608b4883f7bec5167a160 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs b/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs index 41dc1ce84..2b6bea54c 100644 --- a/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs @@ -2,7 +2,6 @@ using System.Collections; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Threading.Tasks; using UniGLTF; using UniHumanoid; @@ -13,13 +12,11 @@ using VRMShaders; namespace VRM.SimpleViewer { + /// + /// UI event handling + /// public class ViewerUI : MonoBehaviour { -#if UNITY_WEBGL - [DllImport("__Internal")] - private static extern void WebGLFileDialog(); -#endif - #region UI [SerializeField] Text m_version = default; @@ -196,118 +193,8 @@ namespace VRM.SimpleViewer m_target = GameObject.FindObjectOfType().gameObject; } - class Loaded : IDisposable - { - RuntimeGltfInstance _instance; - HumanPoseTransfer _pose; - VRMBlendShapeProxy m_proxy; - - Blinker m_blink; - bool m_enableBlinkValue; - public bool EnableBlinkValue - { - set - { - if (m_blink == value) return; - m_enableBlinkValue = value; - if (m_blink != null) - { - m_blink.enabled = m_enableBlinkValue; - } - } - } - - AIUEO m_lipSync; - bool m_enableLipSyncValue; - public bool EnableLipSyncValue - { - set - { - if (m_enableLipSyncValue == value) return; - m_enableLipSyncValue = value; - if (m_lipSync != null) - { - m_lipSync.enabled = m_enableLipSyncValue; - } - } - } - - public Loaded(RuntimeGltfInstance instance, HumanPoseTransfer src, Transform lookAtTarget) - { - _instance = instance; - - var lookAt = instance.GetComponent(); - if (lookAt != null) - { - // vrm - _pose = _instance.gameObject.AddComponent(); - _pose.Source = src; - _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; - - m_lipSync = instance.gameObject.AddComponent(); - m_blink = instance.gameObject.AddComponent(); - - lookAt.Target = lookAtTarget; - lookAt.UpdateType = UpdateType.LateUpdate; // after HumanPoseTransfer's setPose - - m_proxy = instance.GetComponent(); - } - - // not vrm - var animation = instance.GetComponent(); - if (animation && animation.clip != null) - { - animation.Play(animation.clip.name); - } - } - - public void Dispose() - { - // Destroy game object. not RuntimeGltfInstance - GameObject.Destroy(_instance.gameObject); - } - - public void EnableBvh(HumanPoseTransfer src) - { - if (_pose != null) - { - _pose.Source = src; - _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; - } - } - - public void EnableTPose(HumanPoseClip pose) - { - if (_pose != null) - { - _pose.PoseClip = pose; - _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseClip; - } - } - - public void OnResetClicked() - { - if (_pose != null) - { - foreach (var spring in _pose.GetComponentsInChildren()) - { - spring.Setup(); - } - } - } - - public void Update() - { - if (m_proxy != null) - { - m_proxy.Apply(); - } - } - } Loaded m_loaded; - - private void Start() { m_version.text = string.Format("VRMViewer {0}.{1}", @@ -316,7 +203,7 @@ namespace VRM.SimpleViewer m_useFastSpringBone.onValueChanged.AddListener(OnUseFastSpringBoneValueChanged); OnUseFastSpringBoneValueChanged(m_useFastSpringBone.isOn); - m_reset.onClick.AddListener(() => m_loaded.OnResetClicked()); + m_reset.onClick.AddListener(() => m_loaded?.ResetSpring()); // load initial bvh if (m_motion != null) @@ -338,7 +225,9 @@ namespace VRM.SimpleViewer var context = new UniHumanoid.BvhImporterContext(); context.Parse(path, source); context.Load(); - SetMotion(context.Root.GetComponent()); + m_src = context.Root.GetComponent(); + m_src.GetComponent().enabled = false; + m_loaded?.EnableBvh(m_src); } private void Update() @@ -348,7 +237,9 @@ namespace VRM.SimpleViewer if (Root != null) Root.SetActive(!Root.activeSelf); } - m_ui.UpdateToggle(() => m_loaded?.EnableBvh(m_src), () => m_loaded?.EnableTPose(m_pose)); + m_ui.UpdateToggle( + () => m_loaded?.EnableBvh(m_src), + () => m_loaded?.EnableTPose(m_pose)); if (m_loaded != null) { @@ -358,39 +249,30 @@ namespace VRM.SimpleViewer } } - IEnumerator LoadTexture(string url) + IEnumerator LoadCoroutine(string url) { - var www = new WWW(url); + var www = new UnityEngine.Networking.UnityWebRequest(url); yield return www; - LoadModelAsync("tmp.vrm", www.bytes); + var task = LoadBytesAsync("WebGL.vrm", www.downloadHandler.data); } + /// + /// for WebGL + /// call from OpenFile.jslib + /// public void FileSelected(string url) { Debug.Log($"FileSelected: {url}"); - StartCoroutine(LoadTexture(url)); + StartCoroutine(LoadCoroutine(url)); } void OnOpenClicked() { -#if UNITY_STANDALONE_WIN - var path = FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh", "gltf", "zip"); -#elif UNITY_WEBGL - { - WebGLFileDialog(); - return; - } - var path = ""; -#elif UNITY_EDITOR - var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); -#else - var path = Application.dataPath + "/default.vrm"; -#endif + var path = FileUtil.OpenFileDialog("Open VRM", "vrm", "bvh"); if (string.IsNullOrEmpty(path)) { return; } - LoadPathAsync(path); } @@ -401,41 +283,44 @@ namespace VRM.SimpleViewer Debug.LogWarning($"{path} not exists"); return; } - LoadModelAsync(path, File.ReadAllBytes(path)); + var bytes = File.ReadAllBytes(path); + await LoadBytesAsync(path, bytes); } - async void LoadModelAsync(string path, byte[] bytes) + public async Task LoadBytesAsync(string path, byte[] bytes) { var size = bytes != null ? bytes.Length : 0; Debug.Log($"LoadModelAsync: {path}: {size}bytes"); var ext = Path.GetExtension(path).ToLower(); - switch (ext) + if (ext == ".bvh") { - case ".gltf": - case ".glb": - case ".zip": - { - var instance = await GltfUtility.LoadAsync(path, - GetIAwaitCaller(m_useAsync.isOn), - GetGltfMaterialGenerator(m_useUrpMaterial.isOn)); - SetModel(instance); - break; - } - - case ".vrm": - { - VrmUtility.MaterialGeneratorCallback materialCallback = (VRM.glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm); - VrmUtility.MetaCallback metaCallback = m_texts.UpdateMeta; - var instance = await VrmUtility.LoadBytesAsync(path, bytes, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback, loadAnimation: m_loadAnimation.isOn); - SetModel(instance); - break; - } - - case ".bvh": - LoadMotion(path, File.ReadAllText(path)); - break; + // bvh motion + LoadMotion(path, File.ReadAllText(path)); + return; } + + // cleanup + if (m_loaded != null) + { + m_loaded.Dispose(); + m_loaded = null; + } + + // vrm + VrmUtility.MaterialGeneratorCallback materialCallback = (VRM.glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm); + VrmUtility.MetaCallback metaCallback = m_texts.UpdateMeta; + var instance = await VrmUtility.LoadBytesAsync(path, bytes, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback, loadAnimation: m_loadAnimation.isOn); + + if (m_useFastSpringBone.isOn) + { + var _ = FastSpringBoneReplacer.ReplaceAsync(instance.Root); + } + + instance.EnableUpdateWhenOffscreen(); + instance.ShowMeshes(); + + m_loaded = new Loaded(instance, m_src, m_target.transform); } void OnUseFastSpringBoneValueChanged(bool flag) @@ -482,35 +367,5 @@ namespace VRM.SimpleViewer return new ImmediateCaller(); } } - - void SetModel(RuntimeGltfInstance instance) - { - // cleanup - if (m_loaded != null) - { - m_loaded.Dispose(); - m_loaded = null; - } - - if (m_useFastSpringBone.isOn) - { - var _ = FastSpringBoneReplacer.ReplaceAsync(instance.Root); - } - - instance.EnableUpdateWhenOffscreen(); - instance.ShowMeshes(); - - m_loaded = new Loaded(instance, m_src, m_target.transform); - } - - void SetMotion(HumanPoseTransfer src) - { - m_src = src; - src.GetComponent().enabled = false; - if (m_loaded != null) - { - m_loaded.EnableBvh(src); - } - } } }