コード例 #1
0
ファイル: GridAxisDrawer.cs プロジェクト: UnMapache/VT_DEMO
            private void CreatePlaneMesh()
            {
                // Create the grid plane as a combination of 4 quadrants. This allows us to draw them differently
                // depending on various factors e.g. camera position.

                // Each quadrant can be defined by a min and a max point. Each quadrant is labeled below for reference.
                //
                // min ----------------- a axis
                //     |   Q   |   W   |
                //     -----------------    <- center point is grid origin (0, 0, 0)
                //     |   E   |   R   |
                //     -----------------
                // b axis			   max

                GridPoint aAxisOriginOffset = -1 * GridPoint.Scale(m_gridData.gridOrigin, AxisUtil.GetVector(aAxis));
                GridPoint bAxisOriginOffset = -1 * GridPoint.Scale(m_gridData.gridOrigin, AxisUtil.GetVector(bAxis));

                GridPoint aAxisMaxOffset = m_gridData.GridPositionToGridPoint(AxisUtil.GetVector(aAxis) * m_gridData.gridSize) + aAxisOriginOffset;
                GridPoint bAxisMaxOffset = m_gridData.GridPositionToGridPoint(AxisUtil.GetVector(bAxis) * m_gridData.gridSize) + bAxisOriginOffset;

                GridPoint qMin = aAxisOriginOffset + bAxisOriginOffset;
                GridPoint wMin = bAxisOriginOffset;
                GridPoint eMin = aAxisOriginOffset;
                GridPoint rMin = GridPoint.zero;
                GridPoint qMax = rMin;
                GridPoint wMax = aAxisMaxOffset;
                GridPoint eMax = bAxisMaxOffset;
                GridPoint rMax = aAxisMaxOffset + bAxisMaxOffset;

                CreateMeshQuadrant(Quadrant.Q, qMin, qMax, aAxis, bAxis);
                CreateMeshQuadrant(Quadrant.W, wMin, wMax, aAxis, bAxis);
                CreateMeshQuadrant(Quadrant.E, eMin, eMax, aAxis, bAxis);
                CreateMeshQuadrant(Quadrant.R, rMin, rMax, aAxis, bAxis);
            }
コード例 #2
0
ファイル: GridAxisDrawer.cs プロジェクト: UnMapache/VT_DEMO
            private void DrawSelectionPlaneReferenceLines(Quadrant quadrant, Transform transform)
            {
                Color originalColor = Handles.color;
                Color lineColor     = GridSettings.instance.planeReferenceStyle == ReferenceLineStyle.SingleColor ?
                                      GridSettings.instance.planeReferenceColor : GetAxisColor(m_axis);

                lineColor.a   = 1f;
                Handles.color = lineColor;

                Vector3 gridPosition = m_gridData.WorldToGridPosition(transform.position);

                float aStart = ((quadrant & Quadrant.QE) != 0) ? -m_gridData.gridOrigin.GetComponent(aAxis) : 0f;
                float bStart = ((quadrant & Quadrant.QW) != 0) ? -m_gridData.gridOrigin.GetComponent(bAxis) : 0f;
                float aEnd   = ((quadrant & Quadrant.QE) != 0) ? 0f : m_gridData.gridSize - m_gridData.gridOrigin.GetComponent(aAxis);
                float bEnd   = ((quadrant & Quadrant.QW) != 0) ? 0f : m_gridData.gridSize - m_gridData.gridOrigin.GetComponent(bAxis);

                Vector3 start = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(aAxis) * aStart;
                Vector3 end   = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(aAxis) * aEnd;

                Handles.DrawLine(start, end);

                start = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(bAxis) * bStart;
                end   = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(bAxis) * bEnd;
                Handles.DrawLine(start, end);

                Handles.color = originalColor;
            }
コード例 #3
0
ファイル: GridAxisDrawer.cs プロジェクト: UnMapache/VT_DEMO
            private void DrawSelectionAxisReferenceLines(Transform transform)
            {
                Color originalColor = Handles.color;
                Color lineColor     = GridSettings.instance.axisReferenceStyle == ReferenceLineStyle.SingleColor ?
                                      GridSettings.instance.axisReferenceColor : GetAxisColor(m_axis);

                lineColor.a   = 1f;
                Handles.color = lineColor;

                Vector3 gridPosition  = m_gridData.WorldToGridPosition(transform.position);
                Vector3 planePosition = Vector3.Scale(gridPosition, Vector3.one - AxisUtil.GetVector(m_axis));

                if (!Mathf.Approximately(gridPosition.GetComponent(aAxis), 0f) &&
                    !Mathf.Approximately(gridPosition.GetComponent(bAxis), 0f))
                {
                    Handles.DrawLine(gridPosition, planePosition);
                }

                Handles.color = originalColor;
            }
