Example #1
0
    public void LetGo(Vector3 pos, Vector3 angles, Vector3 velocity, Vector3 angularVelocity)
    {
        var device = SteamVR_Controller.Input((int)trackedObj.index);

        Destroy(joint);
        var rigidbody = objectHeld.GetComponent <Rigidbody>();

        rigidbody.isKinematic = !ObjectManager.instance.gravity;
        rigidbody.useGravity  = ObjectManager.instance.gravity;
        var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;

        if (origin != null)
        {
            rigidbody.velocity        = origin.TransformVector(velocity);
            rigidbody.angularVelocity = origin.TransformVector(angularVelocity);
        }
        else
        {
            rigidbody.velocity        = velocity;
            rigidbody.angularVelocity = angularVelocity;
        }
        objectHeld.transform.position = GridSnapTool.Snap(pos, objectHeld);
        objectHeld.transform.rotation = Quaternion.Euler(angles);
        objectHeld.transform.parent   = objectParent;
        var col = objectHeld.GetComponent <MeshCollider>();

        objectHeld = null;
    }
Example #2
0
 // Use this for initialization
 void Start()
 {
     Gridlines = new List <GameObject>();
     if (instance == null)
     {
         instance  = this;
         Gridlines = new List <GameObject>();
     }
     else
     {
         //Destroy(gameObject);
     }
 }
Example #3
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();
        if (IsPlacing)
        {
            Line.SetPosition(CurrentPoint, GridSnapTool.Snap(drawPoint.transform.position));
        }

        if (controller.triggerButtonDown)
        {
            photonView.RPC("PlacePoint", PhotonTargets.AllBufferedViaServer);
        }
    }
Example #4
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 #5
0
    void PlacePoint()
    {
        if (!IsPlacing)
        {
            IsPlacing    = true;
            CurrentPoint = 0;
            Line.enabled = true;
        }
        Points[CurrentPoint] = GridSnapTool.Snap(drawPoint.transform.position);
        for (int i = CurrentPoint; i < 3; i++)
        {
            Line.SetPosition(i, GridSnapTool.Snap(drawPoint.transform.position));
        }

        CurrentPoint++;
        if (CurrentPoint == 3)
        {
            IsPlacing = false;
            FinishShape();
        }
    }
Example #6
0
 public void StartDrawing()
 {
     if (objectType == ObjectType.Shape)
     {
         go = Instantiate(Resources.Load("ShapeSplineTrail"), new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
         go.GetComponent <ShapeSplineTrail>().Init(shapeObject);
         StartPoint = GridSnapTool.Snap(shapeObject.transform.position);
         // checks if there is a mirror -> make a copy
         if (ms.gameObject.activeSelf)
         {
             ms.CreateReflection(go, scene.transform);
             ms.reflection.GetComponent <ShapeSplineTrail>().Init(shapeObject);
         }
     }
     else if (objectType == ObjectType.Section)
     {
         go = Instantiate(Resources.Load("SectionSplineTrail"), new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
         go.GetComponent <SectionSplineTrail>().Init(sectionObject);
         StartPoint = GridSnapTool.Snap(sectionObject.transform.position);
         // checks if there is a mirror -> make a copy
         if (ms.gameObject.activeSelf)
         {
             ms.CreateReflection(go, scene.transform);
             ms.reflection.GetComponent <SectionSplineTrail>().Init(sectionObject);
         }
     }
     else if (objectType == ObjectType.Hair)
     {
         go = Instantiate(Resources.Load("HairSplineTrail"), new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
         go.GetComponent <HairSplineTrail>().Init(hairObject);
         StartPoint = GridSnapTool.Snap(hairObject.transform.position);
         // checks if there is a mirror -> make a copy
         if (ms.gameObject.activeSelf)
         {
             ms.CreateReflection(go, scene.transform);
             ms.reflection.GetComponent <HairSplineTrail>().Init(hairObject);
         }
     }
 }
Example #7
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)));
            }
        }
    }
Example #8
0
    public void UpdateDrawing(Vector3 pos, Vector3 up, Vector3 forward, Vector3 right)
    {
        // set the collider and the mesh
        if (objectType == ObjectType.Shape)
        {
            shape = shapeObject.GetComponent <ProcShape>();
            Vector3 actualPosition = pos;
            if (ConstrainX)
            {
                actualPosition.x = StartPoint.x;
            }
            if (ConstrainY)
            {
                actualPosition.y = StartPoint.y;
            }
            if (ConstrainZ)
            {
                actualPosition.z = StartPoint.z;
            }

            //shape.SetEndPoint(actualPosition);
            go.GetComponent <ShapeSplineTrail>().BuildMeshTrail(GridSnapTool.Snap(actualPosition), up, forward, right);

            // update reflection
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ShapeSplineTrail>().BuildMeshTrail(ms.ReflectPoint(GridSnapTool.Snap(actualPosition)), ms.ReflectVector(up), ms.ReflectVector(forward), ms.ReflectVector(right));
            }
            ToolTracker.net[1] = 1;
            ToolTracker.net[2] = 2;
            ToolTracker.net[3] = 1;
            //ToolTracker.net[4] = (int)shapeObject.GetComponent<ProcShape>().m_Radius;
        }
        else if (objectType == ObjectType.Section)
        {
            Vector3 actualPosition = pos;
            section = sectionObject.GetComponent <ProcSection>();
            if (ConstrainX)
            {
                actualPosition.x = StartPoint.x;
            }
            if (ConstrainY)
            {
                actualPosition.y = StartPoint.y;
            }
            if (ConstrainZ)
            {
                actualPosition.z = StartPoint.z;
            }

            //section.SetEndPoint(actualPosition);
            go.GetComponent <SectionSplineTrail>().BuildMeshTrail(GridSnapTool.Snap(actualPosition), up, forward, right);

            // update reflection
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <SectionSplineTrail>().BuildMeshTrail(ms.ReflectPoint(GridSnapTool.Snap(actualPosition)), -ms.ReflectVector(up), -ms.ReflectVector(forward), -ms.ReflectVector(right));
            }
            ToolTracker.net[1] = 2;
            ToolTracker.net[2] = 2;
            ToolTracker.net[3] = 1;
            //ToolTracker.net[4] = (int)sectionObject.GetComponent<ProcShape>().m_Radius;
        }
        else if (objectType == ObjectType.Hair)
        {
            Vector3 actualPosition = pos;
            hair = sectionObject.GetComponent <ProcHair>();
            if (ConstrainX)
            {
                actualPosition.x = StartPoint.x;
            }
            if (ConstrainY)
            {
                actualPosition.y = StartPoint.y;
            }
            if (ConstrainZ)
            {
                actualPosition.z = StartPoint.z;
            }

            go.GetComponent <HairSplineTrail>().BuildMeshTrail(GridSnapTool.Snap(actualPosition), up, forward, right, false);

            // update reflection
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <HairSplineTrail>().BuildMeshTrail(ms.ReflectPoint(GridSnapTool.Snap(actualPosition)), -ms.ReflectVector(up), -ms.ReflectVector(forward), -ms.ReflectVector(right), false);
            }
        }
    }