Esempio n. 1
0
        /// <summary>
        /// Nodeを置き換える。参照を置換する。
        /// </summary>
        public void NodeReplace(Node src, Node dst)
        {
            if (src == null)
            {
                throw new ArgumentNullException();
            }
            if (dst == null)
            {
                throw new ArgumentNullException();
            }

            // add dst same parent
            src.Parent.Add(dst, ChildMatrixMode.KeepWorld);

            // remove all child
            foreach (var child in src.Children.ToArray())
            {
                dst.Add(child, ChildMatrixMode.KeepWorld);
            }

            // remove from parent
            src.Parent.Remove(src);
            Model.Nodes.Remove(src);

            // remove from skinning
            foreach (var skin in Model.Skins)
            {
                skin.Replace(src, dst);
            }

            // fix animation reference
            foreach (var animation in Model.Animations)
            {
                if (animation.NodeMap.TryGetValue(src, out NodeAnimation nodeAnimation))
                {
                    animation.NodeMap.Remove(src);
                    animation.NodeMap.Add(dst, nodeAnimation);
                }
            }

            if (Model.Nodes.Contains(dst))
            {
                throw new Exception("already exists");
            }
            Model.Nodes.Add(dst);

            // TODO: SpringBone
        }
Esempio n. 2
0
        static void AddBvhNodeRecursive(Model model, Node parent, BvhNode node)
        {
            var newNode = new Node(node.Name)
            {
                HumanoidBone = node.Bone,
            };

            model.Nodes.Add(newNode);
            parent.Add(newNode);
            newNode.Translation = node.SkeletonLocalPosition;

            foreach (var child in node.Children)
            {
                AddBvhNodeRecursive(model, newNode, child);
            }
        }
Esempio n. 3
0
        private static void CreateNodes(
            Transform parentTransform,
            VrmLib.Node parentNode,
            Dictionary <GameObject, VrmLib.Node> nodes)
        {
            // parentNode.SetMatrix(parentTransform.localToWorldMatrix.ToNumericsMatrix4x4(), false);
            parentNode.LocalTranslation = parentTransform.localPosition.ToNumericsVector3();
            parentNode.LocalRotation    = parentTransform.localRotation.ToNumericsQuaternion();
            parentNode.LocalScaling     = parentTransform.localScale.ToNumericsVector3();
            nodes.Add(parentTransform.gameObject, parentNode);

            foreach (Transform child in parentTransform)
            {
                var childNode = new VrmLib.Node(child.gameObject.name);
                CreateNodes(child, childNode, nodes);
                parentNode.Add(childNode);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Nodeを置き換える。参照を置換する。
        /// </summary>
        public void NodeReplace(Node src, Node dst)
        {
            if (src == null)
            {
                throw new ArgumentNullException();
            }
            if (dst == null)
            {
                throw new ArgumentNullException();
            }

            // add dst same parent
            src.Parent.Add(dst, ChildMatrixMode.KeepWorld);

            // remove all child
            foreach (var child in src.Children.ToArray())
            {
                dst.Add(child, ChildMatrixMode.KeepWorld);
            }

            // remove from parent
            src.Parent.Remove(src);
            Model.Nodes.Remove(src);

            // remove from skinning
            foreach (var skin in Model.Skins)
            {
                skin.Replace(src, dst);
            }

            // fix animation reference
            foreach (var animation in Model.Animations)
            {
                if (animation.NodeMap.TryGetValue(src, out NodeAnimation nodeAnimation))
                {
                    animation.NodeMap.Remove(src);
                    animation.NodeMap.Add(dst, nodeAnimation);
                }
            }

            if (Model.Nodes.Contains(dst))
            {
                throw new Exception("already exists");
            }
            Model.Nodes.Add(dst);

            // fix VRM
            if (Model.Vrm != null)
            {
                // replace: VrmMorphTargetBind.Mesh
                if (Model.Vrm.ExpressionManager != null)
                {
                    foreach (var x in Model.Vrm.ExpressionManager.ExpressionList)
                    {
                        for (int i = 0; i < x.MorphTargetBinds.Count; ++i)
                        {
                            var v = x.MorphTargetBinds[i];
                            if (src == v.Node)
                            {
                                v.Node = dst;
                            }
                        }
                    }
                }

                // replace: VrmFirstPerson.MeshAnnotations
                Model.Vrm.FirstPerson.Annotations.RemoveAll(x => x.Node == src);
                if (!Model.Vrm.FirstPerson.Annotations.Any(x => x.Node == dst))
                {
                    Model.Vrm.FirstPerson.Annotations.Add(
                        new FirstPersonMeshAnnotation(dst, FirstPersonMeshType.Auto));
                }
            }

            // TODO: SpringBone
        }