示例#1
0
        public static glTF_VRM_BlendShapeBind Create(Transform root, BlendShapeBinding binding,
                                                     gltfExporter exporter)
        {
            var transform = UniGLTF.UnityExtensions.GetFromPath(root.transform, binding.RelativePath);
            var renderer  = transform.GetComponent <SkinnedMeshRenderer>();

            if (renderer == null)
            {
                return(null);
            }

            if (!renderer.gameObject.activeInHierarchy)
            {
                return(null);
            }

            var mesh      = renderer.sharedMesh;
            var meshIndex = exporter.Meshes.IndexOf(mesh);

            if (meshIndex == -1)
            {
                return(null);
            }

            if (!exporter.MeshBlendShapeIndexMap.TryGetValue(mesh, out Dictionary <int, int> blendShapeIndexMap))
            {
                // この Mesh は  エクスポートされていない
                return(null);
            }

            if (!blendShapeIndexMap.TryGetValue(binding.Index, out int blendShapeIndex))
            {
                // この blendShape は エクスポートされていない(空だった?)
                return(null);
            }

            return(new glTF_VRM_BlendShapeBind
            {
                mesh = meshIndex,
                index = blendShapeIndex,
                weight = binding.Weight,
            });
        }
        static bool ClipsContainsName(List <BlendShapeClip> clips, bool onlyPreset, BlendShapeBinding binding)
        {
            foreach (var c in clips)
            {
                if (onlyPreset)
                {
                    if (c.Preset == BlendShapePreset.Unknown)
                    {
                        continue;
                    }
                }

                foreach (var b in c.Values)
                {
                    if (b.RelativePath == binding.RelativePath && b.Index == binding.Index)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#3
0
        public static glTF_VRM_BlendShapeBind Create(Transform root, List <Mesh> meshes, BlendShapeBinding binding)
        {
            var transform = UniGLTF.UnityExtensions.GetFromPath(root.transform, binding.RelativePath);
            var renderer  = transform.GetComponent <SkinnedMeshRenderer>();

            if (renderer == null)
            {
                return(null);
            }

            if (!renderer.gameObject.activeInHierarchy)
            {
                return(null);
            }

            var mesh      = renderer.sharedMesh;
            var meshIndex = meshes.IndexOf(mesh);

            if (meshIndex == -1)
            {
                return(null);
            }

            return(new glTF_VRM_BlendShapeBind
            {
                mesh = meshIndex,
                index = binding.Index,
                weight = binding.Weight,
            });
        }
示例#4
0
 public static glTF_VRM_BlendShapeBind Cerate(Transform root, List <Mesh> meshes, BlendShapeBinding binding)
 {
     return(Create(root, meshes, binding));
 }
示例#5
0
 public static glTF_VRM_BlendShapeBind Cerate(Transform root, BlendShapeBinding binding,
                                              gltfExporter exporter)
 {
     return(Create(root, binding, exporter));
 }
示例#6
0
        public static glTF_VRM_BlendShapeBind Cerate(Transform root, List <Mesh> meshes, BlendShapeBinding binding)
        {
            var transform = UniGLTF.UnityExtensions.GetFromPath(root.transform, binding.RelativePath);
            var renderer  = transform.GetComponent <SkinnedMeshRenderer>();
            var mesh      = renderer.sharedMesh;
            var meshIndex = meshes.IndexOf(mesh);

            return(new glTF_VRM_BlendShapeBind
            {
                mesh = meshIndex,
                index = binding.Index,
                weight = binding.Weight,
            });
        }
示例#7
0
        public static glTF_VRM_BlendShapeBind Create(Transform root, BlendShapeBinding binding,
                                                     gltfExporter exporter)
        {
            if (root == null || exporter == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty((binding.RelativePath)))
            {
                Debug.LogWarning("binding.RelativePath is null");
                return(null);
            }
            var found = root.transform.Find(binding.RelativePath);

            if (found == null)
            {
                var name = binding.RelativePath.Split('/').Last();
                found = root.GetComponentsInChildren <Transform>().Where(x => x.name == name).First();
                if (found == null)
                {
                    Debug.LogWarning($"{binding.RelativePath} not found");
                    return(null);
                }
                else
                {
                    Debug.LogWarning($"fall back '{binding.RelativePath}' => '{found.RelativePathFrom(root)}'");
                }
            }
            var renderer = found.GetComponent <SkinnedMeshRenderer>();

            if (renderer == null)
            {
                return(null);
            }

            if (!renderer.gameObject.activeInHierarchy)
            {
                return(null);
            }

            var mesh      = renderer.sharedMesh;
            var meshIndex = exporter.Meshes.IndexOf(mesh);

            if (meshIndex == -1)
            {
                return(null);
            }

            if (!exporter.MeshBlendShapeIndexMap.TryGetValue(mesh, out Dictionary <int, int> blendShapeIndexMap))
            {
                // この Mesh は  エクスポートされていない
                return(null);
            }

            if (!blendShapeIndexMap.TryGetValue(binding.Index, out int blendShapeIndex))
            {
                // この blendShape は エクスポートされていない(空だった?)
                return(null);
            }

            return(new glTF_VRM_BlendShapeBind
            {
                mesh = meshIndex,
                index = blendShapeIndex,
                weight = binding.Weight,
            });
        }