├── CHANGELOG.md ├── CHANGELOG.md.meta ├── DbgDraw Examples.unitypackage ├── DbgDraw Examples.unitypackage.meta ├── Editor.meta ├── Editor ├── DbgDrawBuildProcessor.cs ├── DbgDrawBuildProcessor.cs.meta ├── Unity.DbgDraw.Editor.asmdef └── Unity.DbgDraw.Editor.asmdef.meta ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── Core.meta ├── Core │ ├── DbgDraw.Arc.cs │ ├── DbgDraw.Arc.cs.meta │ ├── DbgDraw.Cube.cs │ ├── DbgDraw.Cube.cs.meta │ ├── DbgDraw.Disc.cs │ ├── DbgDraw.Disc.cs.meta │ ├── DbgDraw.Line.cs │ ├── DbgDraw.Line.cs.meta │ ├── DbgDraw.Lines.cs │ ├── DbgDraw.Lines.cs.meta │ ├── DbgDraw.Matrix.cs │ ├── DbgDraw.Matrix.cs.meta │ ├── DbgDraw.Plane.cs │ ├── DbgDraw.Plane.cs.meta │ ├── DbgDraw.PolyLine.cs │ ├── DbgDraw.PolyLine.cs.meta │ ├── DbgDraw.Pyramid.cs │ ├── DbgDraw.Pyramid.cs.meta │ ├── DbgDraw.Quad.cs │ ├── DbgDraw.Quad.cs.meta │ ├── DbgDraw.Ray.cs │ ├── DbgDraw.Ray.cs.meta │ ├── DbgDraw.Sphere.cs │ ├── DbgDraw.Sphere.cs.meta │ ├── DbgDraw.Tube.cs │ ├── DbgDraw.Tube.cs.meta │ ├── DbgDraw.WireArc.cs │ ├── DbgDraw.WireArc.cs.meta │ ├── DbgDraw.WireArrow.cs │ ├── DbgDraw.WireArrow.cs.meta │ ├── DbgDraw.WireCapsule.cs │ ├── DbgDraw.WireCapsule.cs.meta │ ├── DbgDraw.WireCube.cs │ ├── DbgDraw.WireCube.cs.meta │ ├── DbgDraw.WireDisc.cs │ ├── DbgDraw.WireDisc.cs.meta │ ├── DbgDraw.WireHemisphere.cs │ ├── DbgDraw.WireHemisphere.cs.meta │ ├── DbgDraw.WirePyramid.cs │ ├── DbgDraw.WirePyramid.cs.meta │ ├── DbgDraw.WireQuad.cs │ ├── DbgDraw.WireQuad.cs.meta │ ├── DbgDraw.WireSphere.cs │ ├── DbgDraw.WireSphere.cs.meta │ ├── DbgDraw.WireTube.cs │ ├── DbgDraw.WireTube.cs.meta │ ├── DbgDraw.cs │ └── DbgDraw.cs.meta ├── Shaders.meta ├── Shaders │ ├── DbgDraw-Shaded.shader │ └── DbgDraw-Shaded.shader.meta ├── Unity.DbgDraw.Runtime.asmdef └── Unity.DbgDraw.Runtime.asmdef.meta ├── package.json └── package.json.meta /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this package are documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.2.0] - 2024-08-12 8 | ### Fixed 9 | - Fixed ```ArgumentNullException``` during internal ```DbgDraw``` initialization due to missing a required shader. I've implemented a build pre-processor that automatically adds the required ```Hidden/DbgDraw-Shaded``` shader to the 'Always Included Shaders' list found under 'Project Settings > Graphics'. This fixes issue #6. 10 | - Fixed ```FindObjectOfType``` deprecated warning when using Unity 2023.1 and newer. 11 | 12 | ## [1.1.0] - 2022-01-05 13 | ### Fixed 14 | - Fixed ```DbgDraw.Plane``` not not being oriented along the plane normal. 15 | - Fixed ```DbgDraw``` not rendering anything when using Universal Render Pipeline (probably affected any scriptable render pipeline). 16 | 17 | ### Added 18 | - Added ```DbgDraw.Plane``` to "Test Everything" in Examples package. 19 | 20 | ### Changed 21 | - Bumped minimum required Unity version from 2018.3 to 2019.3. 22 | 23 | ## [1.0.0] - 2019-12-17 24 | ### Added 25 | - Public release 26 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a387b5b7fd3f7bf45b046adfb7d2d05f 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /DbgDraw Examples.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pschraut/UnityDbgDraw/ca91b722aa56d937e53d664886771ede5122c8b2/DbgDraw Examples.unitypackage -------------------------------------------------------------------------------- /DbgDraw Examples.unitypackage.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1605c4160a96c714b8d93e160a158b9a 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9b693817e9545c4a83212b6fb239a87 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/DbgDrawBuildProcessor.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | #pragma warning disable IDE0018 // Variable declaration can be inlined 4 | #pragma warning disable IDE0017 // Object initialization can be simplified 5 | #pragma warning disable IDE1006 // Naming rule vilation 6 | 7 | using UnityEngine; 8 | using UnityEditor; 9 | using UnityEditor.Build.Reporting; 10 | using UnityEditor.Build; 11 | 12 | namespace Oddworm.EditorFramework 13 | { 14 | 15 | // The DbgDrawBuildProcessor is responsible for adding the required shaders to the GraphicsSettings > Always Included Shaders list. 16 | // Without the shaders added to this list, they can't be found by the application at runtime, eg a Windows or Android build. 17 | class DbgDrawBuildProcessor : IPreprocessBuildWithReport 18 | { 19 | public int callbackOrder => -100; 20 | 21 | public void OnPreprocessBuild(BuildReport report) 22 | { 23 | var asset = AssetDatabase.LoadMainAssetAtPath("ProjectSettings/GraphicsSettings.asset"); 24 | if (asset == null) 25 | { 26 | Debug.LogError($"{nameof(DbgDrawBuildProcessor)}: Cannot load GraphicsSettings.asset"); 27 | return; 28 | } 29 | 30 | var serObj = new SerializedObject(asset); 31 | serObj.UpdateIfRequiredOrScript(); 32 | 33 | var includedShadersProp = serObj.FindProperty("m_AlwaysIncludedShaders"); 34 | if (includedShadersProp == null) 35 | { 36 | Debug.LogError($"{nameof(DbgDrawBuildProcessor)}: Cannot find m_AlwaysIncludedShaders property"); 37 | return; 38 | } 39 | 40 | TryAddShader(includedShadersProp, "Hidden/DbgDraw-Shaded"); 41 | 42 | serObj.ApplyModifiedPropertiesWithoutUndo(); 43 | } 44 | 45 | void TryAddShader(SerializedProperty includedShadersProp, string shaderName) 46 | { 47 | Shader shader = Shader.Find(shaderName); 48 | if (shader == null) 49 | { 50 | Debug.LogError($"{nameof(DbgDrawBuildProcessor)}: Cannot find shader with name '{shaderName}'"); 51 | return; 52 | } 53 | 54 | for (int i = 0, count = includedShadersProp.arraySize; i < count; ++i) 55 | { 56 | var element = includedShadersProp.GetArrayElementAtIndex(i); 57 | if (element.objectReferenceValue == shader) 58 | return; // Shader added already 59 | } 60 | 61 | includedShadersProp.arraySize++; 62 | var shaderProp = includedShadersProp.GetArrayElementAtIndex(includedShadersProp.arraySize - 1); 63 | shaderProp.objectReferenceValue = shader; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Editor/DbgDrawBuildProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bf557696cfd5d147a82180aa1e80d68 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Unity.DbgDraw.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.DbgDraw.Editor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:f0ca7da2c713f5849a8e3326866a5e49" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Editor/Unity.DbgDraw.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4fbf46724ea0dc3409b567b137deed94 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2024 Peter Schraut (http://www.console-dev.de) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 976282902a178324487ee84a8f689a15 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Debug Draw API for Unity 2 | 3 | ```DbgDraw``` is an API that provides the ability to render various 2D and 3D shapes for visual debugging purposes. It's similar to Unity's [Gizmos](https://docs.unity3d.com/ScriptReference/Gizmos.html) and [Handles](https://docs.unity3d.com/ScriptReference/Handles.html) API's. 4 | 5 | Unity provides a rather limited set of debug draw functions in the Debug class, such as [Debug.DrawLine](https://docs.unity3d.com/ScriptReference/Debug.DrawLine.html) for example. 6 | 7 | Unlike Unity's Gizmo, which requires rendering code to be located in a [OnDrawGizmos](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmos.html) method, you can issue DbgDraw calls from anywhere in your code. Rather than issuing these render calls immediately, DbgDraw collects those calls and defers the actual rendering to a later time. This allows to call DbgDraw from any method, be it Start(), Update() etc. 8 | 9 | DbgDraw provides functionality to render the following shapes: 10 | * Arc 11 | * Cube 12 | * Disc 13 | * Line, Lines and PolyLine 14 | * Matrix 15 | * Plane 16 | * Pyramid 17 | * Quad 18 | * Ray 19 | * Sphere 20 | * Tube 21 | 22 | Most of these shapes can be rendered solid and in wireframe. 23 | 24 | 25 | # Example 26 | 27 | ```csharp 28 | using Oddworm.Framework; 29 | 30 | // Draw a wireframe cube for a single frame 31 | DbgDraw.WireCube(position, rotation, scale, color); 32 | 33 | // Draw a solid cube for ten seconds 34 | DbgDraw.Cube(position, rotation, scale, color, 10); 35 | ``` 36 | Please import the "DbgDraw Examples" file, which part of this package, for more examples. 37 | 38 | 39 | # Limitations 40 | 41 | * DbgDraw works with Unity 2020.3 and later versions. 42 | * DbgDraw works in the Unity editor and [development mode](https://docs.unity3d.com/Manual/BuildSettings.html). 43 | * DbgDraw works in play mode only. 44 | * DbgDraw has been created for visual debugging purposes, not as a fast general purpose shape rendering API. 45 | 46 | 47 | # Installation 48 | 49 | Open in Unity Window > Package Manager, choose "Add package from git URL" and insert one of the Package URL's you can find below. 50 | 51 | ## Package URL's 52 | 53 | I recommend to right-click the URL below and choose "Copy Link" rather than selecting the text and copying it, because sometimes it copies a space at the end and the Unity Package Manager can't handle it and spits out an error when you try to add the package. 54 | 55 | Please see the ```CHANGELOG.md``` file to see what's changed in each version. 56 | 57 | | Version | Link | 58 | |----------|:-------------:| 59 | | 1.2.0 | https://github.com/pschraut/UnityDbgDraw.git#1.2.0 | 60 | | 1.1.0 | https://github.com/pschraut/UnityDbgDraw.git#1.1.0 | 61 | | 1.0.0 | https://github.com/pschraut/UnityDbgDraw.git#1.0.0 | 62 | 63 | 64 | 65 | # FAQ 66 | 67 | ### It's not working in the editor 68 | 69 | DbgDraw works in the editor only, if you tick the ```Development Build``` checkbox in the Build Settings window (File > Build Settings). 70 | 71 | ### It's not working in a build 72 | 73 | DbgDraw works in a build only, if you tick the ```Development Build``` checkbox in the Build Settings window (File > Build Settings). 74 | 75 | ### Remove DbgDraw calls from release builds 76 | 77 | If you untick the ```Development Build``` checkbox in the Build Settings window (File > Build Settings), calls to DbgDraw are being removed by the compiler. 78 | 79 | ### "Hidden/DbgDraw-Shaded" in Always Included Shaders 80 | 81 | The package automatically adds the ```Hidden/DbgDraw-Shaded``` shader to the 'Always Included Shaders' list in the Player settings when you create a build. This is required to make the DbgDraw package work in a build. It's a very simple shader that does add a trivial amount of size to the build. -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd9eb4d77e0b71443baa39b79ced03c8 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e8fae1ae4f6a29445a146da24864dfeb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Core.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24d9f3a3677037040aedafd2318402be 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Arc.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | /// 12 | /// Draws a circular arc in 3D space. 13 | /// 14 | /// The center of the circle. 15 | /// The rotation of the circle. 16 | /// The direction of the point on the circle circumference, relative to the center, where the arc begins. This is often just transform.forward for example. 17 | /// The starting angle of the arc, relative to 'from', in degrees. 18 | /// The ending angle of the arc, relative to 'from', in degrees. 19 | /// The inner radius of the circle. 20 | /// The outer radius of the circle. 21 | /// The color. 22 | /// How long the arc should be visible, in seconds. 23 | /// Whether the arc be obscured by objects closer to the camera. 24 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 25 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 26 | public static void Arc(Vector3 position, Quaternion rotation, Vector3 from, float angle, float radius, Color color, float duration = 0, bool depthTest = true) 27 | { 28 | Arc(position, rotation, from, 0, angle, radius, radius, color, duration, depthTest); 29 | } 30 | 31 | /// 32 | /// Draws a circular arc in 3D space. 33 | /// 34 | /// The center of the circle. 35 | /// The rotation of the circle. 36 | /// The direction of the point on the circle circumference, relative to the center, where the arc begins. This is often just transform.forward for example. 37 | /// The starting angle of the arc, relative to 'from', in degrees. 38 | /// The ending angle of the arc, relative to 'from', in degrees. 39 | /// The inner radius of the circle. 40 | /// The outer radius of the circle. 41 | /// The color. 42 | /// How long the arc should be visible, in seconds. 43 | /// Whether the arc be obscured by objects closer to the camera. 44 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 45 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 46 | public static void Arc(Vector3 position, Quaternion rotation, Vector3 from, float fromAngle, float toAngle, float innerRadius, float outerRadius, Color color, float duration = 0, bool depthTest = true) 47 | { 48 | PrimitiveJob job; 49 | if (!TryAllocPrimitiveJob(out job, GL.TRIANGLE_STRIP, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 50 | return; 51 | 52 | job.matrix = Matrix4x4.TRS(position, rotation, Vector3.one); 53 | job.useMatrix = true; 54 | job.useVertexColor = true; 55 | 56 | if (fromAngle != 0) 57 | fromAngle %= 360; 58 | 59 | if (toAngle != 0) 60 | toAngle %= 360; 61 | 62 | if (fromAngle > toAngle) 63 | { 64 | var temp = fromAngle; 65 | fromAngle = toAngle; 66 | toAngle = temp; 67 | } 68 | 69 | innerRadius = Mathf.Max(0, innerRadius); 70 | outerRadius = Mathf.Max(0, outerRadius); 71 | if (innerRadius > outerRadius) 72 | { 73 | var temp = innerRadius; 74 | innerRadius = outerRadius; 75 | outerRadius = temp; 76 | } 77 | 78 | const int circleSegments = 24; 79 | var rotationRightVector = job.matrix.GetColumn(0); 80 | var rotationUpVector = job.matrix.GetColumn(1); 81 | var startingTheta = Vector3.SignedAngle(rotationRightVector, from, rotationUpVector) * Mathf.Deg2Rad; 82 | var theta = startingTheta + fromAngle * Mathf.Deg2Rad; // start at this angle 83 | var thetaTarget = startingTheta + toAngle * Mathf.Deg2Rad; // end at this angle 84 | var thetaStep = (thetaTarget - theta) / circleSegments; // make a step of this size 85 | 86 | for (var n = 0; n <= circleSegments; ++n) 87 | { 88 | var v = new Vector3(Mathf.Cos(theta), 0, -Mathf.Sin(theta)); 89 | job.AddVertex(new PrimitiveJob.Vertex() { position = v * innerRadius, color = color }); 90 | job.AddVertex(new PrimitiveJob.Vertex() { position = v * outerRadius, color = color }); 91 | theta += thetaStep; 92 | } 93 | 94 | job.Submit(); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Arc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af3a120e01a5bdc43b8d3798b7f74ae7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Cube.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | static Mesh s_CubeMesh = null; 12 | 13 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 14 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 15 | public static void Cube(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 16 | { 17 | MeshJob job; 18 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Back, true)) 19 | return; 20 | 21 | if (s_CubeMesh == null) 22 | { 23 | s_CubeMesh = CreateCubeMesh(); 24 | ReleaseOnDestroy(s_CubeMesh); 25 | } 26 | 27 | job.mesh = s_CubeMesh; 28 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 29 | job.color = color; 30 | 31 | job.Submit(); 32 | } 33 | 34 | static Mesh CreateCubeMesh() 35 | { 36 | var mesh = CreateMesh(PrimitiveType.Cube); 37 | mesh.name = "DbgDraw-Cube-Mesh"; 38 | return mesh; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Cube.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd17d353c2c046e42a8db1fcbbfe80f2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Disc.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_DiscMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void Disc(Vector3 position, Quaternion rotation, float radius, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_DiscMesh == null) 23 | { 24 | s_DiscMesh = CreateDiscMesh(); 25 | ReleaseOnDestroy(s_DiscMesh); 26 | } 27 | 28 | job.mesh = s_DiscMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, Vector3.one * radius); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateDiscMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-Disc-Mesh"; 39 | 40 | var vertices = new List(64 * 3); 41 | var step = kTau / 64; 42 | 43 | for (var theta = step; theta < kTau; theta += step) 44 | { 45 | var cos0 = Mathf.Cos(theta - step); 46 | var cos1 = Mathf.Cos(theta); 47 | var sin0 = Mathf.Sin(theta - step); 48 | var sin1 = Mathf.Sin(theta); 49 | 50 | vertices.Add(Vector3.zero); 51 | vertices.Add(new Vector3(cos0, 0, -sin0)); 52 | vertices.Add(new Vector3(cos1, 0, -sin1)); 53 | } 54 | 55 | var indices = new int[vertices.Count]; 56 | for (var n = 0; n < indices.Length; ++n) 57 | indices[n] = n; 58 | 59 | mesh.SetVertices(vertices); 60 | mesh.SetIndices(indices, MeshTopology.Triangles, 0); 61 | mesh.RecalculateNormals(); 62 | 63 | return mesh; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Disc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6facbba01a373b244ac7f78e7204fd4f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Line.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | /// 12 | /// Draws a line from start to end. 13 | /// 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void Line(Vector3 start, Vector3 end, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | LineBatchJob job; 19 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 20 | return; 21 | 22 | job.AddLine(start, end, color, duration); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Line.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89abe3a65a86d3245969413f7484cb6d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Lines.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | /// 13 | /// Draws a list of line segments. 14 | /// 15 | /// A list of pairs of points that represent the start and end of line segments. 16 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 17 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 18 | public static void Lines(List lineSegments, Color color, float duration = 0, bool depthTest = true) 19 | { 20 | if (lineSegments == null || lineSegments.Count == 0) 21 | return; 22 | 23 | LineBatchJob job; 24 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 25 | return; 26 | 27 | for (var n = 1; n < lineSegments.Count; ++n) 28 | job.AddLine(lineSegments[n - 1], lineSegments[n], color, duration); 29 | } 30 | 31 | /// 32 | /// Draws a list of line segments. 33 | /// 34 | /// A list of pairs of points that represent the start and end of line segments. 35 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 36 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 37 | public static void Lines(Vector3[] lineSegments, Color color, float duration = 0, bool depthTest = true) 38 | { 39 | if (lineSegments == null || lineSegments.Length == 0) 40 | return; 41 | 42 | LineBatchJob job; 43 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 44 | return; 45 | 46 | for (var n = 1; n < lineSegments.Length; ++n) 47 | job.AddLine(lineSegments[n - 1], lineSegments[n], color, duration); 48 | } 49 | 50 | #if UNITY_2018_1_OR_NEWER 51 | /// 52 | /// Draws a list of line segments. 53 | /// 54 | /// A list of pairs of points that represent the start and end of line segments. 55 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 56 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 57 | public static void Lines(Unity.Collections.NativeSlice lineSegments, Color color, float duration = 0, bool depthTest = true) 58 | { 59 | if (lineSegments == null || lineSegments.Length == 0) 60 | return; 61 | 62 | LineBatchJob job; 63 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 64 | return; 65 | 66 | for (var n = 1; n < lineSegments.Length; ++n) 67 | job.AddLine(lineSegments[n - 1], lineSegments[n], color, duration); 68 | } 69 | #endif 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Lines.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4aedd94eaca9ea5408124a0077830e1a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Matrix.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void Matrix(Matrix4x4 matrix, float duration = 0, bool depthTest = true) 14 | { 15 | PrimitiveJob job; 16 | if (!TryAllocPrimitiveJob(out job, GL.LINES, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 17 | return; 18 | 19 | job.matrix = matrix; 20 | job.useMatrix = true; 21 | job.useVertexColor = true; 22 | 23 | job.AddVertex(new PrimitiveJob.Vertex() { position = Vector3.zero, color = s_XAxisColor }); 24 | job.AddVertex(new PrimitiveJob.Vertex() { position = Vector3.right, color = s_XAxisColor }); 25 | 26 | job.AddVertex(new PrimitiveJob.Vertex() { position = Vector3.zero, color = s_YAxisColor }); 27 | job.AddVertex(new PrimitiveJob.Vertex() { position = Vector3.up, color = s_YAxisColor }); 28 | 29 | job.AddVertex(new PrimitiveJob.Vertex() { position = Vector3.zero, color = s_ZAxisColor }); 30 | job.AddVertex(new PrimitiveJob.Vertex() { position = Vector3.forward, color = s_ZAxisColor }); 31 | 32 | job.Submit(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Matrix.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a31e041516ae2f4c96b50155d194989 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Plane.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2022 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_PlaneMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void Plane(UnityEngine.Plane plane, Vector3 position, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_PlaneMesh == null) 23 | { 24 | s_PlaneMesh = CreatePlaneMesh(); 25 | ReleaseOnDestroy(s_PlaneMesh); 26 | } 27 | 28 | job.mesh = s_PlaneMesh; 29 | job.matrix = Matrix4x4.TRS(position, Quaternion.LookRotation(plane.normal), scale); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreatePlaneMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-Plane-Mesh"; 39 | 40 | var vertices = new List(4 * 3); 41 | var s = 0.5f; 42 | 43 | // quad 44 | vertices.Add(new Vector3(-s, -s, 0)); 45 | vertices.Add(new Vector3(-s, +s, 0)); 46 | vertices.Add(new Vector3(+s, +s, 0)); 47 | 48 | vertices.Add(new Vector3(+s, +s, 0)); 49 | vertices.Add(new Vector3(+s, -s, 0)); 50 | vertices.Add(new Vector3(-s, -s, 0)); 51 | 52 | // "arrrow" 53 | s = 0.01f; 54 | vertices.Add(new Vector3(0, -s, 0)); 55 | vertices.Add(new Vector3(0, 0, 0.25f)); 56 | vertices.Add(new Vector3(0, +s, 0)); 57 | 58 | vertices.Add(new Vector3(-s, 0, 0)); 59 | vertices.Add(new Vector3(0, 0, 0.25f)); 60 | vertices.Add(new Vector3(+s, 0, 0)); 61 | 62 | 63 | var indices = new int[vertices.Count]; 64 | for (var n = 0; n < indices.Length; ++n) 65 | indices[n] = n; 66 | 67 | mesh.SetVertices(vertices); 68 | mesh.SetIndices(indices, MeshTopology.Triangles, 0); 69 | mesh.RecalculateNormals(); 70 | 71 | return mesh; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Plane.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3aa30710c79e0ba4ebe048e22c0daafc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.PolyLine.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | /// 13 | /// Draws a line going through the list of points. 14 | /// 15 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 16 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 17 | public static void PolyLine(List points, Color color, float duration = 0, bool depthTest = true) 18 | { 19 | if (points == null || points.Count == 0) 20 | return; 21 | 22 | LineBatchJob job; 23 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 24 | return; 25 | 26 | for (var n = 1; n < points.Count; ++n) 27 | job.AddLine(points[n - 1], points[n], color, duration); 28 | } 29 | 30 | /// 31 | /// Draws a line going through the list of points. 32 | /// 33 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 34 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 35 | public static void PolyLine(Vector3[] points, Color color, float duration = 0, bool depthTest = true) 36 | { 37 | if (points == null || points.Length == 0) 38 | return; 39 | 40 | LineBatchJob job; 41 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 42 | return; 43 | 44 | for (var n = 1; n < points.Length; ++n) 45 | job.AddLine(points[n - 1], points[n], color, duration); 46 | } 47 | 48 | #if UNITY_2018_1_OR_NEWER 49 | /// 50 | /// Draws a line going through the list of points. 51 | /// 52 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 53 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 54 | public static void PolyLine(Unity.Collections.NativeSlice points, Color color, float duration = 0, bool depthTest = true) 55 | { 56 | if (points == null || points.Length == 0) 57 | return; 58 | 59 | LineBatchJob job; 60 | if (!TryGetLineBatch(out job, depthTest, UnityEngine.Rendering.CullMode.Off)) 61 | return; 62 | 63 | for (var n = 1; n < points.Length; ++n) 64 | job.AddLine(points[n - 1], points[n], color, duration); 65 | } 66 | #endif 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.PolyLine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67c65b9f7b913a84087e315e88b2e0d2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Pyramid.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_PyramidMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void Pyramid(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Back, true)) 20 | return; 21 | 22 | if (s_PyramidMesh == null) 23 | { 24 | s_PyramidMesh = CreatePyramidMesh(); 25 | ReleaseOnDestroy(s_PyramidMesh); 26 | } 27 | 28 | job.mesh = s_PyramidMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreatePyramidMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-Pyramid-Mesh"; 39 | 40 | var vertices = new List(6 * 3); 41 | var s = 0.5f; 42 | 43 | // bottom left triangle 44 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 45 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 46 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 47 | 48 | // bottom right triangle 49 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 50 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 51 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 52 | 53 | // front triangle 54 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 55 | vertices.Add(new Vector3(+0, +s, +0)); // top center 56 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 57 | 58 | // back triangle 59 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 60 | vertices.Add(new Vector3(+0, +s, +0)); // top center 61 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 62 | 63 | // left triangle 64 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 65 | vertices.Add(new Vector3(+0, +s, +0)); // top center 66 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 67 | 68 | // right triangle 69 | vertices.Add(new Vector3(+0.5f, -s, -0.5f)); // bottom near right 70 | vertices.Add(new Vector3(0, +s, 0)); // top center 71 | vertices.Add(new Vector3(+0.5f, -s, +0.5f)); // bottom far right 72 | 73 | var indices = new int[vertices.Count]; 74 | for (var n = 0; n < indices.Length; ++n) 75 | indices[n] = n; 76 | 77 | mesh.SetVertices(vertices); 78 | mesh.SetIndices(indices, MeshTopology.Triangles, 0); 79 | mesh.RecalculateNormals(); 80 | 81 | return mesh; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Pyramid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 397498c0b21d63b448795ac7bdc9c73e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Quad.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void Quad(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 14 | { 15 | PrimitiveJob job; 16 | if (!TryAllocPrimitiveJob(out job, GL.QUADS, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 17 | return; 18 | 19 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 20 | job.useMatrix = true; 21 | 22 | var s = 1.0f * 0.5f; 23 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(-s, 0, -s), color = color }); 24 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(-s, 0, +s), color = color }); 25 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(+s, 0, +s), color = color }); 26 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(+s, 0, -s), color = color }); 27 | 28 | job.Submit(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Quad.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fddb1b0c5181c144dbea26cb25120d8b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Ray.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void Ray(Vector3 position, Vector3 direction, Color color, float duration = 0, bool depthTest = true) 14 | { 15 | PrimitiveJob job; 16 | if (!TryAllocPrimitiveJob(out job, GL.LINES, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 17 | return; 18 | 19 | job.AddVertex(new PrimitiveJob.Vertex() { position = position, color = color }); 20 | job.AddVertex(new PrimitiveJob.Vertex() { position = position + direction, color = color }); 21 | 22 | job.Submit(); 23 | } 24 | 25 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 26 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 27 | public static void Ray(Ray ray, Color color, float duration = 0, bool depthTest = true) 28 | { 29 | Ray(ray.origin, ray.direction * 100000, color, duration, depthTest); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Ray.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52e6d0960debb3645bacc0d5d94d1263 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Sphere.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | static Mesh s_SphereMesh = null; 12 | 13 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 14 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 15 | public static void Sphere(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 16 | { 17 | MeshJob job; 18 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Back, true)) 19 | return; 20 | 21 | if (s_SphereMesh == null) 22 | { 23 | s_SphereMesh = CreateSphereMesh(); 24 | ReleaseOnDestroy(s_SphereMesh); 25 | } 26 | 27 | job.mesh = s_SphereMesh; 28 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 29 | job.color = color; 30 | 31 | job.Submit(); 32 | } 33 | 34 | static Mesh CreateSphereMesh() 35 | { 36 | var mesh = CreateMesh(PrimitiveType.Sphere); 37 | mesh.name = "DbgDraw-Sphere-Mesh"; 38 | return mesh; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Sphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46c78ac0158fae04eb91ba037813abdd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Tube.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_TubeMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void Tube(Vector3 position, Quaternion rotation, Vector3 size, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_TubeMesh == null) 23 | { 24 | s_TubeMesh = CreateTubeMesh(); 25 | ReleaseOnDestroy(s_TubeMesh); 26 | } 27 | 28 | job.mesh = s_TubeMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, size); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateTubeMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-Tube-Mesh"; 39 | 40 | var vertices = new List(64 * 4); 41 | var s = 0.5f; 42 | 43 | // ring around y, full circle at top and bottom 44 | var step = kTau / 64; 45 | for (var theta = 0.0f; theta < kTau - step; theta += step) 46 | { 47 | var cos0 = Mathf.Cos(theta); 48 | var cos1 = Mathf.Cos(theta + step); 49 | var sin0 = Mathf.Sin(theta); 50 | var sin1 = Mathf.Sin(theta + step); 51 | 52 | vertices.Add(s * new Vector3(cos1, +1, -sin1)); 53 | vertices.Add(s * new Vector3(cos0, +1, -sin0)); 54 | vertices.Add(s * new Vector3(cos0, -1, -sin0)); 55 | 56 | vertices.Add(s * new Vector3(cos1, -1, -sin1)); 57 | vertices.Add(s * new Vector3(cos1, +1, -sin1)); 58 | vertices.Add(s * new Vector3(cos0, -1, -sin0)); 59 | } 60 | 61 | var indices = new int[vertices.Count]; 62 | for (var n = 0; n < indices.Length; ++n) 63 | indices[n] = n; 64 | 65 | mesh.SetVertices(vertices); 66 | mesh.SetIndices(indices, MeshTopology.Triangles, 0); 67 | mesh.RecalculateNormals(); 68 | 69 | return mesh; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.Tube.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6efdacf7dc94d604181eae20b0153e7d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireArc.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void WireArc(Vector3 position, Quaternion rotation, Vector3 from, float angle, float radius, Color color, float duration = 0, bool depthTest = true) 14 | { 15 | WireArc(position, rotation, from, 0, angle, radius, radius, color, duration, depthTest); 16 | } 17 | 18 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 19 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 20 | public static void WireArc(Vector3 position, Quaternion rotation, Vector3 from, float fromAngle, float toAngle, float innerRadius, float outerRadius, Color color, float duration = 0, bool depthTest = true) 21 | { 22 | PrimitiveJob job; 23 | if (!TryAllocPrimitiveJob(out job, GL.LINE_STRIP, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 24 | return; 25 | 26 | job.matrix = Matrix4x4.TRS(position, rotation, Vector3.one); 27 | job.useMatrix = true; 28 | job.useVertexColor = true; 29 | 30 | if (fromAngle != 0) 31 | fromAngle %= 360; 32 | 33 | if (toAngle != 0) 34 | toAngle %= 360; 35 | 36 | if (fromAngle > toAngle) 37 | { 38 | var temp = fromAngle; 39 | fromAngle = toAngle; 40 | toAngle = temp; 41 | } 42 | 43 | innerRadius = Mathf.Max(0, innerRadius); 44 | outerRadius = Mathf.Max(0, outerRadius); 45 | if (innerRadius > outerRadius) 46 | { 47 | var temp = innerRadius; 48 | innerRadius = outerRadius; 49 | outerRadius = temp; 50 | } 51 | 52 | const int circleSegments = 24; 53 | var rotationRightVector = job.matrix.GetColumn(0); 54 | var rotationUpVector = job.matrix.GetColumn(1); 55 | var startingTheta = Vector3.SignedAngle(rotationRightVector, from, rotationUpVector) * Mathf.Deg2Rad; 56 | var theta = startingTheta + fromAngle * Mathf.Deg2Rad; // start at this angle 57 | var thetaTarget = startingTheta + toAngle * Mathf.Deg2Rad; // end at this angle 58 | var thetaStep = (thetaTarget - theta) / circleSegments; // make a step of this size 59 | var hasInnerRadius = (Mathf.Abs(innerRadius - outerRadius) - 0.001f) > 0; 60 | 61 | // from center 62 | if (hasInnerRadius) 63 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(Mathf.Cos(theta), 0, -Mathf.Sin(theta)) * innerRadius, color = color }); 64 | 65 | // outer ring 66 | for (var n = 0; n <= circleSegments; ++n) 67 | { 68 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(Mathf.Cos(theta), 0, -Mathf.Sin(theta)) * outerRadius, color = color }); 69 | theta += thetaStep; 70 | } 71 | 72 | if (hasInnerRadius) 73 | { 74 | // to center 75 | theta -= thetaStep; 76 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(Mathf.Cos(theta), 0, -Mathf.Sin(theta)) * innerRadius, color = color }); 77 | 78 | // inner ring 79 | for (var n = 0; n <= circleSegments; ++n) 80 | { 81 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(Mathf.Cos(theta), 0, -Mathf.Sin(theta)) * innerRadius, color = color }); 82 | theta -= thetaStep; 83 | } 84 | } 85 | 86 | job.Submit(); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireArc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ad6fe5ae2693d944a0bbe6d77dce604 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireArrow.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void WireArrow(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 14 | { 15 | PrimitiveJob job; 16 | if (!TryAllocPrimitiveJob(out job, GL.LINE_STRIP, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 17 | return; 18 | 19 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 20 | job.useMatrix = true; 21 | 22 | var s = 1.0f * 0.5f; 23 | 24 | // forward aligned arrow 25 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(0, 0, 1), color = color }); // tip 26 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(+s, 0, 0), color = color }); 27 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(-s, 0, 0), color = color }); 28 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(0, 0, 1), color = color }); // tip 29 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(0, +s, 0), color = color }); 30 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(0, -s, 0), color = color }); 31 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(0, 0, 1), color = color }); // tip 32 | //job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(0, 0, 0), color = color }); // middle line 33 | 34 | job.Submit(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireArrow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dbca3363f183b784babfe1c5a2119ae3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireCapsule.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void WireCapsule(Vector3 position, Quaternion rotation, float radius, float height, Color color, float duration = 0, bool depthTest = true) 14 | { 15 | if (!isEnabledAndPlaying) 16 | return; 17 | 18 | radius = Mathf.Max(0, radius); 19 | radius *= 2; 20 | 21 | height -= radius; // subtract the hemisphere on both sides 22 | height = Mathf.Max(0, height); 23 | 24 | 25 | WireHemisphere(position + rotation * new Vector3(0, height * 0.5f, 0), rotation, Vector3.one * radius, color, duration, depthTest); 26 | WireTube(position, rotation, new Vector3(radius, height, radius), color, duration, depthTest); 27 | WireHemisphere(position - rotation * new Vector3(0, height * 0.5f, 0), rotation * Quaternion.AngleAxis(180, Vector3.right), Vector3.one * radius, color, duration, depthTest); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireCapsule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6844a34b83cdf7f49adccc6ca6bf2359 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireCube.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_WireCubeMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void WireCube(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_WireCubeMesh == null) 23 | { 24 | s_WireCubeMesh = CreateWireCubeMesh(); 25 | ReleaseOnDestroy(s_WireCubeMesh); 26 | } 27 | 28 | job.mesh = s_WireCubeMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateWireCubeMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-WireCube-Mesh"; 39 | 40 | var vertices = new List(24); 41 | 42 | var s = 1.0f * 0.5f; 43 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 44 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 45 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 46 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 47 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 48 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 49 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 50 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 51 | 52 | vertices.Add(new Vector3(-s, +s, -s)); // top near left 53 | vertices.Add(new Vector3(-s, +s, +s)); // top far left 54 | vertices.Add(new Vector3(-s, +s, +s)); // top far left 55 | vertices.Add(new Vector3(+s, +s, +s)); // top far right 56 | vertices.Add(new Vector3(+s, +s, +s)); // top far right 57 | vertices.Add(new Vector3(+s, +s, -s)); // top near right 58 | vertices.Add(new Vector3(+s, +s, -s)); // top near right 59 | vertices.Add(new Vector3(-s, +s, -s)); // top near left 60 | 61 | vertices.Add(new Vector3(+s, +s, +s)); // top far right 62 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 63 | vertices.Add(new Vector3(+s, +s, -s)); // top near right 64 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 65 | 66 | vertices.Add(new Vector3(-s, +s, +s)); // top far left 67 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 68 | vertices.Add(new Vector3(-s, +s, -s)); // top near left 69 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 70 | 71 | mesh.SetVertices(vertices); 72 | 73 | var indices = new int[vertices.Count]; 74 | for (var n = 0; n < indices.Length; ++n) 75 | indices[n] = n; 76 | mesh.SetIndices(indices, MeshTopology.Lines, 0); 77 | 78 | return mesh; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireCube.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 85d1bdcf6f0d5ff43819d1f2aaf5bbd3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireDisc.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_WireDiscMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void WireDisc(Vector3 position, Quaternion rotation, float radius, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_WireDiscMesh == null) 23 | { 24 | s_WireDiscMesh = CreateWireDiscMesh(); 25 | ReleaseOnDestroy(s_WireDiscMesh); 26 | } 27 | 28 | job.mesh = s_WireDiscMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, Vector3.one * radius); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateWireDiscMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-WireDisc-Mesh"; 39 | 40 | var vertices = new List(64 * 3); 41 | var step = kTau / 64; 42 | 43 | for (var theta = step; theta < kTau; theta += step) 44 | { 45 | var cos0 = Mathf.Cos(theta - step); 46 | var cos1 = Mathf.Cos(theta); 47 | var sin0 = Mathf.Sin(theta - step); 48 | var sin1 = Mathf.Sin(theta); 49 | 50 | vertices.Add(new Vector3(cos0, 0, -sin0)); 51 | vertices.Add(new Vector3(cos1, 0, -sin1)); 52 | } 53 | 54 | var indices = new int[vertices.Count]; 55 | for (var n = 0; n < indices.Length; ++n) 56 | indices[n] = n; 57 | 58 | mesh.SetVertices(vertices); 59 | mesh.SetIndices(indices, MeshTopology.Lines, 0); 60 | 61 | return mesh; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireDisc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6726fd5fc1b97d4cae480902170b428 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireHemisphere.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_WireHemisphereMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void WireHemisphere(Vector3 position, Quaternion rotation, Vector3 size, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Back, true)) 20 | return; 21 | 22 | if (s_WireHemisphereMesh == null) 23 | { 24 | s_WireHemisphereMesh = CreateWireHemisphereMesh(); 25 | ReleaseOnDestroy(s_WireHemisphereMesh); 26 | } 27 | 28 | job.mesh = s_WireHemisphereMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, size); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateWireHemisphereMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-WireHemisphere-Mesh"; 39 | 40 | var vertices = new List(64 * 3); 41 | var s = 0.5f; 42 | 43 | // ring around y, full circle 44 | var step = kTau / 64; 45 | for (var theta = 0.0f; theta < kTau; theta += step) 46 | { 47 | var cos0 = Mathf.Cos(theta); 48 | var cos1 = Mathf.Cos(theta + step); 49 | var sin0 = Mathf.Sin(theta); 50 | var sin1 = Mathf.Sin(theta + step); 51 | 52 | vertices.Add(s * new Vector3(cos0, 0, -sin0)); 53 | vertices.Add(s * new Vector3(cos1, 0, -sin1)); 54 | } 55 | 56 | 57 | // sides 58 | var stept = kTau / 4; 59 | for (var t = 0.0f; t < kTau; t += stept) 60 | { 61 | var yrot = Quaternion.AngleAxis(Mathf.Rad2Deg * t, Vector3.up); 62 | 63 | // ring around x, half circle 64 | for (var theta = -Mathf.PI; theta < 0; theta += step) 65 | { 66 | var xrot0 = Quaternion.AngleAxis(Mathf.Rad2Deg * theta, Vector3.right); 67 | var xrot1 = Quaternion.AngleAxis(Mathf.Rad2Deg * (theta + step), Vector3.right); 68 | 69 | vertices.Add(yrot * xrot0 * Vector3.forward * s); 70 | vertices.Add(yrot * xrot1 * Vector3.forward * s); 71 | } 72 | } 73 | 74 | #if false 75 | // ring around x, half circle 76 | for (var theta = 0.0f - Mathf.PI * 0.5f; theta < Mathf.PI - Mathf.PI * 0.5f; theta += step) 77 | { 78 | var cos0 = Mathf.Cos(theta); 79 | var cos1 = Mathf.Cos(theta + step); 80 | var sin0 = Mathf.Sin(theta); 81 | var sin1 = Mathf.Sin(theta + step); 82 | 83 | vertices.Add(s * new Vector3(0, cos0, -sin0)); 84 | vertices.Add(s * new Vector3(0, cos1, -sin1)); 85 | } 86 | 87 | // ring around z, half circle 88 | for (var theta = 0.0f - Mathf.PI; theta < 0; theta += step) 89 | { 90 | var cos0 = Mathf.Cos(theta); 91 | var cos1 = Mathf.Cos(theta + step); 92 | var sin0 = Mathf.Sin(theta); 93 | var sin1 = Mathf.Sin(theta + step); 94 | 95 | vertices.Add(s * new Vector3(cos0, -sin0, 0)); 96 | vertices.Add(s * new Vector3(cos1, -sin1, 0)); 97 | } 98 | #endif 99 | 100 | var indices = new int[vertices.Count]; 101 | for (var n = 0; n < indices.Length; ++n) 102 | indices[n] = n; 103 | 104 | mesh.SetVertices(vertices); 105 | mesh.SetIndices(indices, MeshTopology.Lines, 0); 106 | 107 | return mesh; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireHemisphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecae71071b856e84a8a0466f431d70c4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WirePyramid.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_WirePyramidMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void WirePyramid(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_WirePyramidMesh == null) 23 | { 24 | s_WirePyramidMesh = CreateWirePyramidMesh(); 25 | ReleaseOnDestroy(s_WirePyramidMesh); 26 | } 27 | 28 | job.mesh = s_WirePyramidMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | 36 | static Mesh CreateWirePyramidMesh() 37 | { 38 | var mesh = new Mesh(); 39 | mesh.name = "DbgDraw-WirePyramid-Mesh"; 40 | 41 | var vertices = new List(16); 42 | var s = 0.5f; 43 | 44 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 45 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 46 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 47 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 48 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 49 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 50 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 51 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 52 | 53 | vertices.Add(new Vector3(+0, +s, +0)); // top center 54 | vertices.Add(new Vector3(-s, -s, -s)); // bottom near left 55 | vertices.Add(new Vector3(+0, +s, +0)); // top center 56 | vertices.Add(new Vector3(-s, -s, +s)); // bottom far left 57 | vertices.Add(new Vector3(+0, +s, +0)); // top center 58 | vertices.Add(new Vector3(+s, -s, -s)); // bottom near right 59 | vertices.Add(new Vector3(+0, +s, +0)); // top center 60 | vertices.Add(new Vector3(+s, -s, +s)); // bottom far right 61 | 62 | mesh.SetVertices(vertices); 63 | 64 | var indices = new int[vertices.Count]; 65 | for (var n = 0; n < indices.Length; ++n) 66 | indices[n] = n; 67 | mesh.SetIndices(indices, MeshTopology.Lines, 0); 68 | 69 | return mesh; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WirePyramid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57b376d5f0a1698469ea7910c505e03b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireQuad.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using UnityEngine; 4 | #pragma warning disable IDE0018 // Variable declaration can be inlined 5 | #pragma warning disable IDE0017 // Object initialization can be simplified 6 | 7 | namespace Oddworm.Framework 8 | { 9 | public partial class DbgDraw 10 | { 11 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 12 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 13 | public static void WireQuad(Vector3 position, Quaternion rotation, Vector3 scale, Color color, float duration = 0, bool depthTest = true) 14 | { 15 | PrimitiveJob job; 16 | if (!TryAllocPrimitiveJob(out job, GL.LINE_STRIP, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 17 | return; 18 | 19 | job.matrix = Matrix4x4.TRS(position, rotation, scale); 20 | job.useMatrix = true; 21 | 22 | var s = 1.0f * 0.5f; 23 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(-s, 0, -s), color = color }); 24 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(-s, 0, +s), color = color }); 25 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(+s, 0, +s), color = color }); 26 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(+s, 0, -s), color = color }); 27 | job.AddVertex(new PrimitiveJob.Vertex() { position = new Vector3(-s, 0, -s), color = color }); 28 | 29 | job.Submit(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireQuad.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4db129d16a8cba45997e9f7e2199d41 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireSphere.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_WireSphereMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void WireSphere(Vector3 position, Quaternion rotation, Vector3 size, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_WireSphereMesh == null) 23 | { 24 | s_WireSphereMesh = CreateWireSphereMesh(); 25 | ReleaseOnDestroy(s_WireSphereMesh); 26 | } 27 | 28 | job.mesh = s_WireSphereMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, size); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateWireSphereMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-WireSphere-Mesh"; 39 | 40 | var vertices = new List(64 * 3); 41 | var step = kTau / 64; 42 | var s = 0.5f; 43 | 44 | for (var theta = 0.0f; theta < kTau; theta += step) 45 | { 46 | var cos0 = Mathf.Cos(theta); 47 | var cos1 = Mathf.Cos(theta + step); 48 | var sin0 = Mathf.Sin(theta); 49 | var sin1 = Mathf.Sin(theta + step); 50 | 51 | // ring around x 52 | vertices.Add(s * new Vector3(0, cos0, -sin0)); 53 | vertices.Add(s * new Vector3(0, cos1, -sin1)); 54 | 55 | // ring around y 56 | vertices.Add(s * new Vector3(cos0, 0, -sin0)); 57 | vertices.Add(s * new Vector3(cos1, 0, -sin1)); 58 | 59 | // ring around z 60 | vertices.Add(s * new Vector3(cos0, -sin0, 0)); 61 | vertices.Add(s * new Vector3(cos1, -sin1, 0)); 62 | } 63 | 64 | var indices = new int[vertices.Count]; 65 | for (var n = 0; n < indices.Length; ++n) 66 | indices[n] = n; 67 | 68 | mesh.SetVertices(vertices); 69 | mesh.SetIndices(indices, MeshTopology.Lines, 0); 70 | 71 | return mesh; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireSphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a771edea902bffe41bb3f6c377103d58 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireTube.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | #pragma warning disable IDE0018 // Variable declaration can be inlined 6 | #pragma warning disable IDE0017 // Object initialization can be simplified 7 | 8 | namespace Oddworm.Framework 9 | { 10 | public partial class DbgDraw 11 | { 12 | static Mesh s_WireTubeMesh = null; 13 | 14 | [System.Diagnostics.Conditional("UNITY_EDITOR")] 15 | [System.Diagnostics.Conditional("DEVELOPMENT_BUILD")] 16 | public static void WireTube(Vector3 position, Quaternion rotation, Vector3 size, Color color, float duration = 0, bool depthTest = true) 17 | { 18 | MeshJob job; 19 | if (!TryAllocMeshJob(out job, duration, depthTest, UnityEngine.Rendering.CullMode.Off, true)) 20 | return; 21 | 22 | if (s_WireTubeMesh == null) 23 | { 24 | s_WireTubeMesh = CreateWireTubeMesh(); 25 | ReleaseOnDestroy(s_WireTubeMesh); 26 | } 27 | 28 | job.mesh = s_WireTubeMesh; 29 | job.matrix = Matrix4x4.TRS(position, rotation, size); 30 | job.color = color; 31 | 32 | job.Submit(); 33 | } 34 | 35 | static Mesh CreateWireTubeMesh() 36 | { 37 | var mesh = new Mesh(); 38 | mesh.name = "DbgDraw-WireTube-Mesh"; 39 | 40 | var vertices = new List(64 * 4 + 4); 41 | var s = 0.5f; 42 | 43 | // ring around y, full circle at top and bottom 44 | var step = kTau / 64; 45 | for (var theta = 0.0f; theta < kTau; theta += step) 46 | { 47 | var cos0 = Mathf.Cos(theta); 48 | var cos1 = Mathf.Cos(theta + step); 49 | var sin0 = Mathf.Sin(theta); 50 | var sin1 = Mathf.Sin(theta + step); 51 | 52 | vertices.Add(s * new Vector3(cos0, -1, -sin0)); 53 | vertices.Add(s * new Vector3(cos1, -1, -sin1)); 54 | 55 | vertices.Add(s * new Vector3(cos0, +1, -sin0)); 56 | vertices.Add(s * new Vector3(cos1, +1, -sin1)); 57 | } 58 | 59 | // sides 60 | step = kTau / 8; 61 | for (var theta = 0.0f; theta < kTau; theta += step) 62 | { 63 | var cos0 = Mathf.Cos(theta); 64 | var sin0 = Mathf.Sin(theta); 65 | 66 | vertices.Add(s * new Vector3(cos0, -1, -sin0)); 67 | vertices.Add(s * new Vector3(cos0, +1, -sin0)); 68 | } 69 | 70 | var indices = new int[vertices.Count]; 71 | for (var n = 0; n < indices.Length; ++n) 72 | indices[n] = n; 73 | 74 | mesh.SetVertices(vertices); 75 | mesh.SetIndices(indices, MeshTopology.Lines, 0); 76 | 77 | return mesh; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.WireTube.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2d89b98a49a56246a2a1688790b0394 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.cs: -------------------------------------------------------------------------------- 1 | // DbgDraw for Unity. Copyright (c) 2019-2021 Peter Schraut (www.console-dev.de). See LICENSE.md 2 | // https://github.com/pschraut/UnityDbgDraw 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.Rendering; 6 | #pragma warning disable IDE0018 // Variable declaration can be inlined 7 | #pragma warning disable IDE0017 // Object initialization can be simplified 8 | #pragma warning disable IDE1006 // Naming rule vilation 9 | 10 | namespace Oddworm.Framework 11 | { 12 | public partial class DbgDraw 13 | { 14 | /// 15 | /// Gets and sets whether DbgDraw is enabled. 16 | /// 17 | public static bool isEnabled = true; 18 | 19 | /// 20 | /// Gets whether DbgDraw is supported. Returns true in development mode builds and if the development mode setting is ticked editor, false otherwise. 21 | /// 22 | public static bool isSupported 23 | { 24 | get 25 | { 26 | #if UNITY_EDITOR 27 | if (UnityEditor.EditorUserBuildSettings.development) 28 | return true; 29 | return false; 30 | #elif DEVELOPMENT_BUILD 31 | return true; 32 | #else 33 | return false; 34 | #endif 35 | } 36 | } 37 | 38 | const float kTau = 2 * Mathf.PI; 39 | static Color s_XAxisColor = new Color(219f / 255, 62f / 255, 29f / 255, .93f); 40 | static Color s_YAxisColor = new Color(154f / 255, 243f / 255, 72f / 255, .93f); 41 | static Color s_ZAxisColor = new Color(58f / 255, 122f / 255, 248f / 255, .93f); 42 | 43 | static bool isEnabledAndPlaying 44 | { 45 | get 46 | { 47 | if (!isEnabled || !isSupported) 48 | return false; 49 | 50 | #if UNITY_EDITOR 51 | if (!Application.isPlaying) 52 | return false; 53 | 54 | //if (UnityEditor.EditorApplication.isPaused) 55 | // return false; 56 | #endif 57 | 58 | return true; 59 | } 60 | } 61 | 62 | static bool TryGetLineBatch(out LineBatchJob batch, bool depthTest, CullMode cullMode) 63 | { 64 | if (!isEnabledAndPlaying) 65 | { 66 | batch = new LineBatchJob(); 67 | return false; 68 | } 69 | 70 | batch = instance.GetLineBatch(depthTest, cullMode); 71 | return true; 72 | } 73 | 74 | static bool TryAllocPrimitiveJob(out PrimitiveJob job, int primitiveType, float duration, bool depthTest, CullMode cullMode, bool shaded) 75 | { 76 | if (!isEnabledAndPlaying) 77 | { 78 | job = new PrimitiveJob(); 79 | return false; 80 | } 81 | 82 | job = instance.AllocPrimitiveJob(primitiveType, duration, depthTest, cullMode, shaded); 83 | return true; 84 | } 85 | 86 | static bool TryAllocMeshJob(out MeshJob job, float duration, bool depthTest, CullMode cullMode, bool shaded) 87 | { 88 | //shaded = true; 89 | if (!isEnabledAndPlaying) 90 | { 91 | job = new MeshJob(); 92 | return false; 93 | } 94 | 95 | job = instance.AllocMeshJob(duration, depthTest, cullMode, shaded); 96 | return true; 97 | } 98 | 99 | static Mesh CreateMesh(PrimitiveType type) 100 | { 101 | var go = GameObject.CreatePrimitive(type); 102 | var mesh = MonoBehaviour.Instantiate(go.GetComponent().sharedMesh); 103 | MonoBehaviour.Destroy(go); 104 | return mesh; 105 | } 106 | 107 | static void ReleaseOnDestroy(Mesh mesh) 108 | { 109 | instance.ReleaseOnDestroy(mesh); 110 | } 111 | 112 | struct LineBatchJob 113 | { 114 | public struct Line 115 | { 116 | public Vector3 a; 117 | public Vector3 b; 118 | public Color32 color; 119 | public float remainingDuration; 120 | } 121 | 122 | public List list; 123 | public Material material; 124 | 125 | public void AddLine(Vector3 a, Vector3 b, Color32 color, float duration) 126 | { 127 | var line = new Line(); 128 | line.a = a; 129 | line.b = b; 130 | line.color = color; 131 | line.remainingDuration = duration; 132 | list.Add(line); 133 | } 134 | 135 | public void Submit() 136 | { 137 | } 138 | } 139 | 140 | struct PrimitiveJob 141 | { 142 | public struct Vertex 143 | { 144 | public Vector3 position; 145 | public Color32 color; 146 | } 147 | 148 | public int primitiveType; // GL.LINES, GL.TRIANGLES, and so on 149 | public List list; 150 | public float remainingDuration; 151 | public bool depthTest; 152 | public Matrix4x4 matrix; 153 | public bool useMatrix; 154 | public bool useVertexColor; 155 | public Material material; 156 | 157 | readonly List m_Owner; 158 | 159 | public PrimitiveJob(List owner) 160 | : this() 161 | { 162 | m_Owner = owner; 163 | } 164 | 165 | public void AddVertex(Vertex vertex) 166 | { 167 | list.Add(vertex); 168 | } 169 | 170 | public void Submit() 171 | { 172 | m_Owner.Add(this); 173 | } 174 | } 175 | 176 | struct MeshJob 177 | { 178 | public float remainingDuration; 179 | public bool depthTest; 180 | public Matrix4x4 matrix; 181 | public Material material; 182 | public Mesh mesh; 183 | public Color color; 184 | 185 | readonly List m_Owner; 186 | 187 | public MeshJob(List owner) 188 | : this() 189 | { 190 | m_Owner = owner; 191 | } 192 | 193 | public void Submit() 194 | { 195 | m_Owner.Add(this); 196 | } 197 | } 198 | 199 | [DefaultExecutionOrder(int.MinValue)] 200 | class PreDbgDrawBehaviour : MonoBehaviour 201 | { 202 | [System.NonSerialized] 203 | public DbgDrawBehaviour debugDrawBehaviour; 204 | 205 | void Update() 206 | { 207 | if (debugDrawBehaviour != null) 208 | { 209 | UnityEngine.Profiling.Profiler.BeginSample("DbgDraw.RemoveDeadJobs"); 210 | debugDrawBehaviour.RemoveDeadJobs(); 211 | UnityEngine.Profiling.Profiler.EndSample(); 212 | } 213 | } 214 | } 215 | 216 | [DefaultExecutionOrder(int.MaxValue)] 217 | class DbgDrawBehaviour : MonoBehaviour 218 | { 219 | List m_PrimitiveJobs = new List(64); 220 | List> m_VertexListCache = new List>(64); 221 | List m_MeshJobs = new List(64); 222 | List m_ReleaseOnDestroy = new List(); 223 | 224 | Material[,] m_ColoredMaterials = null; // index array via Material[ZTest,CullMode] 225 | Material[,] m_ShadedMaterials = null; // index array via Material[ZTest,CullMode] 226 | LineBatchJob[,] m_LineBatch = null; 227 | 228 | #if UNITY_EDITOR 229 | int m_EditorPauseFrame = -1; 230 | #endif 231 | 232 | void Awake() 233 | { 234 | m_ColoredMaterials = CreateMaterialArray("Hidden/Internal-Colored"); // Added to "Always Included Shaders" in the Graphics settings by Unity 235 | m_ShadedMaterials = CreateMaterialArray("Hidden/DbgDraw-Shaded"); // Added to "Always Included Shaders" in the Graphics settings by DbgDrawBuildProcessor 236 | 237 | m_LineBatch = new LineBatchJob[2, 3]; 238 | for (var y = 0; y < m_LineBatch.GetLength(0); ++y) 239 | { 240 | for (var x = 0; x < m_LineBatch.GetLength(1); ++x) 241 | { 242 | m_LineBatch[y, x].list = new List(); 243 | m_LineBatch[y, x].material = m_ColoredMaterials[y, x]; 244 | } 245 | } 246 | 247 | gameObject.AddComponent().debugDrawBehaviour = this; 248 | RenderPipelineManager.endCameraRendering += OnRenderPipelineManagerEndCameraRendering; 249 | } 250 | 251 | void OnRenderPipelineManagerEndCameraRendering(ScriptableRenderContext context, Camera camera) 252 | { 253 | if (!isActiveAndEnabled) 254 | return; 255 | 256 | UnityEngine.Profiling.Profiler.BeginSample("DbgDraw.Render", camera); 257 | Render(camera); 258 | UnityEngine.Profiling.Profiler.EndSample(); 259 | } 260 | 261 | Material[,] CreateMaterialArray(string shaderName) 262 | { 263 | var materials = new Material[2, 3]; 264 | 265 | // depth test off 266 | materials[0, (int)CullMode.Off] = CreateMaterial(shaderName, CullMode.Off, false); 267 | materials[0, (int)CullMode.Front] = CreateMaterial(shaderName, CullMode.Front, false); 268 | materials[0, (int)CullMode.Back] = CreateMaterial(shaderName, CullMode.Back, false); 269 | 270 | // depth test on 271 | materials[1, (int)CullMode.Off] = CreateMaterial(shaderName, CullMode.Off, true); 272 | materials[1, (int)CullMode.Front] = CreateMaterial(shaderName, CullMode.Front, true); 273 | materials[1, (int)CullMode.Back] = CreateMaterial(shaderName, CullMode.Back, true); 274 | 275 | return materials; 276 | } 277 | 278 | Material CreateMaterial(string shaderName, CullMode cullMode, bool depthTest) 279 | { 280 | var shader = Shader.Find(shaderName); 281 | if (shader == null) 282 | { 283 | // This should not occur, but if it does, we try to find a fallback shader 284 | Debug.LogError($"{nameof(DbgDraw)}: Cannot find shader '{shaderName}'. {nameof(DbgDraw)} will not work correctly."); 285 | foreach (var fallback in new[] { "Hidden/Internal-Colored", "Unlit/Color" }) 286 | { 287 | shader = Shader.Find(shaderName); 288 | if (shader != null) 289 | break; 290 | } 291 | } 292 | 293 | var material = new Material(shader); 294 | 295 | material.SetColor("_Color", Color.white); 296 | material.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha); 297 | material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); 298 | material.SetInt("_Cull", (int)cullMode); 299 | material.SetInt("_ZWrite", 0); 300 | if (!depthTest) 301 | material.SetInt("_ZTest", 0); 302 | 303 | ReleaseOnDestroy(material); 304 | return material; 305 | } 306 | 307 | public void ReleaseOnDestroy(UnityEngine.Object obj) 308 | { 309 | m_ReleaseOnDestroy.Add(obj); 310 | } 311 | 312 | void OnDestroy() 313 | { 314 | for (var n = 0; n < m_ReleaseOnDestroy.Count; ++n) 315 | { 316 | if (m_ReleaseOnDestroy[n] != null) 317 | Destroy(m_ReleaseOnDestroy[n]); 318 | m_ReleaseOnDestroy[n] = null; 319 | } 320 | m_ReleaseOnDestroy.Clear(); 321 | 322 | m_ReleaseOnDestroy = null; 323 | m_PrimitiveJobs = null; 324 | m_VertexListCache = null; 325 | m_MeshJobs = null; 326 | m_ShadedMaterials = null; 327 | m_ColoredMaterials = null; 328 | m_LineBatch = null; 329 | RenderPipelineManager.endCameraRendering -= OnRenderPipelineManagerEndCameraRendering; 330 | } 331 | 332 | void OnRenderObject() 333 | { 334 | var camera = Camera.current; 335 | UnityEngine.Profiling.Profiler.BeginSample("DbgDraw.Render", camera); 336 | Render(camera); 337 | UnityEngine.Profiling.Profiler.EndSample(); 338 | } 339 | 340 | void Render(Camera camera) 341 | { 342 | if (!isEnabled || camera == null || !isSupported) 343 | return; 344 | //if (!Application.isPlaying) 345 | // return; 346 | 347 | // Render only in game or scene view. If we don't to this, we also render 348 | // stuff in the frame debugger mesh preview window for example. 349 | var validCamera = false; 350 | if (camera.cameraType == CameraType.Game && camera.CompareTag("MainCamera")) validCamera = true; 351 | if (camera.cameraType == CameraType.SceneView) validCamera = true; 352 | if (!validCamera) 353 | return; 354 | 355 | // If you pause and then unpause the Unity editor, Time.unscaledDeltaTime gets advanced 356 | // the amount of time you paused the editor. In this case, any jobs with a 'duration' often just vanish. 357 | // Therefore we detect when the editor gets unpaused and for this frame, we ignore the deltatime! 358 | var deltaTime = Time.unscaledDeltaTime; 359 | 360 | #if UNITY_EDITOR 361 | if (UnityEditor.EditorApplication.isPaused) 362 | m_EditorPauseFrame = Time.frameCount; 363 | 364 | if (!UnityEditor.EditorApplication.isPaused && m_EditorPauseFrame == Time.frameCount - 1) 365 | deltaTime = 0; 366 | #endif 367 | 368 | UnityEngine.Profiling.Profiler.BeginSample("DbgDraw.DrawMeshJobs"); 369 | DrawMeshJobs(deltaTime); 370 | UnityEngine.Profiling.Profiler.EndSample(); 371 | 372 | UnityEngine.Profiling.Profiler.BeginSample("DbgDraw.DrawPrimitiveJobs"); 373 | DrawPrimitiveJobs(deltaTime); 374 | UnityEngine.Profiling.Profiler.EndSample(); 375 | 376 | UnityEngine.Profiling.Profiler.BeginSample("DbgDraw.DrawLines"); 377 | DrawLines(deltaTime); 378 | UnityEngine.Profiling.Profiler.EndSample(); 379 | } 380 | 381 | void ResetMaterialColors() 382 | { 383 | ResetMaterialColors(m_ColoredMaterials); 384 | ResetMaterialColors(m_ShadedMaterials); 385 | } 386 | 387 | void ResetMaterialColors(Material[,] materials) 388 | { 389 | for (var y = 0; y < materials.GetLength(0); y++) 390 | { 391 | for (var x = 0; x < materials.GetLength(1); x++) 392 | { 393 | if (materials[y, x] != null) 394 | materials[y, x].color = Color.white; 395 | } 396 | } 397 | } 398 | 399 | void DrawPrimitiveJobs(float deltaTime) 400 | { 401 | ResetMaterialColors(); 402 | Material material = null; 403 | 404 | GL.PushMatrix(); 405 | 406 | for (var k = 0; k < m_PrimitiveJobs.Count; ++k) 407 | { 408 | var job = m_PrimitiveJobs[k]; 409 | 410 | if (job.useMatrix) 411 | { 412 | GL.PushMatrix(); 413 | GL.MultMatrix(job.matrix); 414 | } 415 | 416 | if (job.material != material) 417 | { 418 | material = job.material; 419 | material.color = Color.white; 420 | material.SetPass(0); 421 | } 422 | 423 | GL.Begin(job.primitiveType); 424 | 425 | for (var n = 0; n < job.list.Count; ++n) 426 | { 427 | if (job.useVertexColor || n == 0) 428 | GL.Color(job.list[n].color); 429 | 430 | GL.Vertex(job.list[n].position); 431 | } 432 | 433 | GL.End(); 434 | 435 | if (job.useMatrix) 436 | GL.PopMatrix(); 437 | 438 | job.remainingDuration -= deltaTime; 439 | m_PrimitiveJobs[k] = job; 440 | } 441 | 442 | GL.PopMatrix(); 443 | } 444 | 445 | void DrawMeshJobs(float deltaTime) 446 | { 447 | ResetMaterialColors(); 448 | Material material = null; 449 | 450 | for (var k = 0; k < m_MeshJobs.Count; ++k) 451 | { 452 | var job = m_MeshJobs[k]; 453 | 454 | if (job.material != material || material.color != job.color) 455 | { 456 | material = job.material; 457 | material.color = job.color; 458 | material.SetPass(0); 459 | } 460 | 461 | Graphics.DrawMeshNow(job.mesh, job.matrix); 462 | 463 | job.remainingDuration -= deltaTime; 464 | m_MeshJobs[k] = job; 465 | } 466 | } 467 | 468 | void DrawLines(float deltaTime) 469 | { 470 | ResetMaterialColors(); 471 | GL.PushMatrix(); 472 | 473 | for (var y = 0; y < m_LineBatch.GetLength(0); ++y) 474 | { 475 | for (var x = 0; x < m_LineBatch.GetLength(1); ++x) 476 | { 477 | var list = m_LineBatch[y, x].list; 478 | if (list.Count == 0) 479 | continue; 480 | 481 | var material = m_LineBatch[y, x].material; 482 | if (material == null) 483 | continue; 484 | 485 | material.color = Color.white; 486 | material.SetPass(0); 487 | 488 | GL.Begin(GL.LINES); 489 | 490 | for (var n = 0; n < list.Count; ++n) 491 | { 492 | var line = list[n]; 493 | 494 | GL.Color(line.color); 495 | GL.Vertex(line.a); 496 | GL.Vertex(line.b); 497 | 498 | line.remainingDuration -= deltaTime; 499 | list[n] = line; 500 | } 501 | 502 | GL.End(); 503 | } 504 | } 505 | 506 | GL.PopMatrix(); 507 | } 508 | 509 | List GetCachedVertexList() 510 | { 511 | if (m_VertexListCache.Count == 0) 512 | return new List(32); 513 | 514 | var list = m_VertexListCache[m_VertexListCache.Count - 1]; 515 | m_VertexListCache.RemoveAt(m_VertexListCache.Count - 1); 516 | return list; 517 | } 518 | 519 | public void RemoveDeadJobs() 520 | { 521 | for (var n = m_PrimitiveJobs.Count - 1; n >= 0; --n) 522 | { 523 | var job = m_PrimitiveJobs[n]; 524 | if (job.remainingDuration <= 0) 525 | { 526 | if (job.list != null) 527 | { 528 | job.list.Clear(); 529 | m_VertexListCache.Add(job.list); 530 | } 531 | 532 | m_PrimitiveJobs.RemoveAt(n); 533 | } 534 | } 535 | 536 | for (var y = 0; y < m_LineBatch.GetLength(0); ++y) 537 | { 538 | for (var x = 0; x < m_LineBatch.GetLength(1); ++x) 539 | { 540 | var list = m_LineBatch[y, x].list; 541 | for (var n = list.Count - 1; n >= 0; --n) 542 | { 543 | var line = list[n]; 544 | if (line.remainingDuration <= 0) 545 | list.RemoveAt(n); 546 | } 547 | } 548 | } 549 | 550 | for (var n = m_MeshJobs.Count - 1; n >= 0; --n) 551 | { 552 | var job = m_MeshJobs[n]; 553 | if (job.remainingDuration <= 0) 554 | m_MeshJobs.RemoveAt(n); 555 | } 556 | } 557 | 558 | public LineBatchJob GetLineBatch(bool depthTest, CullMode cullMode) 559 | { 560 | var batch = m_LineBatch[depthTest ? 1 : 0, (int)cullMode]; 561 | return batch; 562 | } 563 | 564 | public PrimitiveJob AllocPrimitiveJob(int primitiveType, float duration, bool depthTest, CullMode cullMode, bool shaded) 565 | { 566 | var job = new PrimitiveJob(m_PrimitiveJobs); 567 | job.primitiveType = primitiveType; 568 | job.remainingDuration = duration; 569 | job.depthTest = depthTest; 570 | 571 | if (shaded) 572 | job.material = m_ShadedMaterials[depthTest ? 1 : 0, (int)cullMode]; 573 | else 574 | job.material = m_ColoredMaterials[depthTest ? 1 : 0, (int)cullMode]; 575 | 576 | job.list = GetCachedVertexList(); 577 | return job; 578 | } 579 | 580 | public MeshJob AllocMeshJob(float duration, bool depthTest, CullMode cullMode, bool shaded) 581 | { 582 | var job = new MeshJob(m_MeshJobs); 583 | job.remainingDuration = duration; 584 | job.depthTest = depthTest; 585 | job.color = Color.white; 586 | 587 | if (shaded) 588 | job.material = m_ShadedMaterials[depthTest ? 1 : 0, (int)cullMode]; 589 | else 590 | job.material = m_ColoredMaterials[depthTest ? 1 : 0, (int)cullMode]; 591 | 592 | return job; 593 | } 594 | } 595 | 596 | static DbgDrawBehaviour s_Instance; 597 | static DbgDrawBehaviour instance 598 | { 599 | get 600 | { 601 | if (s_Instance != null) 602 | return s_Instance; 603 | 604 | #if UNITY_2023_1_OR_NEWER 605 | s_Instance = DbgDrawBehaviour.FindFirstObjectByType(); 606 | #else 607 | s_Instance = DbgDrawBehaviour.FindObjectOfType(); 608 | #endif 609 | if (s_Instance == null) 610 | { 611 | s_Instance = new GameObject("DbgDraw").AddComponent(); 612 | s_Instance.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); 613 | } 614 | 615 | return s_Instance; 616 | } 617 | } 618 | } 619 | } 620 | -------------------------------------------------------------------------------- /Runtime/Core/DbgDraw.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e6cd09bc8e1b074694913cb6ed84245 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a50426d1d287da419563c759c04188b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Shaders/DbgDraw-Shaded.shader: -------------------------------------------------------------------------------- 1 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 2 | 3 | // Unlit alpha-blended shader. 4 | // - no lighting 5 | // - no lightmap support 6 | // - no per-material color 7 | 8 | // DbgDraw for Unity. Copyright (c) 2019-2024 Peter Schraut (www.console-dev.de). See LICENSE.md 9 | // DbgDraw-Shaded implements some kind of fake lighting to mimic how the Unity Gizmos and Handles renders models. 10 | // https://github.com/pschraut/UnityDbgDraw 11 | 12 | Shader "Hidden/DbgDraw-Shaded" { 13 | Properties { 14 | _Color("Color", Color) = (1,1,1,1) 15 | _SrcBlend("SrcBlend", Int) = 5.0 // SrcAlpha 16 | _DstBlend("DstBlend", Int) = 10.0 // OneMinusSrcAlpha 17 | _ZWrite("ZWrite", Int) = 1.0 // On 18 | _ZTest("ZTest", Int) = 4.0 // LEqual 19 | _Cull("Cull", Int) = 0.0 // Off 20 | _ZBias("ZBias", Float) = 0.0 21 | } 22 | 23 | SubShader { 24 | Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} 25 | LOD 100 26 | 27 | Blend[_SrcBlend][_DstBlend] 28 | ZWrite[_ZWrite] 29 | ZTest[_ZTest] 30 | Cull [_Cull] 31 | Offset[_ZBias],[_ZBias] 32 | 33 | Pass { 34 | CGPROGRAM 35 | #pragma vertex vert 36 | #pragma fragment frag 37 | #pragma target 2.0 38 | #pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON 39 | #include "UnityCG.cginc" 40 | 41 | struct appdata_t { 42 | float4 vertex : POSITION; 43 | float2 texcoord : TEXCOORD0; 44 | float3 normal : NORMAL; 45 | float4 color : COLOR0; 46 | UNITY_VERTEX_INPUT_INSTANCE_ID 47 | }; 48 | 49 | struct v2f { 50 | float4 vertex : SV_POSITION; 51 | fixed4 color : COLOR0; 52 | UNITY_VERTEX_OUTPUT_STEREO 53 | }; 54 | 55 | float4 _Color; 56 | 57 | v2f vert (appdata_t v) 58 | { 59 | v2f o; 60 | UNITY_SETUP_INSTANCE_ID(v); 61 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 62 | o.vertex = UnityObjectToClipPos(v.vertex); 63 | 64 | float3 fakeLightNormal = mul((float3x3)unity_WorldToObject, normalize(float3(0, 1, 1))); 65 | float4 shadedColor = saturate(dot(normalize(v.normal), fakeLightNormal)) * 0.35; 66 | 67 | o.color.rgb = v.color.rgb - shadedColor.rgb; 68 | o.color.a = v.color.a; 69 | o.color *= _Color; 70 | return o; 71 | } 72 | 73 | fixed4 frag (v2f i) : SV_Target 74 | { 75 | return i.color; 76 | } 77 | ENDCG 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /Runtime/Shaders/DbgDraw-Shaded.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57a92bcbca250aa4c8148063dd12f7d9 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Runtime/Unity.DbgDraw.Runtime.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.DbgDraw.Runtime" 3 | } 4 | -------------------------------------------------------------------------------- /Runtime/Unity.DbgDraw.Runtime.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0ca7da2c713f5849a8e3326866a5e49 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.oddworm.dbgdraw", 3 | "version": "1.2.0", 4 | "displayName": "Debug Draw API", 5 | "description": "DbgDraw provides the ability to render various 2D and 3D shapes for visual debugging purposes. It's similar to Unity's Gizmos and Handles API's.", 6 | "unity": "2020.3", 7 | "dependencies": { 8 | "com.unity.test-framework": "1.1.3" 9 | }, 10 | "keywords": [ 11 | "unity", 12 | "debug" 13 | ], 14 | "author": { 15 | "name": "Peter Schraut", 16 | "url": "http://console-dev.de" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/pschraut/UnityDbgDraw.git" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1abcf127d7ba71f40a7071bd888d8a28 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------