コード例 #1
0
ファイル: PointModel.cs プロジェクト: jorgejgnz/HPTK
        public override sealed void Awake()
        {
            base.Awake();

            if (!bone)
            {
                bone = GetComponent <BoneModel>();
            }
            if (!bone)
            {
                bone = BasicHelpers.GetComponentInParents <BoneModel>(transform);
            }

            if (!bone.points.Contains(this))
            {
                bone.points.Add(this);
            }
            if (bone.transform == transform)
            {
                bone.point = this;
            }
            if (!bone.point)
            {
                bone.point = this;
            }
        }
コード例 #2
0
        public float GetFingerLength(FingerModel finger)
        {
            if (!finger.knuckle || !finger.tip || !finger.tip.bone.reprs.ContainsKey(AvatarModel.key))
            {
                Debug.LogWarning("It was not possible to calculate length for finger " + finger.name);
                return(0.0f);
            }

            float length = 0.0f;

            BoneModel bone = finger.tip.bone;

            length += Vector3.Distance(finger.tip.transformRef.position, bone.transformRef.position);

            for (int i = 0; i < 50; i++)
            {
                if (!bone.parent || bone == finger.knuckle.bone)
                {
                    break;
                }

                length += Vector3.Distance(bone.transformRef.position, bone.parent.transformRef.position);

                bone = bone.parent;
            }

            return(length);
        }
コード例 #3
0
        public override sealed void Awake()
        {
            base.Awake();

            children.RemoveAll(c => c == null);
            points.RemoveAll(p => p == null);

            if (!part)
            {
                part = GetComponent <PartModel>();
            }
            if (!part)
            {
                part = transform.parent.GetComponent <PartModel>();
            }

            if (!parent)
            {
                int siblingIndex = transform.GetSiblingIndex();
                if (siblingIndex > 0)
                {
                    parent = transform.parent.GetChild(siblingIndex - 1).GetComponent <BoneModel>();
                    if (parent != null && !parent.children.Contains(this))
                    {
                        parent.children.Add(this);
                    }
                }
                else if (!part.root)
                {
                    part.root = this;
                }
                else if (part.root != this)
                {
                    Debug.LogWarning("Multiple roots found for part " + part.name + ": bones " + transform.name + " and " + part.root.name);
                }
            }

            if (!part.bones.Contains(this))
            {
                part.bones.Add(this);
            }

            BoneAwake();
        }
コード例 #4
0
 public override sealed void Awake()
 {
     base.Awake();
     model = GetComponent <BoneModel>();
 }
コード例 #5
0
        void StartPart(PartModel part)
        {
            if (part.body.parts.Contains(part))
            {
                return;
            }

            part.body.parts.Add(part);

            if (part == part.body.root && part.root.parent)
            {
                // Main root bone should have no parents
                part.root.parent.children.Remove(part.root);
                part.root.parent = null;

                Debug.LogWarning("Root bone of root part should have no parent. Parent removed for bone " + part.root.name);
            }
            else if (part.parent != null)
            {
                // Move to the upper element in hierarchy until you reach a bone or body.root
                BoneModel upperBone = null;
                PartModel upperPart = null;
                Transform tsf       = part.transform;
                int       siblingIndex;

                for (int i = 0; i < 50; i++)
                {
                    if (upperBone != null || upperPart == part.body.root)
                    {
                        break;
                    }

                    siblingIndex = tsf.GetSiblingIndex();

                    if (siblingIndex > 0)
                    {
                        tsf = tsf.parent.GetChild(siblingIndex - 1);
                    }
                    else
                    {
                        tsf = tsf.parent;
                    }

                    upperBone = tsf.GetComponent <BoneModel>();
                    upperPart = tsf.GetComponent <PartModel>();
                }

                // Connect part.root.parent with some part.parent.bones
                if (upperBone)
                {
                    part.root.parent = upperBone;
                    if (!upperBone.children.Contains(part.root))
                    {
                        upperBone.children.Add(part.root);
                    }
                }
                else
                {
                    Debug.LogWarning("Part " + part.name + " has a parent but any upper bone was found to which connect its root bone " + part.root.name);
                }
            }
            else if (part != part.body.root)
            {
                Debug.LogWarning(part.name + " has no parent but it's not the root part of " + part.body.name + ". The root part of that body is " + part.body.root.name);
            }

            // Recursive
            part.parts.ForEach(p =>
            {
                if (p.gameObject.activeSelf)
                {
                    p.body = part.body;
                    StartPart(p);
                }
            });

            if (part is HandModel)
            {
                HandStart(part as HandModel);
            }
            if (part is FingerModel)
            {
                FingerStart(part as FingerModel);
            }

            part.registry.ForEach((c) => { if (c.gameObject.activeSelf)
                                           {
                                               c.ControllerStart();
                                           }
                                  });

            // Scaling
            UpdateScale(part);
        }
コード例 #6
0
 void UpdateBone(BoneModel b)
 {
 }