示例#1
0
    public void PrimHandleUpdate(CVectorModel Model, ref SGizmoData Gizmo, int SelectedPrimID)
    {
        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)
        {
            Gizmo.mGizmoHover = EGizmoHandleID.PRIMTIVE;
            Gizmo.mHoverID    = hitPlaneID;
        }
    }
示例#2
0
    public void TranslateHandleMouseDown(ref SGizmoData Gizmo)
    {
        if (Gizmo.mGizmoHover != EGizmoHandleID.TRANSLATE)
        {
            return;
        }

        CModelPlane p = _vectorModel.mPlanes[Gizmo.mHoverID];
        float       t;
        Ray         R = Gizmo.mCurrentMouseRay;

        if (!Gizmo.mActedOnMouseDown)
        {
            Gizmo.mActedOnMouseDown = true;

            GetClosestPoints(Gizmo.mOrigin, Gizmo.mAxis, R.origin, R.direction, out t);
            Gizmo.mStartPos = (Gizmo.mAxis * t);
        }

        GetClosestPoints(Gizmo.mOrigin, Gizmo.mAxis, R.origin, R.direction, out t);
        Vector3 newRayPos = Gizmo.mAxis * t;
        Vector3 deltaPos  = newRayPos - Gizmo.mStartPos;

        Gizmo.mStartPos = newRayPos;
        //Vector3 newGizmoPos = p.mPosition + Gizmo.mAxis * t;
        //CDebug.DrawLine(newGizmoPos, newGizmoPos + Vector3.up, Color.magenta);
        //Vector3 newPos = newGizmoPos - Gizmo.mStartPos;

        /*
         * float scale = _snapSpacingTranslate;
         * float half = scale * 0.5f;
         *
         * if (newPos.x >= 0.0f) newPos.x += half; else newPos.x -= half;
         * if (newPos.y >= 0.0f) newPos.y += half; else newPos.y -= half;
         * if (newPos.z >= 0.0f) newPos.z += half; else newPos.z -= half;
         *
         * newPos.x = (int)((newPos.x) / scale) * scale;
         * newPos.y = (int)((newPos.y) / scale) * scale;
         * newPos.z = (int)((newPos.z) / scale) * scale;
         */

        if (Gizmo.mCornerID == -1)
        {
            p.mPosition += deltaPos;
        }
        else
        {
            Vector3 localPos;
            localPos.y = 0.0f;
            localPos.x = Vector3.Dot(p.mAxisX, deltaPos);
            localPos.z = Vector3.Dot(p.mAxisZ, deltaPos);
            p.mCorner[Gizmo.mCornerID].mPosition += localPos;
        }

        _ModifyAsset();
        mUI.ModifyVector3Editor(_primPosField, p.mPosition);
    }
示例#3
0
    public void PrimHandleMouseDown(ref SGizmoData Gizmo)
    {
        if (!Gizmo.mActedOnMouseDown)
        {
            Gizmo.mActedOnMouseDown = true;

            if (Gizmo.mGizmoHover == EGizmoHandleID.PRIMTIVE)
            {
                _OnClickPrimitive(Gizmo.mHoverID, true);
            }
            else if (Gizmo.mGizmoHover == EGizmoHandleID.NONE)
            {
                _OnClickPrimitive(-1, true);
            }
        }
    }
示例#4
0
    public void EdgePaintHandleMouseDown(ref SGizmoData Gizmo)
    {
        if (Gizmo.mGizmoHover != EGizmoHandleID.EDGE)
        {
            return;
        }

        if (!Gizmo.mActedOnMouseDown)
        {
            _OnClickPrimitive(-1, true);
            Gizmo.mActedOnMouseDown = true;
            CBrushAsset b = null;

            if (_edgeBrush != "(None)")
            {
                b = CGame.AssetManager.GetAsset <CBrushAsset>(_edgeBrush);
            }

            _vectorModel.mPlanes[Gizmo.mHoverID].mEdge[Gizmo.mCornerID].mBrush[(int)_viewDirection] = b;

            _ModifyAsset();
        }
    }
示例#5
0
    public void PrimHandleDraw(ref SGizmoData Gizmo)
    {
        if (_selectedPrimID != -1)
        {
            CModelPlane p = _vectorModel.mPlanes[_selectedPrimID];

            Vector3 o = p.mAxisY * 0.001f;

            CDebug.DrawLine(p.c1 - o, p.c2 - o, Color.green, false);
            CDebug.DrawLine(p.c2 - o, p.c3 - o, Color.green, false);
            CDebug.DrawLine(p.c3 - o, p.c4 - o, Color.green, false);
            CDebug.DrawLine(p.c4 - o, p.c1 - o, Color.green, false);
        }

        if (Gizmo.mGizmoHover == EGizmoHandleID.PRIMTIVE && Gizmo.mHoverID != _selectedPrimID)
        {
            CModelPlane p = _vectorModel.mPlanes[Gizmo.mHoverID];
            CDebug.DrawLine(p.c1, p.c2, Color.yellow, false);
            CDebug.DrawLine(p.c2, p.c3, Color.yellow, false);
            CDebug.DrawLine(p.c3, p.c4, Color.yellow, false);
            CDebug.DrawLine(p.c4, p.c1, Color.yellow, false);
        }
    }
示例#6
0
    public void TranslateHandleUpdate(Vector3 Origin, Vector3 Axis, Color DefaultColor, int CornerID, ref SGizmoData Gizmo)
    {
        float scale     = 1.0f;
        bool  hitHandle = false;
        Ray   R         = Gizmo.mStartMouseRay;

        if (Gizmo.mGizmoHover == EGizmoHandleID.NONE)
        {
            Bounds bounds = new Bounds(new Vector3(0.5f * scale, 0.0f, 0.0f), new Vector3(1.0f * scale, 0.2f * scale, 0.2f * scale));

            Vector3 up = Vector3.up;

            if (Axis == up)
            {
                up = Vector3.forward;
            }

            Vector3 axisX = Axis;
            Vector3 axisZ = Vector3.Cross(up, axisX).normalized;
            Vector3 axisY = Vector3.Cross(axisX, axisZ);

            //Vector3 o = new Vector3(0, 0, 0);
            //CDebug.DrawLine(o, o + axisX, Color.red);
            //CDebug.DrawLine(o, o + axisY, Color.green);
            //CDebug.DrawLine(o, o + axisZ, Color.blue);

            Vector3 rDir = R.direction;
            rDir.x      = Vector3.Dot(R.direction, axisX);
            rDir.y      = Vector3.Dot(R.direction, axisY);
            rDir.z      = Vector3.Dot(R.direction, axisZ);
            R.direction = rDir;

            R.origin -= Origin;
            Vector4 rO = R.origin;
            rO.x     = Vector3.Dot(R.origin, axisX);
            rO.y     = Vector3.Dot(R.origin, axisY);
            rO.z     = Vector3.Dot(R.origin, axisZ);
            R.origin = rO;

            if (bounds.IntersectRay(R))
            {
                Gizmo.mGizmoHover = EGizmoHandleID.TRANSLATE;
                Gizmo.mHoverID    = _selectedPrimID;
                Gizmo.mAxis       = Axis;
                Gizmo.mCornerID   = CornerID;
                Gizmo.mOrigin     = Origin;
                hitHandle         = true;
            }
        }

        if (hitHandle)
        {
            CDebug.DrawLine(Origin, Origin + Axis * scale, Color.yellow, false);
        }
        else
        {
            CDebug.DrawLine(Origin, Origin + Axis * scale, DefaultColor, false);
        }
    }
示例#7
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);
            }
        }
    }