getDifference() публичный Метод

public getDifference ( ) : Solid
Результат Solid
Пример #1
0
    public GameObject DrawWallWithHole(GameObject holeObject)
    {
        GameObject wall = new GameObject();

        wall.name = Name;

        var solidWall = SolidFromGameObject(Instance3D);
        var solidHole = SolidFromGameObject(holeObject);

        // Referencja do starej œciany (aby mo¿na by³o usun¹c obiekt)
        var oldWall = Instance3D;

        var modeller = new Net3dBool.BooleanModeller(solidWall, solidHole);

        Solid tmp = modeller.getDifference();

        MeshFilter mf    = wall.AddComponent <MeshFilter>();
        Mesh       tmesh = new Mesh();

        tmesh.vertices  = GetVertices(tmp);
        tmesh.triangles = tmp.getIndices();
        if (tmesh.vertices != null && tmesh.vertices.Length > 0)
        {
            tmesh.uv = UvCalculator.CalculateUVs(tmesh.vertices, 1);
        }
        tmesh.colors = GetColorsMesh(tmp);
        tmesh.RecalculateNormals();
        mf.mesh = tmesh;
        mf.mesh.RecalculateTangents(0);
        mf.mesh.RecalculateNormals();
        mf.mesh.RecalculateBounds();
        mf.mesh.OptimizeReorderVertexBuffer();
        mf.mesh.OptimizeIndexBuffers();
        mf.mesh.Optimize();

        var mr = wall.AddComponent <MeshRenderer>();

        mr.material = Material;

        wall.AddComponent <MeshCollider>();
        wall.tag = "Wall";

        wall.transform.parent = GameObject.Find("3DArea").transform;

        wall.transform.Translate(new Vector3(2000, 0, 0), Space.World);

        Instance3D = wall;

        DestroyImmediate(oldWall);
        DestroyImmediate(holeObject);

        wall.layer = LayerMask.NameToLayer("3DArea");

        return(wall);
    }
Пример #2
0
    public override bool Calculate()
    {
        if (!allInputsReady ()) {
            return false;
        }

        if (Inputs [0].connection != null) {
            Input1Val = Inputs [0].connection.GetValue<GameObject> ();

            CSGObject csg = Input1Val.GetComponent<CSGObject>();
            if(csg == null)
                csg = Input1Val.AddComponent<CSGObject>();
            csg.GenerateSolid();
        }
        if (Inputs [1].connection != null) {

            Input2Val = Inputs [1].connection.GetValue<GameObject> ();
            CSGObject csg = Input2Val.GetComponent<CSGObject> ();
            if (csg == null)
                csg = Input2Val.AddComponent<CSGObject> ();
            csg.GenerateSolid ();
        }

        if ((Input1Val != null) && (Input2Val != null)) {

            solid1 = Input1Val.GetComponent<CSGObject> ().GetSolid ();
            solid2 = Input2Val.GetComponent<CSGObject> ().GetSolid ();

            modeller = new BooleanModeller (solid1, solid2);
            output = null;

            switch (type) {
            case CalcType.Union:
                output = modeller.getUnion ();
                break;
            case CalcType.Intersection:
                output = modeller.getIntersection ();
                break;
            case CalcType.Difference:
                output = modeller.getDifference ();
                break;
            }

            if (output != null) {
                string goname = string.Format ("CSGOut_{0}", (int)this.GetHashCode ());
                GameObject gout = GameObject.Find (goname);
                if (gout == null)
                    gout = new GameObject (goname);
                CSGObject csg = gout.GetComponent<CSGObject>();
                if(csg == null) csg = gout.AddComponent<CSGObject>();
                csg.AssignSolid(output);
                CSGGameObject.GenerateMesh (gout, objectMaterial, output);

                Outputs [0].SetValue<GameObject> (gout);
            }
        } else
            return false;

        return true;
    }
