Exemple #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));
            }
        }
    }
Exemple #2
0
 void ChangeShape(ObjectType typeObject, int index)
 {
     if (typeObject == ObjectType.Shape)
     {
         SetToObjectType(LineTool.ObjectType.Shape);
         ProcShape shape = shapeObject.GetComponent <ProcShape>();
         shape.radialSegmentCount = index;
     }
     if (typeObject == ObjectType.Section)
     {
         SetToObjectType(LineTool.ObjectType.Section);
         ProcSection sect = sectionObject.GetComponent <ProcSection>();
         sect.shapeType = ShapeTypes[index];
     }
     if (typeObject == ObjectType.Hair)
     {
         SetToObjectType(LineTool.ObjectType.Hair);
         ProcHair hair = hairObject.GetComponent <ProcHair>();
         hair.radialSegmentCount = index;
     }
 }
Exemple #3
0
 void ChangeShape(ObjectType typeObject, int index)
 {
     controller.DeviceController.TriggerHapticPulse(pulseLength);
     if (typeObject == ObjectType.Shape)
     {
         SetToObjectType(SplineTool.ObjectType.Shape);
         ProcShape shape = shapeObject.GetComponent <ProcShape>();
         shape.radialSegmentCount = index;
     }
     if (typeObject == ObjectType.Section)
     {
         SetToObjectType(SplineTool.ObjectType.Section);
         ProcSection sect = sectionObject.GetComponent <ProcSection>();
         sect.shapeType = ShapeTypes[index];
     }
     if (typeObject == ObjectType.Hair)
     {
         SetToObjectType(SplineTool.ObjectType.Hair);
         ProcHair hair = hairObject.GetComponent <ProcHair>();
         hair.radialSegmentCount = index;
     }
 }
Exemple #4
0
    public void EndDrawing()
    {
        // set the collider and the mesh
        if (objectType == ObjectType.Shape)
        {
            shape.SetMeshCollider();
            ObjectManager.instance.AddObject(shape.gameObject);
            shape.gameObject.AddComponent <MeshEditor>().StartGroupGeneration();
            shape = null;

            // add reflection
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ProcShape>().SetMeshCollider();
                ObjectManager.instance.AddObject(ms.reflection);
            }
        }
        else if (objectType == ObjectType.Section)
        {
            section.SetMeshCollider();
            ObjectManager.instance.AddObject(section.gameObject);
            section.gameObject.GetComponent <MeshEditor>().StartGroupGeneration();
            section = null;

            // add reflection
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ProcSection>().SetMeshCollider();
                ObjectManager.instance.AddObject(ms.reflection);
            }
        }
        else if (objectType == ObjectType.Hair)
        {
            hair.SetMeshCollider();
            hair.gameObject.GetComponent <MeshEditor>().StartGroupGeneration();

            // add reflection
            if (ms.gameObject.activeSelf)
            {
                ms.reflection.GetComponent <ProcHair>().SetMeshCollider();
                ObjectManager.instance.AddObject(ms.reflection);
            }

            var        refTrail = hair.GetComponent <HairSplineTrail>();
            GameObject trail    = Instantiate(Resources.Load("NURBSTrail"), new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            trail.GetComponent <NURBSTrail>().InitNURBS(refTrail.spline, refTrail.trackLength, new Vector3(0.005f, 0, 0));
            trail.GetComponent <MeshRenderer>().material.color = hair.GetComponent <MeshRenderer>().material.color;
            hair = null;
            Destroy(hair.GetComponent <HairSplineTrail>());
            Destroy(hair);
            refTrail.Init(hairObject);
            ObjectManager.instance.AddObject(trail);
            Destroy(go.GetComponent <HairSplineTrail>());
        }
        if (ms.gameObject.activeSelf)
        {
            ms.reflection.GetComponent <MeshEditor>().StartGroupGeneration();
        }

        // set object cursor back
        objectCursor.SetActive(true);
        GameObject.Find("Tracker").GetComponent <TrackerScript>().numMesh++;
    }
Exemple #5
0
    public void Init(GameObject Cursor)
    {
        if (Cursor == null)
        {
            Debug.Log("GameObject 'Shape' is not assigned!");
            Application.Quit();
        }

        // setups the script to track input cursor in 3D space
        cursorTransform    = Cursor.transform;
        transform.position = new Vector3(0, 0, 0);

        // gets radial segments, radius and color
        ProcShape    ps = Cursor.GetComponent <ProcShape>();
        var          ph = Cursor.GetComponent <ProcHair>();
        MeshRenderer mr = GetComponent <MeshRenderer>();

        if (ps != null)
        {
            m_RadialSegmentCount = ps.m_RadialSegmentCount;
            m_Radius             = ps.m_Radius;
            mr.material.color    = ps.m_RGB;
        }
        else
        {
            m_RadialSegmentCount = ph.m_RadialSegmentCount;
            m_Radius             = ph.radius;
            mr.material.color    = ph.m_RGB;
        }


        //Get MeshRenderer and set to color of the cursor


        //Look for a MeshCollider component attached to this GameObject:
        meshCollider = GetComponent <MeshCollider>();

        //Create a new mesh builder:
        meshBuilder = new MeshBuilder();

        //Look for a MeshFilter component attached to this GameObject:
        filter = GetComponent <MeshFilter>();

        // creates the spline
        if (spline == null)
        {
            spline = new CatmullRomSpline();

            // add knots via position
            List <Knot> knots = spline.knots;
            Vector3     point = cursorTransform.position;

            // initiate normals at the starting knot
            knotNormals   = new List <Vector3>();
            knotBinormals = new List <Vector3>();
            knotTangents  = new List <Vector3>();
            knotLengths   = new List <float>();
            knotRadius    = new List <float>();

            for (int i = 0; i < 3; ++i)
            {
                addCursorTransform();
            }

            knots.Add(new Knot(point));
            knots.Add(new Knot(point));
            knots.Add(new Knot(point));
            knots.Add(new Knot(point));
            knots.Add(new Knot(point));

            startKnot = 0;
        }

        StartTracking();
    }
Exemple #6
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);
            }
        }
    }