Пример #1
0
        public XZGridCell(XZGridCell source)
        {
            _xIndex = source._xIndex;
            _zIndex = source._zIndex;

            _parentGrid = source._parentGrid;
            _quad       = source.Quad;
        }
Пример #2
0
        public XZGridCell(int xIndex, int zIndex, XZGrid parentGrid, XZOrientedQuad3D orientedQuad)
        {
            _xIndex = xIndex;
            _zIndex = zIndex;

            _parentGrid = parentGrid;
            _quad       = orientedQuad;
        }
Пример #3
0
        private void RenderXZGridRotationField()
        {
            XZGrid  xzGrid          = ObjectSnapping.Get().XZSnapGrid;
            Vector3 currentRotation = xzGrid.Rotation.eulerAngles;
            Vector3 newVector       = EditorGUILayout.Vector3Field(GetContentForXZGridRotationField(), currentRotation);

            if (newVector != currentRotation)
            {
                UndoEx.RecordForToolAction(xzGrid);
                xzGrid.SetRotation(Quaternion.Euler(newVector));

                SceneView.RepaintAll();
            }
        }
Пример #4
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();
        }
Пример #5
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();
        }
Пример #6
0
        public GridCellRayHit GetGridCellRayHit()
        {
            Ray ray = GetWorldRay();

            float  minT;
            XZGrid closestSnapGrid = GetClosestHitSnapGridAndMinT(ObjectSnapping.Get().GetAllSnapGrids(), ray, out minT);

            if (closestSnapGrid != null)
            {
                return(GetGridCellHit(closestSnapGrid, ray, minT));
            }
            else
            {
                return(null);
            }
        }
Пример #7
0
        private void RenderGridCellLines_Obsolete(XZGrid grid, XZVisibleGridCellRange visibleCellRange)
        {
            int   minCellIndexX    = visibleCellRange.XAxisVisibleCellRange.Min;
            int   maxCellIndexX    = visibleCellRange.XAxisVisibleCellRange.Max;
            float numberOfCellsOnX = maxCellIndexX - minCellIndexX + 1.0f;

            int   minCellIndexZ    = visibleCellRange.ZAxisVisibleCellRange.Min;
            int   maxCellIndexZ    = visibleCellRange.ZAxisVisibleCellRange.Max;
            float numberOfCellsOnZ = maxCellIndexZ - minCellIndexZ + 1.0f;

            XZGridCellSizeSettings gridCellSizeSettings = grid.CellSizeSettings;
            XZGridRenderSettings   gridRenderSettings   = grid.RenderSettings;

            Vector3 startPointOnX, startPointOnZ;
            Vector3 lineCubeSize = Vector3.zero;

            // Render the grid lines which extend along the grid's X axis
            GizmosColor.Push(grid.RenderSettings.CellLineColor);
            startPointOnX  = grid.GetCellHrzStart(minCellIndexX);
            lineCubeSize.z = gridRenderSettings.CellLineThickness;
            int maxLineIndex = maxCellIndexZ + 1;

            for (int lineIndex = minCellIndexZ; lineIndex <= maxLineIndex; ++lineIndex)
            {
                startPointOnZ = grid.GetCellDepthStart(lineIndex);
                Vector3 firstPoint  = startPointOnX + startPointOnZ;
                Vector3 secondPoint = firstPoint + XZGrid.ModelSpaceRightAxis * (numberOfCellsOnX * gridCellSizeSettings.CellSizeX);

                lineCubeSize.x = (firstPoint - secondPoint).magnitude + gridRenderSettings.CellLineThickness;
                Gizmos.DrawCube((firstPoint + secondPoint) * 0.5f, lineCubeSize);
            }

            // Render the grid lines which extend along the grid's Z axis
            startPointOnZ  = grid.GetCellDepthStart(minCellIndexZ);
            lineCubeSize.x = gridRenderSettings.CellLineThickness;
            maxLineIndex   = maxCellIndexX + 1;
            for (int lineIndex = minCellIndexX; lineIndex <= maxLineIndex; ++lineIndex)
            {
                startPointOnX = grid.GetCellHrzStart(lineIndex);
                Vector3 firstPoint  = startPointOnX + startPointOnZ;
                Vector3 secondPoint = firstPoint + XZGrid.ModelSpaceLookAxis * (numberOfCellsOnZ * gridCellSizeSettings.CellSizeZ);

                lineCubeSize.z = (firstPoint - secondPoint).magnitude;
                Gizmos.DrawCube((firstPoint + secondPoint) * 0.5f, lineCubeSize);
            }
            GizmosColor.Pop();
        }
Пример #8
0
        private XZGrid GetClosestHitSnapGridAndMinT(List <XZGrid> allSnapGrids, Ray ray, out float minT)
        {
            minT = float.MaxValue;

            XZGrid closestSnapGrid = null;

            foreach (XZGrid snapGrid in allSnapGrids)
            {
                float t;
                if (snapGrid.Plane.Raycast(ray, out t) & t < minT)
                {
                    minT            = t;
                    closestSnapGrid = snapGrid;
                }
            }

            return(closestSnapGrid);
        }
Пример #9
0
        private List <Vector3> GetGridPlaneIntersectionPointsWithVolumeRays(XZGrid grid, CameraViewVolume cameraViewVolume)
        {
            Plane gridPlane = grid.Plane;

            Ray3D[] volumeRays = cameraViewVolume.WorldSpaceVolumeEdgeRays;

            float t;
            var   intersectionPoints = new List <Vector3>();

            foreach (Ray3D ray in volumeRays)
            {
                if (ray.IntersectsPlane(gridPlane, out t))
                {
                    intersectionPoints.Add(ray.Origin + ray.Direction * t);
                }
            }

            return(intersectionPoints);
        }
