Пример #1
0
    public void EdgePaintHandleUpdate(CVectorModel Model, ref SGizmoData Gizmo)
    {
        if (Gizmo.mGizmoHover != EGizmoHandleID.NONE)
        {
            return;
        }

        float   minT          = float.MaxValue;
        Vector3 planeHitPoint = Vector3.zero;
        int     hitPlaneID    = -1;
        bool    planeWasHit   = false;

        for (int i = 0; i < Model.mPlanes.Count; ++i)
        {
            CModelPlane p = Model.mPlanes[i];
            Vector3     hit;
            float       t;
            if (p.IntersectRay(Gizmo.mStartMouseRay, out hit, out t))
            {
                planeWasHit = true;
                if (t < minT)
                {
                    minT          = t;
                    planeHitPoint = hit;
                    hitPlaneID    = i;
                }
            }
        }

        if (planeWasHit)
        {
            CModelPlane p = Model.mPlanes[hitPlaneID];

            // Find closest impact point on plane
            Vector3 projPoint;
            float   d1 = CIntersections.PointVsLine(planeHitPoint, p.c1, p.c2, out projPoint);
            float   d2 = CIntersections.PointVsLine(planeHitPoint, p.c2, p.c3, out projPoint);
            float   d3 = CIntersections.PointVsLine(planeHitPoint, p.c3, p.c4, out projPoint);
            float   d4 = CIntersections.PointVsLine(planeHitPoint, p.c4, p.c1, out projPoint);

            //CDebug.DrawLine(planeHitPoint, planeHitPoint + new Vector3(0, 0.1f, 0), Color.yellow, false);
            //CDebug.DrawLine(projPoint, projPoint + new Vector3(0, 0.1f, 0), Color.magenta, false);

            Gizmo.mGizmoHover = EGizmoHandleID.EDGE;
            Gizmo.mHoverID    = hitPlaneID;

            if (d4 < d2 && d4 < d3 && d4 < d1)
            {
                Gizmo.mCornerID = 3;
                CDebug.DrawLine(p.c4, p.c1, Color.blue, false);
            }
            else if (d2 < d1 && d2 < d3 && d2 < d4)
            {
                Gizmo.mCornerID = 1;
                CDebug.DrawLine(p.c2, p.c3, Color.blue, false);
            }
            else if (d3 < d2 && d3 < d1 && d3 < d4)
            {
                Gizmo.mCornerID = 2;
                CDebug.DrawLine(p.c3, p.c4, Color.blue, false);
            }
            else
            {
                Gizmo.mCornerID = 0;
                CDebug.DrawLine(p.c1, p.c2, Color.blue, false);
            }
        }
    }
