Пример #1
0
		void PaintSquare(Camera camera)
		{
			var wireframeColor = ColorSettings.BoundsOutlines;

			var endPosition = settings.vertices.Length == 1 ? worldPosition : settings.vertices[1];
			var centerPoint = settings.vertices[0];
			var height		= (endPosition - centerPoint).magnitude;

			var upVector = buildPlane.normal * height;

			var point0 = settings.vertices[0] + (gridTangent * settings.sphereRadius) + (gridBinormal * settings.sphereRadius);
			var point1 = settings.vertices[0] + (gridTangent * settings.sphereRadius) - (gridBinormal * settings.sphereRadius);
			var point2 = settings.vertices[0] - (gridTangent * settings.sphereRadius) - (gridBinormal * settings.sphereRadius);
			var point3 = settings.vertices[0] - (gridTangent * settings.sphereRadius) + (gridBinormal * settings.sphereRadius);
			
			var point4 = point0;
			var point5 = point1;
			var point6 = point2;
			var point7 = point3;

            var point8 = point0 + upVector;
            var point9 = point1 + upVector;
            var pointA = point2 + upVector;
            var pointB = point3 + upVector;
			if (!IsHemiSphere)
			{
				point4 -= upVector;
				point5 -= upVector;
				point6 -= upVector;
				point7 -= upVector;
			}

			var points = new Vector3[] { point8, point9, point9, pointA, pointA, pointB, pointB, point8,
										point4, point5, point5, point6, point6, point7, point7, point4,
										point8, point4, point9, point5, pointA, point6, pointB, point7};

			PaintUtility.DrawDottedLines(points, wireframeColor, 4.0f);

			if (settings.vertices.Length == 0)
				return;

			{
				var volume = new Vector3[8];

				var localBounds = new AABB();
				localBounds.Reset();
				localBounds.Extend(toGridQuaternion * (point0 + upVector));
				localBounds.Extend(toGridQuaternion * (point1 + upVector));
				localBounds.Extend(toGridQuaternion * (point2 + upVector));
				localBounds.Extend(toGridQuaternion * (point3 + upVector));
				if (IsHemiSphere)
					localBounds.Extend(toGridQuaternion * point3);
				else
					localBounds.Extend(toGridQuaternion * (point3 - upVector));
				BoundsUtilities.GetBoundsCornerPoints(localBounds, volume);
				
				PaintUtility.RenderBoundsSizes(toGridQuaternion, fromGridQuaternion, camera, volume, Color.white, Color.white, Color.white, true, true, true);
			}
		}
Пример #2
0
		void PaintBounds(Camera camera)
		{
			if (HaveHeight)
			{
				var localBounds = GetShapeBounds(toGridQuaternion);

				var volume = new Vector3[8];
				BoundsUtilities.GetBoundsCornerPoints(localBounds, volume);

				PaintUtility.RenderBoundsSizes(toGridQuaternion, fromGridQuaternion, camera, volume, Color.white, Color.white, Color.white, true, true, true);
			}
		}
Пример #3
0
        void PaintSquare(Camera camera)
        {
            var wireframeColor = ColorSettings.BoundsOutlines;

            if (HaveHeight)
            {
                var localBounds = GetShapeBounds(toGridQuaternion);

                var volume = new Vector3[8];
                BoundsUtilities.GetBoundsCornerPoints(localBounds, volume);

                PaintUtility.DrawDottedLines(Matrix4x4.TRS(Vector3.zero, fromGridQuaternion, Vector3.one), volume, BoundsUtilities.AABBLineIndices, wireframeColor, 4.0f);

                PaintUtility.RenderBoundsSizes(toGridQuaternion, fromGridQuaternion, camera, volume, Color.white, Color.white, Color.white, true, true, true);
            }
        }
        void PaintBounds(Camera camera)
        {
            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);
        }
        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);
        }
Пример #6
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);
        }