예제 #1
0
    public void DeleteObjectNew()
    {
        if (target.GetComponent <WandScript> ().selected.Count > 0)
        {
            if (allWorkspace)
            {
                //add something to toolbar
                GameObject toSelect;
                toSelect = target.GetComponent <WandScript> ().selected [0].transform.parent.gameObject;
                Destroy(toSelect);
            }
            else
            {
                foreach (GameObject to in target.GetComponent <WandScript> ().selected)
                {
                    GameObject toSelect;
                    toSelect = to.transform.gameObject;
                    CADObject ccc = to.transform.parent.GetComponent <CADObject> ();

                    if (toSelect.name.Contains("Vertex"))
                    {
                        ccc.RemoveVertex(toSelect);
                    }
                    Destroy(toSelect);
                }
            }
        }

        target.GetComponent <WandScript> ().selected = new List <GameObject> ();
    }
예제 #2
0
    public IdPath GetRelativePath(CADObject from)
    {
        var result = new IdPath();
        var p      = this;

        while (p != null)
        {
            if (p == from)
            {
                return(result);
            }
            if (p.guid == Id.Null)
            {
                return(result);
            }
            result.path.Add(p.guid);
            p = p.parentObject;
        }
        return(result);
    }
예제 #3
0
    public int Absorb(CADObject toAbsorb)
    {
        //move all vertices over
        this.vertices.AddRange(toAbsorb.vertices);
        //move all the edges over
        List <HashSet <GameObject> > keyList = new List <HashSet <GameObject> >(toAbsorb.edges.Keys);

        foreach (HashSet <GameObject> key in keyList)
        {
            this.edges.Add(key, toAbsorb.edges[key]);
        }
        //loop through all children, switch gameobjects over
        Transform[] children = toAbsorb.gameObject.GetComponentsInChildren <Transform>();
        foreach (Transform t in children)
        {
            t.SetParent(gameObject.transform);
        }
        //delete old gameobject
        toAbsorb.gameObject.SetActive(false);

        return(1);
    }
예제 #4
0
    public void CreateFace()
    {
        Action action = new Action(Nothing);

        if (selected.Count < 3)
        {
            Debug.Log("-----ERROR MUST BELONG SAME OBJECT-----");
            MobileNativePopups.OpenAlertDialog("Error", "Please select at least 3 vertices", "Cancel", action);
            return;
        }

        CADObject cadObject = selected [0].transform.parent.GetComponent <CADObject> ();

        string            objName = selected [0].transform.parent.name;
        List <GameObject> pool    = new List <GameObject> ();

        foreach (GameObject g in selected)
        {
            pool.Add(g);
            if (!g.transform.parent.name.Equals(objName))
            {
                Debug.Log("-----ERROR MUST BELONG SAME OBJECT-----");
                MobileNativePopups.OpenAlertDialog("Error", "Please select vertices that belong to the same object", "Cancel", action);
                return;
            }
        }

        GameObject startingPoint = pool [0];
        GameObject recent        = startingPoint;

        pool.Remove(startingPoint);

        List <GameObject> orderedList        = new List <GameObject> ();
        List <Vector3>    orderListPositions = new List <Vector3> ();

        orderedList.Add(recent);
        orderListPositions.Add(recent.transform.position);

        //action += Nothing;
        int toFind = pool.Count;

        while (true)
        {
            if (pool.Count == 0)
            {
                break;
            }

            GameObject found = null;
            foreach (GameObject checkNeighbor in pool)
            {
                HashSet <GameObject> key = new HashSet <GameObject> ();
                key.Add(checkNeighbor);
                key.Add(recent);
                if (cadObject.edges.ContainsKey(key))
                {
                    found = checkNeighbor;
                    toFind--;
                    break;
                }
            }

            if (found == null)
            {
                Debug.Log("-error form loop");
                MobileNativePopups.OpenAlertDialog("Error", "Please select vertices that form a single, complete loop", "Cancel", action);
                return;
            }
            else
            {
                recent = found;
                pool.Remove(found);
                orderedList.Add(found);
                orderListPositions.Add(found.transform.position);
            }
        }

        HashSet <GameObject> keyEnd = new HashSet <GameObject> ();

        keyEnd.Add(orderedList[0]);
        keyEnd.Add(orderedList[orderedList.Count - 1]);
        if (!cadObject.edges.ContainsKey(keyEnd))
        {
            Debug.Log("-error form loop");
            MobileNativePopups.OpenAlertDialog("Error", "Please select vertices that form a single, complete loop", "Cancel", action);
            return;
        }



        if (orderedList.Count != selected.Count)
        {
            Debug.Log("-error form loop");
            MobileNativePopups.OpenAlertDialog("Error", "You need to select vertices that form a single loop", "Cancel", action);
            return;
        }



        Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
        poly.outside = orderListPositions;
        GameObject a = Poly2Mesh.CreateGameObject(poly);

        a.transform.parent = cadObject.gameObject.transform;
        a.GetComponent <Renderer> ().material = meshTexture;
        orderListPositions.Reverse();
        Poly2Mesh.Polygon poly2 = new Poly2Mesh.Polygon();
        poly2.outside = orderListPositions;
        GameObject a2 = Poly2Mesh.CreateGameObject(poly2);

        a2.transform.parent = cadObject.gameObject.transform;
        a2.GetComponent <Renderer> ().material = meshTexture;


        Debug.Log("CREATE FACE NOW");
        Debug.Log(orderedList.Count);
    }