public bool CheckMaterials()
        {
            bool dirty = false;

            if (Surfaces == null ||
                Surfaces.Length == 0)
            {
                Debug.LogWarning("Surfaces == null || Surfaces.Length == 0");
                return(true);
            }

            int maxTexGenIndex = 0;

            for (int i = 0; i < Surfaces.Length; i++)
            {
                maxTexGenIndex = Mathf.Max(maxTexGenIndex, Surfaces[i].TexGenIndex);
            }
            maxTexGenIndex++;

            if (TexGens == null ||
                TexGens.Length < maxTexGenIndex)
            {
                dirty = true;
                var newTexGens     = new TexGen[maxTexGenIndex];
                var newTexGenFlags = new TexGenFlags[maxTexGenIndex];
                if (TexGens != null &&
                    TexGens.Length > 0)
                {
                    for (int i = 0; i < TexGens.Length; i++)
                    {
                        newTexGens[i]     = TexGens[i];
                        newTexGenFlags[i] = TexGenFlags[i];
                    }
                    for (int i = TexGens.Length; i < newTexGens.Length; i++)
                    {
                        newTexGens[i].Color = Color.white;
                    }
                }
                TexGens     = newTexGens;
                TexGenFlags = newTexGenFlags;
            }

            for (int i = 0; i < TexGens.Length; i++)
            {
                if (TexGens[i].Color == Color.clear)
                {
                    TexGens[i].Color = Color.white;
                }
            }

            return(dirty);
        }
