コード例 #1
0
    private GameObject Boolean(BoolOp operation)
    {
        Reset(main_object, operating_object);
        current_operation = TransfOp.Spectate;
        UpdateTransformationButtons();

        Mesh m;

        if (CSG_operation_history.Count == 0)
        {
            StoreCurrentState("start", main_object);
        }

        switch (operation)
        {
        case BoolOp.Union:
            StoreCurrentState("transformation", main_object);
            StoreCurrentState("union", operating_object);
            m = CSG.Union(main_object, operating_object);
            break;

        case BoolOp.Subtract:
            StoreCurrentState("transformation", main_object);
            StoreCurrentState("subtract", operating_object);
            m = CSG.Subtract(main_object, operating_object);
            break;

        case BoolOp.Intersect:
        default:
            StoreCurrentState("transformation", main_object);
            StoreCurrentState("intersect", operating_object);
            m = CSG.Intersect(main_object, operating_object);
            break;
        }

        composite      = new GameObject();
        composite.name = "Constructed CSG";
        composite.AddComponent <MeshFilter>().sharedMesh       = m;
        composite.AddComponent <MeshRenderer>().sharedMaterial = materials[material_ID];

        // Generate new mesh
        Mesh mesh = ConstructMesh(composite);

        // Generate new meshcollider
        composite.AddComponent <MeshCollider>();
        composite.GetComponent <MeshCollider>().sharedMesh = mesh;

        // Change tag
        composite.tag = "csg";

        Destroy(main_object);
        Destroy(operating_object);

        main_object      = null;
        operating_object = null;


        // Switch new composited object to main object
        return(composite);
    }
コード例 #2
0
    void Start()
    {
        CSG_operation_history = new List <string>();
        current_step_num      = 0;
        max_step_num          = 0;
        current_operation     = TransfOp.Spectate;

        enableDisableTransfButtons(false);
        enableDisableBoolButtons(false);
    }