コード例 #1
0
        private void Init()
        {
            Cleanup();
            var pseudo = new GameObject();

            pseudo.name             = "PseudoSkeleton";
            pseudo.transform.parent = transform;

            if (meshList.Count > 0)
            {
                foreach (var node in meshList)
                {
                    var go = new GameObject();
                    go.name             = node.name;
                    go.transform.parent = pseudo.transform;

                    var newNode = new PseudoSkel();
                    newNode.source = node;
                    newNode.dest   = go.transform;
                    pseudoSkel.Add(newNode);

                    UpdatePosition(newNode);
                }
            }
        }
コード例 #2
0
        private void UpdatePosition(PseudoSkel node)
        {
            if (node == null)
            {
                return;
            }

            // figure out the bounding size of the children
            var parentMesh = node.source.GetComponent <MeshRenderer>();
            var meshes     = node.source.GetComponentsInChildren <MeshRenderer>();

            combinedBounds = meshes[0].bounds;

            //Debug.Log("node: " + node.source.name + " has " + meshes.Length + " submeshes");
            foreach (var mr in meshes)
            {
                if (mr != parentMesh)
                {
                    Debug.Log("mesh: " + mr.name + " center: " + mr.bounds.center + " size: " + mr.bounds.size);
                    if (mr.bounds.size != Vector3.zero && mr.bounds.center != Vector3.zero)
                    {
                        combinedBounds.Encapsulate(mr.bounds);
                    }
                    else
                    {
                        Debug.Log("ignoring mesh: " + mr.name);
                    }
                }
            }

            // Debug.Log("node: " + node.source.name + " center: " + combinedBounds.center + " bounds: " + combinedBounds.size);

            // fix for domain reload being dumb
            if (node.dest.transform != null)
            {
                node.dest.transform.localPosition = combinedBounds.center;
                var box = node.dest.GetOrAddComponent <BoxCollider>();
                box.size = combinedBounds.size;
            }
        }