示例#1
0
    static void Intersect()
    {
        // we need at least two selected objects
        if (Selection.gameObjects.Length > 1)
        {
            CSGObject obj = Selection.activeGameObject.GetComponent <CSGObject>();

            if (obj)
            {
                obj.PerformCSG(CsgOperation.ECsgOperation.CsgOper_Intersect, Selection.gameObjects);
            }


            if (GlobalSettings.DeleteSlaves)
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    // if we are not the active game object and are a CSG Object
                    if (Selection.activeGameObject != go && go.GetComponent <CSGObject>())
                    {
                        GameObject.DestroyImmediate(go);
                    }
                }
            }
        }
    }
示例#2
0
    static void Union()
    {
        // we need at least two selected objects
        if (Selection.gameObjects.Length > 1)
        {
            CSGObject obj = Selection.activeGameObject.GetComponent <CSGObject>();

            if (obj)
            {
                obj.PerformCSG(CsgOperation.ECsgOperation.CsgOper_Additive, Selection.gameObjects);
            }

            if (GlobalSettings.DeleteSlaves)
            {
                // destroy slaves if we want to

                foreach (GameObject go in Selection.gameObjects)
                {
                    if (Selection.activeGameObject != go && go.GetComponent <CSGObject>())
                    {
                        GameObject.DestroyImmediate(go);
                    }
                }
            }
        }
    }
示例#3
0
    public static void Subtract(GameObject a, GameObject b)
    {
        CSGObject obj = a.GetComponent <CSGObject>();

        GameObject[] slaves = new GameObject[2] {
            a, b
        };
        obj.PerformCSG(CsgOperation.ECsgOperation.CsgOper_Subtractive, slaves);
        a.name = "(" + a.name + ") - (" + b.name + ")";
    }
示例#4
0
    // Use this for initialization
    public override void OnInspectorGUI()
    {
        CSGObject obj = (CSGObject)target;

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Intersect"))
        {
            // find game objects (TODO: check if they are touching us)
            Object[]     others = FindObjectsOfType(typeof(GameObject));
            GameObject[] gos    = new GameObject[others.Length];
            int          i      = 0;
            foreach (GameObject gameObj in others)
            {
                gos[i] = gameObj;
                ++i;
            }

            obj.PerformCSG(CsgOperation.ECsgOperation.CsgOper_Intersect, gos);
        }
        if (GUILayout.Button("DeIntersect"))
        {
            // find game objects (TODO: check if they are touching us)
            Object[]     others = FindObjectsOfType(typeof(GameObject));
            GameObject[] gos    = new GameObject[others.Length];
            int          i      = 0;
            foreach (GameObject gameObj in others)
            {
                gos[i] = gameObj;
                ++i;
            }

            obj.PerformCSG(CsgOperation.ECsgOperation.CsgOper_DeIntersect, gos);
        }
        GUILayout.Button("...");
        GUILayout.EndHorizontal();

        EditorGUILayout.BeginVertical();

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.LabelField("Texturing");
        obj.texMode = EditorGUILayout.Popup(obj.texMode, new string[] { "Original", "Planar Mapping" });

        EditorGUILayout.EndHorizontal();

        // add
        if (obj.texMode == CSGObject.TexMode_Planar)
        {
            // offset u
            EditorGUILayout.BeginHorizontal();
            float newTexOffsetU = EditorGUILayout.FloatField("OffsetU", obj.globalTexOffsetU);

            if (obj.globalTexOffsetU != newTexOffsetU)
            {
                obj.globalTexOffsetU = newTexOffsetU;
                obj.TransferFacesToMesh();
            }
            EditorGUILayout.EndHorizontal();

            // offset v
            EditorGUILayout.BeginHorizontal();

            float newTexOffsetV = EditorGUILayout.FloatField("OffsetV", obj.globalTexOffsetV);

            if (obj.globalTexOffsetV != newTexOffsetV)
            {
                obj.globalTexOffsetV = newTexOffsetV;
                obj.TransferFacesToMesh();
            }
            EditorGUILayout.EndHorizontal();


            // scale u
            EditorGUILayout.BeginHorizontal();
            float newTexScaleU = EditorGUILayout.FloatField("ScaleU", obj.globalTexScaleU);
            newTexScaleU = Mathf.Clamp(newTexScaleU, 0.001f, 16.0f);

            if (obj.globalTexScaleU != newTexScaleU)
            {
                obj.globalTexScaleU = newTexScaleU;
                obj.TransferFacesToMesh();
            }

            EditorGUILayout.EndHorizontal();

            // scale v
            EditorGUILayout.BeginHorizontal();
            float newTexScaleV = EditorGUILayout.FloatField("ScaleV", obj.globalTexScaleV);
            newTexScaleV = Mathf.Clamp(newTexScaleV, 0.001f, 16.0f);

            if (obj.globalTexScaleV != newTexScaleV)
            {
                obj.globalTexScaleV = newTexScaleV;
                obj.TransferFacesToMesh();
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();
    }