Esempio n. 1
0
 // Start is called before the first frame update
 void Start()
 {
     name         = "MeshExtrusion";
     extCollider  = gameObject.AddComponent <MeshCollider>();
     extFilter    = gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter;
     extrudeState = ExtrudeFlag.ACTIVE;
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) ||
             (Input.GetMouseButton(0))) && extrudeState == ExtrudeFlag.ACTIVE)
        {
            var        Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(Ray, out hit) &&
                (hit.collider.gameObject.name == "QuadPolygon" || hit.collider.gameObject.name == "QuadCircle"))
            {
                // Clone original polygon rather than pass by reference
                polygon = duplicate(hit.collider.GetComponent <MeshFilter>().mesh);

                extDirection = hit.normal;
                faceNormal   = hit.normal;

                // convert plane to extrudable solid
                extrusion = convertSolid(polygon, extDirection);
                updateMesh();

                // setting up for manual extrusion
                extCollider            = gameObject.GetComponent <MeshCollider>();
                extCollider.sharedMesh = polygon;
                initializeList();

                initializeData();

                updateMesh();

                extrudeState = ExtrudeFlag.EDIT;
            }
        }

        else if (((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) ||
                  (Input.GetMouseButton(0))) && extrudeState == ExtrudeFlag.EDIT)
        {
            //Debug.Log(Input.GetTouch(0).deltaPosition * swipeScale);
            Vector3 swipe = new Vector3(Input.GetTouch(0).deltaPosition.x *swipeScale, Input.GetTouch(0).deltaPosition.y *swipeScale);
            //Debug.Log(swipe);

            if (swipe.magnitude > 0)
            {
                for (int i = 0; i < vertIndex.Count; i++)
                {
                    vertices[vertIndex[i]] += (swipe.x * faceNormal.x + swipe.y * faceNormal.y) * faceNormal;
                }


                for (int i = 0; i < vertData.Count; i++)
                {
                    vertData[i] += (swipe.x * faceNormal.x + swipe.y * faceNormal.y) * faceNormal;
                }
            }

            extrusion.vertices = vertices.ToArray();
            updateMesh();
        }

        if (((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) ||
             (Input.GetMouseButtonUp(0))) && extrudeState == ExtrudeFlag.EDIT)
        {
            extrudeState = ExtrudeFlag.INACTIVE;
        }

        if (extrudeState == ExtrudeFlag.DELETE)
        {
            Destroy(polygon);
            Destroy(extrusion);
            Destroy(gameObject);
        }
    }
Esempio n. 3
0
    /* --------------------------------------------------
     *  Public Methods
     *  -------------------------------------------------- */

    public void setState(string flag)
    {
        extrudeState = (ExtrudeFlag)System.Enum.Parse(typeof(ExtrudeFlag), flag);
    }