Exemplo n.º 1
0
    public void CreateControlPoints(SkinnedMeshRenderer skin)
    {
        if (skin.sharedMesh != null)
        {
            controlPoints = new ControlPoints.Point[skin.sharedMesh.vertices.Length];
            if (points == null)
            {
                points = gameObject.AddComponent <ControlPoints>();
            }
            for (int i = 0; i < skin.sharedMesh.vertices.Length; i++)
            {
                Vector3 originalPos = skin.sharedMesh.vertices[i];

                controlPoints[i]       = new ControlPoints.Point(originalPos);
                controlPoints[i].index = i;
                points.SetPoint(controlPoints[i]);

                GameObject b = new GameObject(skin.name + " Control Point");
                // Unparent the skin temporarily before adding the control point
                Transform skinParent = skin.transform.parent;
                skin.transform.parent = null;

                // Reset the rotation before creating the mesh so the UV's will align properly
                Quaternion localRotation = skin.transform.localRotation;
                skin.transform.localRotation = Quaternion.identity;

                b.transform.position = new Vector3(skin.transform.position.x + (skin.sharedMesh.vertices[i].x * skin.transform.localScale.x), skin.transform.position.y + (skin.sharedMesh.vertices[i].y * skin.transform.localScale.y), skin.transform.position.z + (skin.sharedMesh.vertices[i].z * skin.transform.localScale.z));
                b.transform.parent   = skin.transform;
                ControlPoint[] cps = b.transform.parent.transform.GetComponentsInChildren <ControlPoint>();
                if (cps != null && cps.Length > 0)
                {
                    b.gameObject.name = b.gameObject.name + cps.Length;
                }
                Undo.RegisterCreatedObjectUndo(b, "Add control point");
                ControlPoint controlPoint = b.AddComponent <ControlPoint>();
                controlPoint.index            = i;
                controlPoint.skin             = skin;
                controlPoint.originalPosition = b.transform.localPosition;

                // Reset the rotations of the object
                skin.transform.localRotation = localRotation;
                skin.transform.parent        = skinParent;
            }
        }
    }
Exemplo n.º 2
0
    public void CreateControlPoints(SkinnedMeshRenderer skin)
    {
        if (skin.sharedMesh != null)
        {
            controlPoints = new ControlPoints.Point[skin.sharedMesh.vertices.Length];
            if (points == null)
            {
                points = gameObject.AddComponent <ControlPoints>();
            }
            for (int i = 0; i < skin.sharedMesh.vertices.Length; i++)
            {
                Vector3 originalPos = skin.sharedMesh.vertices[i];

                controlPoints[i]       = new ControlPoints.Point(originalPos);
                controlPoints[i].index = i;
                points.SetPoint(controlPoints[i]);
            }
        }
    }