コード例 #4
0
ファイル: GridAxisDrawer.cs プロジェクト: UnMapache/VT_DEMO
            private void CreateMeshQuadrant(Quadrant quadrant, GridPoint minGridPoint, GridPoint maxGridPoint, Axis aAxis, Axis bAxis)
            {
                if ((minGridPoint.x == maxGridPoint.x && m_axis != Axis.X) ||
                    (minGridPoint.y == maxGridPoint.y && m_axis != Axis.Y) ||
                    (minGridPoint.z == maxGridPoint.z && m_axis != Axis.Z))
                {
                    // one or more dimensions has 0 area, nothing to draw!
                    // note that components for this axis should be the same since that's the level we're drawing the plane at.
                    return;
                }

                Color minorColor;
                Color majorColor;

                int aMin = minGridPoint.GetComponent(aAxis);
                int bMin = minGridPoint.GetComponent(bAxis);
                int aMax = maxGridPoint.GetComponent(aAxis);
                int bMax = maxGridPoint.GetComponent(bAxis);

                minorColor   = GetAxisColor(m_axis);
                majorColor   = minorColor;
                majorColor.a = GridSettings.instance.majorLineOpacity;

                GridPoint startA = GridPoint.Scale(minGridPoint, AxisUtil.GetVector(aAxis));
                GridPoint startB = GridPoint.Scale(minGridPoint, AxisUtil.GetVector(bAxis));
                GridPoint endA   = GridPoint.Scale(maxGridPoint, AxisUtil.GetVector(aAxis));
                GridPoint endB   = GridPoint.Scale(maxGridPoint, AxisUtil.GetVector(bAxis));

                MeshBuilder gridBuilder = new MeshBuilder();

                Vector3 aAxisVector = AxisUtil.GetVector(aAxis);
                Vector3 bAxisVector = AxisUtil.GetVector(bAxis);

                int line = aMin;

                for (int a = aMin; a < aMax + 1; ++a)
                {
                    Color color = (line % GridSettings.instance.majorLineSpacing) == 0 ? majorColor : minorColor;
                    ++line;

                    GridPoint aPoint = m_gridData.GridPositionToGridPoint(a * aAxisVector);
                    Vector3   start  = m_gridData.GridPointToGridPosition(aPoint + startB);
                    Vector3   end    = m_gridData.GridPointToGridPosition(aPoint + endB);

                    gridBuilder.AddVertex(start, color);
                    gridBuilder.AddVertex(end, color);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 2);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 1);
                }

                line = bMin;
                for (int b = bMin; b < bMax + 1; ++b)
                {
                    Color color = (line % GridSettings.instance.majorLineSpacing) == 0 ? majorColor : minorColor;
                    ++line;

                    GridPoint bPoint = m_gridData.GridPositionToGridPoint(b * bAxisVector);
                    Vector3   start  = m_gridData.GridPointToGridPosition(bPoint + startA);
                    Vector3   end    = m_gridData.GridPointToGridPosition(bPoint + endA);

                    gridBuilder.AddVertex(start, color);
                    gridBuilder.AddVertex(end, color);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 2);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 1);
                }

                m_quadrantGrids.Add(quadrant, gridBuilder);


                // add outlines
                {
                    MeshBuilder outlineBuilder = new MeshBuilder();

                    Color color = GridSettings.instance.unfocusedColor;

                    Vector3 a = m_gridData.GridPointToGridPosition(startA + startB);
                    Vector3 b = m_gridData.GridPointToGridPosition(startA + endB);
                    Vector3 c = m_gridData.GridPointToGridPosition(endA + endB);
                    Vector3 d = m_gridData.GridPointToGridPosition(endA + startB);

                    outlineBuilder.AddVertex(a, color);
                    outlineBuilder.AddVertex(b, color);
                    outlineBuilder.AddVertex(c, color);
                    outlineBuilder.AddVertex(d, color);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 4);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 3);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 3);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 2);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 2);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 1);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 1);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 4);

                    m_quadrantOutlines.Add(quadrant, outlineBuilder);
                }
            }