Beispiel #2
0
        public static TexGenFlags OnSurfaceFlagButtons(TexGenFlags texGenFlags, bool isSceneGUI = false)
        {
            var leftStyle   = isSceneGUI ? EditorStyles.miniButtonLeft : GUI.skin.button;
            var middleStyle = isSceneGUI ? EditorStyles.miniButtonMid : GUI.skin.button;
            var rightStyle  = isSceneGUI ? EditorStyles.miniButtonRight : GUI.skin.button;

            var canDiscard        = (texGenFlags & TexGenFlags.Discarded) != TexGenFlags.Discarded;
            var canMakeShadowOnly = (texGenFlags & TexGenFlags.ShadowOnly) != TexGenFlags.ShadowOnly;
            var canMakeVisible    = !canDiscard || !canMakeShadowOnly;

            GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
            {
                EditorGUI.BeginDisabledGroup(!canDiscard);
                {
                    if (GUILayout.Button(ContentDiscardSurfaces, leftStyle))
                    {
                        texGenFlags &= ~TexGenFlags.ShadowOnly;
                        texGenFlags |= TexGenFlags.Discarded;
                        GUI.changed  = true;
                    }
                    TooltipUtility.SetToolTip(ToolTipDiscardSurfaces);
                }
                EditorGUI.EndDisabledGroup();
                EditorGUI.BeginDisabledGroup(!canMakeShadowOnly);
                {
                    if (GUILayout.Button(ContentShadowOnlySurfaces, middleStyle))
                    {
                        texGenFlags &= ~TexGenFlags.Discarded;
                        texGenFlags |= TexGenFlags.ShadowOnly;
                        GUI.changed  = true;
                    }
                    TooltipUtility.SetToolTip(ToolTipShadowOnlySurfaces);
                }
                EditorGUI.EndDisabledGroup();
                EditorGUI.BeginDisabledGroup(!canMakeVisible);
                {
                    if (GUILayout.Button(ContentVisibleSurfaces, rightStyle))
                    {
                        texGenFlags &= ~(TexGenFlags.Discarded | TexGenFlags.ShadowOnly);
                        GUI.changed  = true;
                    }
                    TooltipUtility.SetToolTip(ToolTipVisibleSurfaces);
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndHorizontal();
            return(texGenFlags);
        }
Beispiel #3
0
        /// <summary>Converts a <see cref="RealtimeCSG.Legacy.TexGen"/>/<see cref="RealtimeCSG.Legacy.TexGenFlags"/> pair into a <see cref="RealtimeCSG.Foundation.SurfaceLayers"/>.</summary>
        /// <param name="texGen">A legacy <see cref="RealtimeCSG.Legacy.TexGen"/> that describes what layer parameters will be used for this surface.</param>
        /// <param name="texGenFlags">A legacy <see cref="RealtimeCSG.Legacy.TexGenFlags"/> that describes what layers will be used for this surface</param>
        /// <returns>A new <see cref="RealtimeCSG.Foundation.SurfaceLayers"/></returns>
        public static SurfaceLayers CreateSurfaceLayer(TexGen texGen, TexGenFlags texGenFlags)
        {
            SurfaceLayers layers;

            var renderable     = !((texGenFlags & TexGenFlags.NoRender) == TexGenFlags.NoRender);
            var receiveShadows = !((texGenFlags & TexGenFlags.NoReceiveShadows) == TexGenFlags.NoReceiveShadows);
            var castShadows    = !((texGenFlags & TexGenFlags.NoCastShadows) == TexGenFlags.NoCastShadows);
            var collidable     = !((texGenFlags & TexGenFlags.NoCollision) == TexGenFlags.NoCollision);

            layers.layerUsage = (renderable     ? LayerUsageFlags.Renderable     : LayerUsageFlags.None) |
                                (receiveShadows ? LayerUsageFlags.ReceiveShadows : LayerUsageFlags.None) |
                                (castShadows    ? LayerUsageFlags.CastShadows    : LayerUsageFlags.None) |
                                (collidable     ? LayerUsageFlags.Collidable     : LayerUsageFlags.None);

            layers.layerParameter1 = (texGen.RenderMaterial) ? texGen.RenderMaterial.GetInstanceID()  : 0;
            layers.layerParameter2 = (texGen.PhysicsMaterial) ? texGen.PhysicsMaterial.GetInstanceID() : 0;
            layers.layerParameter3 = 0;

            return(layers);
        }
        public static void Reload()
        {
            LockAxisX = EditorPrefs.GetBool("LockAxisX", false);
            LockAxisY = EditorPrefs.GetBool("LockAxisY", false);
            LockAxisZ = EditorPrefs.GetBool("LockAxisZ", false);

            UniformGrid = EditorPrefs.GetBool("UniformGrid", true);
            EditMode    = GetEnum("EditMode", ToolEditMode.Generate);

            SnapVector          = GetVector3("MoveSnap", Vector3.one);
            DefaultMoveOffset   = GetVector3("DefaultMoveOffset", Vector3.zero);
            DefaultRotateOffset = GetVector3("DefaultRotateOffset", Vector3.zero);

            ShapeBuildMode     = GetEnum("ShapeBuildMode", ShapeMode.Box);
            DefaultTexGenFlags = GetEnum("DefaultTexGenFlags", defaultTextGenFlagsState);

            GridVisible = EditorPrefs.GetBool("ShowGrid", true);
            SnapMode    = (SnapMode)EditorPrefs.GetInt("SnapMode", (int)(EditorPrefs.GetBool("ForceSnapToGrid", true) ? SnapMode.GridSnapping : SnapMode.None));

            VisibleHelperSurfaces = GetEnum("HelperSurfaces", DefaultHelperSurfaceFlags);

            ClipMode          = GetEnum("ClipMode", ClipMode.RemovePositive);
            EnableRealtimeCSG = EditorPrefs.GetBool("EnableRealtimeCSG", true);

            DefaultMaterial = GetMaterial("DefaultMaterial", MaterialUtility.WallMaterial);


            SnapScale          = EditorPrefs.GetFloat("ScaleSnap", 0.1f);
            SnapRotation       = EditorPrefs.GetFloat("RotationSnap", 15.0f);
            DefaultShapeHeight = EditorPrefs.GetFloat("DefaultShapeHeight", 1.0f);
            CurveSides         = (uint)EditorPrefs.GetInt("CurveSides", 10);

            SelectionVertex  = EditorPrefs.GetBool("SelectionVertex", true);
            SelectionEdge    = EditorPrefs.GetBool("SelectionEdge", true);
            SelectionSurface = EditorPrefs.GetBool("SelectionSurface", true);

            HiddenSurfacesNotSelectable = EditorPrefs.GetBool("HiddenSurfacesNotSelectable", true);
//			HiddenSurfacesOrthoSelectable	= EditorPrefs.GetBool("HiddenSurfacesOrthoSelectable", true);
            ShowTooltips       = EditorPrefs.GetBool("ShowTooltips", true);
            AutoRigidbody      = EditorPrefs.GetBool("AutoRigidbody", (CSGModel.DefaultSettings & ModelSettingsFlags.AutoUpdateRigidBody) == ModelSettingsFlags.AutoUpdateRigidBody);
            DefaultPreserveUVs = EditorPrefs.GetBool("DefaultPreserveUVs", (CSGModel.DefaultSettings & ModelSettingsFlags.PreserveUVs) == ModelSettingsFlags.PreserveUVs);
            SnapNonCSGObjects  = EditorPrefs.GetBool("SnapNonCSGObjects", true);

            AutoCommitExtrusion = EditorPrefs.GetBool("AutoCommitExtrusion", false);

            MaxSphereSplits = Mathf.Max(3, EditorPrefs.GetInt("MaxSphereSplits", 9));

            CircleSides             = Mathf.Max(3, EditorPrefs.GetInt("CircleSides", 18));
            MaxCircleSides          = Mathf.Max(3, EditorPrefs.GetInt("MaxCircleSides", 144));
            CircleOffset            = EditorPrefs.GetFloat("CircleOffset", 0);
            CircleSmoothShading     = EditorPrefs.GetBool("CircleSmoothShading", true);
            CircleSingleSurfaceEnds = EditorPrefs.GetBool("CircleSingleSurfaceEnds", true);
            CircleDistanceToSide    = EditorPrefs.GetBool("CircleDistanceToSide", true);
            CircleRecenter          = EditorPrefs.GetBool("CircleRecenter", true);


            SphereSplits         = Mathf.Max(1, EditorPrefs.GetInt("SphereSplits", 1));
            SphereOffset         = EditorPrefs.GetFloat("SphereOffset", 0);
            SphereSmoothShading  = EditorPrefs.GetBool("SphereSmoothShading", true);
            SphereDistanceToSide = EditorPrefs.GetBool("SphereDistanceToSide", true);
            HemiSphereMode       = EditorPrefs.GetBool("HemiSphereMode", false);

            LinearStairsStepLength = EditorPrefs.GetFloat("LinearStairsStepLength", 0.30f);
            LinearStairsStepHeight = EditorPrefs.GetFloat("LinearStairsStepHeight", 0.20f);
            LinearStairsStepWidth  = EditorPrefs.GetFloat("LinearStairsStepWidth", 1.0f);
            LinearStairsTotalSteps = EditorPrefs.GetInt("LinearStairsTotalSteps", 4);

            LinearStairsLength       = EditorPrefs.GetFloat("LinearStairsLength", 16.0f);
            LinearStairsHeight       = EditorPrefs.GetFloat("LinearStairsHeight", 16.0f);
            LinearStairsLengthOffset = EditorPrefs.GetFloat("LinearStairsLengthOffset", 0.0f);
            LinearStairsHeightOffset = EditorPrefs.GetFloat("LinearStairsHeightOffset", 0.0f);

            DistanceUnit = GetEnum("DistanceUnit", DistanceUnit.Meters);

            ShowSceneInfo = EditorPrefs.GetBool("ShowSceneInfo", false);


            var sceneViews = SortedSceneViews();

            EnsureValidSceneviewNames(sceneViews);
            var arrayString = EditorPrefs.GetString("Wireframe", string.Empty);

            if (arrayString.Contains(','))
            {
                LegacyLoadWireframeSettings(sceneViews, arrayString);
            }
            else
            {
                LoadWireframeSettings(sceneViews, arrayString);
            }

            UpdateSnapSettings();
        }
Beispiel #5
0
        /// <summary>Converts a <see cref="RealtimeCSG.Legacy.Surface"/>/<see cref="RealtimeCSG.Legacy.TexGen"/>/<see cref="RealtimeCSG.Legacy.TexGenFlags"/> combination into a <see cref="RealtimeCSG.Foundation.SurfaceDescription"/>.</summary>
        /// <param name="surface">A legacy <see cref="RealtimeCSG.Legacy.Surface"/> that describes how the texture space is orientated relative to the brush.</param>
        /// <param name="texGen">A legacy <see cref="RealtimeCSG.Legacy.TexGen"/> that describes how the texture coordinates are calculated in the <see cref="RealtimeCSG.Foundation.SurfaceDescription"/>.</param>
        /// <param name="texGenFlags">A legacy <see cref="RealtimeCSG.Legacy.TexGenFlags"/> enum that describes if the <see cref="RealtimeCSG.Foundation.SurfaceDescription"/> texture generation will be in world-space or brush-space.</param>
        /// <returns>A new <see cref="RealtimeCSG.Foundation.SurfaceDescription"/></returns>
        public static SurfaceDescription CreateSurfaceDescription(Surface surface, TexGen texGen, TexGenFlags texGenFlags)
        {
            var localToTextureSpace = SurfaceUtility.GetLocalToTextureSpaceMatrix(texGen, surface);

            SurfaceDescription description;

            description.smoothingGroup = texGen.SmoothingGroup;
            description.surfaceFlags   = ((texGenFlags & TexGenFlags.WorldSpaceTexture) == 0) ? SurfaceFlags.None : SurfaceFlags.TextureIsInWorldSpace;

            description.UV0.U = localToTextureSpace.GetRow(0);
            description.UV0.V = localToTextureSpace.GetRow(1);

            return(description);
        }
Beispiel #6
0
        public void CheckVersion()
        {
            if (Version >= LatestVersion)
            {
                return;
            }

            if (Version < 1.0f)
            {
                Version = 1.0f;
            }

            if (Version == 1.0f)
            {
                                #pragma warning disable 618 // Type is now obsolete
                if (Shape.Materials != null && Shape.Materials.Length > 0)
                {
                    // update textures
                    if (Shape.TexGens != null)
                    {
                        for (int i = 0; i < Shape.TexGens.Length; i++)
                        {
                            Shape.TexGens[i].RenderMaterial = null;
                        }

                                                #pragma warning disable 618 // Type is now obsolete
                        for (int i = 0; i < Mathf.Min(Shape.Materials.Length, Shape.TexGens.Length); i++)
                        {
                                                        #pragma warning disable 618 // Type is now obsolete
                            Shape.TexGens[i].RenderMaterial = Shape.Materials[i];
                        }

                        for (int i = 0; i < Shape.TexGenFlags.Length; i++)
                        {
                            var oldFlags            = (int)Shape.TexGenFlags[i];
                            var isWorldSpaceTexture = (oldFlags & 1) == 1;

                            var isNotVisible        = (oldFlags & 2) == 2;
                            var isNoCollision       = isNotVisible;
                            var isNotCastingShadows = ((oldFlags & 4) == 0) && !isNotVisible;

                            TexGenFlags newFlags = (TexGenFlags)0;
                            if (isNotVisible)
                            {
                                newFlags |= RealtimeCSG.TexGenFlags.NoRender;
                            }
                            if (isNoCollision)
                            {
                                newFlags |= RealtimeCSG.TexGenFlags.NoCollision;
                            }
                            if (isNotCastingShadows)
                            {
                                newFlags |= RealtimeCSG.TexGenFlags.NoCastShadows;
                            }
                            if (isWorldSpaceTexture)
                            {
                                newFlags |= RealtimeCSG.TexGenFlags.WorldSpaceTexture;
                            }
                        }
                    }
                }
            }

            Version = LatestVersion;
        }
        public static void UpgradeWhenNecessary(CSGBrush brush)
        {
            if (brush.Version >= CSGBrush.CurrentVersion)
            {
                return;
            }

            if (brush.Version < 1.0f)
            {
                brush.Version = 1.0f;
            }

            if (brush.Version == 1.0f)
            {
#pragma warning disable 618 // Type is now obsolete
                if (brush.Shape.Materials != null && brush.Shape.Materials.Length > 0)
                {
                    // update textures
                    if (brush.Shape.TexGens != null)
                    {
                        for (int i = 0; i < brush.Shape.TexGens.Length; i++)
                        {
                            brush.Shape.TexGens[i].RenderMaterial = null;
                        }

#pragma warning disable 618 // Type is now obsolete
                        for (int i = 0; i < Mathf.Min(brush.Shape.Materials.Length, brush.Shape.TexGens.Length); i++)
                        {
#pragma warning disable 618 // Type is now obsolete
                            brush.Shape.TexGens[i].RenderMaterial = brush.Shape.Materials[i];
                        }

                        for (int i = 0; i < brush.Shape.TexGenFlags.Length; i++)
                        {
                            var oldFlags            = (int)brush.Shape.TexGenFlags[i];
                            var isWorldSpaceTexture = (oldFlags & 1) == 1;

                            var isNotVisible        = (oldFlags & 2) == 2;
                            var isNoCollision       = isNotVisible;
                            var isNotCastingShadows = ((oldFlags & 4) == 0) && !isNotVisible;

                            TexGenFlags newFlags = (TexGenFlags)0;
                            if (isNotVisible)
                            {
                                newFlags |= TexGenFlags.NoRender;
                            }
                            if (isNoCollision)
                            {
                                newFlags |= TexGenFlags.NoCollision;
                            }
                            if (isNotCastingShadows)
                            {
                                newFlags |= TexGenFlags.NoCastShadows;
                            }
                            if (isWorldSpaceTexture)
                            {
                                newFlags |= TexGenFlags.WorldSpaceTexture;
                            }
                        }
                    }
                }
            }

            brush.Version = CSGBrush.CurrentVersion;
        }
Beispiel #8
0
        public static bool CheckMaterials(Shape shape)
        {
            bool dirty = false;

            if (shape.Surfaces == null ||
                shape.Surfaces.Length == 0)
            {
                Debug.Log("Surfaces == null || Surfaces.Length == 0");
                return(true);
            }

            if (shape.CutNodes == null || shape.CutNodes.Length < 1)
            {
                shape.CutNodes = new CutNode[shape.Surfaces.Length - 1];
                dirty          = true;
            }

            int maxTexGenIndex = 0;

            for (int i = 0; i < shape.Surfaces.Length; i++)
            {
                maxTexGenIndex = Mathf.Max(maxTexGenIndex, shape.Surfaces[i].TexGenIndex);
            }
            maxTexGenIndex++;

            if (shape.TexGens == null ||
                shape.TexGens.Length < maxTexGenIndex)
            {
                dirty = true;
                var newTexGens     = new TexGen[maxTexGenIndex];
                var newTexGenFlags = new TexGenFlags[maxTexGenIndex];
                if (shape.TexGens != null &&
                    shape.TexGens.Length > 0)
                {
                    for (int i = 0; i < shape.TexGens.Length; i++)
                    {
                        newTexGens[i]     = shape.TexGens[i];
                        newTexGenFlags[i] = shape.TexGenFlags[i];
                    }
                    for (int i = shape.TexGens.Length; i < newTexGens.Length; i++)
                    {
                        newTexGens[i].Color = Color.white;
                    }
                }
                shape.TexGens     = newTexGens;
                shape.TexGenFlags = newTexGenFlags;
            }

            for (int i = 0; i < shape.TexGens.Length; i++)
            {
                if (shape.TexGens[i].Color == Color.clear)
                {
                    shape.TexGens[i].Color = Color.white;
                }
            }

            if (shape.Materials == null ||
                shape.Materials.Length == 0)
            {
                dirty           = true;
                shape.Materials = new Material[shape.TexGens.Length];
            }

            if (shape.TexGens.Length != shape.Materials.Length)
            {
                dirty = true;
                var new_materials = new Material[shape.TexGens.Length];
                Array.Copy(shape.Materials, new_materials, Math.Min(shape.Materials.Length, shape.TexGens.Length));
                shape.Materials = new_materials;
            }
            return(dirty);
        }
        public static TexGenFlags OnSurfaceFlagButtons(TexGenFlags texGenFlags, bool isSceneGUI = false)
        {
            var leftStyle = EditorStyles.miniButtonLeft;
            //var middleStyle = EditorStyles.miniButtonMid;
            var rightStyle = EditorStyles.miniButtonRight;

            var noRender         = (texGenFlags & TexGenFlags.NoRender) == TexGenFlags.NoRender;
            var noCollision      = (texGenFlags & TexGenFlags.NoCollision) == TexGenFlags.NoCollision;
            var noCastShadows    = (texGenFlags & TexGenFlags.NoCastShadows) == TexGenFlags.NoCastShadows;
            var noReceiveShadows = noRender || (texGenFlags & TexGenFlags.NoReceiveShadows) == TexGenFlags.NoReceiveShadows;

            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
            {
                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.Label(ContentShadows, EditorStyles.miniLabel, EditModeSurfaceGUI.smallLabelWidth);
                    EditorGUI.BeginChangeCheck();
                    {
                        // TODO: implement support
                        noReceiveShadows = !GUILayout.Toggle(!noReceiveShadows, ContentReceiveShadowsSurfaces, leftStyle);
                        TooltipUtility.SetToolTip(ToolTipReceiveShadowsSurfaces);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (noReceiveShadows)
                        {
                            texGenFlags |= TexGenFlags.NoReceiveShadows;
                        }
                        else
                        {
                            texGenFlags &= ~TexGenFlags.NoReceiveShadows;
                        }
                        GUI.changed = true;
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        // TODO: implement support
                        noCastShadows = !GUILayout.Toggle(!noCastShadows, ContentCastShadowsSurfaces, rightStyle);
                        TooltipUtility.SetToolTip(ToolTipCastShadowsSurfaces);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (noCastShadows)
                        {
                            texGenFlags |= TexGenFlags.NoCastShadows;
                        }
                        else
                        {
                            texGenFlags &= ~TexGenFlags.NoCastShadows;
                        }
                        GUI.changed = true;
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        noRender = !GUILayout.Toggle(!noRender, ContentVisibleSurfaces, leftStyle);
                        TooltipUtility.SetToolTip(ToolTipVisibleSurfaces);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (noRender)
                        {
                            texGenFlags |= TexGenFlags.NoRender;
                        }
                        else
                        {
                            texGenFlags &= ~TexGenFlags.NoRender;
                        }
                        GUI.changed = true;
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        noCollision = !GUILayout.Toggle(!noCollision, ContentCollisionSurfaces, rightStyle);
                        TooltipUtility.SetToolTip(ToolTipCollisionSurfaces);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (noCollision)
                        {
                            texGenFlags |= TexGenFlags.NoCollision;
                        }
                        else
                        {
                            texGenFlags &= ~TexGenFlags.NoCollision;
                        }
                        GUI.changed = true;
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            return(texGenFlags);
        }