public static void DrawSimpleOutlines(LineMeshManager lineMeshManager, GeometryWireframe outline, Matrix4x4 transformation, Color color) { if (outline == null || outline.vertices == null || outline.vertices.Length == 0 || (outline.visibleOuterLines == null && outline.invisibleOuterLines == null && outline.visibleInnerLines == null && outline.invisibleInnerLines == null && outline.invalidLines == null)) { return; } var vertices = outline.vertices; var indices = outline.visibleOuterLines; if (indices != null && indices.Length > 0 && (indices.Length & 1) == 0) { lineMeshManager.DrawLines(transformation, vertices, indices, color); } indices = outline.invisibleOuterLines; if (indices != null && indices.Length > 0 && (indices.Length & 1) == 0) { lineMeshManager.DrawLines(transformation, vertices, indices, color); } }
public void Update(SceneView sceneView, CSGBrush[] brushes, ControlMesh[] controlMeshes, ControlMeshState[] meshStates) { if (brushes.Length == 0) { _outlinesManager.Clear(); _edgeColorsManager.Clear(); _polygonManager.Clear(); return; } _outlinesManager.Begin(); _edgeColorsManager.Begin(); _polygonManager.Begin(); for (var t = 0; t < brushes.Length; t++) { var brush = brushes[t]; if (!brush) { continue; } var meshState = meshStates[t]; if (meshState.WorldPoints.Length == 0 && meshState.Edges.Length == 0) { continue; } if (!meshState.UpdateColors(sceneView, brush, controlMeshes[t])) { continue; } _outlinesManager.DrawLines(meshState.WorldPoints, meshState.Edges, ColorSettings.MeshEdgeOutline, thickness: 1.0f); //, zTest: false); _edgeColorsManager.DrawLines(meshState.WorldPoints, meshState.Edges, meshState.EdgeColors, thickness: 1.0f); //, zTest: false); for (int p = 0; p < meshState.PolygonPointIndices.Length; p++) { if (meshState.PolygonColors[p].a < (1.0f / 255.0f)) { continue; } var color = meshState.PolygonColors[p]; var polygonPoints = meshState.PolygonPointIndices[p]; _polygonManager.DrawPolygon(meshState.WorldPoints, polygonPoints, color); } } _polygonManager.End(); _edgeColorsManager.End(); _outlinesManager.End(); }
public static void DrawSimpleOutlines(LineMeshManager lineMeshManager, GeometryWireframe outline, Vector3 translation, Color color) { if (outline == null || outline.vertices == null || outline.vertices.Length == 0 || (outline.visibleOuterLines == null && outline.invisibleOuterLines == null && outline.visibleInnerLines == null && outline.invisibleInnerLines == null && outline.invalidLines == null)) { return; } var translationMatrix = MathConstants.identityMatrix; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; var vertices = outline.vertices; var indices = outline.visibleOuterLines; if (indices != null && indices.Length > 0 && (indices.Length & 1) == 0) { lineMeshManager.DrawLines(translationMatrix, vertices, indices, color); } indices = outline.invisibleOuterLines; if (indices != null && indices.Length > 0 && (indices.Length & 1) == 0) { lineMeshManager.DrawLines(translationMatrix, vertices, indices, color); } }
public static void DrawOutlines(LineMeshManager zTestLineMeshManager, LineMeshManager noZTestLineMeshManager, GeometryWireframe[] outlines, Matrix4x4[] transformations, Color outerColor, Color outerColorOccluded, Color innerColor, Color innerColorOccluded, float thickness = -1) { if (Event.current.type != EventType.Repaint) { return; } if (outlines == null || transformations == null || outlines.Length != transformations.Length) { zTestLineMeshManager.Clear(); noZTestLineMeshManager.Clear(); return; } zTestLineMeshManager.Begin(); if (thickness <= 0) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline == null || outline.vertices == null || outline.vertices.Length == 0) { continue; } var transformation = transformations[i]; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { zTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, outerColor); //, zTest: true); //PaintUtility.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, outerColor);//CustomWireMaterial } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { zTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, innerColor); //, zTest: true);//CustomWireMaterial //PaintUtility.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, innerColor);//CustomWireMaterial } } } else { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline == null || outline.vertices == null || outline.vertices.Length == 0) { continue; } var transformation = transformations[i]; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { //PaintUtility.DrawUnoccludedLines(transformation, outline.vertices, outline.visibleOuterLines, outerColor); zTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, outerColor, thickness: thickness); //, zTest: true); //PaintUtility.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, thickness, outerColor);//CustomThickWireMaterial } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { //PaintUtility.DrawUnoccludedLines(transformation, outline.vertices, outline.visibleInnerLines, innerColor); zTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, innerColor, thickness: thickness); //, zTest: true); //PaintUtility.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, thickness, innerColor);//CustomThickWireMaterial } } } zTestLineMeshManager.End(); noZTestLineMeshManager.Begin(); for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline == null || outline.vertices == null || outline.vertices.Length == 0) { continue; } var transformation = transformations[i]; Handles.matrix = transformation; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { //Handles.color = outerColorOccluded; //Handles.DrawDottedLines(outline.vertices, outline.visibleOuterLines, visibleOuterLineDots); // internal noZTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, outerColorOccluded, dashSize: visibleOuterLineDots); //, zTest: false); } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { //Handles.color = innerColorOccluded; //Handles.DrawDottedLines(outline.vertices, outline.visibleInnerLines, visibleInnerLineDots); // internal noZTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, innerColorOccluded, dashSize: visibleInnerLineDots); //, zTest: false); } if (outline.invisibleOuterLines != null && outline.invisibleOuterLines.Length > 0) { //Handles.color = outerColorOccluded; //Handles.DrawDottedLines(outline.vertices, outline.invisibleOuterLines, invisibleOuterLineDots); // internal noZTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.invisibleOuterLines, outerColorOccluded, dashSize: invisibleOuterLineDots); //, zTest: false); } if (outline.invisibleInnerLines != null && outline.invisibleInnerLines.Length > 0) { //Handles.color = innerColor; //Handles.DrawDottedLines(outline.vertices, outline.invisibleInnerLines, invisibleInnerLineDots); // internal noZTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.invisibleInnerLines, innerColor, dashSize: invisibleInnerLineDots); //, zTest: false); } #if TEST_ENABLED if (outline.invalidLines != null && outline.invalidLines.Length > 0) { //Handles.color = Color.red; //Handles.DrawDottedLines(outline.vertices, outline.invalidLines, invalidLineDots); // internal noZTestLineMeshManager.DrawLines(transformation, outline.vertices, outline.invalidLines, Color.red, dashSize: invalidLineDots); //, zTest: false); } #endif } noZTestLineMeshManager.End(); }
public static void DrawSurfaceOutlines(LineMeshManager visibleLinesMeshManager, LineMeshManager invisibleLinesMeshManager, PolygonMeshManager visibleSurfaceMeshManager, GeometryWireframe[] outlines, Matrix4x4[] transformations, Color visibleInnerColor, Color visibleOuterColor, Color visibleOutlineColor, Color invisibleInnerColor, Color invisibleOuterColor, Color invisibleOutlineColor, Color surfaceColor, float thickness = GUIConstants.thickLineScale) { if (outlines == null) { return; } if (invisibleOutlineColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var transformation = transformations[i]; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, invisibleOutlineColor); } if (outline.invisibleOuterLines != null && outline.invisibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.invisibleOuterLines, invisibleOutlineColor); } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, invisibleOutlineColor); } if (outline.invisibleInnerLines != null && outline.invisibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.invisibleInnerLines, invisibleOutlineColor); } } } if (invisibleInnerColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var transformation = transformations[i]; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, invisibleInnerColor, dashSize: visibleOuterLineDots); } if (outline.invisibleOuterLines != null && outline.invisibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.invisibleOuterLines, invisibleInnerColor, dashSize: invisibleOuterLineDots); } } } if (invisibleOuterColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var transformation = transformations[i]; if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, invisibleOuterColor, dashSize: visibleInnerLineDots); } if (outline.invisibleInnerLines != null && outline.invisibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.invisibleInnerLines, invisibleOuterColor, dashSize: invisibleInnerLineDots); } } } #if TEST_ENABLED for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline.invalidLines == null || outline.invalidLines.Length == 0) { continue; } var transformation = transformations[i]; invisibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.invalidLines, Color.red, dashSize: invalidLineDots); } #endif if (visibleOutlineColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var transformation = transformations[i]; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length != 0) { visibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, visibleOutlineColor, thickness: thickness + 2.0f); } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length != 0) { visibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, visibleOutlineColor, thickness: thickness + 2.0f); } } } if (visibleOuterColor.a >= kMinAlpha || visibleInnerColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var transformation = transformations[i]; if (visibleInnerColor.a >= kMinAlpha && outline.visibleOuterLines != null && outline.visibleOuterLines.Length != 0) { visibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleOuterLines, visibleInnerColor, thickness: thickness * 0.5f); } if (visibleOuterColor.a >= kMinAlpha && outline.visibleInnerLines != null && outline.visibleInnerLines.Length != 0) { visibleLinesMeshManager.DrawLines(transformation, outline.vertices, outline.visibleInnerLines, visibleOuterColor, thickness: thickness * 0.5f); } } } if (surfaceColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline.visibleTriangles == null || outline.visibleTriangles.Length == 0) { continue; } var transformation = transformations[i]; visibleSurfaceMeshManager.DrawTriangles(transformation, outline.vertices, outline.visibleTriangles, surfaceColor); } } }
public static void DrawTexGenOutlines(LineMeshManager visibleLinesMeshManager, LineMeshManager invisibleLinesMeshManager, PolygonMeshManager visibleSurfaceMeshManager, GeometryWireframe[] outlines, Vector3[] translations, //Int32 brushID, Shape shape, Vector3 translation, int texGenID, Color visibleInnerColor, Color visibleOuterColor, Color visibleOutlineColor, Color invisibleInnerColor, Color invisibleOuterColor, Color invisibleOutlineColor, Color surfaceColor, float thickness = ToolConstants.thickLineScale) { if (outlines == null) { return; } var translationMatrix = MathConstants.identityMatrix; if (invisibleOutlineColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleOuterLines, invisibleOutlineColor); } if (outline.invisibleOuterLines != null && outline.invisibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.invisibleOuterLines, invisibleOutlineColor); } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleInnerLines, invisibleOutlineColor); } if (outline.invisibleInnerLines != null && outline.invisibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.invisibleInnerLines, invisibleOutlineColor); } } } if (invisibleInnerColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleOuterLines, invisibleInnerColor, dashSize: visibleOuterLineDots); } if (outline.invisibleOuterLines != null && outline.invisibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.invisibleOuterLines, invisibleInnerColor, dashSize: invisibleOuterLineDots); } } } if (invisibleOuterColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleInnerLines, invisibleOuterColor, dashSize: visibleInnerLineDots); } if (outline.invisibleInnerLines != null && outline.invisibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.invisibleInnerLines, invisibleOuterColor, dashSize: invisibleInnerLineDots); } } } for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline.invalidLines == null || outline.invalidLines.Length == 0) { continue; } var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; invisibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.invalidLines, Color.red, dashSize: invalidLineDots); } if (visibleOutlineColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; if (outline.visibleOuterLines != null && outline.visibleOuterLines.Length != 0) { visibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleOuterLines, visibleOutlineColor, thickness: thickness + 2.0f); } if (outline.visibleInnerLines != null && outline.visibleInnerLines.Length != 0) { visibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleInnerLines, visibleOutlineColor, thickness: thickness + 2.0f); } } } if (visibleOuterColor.a >= kMinAlpha || visibleInnerColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; if (visibleInnerColor.a >= kMinAlpha && outline.visibleOuterLines != null && outline.visibleOuterLines.Length != 0) { visibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleOuterLines, visibleInnerColor, thickness: thickness * 0.5f); } if (visibleOuterColor.a >= kMinAlpha && outline.visibleInnerLines != null && outline.visibleInnerLines.Length != 0) { visibleLinesMeshManager.DrawLines(translationMatrix, outline.vertices, outline.visibleInnerLines, visibleOuterColor, thickness: thickness * 0.5f); } } } if (surfaceColor.a >= kMinAlpha) { for (int i = 0; i < outlines.Length; i++) { var outline = outlines[i]; if (outline.visibleTriangles == null || outline.visibleTriangles.Length == 0) { continue; } var translation = translations[i]; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; visibleSurfaceMeshManager.DrawTriangles(translationMatrix, outline.vertices, outline.visibleTriangles, surfaceColor); } } }
public static void DrawTexGenOutlines(LineMeshManager visibleLinesMeshManager, LineMeshManager invisibleLinesMeshManager, PolygonMeshManager visibleSurfaceMeshManager, Int32 brushID, Shape shape, Vector3 translation, int texGenID, Color innerColor, Color outerColor, Color surfaceColor, float thickness = ToolConstants.thickLineScale) { // .. could be a prefab if (brushID == -1 || texGenID == -1) { return; } if (texGenID < 0 || texGenID >= shape.TexGens.Length) { return; } Vector3[] vertices = null; Int32[] visibleOuterLines = null; Int32[] visibleInnerLines = null; Int32[] visibleTriangles = null; Int32[] invisibleOuterLines = null; Int32[] invisibleInnerLines = null; Int32[] invalidLines = null; if (!InternalCSGModelManager.External.GetTexGenOutline( brushID, texGenID, ref vertices, ref visibleOuterLines, ref visibleInnerLines, ref visibleTriangles, ref invisibleOuterLines, ref invisibleInnerLines, ref invalidLines)) { return; } var translationMatrix = MathConstants.identityMatrix; translationMatrix.m03 = translation.x; translationMatrix.m13 = translation.y; translationMatrix.m23 = translation.z; var dashInnerColor = innerColor; dashInnerColor.a *= 0.5f; if (dashInnerColor.a > 0) { if (visibleOuterLines != null && visibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, vertices, visibleOuterLines, dashInnerColor, dashSize: visibleOuterLineDots); } if (invisibleOuterLines != null && invisibleOuterLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, vertices, invisibleOuterLines, dashInnerColor, dashSize: invisibleOuterLineDots); } } var dashOuterColor = outerColor; dashOuterColor.a *= 0.5f; if (dashOuterColor.a > 0) { if (visibleInnerLines != null && visibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, vertices, visibleInnerLines, dashOuterColor, dashSize: visibleInnerLineDots); } if (invisibleInnerLines != null && invisibleInnerLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, vertices, invisibleInnerLines, dashOuterColor, dashSize: invisibleInnerLineDots); } if (invalidLines != null && invalidLines.Length > 0) { invisibleLinesMeshManager.DrawLines(translationMatrix, vertices, invalidLines, Color.red, dashSize: invalidLineDots); } } innerColor.a = 1.0f; if (innerColor.a > 0 && visibleOuterLines != null && visibleOuterLines.Length > kMinAlpha) { visibleLinesMeshManager.DrawLines(translationMatrix, vertices, visibleOuterLines, ColorSettings.MeshEdgeOutline, thickness: thickness * 2.0f); visibleLinesMeshManager.DrawLines(translationMatrix, vertices, visibleOuterLines, innerColor, thickness: thickness); } outerColor.a = 1.0f; if (outerColor.a > 0 && visibleInnerLines != null && visibleInnerLines.Length > kMinAlpha) { visibleLinesMeshManager.DrawLines(translationMatrix, vertices, visibleInnerLines, ColorSettings.MeshEdgeOutline, thickness: thickness * 2.0f); visibleLinesMeshManager.DrawLines(translationMatrix, vertices, visibleInnerLines, outerColor, thickness: thickness); } if (visibleTriangles != null && visibleTriangles.Length > 0 && surfaceColor.a > kMinAlpha) { PaintUtility.DrawTriangles(translationMatrix, vertices, visibleTriangles, surfaceColor); } }