Пример #2
0
    public void Serialize(BinaryWriter W)
    {
        W.Write(mPlanes.Count);

        // Build brush index table
        List <CBrushAsset> _brushTable = new List <CBrushAsset>();

        for (int i = 0; i < mPlanes.Count; ++i)
        {
            CBrushAsset brush = mPlanes[i].mFillBrush;
            bool        found = false;

            if (brush != null)
            {
                for (int t = 0; t < _brushTable.Count; ++t)
                {
                    if (_brushTable[t] == brush)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _brushTable.Add(brush);
                }
            }

            for (int e = 0; e < 4; ++e)
            {
                for (int b = 0; b < 4; ++b)
                {
                    brush = mPlanes[i].mEdge[e].mBrush[b];
                    found = false;

                    if (brush != null)
                    {
                        for (int t = 0; t < _brushTable.Count; ++t)
                        {
                            if (_brushTable[t] == brush)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            _brushTable.Add(brush);
                        }
                    }
                }
            }
        }

        W.Write(_brushTable.Count);
        for (int t = 0; t < _brushTable.Count; ++t)
        {
            W.Write(_brushTable[t].mName);
        }

        for (int i = 0; i < mPlanes.Count; ++i)
        {
            CModelPlane p = mPlanes[i];
            W.Write(p.mName);

            W.Write(p.mPosition.x);
            W.Write(p.mPosition.y);
            W.Write(p.mPosition.z);

            W.Write(p.mRotation.x);
            W.Write(p.mRotation.y);
            W.Write(p.mRotation.z);

            CBrushAsset brush = p.mFillBrush;

            if (brush == null)
            {
                W.Write((int)-1);
            }
            else
            {
                for (int t = 0; t < _brushTable.Count; ++t)
                {
                    if (_brushTable[t] == brush)
                    {
                        W.Write(t);
                        break;
                    }
                }
            }

            for (int c = 0; c < 4; ++c)
            {
                W.Write(p.mCorner[c].mPosition.x);
                W.Write(p.mCorner[c].mPosition.y);
                W.Write(p.mCorner[c].mPosition.z);
            }

            for (int e = 0; e < 4; ++e)
            {
                for (int b = 0; b < 4; ++b)
                {
                    brush = p.mEdge[e].mBrush[b];

                    if (brush == null)
                    {
                        W.Write((int)-1);
                    }
                    else
                    {
                        for (int t = 0; t < _brushTable.Count; ++t)
                        {
                            if (_brushTable[t] == brush)
                            {
                                W.Write(t);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #3
0
    public override void Update(CInputState InputState)
    {
        DrawGrid(10);

        CModelPlane p        = null;
        Ray         mouseRay = GetViewportMouseRay();

        _gizmoData.mCurrentMouseRay = mouseRay;

        if (_selectedPrimID != -1)
        {
            p = _vectorModel.mPlanes[_selectedPrimID];
        }

        if (_viewportMouseDown)
        {
            EdgePaintHandleMouseDown(ref _gizmoData);
            TranslateHandleMouseDown(ref _gizmoData);
            PrimHandleMouseDown(ref _gizmoData);
        }
        else
        {
            PrimHandleDraw(ref _gizmoData);

            _gizmoData.mGizmoHover       = EGizmoHandleID.NONE;
            _gizmoData.mStartMouseRay    = mouseRay;
            _gizmoData.mActedOnMouseDown = false;
            _gizmoData.mHoverID          = -1;

            if (_tool == ETool.EDGE)
            {
                // Primitive agnostic
                EdgePaintHandleUpdate(_vectorModel, ref _gizmoData);
            }
            else if (_tool == ETool.TRANSLATE)
            {
                if (p != null)
                {
                    Vector3 axisX = p.mAxisX;
                    Vector3 axisY = p.mAxisY;
                    Vector3 axisZ = p.mAxisZ;

                    if (!_localTransform)
                    {
                        axisX = Vector3.right;
                        axisY = Vector3.up;
                        axisZ = Vector3.forward;
                    }

                    TranslateHandleUpdate(p.mPosition, axisX, new Color(1, 0, 0, 1), -1, ref _gizmoData);
                    TranslateHandleUpdate(p.mPosition, axisY, new Color(0, 1, 0, 1), -1, ref _gizmoData);
                    TranslateHandleUpdate(p.mPosition, axisZ, new Color(0, 0, 1, 1), -1, ref _gizmoData);
                }
            }
            else if (_tool == ETool.VERTEX)
            {
                if (p != null)
                {
                    Vector3 axisX = p.mAxisX;
                    Vector3 axisY = p.mAxisY;
                    Vector3 axisZ = p.mAxisZ;

                    TranslateHandleUpdate(p.c1, axisX, new Color(1, 0, 0, 1), 0, ref _gizmoData);
                    TranslateHandleUpdate(p.c1, axisZ, new Color(0, 0, 1, 1), 0, ref _gizmoData);

                    TranslateHandleUpdate(p.c2, axisX, new Color(1, 0, 0, 1), 1, ref _gizmoData);
                    TranslateHandleUpdate(p.c2, axisZ, new Color(0, 0, 1, 1), 1, ref _gizmoData);

                    TranslateHandleUpdate(p.c3, axisX, new Color(1, 0, 0, 1), 2, ref _gizmoData);
                    TranslateHandleUpdate(p.c3, axisZ, new Color(0, 0, 1, 1), 2, ref _gizmoData);

                    TranslateHandleUpdate(p.c4, axisX, new Color(1, 0, 0, 1), 3, ref _gizmoData);
                    TranslateHandleUpdate(p.c4, axisZ, new Color(0, 0, 1, 1), 3, ref _gizmoData);
                }
            }

            PrimHandleUpdate(_vectorModel, ref _gizmoData, _selectedPrimID);
        }
    }