diff --git a/Assets/UniGLTF/Runtime/Extensions/glTFExtensions.cs b/Assets/UniGLTF/Runtime/Extensions/glTFExtensions.cs index 02edf3e123..05b5582ce7 100644 --- a/Assets/UniGLTF/Runtime/Extensions/glTFExtensions.cs +++ b/Assets/UniGLTF/Runtime/Extensions/glTFExtensions.cs @@ -316,17 +316,26 @@ public static T[] GetArrayFromAccessor(this glTF self, int accessorIndex) whe return result; } - public static float[] GetFloatArrayFromAccessor(this glTF self, int accessorIndex) + public static float[] FlatternFloatArrayFromAccessor(this glTF self, int accessorIndex) { var vertexAccessor = self.accessors[accessorIndex]; if (vertexAccessor.count <= 0) return new float[] { }; var bufferCount = vertexAccessor.count * vertexAccessor.TypeCount; - var result = (vertexAccessor.bufferView != -1) - ? self.GetAttrib(bufferCount, vertexAccessor.byteOffset, self.bufferViews[vertexAccessor.bufferView]) - : new float[bufferCount] - ; + + float[] result = null; + if(vertexAccessor.bufferView != -1){ + var attrib = new float[vertexAccessor.count * vertexAccessor.TypeCount]; + var view = self.bufferViews[vertexAccessor.bufferView]; + var segment = self.buffers[view.buffer].GetBytes(); + var bytes = new ArraySegment(segment.Array, segment.Offset + view.byteOffset + vertexAccessor.byteOffset, vertexAccessor.count * view.byteStride); + bytes.MarshalCopyTo(attrib); + result = attrib; + } + else{ + result = new float[bufferCount]; + } var sparse = vertexAccessor.sparse; if (sparse != null && sparse.count > 0) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs index 9cd5fd680d..b300827ab9 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs @@ -202,7 +202,7 @@ public static AnimationClip ConvertAnimationClip(glTF gltf, glTFAnimation animat { var sampler = animation.samplers[channel.sampler]; var input = gltf.GetArrayFromAccessor(sampler.input); - var output = gltf.GetFloatArrayFromAccessor(sampler.output); + var output = gltf.FlatternFloatArrayFromAccessor(sampler.output); AnimationImporterUtil.SetAnimationCurve( clip, @@ -225,7 +225,7 @@ public static AnimationClip ConvertAnimationClip(glTF gltf, glTFAnimation animat { var sampler = animation.samplers[channel.sampler]; var input = gltf.GetArrayFromAccessor(sampler.input); - var output = gltf.GetFloatArrayFromAccessor(sampler.output); + var output = gltf.FlatternFloatArrayFromAccessor(sampler.output); AnimationImporterUtil.SetAnimationCurve( clip, @@ -251,7 +251,7 @@ public static AnimationClip ConvertAnimationClip(glTF gltf, glTFAnimation animat { var sampler = animation.samplers[channel.sampler]; var input = gltf.GetArrayFromAccessor(sampler.input); - var output = gltf.GetFloatArrayFromAccessor(sampler.output); + var output = gltf.FlatternFloatArrayFromAccessor(sampler.output); AnimationImporterUtil.SetAnimationCurve( clip, diff --git a/Assets/VRM.Samples/Scripts/ViewerUI.cs b/Assets/VRM.Samples/Scripts/ViewerUI.cs index bb640dbe49..6de3d72ca2 100644 --- a/Assets/VRM.Samples/Scripts/ViewerUI.cs +++ b/Assets/VRM.Samples/Scripts/ViewerUI.cs @@ -264,7 +264,7 @@ void EnableTPose() void OnOpenClicked() { #if UNITY_STANDALONE_WIN - var path = FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh"); + var path = FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh", "gltf", "zip"); #elif UNITY_EDITOR var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else @@ -281,6 +281,7 @@ void OnOpenClicked() case ".gltf": case ".glb": case ".vrm": + case ".zip": LoadModel(path); break; @@ -328,6 +329,19 @@ void LoadModel(string path) break; } + case ".gltf": + case ".zip": + { + var context = new UniGLTF.ImporterContext(); + context.Parse(path); + context.Load(); + context.ShowMeshes(); + context.EnableUpdateWhenOffscreen(); + context.ShowMeshes(); + SetModel(context.Root); + break; + } + default: Debug.LogWarningFormat("unknown file type: {0}", path); break;