void PaintBounds()
        {
            var camera = Camera.current;

            var worldToLocalRotation = GetWorldToLocalRotation();
            var localToWorldRotation = Quaternion.Inverse(worldToLocalRotation);
            var localBounds          = GetShapeBounds(worldToLocalRotation);

            var volume = new Vector3[8];

            BoundsUtilities.GetBoundsCornerPoints(localBounds, volume);

            var boundOutlinesColor = ColorSettings.MeshEdgeOutline;
            var localToWorld       = Matrix4x4.TRS(Vector3.zero, localToWorldRotation, Vector3.one);

            PaintUtility.DrawDottedLines(localToWorld, volume, BoundsUtilities.AABBLineIndices, boundOutlinesColor, 4.0f);
            PaintUtility.DrawLines(localToWorld, volume, BoundsUtilities.AABBLineIndices, GUIConstants.oldLineScale, boundOutlinesColor);

            PaintUtility.RenderBoundsSizes(worldToLocalRotation, localToWorldRotation, camera, volume, Color.white, Color.white, Color.white, true, true, true);
        }
Пример #2
0
        public void EndCommit()
        {
            if (generatedBrushes == null)
            {
                return;
            }
            var bounds = BoundsUtilities.GetBounds(generatedBrushes);

            if (!bounds.IsEmpty())
            {/*
              * var center = bounds.Center - operationGameObject.transform.position;
              *                 GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center);
              *                 SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center);
              * operationGameObject.transform.position += center;*/
                ControlMeshUtility.RebuildShapes(generatedBrushes);
                var models = operationGameObject.GetComponentsInParent <CSGModel>(includeInactive: true);
                var model  = models.Length == 0 ? null : models[0];
                model.forceUpdate = true;

                InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true);
                Undo.CollapseUndoOperations(undoGroupIndex);
                Cleanup();

                if (generatedGameObjects != null &&
                    generatedGameObjects.Length > 0)
                {
                    Selection.objects = generatedGameObjects;
                }

                Reset();
            }

            if (shapeCommitted != null)
            {
                shapeCommitted();
            }
        }
        public bool ValidateDrop(SceneView sceneView)
        {
            if (!sceneView)
            {
                return(false);
            }

            Reset();
            if (DragAndDrop.objectReferences == null ||
                DragAndDrop.objectReferences.Length == 0)
            {
                dragGameObjects = null;
                return(false);
            }

            bool found = false;

            dragGameObjects = new List <GameObject>();
            foreach (var obj in DragAndDrop.objectReferences)
            {
                var gameObject = obj as GameObject;
                if (gameObject == null)
                {
                    continue;
                }

                if (!CSGPrefabUtility.IsPrefabAsset(gameObject))
                {
                    continue;
                }

                dragGameObjects.Add(gameObject);

                if (gameObject.GetComponentInChildren <Renderer>() != null)
                {
                    found = true;
                }
            }
            if (!found || dragGameObjects.Count != 1)
            {
                dragGameObjects = null;
                return(false);
            }

            var dragGameObjectBounds = new AABB();

            dragGameObjectBounds.Reset();
            foreach (var gameObject in dragGameObjects)
            {
                var renderers = gameObject.GetComponentsInChildren <Renderer>();
                if (renderers.Length == 0)
                {
                    continue;
                }
                foreach (var renderer in renderers)
                {
                    var bounds = renderer.bounds;
                    dragGameObjectBounds.Extend(bounds.min);
                    dragGameObjectBounds.Extend(bounds.max);
                }
            }

            if (!dragGameObjectBounds.Valid)
            {
                dragGameObjectBounds.Extend(MathConstants.zeroVector3);
            }

            projectedBounds = new Vector3[8];
            BoundsUtilities.GetBoundsCornerPoints(dragGameObjectBounds, projectedBounds);

            /*
             * var upPlane = new Plane(MathConstants.upVector3, MathConstants.zeroVector3);
             * for (int i = 7; i >= 0; i--)
             * {
             *      projectedBounds[i] = upPlane.Project(projectedBounds[i]);
             *      for (int j = i+1; j < projectedBounds.Length; j++)
             *      {
             *              if (projectedBounds[i] == projectedBounds[j])
             *              {
             *                      ArrayUtility.RemoveAt(ref projectedBounds, j);
             *                      break;
             *              }
             *      }
             * }*/

            haveNoParent = false;
            return(true);
        }
