internal static CSGModel GetDefaultCSGModel(Scene scene)
        {
            if (!scene.IsValid() ||
                !scene.isLoaded)
            {
                return(null);
            }

            // make sure we're properly initialized (just in case)
            if (!SceneStates.ContainsKey(scene))
            {
                SceneStates[scene] = new CSGSceneState();
            }
            if (!SceneStates[scene].DefaultModel)
            {
                InitializeDefaultCSGModel(scene, SceneStates[scene], createIfNoExists: true);
            }

            return(SceneStates[scene].DefaultModel);
        }
        static void InitializeDefaultCSGModel(Scene currentScene, CSGSceneState sceneState, bool createIfNoExists = true)
        {
            bool      inPrefabMode        = false;
            Transform prefabRootTransform = null;

#if UNITY_2018_3_OR_NEWER
            var currentPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
            if (currentPrefabStage != null)
            {
                var prefabRoot = currentPrefabStage.prefabContentsRoot;
                prefabRootTransform = prefabRoot.transform;
                inPrefabMode        = (prefabRoot.scene == currentScene);
            }
#endif
            var defaultModelName = inPrefabMode ? DefaultPrefabModelName : DefaultModelName;

            // make sure we have a default CSG model
            sceneState.DefaultModelObject = SceneQueryUtility.GetUniqueHiddenGameObjectInSceneWithName(currentScene, defaultModelName);
            if (createIfNoExists)
            {
                if (!sceneState.DefaultModelObject)
                {
                    sceneState.DefaultModelObject = new GameObject(defaultModelName);
                    sceneState.DefaultModel       = CreateCSGModel(sceneState.DefaultModelObject);
                }
                else
                {
                    sceneState.DefaultModel = sceneState.DefaultModelObject.GetComponent <CSGModel>();
                    if (!sceneState.DefaultModel)
                    {
                        sceneState.DefaultModel = CreateCSGModel(sceneState.DefaultModelObject);
                    }
                }

                // make sure it's transformation has sensible values
                var transform = sceneState.DefaultModel.transform;
                if (inPrefabMode)
                {
                    transform.SetParent(prefabRootTransform, false);
                }
                else
                {
                    transform.parent = null;
                }

                transform.localPosition = MathConstants.zeroVector3;
                transform.localScale    = MathConstants.oneVector3;
                transform.localRotation = Quaternion.identity;

                var defaultFlags =                 //StaticEditorFlags.LightmapStatic |
                                   StaticEditorFlags.BatchingStatic |
                                   StaticEditorFlags.NavigationStatic |
                                   StaticEditorFlags.OccludeeStatic |
                                   StaticEditorFlags.OffMeshLinkGeneration |
                                   StaticEditorFlags.ReflectionProbeStatic;
                GameObjectUtility.SetStaticEditorFlags(sceneState.DefaultModel.gameObject, defaultFlags);

                RegisterModel(sceneState.DefaultModel);
            }

            // do not give default CSG model any extra abilities other than rendering
            //  since an invisible object doesn't work well with navmesh/colliders etc.
            // force the users to use a CSG-model, but gracefully let it still be
            //  visible for objects outside of it.
            if (inPrefabMode)
            {
                sceneState.DefaultModelObject.hideFlags = MeshInstanceManager.ComponentHideFlags | HideFlags.DontSave;
            }
            else
            {
                sceneState.DefaultModelObject.hideFlags = MeshInstanceManager.ComponentHideFlags;
            }
        }