Example #1
0
        public static void RenderLine(Vector3 firstPoint, Vector3 secondPoint, Color color)
        {
            GizmosMatrix.Push(Matrix4x4.identity);
            GizmosColor.Push(color);

            Gizmos.DrawLine(firstPoint, secondPoint);

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
Example #2
0
        public static void RenderMesh(Mesh mesh, Matrix4x4 transformMatrix, Color color)
        {
            GizmosMatrix.Push(transformMatrix);
            GizmosColor.Push(color);

            Gizmos.DrawMesh(mesh);

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
Example #3
0
        public static void RenderOrientedBoxEdges(OrientedBox orientedBox, Color color)
        {
            GizmosColor.Push(color);
            GizmosMatrix.Push(Matrix4x4.TRS(orientedBox.Center, orientedBox.Rotation, orientedBox.ScaledSize));

            Gizmos.DrawWireCube(Vector3.zero, Vector3.one);

            GizmosMatrix.Pop();
            GizmosColor.Pop();
        }
Example #4
0
        public static void RenderXZOrientedQuad(XZOrientedQuad3D orientedQuad, Color color)
        {
            GizmosMatrix.Push(orientedQuad.TransformMatrix.ToMatrix4x4x);
            GizmosColor.Push(color);

            Gizmos.DrawCube(Vector3.zero, new Vector3(orientedQuad.ModelSpaceXZSize.x, 0.0f, orientedQuad.ModelSpaceXZSize.y));

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
        public void RenderGizmos(RenderableCoordinateSystem coordinateSystem)
        {
            CoordinateSystemRenderSettings coordinateSystemRenderSettings = coordinateSystem.RenderSettings;

            if (coordinateSystemRenderSettings.IsVisible)
            {
                GizmosMatrix.Push(coordinateSystem.TransformMatrix.ToMatrix4x4x);
                RenderAllCooridnateSystemAxes(coordinateSystemRenderSettings);
                GizmosMatrix.Pop();
            }
        }
Example #6
0
        public static void RenderOrientedBox(OrientedBox orientedBox, Color color)
        {
            Matrix4x4 transformMatrix = Matrix4x4.TRS(orientedBox.Center, orientedBox.Rotation, orientedBox.ScaledSize);

            GizmosMatrix.Push(transformMatrix);
            GizmosColor.Push(color);

            Gizmos.DrawCube(Vector3.zero, Vector3.one);

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
Example #7
0
        public static void RenderXZOrientedQuad(XZOrientedQuad3D orientedQuad, Color color, float offsetAlongNormal)
        {
            Matrix4x4 translationMatrix = Matrix4x4.TRS(orientedQuad.Plane.normal * offsetAlongNormal, Quaternion.identity, Vector3.one);

            GizmosMatrix.Push(translationMatrix * orientedQuad.TransformMatrix.ToMatrix4x4x);
            GizmosColor.Push(color);

            Gizmos.DrawCube(Vector3.zero, new Vector3(orientedQuad.ModelSpaceXZSize.x, 0.0f, orientedQuad.ModelSpaceXZSize.y));

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
Example #8
0
        /// <summary>
        /// This method renders all nodes in the tree using Unity's 'Gizmos' API. It can be
        /// used for debugging purposes.
        /// </summary>
        public void RenderGizmosDebug(TransformMatrix transformMatrix)
        {
            // We will use a transparent green color to render the tree nodes. We will also
            // activate the identity matrix because the necessary transform information resides
            // inside the nodes themsleves (the center is all we need actually).
            GizmosColor.Push(new Color(0.0f, 1.0f, 0.0f, 0.3f));
            GizmosMatrix.Push(transformMatrix.ToMatrix4x4x);

            // Start rendering from the root
            RenderGizmosDebugRecurse(_rootNode);

            // Restore the previous color and matrix
            GizmosMatrix.Pop();
            GizmosColor.Pop();
        }
Example #9
0
        public static void RenderLinesBetweenPoints(List <Vector3> points, Color color, Vector3 offset)
        {
            GizmosMatrix.Push(Matrix4x4.identity);
            GizmosColor.Push(color);

            int numberOfPoints = points.Count;

            for (int pointIndex = 0; pointIndex < numberOfPoints; ++pointIndex)
            {
                Gizmos.DrawLine(points[pointIndex] + offset, points[(pointIndex + 1) % numberOfPoints] + offset);
            }

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
Example #10
0
        public void RenderGizmosDebug(Matrix4x4 transformMatrix, Color aabbLineColor)
        {
            if (!_wasBuilt)
            {
                return;
            }

            GizmosMatrix.Push(transformMatrix);
            GizmosColor.Push(aabbLineColor);

            RenderGizmosDebugRecurse(_root);

            GizmosColor.Pop();
            GizmosMatrix.Pop();
        }
Example #11
0
        public void RenderGizmos(XZGrid grid, CameraViewVolume cameraViewVolume)
        {
            if (!grid.RenderSettings.IsVisible)
            {
                return;
            }

            // Note: Can not figure out how to render a finite grid inside a shader yet... :D
            if (grid.DimensionSettings.DimensionType == XZGridDimensionType.Finite)
            {
                RenderGizmos_Obsolete(grid, cameraViewVolume);
                return;
            }

            Plane   gridPlane       = grid.Plane;
            Vector3 gridPlaneCenter = gridPlane.ProjectPoint(SceneViewCamera.Camera.transform.position);

            Box            camVolumeAABB          = cameraViewVolume.WorldSpaceAABB;
            List <Vector3> projectedVolumeAABBPts = gridPlane.ProjectAllPoints(camVolumeAABB.GetCornerPoints());
            List <Vector3> modelSpacePrjPts       = Vector3Extensions.GetTransformedPoints(projectedVolumeAABBPts, grid.TransformMatrix.ToMatrix4x4x.inverse);
            Box            modelSpacePtsBox       = Box.FromPoints(modelSpacePrjPts);
            Vector3        gridPlaneSize          = modelSpacePtsBox.Size;

            Matrix4x4 planeTransformMatrix = Matrix4x4.TRS(gridPlaneCenter, grid.Rotation, gridPlaneSize);
            Material  xzGridMaterial       = MaterialPool.Get().XZGridMaterial;

            xzGridMaterial.SetFloat("_CellSizeX", grid.CellSizeSettings.CellSizeX);
            xzGridMaterial.SetFloat("_CellSizeZ", grid.CellSizeSettings.CellSizeZ);
            xzGridMaterial.SetVector("_CellOffset", grid.GetOriginPosition());
            xzGridMaterial.SetColor("_LineColor", grid.RenderSettings.CellLineColor);
            xzGridMaterial.SetColor("_PlaneColor", grid.RenderSettings.PlaneColor);
            xzGridMaterial.SetFloat("_CamFarPlaneDist", SceneViewCamera.Camera.farClipPlane);
            xzGridMaterial.SetVector("_CamWorldPos", SceneViewCamera.Camera.transform.position);
            xzGridMaterial.SetMatrix("_InvRotMatrix", Matrix4x4.TRS(Vector3.zero, grid.Rotation, Vector3.one).inverse);
            xzGridMaterial.SetMatrix("_PlaneTransformMtx", planeTransformMatrix);

            int numPasses = xzGridMaterial.passCount;

            for (int passIndex = 0; passIndex < numPasses; ++passIndex)
            {
                xzGridMaterial.SetPass(passIndex);
                Graphics.DrawMeshNow(GizmosEx.XZRectangleMesh, planeTransformMatrix);
            }

            GizmosMatrix.Push(grid.TransformMatrix.ToMatrix4x4x);
            grid.RenderableCoordinateSystem.RenderGizmos();
            GizmosMatrix.Pop();
        }
Example #12
0
        private void RenderGizmos_Obsolete(XZGrid grid, CameraViewVolume cameraViewVolume)
        {
            if (!grid.RenderSettings.IsVisible)
            {
                return;
            }

            var visibleCellRangeCalculator          = new XZVisibleGridCellRangeCalculator();
            XZVisibleGridCellRange visibleCellRange = visibleCellRangeCalculator.Calculate(grid, cameraViewVolume);

            GizmosMatrix.Push(grid.TransformMatrix.ToMatrix4x4x);
            RenderGridPlane_Obsolete(grid, visibleCellRange);
            RenderGridCellLines_Obsolete(grid, visibleCellRange);
            grid.RenderableCoordinateSystem.RenderGizmos();
            GizmosMatrix.Pop();
        }