Пример #4
0
        public bool ValidateDrop(SceneView sceneView)
        {
            if (!sceneView)
            {
                return(false);
            }

            Reset();
            if (DragAndDrop.objectReferences == null ||
                DragAndDrop.objectReferences.Length == 0)
            {
                dragGameObjects = null;
                return(false);
            }

            dragGameObjects = new List <GameObject>();
            containsModel   = false;
            foreach (var obj in DragAndDrop.objectReferences)
            {
                var gameObject = obj as GameObject;
                if (gameObject == null)
                {
                    continue;
                }

                if (gameObject.GetComponent <CSGNode>() == null)
                {
                    continue;
                }

                if (gameObject.GetComponentsInChildren <CSGBrush>() == null)
                {
                    continue;
                }

                if (!CSGPrefabUtility.IsPrefabAsset(gameObject))
                {
                    continue;
                }

                dragGameObjects.Add(gameObject);
                containsModel = containsModel || (gameObject.GetComponent <CSGModel>() != null);
            }
            if (dragGameObjects.Count != 1)
            {
                dragGameObjects = null;
                return(false);
            }

            var dragGameObjectBounds = new AABB();

            dragGameObjectBounds.Reset();
            foreach (var gameObject in dragGameObjects)
            {
                var brushes = gameObject.GetComponentsInChildren <CSGBrush>();
                if (brushes.Length == 0)
                {
                    continue;
                }
                dragGameObjectBounds.Add(BoundsUtilities.GetLocalBounds(brushes, gameObject.transform.worldToLocalMatrix));
            }

            if (!dragGameObjectBounds.Valid)
            {
                dragGameObjectBounds.Extend(MathConstants.zeroVector3);
            }

            projectedBounds = new Vector3[8];
            BoundsUtilities.GetBoundsCornerPoints(dragGameObjectBounds, projectedBounds);
            haveNoParent = false;
            return(true);
        }
        public override bool ValidateDrop(bool inSceneView)
        {
            if (!inSceneView)
            {
                return(false);
            }

            Reset();
            if (DragAndDrop.objectReferences == null ||
                DragAndDrop.objectReferences.Length == 0)
            {
                dragGameObjects = null;
                return(false);
            }

            dragGameObjects = new List <GameObject>();
            containsModel   = false;
            foreach (var obj in DragAndDrop.objectReferences)
            {
                var gameObject = obj as GameObject;
                if (gameObject == null)
                {
                    continue;
                }

                if (gameObject.GetComponentInChildren <CSGBrush>() == null)
                {
                    continue;
                }

                if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.None)
                {
                    continue;
                }

                if (PrefabUtility.GetPrefabParent(gameObject) == null &&
                    PrefabUtility.GetPrefabObject(gameObject) != null)
                {
                    dragGameObjects.Add(gameObject);
                }

                containsModel = containsModel || (gameObject.GetComponent <CSGModel>() != null);
            }
            if (dragGameObjects.Count != 1)
            {
                dragGameObjects = null;
                return(false);
            }

            var dragGameObjectBounds = new AABB();

            dragGameObjectBounds.Reset();
            foreach (var gameObject in dragGameObjects)
            {
                var brushes = gameObject.GetComponentsInChildren <CSGBrush>();
                if (brushes.Length == 0)
                {
                    continue;
                }
                dragGameObjectBounds.Add(BoundsUtilities.GetLocalBounds(brushes, gameObject.transform.worldToLocalMatrix));
            }

            if (!dragGameObjectBounds.Valid)
            {
                dragGameObjectBounds.Extend(MathConstants.zeroVector3);
            }

            projectedBounds = new Vector3[8];
            BoundsUtilities.GetBoundsCornerPoints(dragGameObjectBounds, projectedBounds);

            /*
             * var upPlane = new Plane(MathConstants.upVector3, MathConstants.zeroVector3);
             * for (int i = 7; i >= 0; i--)
             * {
             *      projectedBounds[i] = upPlane.Project(projectedBounds[i]);
             *      for (int j = i+1; j < projectedBounds.Length; j++)
             *      {
             *              if (projectedBounds[i] == projectedBounds[j])
             *              {
             *                      ArrayUtility.RemoveAt(ref projectedBounds, j);
             *                      break;
             *              }
             *      }
             * }*/

            haveNoParent = false;
            return(true);
        }