public ArticulationBodyPoseExtractor(ArticulationBody rootBody)
        {
            if (rootBody == null)
            {
                return;
            }

            if (!rootBody.isRoot)
            {
                Debug.Log("Must pass ArticulationBody.isRoot");
                return;
            }

            var bodies = rootBody.GetComponentsInChildren <ArticulationBody>();

            if (bodies[0] != rootBody)
            {
                Debug.Log("Expected root body at index 0");
                return;
            }

            var numBodies = bodies.Length;

            m_Bodies = bodies;
            int[] parentIndices = new int[numBodies];
            parentIndices[0] = -1;

            var bodyToIndex = new Dictionary <ArticulationBody, int>();

            for (var i = 0; i < numBodies; i++)
            {
                bodyToIndex[m_Bodies[i]] = i;
            }

            for (var i = 1; i < numBodies; i++)
            {
                var currentArticBody = m_Bodies[i];
                // Component.GetComponentInParent will consider the provided object as well.
                // So start looking from the parent.
                var currentGameObject = currentArticBody.gameObject;
                var parentGameObject  = currentGameObject.transform.parent;
                var parentArticBody   = parentGameObject.GetComponentInParent <ArticulationBody>();
                parentIndices[i] = bodyToIndex[parentArticBody];
            }

            Setup(parentIndices);
        }
Пример #2
0
        public ArticulationBodyPoseExtractor(ArticulationBody rootBody)
        {
            if (!rootBody.isRoot)
            {
                Debug.Log("Must pass ArticulationBody.isRoot");
                return;
            }

            var bodies = rootBody.GetComponentsInChildren <ArticulationBody>();

            if (bodies[0] != rootBody)
            {
                Debug.Log("Expected root body at index 0");
                return;
            }

            var numBodies = bodies.Length;

            m_Bodies = bodies;
            int[] parentIndices = new int[numBodies];
            parentIndices[0] = -1;

            var bodyToIndex = new Dictionary <ArticulationBody, int>();

            for (var i = 0; i < numBodies; i++)
            {
                bodyToIndex[m_Bodies[i]] = i;
            }

            for (var i = 1; i < numBodies; i++)
            {
                var body   = m_Bodies[i];
                var parent = body.GetComponentInParent <ArticulationBody>();
                parentIndices[i] = bodyToIndex[parent];
            }

            SetParentIndices(parentIndices);
        }