private void DrawBrushButton(PrimitiveBrushType brushType, PrimitiveBrushType?activeType, GUIStyle brushButtonStyle, GUIStyle labelStyle, int width, int height, bool shortMode) { GUI.enabled = !activeType.HasValue || activeType.Value != brushType; if (GUILayout.Button(new GUIContent(" ", SabreCSGResources.GetButtonTexture(brushType)), brushButtonStyle, GUILayout.Width(width), GUILayout.Height(height))) { ChangeBrushesToType(brushType); } Rect lastRect = GUILayoutUtility.GetLastRect(); string name = brushType.ToString(); if (brushType == PrimitiveBrushType.IcoSphere) { name = "Ico"; } if (shortMode && brushType == PrimitiveBrushType.Cylinder) { name = "Cyl"; } if (shortMode && brushType == PrimitiveBrushType.Capsule) { name = "Cap"; } GUI.Label(lastRect, name, labelStyle); }
public static void DrawMarquee(Vector2 marqueeStart, Vector2 marqueeEnd) { Vector2 point1 = EditorHelper.ConvertMousePointPosition(marqueeStart); Vector2 point2 = EditorHelper.ConvertMousePointPosition(marqueeEnd); Rect rect = new Rect(point1.x, point1.y, point2.x - point1.x, point2.y - point1.y); SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); GL.Color(new Color(0.2f, 0.3f, 0.8f, 0.3f)); // Marquee fill (draw double sided) SabreGraphics.DrawScreenRectFill(rect); GL.End(); // Marquee border GL.Begin(GL.LINES); GL.Color(Color.white); // Draw marquee box edges SabreGraphics.DrawScreenRectOuter(rect); GL.End(); GL.PopMatrix(); }
private void OnRepaint(SceneView sceneView, Event e) { OnRepaintGUI(sceneView, e); if (activePolygon != null && activePolygon.Vertices.Length >= 3) { Camera sceneViewCamera = sceneView.camera; SabreCSGResources.GetVertexMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); GL.Color(Color.white); Vector3 target = sceneViewCamera.WorldToScreenPoint(mouseHoverPoint); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } GL.End(); GL.PopMatrix(); Handles.DrawWireArc(mouseHoverPoint, activePolygon.Plane.normal, activePolygon.GetTangent(), 360f, brushRadius); } }
public void OnRepaint(UnityEditor.SceneView sceneView, Event e) { // Selected brush green outline if (!isBrushConvex) { SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); DrawPolygons(Color.red, polygons); } }
public static void ChangePosSnapDistance(float multiplier) { PositionSnapDistance *= multiplier; SabreCSGResources.GetAddMaterial().SetFloat("_GridSize", PositionSnapDistance); SabreCSGResources.GetSubtractMaterial().SetFloat("_GridSize", PositionSnapDistance); SabreCSGResources.GetVolumeMaterial().SetFloat("_GridSize", PositionSnapDistance); SabreCSGResources.GetNoCSGMaterial().SetFloat("_GridSize", PositionSnapDistance); SabreCSGResources.GetCollisionMaterial().SetFloat("_GridSize", PositionSnapDistance); }
/// <summary> /// Tells the brush it has changed /// </summary> /// <param name="polygonsChanged">If set to <c>true</c> polygons will be recached.</param> public override void Invalidate(bool polygonsChanged) { base.Invalidate(polygonsChanged); if (!gameObject.activeInHierarchy) { return; } // previous versions of sabrecsg used to use mesh colliders for ray collision, but that's no longer the case so we clean them up. MeshCollider[] meshColliders = GetComponents <MeshCollider>(); if (meshColliders.Length > 0) { for (int i = 0; i < meshColliders.Length; i++) { DestroyImmediate(meshColliders[i]); } } // Make sure there is a mesh filter on this object MeshFilter meshFilter = gameObject.AddOrGetComponent <MeshFilter>(); MeshRenderer meshRenderer = gameObject.AddOrGetComponent <MeshRenderer>(); bool requireRegen = false; // If the cached ID hasn't been set or we mismatch if (cachedInstanceID == 0 || gameObject.GetInstanceID() != cachedInstanceID) { requireRegen = true; cachedInstanceID = gameObject.GetInstanceID(); } Mesh renderMesh = meshFilter.sharedMesh; if (requireRegen) { renderMesh = new Mesh(); } if (polygons != null) { List <int> polygonIndices; BrushFactory.GenerateMeshFromPolygons(polygons, ref renderMesh, out polygonIndices); } if (mode == CSGMode.Subtract) { MeshHelper.Invert(ref renderMesh); } // Displace the triangles for display along the normals very slightly (this is so we can overlay built // geometry with semi-transparent geometry and avoid depth fighting) MeshHelper.Displace(ref renderMesh, 0.001f); meshFilter.sharedMesh = renderMesh; meshRenderer.receiveShadows = false; meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshFilter.hideFlags = HideFlags.NotEditable; // | HideFlags.HideInInspector; meshRenderer.hideFlags = HideFlags.NotEditable; // | HideFlags.HideInInspector; #if UNITY_EDITOR Material material; if (IsNoCSG) { material = SabreCSGResources.GetNoCSGMaterial(); } else { if (this.mode == CSGMode.Add) { material = SabreCSGResources.GetAddMaterial(); } else { material = SabreCSGResources.GetSubtractMaterial(); } } if (meshRenderer.sharedMaterial != material) { meshRenderer.sharedMaterial = material; } #endif // isBrushConvex = GeometryHelper.IsBrushConvex(polygons); if (polygonsChanged) { RecalculateBrushCache(); } UpdateVisibility(); objectVersionSerialized++; objectVersionUnserialized = objectVersionSerialized; if (cachedWorldTransform == null) { cachedWorldTransform = new WorldTransformData(transform); } cachedWorldTransform.SetFromTransform(transform); }
private static void Draw() { SceneView sceneView = SceneView.currentDrawingSceneView; // If the user has turned on hiding of perspectve grid then hide it if perspective if (!sceneView.orthographic && CurrentSettings.HideGridInPerspective) { return; } // Cache additional references Camera camera = sceneView.camera; Transform transform = camera.transform; float fullSnapDistance = CurrentSettings.PositionSnapDistance; float snapDistance = fullSnapDistance; // Calculate various camera positions and its orientation EditorHelper.SceneViewCamera cameraOrientation = EditorHelper.GetSceneViewCamera(sceneView); // True if the camera is both orthographic (iso) and axis-aligned bool orthographicAxisAligned = sceneView.orthographic && cameraOrientation != EditorHelper.SceneViewCamera.Other; Vector3 cameraPosition = transform.position; Vector3 roundedCameraPosition = MathHelper.RoundVector3(cameraPosition, snapDistance); // Calculate the world vectors to use for the X and Y grid axes Vector3 xDirection = orthographicAxisAligned ? transform.right : Vector3.right; Vector3 yDirection = orthographicAxisAligned ? transform.up : Vector3.forward; // Now calculate a depth offset to help with dealing with objects far from the origin Vector3 depthOffset = Vector3.zero; if (orthographicAxisAligned) { float depthFudge = 1; depthOffset = transform.forward * (camera.nearClipPlane + depthFudge + Vector3.Dot(cameraPosition, transform.forward)); // Debug.Log(camera.nearClipPlane + " to " + camera.farClipPlane); // Debug.Log(depthOffset); } else { depthOffset = Vector3.zero; } // Line colors Color normalLine = new Color32(200, 200, 200, 128); Color smallestLine = new Color32(50, 50, 50, 128); Color xAxisColor = ColorForVector(xDirection); Color yAxisColor = ColorForVector(yDirection); // How many lines to draw in each axis int xCount; int yCount; // Center point of the grid in each axis int xMid; int yMid; bool scaledUp = false; // Width of one world unit in screen pixels float gridWidthPixels = CalculateWorldUnitScreenSize(camera, 1); if (snapDistance >= 8) { gridWidthPixels = CalculateWorldUnitScreenSize(camera, snapDistance); } if (gridWidthPixels < MIN_VISIBLE) { if (snapDistance > 8) { snapDistance = Mathf.Pow(Mathf.Floor(Mathf.Log(snapDistance, 8)), 8); gridWidthPixels = CalculateWorldUnitScreenSize(camera, snapDistance); } while (gridWidthPixels < MIN_VISIBLE) { if (snapDistance < 8) { snapDistance = 8; } else { snapDistance *= 8; } scaledUp = true; gridWidthPixels = CalculateWorldUnitScreenSize(camera, snapDistance); } } // Alpha of the granular lines, generally based on distance float minorLineAlphaMultiplier = Mathf.InverseLerp(MIN_VISIBLE, MAX_VISIBLE, gridWidthPixels); float sanityScalar = Mathf.Max(1, snapDistance) * Mathf.Lerp(2, 1, minorLineAlphaMultiplier); if (orthographicAxisAligned) { float cameraHeight = camera.orthographicSize * 2; float cameraWidth = camera.aspect * cameraHeight; xCount = Mathf.CeilToInt(cameraWidth / snapDistance); yCount = Mathf.CeilToInt(cameraHeight / snapDistance); xMid = (int)(Vector3.Dot(roundedCameraPosition, xDirection) / snapDistance); yMid = (int)(Vector3.Dot(roundedCameraPosition, yDirection) / snapDistance); } else { List <Vector3> pointsInGrid = GetGridMinMax(camera); Vector3 pivotPointOnGrid = sceneView.pivot; pivotPointOnGrid.y = 0; pointsInGrid.Add(pivotPointOnGrid); Vector3 min = pointsInGrid[0]; Vector3 max = pointsInGrid[0]; // Calculate min,max for (int i = 1; i < pointsInGrid.Count; i++) { min.x = Mathf.Min(pointsInGrid[i].x, min.x); min.z = Mathf.Min(pointsInGrid[i].z, min.z); max.x = Mathf.Max(pointsInGrid[i].x, max.x); max.z = Mathf.Max(pointsInGrid[i].z, max.z); } // Ensure the grid isn't crazily big min.x = Mathf.Max(min.x, pivotPointOnGrid.x - MAJOR_LINE_DISTANCE * sanityScalar); min.z = Mathf.Max(min.z, pivotPointOnGrid.z - MAJOR_LINE_DISTANCE * sanityScalar); max.x = Mathf.Min(max.x, pivotPointOnGrid.x + MAJOR_LINE_DISTANCE * sanityScalar); max.z = Mathf.Min(max.z, pivotPointOnGrid.z + MAJOR_LINE_DISTANCE * sanityScalar); // Now calculate grid line count xCount = Mathf.CeilToInt((max.x - min.x) / snapDistance); yCount = Mathf.CeilToInt((max.z - min.z) / snapDistance); xMid = Mathf.RoundToInt((min.x + max.x) / 2f / snapDistance); yMid = Mathf.RoundToInt((min.z + max.z) / 2f / snapDistance); } // Pad out the edge case xCount += 2; yCount += 2; int xStart = xMid - xCount / 2; int yStart = yMid - yCount / 2; int xEnd = xMid + xCount / 2; int yEnd = yMid + yCount / 2; Vector3 cameraPositionOnPlane = new Vector3(transform.position.x, 0, transform.position.z); // Start rendering SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); GL.Begin(GL.LINES); int lineDistributonWorld = 8; while (lineDistributonWorld <= snapDistance) { lineDistributonWorld *= 8; } // Calculate repetition count of the distribution lines int lineDistributionCount; if (snapDistance < lineDistributonWorld) { lineDistributionCount = (int)(lineDistributonWorld / snapDistance); } else { lineDistributionCount = 1; } int gridJump = 8; // Ensure we don't split grid lines at too high a density when drawing as that would kill performance if (snapDistance < 1) { gridJump = Mathf.RoundToInt(gridJump / snapDistance); } for (int y = yStart; y <= yEnd; y++) { Color sourceColor = normalLine; bool majorLine = true; if (y == 0) { sourceColor = xAxisColor; } else if (y % lineDistributionCount != 0) { majorLine = false; if (!scaledUp) { sourceColor = smallestLine; } sourceColor.a *= minorLineAlphaMultiplier * 0.6f; } float activeDistance = sanityScalar * (majorLine ? MAJOR_LINE_DISTANCE : MINOR_LINE_DISTANCE); for (int x = xStart; x < xEnd; x += gridJump) { Color color = sourceColor; Vector3 yOffset = y * yDirection * snapDistance; Vector3 center = depthOffset + yOffset; Vector3 testPoint = center + xDirection * (x + gridJump / 2f) * snapDistance; testPoint.y = 0; float squareDistance = (testPoint - cameraPositionOnPlane).sqrMagnitude; if (squareDistance > (activeDistance * activeDistance)) { continue; } float distance = Mathf.Sqrt(squareDistance); color.a *= Mathf.InverseLerp(activeDistance, activeDistance / 2f, distance); GL.Color(color); GL.Vertex(center + xDirection * (x + 0) * snapDistance); GL.Vertex(center + xDirection * (x + gridJump) * snapDistance); } } for (int x = xStart; x <= xEnd; x++) { Color sourceColor = normalLine; bool majorLine = true; if (x == 0) { sourceColor = yAxisColor; } else if (x % lineDistributionCount != 0) { majorLine = false; if (!scaledUp) { sourceColor = smallestLine; } sourceColor.a *= minorLineAlphaMultiplier * 0.6f; } float activeDistance = sanityScalar * (majorLine ? MAJOR_LINE_DISTANCE : MINOR_LINE_DISTANCE); for (int y = yStart; y < yEnd; y += gridJump) { Color color = sourceColor; Vector3 xOffset = x * xDirection * snapDistance; Vector3 center = depthOffset + xOffset; Vector3 testPoint = center + yDirection * (y + gridJump / 2f) * snapDistance; testPoint.y = 0; float squareDistance = (testPoint - cameraPositionOnPlane).sqrMagnitude; if (squareDistance > (activeDistance * activeDistance)) { continue; } float distance = Mathf.Sqrt(squareDistance); color.a *= Mathf.InverseLerp(activeDistance, activeDistance * 0.5f, distance); GL.Color(color); GL.Vertex(center + yDirection * (y + 0) * snapDistance); GL.Vertex(center + yDirection * (y + gridJump) * snapDistance); } } GL.End(); }
public static void DrawPlane(UnityEngine.Plane plane, Vector3 center, Color colorFront, Color colorBack, float size) { SabreCSGResources.GetPlaneMaterial().SetPass(0); GL.Begin(GL.QUADS); Vector3 normal = plane.normal.normalized; Vector3 tangent; if (normal == Vector3.up || normal == Vector3.down) { tangent = Vector3.Cross(normal, Vector3.forward).normalized; } else { tangent = Vector3.Cross(normal, Vector3.up).normalized; } Vector3 binormal = Quaternion.AngleAxis(90, normal) * tangent; // GL.Color(colorFront); // GL.Vertex(center + (normal * -plane.distance) - tangent * size - binormal * size); // GL.Vertex(center + (normal * -plane.distance) + tangent * size - binormal * size); // GL.Vertex(center + (normal * -plane.distance) + tangent * size + binormal * size); // GL.Vertex(center + (normal * -plane.distance) - tangent * size + binormal * size); // // GL.Color(colorBack); // GL.Vertex(center + (normal * -plane.distance) - tangent * size + binormal * size); // GL.Vertex(center + (normal * -plane.distance) + tangent * size + binormal * size); // GL.Vertex(center + (normal * -plane.distance) + tangent * size - binormal * size); // GL.Vertex(center + (normal * -plane.distance) - tangent * size - binormal * size); GL.Color(colorFront); GL.Vertex(center - tangent * size - binormal * size); GL.Vertex(center + tangent * size - binormal * size); GL.Vertex(center + tangent * size + binormal * size); GL.Vertex(center - tangent * size + binormal * size); GL.Color(colorBack); GL.Vertex(center - tangent * size + binormal * size); GL.Vertex(center + tangent * size + binormal * size); GL.Vertex(center + tangent * size - binormal * size); GL.Vertex(center - tangent * size - binormal * size); GL.End(); GL.Begin(GL.LINES); GL.Color(Color.white); GL.Vertex(center - tangent * size + binormal * size); GL.Vertex(center + tangent * size + binormal * size); GL.Vertex(center + tangent * size + binormal * size); GL.Vertex(center + tangent * size - binormal * size); GL.Vertex(center + tangent * size - binormal * size); GL.Vertex(center - tangent * size - binormal * size); GL.Vertex(center - tangent * size - binormal * size); GL.Vertex(center - tangent * size + binormal * size); GL.Color(Color.green); Vector3 normalOffset = -normal * 0.01f; GL.Vertex(center + normalOffset - tangent * size + binormal * size); GL.Vertex(center + normalOffset + tangent * size + binormal * size); GL.Vertex(center + normalOffset + tangent * size + binormal * size); GL.Vertex(center + normalOffset + tangent * size - binormal * size); GL.Vertex(center + normalOffset + tangent * size - binormal * size); GL.Vertex(center + normalOffset - tangent * size - binormal * size); GL.Vertex(center + normalOffset - tangent * size - binormal * size); GL.Vertex(center + normalOffset - tangent * size + binormal * size); GL.Color(Color.red); normalOffset = normal * 0.01f; GL.Vertex(center + normalOffset - tangent * size + binormal * size); GL.Vertex(center + normalOffset + tangent * size + binormal * size); GL.Vertex(center + normalOffset + tangent * size + binormal * size); GL.Vertex(center + normalOffset + tangent * size - binormal * size); GL.Vertex(center + normalOffset + tangent * size - binormal * size); GL.Vertex(center + normalOffset - tangent * size - binormal * size); GL.Vertex(center + normalOffset - tangent * size - binormal * size); GL.Vertex(center + normalOffset - tangent * size + binormal * size); GL.End(); }
void OnRepaint(SceneView sceneView, Event e) { if (primaryTargetBrush != null) { // Use a helper method to draw a visualisation of the clipping plane float largestExtent = GetBounds().GetLargestExtent(); float planeSize = largestExtent * 4f; // clipPlane. SabreGraphics.DrawPlane(displayPlane, planePosition, new Color(0f, 1f, 0f, .3f), new Color(1f, 0f, 0f, .3f), planeSize); // Selected brush green outline SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); // Draw black lines where the clip plane intersects the brushes if (!sceneView.camera.orthographic || EditorHelper.GetSceneViewCamera(sceneView) == EditorHelper.SceneViewCamera.Other) { GL.Begin(GL.LINES); GL.Color(Color.black); foreach (PrimitiveBrush brush in targetBrushes) { Polygon[] polygons = brush.GenerateTransformedPolygons(); foreach (Polygon polygon in polygons) { Vector3 position1; Vector3 position2; if (Polygon.PlanePolygonIntersection(polygon, out position1, out position2, displayPlane)) { GL.Vertex(position1); GL.Vertex(position2); } } } GL.End(); } if (displayPoint) { Camera sceneViewCamera = sceneView.camera; SabreCSGResources.GetVertexMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); // Draw points in reverse order because we want the precedence to be Red, Green, Blue GL.Color(Color.blue); Vector3 target = sceneViewCamera.WorldToScreenPoint(points[2]); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } GL.Color(Color.green); target = sceneViewCamera.WorldToScreenPoint(points[1]); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } GL.Color(Color.red); target = sceneViewCamera.WorldToScreenPoint(points[0]); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } GL.End(); GL.PopMatrix(); } } // Draw UI specific to this editor // GUI.backgroundColor = Color.red; Rect rectangle = new Rect(0, 50, 210, 130); GUIStyle toolbar = new GUIStyle(EditorStyles.toolbar); toolbar.normal.background = SabreCSGResources.ClearTexture; toolbar.fixedHeight = rectangle.height; #if UNITY_2021_2_OR_NEWER SabreToolsOverlay.window1 = () => OnToolbarGUI(0); #else GUILayout.Window(140006, rectangle, OnToolbarGUI, "", toolbar); #endif }
private static void OnRepaint(SceneView sceneView) { float distanceScaler = 1f; #if UNITY_5_4_OR_NEWER distanceScaler = EditorGUIUtility.pixelsPerPoint; #endif // Distance in points from the radial center to the center of each option circle float distance = 100 * distanceScaler; // Number of sectors (or slices) the circle is cut into int angleCount = messages.Length; // Radians angle that each sector takes up float angleDelta = (Mathf.PI * 2f) / (float)angleCount; // Radial center position Vector2 centerPosition = new Vector2(Screen.width / 2, Screen.height / 2); // Sector being highlighted int highlightIndex = GetIndex(centerPosition); GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel); labelStyle.alignment = TextAnchor.MiddleCenter; // Draw normal circles SabreCSGResources.GetCircleMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); for (int i = 0; i < angleCount; i++) { float angle = i * angleDelta; Color color = colors[i]; // Highlighted circle should be a bit more opaque if (i == highlightIndex) { color.a = 0.75f; } else { color.a = 0.5f; } GL.Color(color); Vector3 position = centerPosition + distance * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); SabreGraphics.DrawBillboardQuad(position, 64, 64); } // Draw white dots from the center towards the highlighted circle if (highlightIndex != -1) { float angle = highlightIndex * angleDelta; GL.Color(Color.white); Vector3 position = centerPosition; SabreGraphics.DrawBillboardQuad(position, 8, 8); position = centerPosition + 20 * distanceScaler * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); SabreGraphics.DrawBillboardQuad(position, 16, 16); position = centerPosition + 50 * distanceScaler * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); SabreGraphics.DrawBillboardQuad(position, 32, 32); } else { // No highlighted option, just draw a white dot at the center GL.Color(Color.white); Vector3 position = centerPosition; SabreGraphics.DrawBillboardQuad(position, 16, 16); } GL.End(); GL.PopMatrix(); // Draw a white circle around the edge of the higlighted circle if (highlightIndex != -1) { SabreCSGResources.GetCircleOutlineMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); float angle = highlightIndex * angleDelta; GL.Color(Color.white); Vector3 position = centerPosition + distance * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); SabreGraphics.DrawBillboardQuad(position, 64, 64); GL.End(); GL.PopMatrix(); } // Draw the text Vector3 screenOffset = new Vector3(0, 5, 0); for (int i = 0; i < angleCount; i++) { string message = messages[i]; // The Iso/Persp toggle should show the appropriate text based on active scene view if (message == "Iso" && sceneView.orthographic) { message = "Persp"; } // Make the font size bigger for a highlighted option if (i == highlightIndex) { labelStyle.fontSize = 14; } else { labelStyle.fontSize = 12; } float angle = i * angleDelta; Vector3 position = centerPosition + distance * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); // Offset the position slightly so that it better aligns with the drawn circle position += screenOffset * distanceScaler; // Need to manually offset the text to be center aligned for some reason Vector2 size = labelStyle.CalcSize(new GUIContent(message)); position += new Vector3(-size.x * distanceScaler / 4f, 0, 0); // Calculate the world position of the screen point just in front of the camera Ray ray = sceneView.camera.ScreenPointToRay(position); Vector3 world = ray.origin + ray.direction * 0.01f; // Draw using a world space Handle label Handles.Label(world, message, labelStyle); } }
private void OnRepaint(SceneView sceneView, Event e) { Camera sceneViewCamera = sceneView.camera; // if(hoverPoint.HasValue) { // Draw the active polygon if (activePolygon != null) { SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); SabreGraphics.DrawPolygons(new Color(1, 1, 0, 0.15f), new Color(1, 1, 0, 0.5f), activePolygon); } SabreCSGResources.GetVertexMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); if (activePolygon != null) { GL.Color(Color.yellow);// new Color(0.75f,0.75f,0.75f,1)); } else { GL.Color(Color.white); } Vector3 target = sceneViewCamera.WorldToScreenPoint(hoverPoint); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } for (int i = 0; i < hitPoints.Count; i++) { target = sceneViewCamera.WorldToScreenPoint(hitPoints[i]); GL.Color(Color.blue); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } } GL.End(); GL.PopMatrix(); } if (drawMode == DrawMode.RectangleBase || drawMode == DrawMode.PolygonBase) { List <Vector3> pointsToDraw = new List <Vector3>(); if (drawMode == DrawMode.RectangleBase) { pointsToDraw.AddRange(GetRectanglePoints()); } else { pointsToDraw.AddRange(hitPoints); pointsToDraw.Insert(pointsToDraw.Count, hoverPoint); } SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); // GL.Begin(GL); // GL.Color(new Color32(0, 181, 255, 100)); // // // Draw each point // for (int i = 0; i < pointsToDraw.Count; i++) // { // GL.Vertex(pointsToDraw[i]); // } // // GL.End(); // Marquee border GL.Begin(GL.LINES); if (csgMode == CSGMode.Add) { GL.Color(Color.blue); } else if (csgMode == CSGMode.Subtract) { GL.Color(Color.yellow); } // Draw lines between all the points for (int i = 0; i < pointsToDraw.Count; i++) { // In polygon mode, if it's bigger than a line, draw the last edge in grey if (i == pointsToDraw.Count - 1 && drawMode == DrawMode.PolygonBase && pointsToDraw.Count > 2 && !selectingHeight) { GL.Color(Color.grey); } // Draw a line from one point to the next GL.Vertex(pointsToDraw[i]); GL.Vertex(pointsToDraw[(i + 1) % pointsToDraw.Count]); } if (selectingHeight) { Vector3 offset = GetActivePlane().normal *prismHeight; for (int i = 0; i < pointsToDraw.Count; i++) { // Draw a line from one point to the next GL.Vertex(pointsToDraw[i]); GL.Vertex(pointsToDraw[i] + offset); } GL.Color(Color.grey); // Draw grid lines along the prism to indicate size for (int heightLine = 1; heightLine < Mathf.Abs(prismHeight); heightLine++) { for (int i = 0; i < pointsToDraw.Count; i++) { Vector3 gridOffset = GetActivePlane().normal *heightLine *Mathf.Sign(prismHeight); // Draw a line from one point to the next GL.Vertex(pointsToDraw[i] + gridOffset); GL.Vertex(pointsToDraw[(i + 1) % pointsToDraw.Count] + gridOffset); } } GL.Color(Color.green); for (int i = 0; i < pointsToDraw.Count; i++) { // Draw a line from one point to the next GL.Vertex(pointsToDraw[i] + offset); GL.Vertex(pointsToDraw[(i + 1) % pointsToDraw.Count] + offset); } } GL.End(); } // Rect rectangle = new Rect(0, 50, 210, 130); // GUIStyle toolbar = new GUIStyle(EditorStyles.toolbar); // toolbar.normal.background = SabreCSGResources.ClearTexture; // toolbar.fixedHeight = rectangle.height; // GUILayout.Window(140010, rectangle, OnToolbarGUI, "",toolbar); }
void DrawVertices(SceneView sceneView, Event e) { Camera sceneViewCamera = sceneView.camera; SabreCSGResources.GetVertexMaterial().SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(); GL.Begin(GL.QUADS); // Draw each handle, colouring it if it's selected foreach (PrimitiveBrush brush in targetBrushes) { Polygon[] polygons = brush.GetPolygons(); Vector3 target; for (int i = 0; i < polygons.Length; i++) { for (int j = 0; j < polygons[i].Vertices.Length; j++) { Vertex vertex = polygons[i].Vertices[j]; if (selectedVertices.ContainsKey(vertex)) { GL.Color(new Color32(0, 255, 128, 255)); } else { GL.Color(Color.white); } target = sceneViewCamera.WorldToScreenPoint(brush.transform.TransformPoint(vertex.Position)); if (target.z > 0) { // Make it pixel perfect target = MathHelper.RoundVector3(target); SabreGraphics.DrawBillboardQuad(target, 8, 8); } } } } GL.End(); // Draw lines for selected edges SabreCSGResources.GetSelectedBrushMaterial().SetPass(0); GL.Begin(GL.LINES); GL.Color(Color.green); for (int edgeIndex = 0; edgeIndex < selectedEdges.Count; edgeIndex++) { Edge edge = selectedEdges[edgeIndex]; if (selectedVertices.ContainsKey(edge.Vertex1)) { Brush brush = selectedVertices[edge.Vertex1]; Vector3 target1 = sceneViewCamera.WorldToScreenPoint(brush.transform.TransformPoint(edge.Vertex1.Position)); Vector3 target2 = sceneViewCamera.WorldToScreenPoint(brush.transform.TransformPoint(edge.Vertex2.Position)); if (target1.z > 0 && target2.z > 0) { SabreGraphics.DrawScreenLine(target1, target2); } } } GL.End(); GL.PopMatrix(); }