Example #1
0
    public void StartDrawing(Vector3 position, Quaternion rotation)
    {
        startPosition = position;
        GameObject go = Instantiate(objectCursor, Vector3.zero, Quaternion.identity) as GameObject;

        objectCursor.SetActive(false);

        if (objectType == ObjectType.Shape)
        {
            shape = go.GetComponent <ProcShape>();
            shape.ResetPoint(GridSnapTool.Snap(position), transform.rotation.eulerAngles.x);

            // checks if there is a mirror -> make a copy
            if (ms.gameObject.activeSelf)
            {
                ms.CreateReflection(go, scene.transform);
                ms.reflection.transform.position = go.transform.position;
                ms.reflection.GetComponent <ProcShape>().startPoint = ms.ReflectPoint(GridSnapTool.Snap(position));
            }
        }
        if (objectType == ObjectType.Section)
        {
            section = go.GetComponent <ProcSection>();
            section.ResetPoint(GridSnapTool.Snap(position), transform.rotation.eulerAngles.x);

            // checks if there is a mirror -> make a copy
            if (ms.gameObject.activeSelf)
            {
                ms.CreateReflection(go, scene.transform);
                ms.reflection.transform.position = go.transform.position;
                ms.reflection.GetComponent <ProcSection>().startPoint = ms.ReflectPoint(GridSnapTool.Snap(position));
            }
        }
        if (objectType == ObjectType.Hair)
        {
            go = Instantiate(Resources.Load("HairSplineTrail"), new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            go.GetComponent <HairSplineTrail>().Init(hairObject);
            hair = go.GetComponent <ProcHair>();
            hair.ResetPoint(GridSnapTool.Snap(position), transform.rotation.eulerAngles.x);

            // checks if there is a mirror -> make a copy
            if (ms.gameObject.activeSelf)
            {
                ms.CreateReflection(go, scene.transform);
                ms.reflection.transform.position = go.transform.position;
                ms.reflection.GetComponent <ProcHair>().startPoint = ms.ReflectPoint(GridSnapTool.Snap(position));
            }
        }
    }
Example #2
0
    public void UpdateDrawing(Vector3 position, Vector3 up, Vector3 forward, Vector3 right)
    {
        // updates shape
        if (objectType == ObjectType.Shape)
        {
            Vector3 actualPosition = position;
            if (ConstrainX)
            {
                actualPosition.x = shape.startPoint.x;
            }
            if (ConstrainY)
            {
                actualPosition.y = shape.startPoint.y;
            }
            if (ConstrainZ)
            {
                actualPosition.z = shape.startPoint.z;
            }

            if (!ConstrainLength)
            {
                shape.SetEndPoint(GridSnapTool.Snap(actualPosition));
            }
            else
            {
                Vector3 dir = (actualPosition - shape.startPoint).normalized;
                shape.SetEndPoint(GridSnapTool.Snap(shape.startPoint + LengthConstraint * dir));
            }

            lengthText.text = "" + Vector3.Distance(shape.endPoint, shape.startPoint);

            // checks if there is a mirror -> make a copy
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ProcShape>().SetEndPoint(ms.ReflectPoint(GridSnapTool.Snap(actualPosition)));
            }
        }
        else if (objectType == ObjectType.Section)
        {
            Vector3 actualPosition = position;
            if (ConstrainX)
            {
                actualPosition.x = section.startPoint.x;
            }
            if (ConstrainY)
            {
                actualPosition.y = section.startPoint.y;
            }
            if (ConstrainZ)
            {
                actualPosition.z = section.startPoint.z;
            }

            if (!ConstrainLength)
            {
                section.SetEndPoint(GridSnapTool.Snap(actualPosition));
            }
            else
            {
                Vector3 dir = (actualPosition - section.startPoint).normalized;
                section.SetEndPoint(GridSnapTool.Snap(section.startPoint + LengthConstraint * dir));
            }

            lengthText.text = "" + Vector3.Distance(section.endPoint, section.startPoint);

            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ProcSection>().SetEndPoint(ms.ReflectPoint(GridSnapTool.Snap(actualPosition)));
            }
        }
        else if (objectType == ObjectType.Hair)
        {
            Vector3 actualPosition = position;
            if (ConstrainX)
            {
                actualPosition.x = hair.startPoint.x;
            }
            if (ConstrainY)
            {
                actualPosition.y = hair.startPoint.y;
            }
            if (ConstrainZ)
            {
                actualPosition.z = hair.startPoint.z;
            }

            //shape.SetEndPoint(actualPosition);
            hair.ResetPoint(GridSnapTool.Snap(startPosition), transform.rotation.eulerAngles.x);
            hair.GetComponent <HairSplineTrail>().BuildMeshTrail(GridSnapTool.Snap(actualPosition), up, forward, right, true);



            if (!ConstrainLength)
            {
                hair.SetEndPoint(GridSnapTool.Snap(actualPosition));
            }
            else
            {
                Vector3 dir = (actualPosition - hair.startPoint).normalized;
                hair.SetEndPoint(GridSnapTool.Snap(hair.startPoint + LengthConstraint * dir));
            }

            lengthText.text = "" + Vector3.Distance(hair.endPoint, hair.startPoint);

            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ProcHair>().SetEndPoint(ms.ReflectPoint(GridSnapTool.Snap(actualPosition)));
            }
        }
    }