Пример #3
0
    //void CreateC1()
    //{
    //    c1 = CreateCube(100, 50, 10);
    //    c1.transform.position = new Vector3(1000, 0, 0);
    //}

    //void CreateC2()
    //{
    //    c2 = CreateCube(50, 25, 5);
    //    c2.transform.position = new Vector3(1080, 0, 20);
    //    c2.transform.rotation = Quaternion.Euler(0, 90, 0);
    //}

    void Update()
    {
        if (domaManager.HoleInWall2D != null)
        {
            if (!cube.activeSelf)
            {
                cube.SetActive(true);
            }

            cube.transform.position = domaManager.HoleInWall2D.mousePosition;

            Vector3    startPoint = domaManager.HoleInWall2D.domaElement.Points2D[0];
            Vector3    endPoint   = domaManager.HoleInWall2D.domaElement.Points2D[1];
            Vector3    v          = endPoint - startPoint;
            Quaternion rotation   = Quaternion.LookRotation(v, Vector3.forward);
            rotation *= Quaternion.Euler(0, 90, 0);
            cube.transform.rotation = rotation;
        }
        else
        {
            cube.SetActive(false);
        }

        if (Input.GetMouseButtonDown(0))
        {
            Vector3?position = domaManager.HoleInWall2D?.mousePosition;

            if (position != null)
            {
                Vector3 startPoint = domaManager.HoleInWall2D.domaElement.Points2D[0];
                Vector3 endPoint   = domaManager.HoleInWall2D.domaElement.Points2D[1];
                Vector3 v          = endPoint - startPoint;

                // Rotation for 2D
                Quaternion rotation = Quaternion.LookRotation(v, Vector3.forward);
                rotation *= Quaternion.Euler(0, 90, 0);

                DrawHole2D(position.Value, rotation);

                // Rotation for 3D
                startPoint = domaManager.HoleInWall2D.domaElement.Points3D[0];
                endPoint   = domaManager.HoleInWall2D.domaElement.Points3D[1];
                v          = endPoint - startPoint;
                rotation   = Quaternion.LookRotation(v, Vector3.up);
                rotation  *= Quaternion.Euler(0, 90, 0);

                var cubeHoleTuple  = DrawHole3D(new Vector3(position.Value.x, 4f, position.Value.y), rotation);
                var cubeHoleObject = cubeHoleTuple.Item1;
                var cubeHoleSolid  = cubeHoleTuple.Item2;

                GameObject objectWall      = domaManager.HoleInWall2D.domaElement.DomaObject3D;
                Solid      objectWallSolid = domaManager.HoleInWall2D.domaElement.DomaObject3DSolid;

                var modeller = new Net3dBool.BooleanModeller(objectWallSolid, cubeHoleSolid);
                var tmp      = modeller.getDifference();

                GameObject newGameObject = new GameObject();
                newGameObject.name = "OOOOOOOO";

                newGameObject.transform.Translate(new Vector3(2000, 0, 0), Space.World);

                MeshFilter mf    = newGameObject.AddComponent <MeshFilter>();
                Mesh       tmesh = new Mesh();

                tmesh.vertices  = GetVertices(tmp);
                tmesh.triangles = tmp.getIndices();
                tmesh.colors    = GetColorsMesh(tmp);
                tmesh.RecalculateNormals();
                mf.mesh = tmesh;

                mf.mesh.RecalculateTangents(0);
                mf.mesh.RecalculateNormals();
                mf.mesh.RecalculateBounds();
                mf.mesh.OptimizeReorderVertexBuffer();
                mf.mesh.OptimizeIndexBuffers();
                mf.mesh.Optimize();

                MeshRenderer mr = newGameObject.AddComponent <MeshRenderer>();

                DestroyImmediate(domaManager.HoleInWall2D.domaElement.DomaObject3D);
                DestroyImmediate(cubeHoleObject);

                domaManager.HoleInWall2D.domaElement.DomaObject3D      = newGameObject;
                domaManager.HoleInWall2D.domaElement.DomaObject3DSolid = tmp;

                newGameObject.GetComponent <MeshRenderer>().material = material;

                newGameObject.transform.parent = area3D.transform;
            }
        }
    }