Пример #10
0
        private void RenderGridPlane_Obsolete(XZGrid grid, XZVisibleGridCellRange visibleCellRange)
        {
            int minCellIndexX = visibleCellRange.XAxisVisibleCellRange.Min;
            int maxCellIndexX = visibleCellRange.XAxisVisibleCellRange.Max;

            int minCellIndexZ = visibleCellRange.ZAxisVisibleCellRange.Min;
            int maxCellIndexZ = visibleCellRange.ZAxisVisibleCellRange.Max;

            float numberOfCellsOnX = maxCellIndexX - minCellIndexX + 1.0f;
            float numberOfCellsOnZ = maxCellIndexZ - minCellIndexZ + 1.0f;

            XZGridCellSizeSettings gridCellSizeSettings = grid.CellSizeSettings;
            Vector3 planeCenter = (grid.GetCellHrzStart(minCellIndexX) + grid.GetCellDepthStart(minCellIndexZ) +
                                   grid.GetCellHrzStart(maxCellIndexX + 1) + grid.GetCellDepthStart(maxCellIndexZ + 1)) * 0.5f;
            Vector3 planeSize = new Vector3(numberOfCellsOnX * gridCellSizeSettings.CellSizeX, 0.0f, numberOfCellsOnZ * gridCellSizeSettings.CellSizeZ);

            GizmosColor.Push(grid.RenderSettings.PlaneColor);
            Gizmos.DrawCube(planeCenter, planeSize);
            GizmosColor.Pop();
        }
Пример #11
0
        public XZVisibleGridCellRange Calculate(XZGrid grid, CameraViewVolume cameraViewVolume)
        {
            List <Vector3> gridPlaneIntersectionPoints = GetGridPlaneIntersectionPointsWithVolumeRays(grid, cameraViewVolume);

            return(CalculateVisibleCellRangeFromGridPlaneIntersectionPoints(grid, gridPlaneIntersectionPoints));
        }
Пример #12
0
        private XZVisibleGridCellRange CalculateVisibleCellRangeFromGridCells(XZGrid grid, List <XZGridCell> gridCells)
        {
            int minCellIndexX = int.MaxValue;
            int maxCellIndexX = int.MinValue;
            int minCellIndexZ = int.MaxValue;
            int maxCellIndexZ = int.MinValue;

            foreach (XZGridCell cell in gridCells)
            {
                if (cell.XIndex < minCellIndexX)
                {
                    minCellIndexX = cell.XIndex;
                }
                if (cell.XIndex > maxCellIndexX)
                {
                    maxCellIndexX = cell.XIndex;
                }

                if (cell.ZIndex < minCellIndexZ)
                {
                    minCellIndexZ = cell.ZIndex;
                }
                if (cell.ZIndex > maxCellIndexZ)
                {
                    maxCellIndexZ = cell.ZIndex;
                }
            }

            XZGridDimensionSettings gridDimensionSettings = grid.DimensionSettings;

            if (gridDimensionSettings.DimensionType == XZGridDimensionType.Finite)
            {
                XZGridFiniteDimensionSettings gridFiniteDimensionSettings = grid.DimensionSettings.FiniteDimensionSettings;

                if (minCellIndexX < gridFiniteDimensionSettings.XAxisCellIndexRange.Min)
                {
                    minCellIndexX = gridFiniteDimensionSettings.XAxisCellIndexRange.Min;
                }
                if (maxCellIndexX > gridFiniteDimensionSettings.XAxisCellIndexRange.Max)
                {
                    maxCellIndexX = gridFiniteDimensionSettings.XAxisCellIndexRange.Max;
                }

                if (minCellIndexZ < gridFiniteDimensionSettings.ZAxisCellIndexRange.Min)
                {
                    minCellIndexZ = gridFiniteDimensionSettings.ZAxisCellIndexRange.Min;
                }
                if (maxCellIndexZ > gridFiniteDimensionSettings.ZAxisCellIndexRange.Max)
                {
                    maxCellIndexZ = gridFiniteDimensionSettings.ZAxisCellIndexRange.Max;
                }

                if (minCellIndexX > maxCellIndexX)
                {
                    minCellIndexX = maxCellIndexX;
                }
                if (minCellIndexZ > maxCellIndexZ)
                {
                    minCellIndexZ = maxCellIndexZ;
                }
            }

            var visibleCellRange = new XZVisibleGridCellRange();

            visibleCellRange.XAxisVisibleCellRange.Min = minCellIndexX;
            visibleCellRange.XAxisVisibleCellRange.Max = maxCellIndexX;
            visibleCellRange.ZAxisVisibleCellRange.Min = minCellIndexZ;
            visibleCellRange.ZAxisVisibleCellRange.Max = maxCellIndexZ;

            return(visibleCellRange);
        }
Пример #13
0
        private XZVisibleGridCellRange CalculateVisibleCellRangeFromGridPlaneIntersectionPoints(XZGrid grid, List <Vector3> gridPlaneIntersectionPoints)
        {
            if (gridPlaneIntersectionPoints.Count == 0)
            {
                new XZVisibleGridCellRange();
            }

            List <XZGridCell> gridCellsFromIntersectionPoints = grid.GetCellsFromPoints(gridPlaneIntersectionPoints);

            return(CalculateVisibleCellRangeFromGridCells(grid, gridCellsFromIntersectionPoints));
        }
Пример #14
0
        private GridCellRayHit GetGridCellHit(XZGrid hitGrid, Ray ray, float t)
        {
            XZGridCell hitGridCell = hitGrid.GetCellFromPoint(ray.GetPoint(t));

            return(new GridCellRayHit(ray, t, hitGridCell));
        }