12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "platform/platform.h"
- #include "gui/worldEditor/editTSCtrl.h"
- #include "console/consoleTypes.h"
- #include "console/engineAPI.h"
- #include "T3D/gameBase/gameConnection.h"
- #include "gui/worldEditor/editor.h"
- #include "gui/core/guiCanvas.h"
- #include "terrain/terrData.h"
- #include "T3D/missionArea.h"
- #include "gfx/primBuilder.h"
- #include "gfx/gfxDrawUtil.h"
- #include "gfx/gfxTransformSaver.h"
- #include "gfx/gfxDebugEvent.h"
- #include "scene/sceneManager.h"
- #include "scene/sceneRenderState.h"
- #include "renderInstance/renderBinManager.h"
- #include "T3D/Scene.h"
- IMPLEMENT_CONOBJECT(EditTSCtrl);
- ConsoleDocClass( EditTSCtrl,
- "@brief 3D view control used specifically by Torque 3D's editors.\n\n"
- "For Torque 3D editors only, not for actual game development\n\n"
- "@ingroup Editors\n"
- "@internal"
- );
- Point3F EditTSCtrl::smCamPos;
- MatrixF EditTSCtrl::smCamMatrix;
- bool EditTSCtrl::smCamOrtho = false;
- F32 EditTSCtrl::smCamNearPlane;
- F32 EditTSCtrl::smCamFOV = 75.0f;
- F32 EditTSCtrl::smVisibleDistanceScale = 1.0f;
- U32 EditTSCtrl::smSceneBoundsMask = EnvironmentObjectType | TerrainObjectType | WaterObjectType | CameraObjectType;
- Point3F EditTSCtrl::smMinSceneBounds = Point3F(500.0f, 500.0f, 500.0f);
- EditTSCtrl::EditTSCtrl()
- {
- mGizmoProfile = NULL;
- mGizmo = NULL;
- mRenderMissionArea = true;
- mMissionAreaFillColor.set(255,0,0,20);
- mMissionAreaFrameColor.set(255,0,0,128);
- mMissionAreaHeightAdjust = 5.0f;
- mConsoleFrameColor.set(255,0,0,255);
- mConsoleFillColor.set(255,0,0,120);
- mConsoleSphereLevel = 1;
- mConsoleCircleSegments = 32;
- mConsoleLineWidth = 1;
- mRightMousePassThru = true;
- mMiddleMousePassThru = true;
- mConsoleRendering = false;
- mDisplayType = DisplayTypePerspective;
- mOrthoFOV = 50.0f;
- mOrthoCamTrans.set(0.0f, 0.0f, 0.0f);
- mIsoCamAngle = mDegToRad(45.0f);
- mIsoCamRot = EulerF(0, 0, 0);
- mRenderGridPlane = true;
- mGridPlaneOriginColor = ColorI(255, 255, 255, 100);
- mGridPlaneColor = ColorI(102, 102, 102, 100);
- mGridPlaneMinorTickColor = ColorI(51, 51, 51, 100);
- mGridPlaneMinorTicks = 9;
- mGridPlaneSize = 1.0f;
- mGridPlaneSizePixelBias = 10.0f;
- mLastMousePos.set(0, 0);
- mAllowBorderMove = false;
- mMouseMoveBorder = 20;
- mMouseMoveSpeed = 0.1f;
- mLastBorderMoveTime = 0;
- mLeftMouseDown = false;
- mRightMouseDown = false;
- mMiddleMouseDown = false;
- mMiddleMouseTriggered = false;
- mMouseLeft = false;
- mLastMouseClamping = false;
- mBlendSB = NULL;
- }
- EditTSCtrl::~EditTSCtrl()
- {
- mBlendSB = NULL;
- }
- //------------------------------------------------------------------------------
- bool EditTSCtrl::onAdd()
- {
- if(!Parent::onAdd())
- return(false);
- // give all derived access to the fields
- setModStaticFields(true);
- GFXStateBlockDesc blenddesc;
- blenddesc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
- mBlendSB = GFX->createStateBlock( blenddesc );
- if ( !mGizmoProfile )
- {
- Con::errorf( "EditTSCtrl::onadd - gizmoProfile was not assigned, cannot create control!" );
- return false;
- }
- mGizmo = new Gizmo();
- mGizmo->setProfile( mGizmoProfile );
- mGizmo->registerObject();
- return true;
- }
- void EditTSCtrl::onRemove()
- {
- Parent::onRemove();
- if ( mGizmo )
- mGizmo->deleteObject();
- }
- void EditTSCtrl::onRender(Point2I offset, const RectI &updateRect)
- {
- // Perform possible mouse border move...
- if(mAllowBorderMove && smCamOrtho && !mLeftMouseDown && !mRightMouseDown && !mMouseLeft)
- {
- Point2I ext = getExtent();
- U32 current = Platform::getRealMilliseconds();
- bool update = false;
- F32 movex = 0.0f;
- F32 movey = 0.0f;
- Point2I localMouse = globalToLocalCoord(mLastMousePos);
- if(localMouse.x <= mMouseMoveBorder || localMouse.x >= ext.x - mMouseMoveBorder)
- {
- if(mLastBorderMoveTime != 0)
- {
- U32 dt = current - mLastBorderMoveTime;
- if(localMouse.x <= mMouseMoveBorder)
- {
- movex = mMouseMoveSpeed * dt;
- }
- else
- {
- movex = -mMouseMoveSpeed * dt;
- }
- }
- update = true;
- }
- if(localMouse.y <= mMouseMoveBorder || localMouse.y >= ext.y - mMouseMoveBorder)
- {
- if(mLastBorderMoveTime != 0)
- {
- U32 dt = current - mLastBorderMoveTime;
- if(localMouse.y <= mMouseMoveBorder)
- {
- movey = mMouseMoveSpeed * dt;
- }
- else
- {
- movey = -mMouseMoveSpeed * dt;
- }
- }
- update = true;
- }
- if(update)
- {
- mLastBorderMoveTime = current;
- calcOrthoCamOffset(movex, movey);
- }
- else
- {
- mLastBorderMoveTime = 0;
- }
- }
- updateGuiInfo();
- Parent::onRender(offset, updateRect);
- }
- //------------------------------------------------------------------------------
- void EditTSCtrl::initPersistFields()
- {
- addGroup( "Grid" );
-
- addField( "gridSize", TypeF32, Offset( mGridPlaneSize, EditTSCtrl ) );
- addField( "gridColor", TypeColorI, Offset( mGridPlaneColor, EditTSCtrl ) );
- addField( "gridOriginColor", TypeColorI, Offset( mGridPlaneOriginColor, EditTSCtrl ) );
- addField( "gridMinorTickColor", TypeColorI, Offset( mGridPlaneMinorTickColor, EditTSCtrl ) );
- addField( "renderOrthoGrid", TypeBool, Offset( mRenderGridPlane, EditTSCtrl ),
- "Whether to render the grid in orthographic axial projections." );
- addField( "renderOrthoGridPixelBias", TypeF32, Offset( mGridPlaneSizePixelBias, EditTSCtrl ),
- "Grid patch pixel size below which to switch to coarser grid resolutions." );
-
- endGroup( "Grid" );
-
- addGroup("Mission Area");
-
- addField("renderMissionArea", TypeBool, Offset(mRenderMissionArea, EditTSCtrl));
- addField("missionAreaFillColor", TypeColorI, Offset(mMissionAreaFillColor, EditTSCtrl));
- addField("missionAreaFrameColor", TypeColorI, Offset(mMissionAreaFrameColor, EditTSCtrl));
- addField("missionAreaHeightAdjust", TypeF32, Offset(mMissionAreaHeightAdjust, EditTSCtrl),
- "How high above and below the terrain to render the mission area bounds." );
-
- endGroup("Mission Area");
- addGroup("BorderMovement");
-
- addField("allowBorderMove", TypeBool, Offset(mAllowBorderMove, EditTSCtrl));
- addField("borderMovePixelSize", TypeS32, Offset(mMouseMoveBorder, EditTSCtrl));
- addField("borderMoveSpeed", TypeF32, Offset(mMouseMoveSpeed, EditTSCtrl));
-
- endGroup("BorderMovement");
- addGroup("Misc");
-
- addField("consoleFrameColor", TypeColorI, Offset(mConsoleFrameColor, EditTSCtrl));
- addField("consoleFillColor", TypeColorI, Offset(mConsoleFillColor, EditTSCtrl));
- addField("consoleSphereLevel", TypeS32, Offset(mConsoleSphereLevel, EditTSCtrl));
- addField("consoleCircleSegments", TypeS32, Offset(mConsoleCircleSegments, EditTSCtrl));
- addField("consoleLineWidth", TypeS32, Offset(mConsoleLineWidth, EditTSCtrl));
- addField("gizmoProfile", TYPEID< GizmoProfile >(), Offset(mGizmoProfile, EditTSCtrl));
-
- endGroup("Misc");
-
- Parent::initPersistFields();
- }
- void EditTSCtrl::consoleInit()
- {
- Con::addVariable("pref::WorldEditor::visibleDistanceScale", TypeF32, &EditTSCtrl::smVisibleDistanceScale, "Scale factor for the visible render distance.\n"
- "@ingroup ");
-
- Con::addVariable("pref::WorldEditor::cameraFOV", TypeF32, &EditTSCtrl::smCamFOV, "Field of view for editor's perspective camera, in degrees.\n"
- "@ingroup ");
-
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeTop", DisplayTypeTop);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeBottom", DisplayTypeBottom);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeFront", DisplayTypeFront);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeBack", DisplayTypeBack);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeLeft", DisplayTypeLeft);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeRight", DisplayTypeRight);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypePerspective", DisplayTypePerspective);
- Con::setIntVariable( "$EditTsCtrl::DisplayTypeIsometric", DisplayTypeIsometric);
- }
- //------------------------------------------------------------------------------
- bool EditTSCtrl::resize(const Point2I& newPosition, const Point2I& newExtent)
- {
- if (!Parent::resize(newPosition, newExtent))
- return false;
- // Notify the scripts
- if (isMethod("onResize"))
- Con::executef(this, "onResize", newPosition, newExtent);
- return true;
- }
- //------------------------------------------------------------------------------
- void EditTSCtrl::make3DMouseEvent(Gui3DMouseEvent & gui3DMouseEvent, const GuiEvent & event)
- {
- (GuiEvent&)(gui3DMouseEvent) = event;
- gui3DMouseEvent.mousePoint = event.mousePoint;
- if(!smCamOrtho)
- {
- // get the eye pos and the mouse vec from that...
- Point3F screenPoint((F32)gui3DMouseEvent.mousePoint.x, (F32)gui3DMouseEvent.mousePoint.y, 1.0f);
- Point3F wp;
- unproject(screenPoint, &wp);
- gui3DMouseEvent.pos = smCamPos;
- gui3DMouseEvent.vec = wp - smCamPos;
- gui3DMouseEvent.vec.normalizeSafe();
- }
- else
- {
- // get the eye pos and the mouse vec from that...
- Point3F screenPoint((F32)gui3DMouseEvent.mousePoint.x, (F32)gui3DMouseEvent.mousePoint.y, 0.0f);
- Point3F np, fp;
- unproject(screenPoint, &np);
- gui3DMouseEvent.pos = np;
- smCamMatrix.getColumn( 1, &(gui3DMouseEvent.vec) );
- }
- }
- //------------------------------------------------------------------------------
- TerrainBlock* EditTSCtrl::getActiveTerrain()
- {
- // Find a terrain block
- SimSet* scopeAlwaysSet = Sim::getGhostAlwaysSet();
- for(SimSet::iterator itr = scopeAlwaysSet->begin(); itr != scopeAlwaysSet->end(); itr++)
- {
- TerrainBlock* block = dynamic_cast<TerrainBlock*>(*itr);
- if( block )
- return block;
- }
- return NULL;
- }
- //------------------------------------------------------------------------------
- void EditTSCtrl::setDisplayType( S32 type )
- {
- mDisplayType = type;
-
- // Disable middle-mouse pass-thru in ortho views so we can
- // use the middle mouse button for navigation.
- mMiddleMousePassThru = !isOrthoDisplayType();
-
- if( mGizmo )
- {
- // Disable gizmo's grid plane in the isometric views since
- // they will render with the grid from EditTSCtrl. Also disable
- // the move grid as it doesn't make sense in ortho views.
-
- if( type != DisplayTypePerspective )
- {
- mGizmo->setGridPlaneEnabled( false );
- mGizmo->setMoveGridEnabled( false );
- }
- else
- {
- mGizmo->setGridPlaneEnabled( true );
- mGizmo->setMoveGridEnabled( true );
- }
- }
- }
- //------------------------------------------------------------------------------
- void EditTSCtrl::getCursor(GuiCursor *&cursor, bool &visible, const GuiEvent &event)
- {
- make3DMouseEvent(mLastEvent, event);
- get3DCursor(cursor, visible, mLastEvent);
- }
- void EditTSCtrl::get3DCursor(GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event)
- {
- TORQUE_UNUSED(event);
- cursor = NULL;
- visible = false;
- }
- void EditTSCtrl::onMouseUp(const GuiEvent & event)
- {
- mLeftMouseDown = false;
- make3DMouseEvent(mLastEvent, event);
- on3DMouseUp(mLastEvent);
- }
- void EditTSCtrl::onMouseDown(const GuiEvent & event)
- {
- mLeftMouseDown = true;
- mLastBorderMoveTime = 0;
- make3DMouseEvent(mLastEvent, event);
- on3DMouseDown(mLastEvent);
-
- setFirstResponder();
- }
- void EditTSCtrl::onMouseMove(const GuiEvent & event)
- {
- make3DMouseEvent(mLastEvent, event);
- on3DMouseMove(mLastEvent);
- mLastMousePos = event.mousePoint;
- }
- void EditTSCtrl::onMouseDragged(const GuiEvent & event)
- {
- make3DMouseEvent(mLastEvent, event);
- on3DMouseDragged(mLastEvent);
- }
- void EditTSCtrl::onMouseEnter(const GuiEvent & event)
- {
- mMouseLeft = false;
- make3DMouseEvent(mLastEvent, event);
- on3DMouseEnter(mLastEvent);
- }
- void EditTSCtrl::onMouseLeave(const GuiEvent & event)
- {
- mMouseLeft = true;
- mLastBorderMoveTime = 0;
- make3DMouseEvent(mLastEvent, event);
- on3DMouseLeave(mLastEvent);
- }
- void EditTSCtrl::onRightMouseDown(const GuiEvent & event)
- {
- // always process the right mouse event first...
- mRightMouseDown = true;
- mLastBorderMoveTime = 0;
- make3DMouseEvent(mLastEvent, event);
- on3DRightMouseDown(mLastEvent);
- if(!mLeftMouseDown && mRightMousePassThru && mProfile->mCanKeyFocus)
- {
- GuiCanvas *pCanvas = getRoot();
- if( !pCanvas )
- return;
- PlatformWindow *pWindow = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow();
- if( !pWindow )
- return;
- PlatformCursorController *pController = pWindow->getCursorController();
- if( !pController )
- return;
- // ok, gotta disable the mouse
- // script functions are lockMouse(true); Canvas.cursorOff();
- pWindow->setMouseLocked(true);
- pCanvas->setCursorON( false );
- if(mDisplayType != DisplayTypePerspective)
- {
- mouseLock();
- mLastMousePos = event.mousePoint;
- pCanvas->setForceMouseToGUI(true);
- mLastMouseClamping = pCanvas->getClampTorqueCursor();
- pCanvas->setClampTorqueCursor(false);
- }
- if(mDisplayType == DisplayTypeIsometric)
- {
- // Store the screen center point on the terrain for a possible rotation
- TerrainBlock* activeTerrain = getActiveTerrain();
- if( activeTerrain )
- {
- F32 extx, exty;
- if(event.modifier & SI_SHIFT)
- {
- extx = F32(event.mousePoint.x);
- exty = F32(event.mousePoint.y);
- }
- else
- {
- extx = getExtent().x * 0.5;
- exty = getExtent().y * 0.5;
- }
- Point3F sp(extx, exty, 0.0f); // Near plane projection
- Point3F start;
- unproject(sp, &start);
- Point3F end = start + mLastEvent.vec * 4000.0f;
- Point3F tStartPnt, tEndPnt;
- activeTerrain->getTransform().mulP(start, &tStartPnt);
- activeTerrain->getTransform().mulP(end, &tEndPnt);
- RayInfo info;
- bool result = activeTerrain->castRay(tStartPnt, tEndPnt, &info);
- if(result)
- {
- info.point.interpolate(start, end, info.t);
- mIsoCamRotCenter = info.point;
- }
- else
- {
- mIsoCamRotCenter = start;
- }
- }
- else
- {
- F32 extx = getExtent().x * 0.5;
- F32 exty = getExtent().y * 0.5;
- Point3F sp(extx, exty, 0.0f); // Near plane projection
- unproject(sp, &mIsoCamRotCenter);
- }
- }
- setFirstResponder();
- }
- }
- void EditTSCtrl::onRightMouseUp(const GuiEvent & event)
- {
- mRightMouseDown = false;
- make3DMouseEvent(mLastEvent, event);
- on3DRightMouseUp(mLastEvent);
- }
- void EditTSCtrl::onRightMouseDragged(const GuiEvent & event)
- {
- make3DMouseEvent(mLastEvent, event);
- on3DRightMouseDragged(mLastEvent);
- // Handle zoom of orthographic views.
-
- if( isOrthoDisplayType() )
- {
- orthoZoom( ( event.mousePoint.y - mLastMousePos.y ) * 0.5f );
- mLastMousePos = event.mousePoint;
- }
- }
- void EditTSCtrl::onMiddleMouseDown(const GuiEvent & event)
- {
- mMiddleMouseDown = true;
- mMiddleMouseTriggered = false;
- mLastBorderMoveTime = 0;
- if(!mLeftMouseDown && !mRightMouseDown && mMiddleMousePassThru && mProfile->mCanKeyFocus)
- {
- GuiCanvas *pCanvas = getRoot();
- if( !pCanvas )
- return;
- PlatformWindow *pWindow = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow();
- if( !pWindow )
- return;
- PlatformCursorController *pController = pWindow->getCursorController();
- if( !pController )
- return;
- // ok, gotta disable the mouse
- // script functions are lockMouse(true); Canvas.cursorOff();
- pWindow->setMouseLocked(true);
- pCanvas->setCursorON( false );
- // Trigger 2 is used by the camera
- MoveManager::mTriggerCount[2]++;
- mMiddleMouseTriggered = true;
- setFirstResponder();
- }
- }
- void EditTSCtrl::onMiddleMouseUp(const GuiEvent & event)
- {
- // Trigger 2 is used by the camera
- if( mMiddleMouseTriggered )
- {
- MoveManager::mTriggerCount[2]++;
- mMiddleMouseTriggered = false;
- }
- mMiddleMouseDown = false;
- }
- void EditTSCtrl::onMiddleMouseDragged(const GuiEvent & event)
- {
- // Handle translation of orthographic views.
-
- if( isOrthoDisplayType() )
- {
- calcOrthoCamOffset((event.mousePoint.x - mLastMousePos.x), (event.mousePoint.y - mLastMousePos.y), event.modifier);
- mLastMousePos = event.mousePoint;
- }
- }
- bool EditTSCtrl::onMouseWheelUp( const GuiEvent &event )
- {
- // Looks like this should be zooming based on a factor of the GuiEvent.fval
- if( isOrthoDisplayType() && !event.modifier )
- {
- orthoZoom( -2.f );
- return true;
- }
- make3DMouseEvent(mLastEvent, event);
- on3DMouseWheelUp(mLastEvent);
- return false;
- }
- bool EditTSCtrl::onMouseWheelDown( const GuiEvent &event )
- {
- // Looks like this should be zooming based on a factor of the GuiEvent.fval
- if(mDisplayType != DisplayTypePerspective && !event.modifier)
- {
- orthoZoom( 2.f );
- return true;
- }
- make3DMouseEvent(mLastEvent, event);
- on3DMouseWheelDown(mLastEvent);
- return false;
- }
- bool EditTSCtrl::onInputEvent(const InputEventInfo & event)
- {
- if(mRightMousePassThru && event.deviceType == MouseDeviceType &&
- event.objInst == KEY_BUTTON1 && event.action == SI_BREAK)
- {
- // if the right mouse pass thru is enabled,
- // we want to reactivate mouse on a right mouse button up
- GuiCanvas *pCanvas = getRoot();
- if( !pCanvas )
- return false;
- PlatformWindow *pWindow = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow();
- if( !pWindow )
- return false;
- PlatformCursorController *pController = pWindow->getCursorController();
- if( !pController )
- return false;
- pWindow->setMouseLocked(false);
- pCanvas->setCursorON( true );
- if(mDisplayType != DisplayTypePerspective)
- {
- mouseUnlock();
- pCanvas->setForceMouseToGUI(false);
- pCanvas->setClampTorqueCursor(mLastMouseClamping);
- }
- }
- if(mMiddleMousePassThru && event.deviceType == MouseDeviceType &&
- event.objInst == KEY_BUTTON2 && event.action == SI_BREAK)
- {
- // if the middle mouse pass thru is enabled,
- // we want to reactivate mouse on a middle mouse button up
- GuiCanvas *pCanvas = getRoot();
- if( !pCanvas )
- return false;
- PlatformWindow *pWindow = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow();
- if( !pWindow )
- return false;
- PlatformCursorController *pController = pWindow->getCursorController();
- if( !pController )
- return false;
- pWindow->setMouseLocked(false);
- pCanvas->setCursorON( true );
- }
- // we return false so that the canvas can properly process the right mouse button up...
- return false;
- }
- //------------------------------------------------------------------------------
- void EditTSCtrl::orthoZoom( F32 steps )
- {
- //TODO: this really should be proportional
-
- mOrthoFOV += steps;
- if( mOrthoFOV < 1.0f )
- mOrthoFOV = 1.0f;
- }
- void EditTSCtrl::calcOrthoCamOffset(F32 mousex, F32 mousey, U8 modifier)
- {
- F32 camScale = 0.01f;
- switch(mDisplayType)
- {
- case DisplayTypeTop:
- mOrthoCamTrans.x -= mousex * mOrthoFOV * camScale;
- mOrthoCamTrans.y += mousey * mOrthoFOV * camScale;
- break;
- case DisplayTypeBottom:
- mOrthoCamTrans.x -= mousex * mOrthoFOV * camScale;
- mOrthoCamTrans.y -= mousey * mOrthoFOV * camScale;
- break;
- case DisplayTypeFront:
- mOrthoCamTrans.x -= mousex * mOrthoFOV * camScale;
- mOrthoCamTrans.z += mousey * mOrthoFOV * camScale;
- break;
- case DisplayTypeBack:
- mOrthoCamTrans.x += mousex * mOrthoFOV * camScale;
- mOrthoCamTrans.z += mousey * mOrthoFOV * camScale;
- break;
- case DisplayTypeLeft:
- mOrthoCamTrans.y += mousex * mOrthoFOV * camScale;
- mOrthoCamTrans.z += mousey * mOrthoFOV * camScale;
- break;
- case DisplayTypeRight:
- mOrthoCamTrans.y -= mousex * mOrthoFOV * camScale;
- mOrthoCamTrans.z += mousey * mOrthoFOV * camScale;
- break;
- case DisplayTypeIsometric:
- if(modifier & SI_PRIMARY_CTRL)
- {
- // NOTE: Maybe move the center of rotation code to right mouse down to avoid compound errors?
- F32 rot = mDegToRad(mousex);
- Point3F campos = (mRawCamPos + mOrthoCamTrans) - mIsoCamRotCenter;
- MatrixF mat(EulerF(0, 0, rot));
- mat.mulP(campos);
- mOrthoCamTrans = (campos + mIsoCamRotCenter) - mRawCamPos;
- mIsoCamRot.z += rot;
- }
- else
- {
- mOrthoCamTrans.x -= mousex * mOrthoFOV * camScale * mCos(mIsoCamRot.z) - mousey * mOrthoFOV * camScale * mSin(mIsoCamRot.z);
- mOrthoCamTrans.y += mousex * mOrthoFOV * camScale * mSin(mIsoCamRot.z) + mousey * mOrthoFOV * camScale * mCos(mIsoCamRot.z);
- }
- break;
- }
- }
- void EditTSCtrl::updateGizmo()
- {
- mGizmoProfile->restoreDefaultState();
- }
- //------------------------------------------------------------------------------
- void EditTSCtrl::renderWorld(const RectI & updateRect)
- {
- // Make sure that whatever the editor does, it doesn't
- // dirty the GFX transform state.
- GFXTransformSaver saver;
- updateGizmo();
- gClientSceneGraph->setDisplayTargetResolution(getExtent());
- // Use a render instance to do editor 3D scene
- // rendering after HDR is processed and while the depth
- // buffer is still intact.
- RenderPassManager *rpm = gClientSceneGraph->getDefaultRenderPass();
- ObjectRenderInst *inst = rpm->allocInst<ObjectRenderInst>();
- inst->type = RenderPassManager::RIT_Editor;
- inst->renderDelegate.bind(this, &EditTSCtrl::_renderScene);
- rpm->addInst(inst);
- if( mDisplayType == DisplayTypePerspective )
- gClientSceneGraph->renderScene( SPT_Diffuse );
- else
- {
- // If we are in an orthographic mode, do a special render
- // with AL, fog, and PostFX disabled.
- FogData savedFogData = gClientSceneGraph->getFogData();
- gClientSceneGraph->setFogData( FogData() );
- SceneRenderState renderState
- (
- gClientSceneGraph,
- SPT_Diffuse
- );
- gClientSceneGraph->renderScene( &renderState );
- gClientSceneGraph->setFogData( savedFogData );
- }
- }
- void EditTSCtrl::_renderScene( ObjectRenderInst*, SceneRenderState *state, BaseMatInstance* )
- {
- GFXTransformSaver saver;
- // render through console callbacks
- Scene* scene = Scene::getRootScene();
- if(scene)
- {
- mConsoleRendering = true;
- // [ rene, 27-Jan-10 ] This calls onEditorRender on the server objects instead
- // of on the client objects which seems a bit questionable to me.
-
- for(SimSetIterator itr(scene); *itr; ++itr)
- {
- SceneObject* object = dynamic_cast< SceneObject* >( *itr );
- if( object && object->isRenderEnabled() && !object->isHidden() )
- {
- char buf[2][16];
- dSprintf(buf[0], 16, object->isSelected() ? "true" : "false");
- dSprintf(buf[1], 16, object->isExpanded() ? "true" : "false");
-
- Con::executef( object, "onEditorRender", getIdString(), buf[0], buf[1] );
- }
- }
- mConsoleRendering = false;
- }
- // render the mission area...
- renderMissionArea();
- // Draw the grid
- if ( mRenderGridPlane )
- renderGrid();
- // render the editor stuff
- renderScene(mSaveViewport);
- // Draw the camera axis
- GFX->setClipRect(mSaveViewport);
- GFX->setStateBlock(mDefaultGuiSB);
- renderCameraAxis();
- }
- void EditTSCtrl::renderMissionArea()
- {
- MissionArea* obj = MissionArea::getServerObject();
- if ( !obj )
- return;
- if ( !mRenderMissionArea && !obj->isSelected() )
- return;
- GFXDEBUGEVENT_SCOPE( Editor_renderMissionArea, ColorI::WHITE );
- F32 minHeight = 0.0f;
- F32 maxHeight = 0.0f;
- TerrainBlock* terrain = getActiveTerrain();
- if ( terrain )
- {
- terrain->getMinMaxHeight( &minHeight, &maxHeight );
- Point3F pos = terrain->getPosition();
- maxHeight += pos.z + mMissionAreaHeightAdjust;
- minHeight += pos.z - mMissionAreaHeightAdjust;
- }
- const RectI& area = obj->getArea();
- Box3F areaBox( area.point.x,
- area.point.y,
- minHeight,
- area.point.x + area.extent.x,
- area.point.y + area.extent.y,
- maxHeight );
- GFXDrawUtil* drawer = GFX->getDrawUtil();
- GFXStateBlockDesc desc;
- desc.setCullMode( GFXCullNone );
- desc.setBlend( true );
- desc.setZReadWrite( false, false );
- desc.setFillModeSolid();
- drawer->drawCube( desc, areaBox, mMissionAreaFillColor );
- desc.setFillModeWireframe();
- drawer->drawCube( desc, areaBox, mMissionAreaFrameColor );
- }
- void EditTSCtrl::renderCameraAxis()
- {
- GFXDEBUGEVENT_SCOPE( Editor_renderCameraAxis, ColorI::WHITE );
- static MatrixF sRotMat(EulerF( (M_PI_F / -2.0f), 0.0f, 0.0f));
- MatrixF camMat = mLastCameraQuery.cameraMatrix;
- camMat.mul(sRotMat);
- camMat.inverse();
- MatrixF axis;
- axis.setColumn(0, Point3F(1, 0, 0));
- axis.setColumn(1, Point3F(0, 0, 1));
- axis.setColumn(2, Point3F(0, -1, 0));
- axis.mul(camMat);
- Point3F forwardVec, upVec, rightVec;
- axis.getColumn( 2, &forwardVec );
- axis.getColumn( 1, &upVec );
- axis.getColumn( 0, &rightVec );
- Point2I pos = getPosition();
- F32 offsetx = pos.x + 20.0;
- F32 offsety = pos.y + getExtent().y - 42.0; // Take the status bar into account
- F32 scale = 15.0;
- // Generate correct drawing order
- ColorI c1(255,0,0);
- ColorI c2(0,255,0);
- ColorI c3(0,0,255);
- ColorI tc;
- Point3F *p1, *p2, *p3, *tp;
- p1 = &rightVec;
- p2 = &upVec;
- p3 = &forwardVec;
- if(p3->y > p2->y)
- {
- tp = p2; tc = c2;
- p2 = p3; c2 = c3;
- p3 = tp; c3 = tc;
- }
- if(p2->y > p1->y)
- {
- tp = p1; tc = c1;
- p1 = p2; c1 = c2;
- p2 = tp; c2 = tc;
- }
- PrimBuild::begin( GFXLineList, 6 );
- //*** Axis 1
- PrimBuild::color(c1);
- PrimBuild::vertex3f(offsetx, offsety, 0);
- PrimBuild::vertex3f(offsetx+p1->x*scale, offsety-p1->z*scale, 0);
- //*** Axis 2
- PrimBuild::color(c2);
- PrimBuild::vertex3f(offsetx, offsety, 0);
- PrimBuild::vertex3f(offsetx+p2->x*scale, offsety-p2->z*scale, 0);
- //*** Axis 3
- PrimBuild::color(c3);
- PrimBuild::vertex3f(offsetx, offsety, 0);
- PrimBuild::vertex3f(offsetx+p3->x*scale, offsety-p3->z*scale, 0);
- PrimBuild::end();
- }
- void EditTSCtrl::renderGrid()
- {
- if( !isOrthoDisplayType() )
- return;
- GFXDEBUGEVENT_SCOPE( Editor_renderGrid, ColorI::WHITE );
- // Calculate the displayed grid size based on view
- F32 drawnGridSize = mGridPlaneSize;
- F32 gridPixelSize = projectRadius(1.0f, mGridPlaneSize);
- if(gridPixelSize < mGridPlaneSizePixelBias)
- {
- U32 counter = 1;
- while(gridPixelSize < mGridPlaneSizePixelBias)
- {
- drawnGridSize = mGridPlaneSize * counter * 10.0f;
- gridPixelSize = projectRadius(1.0f, drawnGridSize);
- ++counter;
- // No infinite loops here
- if(counter > 1000)
- break;
- }
- }
- F32 minorTickSize = 0;
- F32 gridSize = drawnGridSize;
- U32 minorTickMax = mGridPlaneMinorTicks + 1;
- if(minorTickMax > 0)
- {
- minorTickSize = drawnGridSize;
- gridSize = drawnGridSize * minorTickMax;
- }
- // Build the view-based origin
- VectorF dir;
- smCamMatrix.getColumn( 1, &dir );
- Point3F gridPlanePos = smCamPos + dir;
- Point2F size(mOrthoWidth + 2 * gridSize, mOrthoHeight + 2 * gridSize);
- GFXStateBlockDesc desc;
- desc.setBlend( true );
- desc.setZReadWrite( true, false );
- GFXDrawUtil::Plane plane = GFXDrawUtil::PlaneXY;
- switch( getDisplayType() )
- {
- case DisplayTypeTop:
- case DisplayTypeBottom:
- plane = GFXDrawUtil::PlaneXY;
- break;
- case DisplayTypeLeft:
- case DisplayTypeRight:
- plane = GFXDrawUtil::PlaneYZ;
- break;
- case DisplayTypeFront:
- case DisplayTypeBack:
- plane = GFXDrawUtil::PlaneXZ;
- break;
-
- default:
- break;
- }
- GFX->getDrawUtil()->drawPlaneGrid( desc, gridPlanePos, size, Point2F( minorTickSize, minorTickSize ), mGridPlaneMinorTickColor, plane );
- GFX->getDrawUtil()->drawPlaneGrid( desc, gridPlanePos, size, Point2F( gridSize, gridSize ), mGridPlaneColor, plane );
- }
- static void sceneBoundsCalcCallback(SceneObject* obj, void *key)
- {
- // Early out for those objects that slipped through the mask check
- // because they belong to more than one type.
- if((obj->getTypeMask() & EditTSCtrl::smSceneBoundsMask) != 0)
- return;
- if(obj->isGlobalBounds())
- return;
- Box3F* bounds = (Box3F*)key;
- Point3F min = obj->getWorldBox().minExtents;
- Point3F max = obj->getWorldBox().maxExtents;
- #if 0 // Console messages in render loop lead to massive spam.
- if (min.x <= -5000.0f || min.y <= -5000.0f || min.z <= -5000.0f ||
- min.x >= 5000.0f || min.y >= 5000.0f || min.z >= 5000.0f)
- Con::errorf("SceneObject %d (%s : %s) has a bounds that could cause problems with a non-perspective view", obj->getId(), obj->getClassName(), obj->getName());
- #endif
- bounds->minExtents.setMin(min);
- bounds->minExtents.setMin(max);
- bounds->maxExtents.setMax(min);
- bounds->maxExtents.setMax(max);
- }
- bool EditTSCtrl::getCameraTransform(MatrixF* cameraMatrix)
- {
- GameConnection* connection = dynamic_cast<GameConnection *>(NetConnection::getConnectionToServer());
- return (connection && connection->getControlCameraTransform(0.032f, cameraMatrix));
- }
- void EditTSCtrl::computeSceneBounds(Box3F& bounds)
- {
- bounds.minExtents.set(1e10, 1e10, 1e10);
- bounds.maxExtents.set(-1e10, -1e10, -1e10);
- // Calculate the scene bounds
- gClientContainer.findObjects(~(smSceneBoundsMask), sceneBoundsCalcCallback, &bounds);
- }
- bool EditTSCtrl::processCameraQuery(CameraQuery * query)
- {
- if(mDisplayType == DisplayTypePerspective)
- {
- query->ortho = false;
- }
- else
- {
- query->ortho = true;
- }
- if (getCameraTransform(&query->cameraMatrix))
- {
- query->farPlane = gClientSceneGraph->getVisibleDistance() * smVisibleDistanceScale;
- query->nearPlane = gClientSceneGraph->getNearClip();
- query->fov = mDegToRad(smCamFOV);
- if(query->ortho)
- {
- MatrixF camRot(true);
- const F32 camBuffer = 1.0f;
- Point3F camPos = query->cameraMatrix.getPosition();
- F32 isocamplanedist = 0.0f;
- if(mDisplayType == DisplayTypeIsometric)
- {
- const RectI& vp = GFX->getViewport();
- isocamplanedist = 0.25 * vp.extent.y * mSin(mIsoCamAngle);
- }
- // Calculate the scene bounds
- Box3F sceneBounds;
- computeSceneBounds(sceneBounds);
- if(!sceneBounds.isValidBox())
- {
- sceneBounds.maxExtents = camPos + smMinSceneBounds;
- sceneBounds.minExtents = camPos - smMinSceneBounds;
- }
- else
- {
- query->farPlane = getMax(smMinSceneBounds.x * 2.0f, (sceneBounds.maxExtents - sceneBounds.minExtents).len() + camBuffer * 2.0f + isocamplanedist);
- }
- mRawCamPos = camPos;
- camPos += mOrthoCamTrans;
- switch(mDisplayType)
- {
- case DisplayTypeTop:
- camRot.setColumn(0, Point3F(1.0, 0.0, 0.0));
- camRot.setColumn(1, Point3F(0.0, 0.0, -1.0));
- camRot.setColumn(2, Point3F(0.0, 1.0, 0.0));
- camPos.z = getMax(camPos.z + smMinSceneBounds.z, sceneBounds.maxExtents.z + camBuffer);
- break;
- case DisplayTypeBottom:
- camRot.setColumn(0, Point3F(1.0, 0.0, 0.0));
- camRot.setColumn(1, Point3F(0.0, 0.0, 1.0));
- camRot.setColumn(2, Point3F(0.0, -1.0, 0.0));
- camPos.z = getMin(camPos.z - smMinSceneBounds.z, sceneBounds.minExtents.z - camBuffer);
- break;
- case DisplayTypeFront:
- camRot.setColumn(0, Point3F(1.0, 0.0, 0.0));
- camRot.setColumn(1, Point3F(0.0, 1.0, 0.0));
- camRot.setColumn(2, Point3F(0.0, 0.0, 1.0));
- camPos.y = getMin(camPos.y - smMinSceneBounds.y, sceneBounds.minExtents.y - camBuffer);
- break;
- case DisplayTypeBack:
- camRot.setColumn(0, Point3F(-1.0, 0.0, 0.0));
- camRot.setColumn(1, Point3F(0.0, -1.0, 0.0));
- camRot.setColumn(2, Point3F(0.0, 0.0, 1.0));
- camPos.y = getMax(camPos.y + smMinSceneBounds.y, sceneBounds.maxExtents.y + camBuffer);
- break;
- case DisplayTypeLeft:
- camRot.setColumn(0, Point3F( 0.0, -1.0, 0.0));
- camRot.setColumn(1, Point3F( 1.0, 0.0, 0.0));
- camRot.setColumn(2, Point3F( 0.0, 0.0, 1.0));
- camPos.x = getMin(camPos.x - smMinSceneBounds.x, sceneBounds.minExtents.x - camBuffer);
- break;
- case DisplayTypeRight:
- camRot.setColumn(0, Point3F( 0.0, 1.0, 0.0));
- camRot.setColumn(1, Point3F(-1.0, 0.0, 0.0));
- camRot.setColumn(2, Point3F( 0.0, 0.0, 1.0));
- camPos.x = getMax(camPos.x + smMinSceneBounds.x, sceneBounds.maxExtents.x + camBuffer);
- break;
- case DisplayTypeIsometric:
- camPos.z = sceneBounds.maxExtents.z + camBuffer + isocamplanedist;
- MatrixF angle(EulerF(mIsoCamAngle, 0, 0));
- MatrixF rot(mIsoCamRot);
- camRot.mul(rot, angle);
- break;
- }
- query->cameraMatrix = camRot;
- query->cameraMatrix.setPosition(camPos);
- query->headMatrix = query->cameraMatrix;
- query->fov = mOrthoFOV;
- }
- smCamMatrix = query->cameraMatrix;
- smCamMatrix.getColumn(3,&smCamPos);
- smCamOrtho = query->ortho;
- smCamNearPlane = query->nearPlane;
- return true;
- }
- return false;
- }
- //------------------------------------------------------------------------------
- DefineEngineMethod( EditTSCtrl, getDisplayType, S32, (),, "" )
- {
- return object->getDisplayType();
- }
- DefineEngineMethod( EditTSCtrl, setDisplayType, void, ( S32 displayType ),, "" )
- {
- object->setDisplayType( displayType );
- }
- DefineEngineMethod( EditTSCtrl, getOrthoFOV, F32, (),,
- "Return the FOV for orthographic views." )
- {
- return object->getOrthoFOV();
- }
- DefineEngineMethod( EditTSCtrl, setOrthoFOV, void, ( F32 fov ),,
- "Set the FOV for to use for orthographic views." )
- {
- object->setOrthoFOV( fov );
- }
- DefineEngineMethod( EditTSCtrl, renderBox, void, ( Point3F pos, Point3F size ),, "" )
- {
- if( !object->mConsoleRendering || !object->mConsoleFillColor.alpha )
- return;
- GFXStateBlockDesc desc;
- desc.setBlend( true );
- Box3F box;
- box.set( size );
- box.setCenter( pos );
- MatrixF camera = GFX->getWorldMatrix();
- camera.inverse();
- if( box.isContained( camera.getPosition() ) )
- desc.setCullMode( GFXCullNone );
- GFX->getDrawUtil()->drawCube( desc, size, pos, object->mConsoleFillColor );
- }
- DefineEngineMethod(EditTSCtrl, renderSphere, void, ( Point3F pos, F32 radius, S32 sphereLevel ), ( 0 ), "" )
- {
- if ( !object->mConsoleRendering || !object->mConsoleFillColor.alpha )
- return;
- // TODO: We need to support subdivision levels in GFXDrawUtil!
- if ( sphereLevel <= 0 )
- sphereLevel = object->mConsoleSphereLevel;
- GFXStateBlockDesc desc;
- desc.setBlend( true );
- MatrixF camera = GFX->getWorldMatrix();
- camera.inverse();
-
- SphereF sphere( pos, radius );
- if( sphere.isContained( camera.getPosition() ) )
- desc.setCullMode( GFXCullNone );
- GFX->getDrawUtil()->drawSphere( desc, radius, pos, object->mConsoleFillColor );
- }
- DefineEngineMethod( EditTSCtrl, renderCircle, void, ( Point3F pos, Point3F normal, F32 radius, S32 segments ), ( 0 ), "" )
- {
- if(!object->mConsoleRendering)
- return;
- if(!object->mConsoleFrameColor.alpha && !object->mConsoleFillColor.alpha)
- return;
- if ( segments <= 0 )
- segments = object->mConsoleCircleSegments;
- normal.normalizeSafe();
- AngAxisF aa;
- F32 dotUp = mDot( normal, Point3F(0,0,1) );
- if ( dotUp == 1.0f )
- aa.set( Point3F(0,0,1), 0.0f ); // normal is 0,0,1
- else if ( dotUp == -1.0f )
- aa.set( Point3F(1,0,0), M_PI_F ); // normal is 0,0,-1
- else
- {
- mCross( normal, Point3F(0,0,1), &aa.axis );
- aa.axis.normalizeSafe();
- aa.angle = mAcos( mClampF( dotUp, -1.f, 1.f ) );
- }
- MatrixF mat;
- aa.setMatrix(&mat);
- F32 step = M_2PI / segments;
- F32 angle = 0.f;
- Vector<Point3F> points(segments);
- for(U32 i = 0; i < segments; i++)
- {
- Point3F pnt(mCos(angle), mSin(angle), 0.f);
- mat.mulP(pnt);
- pnt *= radius;
- pnt += pos;
- points.push_front(pnt);
- angle += step;
- }
- GFX->setStateBlock(object->mBlendSB);
- // framed
- if(object->mConsoleFrameColor.alpha)
- {
- // TODO: Set GFX line width (when it exists) to the value of 'object->mConsoleLineWidth'
- PrimBuild::color( object->mConsoleFrameColor );
- PrimBuild::begin( GFXLineStrip, points.size() + 1 );
- for( S32 i = 0; i < points.size(); i++ )
- PrimBuild::vertex3fv( points[i] );
- // GFX does not have a LineLoop primitive, so connect the last line
- if( points.size() > 0 )
- PrimBuild::vertex3fv( points[0] );
- PrimBuild::end();
- // TODO: Reset GFX line width here
- }
- // filled
- if(object->mConsoleFillColor.alpha)
- {
- PrimBuild::color( object->mConsoleFillColor );
- PrimBuild::begin( GFXTriangleStrip, points.size() + 2 );
- // Center point
- PrimBuild::vertex3fv( pos );
- // Edge verts
- for( S32 i = 0; i < points.size(); i++ )
- PrimBuild::vertex3fv( points[i] );
- PrimBuild::vertex3fv( points[0] );
- PrimBuild::end();
- }
- }
- DefineEngineMethod( EditTSCtrl, renderTriangle, void, ( Point3F a, Point3F b, Point3F c ),, "" )
- {
- if(!object->mConsoleRendering)
- return;
- if(!object->mConsoleFrameColor.alpha && !object->mConsoleFillColor.alpha)
- return;
- const Point3F* pnts[3] = { &a, &b, &c };
- GFX->setStateBlock(object->mBlendSB);
- // frame
- if( object->mConsoleFrameColor.alpha )
- {
- PrimBuild::color( object->mConsoleFrameColor );
-
- // TODO: Set GFX line width (when it exists) to the value of 'object->mConsoleLineWidth'
- PrimBuild::begin( GFXLineStrip, 4 );
- PrimBuild::vertex3fv( *pnts[0] );
- PrimBuild::vertex3fv( *pnts[1] );
- PrimBuild::vertex3fv( *pnts[2] );
- PrimBuild::vertex3fv( *pnts[0] );
- PrimBuild::end();
- // TODO: Reset GFX line width here
- }
- // fill
- if( object->mConsoleFillColor.alpha )
- {
- PrimBuild::color( object->mConsoleFillColor );
- PrimBuild::begin( GFXTriangleList, 3 );
- PrimBuild::vertex3fv( *pnts[0] );
- PrimBuild::vertex3fv( *pnts[1] );
- PrimBuild::vertex3fv( *pnts[2] );
- PrimBuild::end();
- }
- }
- DefineEngineMethod( EditTSCtrl, renderLine, void, ( Point3F start, Point3F end, F32 lineWidth ), ( 0 ), "" )
- {
- if ( !object->mConsoleRendering || !object->mConsoleFrameColor.alpha )
- return;
- // TODO: We don't support 3d lines with width... fix this!
- if ( lineWidth <= 0 )
- lineWidth = object->mConsoleLineWidth;
- GFX->getDrawUtil()->drawLine( start, end, object->mConsoleFrameColor );
- }
- DefineEngineMethod( EditTSCtrl, getGizmo, S32, (),, "" )
- {
- return object->getGizmo()->getId();
- }
- DefineEngineMethod( EditTSCtrl, isMiddleMouseDown, bool, (),, "" )
- {
- return object->isMiddleMouseDown();
- }
|