From fd8cdcdcc39b8e8ef1bd524906eddda20be9bad4 Mon Sep 17 00:00:00 2001 From: PoChangSu Date: Tue, 3 Sep 2019 17:40:56 +0900 Subject: [PATCH] Fix the problem where Vector3 Color cannot be recognized --- Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs index b002072fd..1c5b59dd5 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs @@ -208,7 +208,25 @@ namespace UniGLTF // color if (prim.attributes.COLOR_0 != -1) { - context.colors = ctx.GLTF.GetArrayFromAccessor(prim.attributes.COLOR_0); + if (ctx.GLTF.accessors[prim.attributes.COLOR_0].TypeCount == 3) + { + var vec3Color = ctx.GLTF.GetArrayFromAccessor(prim.attributes.COLOR_0); + context.colors = new Color[vec3Color.Length]; + + for (int i = 0; i < vec3Color.Length; i++) + { + Vector3 color = vec3Color[i]; + context.colors[i] = new Color(color.x, color.y, color.z); + } + } + else if (ctx.GLTF.accessors[prim.attributes.COLOR_0].TypeCount == 4) + { + context.colors = ctx.GLTF.GetArrayFromAccessor(prim.attributes.COLOR_0); + } + else + { + throw new NotImplementedException(string.Format("unknown color type {0}", ctx.GLTF.accessors[prim.attributes.COLOR_0].type)); + } } // skin