| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486 |
- //
- // The graphics engine GXScene https://github.com/glscene
- //
- unit GXS.GizmoEx;
- (*
- Invisible component for helping to Move, Rotate and Scale an Object
- This is an enhanced version of TgxGizmo usefull for an Editor.
- *)
- interface
- {$I GLScene.Defines.inc}
- uses
- Winapi.OpenGL,
- Winapi.OpenGLext,
- Winapi.Windows,
- System.Types,
- System.Classes,
- System.SysUtils,
- System.Math,
- FMX.TextLayout,
- GLScene.GeometryBB,
- GLScene.VectorTypes,
- GLScene.VectorGeometry,
- GLScene.PersistentClasses,
- GLScene.Strings,
- GXS.Scene,
- GLScene.Color,
- GXS.Material,
- GXS.Objects,
- GXS.SceneViewer,
- GXS.GeomObjects,
- GXS.BitmapFont,
- GXS.VectorFileObjects,
- GLScene.Coordinates,
- GXS.RenderContextInfo,
- GXS.Canvas,
- GXS.Screen,
- GXS.State,
- GLScene.PipelineTransform,
- GXS.Selection,
- GXS.ImageUtils,
- GXS.Context;
- type
- TgxGizmoExObjectCollection = class;
- TgxGizmoEx = class;
- TgxGizmoExObjectItem = class(TCollectionItem)
- private
- FOldAutoScaling: TVector4f;
- FEffectedObject: TgxBaseSceneObject;
- FParentOldObject: TgxBaseSceneObject;
- FIndexOldObject: Integer;
- FNameOldObject: string;
- FReturnObject: Boolean;
- FOldMatrix: TMatrix4f;
- FGizmoTmpRoot: TgxBaseSceneObject;
- procedure SetEffectedObject(const Value: TgxBaseSceneObject);
- procedure SetOldMatrix(const Value: TMatrix4f);
- protected
- procedure DoUndo;
- function GetParent: TgxGizmoExObjectCollection;
- function GetGizmo: TgxGizmoEx;
- public
- property GizmoTmpRoot: TgxBaseSceneObject read FGizmoTmpRoot write FGizmoTmpRoot;
- constructor Create(AOwner: TCollection); override;
- destructor Destroy; override;
- procedure Notification(AComponent: TComponent; Operation: TOperation); virtual;
- procedure AssignFromObject(const AObject: TgxBaseSceneObject; AssignAndRemoveObj: Boolean = False);
- // TODO: create a special type for Matrix.
- property OldMatrix: TMatrix4f read FOldMatrix write SetOldMatrix;
- published
- property EffectedObject: TgxBaseSceneobject read FEffectedObject write SetEffectedObject;
- end;
- TgxGizmoExObjectCollection = class(TOwnedCollection)
- private
- function GetItems(const Index: Integer): TgxGizmoExObjectItem;
- procedure SetItems(const Index: Integer; const Value: TgxGizmoExObjectItem);
- protected
- function GetParent: TgxGizmoEx;
- procedure DoUndo;
- public
- procedure Notification(AComponent: TComponent; Operation: TOperation);
- procedure RemoveByObject(const AObject: TgxCustomSceneObject);
- function Add: TgxGizmoExObjectItem;
- property Items[const Index: Integer]: TgxGizmoExObjectItem read GetItems write SetItems; default;
- end;
- TgxGizmoExActionHistoryItem = class(TCollectionItem)
- private
- FObject: TObject;
- FGizmoObjectCollection: TgxGizmoExObjectCollection;
- procedure SetObject(aValue: TObject);
- procedure SetGizmoObjectCollection(aValue: TgxGizmoExObjectCollection);
- public
- constructor Create(AOwner: TCollection); override;
- destructor Destroy; override;
- property BaseObject: TObject read FObject write SetObject;
- property GizmoObjectCollection: TgxGizmoExObjectCollection read FGizmoObjectCollection write SetGizmoObjectCollection;
- end;
- TgxGizmoExActionHistoryCollection = class(TOwnedCollection)
- private
- FItemIndex: Integer;
- FItemsMaxCount: Integer;
- FGizmoTmpRoot: TgxBaseSceneObject;
- function GetItems(const Index: Integer): TgxGizmoExActionHistoryItem;
- procedure SetItems(const Index: Integer; const Value: TgxGizmoExActionHistoryItem);
- function Add: TgxGizmoExActionHistoryItem;
- public
- constructor Create(AOwner: TPersistent; ItemClass: TCollectionItemClass);
- procedure Notification(AComponent: TComponent; Operation: TOperation);
- property ItemIndex: Integer read FItemIndex write FItemIndex;
- function Undo: TgxGizmoExActionHistoryItem;
- function Redo: TgxGizmoExActionHistoryItem;
- procedure AddObjects(objs: TgxPickList);
- procedure AddObject(obj: TObject);
- procedure RemoveObjects(objs: TgxPickList);
- property MaxCount: Integer read FItemsMaxCount write FItemsMaxCount;
- property Items[const Index: Integer]: TgxGizmoExActionHistoryItem read GetItems write SetItems; default;
- property GizmoTmpRoot: TgxBaseSceneObject read FGizmoTmpRoot write FGizmoTmpRoot;
- end;
- TgxGizmoExVisibleInfoLabel = (vliName, vliOperation, vliCoords);
- TgxGizmoExVisibleInfoLabels = set of TgxGizmoExVisibleInfoLabel;
- TInfoLabelCoordType = (ilcChanging, ilcChangeRate);
- TgxGizmoExAxis = (gaNone, gaX, gaY, gaZ, gaXY, gaXZ, gaYZ, gaXYZ);
- TgxGizmoExSelectionRegion = (gsrRectangular, gsrCircular, gsrFence,
- gsrLasso);
- TgxGizmoExReferenceCoordinateSystem = (rcsView, rcsLocal);
- TgxGizmoExSelRec = array of TPoint;
- TgxGizmoExOperation = (gopMove, gopRotate, gopScale, gopNone);
- TgxGizmoExOperationMode = (gomNone, gomSelect, gomMove, gomRotate, gomScale);
- TgxGizmoExAcceptEvent = procedure(Sender: TObject; var objs: TgxPickList) of object;
- TgxGizmoExAxisSelected = procedure(Sender: TObject; var Axis: TgxGizmoExAxis) of object;
- TgxGizmoExPickMode = (pmGetPickedObjects, pmRayCast);
- //Gizmo objects
- TgxGizmoExUIFrustrum = class(TgxFrustrum)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUISphere = class(TgxSphere)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUIDisk = class(TgxDisk)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUITorus = class(TgxTorus)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUIPolygon = class(TgxPolygon)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUIArrowLine = class(TgxArrowLine)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUILines = class(TgxLines)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoExUIFlatText = class(TgxFlatText)
- private
- FNoZWrite: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- procedure BuildList(var rci: TgxRenderContextInfo); override;
- property NoZWrite: Boolean read FNoZWrite write FNoZWrite;
- end;
- TgxGizmoEx = class(TComponent)
- private
- FUIBaseGizmo: TgxBaseSceneObject;
- FUIRootHelpers: TgxBaseSceneObject;
- FUIRootSelect: TgxBaseSceneObject; // for None
- FUIRootMovement: TgxBaseSceneObject; // for Move
- FUIRootRotate: TgxBaseSceneObject; //for Rotate
- FUIRootRotateAxisLabel: TgxBaseSceneObject;
- FUIRootScale: TgxBaseSceneObject; // for Scale
- FUIRootAxisLabel: TgxBaseSceneObject;
- FUIRootVisibleInfoLabels: TgxBaseSceneObject;
- FInterfaceRender: TgxDirectOpenGL;
- FInternalRender: TgxDirectOpenGL;
- FUISelectLineX, FUISelectLineY, FUISelectLineZ: TgxGizmoExUILines; // For None (Select)
- //IC- Invisible Contro, for move
- FUIICMovementLineX, FUIICMovementLineY, FUIICMovementLineZ, FUIICMovementLineXY, FUIICMovementLineXZ, FUIICMovementLineYZ: TgxGizmoExUIFrustrum;
- FUIMovementArrowX, FUIMovementArrowY, FUIMovementArrowZ: TgxGizmoExUIArrowLine; // For Move
- FUIMovementLineX, FUIMovementLineY, FUIMovementLineZ, FUIMovementLineXY, FUIMovementLineXZ, FUIMovementLineYZ: TgxGizmoExUILines; // For Move
- FUIMovementPlaneXY, FUIMovementPlaneXZ, FUIMovementPlaneYZ: TgxGizmoExUIPolyGon; // For Move
- //ForRotate
- FUIRotateLineX, FUIRotateLineY, FUIRotateLineZ, FUIRotateLineXY, FUIRotateLineXZ: TgxGizmoExUILines;
- FUIICRotateTorusX, FUIICRotateTorusY, FUIICRotateTorusZ, FUIICRotateTorusXZ: TgxGizmoExUITorus; // For Rotate
- FUIRotateDiskXY, FUIRotateDiskX, FUIRotateDiskX2, FUIRotateDiskY, FUIRotateDiskY2, FUIRotateDiskZ, FUIRotateDiskZ2: TgxGizmoExUIDisk;
- FUIRotateLineArrowX, FUIRotateLineArrowY, FUIRotateLineArrowZ: TgxGizmoExUILines;
- FUIICRotateSphereXY: TgxGizmoExUISphere;
- FUIRotateAxisLabelX, FUIRotateAxisLabelY, FUIRotateAxisLabelZ: TgxGizmoExUIFlatText;
- //ForScale
- FUIScaleArrowX, FUIScaleArrowY, FUIScaleArrowZ: TgxGizmoExUISphere;
- FUIScaleLineX, FUIScaleLineY, FUIScaleLineZ, FUIScaleLineXY, FUIScaleLineYZ, FUIScaleLineXZ: TgxGizmoExUILines;
- FUIICScaleLineX, FUIICScaleLineY, FUIICScaleLineZ, FUIICScaleLineXY, FUIICScaleLineXZ, FUIICScaleLineYZ, FUIICScaleLineXYZ: TgxGizmoExUIFrustrum;
- FUIScalePlaneXY, FUIScalePlaneXZ, FUIScalePlaneYZ, FUIScalePlaneXYZ: TgxGizmoExUIPolyGon; // For Move
- FUIAxisLabelX, FUIAxisLabelY, FUIAxisLabelZ: TgxGizmoExUIFlatText;
- FUIVisibleInfoLabels: TgxGizmoExUIFlatText;
- FRootGizmo: TgxBaseSceneObject;
- FRootObjects: TgxBaseSceneObject;
- FGizmoTmpRoot: TgxBaseSceneObject;
- FSelectedObj: TgxBaseSceneObject;
- FOperation: TgxGizmoExOperation;
- FOperationMode: TgxGizmoExOperationMode;
- FSelAxis: TgxGizmoExAxis;
- fInfoLabelCoordType: TInfoLabelCoordType;
- FReferenceCoordSystem: TgxGizmoExReferenceCoordinateSystem;
- FBoundingBoxColor: TGColor;
- FSelectedColor: TGColor;
- FVisibleInfoLabelsColor: TGColor;
- FSelectionRegionColor: TGColor;
- FVisibleInfoLabelsColorChanged: Boolean;
- FAutoZoom: Boolean;
- FExcludeObjects: Boolean;
- FExcludeClassname: Boolean;
- FNoZWrite: Boolean;
- FEnabled: Boolean;
- FAutoZoomFactor: Single;
- FZoomFactor: Single;
- FMoveCoef: Single;
- FRotationCoef: Single;
- FViewer: TgxSceneViewer;
- FVisibleVisibleInfoLabels: TgxGizmoExVisibleInfoLabels;
- FExcludeObjectsList: TStrings;
- FExcludeClassNameList: TStrings;
- FSelectionRegion: TgxGizmoExSelectionRegion;
- FEnableMultiSelection: Boolean;
- FShowMultiSelecting: Boolean;
- FSelectionRec: TgxGizmoExSelRec;
- FCanAddObjToSelectionList: Boolean;
- FCanRemoveObjFromSelectionList: Boolean;
- FSelectedObjects: TgxPickList;
- FAntiAliasedLines: Boolean;
- FShowAxisLabel: Boolean;
- FShowObjectInfos: Boolean;
- FShowBoundingBox: Boolean;
- FCanChangeWithChildren: Boolean;
- moving: Boolean;
- mx, my: Integer;
- fCursorPos: TPoint;
- fLastCursorPos: TPoint;
- fChangeRate: TAffineVector; //total rotate angle
- FEnableLoopCursorMoving: Boolean;
- lastMousePos: TVector4f;
- FOnUpdate: TNotifyEvent;
- FOnSelect: TgxGizmoExAcceptEvent;
- FOnOperationChange: TNotifyEvent;
- FOnOperationModeChange: TNotifyEvent;
- FOnSelectionLost: TNotifyEvent;
- FOnAxisSelected: TgxGizmoExAxisSelected;
- FScaleCoef: Single;
- FGizmoThickness: Single;
- FPickMode: TgxGizmoExPickMode;
- FEnableHistory: Boolean;
- FHistory: TgxGizmoExActionHistoryCollection;
- FHistoryStepsCount: Integer;
- FLabelFont: TgxCustomBitmapFont;
- procedure SetRootGizmo(const AValue: TgxBaseSceneObject);
- procedure SetRootObjects(const AValue: TgxBaseSceneObject);
- procedure SetGizmoTmpRoot(const AValue: TgxBaseSceneObject);
- procedure SetGizmoExVisibleInfoLabels(const AValue: TgxGizmoExVisibleInfoLabels);
- procedure SetBoundingBoxColor(const AValue: TGColor);
- procedure SetSelectedColor(const AValue: TGColor);
- procedure SetVisibleInfoLabelsColor(const AValue: TGColor);
- procedure SetSelectionRegionColor(const AValue: TGColor);
- procedure SetCanChangeWithChildren(AValue: Boolean);
- procedure SetAALines(aValue: Boolean);
- procedure SetInfoLabelCoordType(aValue: TInfoLabelCoordType);
- procedure SetReferenceCoordSystem(aValue: TgxGizmoExReferenceCoordinateSystem);
- procedure SetHistoryStepsCount(aValue: Integer);
- procedure SetExcludeObjectsList(const AValue: TStrings);
- procedure SetExcludeClassNameList(const AValue: TStrings);
- function MouseWorldPos(const X, Y: Integer): TVector4f;
- function CheckObjectInExcludeList(const Obj: TgxBaseSceneObject): Boolean;
- function CheckClassNameInExcludeList(const Obj: TgxBaseSceneObject): Boolean;
- procedure UpdateVisibleInfoLabels;
- procedure SetGizmoExThickness(const Value: Single);
- procedure ActivatingElements(PickList: TgxPickList);
- procedure InterfaceRender(Sender: TObject; var rci: TgxRenderContextInfo);
- procedure InternalRender(Sender: TObject; var rci: TgxRenderContextInfo);
- function InternalGetPickedObjects(const x1, y1, x2, y2: Integer; const guessCount: Integer = 8): TgxPickList;
- procedure SetViewer(const Value: TgxSceneViewer);
- procedure SetLabelFont(const Value: TgxCustomBitmapFont);
- procedure SetSelectedObj(const Value: TgxBaseSceneObject);
- function GetSelectedObj: TgxBaseSceneObject;
- procedure SetNoZWrite(const Value: Boolean);
- procedure SetOperation(const Value: TgxGizmoExOperation);
- procedure SetOperationMode(const Value: TgxGizmoExOperationMode);
- procedure SetAngleDisk(aAngle: Single);
- procedure SetEnableLoopCursorMoving(const AValue: Boolean);
- procedure SetEnableMultiSelection(const AValue: Boolean);
- procedure SetSelectionRegion(const AValue: TgxGizmoExSelectionRegion);
- procedure SetShowAxisLabel(const AValue: Boolean);
- procedure SetShowObjectInfos(const AValue: Boolean);
- procedure SetShowBoundingBox(const AValue: Boolean);
- procedure SetAutoZoomFactor(const AValue: Single);
- procedure SetZoomFactor(const AValue: Single);
- procedure SetSelAxis(aValue: TgxGizmoExAxis);
- procedure SetPickMode(APickMode: TgxGizmoExPickMode);
- procedure AssignPickList(aList: TgxPickList; RemoveObj: Boolean = False);
- procedure AddObjToSelectionList(Obj: TgxBaseSceneObject);
- procedure RemoveObjFromSelectionList(Obj: TgxBaseSceneObject);
- procedure MultiSelMouseDown(X, Y: Integer);
- procedure MultiSelMouseUp(X, Y: Integer);
- procedure MultiSelMouseMove(X, Y: Integer);
- function GetPickList: TgxPickList;
- procedure SetPickList(aValue: TgxPickList);
- property SelAxis: TgxGizmoExAxis read FSelAxis write SetSelAxis;
- property Operation: TgxGizmoExOperation read FOperation write SetOperation;
- procedure ClearSelection;
- procedure SetVisible(const AValue: Boolean);
- function GetVisible: Boolean;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Loaded; override;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure ViewerMouseMove(const X, Y: Integer);
- procedure ViewerMouseDown(const X, Y: Integer);
- procedure ViewerMouseUp(const X, Y: Integer);
- procedure UpdateGizmo; overload;
- procedure LooseSelection; virtual;
- procedure UndoAdd(const AObject: TObject);
- procedure RemoveSelectedObjects;
- function Undo: TgxGizmoExActionHistoryItem;
- function Redo: TgxGizmoExActionHistoryItem;
- property CanAddObjToSelectionList: Boolean read FCanAddObjToSelectionList write FCanAddObjToSelectionList;
- property CanRemoveObjFromSelectionList: Boolean read FCanRemoveObjFromSelectionList write FCanRemoveObjFromSelectionList;
- procedure LooseCursorSelection;
- property CursorSelectingRegion: Boolean read FShowMultiSelecting;
- property RootObjects: TgxBaseSceneObject read FRootObjects write SetRootObjects;
- property RootGizmo: TgxBaseSceneObject read FRootGizmo write SetRootGizmo;
- property GizmoTmpRoot: TgxBaseSceneObject read FGizmoTmpRoot write SetGizmoTmpRoot;
- //--------------------------------------------------------------------
- published
- property Viewer: TgxSceneViewer read FViewer write SetViewer;
- property BoundingBoxColor: TGColor read FBoundingBoxColor write SetBoundingBoxColor;
- property SelectedColor: TGColor read FSelectedColor write SetSelectedColor;
- property SelectionRegionColor: TGColor read FSelectionRegionColor write SetSelectionRegionColor;
- property SelectedObj: TgxBaseSceneObject read GetSelectedObj write SetSelectedObj;
- property SelectedObjects: TgxPickList read GetPickList write SetPickList;
- property OperationMode: TgxGizmoExOperationMode read FOperationMode write SetOperationMode default gomSelect;
- property ExcludeObjects: Boolean read FExcludeObjects write FExcludeObjects;
- property ExcludeObjectsList: TStrings read FExcludeObjectsList write SetExcludeObjectsList;
- property ExcludeClassname: Boolean read FExcludeClassname write FExcludeClassname;
- property ExcludeClassnameList: TStrings read FExcludeClassnameList write SetExcludeClassnameList;
- property VisibleInfoLabels: TgxGizmoExVisibleInfoLabels read FVisibleVisibleInfoLabels write SetGizmoExVisibleInfoLabels;
- property VisibleInfoLabelsColor: TGColor read FVisibleInfoLabelsColor write SetVisibleInfoLabelsColor;
- property AutoZoom: Boolean read FAutoZoom write FAutoZoom default True;
- property AutoZoomFactor: Single read FAutoZoomFactor write SetAutoZoomFactor;
- property ZoomFactor: Single read FZoomFactor write SetZoomFactor;
- property MoveCoef: Single read FMoveCoef write FMoveCoef;
- property RotationCoef: Single read FRotationCoef write FRotationCoef;
- property ScaleCoef: Single read FScaleCoef write FScaleCoef;
- property NoZWrite: Boolean read FNoZWrite write SetNoZWrite default True;
- property GizmoThickness: Single read FGizmoThickness write SetGizmoExThickness;
- (* Indicates whether the gizmo is enabled or not.
- WARNING: When loading/editing (possibly whenever a structureChanged
- call is made) a model, sometimes the gizmo will trigger a
- bug if the mouse is inside the glscene Viewer. To prevent that,
- remember to disable the gizmo before loading, then process windows
- messages (i.e. application.processMessage) and then enable the gizmo
- again. *)
- (* Warning Enable is ReadOnly property if you set to False, Gizmo is not Hidden
- use Visible instead if you want to Hide, if you want to Hide but keep enabled
- see the VisibleGizmo property *)
- (* Use the property OperationMode=gomNone to unactivate gizmo and make it invisible *)
- property Enabled: Boolean read FEnabled write FEnabled default True;
- property LabelFont: TgxCustomBitmapFont read FLabelFont write SetLabelFont default nil;
- property OnSelectionLost: TNotifyEvent read FOnSelectionLost write FOnSelectionLost;
- property OnOperationChange: TNotifyEvent read FOnOperationChange write FOnOperationChange;
- property OnOperationModeChange: TNotifyEvent read FOnOperationModeChange write FOnOperationModeChange;
- property OnSelect: TgxGizmoExAcceptEvent read FOnSelect write FOnSelect;
- property OnAxisSelected: TgxGizmoExAxisSelected read FOnAxisSelected write FOnAxisSelected;
- property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
- property PickMode: TgxGizmoExPickMode read FPickMode write SetPickMode default pmGetPickedObjects;
- property EnableActionHistory: Boolean read FEnableHistory write FEnableHistory default True;
- property HistoryStepsCount: Integer read FHistoryStepsCount write SetHistoryStepsCount;
- property EnableLoopCursorMoving: Boolean read FEnableLoopCursorMoving write SetEnableLoopCursorMoving default True;
- property EnableMultiSelection: Boolean read FEnableMultiSelection write SetEnableMultiSelection default True;
- property CanChangeWithChildren: Boolean read FCanChangeWithChildren write SetCanChangeWithChildren;
- property AntiAliasedLines: Boolean read FAntiAliasedLines write SetAALines default True;
- property InfoLabelCoordType: TInfoLabelCoordType read fInfoLabelCoordType write SetInfoLabelCoordType default ilcChangeRate;
- property SelectionRegion: TgxGizmoExSelectionRegion read FSelectionRegion write SetSelectionRegion default gsrRectangular;
- property ShowAxisLabel: Boolean read FShowAxisLabel write SetShowAxisLabel default True;
- property ShowObjectInfos: Boolean read FShowObjectInfos write SetShowObjectInfos default True;
- property ShowBoundingBox: Boolean read FShowBoundingBox write SetShowBoundingBox default True;
- property ReferenceCoordSystem: TgxGizmoExReferenceCoordinateSystem read FReferenceCoordSystem write SetReferenceCoordSystem default rcsView;
- property Visible: Boolean read GetVisible write SetVisible;
- end;
- //--------------------------------------------------------------------
- implementation
- //---------------------------------------------------------------------
- procedure RotateAroundArbitraryAxis(const anObject: TgxBaseSceneObject; const Axis, Origin: TAffineVector; const angle: Single);
- var
- M, M1, M2, M3: TMatrix4f;
- begin
- M1 := CreateTranslationMatrix(VectorNegate(Origin));
- M2 := CreateRotationMatrix(Axis, Angle * PI / 180);
- M3 := CreateTranslationMatrix(Origin);
- M := MatrixMultiply(M1, M2);
- M := MatrixMultiply(M, M3);
- anObject.AbsoluteMatrix := MatrixMultiply(anObject.AbsoluteMatrix, M);
- //Just a workarround to Update angles...
- anObject.Roll(0);
- anObject.Pitch(0);
- anObject.Turn(0);
- end;
- //-------------------------------------------------------------------
- // Mathematical functions for canvas
- //-------------------------------------------------------------------
- function Det(const a, b, c, d: real): real;
- begin
- Det := a * d - b * c;
- end;
- //Distance between two points
- function Dist(const P1, P2: TPoint): real;
- begin
- Result := Sqrt(Sqr(P1.X - P2.X) + Sqr(P1.Y - P2.Y));
- end;
- function CrossingPointLine(p: TPoint; p1, p2: TPoint): Boolean;
- begin
- Result := (abs(p1.X - p.X) + abs(p2.X - p.X) = abs(p2.X - p1.X)) and
- (abs(p1.Y - p.Y) + abs(p2.Y - p.Y) = abs(p2.Y - p1.Y));
- end;
- //Intersection between two lines, return true or false
- //converted from http://doc-for-prog.narod.ru/topics/math/crossing.html
- function IsLineIntLine(p11, p12, p21, p22: TPoint; var p: TPoint): Boolean; // êîîðäèíàòû âòîðîãî îòðåçêà
- var
- Z, ca, cb, ua, ub: Single;
- begin
- // demominator
- Z := (p12.Y - p11.Y) * (p21.X - p22.X) - (p21.Y - p22.Y) * (p12.X - p11.X);
- // numerator 1
- Ca := (p12.Y - p11.Y) * (p21.X - p11.X) - (p21.Y - p11.Y) * (p12.X - p11.X);
- // numerator 2
- Cb := (p21.Y - p11.Y) * (p21.X - p22.X) - (p21.Y - p22.Y) * (p21.X - p11.X);
- // if numerator and demominator = 0, then coincide lines
- if (Z = 0) and (Ca = 0) and (Cb = 0) then
- begin
- Result := False;
- Exit;
- end
- else
- // if demominator = 0, then parallel lines
- if Z = 0 then
- begin
- Result := False;
- Exit;
- end;
- Ua := Ca / Z;
- Ub := Cb / Z;
- // if 0<=Ua<=1 and 0<=Ub<=1, then the intersection point is inside intervals
- if (0 <= Ua) and (Ua <= 1) and (0 <= Ub) and (Ub <= 1) then
- begin
- p.X := round(p11.X + (p12.X - p11.X) * Ub);
- p.Y := round(p11.Y + (p12.Y - p11.Y) * Ub);
- Result := True;
- end
- // otherwise the intersection point is outside intervals
- else
- Result := False;
- end;
- //Intersection of line and circle
- function IsLineIntCirlce(CR: Single; CC: TPoint; LP1, LP2: TPoint; var PIL1, PIL2: TPoint): Smallint;
- var
- d, K, b: Single;
- begin
- K := (LP1.Y - LP2.Y) / (LP1.X - LP2.X);
- b := LP1.Y - K * LP1.X;
- //determine decrement of quadratic equation
- d := (power((2 * K * b - 2 * CC.X - 2 * CC.Y * K), 2) - (4 + 4 * K * K) * (b * b - cr * cr + CC.X * CC.X + CC.Y * CC.Y - 2 * CC.Y * b));
- //if decrement = 0, then no decision and line and circle do not intersect
- if (d < 0) then
- begin
- Result := -1;
- PIL1 := point(0, 0);
- PIL2 := point(0, 0);
- Exit;
- end;
- //otherwise find roots of quadratic equation
- PIL1.X := round((-(2 * K * b - 2 * CC.X - 2 * CC.Y * K) - sqrt(d)) / (2 + 2 * K * K));
- PIL2.X := round((-(2 * K * b - 2 * CC.X - 2 * CC.Y * K) + sqrt(d)) / (2 + 2 * K * K));
- //if abscissas of points are coinside, then the intersection is only in one point
- //and line and circle have a point of contact
- if (PIL1.X = PIL2.X) then
- begin
- Result := 0;
- PIL1.Y := round(K * PIL1.X + b);
- PIL2 := PIL1;
- Exit;
- end;
- //otherwise find ordinates of intersection points
- PIL1.Y := round(K * PIL1.X + b);
- PIL2.Y := round(K * PIL2.X + b);
- Result := 1;
- end;
- constructor TgxGizmoExUIArrowLine.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUIArrowLine.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUIDisk.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUIDisk.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUISphere.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUISphere.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUIPolyGon.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUIPolyGon.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUIFrustrum.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUIFrustrum.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUITorus.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUITorus.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUILines.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUILines.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- constructor TgxGizmoExUIFlatText.Create(AOwner: TComponent);
- begin
- FNoZWrite := True;
- inherited;
- end;
- procedure TgxGizmoExUIFlatText.BuildList(var rci: TgxRenderContextInfo);
- begin
- if FNoZWrite then
- rci.gxStates.Disable(stDepthTest)
- else
- rci.gxStates.Enable(stDepthTest);
- inherited;
- end;
- //------------------------------------------------------------------------------
- constructor TgxGizmoEx.Create(aOwner: TComponent);
- var
- I: Integer;
- begin
- inherited Create(aOwner);
- FHistory := TgxGizmoExActionHistoryCollection.Create(Self, TgxGizmoExActionHistoryItem);
- FPickMode := pmGetPickedObjects;
- FRotationCoef := 1;
- FMoveCoef := 0.1;
- FScaleCoef := 0.1;
- FBoundingBoxColor := TGColor.Create(Self);
- FBoundingBoxColor.Color := clrWhite;
- FSelectionRegionColor := TGColor.Create(Self);
- SelectionRegionColor.Color := clrBlack;
- FSelectedColor := TGColor.Create(Self);
- FSelectedColor.Color := clrYellow;
- FVisibleInfoLabelsColor := TGColor.Create(Self);
- FVisibleInfoLabelsColor.Color := clrYellow;
- FVisibleInfoLabelsColorChanged := False;
- FUIBaseGizmo := TgxDummyCube.Create(Self);
- //BoundingBoxes...
- FInternalRender := TgxDirectOpenGL(FUIBaseGizmo.AddNewChild(TgxDirectOpenGL));
- FInternalRender.OnRender := InternalRender;
- FUIRootHelpers := TgxDummyCube(FUIBaseGizmo.AddNewChild(TgxDummyCube));
- //Canvas...
- FInterfaceRender := TgxDirectOpenGL(FUIBaseGizmo.AddNewChild(TgxDirectOpenGL));
- FInterfaceRender.OnRender := InterfaceRender;
- FSelectedObjects := TgxPickList.Create(psMinDepth);
- //For None
- FUIRootSelect := FUIRootHelpers.AddNewChild(TgxDummyCube); // for None
- FUIRootMovement := FUIRootHelpers.AddNewChild(TgxDummyCube);
- FUIRootRotate := FUIRootHelpers.AddNewChild(TgxDummyCube);
- FUIRootScale := FUIRootHelpers.AddNewChild(TgxDummyCube);
- FUIRootAxisLabel := FUIRootHelpers.AddNewChild(TgxDummyCube);
- FUIRootVisibleInfoLabels := FUIRootHelpers.AddNewChild(TgxDummyCube);
- FUISelectLineX := TgxGizmoExUILines(FUIRootSelect.addnewChild(TgxGizmoExUILines));
- with FUISelectLineX do
- begin
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(1, 0, 0);
- AddNode(0.9, 0, -0.1);
- addNode(1, 0, 0);
- addNode(0.9, 0, 0.1);
- end;
- FUISelectLineY := TgxGizmoExUILines(FUIRootSelect.addnewChild(TgxGizmoExUILines));
- with FUISelectLineY do
- begin
- LineColor.Color := clrLime;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0, 1, 0);
- AddNode(0.1, 0.9, 0);
- addNode(0, 1, 0);
- addNode(-0.1, 0.9, 0);
- end;
- FUISelectLineZ := TgxGizmoExUILines(FUIRootSelect.addnewChild(TgxGizmoExUILines));
- with FUISelectLineZ do
- begin
- LineColor.Color := clrBlue;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0, 0, 1);
- AddNode(0.1, 0, 0.9);
- addNode(0, 0, 1);
- addNode(-0.1, 0, 0.9);
- end;
- //For movement
- FUIMovementLineX := TgxGizmoExUILines(FUIRootMovement.addnewChild(TgxGizmoExUILines));
- with FUIMovementLineX do
- begin
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0.2, 0, 0);
- AddNode(1, 0, 0);
- // Raycast pickable object
- FUIICMovementLineX := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICMovementLineX do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(1, 0, 0);
- Height := 0.8;
- ApexHeight := 8;
- BaseDepth := 0.15;
- BaseWidth := 0.15;
- position.SetPoint(0.6, 0, 0);
- end;
- FUIMovementArrowX := TgxGizmoExUIArrowLine(addnewChild(TgxGizmoExUIArrowLine));
- with FUIMovementArrowX do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrRed;
- TurnAngle := 90;
- Height := 0.3;
- Position.X := 1;
- Slices := 8;
- Stacks := 2;
- TopRadius := 0;
- TopArrowHeadHeight := 0;
- TopArrowHeadRadius := 0;
- BottomArrowHeadHeight := 0.1;
- BottomRadius := 0.06;
- end;
- end;
- FUIMovementLineY := TgxGizmoExUILines(FUIRootMovement.addnewChild(TgxGizmoExUILines));
- with FUIMovementLineY do
- begin
- LineColor.Color := clrLime;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0.2, 0);
- AddNode(0, 1, 0);
- FUIMovementArrowY := TgxGizmoExUIArrowLine(addnewChild(TgxGizmoExUIArrowLine));
- with FUIMovementArrowY do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrLime;
- PitchAngle := 90;
- Height := 0.3;
- Position.Y := 1;
- Slices := 8;
- Stacks := 2;
- TopRadius := 0;
- TopArrowHeadHeight := 0;
- TopArrowHeadRadius := 0;
- BottomArrowHeadHeight := 0.1;
- BottomRadius := 0.06;
- end;
- // Raycast pickable object
- FUIICMovementLineY := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICMovementLineY do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(0, 1, 0);
- Height := 0.8;
- ApexHeight := 8;
- BaseDepth := 0.15;
- BaseWidth := 0.15;
- position.SetPoint(0, 0.6, 0);
- end;
- end;
- FUIMovementLineZ := TgxGizmoExUILines(FUIRootMovement.addnewChild(TgxGizmoExUILines));
- with FUIMovementLineZ do
- begin
- LineColor.Color := clrBlue;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0.2);
- AddNode(0, 0, 1);
- FUIMovementArrowZ := TgxGizmoExUIArrowLine(addnewChild(TgxGizmoExUIArrowLine));
- with FUIMovementArrowZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrBlue;
- RollAngle := 90;
- Height := 0.3;
- Position.Z := 1;
- Slices := 8;
- Stacks := 2;
- TopRadius := 0;
- TopArrowHeadHeight := 0;
- TopArrowHeadRadius := 0;
- BottomArrowHeadHeight := 0.1;
- BottomRadius := 0.06;
- end;
- // Raycast pickable object
- FUIICMovementLineZ := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICMovementLineZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(0, 0, 1);
- Height := 0.8;
- ApexHeight := 8;
- BaseDepth := 0.15;
- BaseWidth := 0.15;
- position.SetPoint(0, 0, 0.6);
- end;
- end;
- FUIMovementLineXY := TgxGizmoExUILines(FUIRootMovement.addnewChild(TgxGizmoExUILines));
- with FUIMovementLineXY do
- begin
- LineWidth := 1;
- Options := [loUseNodeColorForLines];
- NodesAspect := lnaInvisible;
- SplineMode := lsmSegments;
- addNode(0, 0.4, 0);
- TgxLinesNode(Nodes[0]).Color.color := clrLime;
- addNode(0.4, 0.4, 0);
- TgxLinesNode(Nodes[1]).Color.color := clrLime;
- addNode(0.4, 0.4, 0);
- TgxLinesNode(Nodes[2]).Color.color := clrRed;
- addNode(0.4, 0, 0);
- TgxLinesNode(Nodes[3]).Color.color := clrRed;
- // Raycast pickable object
- FUIMovementPlaneXY := TgxGizmoExUIPolyGon(addnewChild(TgxGizmoExUIPolyGon));
- with FUIMovementPlaneXY do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0.01;
- addNode(0.01, 0.39, 0);
- addNode(0.39, 0.39, 0);
- addNode(0.39, 0.01, 0);
- addNode(0.01, 0.01, 0);
- end;
- FUIICMovementLineXY := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICMovementLineXY do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(1, 0, 0);
- Height := 0.35;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.35;
- position.SetPoint(0.25, 0.25, 0);
- end;
- end;
- FUIMovementLineXZ := TgxGizmoExUILines(FUIRootMovement.addnewChild(TgxGizmoExUILines));
- with FUIMovementLineXZ do
- begin
- LineWidth := 1;
- Options := [loUseNodeColorForLines];
- NodesAspect := lnaInvisible;
- SplineMode := lsmSegments;
- addNode(0.4, 0, 0);
- TgxLinesNode(Nodes[0]).Color.color := clrRed;
- addNode(0.4, 0, 0.4);
- TgxLinesNode(Nodes[1]).Color.color := clrRed;
- addNode(0.4, 0, 0.4);
- TgxLinesNode(Nodes[2]).Color.color := clrBlue;
- addNode(0, 0, 0.4);
- TgxLinesNode(Nodes[3]).Color.color := clrBlue;
- FUIMovementPlaneXZ := TgxGizmoExUIPolyGon(addnewChild(TgxGizmoExUIPolyGon));
- with FUIMovementPlaneXZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0.01;
- addNode(0.39, 0, 0.01);
- addNode(0.39, 0, 0.39);
- addNode(0.01, 0, 0.39);
- addNode(0, 0, 0.01);
- end;
- // Raycast pickable object
- FUIICMovementLineXZ := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICMovementLineXZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Alpha := 0;
- pitchAngle := 90;
- Height := 0.35;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.35;
- position.SetPoint(0.25, 0, 0.25);
- end;
- end;
- FUIMovementLineYZ := TgxGizmoExUILines(FUIRootMovement.addnewChild(TgxGizmoExUILines));
- with FUIMovementLineYZ do
- begin
- LineWidth := 1;
- Options := [loUseNodeColorForLines];
- NodesAspect := lnaInvisible;
- SplineMode := lsmSegments;
- addNode(0, 0, 0.4);
- TgxLinesNode(Nodes[0]).Color.color := clrBlue;
- addNode(0, 0.4, 0.4);
- TgxLinesNode(Nodes[1]).Color.color := clrBlue;
- addNode(0, 0.4, 0.4);
- TgxLinesNode(Nodes[2]).Color.color := clrLime;
- addNode(0, 0.4, 0);
- TgxLinesNode(Nodes[3]).Color.color := clrLime;
- FUIMovementPlaneYZ := TgxGizmoExUIPolyGon(addnewChild(TgxGizmoExUIPolyGon));
- with FUIMovementPlaneYZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0.01;
- addNode(0, 0.01, 0.39);
- addNode(0, 0.39, 0.39);
- addNode(0, 0.39, 0);
- addNode(0, 0.01, 0);
- end;
- // Raycast pickable object
- FUIICMovementLineYZ := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICMovementLineYZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(0, 0, 1);
- Height := 0.35;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.35;
- position.SetPoint(0, 0.25, 0.25);
- end;
- end;
- //Rotate
- FUIRotateLineXY := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineXY do
- begin
- LineColor.Color := clrGray50;
- SplineMode := lsmCubicSpline;
- NodesAspect := lnaInvisible;
- LineWidth := 1;
- Nodes.AddXYArc(1, 1, 0, 360, 24, AffineVectorMake(0, 0, 0));
- FUIRotateDiskXY := TgxGizmoExUIDisk(addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskXY do
- begin
- OuterRadius := 1;
- Slices := 18;
- with Material do
- begin
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrGray50;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIICRotateSphereXY := TgxGizmoExUISphere(addnewChild(TgxGizmoExUISphere));
- with FUIICRotateSphereXY do
- begin
- Radius := 1;
- Stop := 180;
- Slices := 18;
- TurnAngle := -90;
- with Material do
- begin
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clryellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- end;
- FUIRotateLineXZ := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineXZ do
- begin
- LineColor.Color := clrGray75;
- SplineMode := lsmCubicSpline;
- NodesAspect := lnaInvisible;
- LineWidth := 1;
- Nodes.AddXYArc(1.3, 1.3, 0, 360, 24, AffineVectorMake(0, 0, 0));
- FUIICRotateTorusXZ := TgxGizmoExUITorus(addnewChild(TgxGizmoExUITorus));
- with FUIICRotateTorusXZ do
- begin
- Rings := 18;
- Sides := 0;
- MajorRadius := 1.3;
- MinorRadius := 0.07;
- with material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- end;
- FUIRotateLineX := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineX do
- begin
- Options := [loUseNodeColorForLines];
- // To fix transparency issues
- lineColor.Alpha := 0.1;
- Nodecolor.Color := clrred;
- Nodecolor.Alpha := 0.1;
- TurnAngle := 90;
- SplineMode := lsmCubicSpline;
- NodesAspect := lnaInvisible;
- LineWidth := 1;
- Nodes.AddXYArc(1, 1, 0, 360, 24, AffineVectorMake(0, 0, 0));
- for I := 0 to 24 do
- begin
- TgxLinesNode(Nodes[I]).Color.color := clrred;
- end;
- end;
- FUIRotateLineArrowX := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineArrowX do
- begin
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0.4, 0, 0);
- end;
- FUIRotateDiskX := TgxGizmoExUIDisk(FUIRootRotate.addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskX do
- begin
- OuterRadius := 1.01;
- Slices := 18;
- sweepangle := 10;
- StartAngle := 0;
- TurnAngle := 90;
- with Material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrred;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIRotateDiskX2 := TgxGizmoExUIDisk(FUIRootRotate.addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskX2 do
- begin
- OuterRadius := 1.01;
- Slices := 18;
- sweepangle := 10;
- StartAngle := 0;
- TurnAngle := 90;
- with Material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrred;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIICRotateTorusX := TgxGizmoExUITorus(FUIRootRotate.addnewChild(TgxGizmoExUITorus));
- with FUIICRotateTorusX do
- begin
- Rings := 18;
- Sides := 0;
- MajorRadius := 1;
- MinorRadius := 0.07;
- TurnAngle := 90;
- with material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIRotateLineY := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineY do
- begin
- Options := [loUseNodeColorForLines];
- // To fix transparency issues
- lineColor.Alpha := 0.1;
- Nodecolor.Color := clrLime;
- Nodecolor.Alpha := 0.1;
- SplineMode := lsmCubicSpline;
- NodesAspect := lnaInvisible;
- LineWidth := 1;
- Nodes.AddXYArc(1, 1, 0, 360, 24, AffineVectorMake(0, 0, 0));
- PitchAngle := 90;
- for I := 0 to 24 do
- begin
- TgxLinesNode(Nodes[I]).Color.color := clrLime;
- end;
- end;
- FUIRotateLineArrowY := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineArrowY do
- begin
- LineColor.Color := clrLime;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0, 0.4, 0);
- end;
- FUIRotateDiskY := TgxGizmoExUIDisk(FUIRootRotate.addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskY do
- begin
- OuterRadius := 1;
- Slices := 18;
- sweepangle := 20;
- startangle := 0;
- PitchAngle := 90;
- with Material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrLime;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIRotateDiskY2 := TgxGizmoExUIDisk(FUIRootRotate.addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskY2 do
- begin
- OuterRadius := 1;
- Slices := 18;
- sweepangle := 20;
- startangle := 0;
- PitchAngle := 90;
- with Material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrLime;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIICRotateTorusY := TgxGizmoExUITorus(FUIRootRotate.addnewChild(TgxGizmoExUITorus));
- with FUIICRotateTorusY do
- begin
- Rings := 18;
- Sides := 0;
- MajorRadius := 1;
- MinorRadius := 0.07;
- PitchAngle := 90;
- with material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIRotateLineZ := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineZ do
- begin
- Options := [loUseNodeColorForLines];
- //to correct transparency problem
- lineColor.Alpha := 0.1;
- Nodecolor.Color := clrBlue;
- Nodecolor.Alpha := 0.1;
- SplineMode := lsmCubicSpline;
- NodesAspect := lnaInvisible;
- LineWidth := 1;
- Nodes.AddXYArc(1, 1, 0, 360, 24, AffineVectorMake(0, 0, 0));
- for I := 0 to 24 do
- begin
- TgxLinesNode(Nodes[I]).Color.color := clrBlue;
- end;
- end;
- FUIRotateLineArrowZ := TgxGizmoExUILines(FUIRootRotate.addnewChild(TgxGizmoExUILines));
- with FUIRotateLineArrowZ do
- begin
- LineColor.Color := clrBlue;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0, 0, 0.4);
- end;
- FUIRotateDiskZ := TgxGizmoExUIDisk(FUIRootRotate.addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskZ do
- begin
- OuterRadius := 1;
- Slices := 18;
- SweepAngle := 10;
- StartAngle := 0;
- with Material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrBlue;
- BackProperties.Diffuse.Color := clrBlue;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIRotateDiskZ2 := TgxGizmoExUIDisk(FUIRootRotate.addnewChild(TgxGizmoExUIDisk));
- with FUIRotateDiskZ2 do
- begin
- OuterRadius := 1;
- Slices := 18;
- SweepAngle := 10;
- StartAngle := 0;
- with Material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrBlue;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIICRotateTorusZ := TgxGizmoExUITorus(FUIRootRotate.addnewChild(TgxGizmoExUITorus));
- with FUIICRotateTorusZ do
- begin
- Rings := 18;
- Sides := 0;
- MajorRadius := 1;
- MinorRadius := 0.07;
- with material do
- begin
- FaceCulling := fcNoCull;
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- end;
- FUIRootRotateAxisLabel := FUIRootRotate.AddNewChild(TgxDummyCube);
- FUIRotateAxisLabelX := TgxGizmoExUIFlatText(FUIRootRotateAxisLabel.AddNewChild(TgxGizmoExUIFlatText));
- with FUIRotateAxisLabelX do
- begin
- ModulateColor.Color := clrRed;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.X := 0.5;
- Scale.X := 0.010;
- Scale.Y := 0.010;
- Text := 'X';
- end;
- FUIRotateAxisLabelY := TgxGizmoExUIFlatText(FUIRootRotateAxisLabel.AddNewChild(TgxGizmoExUIFlatText));
- with FUIRotateAxisLabelY do
- begin
- ModulateColor.Color := clrLime;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.Y := 0.5;
- Scale.X := 0.010;
- Scale.Y := 0.010;
- Text := 'Y';
- end;
- FUIRotateAxisLabelZ := TgxGizmoExUIFlatText(FUIRootRotateAxisLabel.AddNewChild(TgxGizmoExUIFlatText));
- with FUIRotateAxisLabelZ do
- begin
- ModulateColor.Color := clrBlue;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.Z := 0.5;
- Scale.X := 0.010;
- Scale.Y := 0.010;
- Text := 'Z';
- end;
- //for Scale
- FUIScaleLineX := TgxGizmoExUILines(FUIRootScale.addnewChild(TgxGizmoExUILines));
- with FUIScaleLineX do
- begin
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(1, 0, 0);
- // Raycast pickable object
- FUIICScaleLineX := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineX do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(1, 0, 0);
- Height := 0.5;
- ApexHeight := 8;
- BaseDepth := 0.15;
- BaseWidth := 0.15;
- position.SetPoint(0.8, 0, 0);
- end;
- end;
- FUIScaleLineY := TgxGizmoExUILines(FUIRootScale.addnewChild(TgxGizmoExUILines));
- with FUIScaleLineY do
- begin
- LineColor.Color := clrLime;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0, 1, 0);
- // Raycast pickable object
- FUIICScaleLineY := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineY do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(0, 1, 0);
- Height := 0.5;
- ApexHeight := 8;
- BaseDepth := 0.15;
- BaseWidth := 0.15;
- position.SetPoint(0, 0.8, 0);
- end;
- end;
- FUIScaleLineZ := TgxGizmoExUILines(FUIRootScale.addnewChild(TgxGizmoExUILines));
- with FUIScaleLineZ do
- begin
- LineColor.Color := clrBlue;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0, 0);
- AddNode(0, 0, 1);
- // Raycast pickable object
- FUIICScaleLineZ := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- Up.SetVector(0, 0, 1);
- Height := 0.5;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.1;
- position.SetPoint(0, 0, 0.8);
- end;
- end;
- FUIScaleLineXY := TgxGizmoExUILines(FUIRootScale.addnewChild(TgxGizmoExUILines));
- with FUIScaleLineXY do
- begin
- Options := [loUseNodeColorForLines];
- SplineMode := lsmSegments;
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0.7, 0);
- AddNode(0.35, 0.35, 0);
- TgxLinesNode(Nodes[0]).Color.color := clrLime;
- TgxLinesNode(Nodes[1]).Color.color := clrLime;
- AddNode(0.35, 0.35, 0);
- AddNode(0.7, 0, 0);
- TgxLinesNode(Nodes[2]).Color.color := clrRed;
- TgxLinesNode(Nodes[3]).Color.color := clrRed;
- AddNode(0.5, 0, 0);
- AddNode(0.25, 0.25, 0);
- TgxLinesNode(Nodes[4]).Color.color := clrRed;
- TgxLinesNode(Nodes[5]).Color.color := clrRed;
- AddNode(0.25, 0.25, 0);
- AddNode(0, 0.5, 0);
- TgxLinesNode(Nodes[6]).Color.color := clrLime;
- TgxLinesNode(Nodes[7]).Color.color := clrLime;
- FUIScalePlaneXY := TgxGizmoExUIPolyGon(addnewChild(TgxGizmoExUIPolyGon));
- with FUIScalePlaneXY do
- begin
- with Material do
- begin
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0.01;
- end;
- AddNode(0, 0.7, 0);
- AddNode(0.35, 0.35, 0);
- AddNode(0.7, 0, 0);
- AddNode(0.5, 0, 0);
- AddNode(0.25, 0.25, 0);
- AddNode(0, 0.5, 0);
- end;
- // Raycast pickable object
- FUIICScaleLineXY := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineXY do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- rollAngle := 45;
- turnAngle := 45;
- Height := 0.8;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.1;
- position.SetPoint(0.3, 0.3, 0);
- end;
- end;
- FUIScaleLineXZ := TgxGizmoExUILines(FUIRootScale.addnewChild(TgxGizmoExUILines));
- with FUIScaleLineXZ do
- begin
- Options := [loUseNodeColorForLines];
- SplineMode := lsmSegments;
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0.7, 0, 0);
- AddNode(0.35, 0, 0.35);
- TgxLinesNode(Nodes[0]).Color.color := clrRed;
- TgxLinesNode(Nodes[1]).Color.color := clrRed;
- AddNode(0.35, 0, 0.35);
- AddNode(0, 0, 0.7);
- TgxLinesNode(Nodes[2]).Color.color := clrBlue;
- TgxLinesNode(Nodes[3]).Color.color := clrBlue;
- AddNode(0, 0, 0.5);
- AddNode(0.25, 0, 0.25);
- TgxLinesNode(Nodes[4]).Color.color := clrBlue;
- TgxLinesNode(Nodes[5]).Color.color := clrBlue;
- AddNode(0.25, 0, 0.25);
- AddNode(0.5, 0, 0);
- TgxLinesNode(Nodes[6]).Color.color := clrRed;
- TgxLinesNode(Nodes[7]).Color.color := clrRed;
- FUIScalePlaneXZ := TgxGizmoExUIPolyGon(addnewChild(TgxGizmoExUIPolyGon));
- with FUIScalePlaneXZ do
- begin
- with Material do
- begin
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- AddNode(0.7, 0, 0);
- AddNode(0.35, 0, 0.35);
- AddNode(0, 0, 0.7);
- AddNode(0, 0, 0.5);
- AddNode(0.25, 0, 0.25);
- AddNode(0.5, 0, 0);
- end;
- // Raycast pickable object
- FUIICScaleLineXZ := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineXZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- turnAngle := -45;
- pitchAngle := 90;
- Height := 0.8;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.1;
- position.SetPoint(0.3, 0, 0.3);
- end;
- end;
- FUIScaleLineYZ := TgxGizmoExUILines(FUIRootScale.addnewChild(TgxGizmoExUILines));
- with FUIScaleLineYZ do
- begin
- Options := [loUseNodeColorForLines];
- SplineMode := lsmSegments;
- LineColor.Color := clrRed;
- LineWidth := 1;
- NodesAspect := lnaInvisible;
- AddNode(0, 0.7, 0);
- AddNode(0, 0.35, 0.35);
- TgxLinesNode(Nodes[0]).Color.color := clrLime;
- TgxLinesNode(Nodes[1]).Color.color := clrLime;
- AddNode(0, 0.35, 0.35);
- AddNode(0, 0, 0.7);
- TgxLinesNode(Nodes[2]).Color.color := clrBlue;
- TgxLinesNode(Nodes[3]).Color.color := clrBlue;
- AddNode(0, 0, 0.5);
- AddNode(0, 0.25, 0.25);
- TgxLinesNode(Nodes[4]).Color.color := clrBlue;
- TgxLinesNode(Nodes[5]).Color.color := clrBlue;
- AddNode(0, 0.25, 0.25);
- AddNode(0, 0.5, 0);
- TgxLinesNode(Nodes[6]).Color.color := clrLime;
- TgxLinesNode(Nodes[7]).Color.color := clrLime;
- FUIScalePlaneYZ := TgxGizmoExUIPolyGon(addnewChild(TgxGizmoExUIPolyGon));
- with FUIScalePlaneYZ do
- begin
- with Material do
- begin
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- AddNode(0, 0.7, 0);
- AddNode(0, 0.35, 0.35);
- AddNode(0, 0, 0.7);
- AddNode(0, 0, 0.5);
- AddNode(0, 0.25, 0.25);
- AddNode(0, 0.5, 0);
- end;
- // Raycast pickable object
- FUIICScaleLineYZ := TgxGizmoExUIFrustrum(AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineYZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- pitchAngle := 45;
- Height := 0.8;
- ApexHeight := 8;
- BaseDepth := 0.1;
- BaseWidth := 0.1;
- position.SetPoint(0, 0.3, 0.3);
- end;
- end;
- FUIScalePlaneXYZ := TgxGizmoExUIPolyGon(FUIRootScale.addnewChild(TgxGizmoExUIPolyGon));
- with FUIScalePlaneXYZ do
- begin
- with Material do
- begin
- MaterialOptions := [moNoLighting];
- BlendingMode := bmTransparency;
- FrontProperties.Diffuse.Color := clrYellow;
- FrontProperties.Diffuse.Alpha := 0;
- end;
- AddNode(0.5, 0, 0);
- AddNode(0, 0.5, 0);
- AddNode(0, 0, 0.5);
- AddNode(0.5, 0, 0);
- // Raycast pickable object
- FUIICScaleLineXYZ := TgxGizmoExUIFrustrum(FUIRootScale.AddNewChild(TgxGizmoExUIFrustrum));
- with FUIICScaleLineXYZ do
- begin
- Material.MaterialOptions := [moNoLighting];
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Color := clrYellow;
- Material.FrontProperties.Diffuse.Alpha := 0;
- turnAngle := -45;
- rollAngle := 35;
- Height := 0.5;
- ApexHeight := 0.6;
- BaseDepth := 0.6;
- BaseWidth := 0.05;
- position.SetPoint(0.15, 0.2, 0.15);
- end;
- end;
- FUIScaleArrowX := TgxGizmoExUISphere(FUIRootScale.addnewChild(TgxGizmoExUISphere));
- with FUIScaleArrowX do
- begin
- Slices := 8;
- Stacks := 2;
- Radius := 0.04;
- Position.X := 1;
- with material do
- begin
- MaterialOptions := [moNoLighting];
- FrontProperties.Diffuse.Color := clrRed;
- end;
- end;
- FUIScaleArrowY := TgxGizmoExUISphere(FUIRootScale.addnewChild(TgxGizmoExUISphere));
- with FUIScaleArrowY do
- begin
- Slices := 8;
- Stacks := 2;
- Radius := 0.04;
- Position.Y := 1;
- with material do
- begin
- //FaceCulling := fcNoCull;
- // FrontProperties.PolygonMode := pmFill;
- // BackProperties.PolygonMode := pmFill;
- MaterialOptions := [moNoLighting];
- FrontProperties.Diffuse.Color := clrLime;
- //FrontProperties.Emission.Color := clrLime;
- end;
- end;
- FUIScaleArrowZ := TgxGizmoExUISphere(FUIRootScale.addnewChild(TgxGizmoExUISphere));
- with FUIScaleArrowZ do
- begin
- Slices := 8;
- Stacks := 2;
- Radius := 0.04;
- Position.Z := 1;
- with material do
- begin
- // FaceCulling := fcNoCull;
- //FrontProperties.PolygonMode := pmFill;
- //BackProperties.PolygonMode := pmFill;
- MaterialOptions := [moNoLighting];
- FrontProperties.Diffuse.Color := clrBlue;
- //FrontProperties.Emission.Color := clrBlue;
- end;
- end;
- //For Axis
- FUIAxisLabelX := TgxGizmoExUIFlatText(FUIRootAxisLabel.AddNewChild(TgxGizmoExUIFlatText));
- with FUIAxisLabelX do
- begin
- ModulateColor.Color := clrRed;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.X := 1.3;
- Scale.X := 0.015;
- Scale.Y := 0.015;
- Text := 'X';
- end;
- FUIAxisLabelY := TgxGizmoExUIFlatText(FUIRootAxisLabel.AddNewChild(TgxGizmoExUIFlatText));
- with FUIAxisLabelY do
- begin
- ModulateColor.Color := clrLime;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.Y := 1.3;
- Scale.X := 0.015;
- Scale.Y := 0.015;
- Text := 'Y';
- end;
- FUIAxisLabelZ := TgxGizmoExUIFlatText(FUIRootAxisLabel.AddNewChild(TgxGizmoExUIFlatText));
- with FUIAxisLabelZ do
- begin
- ModulateColor.Color := clrBlue;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.Z := 1.3;
- Scale.X := 0.015;
- Scale.Y := 0.015;
- Text := 'Z';
- end;
- FUIVisibleInfoLabels := TgxGizmoExUIFlatText(FUIRootVisibleInfoLabels.AddNewChild(TgxGizmoExUIFlatText));
- with FUIVisibleInfoLabels do
- begin
- ModulateColor.Color := clrYellow;
- Alignment := taCenter;
- Layout := tlCenter;
- Options := Options + [ftoTwoSided];
- Position.Y := 1.8;
- Position.X := 0;
- Scale.X := 0.01;
- Scale.Y := 0.01;
- Text := '';
- end;
- HistoryStepsCount := 30;
- BoundingBoxColor.Color := clrWhite;
- VisibleInfoLabelsColor.Color := clrYellow;
- SelectedColor.Color := clrYellow;
- SelectionRegionColor.Color := clrBlack;
- ShowAxisLabel := True;
- ShowObjectInfos := True;
- ShowBoundingBox := True;
- FReferenceCoordSystem := rcsView;
- FEnableHistory := True;
- FinfoLabelCoordType := ilcChangeRate;
- AntiAliasedLines := True;
- FOperation := gopNone;
- FSelAxis := gaNone;
- EnableMultiSelection := True;
- FSelectionRegion := gsrRectangular;
- EnableLoopCursorMoving := True;
- FUIRootHelpers.Visible := False;
- OperationMode := gomSelect;
- FVisibleVisibleInfoLabels := FVisibleVisibleInfoLabels + [vliName, vliOperation, vliCoords];
- GizmoThickness := 1;
- AutoZoom := True;
- AutoZoomFactor := 5.0;
- ZoomFactor := 0.35;
- Enabled := True;
- FNoZWrite := True;
- FExcludeObjectsList := TStringList.Create;
- FExcludeClassNameList := TStringList.Create;
- end;
- destructor TgxGizmoEx.Destroy;
- begin
- if Assigned(FRootGizmo) then
- FRootGizmo.DeleteChildren
- else
- begin
- FUIBaseGizmo.DeleteChildren;
- FUIBaseGizmo.Free;
- end;
- FRootObjects := nil;
- FGizmoTmpRoot := nil;
- FBoundingBoxColor.Free;
- SelectionRegionColor.Free;
- FSelectedObjects.Free;
- FSelectedColor.Free;
- FVisibleInfoLabelsColor.Free;
- FExcludeObjectsList.Free;
- FExcludeClassNameList.Free;
- // FUndoHistory has to be nil before Notification() is called.
- FreeAndNil(FHistory);
- inherited Destroy;
- end;
- procedure TgxGizmoEx.SetVisible(const AValue: Boolean);
- begin
- FUIBaseGizmo.Visible := AValue;
- end;
- function TgxGizmoEx.GetVisible: Boolean;
- begin
- Result := FUIBaseGizmo.Visible;
- end;
- procedure TgxGizmoEx.SetSelectionRegion(const AValue: TgxGizmoExSelectionRegion);
- begin
- if FSelectionRegion <> AValue then
- FSelectionRegion := AValue;
- end;
- procedure TgxGizmoEx.SetShowAxisLabel(const AValue: Boolean);
- begin
- if FShowAxisLabel <> AValue then
- begin
- FShowAxisLabel := AValue;
- FUIRootRotateAxisLabel.Visible := AValue;
- if FOperationMode <> gomRotate then
- FUIRootAxisLabel.Visible := AValue;
- end;
- end;
- procedure TgxGizmoEx.SetSelAxis(aValue: TgxGizmoExAxis);
- begin
- if FSelAxis <> aValue then
- begin
- FSelAxis := aValue;
- if Assigned(OnAxisSelected) then
- OnAxisSelected(self, FSelAxis);
- end;
- end;
- procedure TgxGizmoEx.SetPickMode(APickMode: TgxGizmoExPickMode);
- begin
- if APickMode <> FPickMode then
- FPickMode := APickMode;
- end;
- procedure TgxGizmoEx.SetAutoZoomFactor(const AValue: Single);
- begin
- if (FAutoZoomFactor <> AValue) and (AValue > 0) then
- begin
- FAutoZoomFactor := AValue;
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetZoomFactor(const AValue: Single);
- begin
- if (FZoomFactor <> AValue) and (AValue > 0) then
- begin
- FZoomFactor := AValue;
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetShowObjectInfos(const AValue: Boolean);
- begin
- if FShowObjectInfos <> AValue then
- begin
- FShowObjectInfos := AValue;
- FUIRootVisibleInfoLabels.Visible := FShowObjectInfos;
- end;
- end;
- procedure TgxGizmoEx.SetShowBoundingBox(const AValue: Boolean);
- begin
- if FShowBoundingBox <> AValue then
- FShowBoundingBox := AValue;
- end;
- function TgxGizmoEx.GetPickList: TgxPickList;
- begin
- Result := FSelectedObjects;
- end;
- procedure TgxGizmoEx.SetPickList(aValue: TgxPickList);
- var
- I: Integer;
- begin
- if FSelectedObjects <> aValue then
- if aValue.Count - 1 >= 0 then
- begin
- FSelectedObjects.Clear;
- for I := 0 to aValue.Count - 1 do
- with aValue do
- FSelectedObjects.AddHit(hit[I], SubObjects[I], NearDistance[I], FarDistance[I]);
- UpdateGizmo();
- end
- else
- LooseSelection();
- end;
- procedure TgxGizmoEx.SetSelectedObj(const Value: TgxBaseSceneObject);
- begin
- if FSelectedObjects.FindObject(Value) <> -1 then
- Exit;
- if (FSelectedObjects.Count - 1 >= 0) or (Value = nil) then
- ClearSelection;
- if Value <> nil then
- FSelectedObjects.AddHit(Value, nil, 0, 0);
- UpdateGizmo();
- end;
- function TgxGizmoEx.GetSelectedObj: TgxBaseSceneObject;
- begin
- Result := nil;
- if FSelectedObjects.Count - 1 = -1 then
- Result := nil
- else
- if FSelectedObjects.Count - 1 >= 0 then
- Result := TgxBaseSceneObject(FSelectedObjects.Hit[0]);
- end;
- procedure TgxGizmoEx.AddObjToSelectionList(Obj: TgxBaseSceneObject);
- begin
- if (Obj <> nil) and (FSelectedObjects.FindObject(Obj) = -1) then
- FSelectedObjects.AddHit(Obj, nil, 0, 0);
- end;
- procedure TgxGizmoEx.RemoveObjFromSelectionList(Obj: TgxBaseSceneObject);
- var
- I: Integer;
- begin
- I := FSelectedObjects.FindObject(Obj);
- if I <> -1 then
- FSelectedObjects.Delete(I);
- end;
- procedure TgxGizmoEx.AssignPickList(aList: TgxPickList; RemoveObj: Boolean = False);
- function WithOutGizmoElements(obj: TgxBaseSceneObject): Boolean;
- begin
- if (obj <> FInterfaceRender) and (obj <> FInternalRender) and
- not(obj is TgxGizmoExUISphere) and not(obj is TgxGizmoExUIPolygon) and
- not(obj is TgxGizmoExUITorus) and not(obj is TgxGizmoExUIFrustrum) and
- not(obj is TgxGizmoExUIArrowLine) and not(obj is TgxGizmoExUILines) and
- not(obj is TgxGizmoExUIDisk) and not(obj is TgxGizmoExUIFlatText) and
- not(CheckObjectInExcludeList(obj)) and
- not(CheckClassNameInExcludeList(obj)) then
- Result := True
- else
- Result := False;
- end;
- var
- I: Integer;
- begin
- for I := 0 to aList.Count - 1 do
- with aList do
- if WithOutGizmoElements(TgxBaseSceneObject(hit[I])) then
- if not RemoveObj then
- begin
- if (hit[I] <> nil) and (FSelectedObjects.FindObject(hit[I]) = -1) then
- FSelectedObjects.AddHit(hit[I], SubObjects[I], NearDistance[I],
- FarDistance[I]);
- end
- else if (hit[I] <> nil) and (FSelectedObjects.FindObject(hit[I]) <> -1)
- then
- FSelectedObjects.Delete(FSelectedObjects.FindObject(hit[I]));
- end;
- procedure TgxGizmoEx.InterfaceRender(Sender: TObject; var rci: TgxRenderContextInfo);
- procedure cLine(glc: TgxCanvas; p1, p2: TPoint);
- begin
- glc.Line(p1.X, p1.Y, p2.X, p2.Y);
- end;
- var
- glc: TgxCanvas;
- I: Integer;
- LastCurPosX, LastCurPosY, CurPosX, CurPosY: Single;
- begin
- if (not Enabled) or (RootGizmo = nil) or (RootObjects = nil) then
- Exit;
- //here takes place rendering of lines and circles on canvas
- //according to modes, it's a pity that canvas has restrictions
- if FShowMultiSelecting then
- begin
- glc := TgxCanvas.Create(Round(Viewer.Width), Round(Viewer.Height));
- glc.PenColor := FSelectionRegionColor.AsWinColor;
- glc.PenWidth := 1;
- LastCurPosX := fLastCursorPos.X;
- LastCurPosY := fLastCursorPos.Y;
- CurPosX := fCursorPos.X;
- CurPosY := fCursorPos.Y;
- with glc do
- case FSelectionRegion of
- gsrRectangular: FrameRect(LastCurPosX, LastCurPosY, CurPosX, CurPosY);
- gsrCircular: Ellipse(LastCurPosX, LastCurPosY,
- MaxFloat(abs(CurPosX - LastCurPosX),
- abs(CurPosY - LastCurPosY)));
- gsrFence:
- begin
- for I := Low(FSelectionRec) to High(FSelectionRec) do
- if I <> High(FSelectionRec) then
- cLine(glc, FSelectionRec[I], FSelectionRec[I + 1])
- else
- cLine(glc, FSelectionRec[I], fcursorPos);
- //glc.PenWidth thickness of rectangle
- //it's necessary to show that the begining and the end
- // of a figure are joining and when cursor is near begining of array
- // then appears square, that show to user that he picked right object
- if High(FSelectionRec) > 0 then
- with FSelectionRec[Low(FSelectionRec)] do
- if IsInRange(CurPosX, X + 2, X - 2) and IsInRange(CurPosY, Y + 2, Y - 2) then
- FillRect(CurPosX - PenWidth - 2, CurPosY - PenWidth - 2,
- CurPosX + PenWidth + 2, CurPosY + PenWidth + 2);
- end;
- gsrLasso:
- begin
- //here showing arrays of lines
- //when additional line formed by begining and and of array
- for I := Low(FSelectionRec) to High(FSelectionRec) do
- if I <> High(FSelectionRec) then
- cLine(glc, FSelectionRec[I], FSelectionRec[I + 1])
- else
- cLine(glc, FSelectionRec[I], FSelectionRec[Low(FSelectionRec)]);
- end;
- end;
- glc.Destroy;
- end;
- end;
- procedure TgxGizmoEx.InternalRender(Sender: TObject; var rci: TgxRenderContextInfo);
- procedure ShowBoundingBox(aObject: TgxBaseSceneObject);
- const
- ACorners: array [0..7, 0..2] of Byte = ((1, 3, 4),
- (0, 2, 5),
- (1, 6, 3),
- (0, 2, 7),
- (0, 5, 7),
- (1, 4, 6),
- (2, 5, 7),
- (3, 4, 6));
- var
- I, J: Byte;
- BB: THmgBoundingBox;
- AVector: TVector4f;
- begin
- if aObject = nil then
- Exit;
- BB := aObject.BoundingBoxAbsolute(False);
- for I := 0 to 7 do
- begin
- for J := 0 to 2 do
- begin
- AVector := VectorSubtract(BB.BBox[ACorners[I][J]], BB.BBox[I]);
- AVector := VectorScale(AVector, 0.25);
- AVector := VectorAdd(AVector, BB.BBox[I]);
- glBegin(GL_LINES);
- glVertex3f(BB.BBox[I].X, BB.BBox[I].Y, BB.BBox[I].Z);
- glVertex3f(AVector.X, AVector.Y, AVector.Z);
- glEnd;
- end;
- end;
- end;
- //test#12 result is positive, but only for 2d
- procedure ShowText(const Text: UnicodeString; Position: TVector4f; Scale: TVector4f; Color: TVector4f);
- var
- FLayout: TgxTextLayout;
- FAlignment: TAlignment;
- wm: TMatrix4f;
- I, J: Integer;
- begin
- if not Assigned(FLabelFont) and (Text = '') then
- Exit;
- rci.gxStates.Enable(stDepthTest);
- FLayout := tlCenter;
- FAlignment := taCenter;
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix;
- wm := rci.PipelineTransformation.ViewMatrix^;
- TransposeMatrix(wm);
- for I := 0 to 2 do
- for J := 0 to 2 do
- if I = J then
- wm.V[I].V[J] := 1
- else
- wm.V[I].V[J] := 0;
- glLoadMatrixf(@wm);
- rci.gxStates.PolygonMode := pmFill;
- glScalef(Scale.X, Scale.Y, Scale.Z);
- glTranslatef(Position.X, Position.Y, Position.Z);
- if Color.W <> 1 then
- begin
- rci.gxStates.Enable(stBlend);
- rci.gxStates.SetBlendFunc(bfSrcAlpha, bfOneMinusSrcAlpha);
- end;
- rci.gxStates.Disable(stDepthTest);
- rci.gxStates.Disable(stCullFace);
- FLabelFont.RenderString(rci, Text, FAlignment, FLayout, Color);
- glPopMatrix;
- end;
- var
- I: Integer;
- begin
- if (not Enabled) or (RootGizmo = nil) or (RootObjects = nil) then
- Exit;
- if FShowBoundingBox and (FSelectedObjects.Count - 1 >= 0) then
- begin
- rci.gxStates.Disable(stLighting);
- if FAntiAliasedLines then
- rci.gxStates.Enable(stLineSmooth);
- if (FGizmoThickness >= 0.5) and (FGizmoThickness <= 7) then
- rci.gxStates.LineWidth := FGizmoThickness
- else
- rci.gxStates.LineWidth := 1;
- glColorMaterial(GL_FRONT, GL_EMISSION);
- rci.gxStates.Enable(stColorMaterial);
- glColor4fv(@FBoundingBoxColor.Color);
- for I := 0 to FSelectedObjects.Count - 1 do
- ShowBoundingBox(TgxBaseSceneObject(FSelectedObjects.Hit[I]));
- end;
- rci.gxStates.Disable(stColorMaterial);
- end;
- procedure TgxGizmoEx.SetReferenceCoordSystem(aValue: TgxGizmoExReferenceCoordinateSystem);
- begin
- if FReferenceCoordSystem <> aValue then
- begin
- FReferenceCoordSystem := aValue;
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetHistoryStepsCount(aValue: Integer);
- begin
- if (FHistoryStepsCount <> aValue) and (aValue > 5) then
- begin
- FHistoryStepsCount := aValue;
- FHistory.FItemsMaxCount := aValue;
- end;
- end;
- procedure TgxGizmoEx.SetCanChangeWithChildren(AValue: Boolean);
- begin
- if FCanChangeWithChildren <> AValue then
- FCanChangeWithChildren := AValue;
- end;
- procedure TgxGizmoEx.SetAALines(aValue: Boolean);
- begin
- if FAntiAliasedLines <> aValue then
- begin
- FAntiAliasedLines := aValue;
- FUISelectLineX.AntiAliased := aValue;
- FUISelectLineY.AntiAliased := aValue;
- FUISelectLineZ.AntiAliased := aValue;
- FUIMovementLineX.AntiAliased := aValue;
- FUIMovementLineY.AntiAliased := aValue;
- FUIMovementLineZ.AntiAliased := aValue;
- FUIMovementLineXY.AntiAliased := aValue;
- FUIMovementLineXZ.AntiAliased := aValue;
- FUIMovementLineYZ.AntiAliased := aValue;
- FUIRotateLineX.AntiAliased := aValue;
- FUIRotateLineY.AntiAliased := aValue;
- FUIRotateLineZ.AntiAliased := aValue;
- FUIrotateLineXY.AntiAliased := aValue;
- FUIRotateLineXZ.AntiAliased := aValue;
- FUIRotateLineArrowX.AntiAliased := aValue;
- FUIRotateLineArrowY.AntiAliased := aValue;
- FUIRotateLineArrowZ.AntiAliased := aValue;
- FUIScaleLineX.AntiAliased := aValue;
- FUIScaleLineY.AntiAliased := aValue;
- FUIScaleLineZ.AntiAliased := aValue;
- FUIScaleLineXY.AntiAliased := aValue;
- FUIScaleLineXZ.AntiAliased := aValue;
- FUIScaleLineYZ.AntiAliased := aValue;
- end;
- end;
- procedure TgxGizmoEx.SetInfoLabelCoordType(aValue: TInfoLabelCoordType);
- begin
- if fInfoLabelCoordType <> aValue then
- begin
- fInfoLabelCoordType := aValue;
- UpdateVisibleInfoLabels;
- end;
- end;
- procedure TgxGizmoEx.SetAngleDisk(aAngle: Single);
- var
- Disk1alpha, Disk2alpha, Disk1Angle, Disk2Angle: Single;
- begin
- Disk1alpha := 0;
- Disk2alpha := 0;
- Disk1Angle := 0;
- Disk2Angle := 0;
- if aAngle = 0 then
- begin
- fchangerate := NullVector;
- FUIRotateDiskX.SweepAngle := 0;
- FUIRotateDiskY.SweepAngle := 0;
- FUIRotateDiskZ.SweepAngle := 0;
- FUIRotateDiskX.Material.FrontProperties.Diffuse.Alpha := 0;
- FUIRotateDiskY.Material.FrontProperties.Diffuse.Alpha := 0;
- FUIRotateDiskZ.Material.FrontProperties.Diffuse.Alpha := 0;
- FUIRotateDiskX2.SweepAngle := 0;
- FUIRotateDiskY2.SweepAngle := 0;
- FUIRotateDiskZ2.SweepAngle := 0;
- FUIRotateDiskX2.Material.FrontProperties.Diffuse.Alpha := 0;
- FUIRotateDiskY2.Material.FrontProperties.Diffuse.Alpha := 0;
- FUIRotateDiskZ2.Material.FrontProperties.Diffuse.Alpha := 0;
- end
- else
- if (abs(aAngle) > 0) and (abs(aAngle) <= 360) then
- begin
- Disk1alpha := 0.3;
- Disk2alpha := 0;
- Disk1Angle := aAngle;
- Disk2Angle := 0;
- end
- else
- if (abs(aAngle) > 360) and (abs(aAngle) <= 720) then
- begin
- Disk1alpha := 0.3;
- Disk2alpha := 0.3;
- Disk1Angle := 360;
- if aAngle > 0 then
- Disk2Angle := aAngle - 360
- else
- Disk2Angle := aAngle + 360;
- end
- else
- if (abs(aAngle) > 720) and (abs(aAngle) <= 1080) then
- begin
- Disk1alpha := 0.5;
- Disk2alpha := 0.3;
- Disk1Angle := 360;
- if aAngle > 0 then
- Disk2Angle := aAngle - 720
- else
- Disk2Angle := aAngle + 720;
- end
- else
- if (abs(aAngle) > 1080) and (abs(aAngle) <= 1440) then
- begin
- Disk1alpha := 0.6;
- Disk2alpha := 0.3;
- Disk1Angle := 360;
- if aAngle > 0 then
- Disk2Angle := aAngle - 1080
- else
- Disk2Angle := aAngle + 1080;
- end
- else
- if (abs(aAngle) > 1440) then
- begin
- Disk1alpha := 0.6;
- Disk2alpha := 0.3;
- Disk1Angle := 360;
- Disk2Angle := 360;
- end;
- case SelAxis of
- gaX:
- begin
- FUIRotateDiskX.SweepAngle := Disk1Angle;
- FUIRotateDiskX.Material.FrontProperties.Diffuse.Alpha := Disk1alpha;
- FUIRotateDiskX2.SweepAngle := Disk2Angle;
- FUIRotateDiskX2.Material.FrontProperties.Diffuse.Alpha := Disk2alpha;
- end;
- gaY:
- begin
- FUIRotateDiskY.SweepAngle := Disk1Angle;
- FUIRotateDiskY.Material.FrontProperties.Diffuse.Alpha := Disk1alpha;
- FUIRotateDiskY2.SweepAngle := Disk2Angle;
- FUIRotateDiskY2.Material.FrontProperties.Diffuse.Alpha := Disk2alpha;
- end;
- gaZ:
- begin
- FUIRotateDiskZ.SweepAngle := Disk1Angle;
- FUIRotateDiskZ.Material.FrontProperties.Diffuse.Alpha := Disk1alpha;
- FUIRotateDiskZ2.SweepAngle := Disk2Angle;
- FUIRotateDiskZ2.Material.FrontProperties.Diffuse.Alpha := Disk2alpha;
- end;
- end;
- end;
- procedure TgxGizmoEx.SetBoundingBoxColor(const AValue: TGColor);
- begin
- if AValue <> FBoundingBoxColor then
- begin
- FBoundingBoxColor.Color := AValue.Color;
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetSelectedColor(const AValue: TGColor);
- begin
- if AValue <> FSelectedColor then
- begin
- FSelectedColor.Color := AValue.Color;
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetOperation(const Value: TgxGizmoExOperation);
- begin
- if FOperation <> Value then
- begin
- FOperation := Value;
- if Assigned(OnOperationChange) then
- OnOperationChange(self);
- end;
- end;
- procedure TgxGizmoEx.SetOperationMode(const Value: TgxGizmoExOperationMode);
- begin
- if FOperationMode <> Value then
- begin
- FOperationMode := Value;
- if Value = gomNone then
- begin
- Visible := False;
- Enabled := False;
- end
- else
- begin
- Visible := True;
- Enabled := True;
- end;
- if Value = gomSelect then
- FUIRootSelect.Visible := True
- else
- FUIRootSelect.Visible := False;
- if Value = gomMove then
- FUIRootMovement.Visible := True
- else
- FUIRootMovement.Visible := False;
- if Value = gomrotate then
- begin
- FUIRootAxisLabel.Visible := False;
- FUIRootRotate.Visible := True;
- end
- else
- begin
- FUIRootRotate.Visible := False;
- FUIRootAxisLabel.Visible := ShowAxisLabel;
- end;
- if Value = gomscale then
- FUIRootScale.Visible := True
- else
- FUIRootScale.Visible := False;
- if Assigned(OnOperationModeChange) then
- OnOperationModeChange(self);
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetNoZWrite(const Value: Boolean);
- begin
- if fNoZWrite <> Value then
- begin
- fNoZWrite := Value;
- //For Select
- FUISelectLineX.NoZWrite := Value;
- FUISelectLineY.NoZWrite := Value;
- FUISelectLineZ.NoZWrite := Value;
- //For Move
- FUIMovementLineX.NoZWrite := Value;
- FUIMovementLineY.NoZWrite := Value;
- FUIMovementLineZ.NoZWrite := Value;
- FUIMovementLineXY.NoZWrite := Value;
- FUIMovementLineXZ.NoZWrite := Value;
- FUIMovementLineYZ.NoZWrite := Value;
- FUIMovementArrowX.NoZWrite := Value;
- FUIMovementArrowY.NoZWrite := Value;
- FUIMovementArrowZ.NoZWrite := Value;
- FUIMovementPlaneXY.NoZWrite := Value;
- FUIMovementPlaneXZ.NoZWrite := Value;
- FUIMovementPlaneYZ.NoZWrite := Value;
- FUIICMovementLineX.NoZWrite := Value;
- FUIICMovementLineY.NoZWrite := Value;
- FUIICMovementLineZ.NoZWrite := Value;
- FUIICMovementLineXY.NoZWrite := Value;
- FUIICMovementLineXZ.NoZWrite := Value;
- FUIICMovementLineYZ.NoZWrite := Value;
- //ForRotate
- FUIRotateLineX.NoZWrite := Value;
- FUIRotateLineY.NoZWrite := Value;
- FUIRotateLineZ.NoZWrite := Value;
- FUIRotateLineXY.NoZWrite := Value;
- FUIRotateLineXZ.NoZWrite := Value;
- FUIICRotateTorusX.NoZWrite := Value;
- FUIICRotateTorusY.NoZWrite := Value;
- FUIICRotateTorusZ.NoZWrite := Value;
- FUIICRotateTorusXZ.NoZWrite := Value;
- FUIRotateDiskXY.NoZWrite := Value;
- FUIRotateDiskX.NoZWrite := Value;
- FUIRotateDiskY.NoZWrite := Value;
- FUIRotateDiskZ.NoZWrite := Value;
- FUIRotateDiskX2.NoZWrite := Value;
- FUIRotateDiskY2.NoZWrite := Value;
- FUIRotateDiskZ2.NoZWrite := Value;
- FUIICRotateSphereXY.NoZWrite := Value;
- FUIRotateLineArrowX.NoZWrite := Value;
- FUIRotateLineArrowY.NoZWrite := Value;
- FUIRotateLineArrowZ.NoZWrite := Value;
- FUIRotateAxisLabelX.NoZWrite := Value;
- FUIRotateAxisLabelY.NoZWrite := Value;
- FUIRotateAxisLabelZ.NoZWrite := Value;
- //ForScale
- FUIScaleArrowX.NoZWrite := Value;
- FUIScaleArrowY.NoZWrite := Value;
- FUIScaleArrowZ.NoZWrite := Value;
- FUIScaleLineX.NoZWrite := Value;
- FUIScaleLineY.NoZWrite := Value;
- FUIScaleLineZ.NoZWrite := Value;
- FUIScaleLineXY.NoZWrite := Value;
- FUIScaleLineYZ.NoZWrite := Value;
- FUIScaleLineXZ.NoZWrite := Value;
- FUIICScaleLineX.NoZWrite := Value;
- FUIICScaleLineY.NoZWrite := Value;
- FUIICScaleLineZ.NoZWrite := Value;
- FUIICScaleLineXY.NoZWrite := Value;
- FUIICScaleLineXZ.NoZWrite := Value;
- FUIICScaleLineYZ.NoZWrite := Value;
- FUIICScaleLineXYZ.NoZWrite := Value;
- FUIScalePlaneXY.NoZWrite := Value;
- FUIScalePlaneXZ.NoZWrite := Value;
- FUIScalePlaneYZ.NoZWrite := Value;
- FUIScalePlaneXYZ.NoZWrite := Value;
- FUIAxisLabelX.NoZWrite := Value;
- FUIAxisLabelY.NoZWrite := Value;
- FUIAxisLabelZ.NoZWrite := Value;
- FUIVisibleInfoLabels.NoZWrite := Value;
- end;
- end;
- procedure TgxGizmoEx.SetEnableLoopCursorMoving(const AValue: Boolean);
- begin
- if FEnableLoopCursorMoving <> AValue then
- FEnableLoopCursorMoving := AValue;
- end;
- procedure TgxGizmoEx.SetEnableMultiSelection(const AValue: Boolean);
- begin
- if FEnableMultiSelection <> AValue then
- begin
- FEnableMultiSelection := AValue;
- FInterfaceRender.Visible := AValue;
- end;
- end;
- procedure TgxGizmoEx.MultiSelMouseDown(X, Y: Integer);
- begin
- flastcursorPos := Point(X, Y);
- fcursorPos := point(X, Y);
- if (fSelectionRegion = gsrFence) and FShowMultiSelecting then
- begin
- SetLength(FSelectionRec, Length(FSelectionRec) + 1);
- FSelectionRec[high(FSelectionRec)] := point(X, Y);
- end;
- end;
- procedure TgxGizmoEx.MultiSelMouseMove(X, Y: Integer);
- begin
- //calculation starts when the mouse button is down
- //ans distance from pick pisition is not more then 10
- if Moving and not FShowMultiSelecting and
- (Dist(point(X, Y), flastcursorPos) > 10) then
- begin
- FShowMultiSelecting := True;
- if fSelectionRegion = gsrFence then
- begin
- SetLength(FSelectionRec, Length(FSelectionRec) + 1);
- FSelectionRec[high(FSelectionRec)] := point(X, Y);
- end;
- end;
- if FShowMultiSelecting then
- begin
- fcursorPos := point(X, Y);
- //creating lines when moving mouse
- if (fSelectionRegion = gsrLasso) and
- //clculate distance between two points to view as in 3D Max
- (Dist(point(X, Y), flastcursorPos) > 20) then
- begin
- flastcursorPos := point(X, Y);
- SetLength(FSelectionRec, Length(FSelectionRec) + 1);
- FSelectionRec[high(FSelectionRec)] := point(X, Y);
- end;
- end;
- end;
- procedure TgxGizmoEx.MultiSelMouseUp(X, Y: Integer);
- procedure SelectAssignMode(pick: TgxPickList);
- begin
- if not FCanRemoveObjFromSelectionList and not FCanAddObjtoSelectionList then
- AssignPickList(pick)
- else
- if FCanRemoveObjFromSelectionList then
- AssignPickList(pick, FCanRemoveObjFromSelectionList)
- else
- if FCanAddObjtoSelectionList then
- AssignPickList(pick);
- end;
- var
- I, J: Integer;
- pick: TgxPickList;
- p1, p2: TPoint;
- Line: TgxGizmoExSelRec;
- LastCurPosX, LastCurPosY, CurPosX, CurPosY: Single;
- begin
- LastCurPosX := flastcursorPos.X;
- LastCurPosY := flastcursorPos.Y;
- CurPosX := fcursorPos.X;
- CurPosY := fcursorPos.Y;
- if (fSelectionRegion = gsrRectangular) then
- begin
- pick := InternalGetPickedObjects(X - 1, Y - 1, flastcursorPos.X + 1, flastcursorPos.Y + 1, 8);
- if not FCanRemoveObjFromSelectionList and not FCanAddObjtoSelectionList then
- FSelectedObjects.Clear;
- SelectAssignMode(pick);
- pick.Free;
- if Assigned(onSelect) then
- onSelect(self, FSelectedObjects);
- FShowMultiSelecting := False;
- end;
- if (fSelectionRegion = gsrCircular) then
- begin
- FShowMultiSelecting := False;
- if not FCanRemoveObjFromSelectionList and not FCanAddObjtoSelectionList then
- FSelectedObjects.Clear;
- for I := 0 to Round(viewer.Height) - 1 do
- if IsLineIntCirlce(Maxfloat(abs(CurPosX - LastCurPosX),
- abs(CurPosY - LastCurPosY)),
- flastcursorPos, point(0, I), point(Round(viewer.Width), I), p1, p2) >= 0 then
- if (I mod 2 = 0) then
- begin
- pick := InternalGetPickedObjects(p2.X - 1, p2.Y - 1, p1.X + 1, p1.Y + 1, 8);
- SelectAssignMode(pick);
- pick.Free;
- end;
- if Assigned(onSelect) then
- onSelect(self, FSelectedObjects);
- end;
- if (fSelectionRegion = gsrFence) and (high(FSelectionRec) > 0) then
- with FSelectionRec[Low(FSelectionRec)] do
- //verify if a pick is near point, not to seek a centre
- if IsInRange(CurPosX, X + 2, X - 2) and IsInRange(CurPosY, Y + 2, Y - 2) then
- begin
- FShowMultiSelecting := False;
- //connect the begining and end
- SetLength(FSelectionRec, Length(FSelectionRec) + 1);
- FSelectionRec[high(FSelectionRec)] := point(X, Y);
- if not FCanRemoveObjFromSelectionList and not FCanAddObjtoSelectionList then
- FSelectedObjects.Clear;
- for J := 0 to Round(viewer.Height) - 1 do
- for I := 0 to Round(viewer.Width) - 1 do
- begin
- if IsPointInPolygon(FSelectionRec, point(I, J)) then
- begin
- if not IsPointInPolygon(FSelectionRec, point(I + 1, J)) then
- begin
- SetLength(line, Length(line) + 1);
- line[high(line)] := point(I, J);
- end;
- end
- else
- if IsPointInPolygon(FSelectionRec, point(I + 1, J)) then
- begin
- SetLength(line, Length(line) + 1);
- line[high(line)] := point(I, J);
- end;
- end;
- for I := 0 to High(line) do
- if (I mod 2 = 0) then
- begin
- pick := InternalGetPickedObjects(line[I].X - 1, line[I].Y - 1, line[I + 1].X + 1, line[I + 1].Y + 1, 8);
- SelectAssignMode(pick);
- pick.Free;
- end;
- if Assigned(onSelect) then
- onSelect(self, FSelectedObjects);
- //nulling of array
- SetLength(line, 0);
- SetLength(FSelectionRec, 0);
- end;
- if (fSelectionRegion = gsrLasso) then
- begin
- FShowMultiSelecting := False;
- SetLength(FSelectionRec, Length(FSelectionRec) + 1);
- FSelectionRec[high(FSelectionRec)] := FSelectionRec[Low(FSelectionRec)];
- if not FCanRemoveObjFromSelectionList and not FCanAddObjtoSelectionList then
- FSelectedObjects.Clear;
- for J := 0 to Round(viewer.Height) - 1 do
- for I := 0 to Round(viewer.Width) - 1 do
- begin
- if IsPointInPolygon(FSelectionRec, point(I, J)) then
- begin
- if not IsPointInPolygon(FSelectionRec, point(I + 1, J)) then
- begin
- SetLength(line, Length(line) + 1);
- line[high(line)] := point(I, J);
- end;
- end
- else
- if IsPointInPolygon(FSelectionRec, point(I + 1, J)) then
- begin
- SetLength(line, Length(line) + 1);
- line[high(line)] := point(I, J);
- end;
- end;
- for I := 0 to High(line) do
- if (I mod 2 = 0) then
- begin
- pick := InternalGetPickedObjects(line[I].X - 1, line[I].Y - 1, line[I + 1].X + 1, line[I + 1].Y + 1, 8);
- SelectAssignMode(pick);
- pick.Free;
- end;
- SetLength(line, 0);
- SetLength(FSelectionRec, 0);
- if Assigned(onSelect) then
- onSelect(self, FSelectedObjects);
- end;
- end;
- procedure TgxGizmoEx.SetVisibleInfoLabelsColor(const AValue: TGColor);
- begin
- if AValue <> FSelectedColor then
- begin
- FVisibleInfoLabelsColor.Color := AValue.Color;
- FUIVisibleInfoLabels.ModulateColor.Color := AValue.Color;
- FVisibleInfoLabelsColorChanged := True;
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.SetSelectionRegionColor(const AValue: TGColor);
- begin
- if AValue <> FSelectionRegionColor then
- begin
- FSelectionRegionColor.Color := AValue.Color;
- end;
- end;
- procedure TgxGizmoEx.SetGizmoExVisibleInfoLabels(const AValue: TgxGizmoExVisibleInfoLabels);
- begin
- if AValue <> FVisibleVisibleInfoLabels then
- begin
- FVisibleVisibleInfoLabels := AValue;
- if not (csDesigning in ComponentState) then
- UpdateGizmo;
- end;
- end;
- procedure TgxGizmoEx.UndoAdd(const AObject: TObject);
- begin
- if AObject <> nil then
- FHistory.AddObject(AObject);
- end;
- procedure TgxGizmoEx.RemoveSelectedObjects;
- begin
- if not Assigned(FHistory.FGizmoTmpRoot) then
- Exit;
- FHistory.RemoveObjects(SelectedObjects);
- FHistory.AddObjects(SelectedObjects);
- UpdateGizmo();
- end;
- procedure TgxGizmoEx.SetRootGizmo(const AValue: TgxBaseSceneObject);
- begin
- if FRootGizmo <> AValue then
- begin
- if FRootGizmo <> nil then
- FRootGizmo.RemoveFreeNotification(Self);
- FRootGizmo := AValue;
- if FRootGizmo <> nil then
- FRootGizmo.FreeNotification(Self);
- FUIBaseGizmo.MoveTo(AValue);
- end;
- end;
- procedure TgxGizmoEx.SetGizmoTmpRoot(const AValue: TgxBaseSceneObject);
- begin
- if FGizmoTmpRoot <> AValue then
- begin
- if FGizmoTmpRoot <> nil then
- FGizmoTmpRoot.RemoveFreeNotification(Self);
- FGizmoTmpRoot := AValue;
- FGizmoTmpRoot.Visible := False;
- FHistory.GizmoTmpRoot := FGizmoTmpRoot;
- end;
- end;
- procedure TgxGizmoEx.SetRootObjects(const AValue: TgxBaseSceneObject);
- begin
- if fRootObjects <> AValue then
- begin
- if fRootObjects <> nil then
- fRootObjects.RemoveFreeNotification(Self);
- fRootObjects := AValue;
- end;
- end;
- procedure TgxGizmoEx.SetExcludeObjectsList(const AValue: TStrings);
- begin
- FExcludeObjectsList.Clear;
- FExcludeObjectsList.AddStrings(AValue);
- end;
- procedure TgxGizmoEx.SetExcludeClassNameList(const AValue: TStrings);
- begin
- FExcludeClassNameList.Clear;
- FExcludeClassNameList.AddStrings(AValue);
- end;
- procedure TgxGizmoEx.SetGizmoExThickness(const Value: Single);
- begin
- if (FGizmoThickness <> Value) and (Value > 0.2) then
- begin
- FGizmoThickness := Value;
- FUISelectLineX.LineWidth := 1 * Value;
- FUISelectLineY.LineWidth := 1 * Value;
- FUISelectLineZ.LineWidth := 1 * Value;
- FUIMovementLineX.LineWidth := 1 * Value;
- FUIMovementLineY.LineWidth := 1 * Value;
- FUIMovementLineZ.LineWidth := 1 * Value;
- FUIMovementLineXY.LineWidth := 1 * Value;
- FUIMovementLineXZ.LineWidth := 1 * Value;
- FUIMovementLineYZ.LineWidth := 1 * Value;
- FUIRotateLineX.LineWidth := 1 * Value;
- FUIRotateLineY.LineWidth := 1 * Value;
- FUIRotateLineZ.LineWidth := 1 * Value;
- FUIrotateLineXY.LineWidth := 1 * Value;
- FUIRotateLineXZ.LineWidth := 1 * Value;
- FUIRotateLineArrowX.LineWidth := 1 * Value;
- FUIRotateLineArrowY.LineWidth := 1 * Value;
- FUIRotateLineArrowZ.LineWidth := 1 * Value;
- FUIScaleLineX.LineWidth := 1 * Value;
- FUIScaleLineY.LineWidth := 1 * Value;
- FUIScaleLineZ.LineWidth := 1 * Value;
- FUIScaleLineXY.LineWidth := 1 * Value;
- FUIScaleLineXZ.LineWidth := 1 * Value;
- FUIScaleLineYZ.LineWidth := 1 * Value;
- end;
- end;
- //------------------------------------------------------------------------------
- procedure TgxGizmoEx.SetLabelFont(const Value: TgxCustomBitmapFont);
- begin
- if FLabelFont <> Value then
- begin
- if FLabelFont <> nil then
- FLabelFont.RemoveFreeNotification(Self);
- FLabelFont := Value;
- if FLabelFont <> nil then
- FLabelFont.FreeNotification(Self);
- FUIAxisLabelX.BitmapFont := Value;
- FUIAxisLabelY.BitmapFont := Value;
- FUIAxisLabelZ.BitmapFont := Value;
- FUIRotateAxisLabelX.BitmapFont := Value;
- FUIRotateAxisLabelY.BitmapFont := Value;
- FUIRotateAxisLabelZ.BitmapFont := Value;
- FUIVisibleInfoLabels.BitmapFont := Value;
- end;
- end;
- function TgxGizmoEx.InternalGetPickedObjects(const x1, y1, x2, y2: Integer; const guessCount: Integer): TgxPickList;
- procedure AddObjectToPicklList(const root: TgxBaseSceneObject; PickList: TgxPickList; X, Y: Integer);
- var
- t: Integer;
- dist: Single;
- rayStart, rayVector, iPoint, iNormal: TVector4f;
- begin
- SetVector(rayStart, Viewer.Camera.AbsolutePosition);
- SetVector(rayVector, Viewer.Buffer.ScreenToVector(AffineVectorMake(X, Viewer.Height - Y, 0)));
- NormalizeVector(rayVector);
- for t := 0 to root.Count - 1 do
- if root[t].Visible then
- begin
- if (root[t].RayCastIntersect(rayStart, rayVector, @iPoint, @iNormal)) and
- (VectorDotProduct(rayVector, iNormal) < 0) then
- if PickList.FindObject(root[t]) = -1 then
- begin
- dist := VectorLength(VectorSubtract(iPoint, rayStart));
- PickList.AddHit(root[t], nil, dist, 0);
- end;
- AddObjectToPicklList(root[t], PickList, X, Y);
- end;
- end;
- var
- I, J: Integer;
- minx, miny, maxx, maxy: Integer;
- begin
- case FPickMode of
- pmGetPickedObjects:
- begin
- Result := Viewer.Buffer.GetPickedObjects(rect(x1, y1, x2, y2), guessCount);
- end;
- pmRayCast:
- begin
- Result := TgxPickList.Create(psMinDepth);
- maxX := MaxInteger(x1, x2);
- maxY := MaxInteger(Y1, Y2);
- minX := MinInteger(x1, x2);
- minY := MinInteger(Y1, Y2);
- for J := minY to maxY do
- for I := minX to maxX do
- //uploading to exclude hanging of application :)
- if (I mod 4 = 0) or (J mod 4 = 0) then
- AddObjectToPicklList(RootObjects, Result, I, J);
- AddObjectToPicklList(RootGizmo, Result, round((x1 + x2) * 0.5), round((y1 + y2) * 0.5));
- end;
- else
- begin
- Result := nil;
- Assert(False, strUnknownType);
- end;
- end;
- end;
- procedure TgxGizmoEx.Loaded;
- begin
- inherited;
- SetGizmoExThickness(GizmoThickness);
- end;
- //------------------------------------------------------------------------------
- procedure TgxGizmoEx.UpdateVisibleInfoLabels;
- var
- T: string;
- X, Y, Z: Single;
- obj: TgxBaseSceneObject;
- begin
- t := '';
- X := 0;
- Y := 0;
- Z := 0;
- if FSelectedObjects.Count - 1 < 0 then
- Exit;
- if (FSelectedObjects.Count - 1 = 0) and (vliName in FVisibleVisibleInfoLabels) then
- t := TgxBaseSceneObject(FSelectedObjects[0]).Name;
- if vliOperation in FVisibleVisibleInfoLabels then
- begin
- begin
- if Length(t) > 0 then
- T := T + ' - ';
- case Operation of
- gopNone: T := T + 'Selected';
- gopMove: T := T + 'Move';
- gopRotate: T := T + 'Rotate';
- gopScale: T := T + 'Scale';
- end;
- end;
- end;
- if vliCoords in FVisibleVisibleInfoLabels then
- begin
- if (Operation <> gopNone) then
- begin
- if Length(t) > 0 then
- T := T + ' - ';
- if FinfoLabelCoordType = ilcChanging then
- begin
- obj := TgxBaseSceneObject(FSelectedObjects[0]);
- case Operation of
- gopMove:
- begin
- X := obj.Position.X;
- Y := obj.Position.Y;
- Z := obj.Position.Z;
- end;
- gopRotate:
- begin
- X := obj.Rotation.X;
- Y := obj.Rotation.Y;
- Z := obj.Rotation.Z;
- end;
- gopScale:
- begin
- X := obj.Scale.X;
- Y := obj.Scale.Y;
- Z := obj.Scale.Z;
- end;
- end;
- T := T + '[' + Format('%2.2f', [X]);
- T := T + ' ' + Format('%2.2f', [Y]);
- T := T + ' ' + Format('%2.2f', [Z]) + ']';
- end
- else
- begin
- T := T + '[' + Format('%2.2f', [FChangeRate.X]);
- T := T + ' ' + Format('%2.2f', [FChangeRate.Y]);
- T := T + ' ' + Format('%2.2f', [FChangeRate.Z]) + ']';
- end;
- end;
- end;
- FUIVisibleInfoLabels.Text := T;
- FUIVisibleInfoLabels.StructureChanged;
- end;
- //------------------------------------------------------------------------------
- function TgxGizmoEx.CheckObjectInExcludeList(const Obj: TgxBaseSceneObject): Boolean;
- var
- I: Integer;
- begin
- Result := False;
- if FExcludeObjects then
- begin
- for I := 0 to FExcludeObjectsList.Count - 1 do
- begin
- if UpperCase(obj.Name) = UpperCase(FExcludeObjectsList[I]) then
- begin
- Result := True;
- Exit;
- end;
- end;
- end;
- end;
- function TgxGizmoEx.CheckClassNameInExcludeList(const Obj: TgxBaseSceneObject): Boolean;
- var
- I: Integer;
- begin
- Result := False;
- if FExcludeClassName then
- begin
- for I := 0 to FExcludeClassNameList.Count - 1 do
- begin
- if UpperCase(obj.ClassName) = UpperCase(FExcludeClassNameList[I]) then
- begin
- Result := True;
- Exit;
- end;
- end;
- end;
- end;
- function TgxGizmoEx.MouseWorldPos(const X, Y: Integer): TVector4f;
- var
- v: TVector4f;
- InvertedY: Integer;
- begin
- InvertedY := Round(Viewer.Height) - Y;
- SetVector(v, X, InvertedY, 0);
- case selAxis of
- gaX: Viewer.Buffer.ScreenVectorIntersectWithPlaneXZ(v, FUIRootHelpers.AbsolutePosition.Y, Result);
- gaY: Viewer.Buffer.ScreenVectorIntersectWithPlaneYZ(v, FUIRootHelpers.AbsolutePosition.X, Result);
- gaZ: Viewer.Buffer.ScreenVectorIntersectWithPlaneYZ(v, FUIRootHelpers.AbsolutePosition.X, Result);
- gaXY: Viewer.Buffer.ScreenVectorIntersectWithPlaneXY(v, FUIRootHelpers.AbsolutePosition.Z, Result);
- gaYZ: Viewer.Buffer.ScreenVectorIntersectWithPlaneYZ(v, FUIRootHelpers.AbsolutePosition.X, Result);
- gaXZ: Viewer.Buffer.ScreenVectorIntersectWithPlaneXZ(v, FUIRootHelpers.AbsolutePosition.Y, Result);
- gaXYZ:
- begin
- Viewer.Buffer.ScreenVectorIntersectWithPlaneXZ(v, FUIRootHelpers.AbsolutePosition.Y, Result);
- MakeVector(Result, InvertedY / 25, InvertedY / 25, InvertedY / 25);
- end;
- end;
- end;
- procedure TgxGizmoEx.ActivatingElements(PickList: TgxPickList);
- procedure ActlightRotateLine(const line: TgxLines; const dark: TVector4f);
- var
- v: TVector4f;
- I: Integer;
- begin
- line.options := [loUseNodeColorForLines];
- for I := 0 to line.Nodes.Count - 1 do
- begin
- v := FUIRotateLineXY.AbsoluteToLocal((line.LocalToAbsolute(line.Nodes[I].AsVector)));
- if v.Z >= 0 then
- begin
- TgxLinesNode(line.Nodes[I]).Color.Color := FSelectedColor.Color;
- TgxLinesNode(line.Nodes[I]).Color.Alpha := 1;
- end
- else
- begin
- TgxLinesNode(line.Nodes[I]).Color.Color := dark;
- TgxLinesNode(line.Nodes[I]).Color.Alpha := 1;
- end;
- end;
- end;
- procedure DeActlightRotateLine(const line: TgxLines; const dark: TVector4f);
- var
- v: TVector4f;
- I: Integer;
- begin
- line.options := [loUseNodeColorForLines];
- for I := 0 to line.Nodes.Count - 1 do
- begin
- v := FUIRotateLineXY.AbsoluteToLocal((line.LocalToAbsolute(line.Nodes[I].AsVector)));
- if v.Z >= 0 then
- begin
- TgxLinesNode(line.Nodes[I]).Color.Color := dark;
- TgxLinesNode(line.Nodes[I]).Color.Alpha := 1;
- end
- else
- begin
- TgxLinesNode(line.Nodes[I]).Color.Color := dark;
- TgxLinesNode(line.Nodes[I]).Color.Alpha := 0;
- end;
- end;
- end;
- procedure ActlightLine(const line: TgxLines);
- begin
- line.LineColor.color := FSelectedColor.Color;
- line.Options := [];
- end;
- procedure DeActlightLine(const line: TgxLines; const dark: TVector4f; alterStyle: Boolean = False);
- begin
- with line.LineColor do
- if (AsWinColor = FSelectedColor.AsWinColor) then
- begin
- color := dark;
- line.Options := [];
- if alterStyle then
- line.options := [loUseNodeColorForLines];
- end;
- end;
- procedure ActlightRotateArrowLine(const line: TgxLines; Color: TVector4f);
- begin
- line.LineColor.color := Color;
- line.Options := [];
- end;
- procedure DeActlightRotateArrowLine(const line: TgxLines; const dark: TVector4f);
- begin
- if not VectorEquals(line.LineColor.Color, dark) then
- begin
- line.LineColor.Color := dark;
- line.Options := [];
- end;
- end;
- procedure Actlightobject(const aObject: TgxCustomSceneObject);
- begin
- aObject.Material.FrontProperties.Diffuse.Alpha := 0.4;
- aObject.Visible := True;
- end;
- procedure DeActlightObject(const aObject: TgxCustomSceneObject);
- begin
- aObject.Visible := False;
- end;
- procedure ActlightText(const FlatText: TgxFlatText);
- begin
- FlatText.ModulateColor.Color := FSelectedColor.Color;
- end;
- procedure DeActlightText(const FlatText: TgxFlatText; const dark: TVector4f);
- begin
- with FlatText.ModulateColor do
- if AsWinColor = FSelectedColor.AsWinColor then
- Color := dark;
- end;
- procedure ActlightTextRotate(const FlatText: TgxFlatText; Color: TVector4f);
- begin
- FlatText.ModulateColor.Color := Color;
- end;
- procedure DeActlightTextRotate(const FlatText: TgxFlatText; const dark: TVector4f);
- begin
- with FlatText.ModulateColor do
- if not VectorEquals(Color, dark) then
- Color := dark;
- end;
- procedure AssingOpertion(const aOperation: TgxGizmoExOperation; const axis: TgxGizmoExAxis);
- begin
- if Operation <> aOperation then
- Operation := aOperation;
- if SelAxis <> axis then
- SelAxis := axis;
- end;
- var
- I: Integer;
- begin
- AssingOpertion(gopNone, gaNone);
- if FUIRootMovement.Visible then
- begin
- DeActlightObject(FUIMovementPlaneXY);
- DeActlightObject(FUIMovementPlaneXZ);
- DeActlightObject(FUIMovementPlaneYZ);
- DeActlightLine(FUIMovementLineX, clrRed);
- DeActlightLine(FUIMovementLineY, clrLime);
- DeActlightLine(FUIMovementLineZ, clrBlue);
- DeActlightLine(FUIMovementLineXY, clrWhite, True);
- DeActlightLine(FUIMovementLineXZ, clrWhite, True);
- DeActlightLine(FUIMovementLineYZ, clrWhite, True);
- end;
- if FUIRootRotate.Visible then
- begin
- DeActlightObject(FUIRotateDiskXY);
- DeActlightLine(FUIRotateLineXZ, clrgray70);
- DeActlightRotateArrowLine(FUIRotateLineArrowX, clrgray70);
- DeActlightRotateArrowLine(FUIRotateLineArrowY, clrgray70);
- DeActlightRotateArrowLine(FUIRotateLineArrowZ, clrgray70);
- DeActlightRotateLine(FUIRotateLineX, clrRed);
- DeActlightRotateLine(FUIRotateLineY, clrLime);
- DeActlightRotateLine(FUIRotateLineZ, clrBlue);
- DeActlightTextRotate(FUIRotateAxisLabelX, clrgray70);
- DeActlightTextRotate(FUIRotateAxisLabelY, clrgray70);
- DeActlightTextRotate(FUIRotateAxisLabelZ, clrgray70);
- end;
- if FUIRootScale.Visible then
- begin
- DeActlightLine(FUIScaleLineX, clrRed);
- DeActlightLine(FUIScaleLineY, clrLime);
- DeActlightLine(FUIScaleLineZ, clrBlue);
- DeActlightLine(FUIScaleLineXY, clrWhite, True);
- DeActlightLine(FUIScaleLineYZ, clrWhite, True);
- DeActlightLine(FUIScaleLineXZ, clrWhite, True);
- DeActlightObject(FUIScalePlaneXY);
- DeActlightObject(FUIScalePlaneXZ);
- DeActlightObject(FUIScalePlaneYZ);
- DeActlightObject(FUIScalePlaneXYZ);
- end;
- DeActlightText(FUIAxisLabelX, clrRed);
- DeActlightText(FUIAxisLabelY, clrLime);
- DeActlightText(FUIAxisLabelZ, clrBlue);
- for I := 0 to pickList.Count - 1 do
- with pickList do
- begin
- if FUIRootMovement.Visible then
- begin
- if hit[I] = FUIICMovementLineXY then
- begin
- AssingOpertion(gopMove, gaXY);
- ActlightObject(FUIMovementPlaneXY);
- ActlightLine(FUIMovementLineX);
- ActlightLine(FUIMovementLineY);
- ActlightLine(FUIMovementLineXY);
- ActlightText(FUIAxisLabelX);
- ActlightText(FUIAxisLabelY);
- Break;
- end;
- if hit[I] = FUIICMovementLineXZ then
- begin
- AssingOpertion(gopMove, gaXZ);
- Actlightobject(FUIMovementPlaneXZ);
- ActlightLine(FUIMovementLineX);
- ActlightLine(FUIMovementLineZ);
- ActlightLine(FUIMovementLineXZ);
- ActlightText(FUIAxisLabelX);
- ActlightText(FUIAxisLabelZ);
- Break;
- end;
- if hit[I] = FUIICMovementLineYZ then
- begin
- AssingOpertion(gopMove, gaYZ);
- Actlightobject(FUIMovementPlaneYZ);
- ActlightLine(FUIMovementLineY);
- ActlightLine(FUIMovementLineZ);
- ActlightLine(FUIMovementLineYZ);
- ActlightText(FUIAxisLabelY);
- ActlightText(FUIAxisLabelZ);
- Break;
- end;
- if hit[I] = FUIICMovementLineX then
- begin
- AssingOpertion(gopMove, gaX);
- ActlightLine(FUIMovementLineX);
- ActlightText(FUIAxisLabelX);
- Break;
- end;
- if hit[I] = FUIICMovementLineY then
- begin
- AssingOpertion(gopMove, gaY);
- ActlightLine(FUIMovementLineY);
- ActlightText(FUIAxisLabelY);
- Break;
- end;
- if hit[I] = FUIICMovementLineZ then
- begin
- AssingOpertion(gopMove, gaZ);
- ActlightLine(FUIMovementLineZ);
- ActlightText(FUIAxisLabelZ);
- Break;
- end;
- end;
- if FUIRootRotate.Visible then
- begin
- if hit[I] = FUIICRotateTorusX then
- begin
- AssingOpertion(gopRotate, gaX);
- ActlightRotateLine(FUIRotateLineX, clrgray50);
- ActlightRotateArrowLine(FUIRotateLineArrowX, clrRed);
- DeActlightTextRotate(FUIRotateAxisLabelX, clrRed);
- Break;
- end;
- if hit[I] = FUIICRotateTorusY then
- begin
- AssingOpertion(gopRotate, gaY);
- ActlightRotateLine(FUIRotateLineY, clrgray50);
- ActlightRotateArrowLine(FUIRotateLineArrowY, clrLime);
- DeActlightTextRotate(FUIRotateAxisLabelY, clrLime);
- Break;
- end;
- if hit[I] = FUIICRotateTorusZ then
- begin
- AssingOpertion(gopRotate, gaZ);
- ActlightRotateLine(FUIRotateLineZ, clrgray50);
- ActlightRotateArrowLine(FUIRotateLineArrowZ, clrBlue);
- DeActlightTextRotate(FUIRotateAxisLabelZ, clrBlue);
- Break;
- end;
- if hit[I] = FUIICRotateSphereXY then
- begin
- AssingOpertion(gopRotate, gaXY);
- ActlightObject(FUIRotateDiskXY);
- DeActlightTextRotate(FUIRotateAxisLabelX, clrRed);
- DeActlightTextRotate(FUIRotateAxisLabelY, clrLime);
- ActlightRotateArrowLine(FUIRotateLineArrowX, clrRed);
- ActlightRotateArrowLine(FUIRotateLineArrowY, clrLime);
- Break;
- end;
- if hit[I] = FUIICRotateTorusXZ then
- begin
- AssingOpertion(gopRotate, gaXZ);
- ActlightLine(FUIRotateLineXZ);
- DeActlightTextRotate(FUIRotateAxisLabelX, clrRed);
- DeActlightTextRotate(FUIRotateAxisLabelZ, clrBlue);
- ActlightRotateArrowLine(FUIRotateLineArrowX, clrRed);
- ActlightRotateArrowLine(FUIRotateLineArrowZ, clrBlue);
- Break;
- end;
- end;
- if FUIRootScale.Visible then
- begin
- if hit[I] = FUIICScaleLineX then
- begin
- AssingOpertion(gopScale, gaX);
- ActlightLine(FUIScaleLineX);
- ActlightText(FUIAxisLabelX);
- Break;
- end;
- if hit[I] = FUIICScaleLineY then
- begin
- AssingOpertion(gopScale, gaY);
- ActlightLine(FUIScaleLineY);
- ActlightText(FUIAxisLabelY);
- Break;
- end;
- if hit[I] = FUIICScaleLineZ then
- begin
- AssingOpertion(gopScale, gaZ);
- ActlightLine(FUIScaleLineZ);
- ActlightText(FUIAxisLabelZ);
- Break;
- end;
- if hit[I] = FUIICScaleLineXY then
- begin
- AssingOpertion(gopScale, gaXY);
- Actlightobject(FUIScalePlaneXY);
- ActlightLine(FUIScaleLineXY);
- ActlightText(FUIAxisLabelX);
- ActlightText(FUIAxisLabelY);
- Break;
- end;
- if hit[I] = FUIICScaleLineXZ then
- begin
- AssingOpertion(gopScale, gaXZ);
- Actlightobject(FUIScalePlaneXZ);
- ActlightLine(FUIScaleLineXZ);
- ActlightText(FUIAxisLabelX);
- ActlightText(FUIAxisLabelZ);
- Break;
- end;
- if hit[I] = FUIICScaleLineYZ then
- begin
- AssingOpertion(gopScale, gaYZ);
- Actlightobject(FUIScalePlaneYZ);
- ActlightLine(FUIScaleLineYZ);
- ActlightText(FUIAxisLabelY);
- ActlightText(FUIAxisLabelZ);
- Break;
- end;
- if hit[I] = FUIICScaleLineXYZ then
- begin
- AssingOpertion(gopScale, gaXYZ);
- Actlightobject(FUIScalePlaneXYZ);
- ActlightText(FUIAxisLabelX);
- ActlightText(FUIAxisLabelY);
- ActlightText(FUIAxisLabelZ);
- Actlightobject(FUIScalePlaneXY);
- ActlightLine(FUIScaleLineXY);
- Actlightobject(FUIScalePlaneYZ);
- ActlightLine(FUIScaleLineYZ);
- Actlightobject(FUIScalePlaneXZ);
- ActlightLine(FUIScaleLineXZ);
- Break;
- end;
- end;
- end;
- end;
- procedure TgxGizmoEx.ViewerMouseMove(const X, Y: Integer);
- var
- pickList: TgxPickList;
- mousePos: TVector4f;
- includeCh: Boolean;
- function FindParent(parent: TgxBaseSceneObject): Boolean;
- begin
- Result := False;
- if assigned(parent) then
- begin
- if parent = rootobjects then
- Exit;
- Result := FSelectedObjects.FindObject(parent) = -1;
- end;
- end;
- procedure OpeMove(mousePos: TVector4f);
- var
- vec1, vec2: TVector4f;
- quantizedMousePos, quantizedMousePos2: TVector4f;
- I: Integer;
- begin
- if VectorNorm(lastMousePos) = 0 then
- Exit;
- for I := 0 to 3 do
- begin
- quantizedMousePos.V[I] := (Round(mousePos.V[I] / MoveCoef)) * MoveCoef;
- quantizedMousePos2.V[I] := (Round(lastMousePos.V[I] / MoveCoef)) * MoveCoef;
- end;
- case SelAxis of
- gaX:
- begin
- MakeVector(vec1, quantizedMousePos.X, 0, 0);
- makeVector(vec2, quantizedMousePos2.X, 0, 0);
- end;
- gaY:
- begin
- MakeVector(vec1, 0, quantizedMousePos.Y, 0);
- makeVector(vec2, 0, quantizedMousePos2.Y, 0);
- end;
- gaZ:
- begin
- MakeVector(vec1, 0, 0, quantizedMousePos.Z);
- makeVector(vec2, 0, 0, quantizedMousePos2.Z);
- end;
- else
- begin
- vec1 := quantizedMousePos;
- vec2 := quantizedMousePos2;
- end;
- end;
- SubtractVector(vec1, vec2);
- //Control of object flying to infinity
- if (VectorLength(Vec1) > 5) then
- Exit;// prevents NAN problems
- case SelAxis of
- gaX: fchangerate.X := fchangerate.X + vec1.X;
- gaY: fchangerate.Y := fchangerate.Y + vec1.Y;
- gaZ: fchangerate.Z := fchangerate.Z + vec1.Z;
- gaXY:
- begin
- fchangerate.X := fchangerate.X + vec1.X;
- fchangerate.Y := fchangerate.Y + vec1.Y;
- end;
- gaYZ:
- begin
- fchangerate.Z := fchangerate.Z + vec1.Z;
- fchangerate.Y := fchangerate.Y + vec1.Y;
- end;
- gaXZ:
- begin
- fchangerate.X := fchangerate.X + vec1.X;
- fchangerate.Z := fchangerate.Z + vec1.Z;
- end;
- end;
- for I := 0 to FSelectedObjects.Count - 1 do
- with TgxBaseSceneObject(FSelectedObjects.Hit[I]) do
- begin
- IncludeCh := True;
- if not CanChangeWithChildren and (parent <> RootObjects) and (FSelectedObjects.Count - 1 > 0) then
- IncludeCh := FindParent(parent);
- if IncludeCh then
- case Ord(ReferenceCoordSystem) of
- 0: AbsolutePosition := VectorAdd(absoluteposition, vec1);
- 1:
- begin
- vec1 := LocalToAbsolute(vec1);
- absoluteposition := VectorAdd(absoluteposition, vec1);
- end;
- end;
- end;
- end;
- procedure OpeRotate(const X, Y: Integer);
- var
- vec1: TVector4f;
- rotV: TAffineVector;
- pmat: TMatrix4f;
- I: Integer;
- IncludeCh: Boolean;
- v: TVector4f;
- begin
- vec1.X := 0;
- vec1.Y := 0;
- if abs(X - mx) >= RotationCoef then
- begin
- if RotationCoef > 1 then
- vec1.X := RotationCoef * (Round((X - mx) / (RotationCoef)))
- else
- vec1.X := RotationCoef * (X - mx);
- mx := X;
- end;
- if abs(Y - my) >= RotationCoef then
- begin
- if RotationCoef > 1 then
- vec1.Y := RotationCoef * (Round((Y - my) / (RotationCoef)))
- else
- vec1.Y := RotationCoef * (Y - my);
- my := Y;
- end;
- vec1.Z := 0;
- vec1.W := 0;
- case SelAxis of
- gaX: fchangerate.Y := fchangerate.Y + vec1.Y;
- gaY: fchangerate.X := fchangerate.X + vec1.X;
- gaZ: fchangerate.Y := fchangerate.Y + vec1.Y;
- end;
- for I := 0 to FSelectedObjects.Count - 1 do
- with FSelectedObjects do
- begin
- case Ord(FReferenceCoordSystem) of
- 0: v := FUIRootHelpers.AbsolutePosition;
- 1: v := TgxBaseSceneObject(Hit[I]).AbsolutePosition;
- end;
- IncludeCh := True;
- if not CanChangeWithChildren
- and (TgxBaseSceneObject(Hit[I]).parent <> RootObjects)
- and (FSelectedObjects.Count - 1 > 0) then
- IncludeCh := FindParent(TgxBaseSceneObject(Hit[I]).parent);
- pmat := TgxBaseSceneObject(Hit[I]).parent.InvAbsoluteMatrix;
- SetVector(pmat.W, NullHmgPoint);
- if IncludeCh then
- case SelAxis of
- gaX:
- begin
- rotV := VectorTransform(XVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.Y);
- end;
- gaY:
- begin
- rotV := VectorTransform(YVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.X);
- end;
- gaZ:
- begin
- rotV := VectorTransform(ZVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.Y);
- end;
- gaXY:
- begin
- rotV := VectorTransform(XVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.Y);
- rotV := VectorTransform(YVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.X);
- end;
- gaXZ:
- begin
- rotV := VectorTransform(XVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.Y);
- rotV := VectorTransform(ZVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.X);
- end;
- gaYZ:
- begin
- rotV := VectorTransform(YVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.Y);
- rotV := VectorTransform(ZVector, pmat);
- RotateAroundArbitraryAxis(TgxBaseSceneObject(Hit[I]), rotV, AffineVectorMake(v), vec1.X);
- end;
- end;
- end;
- end;
- procedure OpeScale(const mousePos: TVector4f);
- var
- vec1, vec2: TVector4f;
- quantizedMousePos, quantizedMousePos2: TVector4f;
- t: Integer;
- begin
- if VectorNorm(lastMousePos) = 0 then
- Exit;
- for t := 0 to 3 do
- begin
- quantizedMousePos.V[t] := (Round(mousePos.V[t] / ScaleCoef)) * FScaleCoef;
- quantizedMousePos2.V[t] := (Round(lastMousePos.V[t] / FScaleCoef)) * FScaleCoef;
- end;
- case SelAxis of
- gaX:
- begin
- MakeVector(vec1, quantizedMousePos.X, 0, 0);
- makeVector(vec2, quantizedMousePos2.X, 0, 0);
- end;
- gaY:
- begin
- MakeVector(vec1, 0, quantizedMousePos.Y, 0);
- makeVector(vec2, 0, quantizedMousePos2.Y, 0);
- end;
- gaZ:
- begin
- MakeVector(vec1, 0, 0, quantizedMousePos.Z);
- makeVector(vec2, 0, 0, quantizedMousePos2.Z);
- end;
- gaXY:
- begin
- MakeVector(vec1, quantizedMousePos.X, quantizedMousePos.Y, 0);
- makeVector(vec2, quantizedMousePos2.X, quantizedMousePos2.Y, 0);
- end;
- gaXYZ:
- begin
- MakeVector(vec1, quantizedMousePos.X, quantizedMousePos.Y, quantizedMousePos.Z);
- makeVector(vec2, quantizedMousePos2.X, quantizedMousePos2.Y, quantizedMousePos2.Z);
- end
- else
- begin
- vec1 := quantizedMousePos;
- vec2 := quantizedMousePos2;
- end;
- end;
- SubtractVector(vec1, vec2);
- if (VectorLength(Vec1) > 5) then
- Exit;// prevents NAN problems
- case SelAxis of
- gaX: fchangerate.X := fchangerate.X + vec1.X;
- gaY: fchangerate.Y := fchangerate.Y + vec1.Y;
- gaZ: fchangerate.Z := fchangerate.Z + vec1.Z;
- gaXY:
- begin
- fchangerate.X := fchangerate.X + vec1.X;
- fchangerate.Y := fchangerate.Y + vec1.Y;
- end;
- gaYZ:
- begin
- fchangerate.Z := fchangerate.Z + vec1.Z;
- fchangerate.Y := fchangerate.Y + vec1.Y;
- end;
- gaXZ:
- begin
- fchangerate.X := fchangerate.X + vec1.X;
- fchangerate.Z := fchangerate.Z + vec1.Z;
- end;
- gaXYZ:
- fchangerate := VectorAdd(fchangerate, AffineVectorMake(vec1));
- end;
- for t := 0 to FSelectedObjects.Count - 1 do
- with TgxBaseSceneObject(FSelectedObjects.Hit[t]) do
- begin
- IncludeCh := True;
- if not CanChangeWithChildren and (parent <> RootObjects) and (FSelectedObjects.Count - 1 > 0) then
- IncludeCh := FindParent(parent);
- FUIRootScale.Scale.Translate(vec1);
- if IncludeCh then
- begin
- (* case ord(ReferenceCoordSystem) of
- 0:begin
- vec1:=LocalToAbsolute(vec1);
- absoluteScale:=VectorAdd(absolutescale,vec1);
- end;
- 1:Scale.Translate(vec1);
- end; *)
- Scale.Translate(vec1);
- end;
- end;
- end;
- procedure LoopCursorMoving(isvector: Boolean = False);
- {$IFDEF MSWINDOWS}
- var
- R, vR: TRect;
- cp: TPoint;
- {$ENDIF}
- begin
- {$IFDEF MSWINDOWS}
- (* Procedure for moving the cursor from beginning to end
- without loss of operations on the object *)
- GetWindowRect(GetDesktopWindow, R);
- { TODO : E2003 Undeclared identifier: 'Handle' }
- (*GetWindowRect(viewer.Handle, VR);*)
- GLGetCursorPos(cp);
- if cp.Y = R.Bottom - 1 then
- begin
- SetCursorPos(cp.X, R.Top + 3);
- if not isvector then
- my := r.Top - vr.Top
- else
- begin
- lastMousePos := MouseWorldPos(X, r.Top + 3 - vr.Top);
- // entered so that the object does not twitch
- mousepos := lastMousePos;
- end;
- end;
- if cp.Y = R.Top then
- begin
- SetCursorPos(cp.X, R.Bottom - 3);
- if not isvector then
- my := R.Bottom - 1 - vr.top
- else
- begin
- lastMousePos := MouseWorldPos(X, R.Bottom - 1 - vr.top);
- mousepos := lastMousePos;
- end;
- end;
- if cp.X = R.Right - 1 then
- begin
- SetCursorPos(r.Left + 3, cp.Y);
- if not isvector then
- mx := r.Left - vr.Left
- else
- begin
- lastMousePos := MouseWorldPos(r.Left - vr.Left, Y);
- mousepos := lastMousePos;
- end;
- end;
- if cp.X = R.Left then
- begin
- SetCursorPos(r.Right - 3, cp.Y);
- if not isvector then
- mx := r.Right - 1 - vr.Left
- else
- begin
- lastMousePos := MouseWorldPos(r.Right - 1 - vr.Left, Y);
- mousepos := lastMousePos;
- end;
- end;
- {$ENDIF}
- end;
- begin
- if (not Enabled) or (RootGizmo = nil) or (RootObjects = nil) then
- Exit;
- if not FShowMultiSelecting then
- begin
- if (FSelectedObjects.Count - 1 >= 0) and (SelAxis <> gaNone) and moving then
- begin
- mousePos := MouseWorldPos(X, Y);
- //moving object...
- if Operation = gopMove then
- begin
- OpeMove(MousePos);
- end
- else if Operation = gopRotate then
- begin
- if EnableLoopCursorMoving then
- LoopCursorMoving;
- OpeRotate(X, Y);
- if (SelAxis = gax) or (SelAxis = gaz) then
- SetAngleDisk(fchangerate.Y)
- else
- if SelAxis = gaY then
- SetAngleDisk(fchangerate.X);
- end
- else if Operation = gopScale then
- begin
- if EnableLoopCursorMoving then
- LoopCursorMoving(True);
- OpeScale(MousePos);
- end;
- UpdateGizmo;
- mx := X;
- my := Y;
- lastMousePos := mousePos;
- Exit;
- end;
- Assert(FViewer <> nil, 'Viewer not Assigned to gizmo');
- picklist := InternalGetPickedObjects(X - 1, Y - 1, X + 1, Y + 1, 8);//Viewer.buffer.GetPickedObjects(rect(x-1, y-1, x+1, y+1), 8);
- ActivatingElements(picklist);
- picklist.Free;
- end;
- if EnableMultiSelection and (Operation = gopNone) and (SelAxis = gaNone) then
- MultiSelMouseMove(X, Y);
- mx := X;
- my := Y;
- end;
- procedure TgxGizmoEx.ViewerMouseDown(const X, Y: Integer);
- function SetInitialDiskPostition(aObject, aObject2: TgxCustomSceneObject): TVector4f;
- var
- rayStart, rayVector, iPoint, iNormal: TVector4f;
- begin
- if (Viewer = nil) then
- Exit;
- if (Viewer.Camera = nil) then
- Exit;
- SetVector(rayStart, Viewer.Camera.AbsolutePosition);
- SetVector(rayVector, Viewer.Buffer.ScreenToVector(AffineVectorMake(X, Viewer.Height - Y, 0)));
- NormalizeVector(rayVector);
- if aObject.RayCastIntersect(rayStart, rayVector, @iPoint, @iNormal) then
- aObject2.Up.Setvector(VectorNormalize(VectorSubtract(iPoint, FUIRootHelpers.Position.AsVector)));
- aObject2.StructureChanged;
- Result := iPoint;
- end;
- var
- pick: TgxPickList;
- I: Integer;
- gotPick: Boolean;
- begin
- if not Enabled or
- not Assigned(RootGizmo) or
- not Assigned(RootObjects) or
- not Assigned(Viewer) then
- Exit;
- mx := X;
- my := Y;
- pick := InternalGetPickedObjects(X - 1, Y - 1, X + 1, Y + 1);
- gotPick := False;
- for I := 0 to pick.Count - 1 do
- if (pick.Hit[I] is TgxGizmoExUIDisk) or
- (pick.Hit[I] is TgxGizmoExUISphere) or
- (pick.Hit[I] is TgxGizmoExUIPolyGon) or
- (pick.Hit[I] is TgxGizmoExuITorus) or
- (pick.Hit[I] is TgxGizmoExUIFrustrum) or
- (pick.Hit[I] is TgxGizmoExUIArrowLine) or
- (pick.Hit[I] is TgxGizmoExUIFlatText) or
- (pick.Hit[I] is TgxGizmoExUILines) then
- begin
- gotPick := True;
- case fOperation of
- gopRotate:
- begin
- if (pick.Hit[I] = FUIICRotateTorusX) then
- begin
- SetInitialDiskPostition(FUIICRotateTorusX, FUIRotateDiskx);
- SetInitialDiskPostition(FUIICRotateTorusX, FUIRotateDiskx2);
- end;
- if (pick.Hit[I] = FUIICRotateTorusY) then
- begin
- SetInitialDiskPostition(FUIICRotateTorusY, FUIRotateDiskY);
- SetInitialDiskPostition(FUIICRotateTorusY, FUIRotateDiskY2);
- end;
- if (pick.Hit[I] = FUIICRotateTorusZ) then
- begin
- SetInitialDiskPostition(FUIICRotateTorusZ, FUIRotateDiskZ);
- SetInitialDiskPostition(FUIICRotateTorusZ, FUIRotateDiskZ2);
- end;
- end;
- end;
- end;
- if not FShowMultiSelecting and not gotPick then
- begin
- for I := 0 to pick.Count - 1 do
- if (pick.Hit[I] <> FInterfaceRender) and
- (pick.Hit[I] <> FInternalRender) and not (pick.Hit[I] is TgxGizmoExUISphere)
- and not (pick.Hit[I] is TgxGizmoExUIPolyGon)
- and not (pick.Hit[I] is TgxGizmoExuITorus)
- and not (pick.Hit[I] is TgxGizmoExUIFrustrum)
- and not (pick.Hit[I] is TgxGizmoExUIArrowLine)
- and not (pick.Hit[I] is TgxGizmoExUILines)
- and not (pick.Hit[I] is TgxGizmoExUIFlatText)
- and not (CheckObjectInExcludeList(TgxBaseSceneObject(pick.hit[I])))
- and not (CheckClassNameInExcludeList(TgxBaseSceneObject(pick.hit[I]))) then
- begin
- //Clear list
- if not EnableMultiSelection then
- ClearSelection
- else
- if (pick.Count - 1 >= 0) and
- (FSelectedObjects.FindObject(pick.Hit[I]) = -1) then
- if not FCanAddObjToSelectionList and not FCanRemoveObjFromSelectionList then
- ClearSelection;
- if not FCanRemoveObjFromSelectionList then
- AddObjToSelectionList(TgxBaseSceneObject(pick.Hit[I]))
- else
- RemoveObjFromSelectionList(TgxBaseSceneObject(pick.Hit[I]));
- if Assigned(onSelect) then
- onSelect(self, FSelectedObjects);
- UpdateGizmo();
- Break;
- end;
- end
- else
- UpdateVisibleInfoLabels();
- pick.Free;
- moving := True;
- lastMousePos := MouseWorldPos(X, Y);
- if EnableMultiSelection then
- MultiSelMouseDown(X, Y);
- end;
- procedure TgxGizmoEx.ViewerMouseUp(const X, Y: Integer);
- var
- pick: TgxPickList;
- begin
- if (not Enabled) or (RootGizmo = nil) or (RootObjects = nil) then
- Exit;
- moving := False;
- case fOperation of
- gopRotate: SetAngleDisk(0);
- end;
- fchangerate := NullVector;
- //MassSelection+\-add mass selected obj
- if operation = gopNone then
- begin
- pick := InternalGetPickedObjects(X - 1, Y - 1, X + 1, Y + 1, 8);
- // clear the list if clicked into the void
- if not FCanAddObjToSelectionList and not FCanRemoveObjFromSelectionList and (pick.Count = 0) then
- ClearSelection;
- pick.Free;
- end;
- if EnableMultiSelection and FShowMultiSelecting then
- MultiSelMouseUp(X, Y);
- if not FShowMultiSelecting and EnableActionHistory then
- FHistory.AddObjects(FSelectedObjects);
- Updategizmo;
- end;
- //------------------------------------------------------------------------------
- procedure TgxGizmoEx.UpdateGizmo;
- var
- d: Single;
- v: TVector4f;
- I: Integer;
- begin
- if not Assigned(RootGizmo) or
- not Assigned(RootObjects) or
- not Assigned(Viewer) then
- Exit;
- if FSelectedObjects.Count - 1 < 0 then
- begin
- FUIRootHelpers.Visible := False;
- Exit;
- end
- else
- begin
- FUIRootHelpers.Visible := True;
- if Assigned(onUpdate) then
- OnUpdate(self);
- v := VectorMake(0, 0, 0);
- // set the gizmo to the desired position!
- for I := 0 to FSelectedObjects.Count - 1 do
- VectorAdd(v, TgxBaseSceneObject(FSelectedObjects.Hit[I]).AbsolutePosition, v);
- if FSelectedObjects.Count = 1 then
- I := 1
- else
- I := FSelectedObjects.Count;
- FUIRootHelpers.Position.AsVector := VectorDivide(v, VectorMake(I, I, I));
- end;
- case Ord(ReferenceCoordSystem) of
- 0:
- begin
- FUIRootHelpers.Direction := FUIBaseGizmo.Direction;
- FUIRootHelpers.Up := FUIBaseGizmo.Up;
- end;
- 1:
- begin
- FUIRootHelpers.AbsoluteDirection := TgxBaseSceneObject(FSelectedObjects.Hit[0]).AbsoluteDirection;
- FUIRootHelpers.AbsoluteUp := TgxBaseSceneObject(FSelectedObjects.Hit[0]).AbsoluteUp;
- end;
- end;
- Assert(Viewer <> nil, 'Viewer not Assigned to gizmo');
- if FAutoZoom then
- d := Viewer.Camera.distanceTo(FUIRootHelpers) / FAutoZoomFactor
- else
- d := FZoomFactor;
- if FUIRootAxisLabel.Visible then
- begin
- FUIAxisLabelX.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIAxisLabelX.StructureChanged;
- FUIAxisLabelY.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIAxisLabelY.StructureChanged;
- FUIAxisLabelZ.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIAxisLabelZ.StructureChanged;
- FUIRootAxisLabel.Scale.AsVector := VectorMake(d, d, d);
- end;
- if FUIRootSelect.Visible then
- FUIRootSelect.Scale.AsVector := VectorMake(d, d, d);
- if FUIRootMovement.Visible then
- FUIRootMovement.Scale.AsVector := VectorMake(d, d, d);
- if FUIRootRotate.Visible then
- begin
- FUIRotateLineXY.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIRotateLineXY.StructureChanged;
- FUIRotateLineXZ.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIRotateLineXZ.StructureChanged;
- FUIRotateAxisLabelX.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIRotateAxisLabelX.StructureChanged;
- FUIRotateAxisLabelY.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIRotateAxisLabelY.StructureChanged;
- FUIRotateAxisLabelZ.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIRotateAxisLabelZ.StructureChanged;
- FUIRootRotate.Scale.AsVector := VectorMake(d, d, d);
- end;
- if not moving and FUIRootScale.Visible then
- FUIRootScale.Scale.AsVector := VectorMake(d, d, d);
- if FUIRootVisibleInfoLabels.Visible then
- begin
- UpdateVisibleInfoLabels;
- FUIRootVisibleInfoLabels.AbsoluteDirection := FUIBaseGizmo.AbsoluteDirection;
- FUIRootVisibleInfoLabels.AbsoluteUp := FUIBaseGizmo.AbsoluteUp;
- FUIVisibleInfoLabels.ModulateColor.Color := FVisibleInfoLabelsColor.Color;
- FUIVisibleInfoLabels.PointTo(Viewer.Camera.Position.AsVector, Viewer.Camera.Up.AsVector);
- FUIVisibleInfoLabels.StructureChanged;
- FUIRootVisibleInfoLabels.Scale.AsVector := VectorMake(d, d, d);
- end;
- end;
- procedure TgxGizmoEx.LooseSelection;
- begin
- ClearSelection;
- UpdateGizmo;
- if Assigned(onSelectionLost) then
- OnSelectionLost(self);
- end;
- procedure TgxGizmoEx.ClearSelection;
- begin
- FSelectedObj := nil;
- FSelectedObjects.Clear;
- end;
- procedure TgxGizmoEx.LooseCursorSelection;
- begin
- FShowMultiSelecting := False;
- if high(FSelectionRec) > 0 then
- SetLength(FSelectionRec, 0);
- flastcursorPos := Point(0, 0);
- fcursorPos := point(0, 0);
- end;
- procedure TgxGizmoEx.SetViewer(const Value: TgxSceneViewer);
- begin
- if FViewer <> Value then
- begin
- if FViewer <> nil then
- FViewer.RemoveFreeNotification(Self);
- FViewer := Value;
- if FViewer <> nil then
- FViewer.FreeNotification(Self);
- end;
- end;
- procedure TgxGizmoEx.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited;
- if Operation = opRemove then
- begin
- if AComponent = FViewer then
- FViewer := nil;
- if AComponent = FRootGizmo then
- FRootGizmo := nil;
- if AComponent = FRootObjects then
- FRootObjects := nil;
- if AComponent = FGizmoTmpRoot then
- FGizmoTmpRoot := nil;
- end;
- if FHistory <> nil then
- FHistory.Notification(AComponent, Operation);
- end;
- function TgxGizmoEx.Undo: TgxGizmoExActionHistoryItem;
- var
- I: Integer;
- begin
- Result := FHistory.Undo;
- if Result = nil then
- Exit;
- FSelectedObjects.Clear;
- for I := 0 to Result.GizmoObjectCollection.Count - 1 do
- FSelectedObjects.AddHit(Result.GizmoObjectCollection.Items[I].EffectedObject, nil, 0, 0);
- UpdateGizmo;
- end;
- function TgxGizmoEx.Redo: TgxGizmoExActionHistoryItem;
- var
- I: Integer;
- begin
- Result := FHistory.Redo;
- if Result = nil then
- Exit;
- FSelectedObjects.Clear;
- for I := 0 to Result.GizmoObjectCollection.Count - 1 do
- if not Result.GizmoObjectCollection.Items[I].FReturnObject then
- FSelectedObjects.AddHit(Result.GizmoObjectCollection.Items[I].EffectedObject, nil, 0, 0);
- UpdateGizmo;
- end;
- //************************)
- procedure TgxGizmoExObjectItem.AssignFromObject(const AObject: TgxBaseSceneObject; AssignAndRemoveObj: Boolean = False);
- begin
- if not AssignAndRemoveObj then
- begin
- EffectedObject := AObject;
- SetOldMatrix(AObject.Matrix^);
- if AObject is TgxFreeForm then
- FOldAutoScaling := TgxFreeForm(AObject).AutoScaling.AsVector;
- end
- else
- begin
- EffectedObject := AObject;
- FParentOldObject := EffectedObject.Parent;
- FIndexOldObject := EffectedObject.Index;
- FNameOldObject := EffectedObject.Name;
- FEffectedObject.MoveTo(GizmoTmpRoot);
- FReturnObject := True;
- end;
- end;
- constructor TgxGizmoExObjectItem.Create(AOwner: TCollection);
- begin
- FReturnObject := False;
- inherited;
- end;
- destructor TgxGizmoExObjectItem.Destroy;
- begin
- if FReturnObject then
- if assigned(fEffectedObject) then
- FreeAndNil(fEffectedObject);
- inherited;
- end;
- function TgxGizmoExObjectItem.GetGizmo: TgxGizmoEx;
- begin
- if GetParent <> nil then
- Result := GetPArent.GetParent
- else
- Result := nil;
- end;
- function TgxGizmoExObjectItem.GetParent: TgxGizmoExObjectCollection;
- begin
- Result := TgxGizmoExObjectCollection(GetOwner);
- end;
- procedure TgxGizmoExObjectItem.DoUndo;
- begin
- if FEffectedObject = nil then
- Exit;
- if not FReturnObject then
- begin
- FEffectedObject.SetMatrix(FOldMatrix);
- if FEffectedObject is TgxFreeForm then
- TgxFreeForm(FEffectedObject).AutoScaling.AsVector := FOldAutoScaling;
- end
- else
- begin
- if fEffectedObject.Parent <> GizmoTmpRoot then
- begin
- fEffectedObject.MoveTo(FGizmoTmpRoot);
- Exit;
- end;
- FParentOldObject.Insert(FIndexOldObject, fEffectedObject);
- end;
- end;
- procedure TgxGizmoExObjectItem.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited;
- if Operation = opRemove then
- begin
- if AComponent = FEffectedObject then
- if FReturnObject then
- FreeAndNil(FEffectedObject)
- else
- FEffectedObject := nil;
- GizmoTmpRoot := nil;
- end;
- end;
- procedure TgxGizmoExObjectItem.SetEffectedObject(const Value: TgxBaseSceneObject);
- begin
- FEffectedObject := Value;
- end;
- procedure TgxGizmoExObjectItem.SetOldMatrix(const Value: TMatrix4f);
- begin
- FOldMatrix := Value;
- end;
- //------------------------------------
- // TgxGizmoExUndoCollection
- //------------------------------------
- function TgxGizmoExObjectCollection.Add: TgxGizmoExObjectItem;
- begin
- Result := TgxGizmoExObjectItem(inherited Add);
- end;
- function TgxGizmoExObjectCollection.GetItems(const Index: Integer): TgxGizmoExObjectItem;
- begin
- Result := TgxGizmoExObjectItem(inherited GetItem(Index));
- end;
- function TgxGizmoExObjectCollection.GetParent: TgxGizmoEx;
- begin
- Result := TgxGizmoEx(GetOwner);
- end;
- procedure TgxGizmoExObjectCollection.Notification(AComponent: TComponent; Operation: TOperation);
- var
- I: Integer;
- begin
- if Count <> 0 then
- for I := 0 to Count - 1 do
- GetItems(I).Notification(AComponent, Operation);
- end;
- procedure TgxGizmoExObjectCollection.RemoveByObject(const AObject: TgxCustomSceneObject);
- var
- I: Integer;
- begin
- for I := Count - 1 downto 0 do
- if GetItems(I).FEffectedObject = AObject then
- GetItems(I).Free;
- end;
- procedure TgxGizmoExObjectCollection.SetItems(const Index: Integer; const Value: TgxGizmoExObjectItem);
- begin
- GetItems(Index).Assign(Value);
- end;
- procedure TgxGizmoExObjectCollection.DoUndo;
- var
- I: Integer;
- begin
- for I := Count - 1 downto 0 do
- GetItems(I).DoUndo;
- end;
- //**********)
- constructor TgxGizmoExActionHistoryItem.Create(AOwner: TCollection);
- begin
- inherited;
- FGizmoObjectCollection := TgxGizmoExObjectCollection.Create(self, TgxGizmoExObjectItem);
- end;
- destructor TgxGizmoExActionHistoryItem.Destroy;
- begin
- FGizmoObjectCollection.Free;
- inherited;
- end;
- procedure TgxGizmoExActionHistoryItem.SetObject(aValue: TObject);
- begin
- if FObject <> AValue then
- FObject := AValue;
- end;
- procedure TgxGizmoExActionHistoryItem.SetGizmoObjectCollection(aValue: TgxGizmoExObjectCollection);
- begin
- if FGizmoObjectCollection <> aValue then
- FGizmoObjectCollection := aValue;
- end;
- //----------------------------------------
- // TgxGizmoExUndoCollection
- //----------------------------------------
- constructor TgxGizmoExActionHistoryCollection.Create(AOwner: TPersistent; ItemClass: TCollectionItemClass);
- begin
- MaxCount := 30;
- FItemIndex := -1;
- inherited;
- end;
- function TgxGizmoExActionHistoryCollection.Add: TgxGizmoExActionHistoryItem;
- begin
- Result := nil;
- //If used undo then rewrite previous record
- if FItemIndex = Count - 1 then
- begin
- Result := TgxGizmoExActionHistoryItem(inherited Add);
- FItemIndex := FItemIndex + 1;
- ;
- end
- else
- if (FItemIndex >= 0) or (FItemIndex < Count - 1) then
- begin
- Result := Items[FItemIndex];
- FItemIndex := FItemIndex + 1;
- end;
- // if number of record greater then maxcount then delete elements
- if Count - 1 > MaxCount then
- begin
- Delete(0);
- FItemIndex := Count - 1;
- end;
- end;
- function TgxGizmoExActionHistoryCollection.GetItems(const Index: Integer): TgxGizmoExActionHistoryItem;
- begin
- Result := TgxGizmoExActionHistoryItem(inherited GetItem(Index));
- end;
- procedure TgxGizmoExActionHistoryCollection.Notification(AComponent: TComponent; Operation: TOperation);
- var
- I: Integer;
- begin
- if Count <> 0 then
- for I := 0 to Count - 1 do
- GetItems(I).FGizmoObjectCollection.Notification(AComponent, Operation);
- end;
- procedure TgxGizmoExActionHistoryCollection.SetItems(const Index: Integer; const Value: TgxGizmoExActionHistoryItem);
- begin
- GetItems(Index).Assign(Value);
- end;
- function TgxGizmoExActionHistoryCollection.Undo: TgxGizmoExActionHistoryItem;
- begin
- Result := nil;
- if not (FItemIndex > 0) or not (FItemIndex <= Count - 1) then
- Exit;
- if FItemIndex <> 0 then
- FItemIndex := FItemIndex - 1;
- Result := Items[FItemIndex];
- Result.GizmoObjectCollection.DoUndo;
- end;
- function TgxGizmoExActionHistoryCollection.Redo: TgxGizmoExActionHistoryItem;
- begin
- Result := nil;
- if not (FItemIndex >= 0) or not (FItemIndex < Count - 1) then
- Exit;
- if FItemIndex <> Count - 1 then
- FItemIndex := FItemIndex + 1;
- Result := Items[FItemIndex];
- Result.GizmoObjectCollection.DoUndo;
- end;
- procedure TgxGizmoExActionHistoryCollection.AddObjects(objs: TgxPickList);
- var
- I: Integer;
- begin
- with Add do
- begin
- for I := 0 to objs.Count - 1 do
- GizmoObjectCollection.Add.AssignFromObject(TgxBaseSceneObject(objs.Hit[I]));
- end;
- end;
- procedure TgxGizmoExActionHistoryCollection.AddObject(obj: TObject);
- begin
- if obj = nil then
- Exit;
- Add.FObject := obj;
- end;
- procedure TgxGizmoExActionHistoryCollection.RemoveObjects(objs: TgxPickList);
- var
- I: Integer;
- begin
- if not Assigned(self.GizmoTmpRoot) then
- Exit;
- with Add do
- for I := 0 to objs.Count - 1 do
- if objs.Hit[I] <> nil then
- with GizmoObjectCollection.Add do
- begin
- GizmoTmpRoot := self.GizmoTmpRoot;
- AssignFromObject(TgxBaseSceneObject(objs.Hit[I]), True);
- end;
- objs.Clear;
- end;
- end.
|