GenerateSolid() public method

public GenerateSolid ( ) : void
return void
Ejemplo n.º 1
0
    public override bool Calculate()
    {
        if (value != null)
        {
            CSGObject csg = value.GetComponent <CSGObject>();
            if (csg == null)
            {
                csg = value.AddComponent <CSGObject>();
            }
            csg.GenerateSolid();
        }

        Outputs[0].SetValue <GameObject> (value);
        return(true);
    }
Ejemplo n.º 2
0
    public override bool Calculate()
    {
        if (Inputs [0].connection != null)
        {
            parent = Inputs [0].connection.GetValue <GameObject> ();
        }

        string name = "";

        // Make a primitive everytime calculate is called (in case type or loc changes)
        switch (type)
        {
        case PrimitiveType.Cube:
            name  = CSGPrimitives.MakePrimitiveName(this.GetHashCode());
            value = GameObject.Find(name);
            if (value != null)
            {
                DestroyImmediate(value);
            }
            value      = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube);
            value.name = name;
            break;

        case PrimitiveType.Plane:
            name  = CSGPrimitives.MakePrimitiveName(this.GetHashCode());
            value = GameObject.Find(name);
            if (value != null)
            {
                DestroyImmediate(value);
            }
            value      = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Plane);
            value.name = name;
            break;

        case PrimitiveType.Cone:
            value = CSGPrimitives.CreateCone(this.GetHashCode());
            break;

        case PrimitiveType.Tube:
            name  = CSGPrimitives.MakePrimitiveName(this.GetHashCode());
            value = GameObject.Find(name);
            if (value != null)
            {
                DestroyImmediate(value);
            }
            value      = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cylinder);
            value.name = name;
            break;

        case PrimitiveType.Sphere:
            name  = CSGPrimitives.MakePrimitiveName(this.GetHashCode());
            value = GameObject.Find(name);
            if (value != null)
            {
                DestroyImmediate(value);
            }
            value      = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Sphere);
            value.name = name;
            break;

        case PrimitiveType.Torus:
            value = CSGPrimitives.CreateTorus(this.GetHashCode());
            break;
        }

        if (value != null)
        {
            CSGObject csg = value.GetComponent <CSGObject>();
            if (csg == null)
            {
                csg = value.AddComponent <CSGObject>();
            }
            csg.GenerateSolid();

            if (parent != null)
            {
                value.transform.SetParent(parent.transform);
                value.transform.localPosition = location;
            }
            else
            {
                value.transform.SetParent(null);
                value.transform.position = location;
            }
        }

        Outputs[0].SetValue <GameObject> (value);
        return(true);
    }
Ejemplo n.º 3
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);
    }