コード例 #1
0
    public void ApplyCSG()
    {
        switch (operation)
        {
        case OperatorType.Union:
            temp = modeller.getUnion();
            break;

        case OperatorType.Intersection:
            temp = modeller.getIntersection();
            break;

        case OperatorType.Difference:
            temp = modeller.getDifference();
            break;
        }

        // Apply to output game object
        CSGGameObject.GenerateMesh(output, ObjMaterial, temp);
        // Make sure the output object has its 'solid' updated
        output.GetComponent <CSGObject> ().GenerateSolid();

        // Hide the original objects
        objectA.SetActive(false);
        objectB.SetActive(false);

        lasten = enableOperator;
        lastop = operation;
    }
コード例 #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);
    }