| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785 |
- // Filename: nodePath.cxx
- // Created by: drose (25Feb02)
- //
- ////////////////////////////////////////////////////////////////////
- //
- // PANDA 3D SOFTWARE
- // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
- //
- // All use of this software is subject to the terms of the Panda 3d
- // Software license. You should have received a copy of this license
- // along with this source code; you will also find a current copy of
- // the license at http://etc.cmu.edu/panda3d/docs/license/ .
- //
- // To contact the maintainers of this program write to
- // [email protected] .
- //
- ////////////////////////////////////////////////////////////////////
- #include "nodePath.h"
- #include "nodePathCollection.h"
- #include "findApproxPath.h"
- #include "findApproxLevelEntry.h"
- #include "config_pgraph.h"
- #include "colorAttrib.h"
- #include "colorScaleAttrib.h"
- #include "cullBinAttrib.h"
- #include "textureAttrib.h"
- #include "texMatrixAttrib.h"
- #include "texGenAttrib.h"
- #include "materialAttrib.h"
- #include "lightAttrib.h"
- #include "clipPlaneAttrib.h"
- #include "polylightEffect.h"
- #include "fogAttrib.h"
- #include "renderModeAttrib.h"
- #include "cullFaceAttrib.h"
- #include "alphaTestAttrib.h"
- #include "depthTestAttrib.h"
- #include "depthWriteAttrib.h"
- #include "billboardEffect.h"
- #include "compassEffect.h"
- #include "showBoundsEffect.h"
- #include "transparencyAttrib.h"
- #include "antialiasAttrib.h"
- #include "texProjectorEffect.h"
- #include "planeNode.h"
- #include "lensNode.h"
- #include "materialPool.h"
- #include "look_at.h"
- #include "plist.h"
- #include "boundingSphere.h"
- #include "geomNode.h"
- #include "sceneGraphAnalyzer.h"
- #include "sceneGraphReducer.h"
- #include "textureCollection.h"
- #include "textureStageCollection.h"
- #include "globPattern.h"
- #include "config_gobj.h"
- #include "bamFile.h"
- #include "preparedGraphicsObjects.h"
- #include "dcast.h"
- // stack seems to overflow on Intel C++ at 7000. If we need more than
- // 7000, need to increase stack size.
- int NodePath::_max_search_depth = 7000;
- TypeHandle NodePath::_type_handle;
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_num_nodes
- // Access: Published
- // Description: Returns the number of nodes in the path.
- ////////////////////////////////////////////////////////////////////
- int NodePath::
- get_num_nodes() const {
- if (is_empty()) {
- return 0;
- }
- return _head->get_length();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_node
- // Access: Published
- // Description: Returns the nth node of the path, where 0 is the
- // referenced (bottom) node and get_num_nodes() - 1 is
- // the top node. This requires iterating through the
- // path.
- //
- // Also see node(), which is a convenience function to
- // return the same thing as get_node(0) (since the
- // bottom node is the most important node in the
- // NodePath, and is the one most frequently referenced).
- ////////////////////////////////////////////////////////////////////
- PandaNode *NodePath::
- get_node(int index) const {
- nassertr(index >= 0 && index < get_num_nodes(), NULL);
- NodePathComponent *comp = _head;
- while (index > 0) {
- // If this assertion fails, the index was out of range; the
- // component's length must have been invalid.
- nassertr(comp != (NodePathComponent *)NULL, NULL);
- comp = comp->get_next();
- index--;
- }
- // If this assertion fails, the index was out of range; the
- // component's length must have been invalid.
- nassertr(comp != (NodePathComponent *)NULL, NULL);
- return comp->get_node();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_top
- // Access: Published
- // Description: Returns a singleton NodePath that represents the top
- // of the path, or empty NodePath if this path is empty.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- get_top() const {
- if (is_empty()) {
- return *this;
- }
- NodePathComponent *comp = _head;
- while (!comp->is_top_node()) {
- comp = comp->get_next();
- nassertr(comp != (NodePathComponent *)NULL, NULL);
- }
- NodePath top;
- top._head = comp;
- return top;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_children
- // Access: Published
- // Description: Returns the set of all child nodes of the referenced
- // node.
- ////////////////////////////////////////////////////////////////////
- NodePathCollection NodePath::
- get_children() const {
- NodePathCollection result;
- nassertr_always(!is_empty(), result);
- PandaNode *bottom_node = node();
- PandaNode::Children cr = bottom_node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- NodePath child;
- child._head = PandaNode::get_component(_head, cr.get_child(i));
- result.add_path(child);
- }
- return result;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_stashed_children
- // Access: Published
- // Description: Returns the set of all child nodes of the referenced
- // node that have been stashed. These children are not
- // normally visible on the node, and do not appear in
- // the list returned by get_children().
- ////////////////////////////////////////////////////////////////////
- NodePathCollection NodePath::
- get_stashed_children() const {
- NodePathCollection result;
- nassertr_always(!is_empty(), result);
- PandaNode *bottom_node = node();
- int num_stashed = bottom_node->get_num_stashed();
- for (int i = 0; i < num_stashed; i++) {
- NodePath stashed;
- stashed._head = PandaNode::get_component(_head, bottom_node->get_stashed(i));
- result.add_path(stashed);
- }
- return result;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_sort
- // Access: Published
- // Description: Returns the sort value of the referenced node within
- // its parent; that is, the sort number passed on the
- // last reparenting operation for this node. This will
- // control the position of the node within its parent's
- // list of children.
- ////////////////////////////////////////////////////////////////////
- int NodePath::
- get_sort() const {
- if (!has_parent()) {
- return 0;
- }
- PandaNode *parent = _head->get_next()->get_node();
- PandaNode *child = node();
- nassertr(parent != (PandaNode *)NULL && child != (PandaNode *)NULL, 0);
- int child_index = parent->find_child(child);
- if (child_index != -1) {
- return parent->get_child_sort(child_index);
- }
- child_index = parent->find_stashed(child);
- if (child_index != -1) {
- return parent->get_stashed_sort(child_index);
- }
- nassertr(false, 0);
- return 0;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find
- // Access: Published
- // Description: Searches for a node below the referenced node that
- // matches the indicated string. Returns the shortest
- // match found, if any, or an empty NodePath if no match
- // can be found.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- find(const string &path) const {
- nassertr_always(!is_empty(), fail());
- NodePathCollection col;
- find_matches(col, path, 1);
- if (col.is_empty()) {
- return NodePath::not_found();
- }
- return col.get_path(0);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_path_to
- // Access: Published
- // Description: Searches for the indicated node below this node and
- // returns the shortest NodePath that connects them.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- find_path_to(PandaNode *node) const {
- nassertr_always(!is_empty(), fail());
- nassertr(node != (PandaNode *)NULL, fail());
- NodePathCollection col;
- FindApproxPath approx_path;
- approx_path.add_match_many(0);
- approx_path.add_match_pointer(node, 0);
- find_matches(col, approx_path, 1);
- if (col.is_empty()) {
- return NodePath::not_found();
- }
- return col.get_path(0);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_matches
- // Access: Published
- // Description: Returns the complete set of all NodePaths that begin
- // with this NodePath and can be extended by
- // path. The shortest paths will be listed
- // first.
- ////////////////////////////////////////////////////////////////////
- NodePathCollection NodePath::
- find_all_matches(const string &path) const {
- NodePathCollection col;
- nassertr_always(!is_empty(), col);
- nassertr(verify_complete(), col);
- find_matches(col, path, -1);
- return col;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_paths_to
- // Access: Published
- // Description: Returns the set of all NodePaths that extend from
- // this NodePath down to the indicated node. The
- // shortest paths will be listed first.
- ////////////////////////////////////////////////////////////////////
- NodePathCollection NodePath::
- find_all_paths_to(PandaNode *node) const {
- NodePathCollection col;
- nassertr_always(!is_empty(), col);
- nassertr(verify_complete(), col);
- nassertr(node != (PandaNode *)NULL, col);
- FindApproxPath approx_path;
- approx_path.add_match_many(0);
- approx_path.add_match_pointer(node, 0);
- find_matches(col, approx_path, -1);
- return col;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::reparent_to
- // Access: Published
- // Description: Removes the referenced node of the NodePath from its
- // current parent and attaches it to the referenced node
- // of the indicated NodePath.
- //
- // If the destination NodePath is empty, this is the
- // same thing as detach_node().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- reparent_to(const NodePath &other, int sort) {
- nassertv(verify_complete());
- nassertv(other.verify_complete());
- nassertv_always(!is_empty());
- nassertv(other._error_type == ET_ok);
- // Reparenting implicitly resents the delta vector.
- node()->reset_prev_transform();
- bool reparented = PandaNode::reparent(other._head, _head, sort, false);
- nassertv(reparented);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::wrt_reparent_to
- // Access: Published
- // Description: This functions identically to reparent_to(), except
- // the transform on this node is also adjusted so that
- // the node remains in the same place in world
- // coordinates, even if it is reparented into a
- // different coordinate system.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- wrt_reparent_to(const NodePath &other, int sort) {
- nassertv(verify_complete());
- nassertv(other.verify_complete());
- nassertv_always(!is_empty());
- nassertv(other._error_type == ET_ok);
- if (get_transform() == get_prev_transform()) {
- set_transform(get_transform(other));
- node()->reset_prev_transform();
- } else {
- set_transform(get_transform(other));
- set_prev_transform(get_prev_transform(other));
- }
- reparent_to(other, sort);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::instance_to
- // Access: Published
- // Description: Adds the referenced node of the NodePath as a child
- // of the referenced node of the indicated other
- // NodePath. Any other parent-child relations of the
- // node are unchanged; in particular, the node is not
- // removed from its existing parent, if any.
- //
- // If the node already had an existing parent, this
- // method will create a new instance of the node within
- // the scene graph.
- //
- // This does not change the NodePath itself, but does
- // return a new NodePath that reflects the new instance
- // node.
- //
- // If the destination NodePath is empty, this creates a
- // new instance which is not yet parented to any node.
- // A new instance of this sort cannot easily be
- // differentiated from other similar instances, but it
- // is nevertheless a different instance and it will
- // return a different get_id() value.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- instance_to(const NodePath &other, int sort) const {
- nassertr(verify_complete(), NodePath::fail());
- nassertr(other.verify_complete(), NodePath::fail());
- nassertr_always(!is_empty(), NodePath::fail());
- nassertr(other._error_type == ET_ok, NodePath::fail());
- NodePath new_instance;
- // First, we'll attach to NULL, to guarantee we get a brand new
- // instance.
- new_instance._head = PandaNode::attach(NULL, node(), sort);
- // Now, we'll reparent the new instance to the target node.
- bool reparented = PandaNode::reparent(other._head, new_instance._head,
- sort, false);
- nassertr(reparented, new_instance);
- // instance_to() doesn't reset the velocity delta, unlike most of
- // the other reparenting operations. The reasoning is that
- // instance_to() is not necessarily a reparenting operation, since
- // it doesn't change the original instance.
- return new_instance;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::instance_under_node
- // Access: Published
- // Description: Behaves like instance_to(), but implicitly creates a
- // new node to instance the geometry under, and returns a
- // NodePath to that new node. This allows the
- // programmer to set a unique state and/or transform on
- // this instance.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- instance_under_node(const NodePath &other, const string &name, int sort) const {
- NodePath new_node = other.attach_new_node(name, sort);
- NodePath instance = instance_to(new_node);
- if (instance.is_empty()) {
- new_node.remove_node();
- return instance;
- }
- return new_node;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::copy_to
- // Access: Published
- // Description: Functions like instance_to(), except a deep
- // copy is made of the referenced node and all of its
- // descendents, which is then parented to the indicated
- // node. A NodePath to the newly created copy is
- // returned.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- copy_to(const NodePath &other, int sort) const {
- nassertr(verify_complete(), fail());
- nassertr(other.verify_complete(), fail());
- nassertr_always(!is_empty(), fail());
- nassertr(other._error_type == ET_ok, fail());
- PandaNode *source_node = node();
- PT(PandaNode) copy_node = source_node->copy_subgraph();
- nassertr(copy_node != (PandaNode *)NULL, fail());
- copy_node->reset_prev_transform();
- return other.attach_new_node(copy_node, sort);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::attach_new_node
- // Access: Published
- // Description: Attaches a new node, with or without existing
- // parents, to the scene graph below the referenced node
- // of this NodePath. This is the preferred way to add
- // nodes to the graph.
- //
- // If the node was already a child of the parent, this
- // returns a NodePath to the existing child.
- //
- // This does *not* automatically extend the current
- // NodePath to reflect the attachment; however, a
- // NodePath that does reflect this extension is
- // returned.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- attach_new_node(PandaNode *node, int sort) const {
- nassertr(verify_complete(), NodePath::fail());
- nassertr(_error_type == ET_ok, NodePath::fail());
- nassertr(node != (PandaNode *)NULL, NodePath::fail());
- NodePath new_path(*this);
- new_path._head = PandaNode::attach(_head, node, sort);
- return new_path;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::remove_node
- // Access: Published
- // Description: Disconnects the referenced node from the scene graph.
- // This will also delete the node if there are no other
- // pointers to it.
- //
- // Normally, this should be called only when you are
- // really done with the node. If you want to remove a
- // node from the scene graph but keep it around for
- // later, you should probably use detach_node() instead.
- //
- // In practice, the only difference between
- // remove_node() and detach_node() is that remove_node()
- // also resets the NodePath to empty, which will cause
- // the node to be deleted immediately if there are no
- // other references. On the other hand, detach_node()
- // leaves the NodePath referencing the node, which will
- // keep at least one reference to the node for as long
- // as the NodePath exists.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- remove_node() {
- nassertv(_error_type != ET_not_found);
- // If we have no parents, remove_node() is just a do-nothing
- // operation; if we have no nodes, maybe we were already removed.
- // In either case, quietly do nothing except to ensure the
- // NodePath is clear.
- if (!is_empty() && !is_singleton()) {
- node()->reset_prev_transform();
- PandaNode::detach(_head);
- }
- if (is_empty() || _head->has_key()) {
- // Preserve the key we had on the node before we removed it.
- int key = get_key();
- (*this) = NodePath::removed();
- _backup_key = key;
- } else {
- // We didn't have a key; just clear the NodePath.
- (*this) = NodePath::removed();
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::detach_node
- // Access: Published
- // Description: Disconnects the referenced node from its parent, but
- // does not immediately delete it. The NodePath retains
- // a pointer to the node, and becomes a singleton
- // NodePath.
- //
- // This should be called to detach a node from the scene
- // graph, with the option of reattaching it later to the
- // same parent or to a different parent.
- //
- // In practice, the only difference between
- // remove_node() and detach_node() is that remove_node()
- // also resets the NodePath to empty, which will cause
- // the node to be deleted immediately if there are no
- // other references. On the other hand, detach_node()
- // leaves the NodePath referencing the node, which will
- // keep at least one reference to the node for as long
- // as the NodePath exists.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- detach_node() {
- nassertv(_error_type != ET_not_found);
- if (!is_empty() && !is_singleton()) {
- node()->reset_prev_transform();
- PandaNode::detach(_head);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::output
- // Access: Published
- // Description: Writes a sensible description of the NodePath to the
- // indicated output stream.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- output(ostream &out) const {
- switch (_error_type) {
- case ET_not_found:
- out << "**not found**";
- return;
- case ET_removed:
- out << "**removed**";
- return;
- case ET_fail:
- out << "**error**";
- return;
- default:
- break;
- }
- if (_head == (NodePathComponent *)NULL) {
- out << "(empty)";
- } else {
- _head->output(out);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_state
- // Access: Published
- // Description: Returns the state changes that must be made to
- // transition to the render state of this node from the
- // render state of the other node.
- ////////////////////////////////////////////////////////////////////
- CPT(RenderState) NodePath::
- get_state(const NodePath &other) const {
- nassertr(_error_type == ET_ok && other._error_type == ET_ok, RenderState::make_empty());
- if (other.is_empty()) {
- return get_net_state();
- }
- if (is_empty()) {
- return other.get_net_state()->invert_compose(RenderState::make_empty());
- }
-
- nassertr(verify_complete(), RenderState::make_empty());
- nassertr(other.verify_complete(), RenderState::make_empty());
- int a_count, b_count;
- if (find_common_ancestor(*this, other, a_count, b_count) == (NodePathComponent *)NULL) {
- if (allow_unrelated_wrt) {
- pgraph_cat.debug()
- << *this << " is not related to " << other << "\n";
- } else {
- pgraph_cat.error()
- << *this << " is not related to " << other << "\n";
- nassertr(false, RenderState::make_empty());
- }
- }
- CPT(RenderState) a_state = r_get_partial_state(_head, a_count);
- CPT(RenderState) b_state = r_get_partial_state(other._head, b_count);
- return b_state->invert_compose(a_state);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_state
- // Access: Published
- // Description: Sets the state object on this node, relative to
- // the other node. This computes a new state object
- // that will have the indicated value when seen from the
- // other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_state(const NodePath &other, const RenderState *state) {
- nassertv(_error_type == ET_ok && other._error_type == ET_ok);
- nassertv_always(!is_empty());
- // First, we perform a wrt to the parent, to get the conversion.
- CPT(RenderState) rel_state;
- if (has_parent()) {
- rel_state = other.get_state(get_parent());
- } else {
- rel_state = other.get_state(NodePath());
- }
- CPT(RenderState) new_state = rel_state->compose(state);
- set_state(new_state);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_transform
- // Access: Published
- // Description: Returns the relative transform to this node from the
- // other node; i.e. the transformation of this node
- // as seen from the other node.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- get_transform(const NodePath &other) const {
- nassertr(_error_type == ET_ok && other._error_type == ET_ok, TransformState::make_identity());
- if (other.is_empty()) {
- return get_net_transform();
- }
- if (is_empty()) {
- return other.get_net_transform()->invert_compose(TransformState::make_identity());
- }
-
- nassertr(verify_complete(), TransformState::make_identity());
- nassertr(other.verify_complete(), TransformState::make_identity());
- int a_count, b_count;
- if (find_common_ancestor(*this, other, a_count, b_count) == (NodePathComponent *)NULL) {
- if (allow_unrelated_wrt) {
- if (pgraph_cat.is_debug()) {
- pgraph_cat.debug()
- << *this << " is not related to " << other << "\n";
- }
- } else {
- pgraph_cat.error()
- << *this << " is not related to " << other << "\n";
- nassertr(false, TransformState::make_identity());
- }
- }
- CPT(TransformState) a_transform, b_transform;
- a_transform = r_get_partial_transform(_head, a_count);
- if (a_transform != (TransformState *)NULL) {
- b_transform = r_get_partial_transform(other._head, b_count);
- }
- if (b_transform == (TransformState *)NULL) {
- // If either path involved a node with a net_transform
- // RenderEffect applied, we have to go all the way up to the root
- // to get the right answer.
- a_transform = r_get_net_transform(_head);
- b_transform = r_get_net_transform(other._head);
- }
- return b_transform->invert_compose(a_transform);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_transform
- // Access: Published
- // Description: Sets the transform object on this node, relative to
- // the other node. This computes a new transform object
- // that will have the indicated value when seen from the
- // other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_transform(const NodePath &other, const TransformState *transform) {
- nassertv(_error_type == ET_ok && other._error_type == ET_ok);
- nassertv_always(!is_empty());
- // First, we perform a wrt to the parent, to get the conversion.
- CPT(TransformState) rel_trans;
- if (has_parent()) {
- rel_trans = other.get_transform(get_parent());
- } else {
- rel_trans = other.get_transform(NodePath());
- }
- CPT(TransformState) new_trans = rel_trans->compose(transform);
- set_transform(new_trans);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_prev_transform
- // Access: Published
- // Description: Returns the relative "previous" transform to this
- // node from the other node; i.e. the position of this
- // node in the previous frame, as seen by the other node
- // in the previous frame.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- get_prev_transform(const NodePath &other) const {
- nassertr(_error_type == ET_ok && other._error_type == ET_ok, TransformState::make_identity());
- if (other.is_empty()) {
- return get_net_prev_transform();
- }
- if (is_empty()) {
- return other.get_net_prev_transform()->invert_compose(TransformState::make_identity());
- }
-
- nassertr(verify_complete(), TransformState::make_identity());
- nassertr(other.verify_complete(), TransformState::make_identity());
- int a_count, b_count;
- if (find_common_ancestor(*this, other, a_count, b_count) == (NodePathComponent *)NULL) {
- if (allow_unrelated_wrt) {
- pgraph_cat.debug()
- << *this << " is not related to " << other << "\n";
- } else {
- pgraph_cat.error()
- << *this << " is not related to " << other << "\n";
- nassertr(false, TransformState::make_identity());
- }
- }
- CPT(TransformState) a_prev_transform = r_get_partial_prev_transform(_head, a_count);
- CPT(TransformState) b_prev_transform = r_get_partial_prev_transform(other._head, b_count);
- return b_prev_transform->invert_compose(a_prev_transform);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_prev_transform
- // Access: Published
- // Description: Sets the "previous" transform object on this node,
- // relative to the other node. This computes a new
- // transform object that will have the indicated value
- // when seen from the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_prev_transform(const NodePath &other, const TransformState *transform) {
- nassertv(_error_type == ET_ok && other._error_type == ET_ok);
- nassertv_always(!is_empty());
- // First, we perform a wrt to the parent, to get the conversion.
- CPT(TransformState) rel_trans;
- if (has_parent()) {
- rel_trans = other.get_prev_transform(get_parent());
- } else {
- rel_trans = other.get_prev_transform(NodePath());
- }
- CPT(TransformState) new_trans = rel_trans->compose(transform);
- set_prev_transform(new_trans);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos
- // Access: Published
- // Description: Sets the translation component of the transform,
- // leaving rotation and scale untouched. This also
- // resets the node's "previous" position, so that the
- // collision system will see the node as having suddenly
- // appeared in the new position, without passing any
- // points in between.
- // See Also: NodePath::set_fluid_pos
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos(const LVecBase3f &pos) {
- nassertv_always(!is_empty());
- set_transform(get_transform()->set_pos(pos));
- node()->reset_prev_transform();
- }
- void NodePath::
- set_x(float x) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- pos[0] = x;
- set_pos(pos);
- }
- void NodePath::
- set_y(float y) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- pos[1] = y;
- set_pos(pos);
- }
- void NodePath::
- set_z(float z) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- pos[2] = z;
- set_pos(pos);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_fluid_pos
- // Access: Published
- // Description: Sets the translation component, without changing the
- // "previous" position, so that the collision system
- // will see the node as moving fluidly from its previous
- // position to its new position.
- // See Also: NodePath::set_pos
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_fluid_pos(const LVecBase3f &pos) {
- nassertv_always(!is_empty());
- set_transform(get_transform()->set_pos(pos));
- }
- void NodePath::
- set_fluid_x(float x) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- pos[0] = x;
- set_fluid_pos(pos);
- }
- void NodePath::
- set_fluid_y(float y) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- pos[1] = y;
- set_fluid_pos(pos);
- }
- void NodePath::
- set_fluid_z(float z) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- pos[2] = z;
- set_fluid_pos(pos);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_pos
- // Access: Published
- // Description: Retrieves the translation component of the transform.
- ////////////////////////////////////////////////////////////////////
- LPoint3f NodePath::
- get_pos() const {
- nassertr_always(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
- return get_transform()->get_pos();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_pos_delta
- // Access: Published
- // Description: Returns the delta vector from this node's position in
- // the previous frame (according to
- // set_prev_transform(), typically set via the use of
- // set_fluid_pos()) and its position in the current
- // frame. This is the vector used to determine
- // collisions. Generally, if the node was last
- // repositioned via set_pos(), the delta will be zero;
- // if it was adjusted via set_fluid_pos(), the delta
- // will represent the change from the previous frame's
- // position.
- ////////////////////////////////////////////////////////////////////
- LVector3f NodePath::
- get_pos_delta() const {
- nassertr_always(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
- return get_transform()->get_pos() - get_prev_transform()->get_pos();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_hpr
- // Access: Published
- // Description: Sets the rotation component of the transform,
- // leaving translation and scale untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_hpr(const LVecBase3f &hpr) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- nassertv(transform->has_hpr());
- set_transform(transform->set_hpr(hpr));
- }
- void NodePath::
- set_h(float h) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- nassertv(transform->has_hpr());
- LVecBase3f hpr = transform->get_hpr();
- hpr[0] = h;
- set_transform(transform->set_hpr(hpr));
- }
- void NodePath::
- set_p(float p) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- nassertv(transform->has_hpr());
- LVecBase3f hpr = transform->get_hpr();
- hpr[1] = p;
- set_transform(transform->set_hpr(hpr));
- }
- void NodePath::
- set_r(float r) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- nassertv(transform->has_hpr());
- LVecBase3f hpr = transform->get_hpr();
- hpr[2] = r;
- set_transform(transform->set_hpr(hpr));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_hpr
- // Access: Published
- // Description: Retrieves the rotation component of the transform.
- ////////////////////////////////////////////////////////////////////
- LVecBase3f NodePath::
- get_hpr() const {
- nassertr_always(!is_empty(), LVecBase3f(0.0f, 0.0f, 0.0f));
- CPT(TransformState) transform = get_transform();
- nassertr(transform->has_hpr(), LVecBase3f(0.0f, 0.0f, 0.0f));
- return transform->get_hpr();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_quat
- // Access: Published
- // Description: Sets the rotation component of the transform,
- // leaving translation and scale untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_quat(const LQuaternionf &quat) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- set_transform(transform->set_quat(quat));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_quat
- // Access: Published
- // Description: Retrieves the rotation component of the transform.
- ////////////////////////////////////////////////////////////////////
- LQuaternionf NodePath::
- get_quat() const {
- nassertr_always(!is_empty(), LQuaternionf::ident_quat());
- CPT(TransformState) transform = get_transform();
- return transform->get_quat();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_scale
- // Access: Published
- // Description: Sets the scale component of the transform,
- // leaving translation and rotation untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_scale(const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- set_transform(transform->set_scale(scale));
- }
- void NodePath::
- set_sx(float sx) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- LVecBase3f scale = transform->get_scale();
- scale[0] = sx;
- set_transform(transform->set_scale(scale));
- }
- void NodePath::
- set_sy(float sy) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- LVecBase3f scale = transform->get_scale();
- scale[1] = sy;
- set_transform(transform->set_scale(scale));
- }
- void NodePath::
- set_sz(float sz) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- LVecBase3f scale = transform->get_scale();
- scale[2] = sz;
- set_transform(transform->set_scale(scale));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_scale
- // Access: Published
- // Description: Retrieves the scale component of the transform.
- ////////////////////////////////////////////////////////////////////
- LVecBase3f NodePath::
- get_scale() const {
- nassertr_always(!is_empty(), LVecBase3f(0.0f, 0.0f, 0.0f));
- CPT(TransformState) transform = get_transform();
- return transform->get_scale();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_shear
- // Access: Published
- // Description: Sets the shear component of the transform,
- // leaving translation and rotation untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_shear(const LVecBase3f &shear) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- set_transform(transform->set_shear(shear));
- }
- void NodePath::
- set_shxy(float shxy) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- LVecBase3f shear = transform->get_shear();
- shear[0] = shxy;
- set_transform(transform->set_shear(shear));
- }
- void NodePath::
- set_shxz(float shxz) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- LVecBase3f shear = transform->get_shear();
- shear[1] = shxz;
- set_transform(transform->set_shear(shear));
- }
- void NodePath::
- set_shyz(float shyz) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- LVecBase3f shear = transform->get_shear();
- shear[2] = shyz;
- set_transform(transform->set_shear(shear));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_shear
- // Access: Published
- // Description: Retrieves the shear component of the transform.
- ////////////////////////////////////////////////////////////////////
- LVecBase3f NodePath::
- get_shear() const {
- nassertr_always(!is_empty(), LVecBase3f(0.0f, 0.0f, 0.0f));
- CPT(TransformState) transform = get_transform();
- return transform->get_shear();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_hpr
- // Access: Published
- // Description: Sets the translation and rotation component of the
- // transform, leaving scale untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_hpr(const LVecBase3f &pos, const LVecBase3f &hpr) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- transform = TransformState::make_pos_hpr_scale_shear
- (pos, hpr, transform->get_scale(), transform->get_shear());
- set_transform(transform);
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_quat
- // Access: Published
- // Description: Sets the translation and rotation component of the
- // transform, leaving scale untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_quat(const LVecBase3f &pos, const LQuaternionf &quat) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- transform = TransformState::make_pos_quat_scale_shear
- (pos, quat, transform->get_scale(), transform->get_shear());
- set_transform(transform);
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_hpr_scale
- // Access: Published
- // Description: Sets the rotation and scale components of the
- // transform, leaving translation untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_hpr_scale(const LVecBase3f &hpr, const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- transform = TransformState::make_pos_hpr_scale_shear
- (transform->get_pos(), hpr, scale, transform->get_shear());
- set_transform(transform);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_quat_scale
- // Access: Published
- // Description: Sets the rotation and scale components of the
- // transform, leaving translation untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_quat_scale(const LQuaternionf &quat, const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform();
- transform = TransformState::make_pos_quat_scale_shear
- (transform->get_pos(), quat, scale, transform->get_shear());
- set_transform(transform);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_hpr_scale
- // Access: Published
- // Description: Replaces the translation, rotation, and scale
- // components, implicitly setting shear to 0.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_hpr_scale(const LVecBase3f &pos, const LVecBase3f &hpr,
- const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- set_transform(TransformState::make_pos_hpr_scale
- (pos, hpr, scale));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_quat_scale
- // Access: Published
- // Description: Replaces the translation, rotation, and scale
- // components, implicitly setting shear to 0.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_quat_scale(const LVecBase3f &pos, const LQuaternionf &quat,
- const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- set_transform(TransformState::make_pos_quat_scale
- (pos, quat, scale));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_hpr_scale_shear
- // Access: Published
- // Description: Completely replaces the transform with new
- // translation, rotation, scale, and shear components.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_hpr_scale_shear(const LVecBase3f &pos, const LVecBase3f &hpr,
- const LVecBase3f &scale, const LVecBase3f &shear) {
- nassertv_always(!is_empty());
- set_transform(TransformState::make_pos_hpr_scale_shear
- (pos, hpr, scale, shear));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_quat_scale_shear
- // Access: Published
- // Description: Completely replaces the transform with new
- // translation, rotation, scale, and shear components.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_quat_scale_shear(const LVecBase3f &pos, const LQuaternionf &quat,
- const LVecBase3f &scale, const LVecBase3f &shear) {
- nassertv_always(!is_empty());
- set_transform(TransformState::make_pos_quat_scale_shear
- (pos, quat, scale, shear));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_mat
- // Access: Published
- // Description: Directly sets an arbitrary 4x4 transform matrix.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_mat(const LMatrix4f &mat) {
- nassertv_always(!is_empty());
- set_transform(TransformState::make_mat(mat));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::look_at
- // Access: Published
- // Description: Sets the hpr on this NodePath so that it
- // rotates to face the indicated point in space.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- look_at(const LPoint3f &point, const LVector3f &up) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- LQuaternionf quat;
- ::look_at(quat, point - pos, up);
- set_quat(quat);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::heads_up
- // Access: Published
- // Description: Behaves like look_at(), but with a strong preference
- // to keeping the up vector oriented in the indicated
- // "up" direction.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- heads_up(const LPoint3f &point, const LVector3f &up) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos();
- LQuaternionf quat;
- ::heads_up(quat, point - pos, up);
- set_quat(quat);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos
- // Access: Published
- // Description: Sets the translation component of the transform,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos(const NodePath &other, const LVecBase3f &pos) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other three components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_hpr = orig_transform->get_hpr();
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- set_transform(other, rel_transform->set_pos(pos));
- set_pos_hpr_scale_shear(get_transform()->get_pos(), orig_hpr, orig_scale, orig_shear);
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, rel_transform->set_pos(pos));
- }
- node()->reset_prev_transform();
- }
- void NodePath::
- set_x(const NodePath &other, float x) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos(other);
- pos[0] = x;
- set_pos(other, pos);
- }
- void NodePath::
- set_y(const NodePath &other, float y) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos(other);
- pos[1] = y;
- set_pos(other, pos);
- }
- void NodePath::
- set_z(const NodePath &other, float z) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos(other);
- pos[2] = z;
- set_pos(other, pos);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_fluid_pos
- // Access: Published
- // Description: Sets the translation component of the transform,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_fluid_pos(const NodePath &other, const LVecBase3f &pos) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other three components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_hpr = orig_transform->get_hpr();
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- // Use the relative set_transform() to compute the relative pos, and
- // then reset all of the other components back to the way they were.
- set_transform(other, rel_transform->set_pos(pos));
- set_transform(TransformState::make_pos_hpr_scale_shear
- (get_transform()->get_pos(), orig_hpr, orig_scale, orig_shear));
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, rel_transform->set_pos(pos));
- }
- }
- void NodePath::
- set_fluid_x(const NodePath &other, float x) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos(other);
- pos[0] = x;
- set_fluid_pos(other, pos);
- }
- void NodePath::
- set_fluid_y(const NodePath &other, float y) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos(other);
- pos[1] = y;
- set_fluid_pos(other, pos);
- }
- void NodePath::
- set_fluid_z(const NodePath &other, float z) {
- nassertv_always(!is_empty());
- LPoint3f pos = get_pos(other);
- pos[2] = z;
- set_fluid_pos(other, pos);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_pos
- // Access: Published
- // Description: Returns the relative position of the referenced node
- // as seen from the other node.
- ////////////////////////////////////////////////////////////////////
- LPoint3f NodePath::
- get_pos(const NodePath &other) const {
- nassertr_always(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
- return get_transform(other)->get_pos();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_pos_delta
- // Access: Published
- // Description: Returns the delta vector from this node's position in
- // the previous frame (according to
- // set_prev_transform(), typically set via the use of
- // set_fluid_pos()) and its position in the current
- // frame, as seen in the indicated node's coordinate
- // space. This is the vector used to determine
- // collisions. Generally, if the node was last
- // repositioned via set_pos(), the delta will be zero;
- // if it was adjusted via set_fluid_pos(), the delta
- // will represent the change from the previous frame's
- // position.
- ////////////////////////////////////////////////////////////////////
- LVector3f NodePath::
- get_pos_delta(const NodePath &other) const {
- nassertr_always(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
- return get_transform(other)->get_pos() - get_prev_transform(other)->get_pos();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_hpr
- // Access: Published
- // Description: Sets the rotation component of the transform,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_hpr(const NodePath &other, const LVecBase3f &hpr) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- nassertv(rel_transform->has_hpr());
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other three components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_pos = orig_transform->get_pos();
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- set_transform(other, rel_transform->set_hpr(hpr));
- const TransformState *new_transform = get_transform();
- if (new_transform->has_components()) {
- set_transform(TransformState::make_pos_hpr_scale_shear
- (orig_pos, new_transform->get_hpr(), orig_scale, orig_shear));
- }
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, rel_transform->set_hpr(hpr));
- }
- }
- void NodePath::
- set_h(const NodePath &other, float h) {
- nassertv_always(!is_empty());
- LVecBase3f hpr = get_hpr(other);
- hpr[0] = h;
- set_hpr(other, hpr);
- }
- void NodePath::
- set_p(const NodePath &other, float p) {
- nassertv_always(!is_empty());
- LVecBase3f hpr = get_hpr(other);
- hpr[1] = p;
- set_hpr(other, hpr);
- }
- void NodePath::
- set_r(const NodePath &other, float r) {
- nassertv_always(!is_empty());
- LVecBase3f hpr = get_hpr(other);
- hpr[2] = r;
- set_hpr(other, hpr);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_hpr
- // Access: Published
- // Description: Returns the relative orientation of the bottom node
- // as seen from the other node.
- ////////////////////////////////////////////////////////////////////
- LVecBase3f NodePath::
- get_hpr(const NodePath &other) const {
- nassertr_always(!is_empty(), LVecBase3f(0.0f, 0.0f, 0.0f));
- CPT(TransformState) transform = get_transform(other);
- nassertr(transform->has_hpr(), LVecBase3f(0.0f, 0.0f, 0.0f));
- return transform->get_hpr();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_quat
- // Access: Published
- // Description: Sets the rotation component of the transform,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_quat(const NodePath &other, const LQuaternionf &quat) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other three components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_pos = orig_transform->get_pos();
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- set_transform(other, rel_transform->set_quat(quat));
- const TransformState *new_transform = get_transform();
- if (new_transform->has_components()) {
- set_transform(TransformState::make_pos_quat_scale_shear
- (orig_pos, new_transform->get_quat(), orig_scale, orig_shear));
- }
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, rel_transform->set_quat(quat));
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_quat
- // Access: Published
- // Description: Returns the relative orientation of the bottom node
- // as seen from the other node.
- ////////////////////////////////////////////////////////////////////
- LQuaternionf NodePath::
- get_quat(const NodePath &other) const {
- nassertr_always(!is_empty(), LQuaternionf::ident_quat());
- CPT(TransformState) transform = get_transform(other);
- return transform->get_quat();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_scale
- // Access: Published
- // Description: Sets the scale component of the transform,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_scale(const NodePath &other, const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other three components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_pos = orig_transform->get_pos();
- const LVecBase3f &orig_hpr = orig_transform->get_hpr();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- set_transform(other, rel_transform->set_scale(scale));
- const TransformState *new_transform = get_transform();
- if (new_transform->has_components()) {
- set_transform(TransformState::make_pos_hpr_scale_shear
- (orig_pos, orig_hpr, new_transform->get_scale(), orig_shear));
- }
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, rel_transform->set_scale(scale));
- }
- }
- void NodePath::
- set_sx(const NodePath &other, float sx) {
- nassertv_always(!is_empty());
- LVecBase3f scale = get_scale(other);
- scale[0] = sx;
- set_scale(other, scale);
- }
- void NodePath::
- set_sy(const NodePath &other, float sy) {
- nassertv_always(!is_empty());
- LVecBase3f scale = get_scale(other);
- scale[1] = sy;
- set_scale(other, scale);
- }
- void NodePath::
- set_sz(const NodePath &other, float sz) {
- nassertv_always(!is_empty());
- LVecBase3f scale = get_scale(other);
- scale[2] = sz;
- set_scale(other, scale);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_scale
- // Access: Published
- // Description: Returns the relative scale of the bottom node
- // as seen from the other node.
- ////////////////////////////////////////////////////////////////////
- LVecBase3f NodePath::
- get_scale(const NodePath &other) const {
- nassertr_always(!is_empty(), LVecBase3f(0.0f, 0.0f, 0.0f));
- CPT(TransformState) transform = get_transform(other);
- return transform->get_scale();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_shear
- // Access: Published
- // Description: Sets the shear component of the transform,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_shear(const NodePath &other, const LVecBase3f &shear) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other three components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_pos = orig_transform->get_pos();
- const LVecBase3f &orig_hpr = orig_transform->get_hpr();
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- set_transform(other, rel_transform->set_shear(shear));
- const TransformState *new_transform = get_transform();
- if (new_transform->has_components()) {
- set_transform(TransformState::make_pos_hpr_scale_shear
- (orig_pos, orig_hpr, orig_scale, new_transform->get_shear()));
- }
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, rel_transform->set_shear(shear));
- }
- }
- void NodePath::
- set_shxy(const NodePath &other, float shxy) {
- nassertv_always(!is_empty());
- LVecBase3f shear = get_shear(other);
- shear[0] = shxy;
- set_shear(other, shear);
- }
- void NodePath::
- set_shxz(const NodePath &other, float shxz) {
- nassertv_always(!is_empty());
- LVecBase3f shear = get_shear(other);
- shear[1] = shxz;
- set_shear(other, shear);
- }
- void NodePath::
- set_shyz(const NodePath &other, float shyz) {
- nassertv_always(!is_empty());
- LVecBase3f shear = get_shear(other);
- shear[2] = shyz;
- set_shear(other, shear);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_shear
- // Access: Published
- // Description: Returns the relative shear of the bottom node
- // as seen from the other node.
- ////////////////////////////////////////////////////////////////////
- LVecBase3f NodePath::
- get_shear(const NodePath &other) const {
- nassertr_always(!is_empty(), LVecBase3f(0.0f, 0.0f, 0.0f));
- CPT(TransformState) transform = get_transform(other);
- return transform->get_shear();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_hpr
- // Access: Published
- // Description: Sets the translation and rotation component of the
- // transform, relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_hpr(const NodePath &other, const LVecBase3f &pos,
- const LVecBase3f &hpr) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other two components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- set_transform(other, TransformState::make_pos_hpr_scale_shear
- (pos, hpr, rel_transform->get_scale(), rel_transform->get_shear()));
- const TransformState *new_transform = get_transform();
- if (new_transform->has_components()) {
- set_pos_hpr_scale_shear(new_transform->get_pos(), new_transform->get_hpr(),
- orig_scale, orig_shear);
- }
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, TransformState::make_pos_hpr_scale_shear
- (pos, hpr, rel_transform->get_scale(), rel_transform->get_shear()));
- node()->reset_prev_transform();
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_quat
- // Access: Published
- // Description: Sets the translation and rotation component of the
- // transform, relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_quat(const NodePath &other, const LVecBase3f &pos,
- const LQuaternionf &quat) {
- nassertv_always(!is_empty());
- CPT(TransformState) rel_transform = get_transform(other);
-
- CPT(TransformState) orig_transform = get_transform();
- if (orig_transform->has_components()) {
- // If we had a componentwise transform before we started, we
- // should be careful to preserve the other two components. We
- // wouldn't need to do this, except for the possibility of
- // numerical error or decompose ambiguity.
- const LVecBase3f &orig_scale = orig_transform->get_scale();
- const LVecBase3f &orig_shear = orig_transform->get_shear();
- set_transform(other, TransformState::make_pos_quat_scale_shear
- (pos, quat, rel_transform->get_scale(), rel_transform->get_shear()));
- const TransformState *new_transform = get_transform();
- if (new_transform->has_components()) {
- set_pos_quat_scale_shear(new_transform->get_pos(), new_transform->get_quat(),
- orig_scale, orig_shear);
- }
- } else {
- // If we didn't have a componentwise transform already, never
- // mind.
- set_transform(other, TransformState::make_pos_quat_scale_shear
- (pos, quat, rel_transform->get_scale(), rel_transform->get_shear()));
- node()->reset_prev_transform();
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_hpr_scale
- // Access: Published
- // Description: Sets the rotation and scale components of the
- // transform, leaving translation untouched. This, or
- // set_pos_hpr_scale, is the preferred way to update a
- // transform when both hpr and scale are to be changed.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_hpr_scale(const NodePath &other, const LVecBase3f &hpr, const LVecBase3f &scale) {
- // We don't bother trying very hard to preserve pos across this
- // operation, unlike the work we do above to preserve hpr or scale,
- // since it generally doesn't matter that much if pos is off by a
- // few thousandths.
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform(other);
- transform = TransformState::make_pos_hpr_scale_shear
- (transform->get_pos(), hpr, scale, transform->get_shear());
- set_transform(other, transform);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_quat_scale
- // Access: Published
- // Description: Sets the rotation and scale components of the
- // transform, leaving translation untouched. This, or
- // set_pos_quat_scale, is the preferred way to update a
- // transform when both quat and scale are to be changed.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_quat_scale(const NodePath &other, const LQuaternionf &quat,
- const LVecBase3f &scale) {
- // We don't bother trying very hard to preserve pos across this
- // operation, unlike the work we do above to preserve quat or scale,
- // since it generally doesn't matter that much if pos is off by a
- // few thousandths.
- nassertv_always(!is_empty());
- CPT(TransformState) transform = get_transform(other);
- transform = TransformState::make_pos_quat_scale_shear
- (transform->get_pos(), quat, scale, transform->get_shear());
- set_transform(other, transform);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_hpr_scale
- // Access: Published
- // Description: Completely replaces the transform with new
- // translation, rotation, and scale components, relative
- // to the other node, implicitly setting shear to 0.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_hpr_scale(const NodePath &other,
- const LVecBase3f &pos, const LVecBase3f &hpr,
- const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- set_transform(other, TransformState::make_pos_hpr_scale
- (pos, hpr, scale));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_quat_scale
- // Access: Published
- // Description: Completely replaces the transform with new
- // translation, rotation, and scale components, relative
- // to the other node, implicitly setting shear to 0.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_quat_scale(const NodePath &other,
- const LVecBase3f &pos, const LQuaternionf &quat,
- const LVecBase3f &scale) {
- nassertv_always(!is_empty());
- set_transform(other, TransformState::make_pos_quat_scale
- (pos, quat, scale));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_hpr_scale_shear
- // Access: Published
- // Description: Completely replaces the transform with new
- // translation, rotation, scale, and shear components,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_hpr_scale_shear(const NodePath &other,
- const LVecBase3f &pos, const LVecBase3f &hpr,
- const LVecBase3f &scale, const LVecBase3f &shear) {
- nassertv_always(!is_empty());
- set_transform(other, TransformState::make_pos_hpr_scale_shear
- (pos, hpr, scale, shear));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_pos_quat_scale_shear
- // Access: Published
- // Description: Completely replaces the transform with new
- // translation, rotation, scale, and shear components,
- // relative to the other node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_pos_quat_scale_shear(const NodePath &other,
- const LVecBase3f &pos, const LQuaternionf &quat,
- const LVecBase3f &scale, const LVecBase3f &shear) {
- nassertv_always(!is_empty());
- set_transform(other, TransformState::make_pos_quat_scale_shear
- (pos, quat, scale, shear));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_mat
- // Access: Published
- // Description: Returns the matrix that describes the coordinate
- // space of the bottom node, relative to the other
- // path's bottom node's coordinate space.
- ////////////////////////////////////////////////////////////////////
- LMatrix4f NodePath::
- get_mat(const NodePath &other) const {
- CPT(TransformState) transform = get_transform(other);
- // We can't safely return a reference to the matrix, because we
- // can't assume the transform won't go away when the function
- // returns. If the transform was partially modified by, say, a
- // CompassEffect, it won't be stored in the cache, and thus we might
- // have the only reference to it.
- return transform->get_mat();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_mat
- // Access: Published
- // Description: Converts the indicated matrix from the other's
- // coordinate space to the local coordinate space, and
- // applies it to the node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_mat(const NodePath &other, const LMatrix4f &mat) {
- nassertv_always(!is_empty());
- set_transform(other, TransformState::make_mat(mat));
- node()->reset_prev_transform();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_relative_point
- // Access: Published
- // Description: Given that the indicated point is in the coordinate
- // system of the other node, returns the same point in
- // this node's coordinate system.
- ////////////////////////////////////////////////////////////////////
- LPoint3f NodePath::
- get_relative_point(const NodePath &other, const LVecBase3f &point) const {
- CPT(TransformState) transform = other.get_transform(*this);
- LPoint3f rel_point = LPoint3f(point) * transform->get_mat();
- return rel_point;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_relative_vector
- // Access: Published
- // Description: Given that the indicated vector is in the coordinate
- // system of the other node, returns the same vector in
- // this node's coordinate system.
- ////////////////////////////////////////////////////////////////////
- LVector3f NodePath::
- get_relative_vector(const NodePath &other, const LVecBase3f &vec) const {
- CPT(TransformState) transform = other.get_transform(*this);
- LVector3f rel_vector = LVector3f(vec) * transform->get_mat();
- return rel_vector;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::look_at
- // Access: Published
- // Description: Sets the transform on this NodePath so that it
- // rotates to face the indicated point in space, which
- // is relative to the other NodePath.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- look_at(const NodePath &other, const LPoint3f &point, const LVector3f &up) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = other.get_transform(get_parent());
- LPoint3f rel_point = point * transform->get_mat();
- LPoint3f pos = get_pos();
- LQuaternionf quat;
- ::look_at(quat, rel_point - pos, up);
- set_quat(quat);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::heads_up
- // Access: Published
- // Description: Behaves like look_at(), but with a strong preference
- // to keeping the up vector oriented in the indicated
- // "up" direction.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- heads_up(const NodePath &other, const LPoint3f &point, const LVector3f &up) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = other.get_transform(get_parent());
- LPoint3f rel_point = point * transform->get_mat();
- LPoint3f pos = get_pos();
- LQuaternionf quat;
- ::heads_up(quat, rel_point - pos, up);
- set_quat(quat);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_color
- // Access: Published
- // Description: Applies a scene-graph color to the referenced node.
- // This color will apply to all geometry at this level
- // and below (that does not specify a new color or a
- // set_color_off()).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_color(float r, float g, float b, float a,
- int priority) {
- set_color(Colorf(r, g, b, a), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_color
- // Access: Published
- // Description: Applies a scene-graph color to the referenced node.
- // This color will apply to all geometry at this level
- // and below (that does not specify a new color or a
- // set_color_off()).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_color(const Colorf &color, int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(ColorAttrib::make_flat(color), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_color_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using the geometry color. This is normally the
- // default, but it may be useful to use this to
- // contradict set_color() at a higher node level (or,
- // with a priority, to override a set_color() at a lower
- // level).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_color_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(ColorAttrib::make_vertex(), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_color
- // Access: Published
- // Description: Completely removes any color adjustment from the node.
- // This allows the natural color of the geometry, or
- // whatever color transitions might be otherwise
- // affecting the geometry, to show instead.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_color() {
- nassertv_always(!is_empty());
- node()->clear_attrib(ColorAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_color
- // Access: Published
- // Description: Returns true if a color has been applied to the given
- // node, false otherwise.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_color() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(ColorAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_color
- // Access: Published
- // Description: Returns the color that has been assigned to the node,
- // or black if no color has been assigned.
- ////////////////////////////////////////////////////////////////////
- Colorf NodePath::
- get_color() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(ColorAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const ColorAttrib *ca = DCAST(ColorAttrib, attrib);
- if (ca->get_color_type() == ColorAttrib::T_flat) {
- return ca->get_color();
- }
- }
- pgraph_cat.warning()
- << "get_color() called on " << *this << " which has no color set.\n";
- return Colorf(1.0f, 1.0f, 1.0f, 1.0f);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_color_scale
- // Access: Published
- // Description: Returns true if a color scale has been applied
- // to the referenced node, false otherwise. It is still
- // possible that color at this node might have been
- // scaled by an ancestor node.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_color_scale() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(ColorScaleAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_color_scale
- // Access: Published
- // Description: Completely removes any color scale from the
- // referenced node. This is preferable to simply
- // setting the color scale to identity, as it also
- // removes the overhead associated with having a color
- // scale at all.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_color_scale() {
- nassertv_always(!is_empty());
- node()->clear_attrib(ColorScaleAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_color_scale
- // Access: Published
- // Description: Sets the color scale component of the transform,
- // leaving translation and rotation untouched.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_color_scale(const LVecBase4f &scale, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(ColorScaleAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(ColorScaleAttrib::get_class_type()));
- const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib);
- // Modify the existing ColorScaleAttrib to add the indicated
- // colorScale.
- node()->set_attrib(csa->set_scale(scale), priority);
- } else {
- // Create a new ColorScaleAttrib for this node.
- node()->set_attrib(ColorScaleAttrib::make(scale), priority);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_color_scale_off
- // Access: Published
- // Description: Disables any color scale attribute inherited from
- // above. This is not the same thing as
- // clear_color_scale(), which undoes any previous
- // set_color_scale() operation on this node; rather,
- // this actively disables any set_color_scale() that
- // might be inherited from a parent node. This also
- // disables set_alpha_scale() at the same time.
- //
- // It is legal to specify a new color scale on the same
- // node with a subsequent call to set_color_scale() or
- // set_alpha_scale(); this new scale will apply to lower
- // geometry.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_color_scale_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(ColorScaleAttrib::make_off(), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_alpha_scale
- // Access: Published
- // Description: Sets the alpha scale component of the transform
- // without (much) affecting the color scale. Note that
- // any priority specified will also apply to the color
- // scale.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_alpha_scale(float scale, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(ColorScaleAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(ColorScaleAttrib::get_class_type()));
- const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib);
- // Modify the existing ColorScaleAttrib to add the indicated
- // colorScale.
- const LVecBase4f &sc = csa->get_scale();
- node()->set_attrib(csa->set_scale(LVecBase4f(sc[0], sc[1], sc[2], scale)), priority);
- } else {
- // Create a new ColorScaleAttrib for this node.
- node()->set_attrib(ColorScaleAttrib::make(LVecBase4f(1.0f, 1.0f, 1.0f, scale)), priority);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_all_color_scale
- // Access: Published
- // Description: Scales all the color components of the object by the
- // same amount, darkening the object, without (much)
- // affecting alpha. Note that any priority specified
- // will also apply to the alpha scale.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_all_color_scale(float scale, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(ColorScaleAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(ColorScaleAttrib::get_class_type()));
- const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib);
- // Modify the existing ColorScaleAttrib to add the indicated
- // colorScale.
- const LVecBase4f &sc = csa->get_scale();
- node()->set_attrib(csa->set_scale(LVecBase4f(scale, scale, scale, sc[3])), priority);
- } else {
- // Create a new ColorScaleAttrib for this node.
- node()->set_attrib(ColorScaleAttrib::make(LVecBase4f(scale, scale, scale, 1.0f)), priority);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_color_scale
- // Access: Published
- // Description: Returns the complete color scale vector that has been
- // applied to this node via a previous call to
- // set_color_scale() and/or set_alpha_scale(), or all
- // 1's (identity) if no scale has been applied to this
- // particular node.
- ////////////////////////////////////////////////////////////////////
- const LVecBase4f &NodePath::
- get_color_scale() const {
- static const LVecBase4f ident_scale(1.0f, 1.0f, 1.0f, 1.0f);
- nassertr_always(!is_empty(), ident_scale);
- const RenderAttrib *attrib =
- node()->get_attrib(ColorScaleAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib);
- return csa->get_scale();
- }
- return ident_scale;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_light
- // Access: Published
- // Description: Adds the indicated Light or PolylightNode to the list
- // of lights that illuminate geometry at this node and
- // below. The light itself should be parented into the
- // scene graph elsewhere, to represent the light's
- // position in space; but until set_light() is called it
- // will illuminate no geometry.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_light(const NodePath &light, int priority) {
- nassertv_always(!is_empty());
- if (!light.is_empty()) {
- Light *light_obj = light.node()->as_light();
- if (light_obj != (Light *)NULL) {
- // It's an actual Light object.
- const RenderAttrib *attrib =
- node()->get_attrib(LightAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(LightAttrib::get_class_type()));
- const LightAttrib *la = DCAST(LightAttrib, attrib);
-
- // Modify the existing LightAttrib to add the indicated
- // light.
- node()->set_attrib(la->add_on_light(light), priority);
-
- } else {
- // Create a new LightAttrib for this node.
- CPT(LightAttrib) la = DCAST(LightAttrib, LightAttrib::make());
- node()->set_attrib(la->add_on_light(light), priority);
- }
- return;
- } else if (light.node()->is_of_type(PolylightNode::get_class_type())) {
- // It's a Polylight object.
- if (priority != 0) {
- // PolylightEffects can't have a priority, since they're just
- // an effect to be applied immediately.
- pgraph_cat.warning()
- << "Ignoring priority on set_light(" << light << ")\n";
- }
- const RenderEffect *effect =
- node()->get_effect(PolylightEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- const PolylightEffect *ple = DCAST(PolylightEffect, effect);
-
- // Modify the existing PolylightEffect to add the indicated
- // light.
- node()->set_effect(ple->add_light(light));
-
- } else {
- // Create a new PolylightEffect for this node.
- CPT(PolylightEffect) ple = DCAST(PolylightEffect, PolylightEffect::make());
- node()->set_effect(ple->add_light(light));
- }
- return;
- }
- }
- nassert_raise("Not a Light object.");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_light_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using no lights at all. This is different
- // from not specifying a light; rather, this
- // specifically contradicts set_light() at a higher
- // node level (or, with a priority, overrides a
- // set_light() at a lower level).
- //
- // If no lights are in effect on a particular piece of
- // geometry, that geometry is rendered with lighting
- // disabled.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_light_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(LightAttrib::make_all_off(), priority);
- node()->clear_effect(PolylightEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_light_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // without using the indicated Light. This is different
- // from not specifying the Light; rather, this
- // specifically contradicts set_light() at a higher node
- // level (or, with a priority, overrides a set_light()
- // at a lower level).
- //
- // This interface does not support PolylightNodes, which
- // cannot be turned off at a lower level.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_light_off(const NodePath &light, int priority) {
- nassertv_always(!is_empty());
- if (!light.is_empty()) {
- Light *light_obj = light.node()->as_light();
- if (light_obj != (Light *)NULL) {
- const RenderAttrib *attrib =
- node()->get_attrib(LightAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(LightAttrib::get_class_type()));
- const LightAttrib *la = DCAST(LightAttrib, attrib);
-
- // Modify the existing LightAttrib to add the indicated light
- // to the "off" list. This also, incidentally, removes it from
- // the "on" list if it is there.
- node()->set_attrib(la->add_off_light(light), priority);
-
- } else {
- // Create a new LightAttrib for this node that turns off the
- // indicated light.
- CPT(LightAttrib) la = DCAST(LightAttrib, LightAttrib::make());
- node()->set_attrib(la->add_off_light(light), priority);
- }
- return;
- }
- }
- nassert_raise("Not a Light object.");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_light
- // Access: Published
- // Description: Completely removes any lighting operations that may
- // have been set via set_light() or set_light_off()
- // from this particular node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_light() {
- nassertv_always(!is_empty());
- node()->clear_attrib(LightAttrib::get_class_type());
- node()->clear_effect(PolylightEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_light
- // Access: Published
- // Description: Removes any reference to the indicated Light or
- // PolylightNode from the NodePath.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_light(const NodePath &light) {
- nassertv_always(!is_empty());
- if (!light.is_empty()) {
- Light *light_obj = light.node()->as_light();
- if (light_obj != (Light *)NULL) {
- const RenderAttrib *attrib =
- node()->get_attrib(LightAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- CPT(LightAttrib) la = DCAST(LightAttrib, attrib);
- la = DCAST(LightAttrib, la->remove_on_light(light));
- la = DCAST(LightAttrib, la->remove_off_light(light));
-
- if (la->is_identity()) {
- node()->clear_attrib(LightAttrib::get_class_type());
-
- } else {
- int priority = node()->get_state()->get_override(LightAttrib::get_class_type());
- node()->set_attrib(la, priority);
- }
- }
- return;
- } else if (light.node()->is_of_type(PolylightNode::get_class_type())) {
- const RenderEffect *effect =
- node()->get_effect(PolylightEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- CPT(PolylightEffect) ple = DCAST(PolylightEffect, effect);
- ple = DCAST(PolylightEffect, ple->remove_light(light));
- node()->set_effect(ple);
- }
- return;
- }
- }
- nassert_raise("Not a Light object.");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_light
- // Access: Published
- // Description: Returns true if the indicated Light or PolylightNode
- // has been specifically enabled on this particular
- // node. This means that someone called set_light() on
- // this node with the indicated light.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_light(const NodePath &light) const {
- nassertr_always(!is_empty(), false);
- if (!light.is_empty()) {
- Light *light_obj = light.node()->as_light();
- if (light_obj != (Light *)NULL) {
- const RenderAttrib *attrib =
- node()->get_attrib(LightAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const LightAttrib *la = DCAST(LightAttrib, attrib);
- return la->has_on_light(light);
- }
- return false;
- } else if (light.node()->is_of_type(PolylightNode::get_class_type())) {
- const RenderEffect *effect =
- node()->get_effect(PolylightEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- const PolylightEffect *ple = DCAST(PolylightEffect, effect);
- return ple->has_light(light);
- }
- return false;
- }
- }
- nassert_raise("Not a Light object.");
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_light_off
- // Access: Published
- // Description: Returns true if all Lights have been specifically
- // disabled on this particular node. This means that
- // someone called set_light_off() on this node with no
- // parameters.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_light_off() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(LightAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const LightAttrib *la = DCAST(LightAttrib, attrib);
- return la->has_all_off();
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_light_off
- // Access: Published
- // Description: Returns true if the indicated Light has been
- // specifically disabled on this particular node. This
- // means that someone called set_light_off() on this
- // node with the indicated light.
- //
- // This interface does not support PolylightNodes, which
- // cannot be turned off at a lower level.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_light_off(const NodePath &light) const {
- nassertr_always(!is_empty(), false);
- if (!light.is_empty()) {
- Light *light_obj = light.node()->as_light();
- if (light_obj != (Light *)NULL) {
- const RenderAttrib *attrib =
- node()->get_attrib(LightAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const LightAttrib *la = DCAST(LightAttrib, attrib);
- return la->has_off_light(light);
- }
- }
- }
- nassert_raise("Not a Light object.");
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_clip_plane
- // Access: Published
- // Description: Adds the indicated clipping plane to the list of
- // planes that apply to geometry at this node and below.
- // The clipping plane itself, a PlaneNode, should be
- // parented into the scene graph elsewhere, to represent
- // the plane's position in space; but until
- // set_clip_plane() is called it will clip no geometry.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_clip_plane(const NodePath &clip_plane, int priority) {
- nassertv_always(!is_empty());
- if (!clip_plane.is_empty() && clip_plane.node()->is_of_type(PlaneNode::get_class_type())) {
- const RenderAttrib *attrib =
- node()->get_attrib(ClipPlaneAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(ClipPlaneAttrib::get_class_type()));
- const ClipPlaneAttrib *la = DCAST(ClipPlaneAttrib, attrib);
-
- // Modify the existing ClipPlaneAttrib to add the indicated
- // clip_plane.
- node()->set_attrib(la->add_on_plane(clip_plane), priority);
-
- } else {
- // Create a new ClipPlaneAttrib for this node.
- CPT(ClipPlaneAttrib) la = DCAST(ClipPlaneAttrib, ClipPlaneAttrib::make());
- node()->set_attrib(la->add_on_plane(clip_plane), priority);
- }
- return;
- }
- nassert_raise("Not a PlaneNode object.");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_clip_plane_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using no clip_planes at all. This is different
- // from not specifying a clip_plane; rather, this
- // specifically contradicts set_clip_plane() at a higher
- // node level (or, with a priority, overrides a
- // set_clip_plane() at a lower level).
- //
- // If no clip_planes are in effect on a particular piece
- // of geometry, that geometry is rendered without being
- // clipped (other than by the viewing frustum).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_clip_plane_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(ClipPlaneAttrib::make_all_off(), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_clip_plane_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // without being clipped by the indicated PlaneNode.
- // This is different from not specifying the PlaneNode;
- // rather, this specifically contradicts
- // set_clip_plane() at a higher node level (or, with a
- // priority, overrides a set_clip_plane() at a lower
- // level).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_clip_plane_off(const NodePath &clip_plane, int priority) {
- nassertv_always(!is_empty());
- if (!clip_plane.is_empty() && clip_plane.node()->is_of_type(PlaneNode::get_class_type())) {
- const RenderAttrib *attrib =
- node()->get_attrib(ClipPlaneAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(ClipPlaneAttrib::get_class_type()));
- const ClipPlaneAttrib *la = DCAST(ClipPlaneAttrib, attrib);
-
- // Modify the existing ClipPlaneAttrib to add the indicated clip_plane
- // to the "off" list. This also, incidentally, removes it from
- // the "on" list if it is there.
- node()->set_attrib(la->add_off_plane(clip_plane), priority);
-
- } else {
- // Create a new ClipPlaneAttrib for this node that turns off the
- // indicated clip_plane.
- CPT(ClipPlaneAttrib) la = DCAST(ClipPlaneAttrib, ClipPlaneAttrib::make());
- node()->set_attrib(la->add_off_plane(clip_plane), priority);
- }
- return;
- }
- nassert_raise("Not a PlaneNode object.");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_clip_plane
- // Access: Published
- // Description: Completely removes any clip planes that may have been
- // set via set_clip_plane() or set_clip_plane_off() from
- // this particular node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_clip_plane() {
- nassertv_always(!is_empty());
- node()->clear_attrib(ClipPlaneAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_clip_plane
- // Access: Published
- // Description: Removes any reference to the indicated clipping plane
- // from the NodePath.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_clip_plane(const NodePath &clip_plane) {
- nassertv_always(!is_empty());
- if (!clip_plane.is_empty() && clip_plane.node()->is_of_type(PlaneNode::get_class_type())) {
- const RenderAttrib *attrib =
- node()->get_attrib(ClipPlaneAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- CPT(ClipPlaneAttrib) la = DCAST(ClipPlaneAttrib, attrib);
- la = DCAST(ClipPlaneAttrib, la->remove_on_plane(clip_plane));
- la = DCAST(ClipPlaneAttrib, la->remove_off_plane(clip_plane));
-
- if (la->is_identity()) {
- node()->clear_attrib(ClipPlaneAttrib::get_class_type());
-
- } else {
- int priority = node()->get_state()->get_override(ClipPlaneAttrib::get_class_type());
- node()->set_attrib(la, priority);
- }
- }
- return;
- }
- nassert_raise("Not a PlaneNode object.");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_clip_plane
- // Access: Published
- // Description: Returns true if the indicated clipping plane has been
- // specifically applied to this particular node. This
- // means that someone called set_clip_plane() on this
- // node with the indicated clip_plane.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_clip_plane(const NodePath &clip_plane) const {
- nassertr_always(!is_empty(), false);
- if (!clip_plane.is_empty() && clip_plane.node()->is_of_type(PlaneNode::get_class_type())) {
- const RenderAttrib *attrib =
- node()->get_attrib(ClipPlaneAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const ClipPlaneAttrib *la = DCAST(ClipPlaneAttrib, attrib);
- return la->has_on_plane(clip_plane);
- }
- return false;
- }
- nassert_raise("Not a PlaneNode object.");
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_clip_plane_off
- // Access: Published
- // Description: Returns true if all clipping planes have been
- // specifically disabled on this particular node. This
- // means that someone called set_clip_plane_off() on
- // this node with no parameters.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_clip_plane_off() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(ClipPlaneAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const ClipPlaneAttrib *la = DCAST(ClipPlaneAttrib, attrib);
- return la->has_all_off();
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_clip_plane_off
- // Access: Published
- // Description: Returns true if the indicated clipping plane has been
- // specifically disabled on this particular node. This
- // means that someone called set_clip_plane_off() on
- // this node with the indicated clip_plane.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_clip_plane_off(const NodePath &clip_plane) const {
- nassertr_always(!is_empty(), false);
- if (!clip_plane.is_empty() && clip_plane.node()->is_of_type(PlaneNode::get_class_type())) {
- const RenderAttrib *attrib =
- node()->get_attrib(ClipPlaneAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const ClipPlaneAttrib *la = DCAST(ClipPlaneAttrib, attrib);
- return la->has_off_plane(clip_plane);
- }
- }
- nassert_raise("Not a PlaneNode object.");
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_bin
- // Access: Published
- // Description: Assigns the geometry at this level and below to the
- // named rendering bin. It is the user's responsibility
- // to ensure that such a bin already exists, either via
- // the cull-bin Configrc variable, or by explicitly
- // creating a GeomBin of the appropriate type at
- // runtime.
- //
- // There are two default bins created when Panda is
- // started: "default" and "fixed". Normally, all
- // geometry is assigned to "default" unless specified
- // otherwise. This bin renders opaque geometry in
- // state-sorted order, followed by transparent geometry
- // sorted back-to-front. If any geometry is assigned to
- // "fixed", this will be rendered following all the
- // geometry in "default", in the order specified by
- // draw_order for each piece of geometry so assigned.
- //
- // The draw_order parameter is meaningful only for
- // GeomBinFixed type bins, e.g. "fixed". Other kinds of
- // bins ignore it.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_bin(const string &bin_name, int draw_order, int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(CullBinAttrib::make(bin_name, draw_order), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_bin
- // Access: Published
- // Description: Completely removes any bin adjustment that may have
- // been set via set_bin() from this particular node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_bin() {
- nassertv_always(!is_empty());
- node()->clear_attrib(CullBinAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_bin
- // Access: Published
- // Description: Returns true if the node has been assigned to the a
- // particular rendering bin via set_bin(), false
- // otherwise.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_bin() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(CullBinAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_bin_name
- // Access: Published
- // Description: Returns the name of the bin that this particular node
- // was assigned to via set_bin(), or the empty string if
- // no bin was assigned. See set_bin() and has_bin().
- ////////////////////////////////////////////////////////////////////
- string NodePath::
- get_bin_name() const {
- nassertr_always(!is_empty(), string());
- const RenderAttrib *attrib =
- node()->get_attrib(CullBinAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const CullBinAttrib *ba = DCAST(CullBinAttrib, attrib);
- return ba->get_bin_name();
- }
- return string();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_bin_draw_order
- // Access: Published
- // Description: Returns the drawing order associated with the bin
- // that this particular node was assigned to via
- // set_bin(), or 0 if no bin was assigned. See
- // set_bin() and has_bin().
- ////////////////////////////////////////////////////////////////////
- int NodePath::
- get_bin_draw_order() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(CullBinAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const CullBinAttrib *ba = DCAST(CullBinAttrib, attrib);
- return ba->get_draw_order();
- }
- return 0;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_texture
- // Access: Published
- // Description: Adds the indicated texture to the list of textures
- // that will be rendered on the default texture stage.
- //
- // This is the deprecated single-texture variant of this
- // method; it is now superceded by set_texture() that
- // accepts a stage and texture. However, this method
- // may be used in the presence of multitexture if you
- // just want to adjust the default stage.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_texture(Texture *tex, int priority) {
- nassertv_always(!is_empty());
- PT(TextureStage) stage = TextureStage::get_default();
- set_texture(stage, tex, priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_texture
- // Access: Published
- // Description: Adds the indicated texture to the list of textures
- // that will be rendered on the indicated multitexture
- // stage. If there are multiple texture stages
- // specified (possibly on multiple different nodes at
- // different levels), they will all be applied to
- // geometry together, according to the stage
- // specification set up in the TextureStage object.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_texture(TextureStage *stage, Texture *tex, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(TextureAttrib::get_class_type()));
- const TextureAttrib *tsa = DCAST(TextureAttrib, attrib);
- // Modify the existing TextureAttrib to add the indicated
- // texture.
- node()->set_attrib(tsa->add_on_stage(stage, tex), priority);
- } else {
- // Create a new TextureAttrib for this node.
- CPT(TextureAttrib) tsa = DCAST(TextureAttrib, TextureAttrib::make());
- node()->set_attrib(tsa->add_on_stage(stage, tex), priority);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_texture_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using no texture, on any stage. This is different
- // from not specifying a texture; rather, this
- // specifically contradicts set_texture() at a higher
- // node level (or, with a priority, overrides a
- // set_texture() at a lower level).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_texture_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(TextureAttrib::make_all_off(), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_texture_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using no texture, on the indicated stage. This is
- // different from not specifying a texture; rather, this
- // specifically contradicts set_texture() at a higher
- // node level (or, with a priority, overrides a
- // set_texture() at a lower level).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_texture_off(TextureStage *stage, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(TextureAttrib::get_class_type()));
- const TextureAttrib *tsa = DCAST(TextureAttrib, attrib);
- // Modify the existing TextureAttrib to add the indicated texture
- // to the "off" list. This also, incidentally, removes it from
- // the "on" list if it is there.
- node()->set_attrib(tsa->add_off_stage(stage), priority);
- } else {
- // Create a new TextureAttrib for this node that turns off the
- // indicated stage.
- CPT(TextureAttrib) tsa = DCAST(TextureAttrib, TextureAttrib::make());
- node()->set_attrib(tsa->add_off_stage(stage), priority);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_texture
- // Access: Published
- // Description: Completely removes any texture adjustment that may
- // have been set via set_texture() or set_texture_off()
- // from this particular node. This allows whatever
- // textures might be otherwise affecting the geometry to
- // show instead.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_texture() {
- nassertv_always(!is_empty());
- node()->clear_attrib(TextureAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_texture
- // Access: Published
- // Description: Removes any reference to the indicated texture stage
- // from the NodePath.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_texture(TextureStage *stage) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- CPT(TextureAttrib) tsa = DCAST(TextureAttrib, attrib);
- tsa = DCAST(TextureAttrib, tsa->remove_on_stage(stage));
- tsa = DCAST(TextureAttrib, tsa->remove_off_stage(stage));
- if (tsa->is_identity()) {
- node()->clear_attrib(TextureAttrib::get_class_type());
- } else {
- int priority = node()->get_state()->get_override(TextureAttrib::get_class_type());
- node()->set_attrib(tsa, priority);
- }
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_texture
- // Access: Published
- // Description: Returns true if a texture has been applied to this
- // particular node via set_texture(), false otherwise.
- // This is not the same thing as asking whether the
- // geometry at this node will be rendered with
- // texturing, as there may be a texture in effect from a
- // higher or lower level.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_texture() const {
- return get_texture() != (Texture *)NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_texture
- // Access: Published
- // Description: Returns true if texturing has been specifically
- // enabled on this particular node for the indicated
- // stage. This means that someone called
- // set_texture() on this node with the indicated stage
- // name, or the stage_name is the default stage_name,
- // and someone called set_texture() on this node.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_texture(TextureStage *stage) const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- return ta->has_on_stage(stage);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_texture_off
- // Access: Published
- // Description: Returns true if texturing has been specifically
- // disabled on this particular node via
- // set_texture_off(), false otherwise. This is not the
- // same thing as asking whether the geometry at this
- // node will be rendered untextured, as there may be a
- // texture in effect from a higher or lower level.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_texture_off() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- return ta->has_all_off();
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_texture_off
- // Access: Published
- // Description: Returns true if texturing has been specifically
- // disabled on this particular node for the indicated
- // stage. This means that someone called
- // set_texture_off() on this node with the indicated
- // stage name, or that someone called set_texture_off()
- // on this node to remove all stages.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_texture_off(TextureStage *stage) const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- return ta->has_off_stage(stage);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_texture
- // Access: Published
- // Description: Returns the base-level texture that has been set on
- // this particular node, or NULL if no texture has been
- // set. This is not necessarily the texture that will
- // be applied to the geometry at or below this level, as
- // another texture at a higher or lower level may
- // override.
- //
- // See also find_texture().
- ////////////////////////////////////////////////////////////////////
- Texture *NodePath::
- get_texture() const {
- nassertr_always(!is_empty(), NULL);
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- return ta->get_texture();
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_texture
- // Access: Published
- // Description: Returns the texture that has been set on the
- // indicated stage for this particular node, or NULL if
- // no texture has been set for this stage.
- ////////////////////////////////////////////////////////////////////
- Texture *NodePath::
- get_texture(TextureStage *stage) const {
- nassertr_always(!is_empty(), NULL);
- const RenderAttrib *attrib =
- node()->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- return ta->get_on_texture(stage);
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_tex_transform
- // Access: Published
- // Description: Sets the texture matrix on the current node to the
- // indicated transform for the given stage.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_tex_transform(TextureStage *stage, const TransformState *transform) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TexMatrixAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, attrib);
- // Modify the existing TexMatrixAttrib to add the indicated
- // stage.
- node()->set_attrib(tma->add_stage(stage, transform));
- } else {
- // Create a new TexMatrixAttrib for this node.
- node()->set_attrib(TexMatrixAttrib::make(stage, transform));
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_tex_transform
- // Access: Published
- // Description: Removes all texture matrices from the current node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_tex_transform() {
- nassertv_always(!is_empty());
- node()->clear_attrib(TexMatrixAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_tex_transform
- // Access: Published
- // Description: Removes the texture matrix on the current node for
- // the given stage.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_tex_transform(TextureStage *stage) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TexMatrixAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- CPT(TexMatrixAttrib) tma = DCAST(TexMatrixAttrib, attrib);
- tma = DCAST(TexMatrixAttrib, tma->remove_stage(stage));
- if (tma->is_empty()) {
- node()->clear_attrib(TexMatrixAttrib::get_class_type());
- } else {
- node()->set_attrib(tma);
- }
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_tex_transform
- // Access: Published
- // Description: Returns true if there is an explicit texture matrix
- // on the current node for the given stage.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_tex_transform(TextureStage *stage) const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(TexMatrixAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, attrib);
- return tma->has_stage(stage);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_tex_transform
- // Access: Published
- // Description: Returns the texture matrix on the current node for the
- // given stage, or identity transform if there is no
- // explicit transform set for the given stage.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- get_tex_transform(TextureStage *stage) const {
- nassertr_always(!is_empty(), NULL);
- const RenderAttrib *attrib =
- node()->get_attrib(TexMatrixAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, attrib);
- return tma->get_transform(stage);
- }
- return TransformState::make_identity();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_tex_transform
- // Access: Published
- // Description: Sets the texture matrix on the current node to the
- // indicated transform for the given stage.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_tex_transform(const NodePath &other, TextureStage *stage, const TransformState *transform) {
- nassertv(_error_type == ET_ok && other._error_type == ET_ok);
- nassertv_always(!is_empty());
- CPT(RenderState) state = get_state(other);
- const RenderAttrib *attrib =
- state->get_attrib(TexMatrixAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, attrib);
- // Modify the existing TexMatrixAttrib to add the indicated
- // stage.
- state = state->add_attrib(tma->add_stage(stage, transform));
- } else {
- // Create a new TexMatrixAttrib for this node.
- state = state->add_attrib(TexMatrixAttrib::make(stage, transform));
- }
- // Now compose that with our parent's state.
- CPT(RenderState) rel_state;
- if (has_parent()) {
- rel_state = other.get_state(get_parent());
- } else {
- rel_state = other.get_state(NodePath());
- }
- CPT(RenderState) new_state = rel_state->compose(state);
- // And apply only the TexMatrixAttrib to the current node, leaving
- // the others unchanged.
- node()->set_attrib(new_state->get_attrib(TexMatrixAttrib::get_class_type()));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_tex_transform
- // Access: Published
- // Description: Returns the texture matrix on the current node for the
- // given stage, relative to the other node.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- get_tex_transform(const NodePath &other, TextureStage *stage) const {
- nassertr(_error_type == ET_ok && other._error_type == ET_ok, TransformState::make_identity());
- CPT(RenderState) state = get_state(other);
- const RenderAttrib *attrib =
- state->get_attrib(TexMatrixAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, attrib);
- return tma->get_transform(stage);
- }
- return TransformState::make_identity();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_tex_gen
- // Access: Published
- // Description: Enables automatic texture coordinate generation for
- // the indicated texture stage.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_tex_gen(TextureStage *stage, RenderAttrib::TexGenMode mode, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TexGenAttrib::get_class_type());
- CPT(TexGenAttrib) tga;
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(TextureAttrib::get_class_type()));
- tga = DCAST(TexGenAttrib, attrib);
- } else {
- tga = DCAST(TexGenAttrib, TexGenAttrib::make());
- }
- node()->set_attrib(tga->add_stage(stage, mode), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_tex_gen
- // Access: Published
- // Description: Enables automatic texture coordinate generation for
- // the indicated texture stage. This version of this
- // method is useful when setting M_light_vector, which
- // requires the name of the texture coordinate set that
- // supplies the tangent and binormal, as well as the
- // specific light to generate coordinates for.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_tex_gen(TextureStage *stage, RenderAttrib::TexGenMode mode,
- const string &source_name, const NodePath &light, int priority) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TexGenAttrib::get_class_type());
- CPT(TexGenAttrib) tga;
- if (attrib != (const RenderAttrib *)NULL) {
- priority = max(priority,
- node()->get_state()->get_override(TextureAttrib::get_class_type()));
- tga = DCAST(TexGenAttrib, attrib);
- } else {
- tga = DCAST(TexGenAttrib, TexGenAttrib::make());
- }
- node()->set_attrib(tga->add_stage(stage, mode, source_name, light), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_tex_gen
- // Access: Published
- // Description: Removes the texture coordinate generation mode from
- // all texture stages on this node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_tex_gen() {
- nassertv_always(!is_empty());
- node()->clear_attrib(TexGenAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_tex_gen
- // Access: Published
- // Description: Disables automatic texture coordinate generation for
- // the indicated texture stage.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_tex_gen(TextureStage *stage) {
- nassertv_always(!is_empty());
- const RenderAttrib *attrib =
- node()->get_attrib(TexGenAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- CPT(TexGenAttrib) tga = DCAST(TexGenAttrib, attrib);
- tga = DCAST(TexGenAttrib, tga->remove_stage(stage));
- if (tga->is_empty()) {
- node()->clear_attrib(TexGenAttrib::get_class_type());
- } else {
- node()->set_attrib(tga);
- }
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_tex_gen
- // Access: Published
- // Description: Returns true if there is a mode for automatic texture
- // coordinate generation on the current node for the
- // given stage.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_tex_gen(TextureStage *stage) const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(TexGenAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexGenAttrib *tga = DCAST(TexGenAttrib, attrib);
- return tga->has_stage(stage);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_tex_gen
- // Access: Published
- // Description: Returns the texture coordinate generation mode for
- // the given stage, or M_off if there is no explicit
- // mode set for the given stage.
- ////////////////////////////////////////////////////////////////////
- RenderAttrib::TexGenMode NodePath::
- get_tex_gen(TextureStage *stage) const {
- nassertr_always(!is_empty(), TexGenAttrib::M_off);
- const RenderAttrib *attrib =
- node()->get_attrib(TexGenAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexGenAttrib *tga = DCAST(TexGenAttrib, attrib);
- return tga->get_mode(stage);
- }
- return TexGenAttrib::M_off;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_tex_gen_light
- // Access: Published
- // Description: Returns the particular Light set for the indicated
- // texgen mode's texture stage, or empty NodePath if no
- // light is set. This is only meaningful if the texgen
- // mode (returned by get_tex_gen()) is M_light_vector.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- get_tex_gen_light(TextureStage *stage) const {
- nassertr_always(!is_empty(), NodePath::fail());
- const RenderAttrib *attrib =
- node()->get_attrib(TexGenAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TexGenAttrib *tga = DCAST(TexGenAttrib, attrib);
- return tga->get_light(stage);
- }
- return NodePath();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_tex_projector
- // Access: Published
- // Description: Establishes a TexProjectorEffect on this node, which
- // can be used to establish projective texturing (but
- // see also the NodePath::project_texture() convenience
- // function), or it can be used to bind this node's
- // texture transform to particular node's position in
- // space, allowing a LerpInterval (for instance) to
- // adjust this node's texture coordinates.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_tex_projector(TextureStage *stage, const NodePath &from, const NodePath &to) {
- nassertv_always(!is_empty());
- const RenderEffect *effect =
- node()->get_effect(TexProjectorEffect::get_class_type());
- CPT(TexProjectorEffect) tpe;
- if (effect != (const RenderEffect *)NULL) {
- tpe = DCAST(TexProjectorEffect, effect);
- } else {
- tpe = DCAST(TexProjectorEffect, TexProjectorEffect::make());
- }
- node()->set_effect(tpe->add_stage(stage, from, to));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_tex_projector
- // Access: Published
- // Description: Removes the TexProjectorEffect for the indicated
- // stage from this node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_tex_projector(TextureStage *stage) {
- nassertv_always(!is_empty());
- const RenderEffect *effect =
- node()->get_effect(TexProjectorEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- CPT(TexProjectorEffect) tpe = DCAST(TexProjectorEffect, effect);
- tpe = DCAST(TexProjectorEffect, tpe->remove_stage(stage));
- if (tpe->is_empty()) {
- node()->clear_effect(TexProjectorEffect::get_class_type());
- } else {
- node()->set_effect(tpe);
- }
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_tex_projector
- // Access: Published
- // Description: Removes the TexProjectorEffect for all stages from
- // this node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_tex_projector() {
- nassertv_always(!is_empty());
- node()->clear_effect(TexProjectorEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_tex_projector
- // Access: Published
- // Description: Returns true if this node has a TexProjectorEffect
- // for the indicated stage, false otherwise.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_tex_projector(TextureStage *stage) const {
- nassertr_always(!is_empty(), false);
- const RenderEffect *effect =
- node()->get_effect(TexProjectorEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- const TexProjectorEffect *tpe = DCAST(TexProjectorEffect, effect);
- return tpe->has_stage(stage);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_tex_projector_from
- // Access: Published
- // Description: Returns the "from" node associated with the
- // TexProjectorEffect on the indicated stage. The
- // relative transform between the "from" and the "to"
- // nodes is automatically applied to the texture
- // transform each frame.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- get_tex_projector_from(TextureStage *stage) const {
- nassertr_always(!is_empty(), NodePath::fail());
- const RenderEffect *effect =
- node()->get_effect(TexProjectorEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- const TexProjectorEffect *tpe = DCAST(TexProjectorEffect, effect);
- return tpe->get_from(stage);
- }
- return NodePath::not_found();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_tex_projector_to
- // Access: Published
- // Description: Returns the "to" node associated with the
- // TexProjectorEffect on the indicated stage. The
- // relative transform between the "from" and the "to"
- // nodes is automatically applied to the texture
- // transform each frame.
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- get_tex_projector_to(TextureStage *stage) const {
- nassertr_always(!is_empty(), NodePath::fail());
- const RenderEffect *effect =
- node()->get_effect(TexProjectorEffect::get_class_type());
- if (effect != (const RenderEffect *)NULL) {
- const TexProjectorEffect *tpe = DCAST(TexProjectorEffect, effect);
- return tpe->get_to(stage);
- }
- return NodePath::not_found();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::project_texture
- // Access: Published
- // Description: A convenience function to enable projective texturing
- // at this node level and below, using the indicated
- // NodePath (which should contain a LensNode) as the
- // projector.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- project_texture(TextureStage *stage, Texture *tex, const NodePath &projector) {
- nassertv(!projector.is_empty() && projector.node()->is_of_type(LensNode::get_class_type()));
- set_texture(stage, tex);
- set_tex_gen(stage, TexGenAttrib::M_world_position);
- set_tex_projector(stage, NodePath(), projector);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_texture
- // Access: Published
- // Description: Returns the first texture found applied to geometry
- // at this node or below that matches the indicated name
- // (which may contain wildcards). Returns the texture
- // if it is found, or NULL if it is not.
- ////////////////////////////////////////////////////////////////////
- Texture *NodePath::
- find_texture(const string &name) const {
- GlobPattern glob(name);
- return r_find_texture(node(), get_net_state(), glob);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_texture
- // Access: Published
- // Description: Returns the first texture found applied to geometry
- // at this node or below that is assigned to the
- // indicated texture stage. Returns the texture if it
- // is found, or NULL if it is not.
- ////////////////////////////////////////////////////////////////////
- Texture *NodePath::
- find_texture(TextureStage *stage) const {
- return r_find_texture(node(), stage);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_textures
- // Access: Published
- // Description: Returns a list of a textures applied to geometry at
- // this node and below.
- ////////////////////////////////////////////////////////////////////
- TextureCollection NodePath::
- find_all_textures() const {
- Textures textures;
- r_find_all_textures(node(), get_net_state(), textures);
- TextureCollection tc;
- Textures::iterator ti;
- for (ti = textures.begin(); ti != textures.end(); ++ti) {
- tc.add_texture(*ti);
- }
- return tc;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_textures
- // Access: Published
- // Description: Returns a list of a textures applied to geometry at
- // this node and below that match the indicated name
- // (which may contain wildcard characters).
- ////////////////////////////////////////////////////////////////////
- TextureCollection NodePath::
- find_all_textures(const string &name) const {
- Textures textures;
- r_find_all_textures(node(), get_net_state(), textures);
- GlobPattern glob(name);
- TextureCollection tc;
- Textures::iterator ti;
- for (ti = textures.begin(); ti != textures.end(); ++ti) {
- Texture *texture = (*ti);
- if (glob.matches(texture->get_name())) {
- tc.add_texture(texture);
- }
- }
- return tc;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_textures
- // Access: Published
- // Description: Returns a list of a textures on geometry at
- // this node and below that are assigned to the
- // indicated texture stage.
- ////////////////////////////////////////////////////////////////////
- TextureCollection NodePath::
- find_all_textures(TextureStage *stage) const {
- Textures textures;
- r_find_all_textures(node(), stage, textures);
- TextureCollection tc;
- Textures::iterator ti;
- for (ti = textures.begin(); ti != textures.end(); ++ti) {
- Texture *texture = (*ti);
- tc.add_texture(texture);
- }
- return tc;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_texture_stage
- // Access: Published
- // Description: Returns the first TextureStage found applied to
- // geometry at this node or below that matches the
- // indicated name (which may contain wildcards).
- // Returns the TextureStage if it is found, or NULL if
- // it is not.
- ////////////////////////////////////////////////////////////////////
- TextureStage *NodePath::
- find_texture_stage(const string &name) const {
- GlobPattern glob(name);
- return r_find_texture_stage(node(), get_net_state(), glob);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_texture_stages
- // Access: Published
- // Description: Returns a list of a TextureStages applied to geometry
- // at this node and below.
- ////////////////////////////////////////////////////////////////////
- TextureStageCollection NodePath::
- find_all_texture_stages() const {
- TextureStages texture_stages;
- r_find_all_texture_stages(node(), get_net_state(), texture_stages);
- TextureStageCollection tc;
- TextureStages::iterator ti;
- for (ti = texture_stages.begin(); ti != texture_stages.end(); ++ti) {
- tc.add_texture_stage(*ti);
- }
- return tc;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::unify_texture_stages
- // Access: Published
- // Description: Searches through all TextureStages at this node and
- // below. Any TextureStages that share the same name as
- // the indicated TextureStage object are replaced with
- // this object, thus ensuring that all geometry at this
- // node and below with a particular TextureStage name is
- // using the same TextureStage object.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- unify_texture_stages(TextureStage *stage) {
- r_unify_texture_stages(node(), stage);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_all_texture_stages
- // Access: Published
- // Description: Returns a list of a TextureStages applied to geometry
- // at this node and below that match the indicated name
- // (which may contain wildcard characters).
- ////////////////////////////////////////////////////////////////////
- TextureStageCollection NodePath::
- find_all_texture_stages(const string &name) const {
- TextureStages texture_stages;
- r_find_all_texture_stages(node(), get_net_state(), texture_stages);
- GlobPattern glob(name);
- TextureStageCollection tc;
- TextureStages::iterator ti;
- for (ti = texture_stages.begin(); ti != texture_stages.end(); ++ti) {
- TextureStage *texture_stage = (*ti);
- if (glob.matches(texture_stage->get_name())) {
- tc.add_texture_stage(texture_stage);
- }
- }
- return tc;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_material
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using the indicated material.
- //
- // This operation copies the given material pointer. If
- // the material structure is changed later, it must be
- // reapplied via another call to set_material().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_material(Material *mat, int priority) {
- nassertv_always(!is_empty());
- nassertv(mat != NULL);
- // We create a temporary Material pointer, a copy of the one we are
- // given, to allow the user to monkey with the material and set it
- // again later, with the desired effect. If we stored the user's
- // pointer directly, it would be bad if the user later modified the
- // values within the Material.
- PT(Material) temp = new Material(*mat);
- const Material *mp = MaterialPool::get_material(temp);
- node()->set_attrib(MaterialAttrib::make(mp), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_material_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using no material. This is normally the default, but
- // it may be useful to use this to contradict
- // set_material() at a higher node level (or, with a
- // priority, to override a set_material() at a lower
- // level).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_material_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(MaterialAttrib::make_off(), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_material
- // Access: Published
- // Description: Completely removes any material adjustment that may
- // have been set via set_material() from this particular
- // node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_material() {
- nassertv_always(!is_empty());
- node()->clear_attrib(MaterialAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_material
- // Access: Published
- // Description: Returns true if a material has been applied to this
- // particular node via set_material(), false otherwise.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_material() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(MaterialAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const MaterialAttrib *ma = DCAST(MaterialAttrib, attrib);
- return !ma->is_off();
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_material
- // Access: Published
- // Description: Returns the material that has been set on this
- // particular node, or NULL if no material has been set.
- // This is not necessarily the material that will be
- // applied to the geometry at or below this level, as
- // another material at a higher or lower level may
- // override.
- //
- // This function returns a copy of the given material,
- // to allow changes, if desired. Once changes are made,
- // they should be reapplied via set_material().
- ////////////////////////////////////////////////////////////////////
- PT(Material) NodePath::
- get_material() const {
- nassertr_always(!is_empty(), NULL);
- const RenderAttrib *attrib =
- node()->get_attrib(MaterialAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const MaterialAttrib *ma = DCAST(MaterialAttrib, attrib);
- return new Material(*ma->get_material());
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_fog
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using the indicated fog.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_fog(Fog *fog, int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(FogAttrib::make(fog), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_fog_off
- // Access: Published
- // Description: Sets the geometry at this level and below to render
- // using no fog. This is normally the default, but
- // it may be useful to use this to contradict
- // set_fog() at a higher node level (or, with a
- // priority, to override a set_fog() at a lower
- // level).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_fog_off(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(FogAttrib::make_off(), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_fog
- // Access: Published
- // Description: Completely removes any fog adjustment that may
- // have been set via set_fog() or set_fog_off()
- // from this particular node. This allows whatever
- // fogs might be otherwise affecting the geometry to
- // show instead.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_fog() {
- nassertv_always(!is_empty());
- node()->clear_attrib(FogAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_fog
- // Access: Published
- // Description: Returns true if a fog has been applied to this
- // particular node via set_fog(), false otherwise.
- // This is not the same thing as asking whether the
- // geometry at this node will be rendered with
- // fog, as there may be a fog in effect from a higher or
- // lower level.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_fog() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(FogAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const FogAttrib *fa = DCAST(FogAttrib, attrib);
- return !fa->is_off();
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_fog_off
- // Access: Published
- // Description: Returns true if a fog has been specifically
- // disabled on this particular node via
- // set_fog_off(), false otherwise. This is not the
- // same thing as asking whether the geometry at this
- // node will be rendered unfogged, as there may be a
- // fog in effect from a higher or lower level.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_fog_off() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(FogAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const FogAttrib *fa = DCAST(FogAttrib, attrib);
- return fa->is_off();
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_fog
- // Access: Published
- // Description: Returns the fog that has been set on this
- // particular node, or NULL if no fog has been set.
- // This is not necessarily the fog that will be
- // applied to the geometry at or below this level, as
- // another fog at a higher or lower level may
- // override.
- ////////////////////////////////////////////////////////////////////
- Fog *NodePath::
- get_fog() const {
- nassertr_always(!is_empty(), NULL);
- const RenderAttrib *attrib =
- node()->get_attrib(FogAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const FogAttrib *fa = DCAST(FogAttrib, attrib);
- return fa->get_fog();
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_render_mode_wireframe
- // Access: Published
- // Description: Sets up the geometry at this level and below (unless
- // overridden) to render in wireframe mode.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_render_mode_wireframe(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(RenderModeAttrib::make(RenderModeAttrib::M_wireframe), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_render_mode_filled
- // Access: Published
- // Description: Sets up the geometry at this level and below (unless
- // overridden) to render in filled (i.e. not wireframe)
- // mode.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_render_mode_filled(int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(RenderModeAttrib::make(RenderModeAttrib::M_filled), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_render_mode
- // Access: Published
- // Description: Sets up the geometry at this level and below (unless
- // overridden) to render in the specified mode and with
- // the indicated line and/or point thickness.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_render_mode(RenderModeAttrib::Mode mode, float thickness, int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(RenderModeAttrib::make(mode, thickness), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_render_mode
- // Access: Published
- // Description: Completely removes any render mode adjustment that
- // may have been set on this node via
- // set_render_mode_wireframe() or
- // set_render_mode_filled().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_render_mode() {
- nassertv_always(!is_empty());
- node()->clear_attrib(RenderModeAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_render_mode
- // Access: Published
- // Description: Returns true if a render mode has been explicitly set
- // on this particular node via set_render_mode() (or
- // set_render_mode_wireframe() or
- // set_render_mode_filled()), false otherwise.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_render_mode() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(RenderModeAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_render_mode
- // Access: Published
- // Description: Returns the render mode that has been specifically
- // set on this node via set_render_mode(), or
- // M_unchanged if nothing has been set.
- ////////////////////////////////////////////////////////////////////
- RenderModeAttrib::Mode NodePath::
- get_render_mode() const {
- nassertr_always(!is_empty(), RenderModeAttrib::M_unchanged);
- const RenderAttrib *attrib =
- node()->get_attrib(RenderModeAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const RenderModeAttrib *ta = DCAST(RenderModeAttrib, attrib);
- return ta->get_mode();
- }
- return RenderModeAttrib::M_unchanged;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_render_mode_thickness
- // Access: Published
- // Description: Returns the render mode thickness that has been
- // specifically set on this node via set_render_mode(),
- // or 0.0 if nothing has been set.
- ////////////////////////////////////////////////////////////////////
- float NodePath::
- get_render_mode_thickness() const {
- nassertr_always(!is_empty(), 0.0f);
- const RenderAttrib *attrib =
- node()->get_attrib(RenderModeAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const RenderModeAttrib *ta = DCAST(RenderModeAttrib, attrib);
- return ta->get_thickness();
- }
- return 0.0f;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_two_sided
- // Access: Published
- // Description: Specifically sets or disables two-sided rendering
- // mode on this particular node. If no other nodes
- // override, this will cause backfacing polygons to be
- // drawn (in two-sided mode, true) or culled (in
- // one-sided mode, false).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_two_sided(bool two_sided, int priority) {
- nassertv_always(!is_empty());
- CullFaceAttrib::Mode mode =
- two_sided ?
- CullFaceAttrib::M_cull_none :
- CullFaceAttrib::M_cull_clockwise;
- node()->set_attrib(CullFaceAttrib::make(mode), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_two_sided
- // Access: Published
- // Description: Completely removes any two-sided adjustment that
- // may have been set on this node via set_two_sided().
- // The geometry at this level and below will
- // subsequently be rendered either two-sided or
- // one-sided, according to whatever other nodes may have
- // had set_two_sided() on it, or according to the
- // initial state otherwise.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_two_sided() {
- nassertv_always(!is_empty());
- node()->clear_attrib(CullFaceAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_two_sided
- // Access: Published
- // Description: Returns true if a two-sided adjustment has been
- // explicitly set on this particular node via
- // set_two_sided(). If this returns true, then
- // get_two_sided() may be called to determine which has
- // been set.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_two_sided() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(CullFaceAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_two_sided
- // Access: Published
- // Description: Returns true if two-sided rendering has been
- // specifically set on this node via set_two_sided(), or
- // false if one-sided rendering has been specifically
- // set, or if nothing has been specifically set. See
- // also has_two_sided(). This does not necessarily
- // imply that the geometry will or will not be rendered
- // two-sided, as there may be other nodes that override.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- get_two_sided() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(CullFaceAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const CullFaceAttrib *cfa = DCAST(CullFaceAttrib, attrib);
- return (cfa->get_actual_mode() == CullFaceAttrib::M_cull_none);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_depth_test
- // Access: Published
- // Description: Specifically sets or disables the testing of the
- // depth buffer on this particular node. This is
- // normally on in the 3-d scene graph and off in the 2-d
- // scene graph; it should be on for rendering most 3-d
- // objects properly.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_depth_test(bool depth_test, int priority) {
- nassertv_always(!is_empty());
- DepthTestAttrib::PandaCompareFunc mode =
- depth_test ?
- DepthTestAttrib::M_less :
- DepthTestAttrib::M_none;
- node()->set_attrib(DepthTestAttrib::make(mode), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_depth_test
- // Access: Published
- // Description: Completely removes any depth-test adjustment that
- // may have been set on this node via set_depth_test().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_depth_test() {
- nassertv_always(!is_empty());
- node()->clear_attrib(DepthTestAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_depth_test
- // Access: Published
- // Description: Returns true if a depth-test adjustment has been
- // explicitly set on this particular node via
- // set_depth_test(). If this returns true, then
- // get_depth_test() may be called to determine which has
- // been set.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_depth_test() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(DepthTestAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_depth_test
- // Access: Published
- // Description: Returns true if depth-test rendering has been
- // specifically set on this node via set_depth_test(), or
- // false if depth-test rendering has been specifically
- // disabled, or if nothing has been specifically set. See
- // also has_depth_test().
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- get_depth_test() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(DepthTestAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const DepthTestAttrib *dta = DCAST(DepthTestAttrib, attrib);
- return (dta->get_mode() != DepthTestAttrib::M_none);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_depth_write
- // Access: Published
- // Description: Specifically sets or disables the writing to the
- // depth buffer on this particular node. This is
- // normally on in the 3-d scene graph and off in the 2-d
- // scene graph; it should be on for rendering most 3-d
- // objects properly.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_depth_write(bool depth_write, int priority) {
- nassertv_always(!is_empty());
- DepthWriteAttrib::Mode mode =
- depth_write ?
- DepthWriteAttrib::M_on :
- DepthWriteAttrib::M_off;
- node()->set_attrib(DepthWriteAttrib::make(mode), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_depth_write
- // Access: Published
- // Description: Completely removes any depth-write adjustment that
- // may have been set on this node via set_depth_write().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_depth_write() {
- nassertv_always(!is_empty());
- node()->clear_attrib(DepthWriteAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_depth_write
- // Access: Published
- // Description: Returns true if a depth-write adjustment has been
- // explicitly set on this particular node via
- // set_depth_write(). If this returns true, then
- // get_depth_write() may be called to determine which has
- // been set.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_depth_write() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(DepthWriteAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_depth_write
- // Access: Published
- // Description: Returns true if depth-write rendering has been
- // specifically set on this node via set_depth_write(), or
- // false if depth-write rendering has been specifically
- // disabled, or if nothing has been specifically set. See
- // also has_depth_write().
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- get_depth_write() const {
- nassertr_always(!is_empty(), false);
- const RenderAttrib *attrib =
- node()->get_attrib(DepthWriteAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const DepthWriteAttrib *dta = DCAST(DepthWriteAttrib, attrib);
- return (dta->get_mode() != DepthWriteAttrib::M_off);
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::do_billboard_axis
- // Access: Published
- // Description: Performs a billboard-type rotate to the indicated
- // camera node, one time only, and leaves the object
- // rotated. This is similar in principle to heads_up().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- do_billboard_axis(const NodePath &camera, float offset) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = camera.get_transform(get_parent());
- const LMatrix4f &rel_mat = transform->get_mat();
- LVector3f up = LVector3f::up();
- LVector3f rel_pos = -rel_mat.get_row3(3);
- LQuaternionf quat;
- ::heads_up(quat, rel_pos, up);
- set_quat(quat);
- // Also slide the geometry towards the camera according to the
- // offset factor.
- if (offset != 0.0f) {
- LVector3f translate = rel_mat.get_row3(3);
- translate.normalize();
- translate *= offset;
- set_pos(translate);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::do_billboard_point_eye
- // Access: Published
- // Description: Performs a billboard-type rotate to the indicated
- // camera node, one time only, and leaves the object
- // rotated. This is similar in principle to look_at(),
- // although the point_eye billboard effect cannot be
- // achieved using the ordinary look_at() call.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- do_billboard_point_eye(const NodePath &camera, float offset) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = camera.get_transform(get_parent());
- const LMatrix4f &rel_mat = transform->get_mat();
- LVector3f up = LVector3f::up() * rel_mat;
- LVector3f rel_pos = LVector3f::forward() * rel_mat;
- LQuaternionf quat;
- ::look_at(quat, rel_pos, up);
- set_quat(quat);
- // Also slide the geometry towards the camera according to the
- // offset factor.
- if (offset != 0.0f) {
- LVector3f translate = rel_mat.get_row3(3);
- translate.normalize();
- translate *= offset;
- set_pos(translate);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::do_billboard_point_world
- // Access: Published
- // Description: Performs a billboard-type rotate to the indicated
- // camera node, one time only, and leaves the object
- // rotated. This is similar in principle to look_at().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- do_billboard_point_world(const NodePath &camera, float offset) {
- nassertv_always(!is_empty());
- CPT(TransformState) transform = camera.get_transform(get_parent());
- const LMatrix4f &rel_mat = transform->get_mat();
- LVector3f up = LVector3f::up();
- LVector3f rel_pos = -rel_mat.get_row3(3);
- LQuaternionf quat;
- ::look_at(quat, rel_pos, up);
- set_quat(quat);
- // Also slide the geometry towards the camera according to the
- // offset factor.
- if (offset != 0.0f) {
- LVector3f translate = rel_mat.get_row3(3);
- translate.normalize();
- translate *= offset;
- set_pos(translate);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_billboard_axis
- // Access: Published
- // Description: Puts a billboard transition on the node such that it
- // will rotate in two dimensions around the up axis,
- // towards a specified "camera" instead of to the
- // viewing camera.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_billboard_axis(const NodePath &camera, float offset) {
- nassertv_always(!is_empty());
- CPT(RenderEffect) billboard = BillboardEffect::make
- (LVector3f::up(), false, true,
- offset, camera, LPoint3f(0.0f, 0.0f, 0.0f));
- node()->set_effect(billboard);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_billboard_point_eye
- // Access: Published
- // Description: Puts a billboard transition on the node such that it
- // will rotate in three dimensions about the origin,
- // keeping its up vector oriented to the top of the
- // camera, towards a specified "camera" instead of to
- // the viewing camera.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_billboard_point_eye(const NodePath &camera, float offset) {
- nassertv_always(!is_empty());
- CPT(RenderEffect) billboard = BillboardEffect::make
- (LVector3f::up(), true, false,
- offset, camera, LPoint3f(0.0f, 0.0f, 0.0f));
- node()->set_effect(billboard);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_billboard_point_world
- // Access: Published
- // Description: Puts a billboard transition on the node such that it
- // will rotate in three dimensions about the origin,
- // keeping its up vector oriented to the sky, towards a
- // specified "camera" instead of to the viewing camera.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_billboard_point_world(const NodePath &camera, float offset) {
- nassertv_always(!is_empty());
- CPT(RenderEffect) billboard = BillboardEffect::make
- (LVector3f::up(), false, false,
- offset, camera, LPoint3f(0.0f, 0.0f, 0.0f));
- node()->set_effect(billboard);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_billboard
- // Access: Published
- // Description: Removes any billboard effect from the node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_billboard() {
- nassertv_always(!is_empty());
- node()->clear_effect(BillboardEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_billboard
- // Access: Published
- // Description: Returns true if there is any billboard effect on
- // the node.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_billboard() const {
- nassertr_always(!is_empty(), false);
- return node()->has_effect(BillboardEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_compass
- // Access: Published
- // Description: Puts a compass effect on the node, so that it will
- // retain a fixed rotation relative to the reference
- // node (or render if the reference node is empty)
- // regardless of the transforms above it.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_compass(const NodePath &reference) {
- nassertv_always(!is_empty());
- node()->set_effect(CompassEffect::make(reference));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_compass
- // Access: Published
- // Description: Removes any compass effect from the node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_compass() {
- nassertv_always(!is_empty());
- node()->clear_effect(CompassEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_compass
- // Access: Published
- // Description: Returns true if there is any compass effect on
- // the node.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_compass() const {
- nassertr_always(!is_empty(), false);
- return node()->has_effect(CompassEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_transparency
- // Access: Published
- // Description: Specifically sets or disables transparent rendering
- // mode on this particular node. If no other nodes
- // override, this will cause items with a non-1 value
- // for alpha color to be rendered partially transparent.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_transparency(TransparencyAttrib::Mode mode, int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(TransparencyAttrib::make(mode), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_transparency
- // Access: Published
- // Description: Completely removes any transparency adjustment that
- // may have been set on this node via set_transparency().
- // The geometry at this level and below will
- // subsequently be rendered either transparent or not,
- // to whatever other nodes may have had
- // set_transparency() on them.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_transparency() {
- nassertv_always(!is_empty());
- node()->clear_attrib(TransparencyAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_transparency
- // Access: Published
- // Description: Returns true if a transparent-rendering adjustment
- // has been explicitly set on this particular node via
- // set_transparency(). If this returns true, then
- // get_transparency() may be called to determine whether
- // transparency has been explicitly enabled or
- // explicitly disabled for this node.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_transparency() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(TransparencyAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_transparency
- // Access: Published
- // Description: Returns the transparent rendering that has been
- // specifically set on this node via set_transparency(), or
- // M_none if nontransparent rendering has been specifically
- // set, or if nothing has been specifically set. See
- // also has_transparency(). This does not necessarily
- // imply that the geometry will or will not be rendered
- // transparent, as there may be other nodes that override.
- ////////////////////////////////////////////////////////////////////
- TransparencyAttrib::Mode NodePath::
- get_transparency() const {
- nassertr_always(!is_empty(), TransparencyAttrib::M_none);
- const RenderAttrib *attrib =
- node()->get_attrib(TransparencyAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TransparencyAttrib *ta = DCAST(TransparencyAttrib, attrib);
- return ta->get_mode();
- }
- return TransparencyAttrib::M_none;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::set_antialias
- // Access: Published
- // Description: Specifies the antialiasing type that should be
- // applied at this node and below. See AntialiasAttrib.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- set_antialias(unsigned short mode, int priority) {
- nassertv_always(!is_empty());
- node()->set_attrib(AntialiasAttrib::make(mode), priority);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::clear_antialias
- // Access: Published
- // Description: Completely removes any antialias setting that
- // may have been set on this node via set_antialias().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- clear_antialias() {
- nassertv_always(!is_empty());
- node()->clear_attrib(AntialiasAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::has_antialias
- // Access: Published
- // Description: Returns true if an antialias setting has been
- // explicitly mode on this particular node via
- // set_antialias(). If this returns true, then
- // get_antialias() may be called to determine what the
- // setting was.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- has_antialias() const {
- nassertr_always(!is_empty(), false);
- return node()->has_attrib(AntialiasAttrib::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_antialias
- // Access: Published
- // Description: Returns the antialias setting that has been
- // specifically set on this node via set_antialias(), or
- // M_none if no setting has been made.
- ////////////////////////////////////////////////////////////////////
- unsigned short NodePath::
- get_antialias() const {
- nassertr_always(!is_empty(), AntialiasAttrib::M_none);
- const RenderAttrib *attrib =
- node()->get_attrib(AntialiasAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const AntialiasAttrib *ta = DCAST(AntialiasAttrib, attrib);
- return ta->get_mode();
- }
- return AntialiasAttrib::M_none;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_hidden_ancestor
- // Access: Published
- // Description: Returns the NodePath at or above the referenced node
- // that is hidden to the indicated camera(s), or an
- // empty NodePath if no ancestor of the referenced node
- // is hidden (and the node should be visible).
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- get_hidden_ancestor(DrawMask camera_mask) const {
- NodePathComponent *comp;
- for (comp = _head;
- comp != (NodePathComponent *)NULL;
- comp = comp->get_next()) {
- PandaNode *node = comp->get_node();
- if ((node->get_draw_mask() & camera_mask).is_zero()) {
- NodePath result;
- result._head = comp;
- return result;
- }
- }
- return not_found();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::stash
- // Access: Published
- // Description: Removes the referenced node (and the entire subgraph
- // below this node) from the scene graph in any normal
- // sense. The node will no longer be visible and is not
- // tested for collisions; furthermore, no normal scene
- // graph traversal will visit the node. The node's
- // bounding volume no longer contributes to its parent's
- // bounding volume.
- //
- // A stashed node cannot be located by a normal find()
- // operation (although a special find string can still
- // retrieve it).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- stash(int sort) {
- nassertv_always(!is_singleton() && !is_empty());
- nassertv(verify_complete());
- bool reparented = PandaNode::reparent(_head->get_next(), _head, sort, true);
- nassertv(reparented);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::unstash
- // Access: Published
- // Description: Undoes the effect of a previous stash() on this
- // node: makes the referenced node (and the entire
- // subgraph below this node) once again part of the
- // scene graph.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- unstash(int sort) {
- nassertv_always(!is_singleton() && !is_empty());
- nassertv(verify_complete());
- bool reparented = PandaNode::reparent(_head->get_next(), _head, sort, false);
- nassertv(reparented);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::unstash_all
- // Access: Published
- // Description: Unstashes this node and all stashed child nodes.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- unstash_all() {
- NodePathCollection stashed_descendents = find_all_matches("**/@@*");
- stashed_descendents.unstash();
- unstash();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_stashed_ancestor
- // Access: Published
- // Description: Returns the NodePath at or above the referenced node
- // that is stashed, or an empty NodePath if no ancestor
- // of the referenced node is stashed (and the node should
- // be visible).
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- get_stashed_ancestor() const {
- NodePathComponent *comp = _head;
- if (comp != (NodePathComponent *)NULL) {
- NodePathComponent *next = comp->get_next();
- while (next != (NodePathComponent *)NULL) {
- PandaNode *node = comp->get_node();
- PandaNode *parent_node = next->get_node();
- if (parent_node->find_stashed(node) >= 0) {
- NodePath result;
- result._head = comp;
- return result;
- }
- comp = next;
- next = next->get_next();
- }
- }
- return not_found();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::verify_complete
- // Access: Published
- // Description: Returns true if all of the nodes described in the
- // NodePath are connected, or false otherwise.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- verify_complete() const {
- if (is_empty()) {
- return true;
- }
- const NodePathComponent *comp = _head;
- nassertr(comp != (const NodePathComponent *)NULL, false);
- PandaNode *node = comp->get_node();
- nassertr(node != (const PandaNode *)NULL, false);
- int length = comp->get_length();
- comp = comp->get_next();
- length--;
- while (comp != (const NodePathComponent *)NULL) {
- PandaNode *next_node = comp->get_node();
- nassertr(next_node != (const PandaNode *)NULL, false);
- if (node->find_parent(next_node) < 0) {
- pgraph_cat.warning()
- << *this << " is incomplete; " << *node << " is not a child of "
- << *next_node << "\n";
- return false;
- }
- if (comp->get_length() != length) {
- pgraph_cat.warning()
- << *this << " is incomplete; length at " << *next_node
- << " indicates " << comp->get_length() << " while length at "
- << *node << " indicates " << length << "\n";
- return false;
- }
- node = next_node;
- comp = comp->get_next();
- length--;
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::prepare_scene
- // Access: Published
- // Description: Walks through the scene graph beginning at the bottom
- // node, and does whatever initialization is required to
- // render the scene properly with the indicated GSG. It
- // is not strictly necessary to call this, since the GSG
- // will initialize itself when the scene is rendered,
- // but this may take some of the overhead away from that
- // process.
- //
- // In particular, this will ensure that textures within
- // the scene are loaded in texture memory, and display
- // lists are built up from static geometry.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- prepare_scene(GraphicsStateGuardianBase *gsg) {
- nassertv_always(!is_empty());
- PreparedGraphicsObjects *prepared_objects = gsg->get_prepared_objects();
- CPT(RenderState) net_state = get_net_state();
- r_prepare_scene(node(), net_state, prepared_objects);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::show_bounds
- // Access: Published
- // Description: Causes the bounding volume of the bottom node and all
- // of its descendants (that is, the bounding volume
- // associated with the the bottom arc) to be rendered,
- // if possible. The rendering method is less than
- // optimal; this is intended primarily for debugging.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- show_bounds() {
- nassertv_always(!is_empty());
- node()->set_effect(ShowBoundsEffect::make(false));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::show_tight_bounds
- // Access: Published
- // Description: Similar to show_bounds(), this draws a bounding box
- // representing the "tight" bounds of this node and all
- // of its descendants. The bounding box is recomputed
- // every frame by reexamining all of the vertices; this
- // is far from efficient, but this is intended for
- // debugging.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- show_tight_bounds() {
- nassertv_always(!is_empty());
- node()->set_effect(ShowBoundsEffect::make(true));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::hide_bounds
- // Access: Published
- // Description: Stops the rendering of the bounding volume begun with
- // show_bounds().
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- hide_bounds() {
- nassertv_always(!is_empty());
- node()->clear_effect(ShowBoundsEffect::get_class_type());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::get_bounds
- // Access: Published
- // Description: Returns a newly-allocated bounding volume containing
- // the bottom node and all of its descendants. This is
- // the bounding volume on the bottom arc, converted to
- // the local coordinate space of the node.
- ////////////////////////////////////////////////////////////////////
- PT(BoundingVolume) NodePath::
- get_bounds() const {
- nassertr_always(!is_empty(), new BoundingSphere);
- return node()->get_bound().make_copy();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::force_recompute_bounds
- // Access: Published
- // Description: Forces the recomputing of all the bounding volumes at
- // every node in the subgraph beginning at this node and
- // below.
- //
- // This should not normally need to be called, since the
- // bounding volumes are supposed to be recomputed
- // automatically when necessary. It may be useful when
- // debugging, to verify that the bounding volumes have
- // not become inadvertently stale; it may also be useful
- // to force animated characters to update their bounding
- // volumes (which does not presently happen
- // automatically).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- force_recompute_bounds() {
- nassertv_always(!is_empty());
- r_force_recompute_bounds(node());
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::write_bounds
- // Access: Published
- // Description: Writes a description of the bounding volume
- // containing the bottom node and all of its descendants
- // to the indicated output stream.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- write_bounds(ostream &out) const {
- get_bounds()->write(out);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::calc_tight_bounds
- // Access: Published
- // Description: Calculates the minimum and maximum vertices of all
- // Geoms at this NodePath's bottom node and below. This
- // is a tight bounding box; it will generally be tighter
- // than the bounding volume returned by get_bounds()
- // (but it is more expensive to compute).
- //
- // The return value is true if any points are within the
- // bounding volume, or false if none are.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point) {
- min_point.set(0.0f, 0.0f, 0.0f);
- max_point.set(0.0f, 0.0f, 0.0f);
- nassertr_always(!is_empty(), false);
- bool found_any = false;
- node()->calc_tight_bounds(min_point, max_point, found_any,
- TransformState::make_identity());
- return found_any;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::analyze
- // Access: Published
- // Description: Analyzes the geometry below this node and reports the
- // number of vertices, triangles, etc. This is the same
- // information reported by the bam-info program.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- analyze() const {
- nassertv_always(!is_empty());
- SceneGraphAnalyzer sga;
- sga.add_node(node());
- sga.write(nout);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::flatten_light
- // Access: Published
- // Description: Lightly flattens out the hierarchy below this node by
- // applying transforms, colors, and texture matrices
- // from the arcs onto the vertices, but does not remove
- // any nodes.
- //
- // This can result in improved rendering performance
- // because there will be fewer transforms in the
- // resulting scene graph, but the number of nodes will
- // remain the same.
- //
- // Particularly, any NodePaths that reference nodes
- // within this hierarchy will not be damaged. However,
- // since this operation will remove transforms from the
- // scene graph, it may be dangerous to apply to arcs
- // where you expect to dynamically modify the transform,
- // or where you expect the geometry to remain in a
- // particular local coordinate system.
- //
- // The return value is always 0, since flatten_light
- // does not remove any arcs.
- ////////////////////////////////////////////////////////////////////
- int NodePath::
- flatten_light() {
- nassertr_always(!is_empty(), 0);
- SceneGraphReducer gr;
- gr.apply_attribs(node());
- return 0;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::flatten_medium
- // Access: Published
- // Description: A more thorough flattening than flatten_light(), this
- // first applies all the transforms, colors, and texture
- // matrices from the arcs onto the vertices, and then
- // removes unneeded grouping nodes--nodes that have
- // exactly one child, for instance, but have no special
- // properties in themselves.
- //
- // This results in improved perforamance over
- // flatten_light() because the number of nodes in the
- // scene graph is reduced.
- //
- // If max_children is specified, it represents the
- // maximum number of children a node is allowed to have
- // and still be flattened. Normally, this is 1; we
- // don't typically want to flatten a node that has
- // multiple children. However, sometimes this may be
- // desirable; set this parameter to control the limit.
- // If this is set to -1, there is no limit.
- //
- // The return value is the number of arcs removed.
- ////////////////////////////////////////////////////////////////////
- int NodePath::
- flatten_medium() {
- nassertr_always(!is_empty(), 0);
- SceneGraphReducer gr;
- gr.apply_attribs(node());
- int num_removed = gr.flatten(node(), 0);
- return num_removed;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::flatten_strong
- // Access: Published
- // Description: The strongest possible flattening. This first
- // applies all of the transforms to the vertices, as in
- // flatten_medium(), but then it will combine sibling
- // nodes together when possible, in addition to removing
- // unnecessary parent-child nodes. This can result in
- // substantially fewer nodes, but any nicely-grouped
- // hierachical bounding volumes may be lost.
- //
- // It is generally a good idea to apply this kind of
- // flattening only to nodes that will be culled largely
- // as a single unit, like a car. Applying this to an
- // entire scene may result in overall poorer performance
- // because of less-effective culling.
- ////////////////////////////////////////////////////////////////////
- int NodePath::
- flatten_strong() {
- nassertr_always(!is_empty(), 0);
- SceneGraphReducer gr;
- gr.apply_attribs(node());
- int num_removed = gr.flatten(node(), ~0);
- return num_removed;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_net_tag
- // Access: Published
- // Description: Returns the lowest ancestor of this node that
- // contains a tag definition with the indicated key, if
- // any, or an empty NodePath if no ancestor of this node
- // contains this tag definition. See set_tag().
- ////////////////////////////////////////////////////////////////////
- NodePath NodePath::
- find_net_tag(const string &key) const {
- if (is_empty()) {
- return NodePath::not_found();
- }
- if (has_tag(key)) {
- return *this;
- }
- return get_parent().find_net_tag(key);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::write_bam_file
- // Access: Published
- // Description: Writes the contents of this node and below out to a
- // bam file with the indicated filename. This file may
- // then be read in again, as is, at some later point.
- // Returns true if successful, false on some kind of
- // error.
- ////////////////////////////////////////////////////////////////////
- bool NodePath::
- write_bam_file(const string &filename) const {
- nassertr_always(!is_empty(), false);
- BamFile bam_file;
- bool okflag = false;
- if (bam_file.open_write(filename)) {
- if (bam_file.write_object(node())) {
- okflag = true;
- }
- bam_file.close();
- }
- return okflag;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_common_ancestor
- // Access: Private, Static
- // Description: Walks up from both NodePaths to find the first node
- // that both have in common, if any. Fills a_count and
- // b_count with the number of nodes below the common
- // node in each path.
- //
- // The return value is the NodePathComponent of the node
- // they have in common, or NULL if they have nothing in
- // common.
- ////////////////////////////////////////////////////////////////////
- NodePathComponent *NodePath::
- find_common_ancestor(const NodePath &a, const NodePath &b,
- int &a_count, int &b_count) {
- nassertr(!a.is_empty() && !b.is_empty(), NULL);
- NodePathComponent *ac = a._head;
- NodePathComponent *bc = b._head;
- a_count = 0;
- b_count = 0;
- // Shorten up the longer one until they are the same length.
- while (ac->get_length() > bc->get_length()) {
- nassertr(ac != (NodePathComponent *)NULL, NULL);
- ac = ac->get_next();
- a_count++;
- }
- while (bc->get_length() > ac->get_length()) {
- nassertr(bc != (NodePathComponent *)NULL, NULL);
- bc = bc->get_next();
- b_count++;
- }
- // Now shorten them both up until we reach the same component.
- while (ac != bc) {
- // These shouldn't go to NULL unless they both go there together.
- nassertr(ac != (NodePathComponent *)NULL, NULL);
- nassertr(bc != (NodePathComponent *)NULL, NULL);
- ac = ac->get_next();
- a_count++;
- bc = bc->get_next();
- b_count++;
- }
- return ac;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_get_net_state
- // Access: Private
- // Description: Recursively determines the net state changes to the
- // indicated component node from the root of the graph.
- ////////////////////////////////////////////////////////////////////
- CPT(RenderState) NodePath::
- r_get_net_state(NodePathComponent *comp) const {
- if (comp == (NodePathComponent *)NULL) {
- return RenderState::make_empty();
- } else {
- CPT(RenderState) state = comp->get_node()->get_state();
- return r_get_net_state(comp->get_next())->compose(state);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_get_partial_state
- // Access: Private
- // Description: Recursively determines the net state changes to the
- // indicated component node from the nth node above it.
- // If n exceeds the length of the path, this returns the
- // net transform from the root of the graph.
- ////////////////////////////////////////////////////////////////////
- CPT(RenderState) NodePath::
- r_get_partial_state(NodePathComponent *comp, int n) const {
- if (n == 0 || comp == (NodePathComponent *)NULL) {
- return RenderState::make_empty();
- } else {
- CPT(RenderState) state = comp->get_node()->get_state();
- return r_get_partial_state(comp->get_next(), n - 1)->compose(state);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_get_net_transform
- // Access: Private
- // Description: Recursively determines the net transform to the
- // indicated component node from the root of the graph.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- r_get_net_transform(NodePathComponent *comp) const {
- if (comp == (NodePathComponent *)NULL) {
- return TransformState::make_identity();
- } else {
- CPT(TransformState) net_transform = r_get_net_transform(comp->get_next());
- CPT(TransformState) transform = comp->get_node()->get_transform();
- CPT(RenderEffects) effects = comp->get_node()->get_effects();
- if (effects->has_adjust_transform()) {
- effects->adjust_transform(net_transform, transform);
- }
-
- return net_transform->compose(transform);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_get_partial_transform
- // Access: Private
- // Description: Recursively determines the net transform to the
- // indicated component node from the nth node above it.
- // If n exceeds the length of the path, this returns the
- // net transform from the root of the graph.
- //
- // If any node in the path had a net_transform effect
- // applied, returns NULL--in this case the partial
- // transform cannot be easily determined.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- r_get_partial_transform(NodePathComponent *comp, int n) const {
- if (n == 0 || comp == (NodePathComponent *)NULL) {
- return TransformState::make_identity();
- } else {
- if (comp->get_node()->get_effects()->has_adjust_transform()) {
- return NULL;
- }
- CPT(TransformState) transform = comp->get_node()->get_transform();
- CPT(TransformState) partial = r_get_partial_transform(comp->get_next(), n - 1);
- if (partial == (const TransformState *)NULL) {
- return NULL;
- }
- return partial->compose(transform);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_get_net_prev_transform
- // Access: Private
- // Description: Recursively determines the net "previous" transform
- // to the indicated component node from the root of the
- // graph.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- r_get_net_prev_transform(NodePathComponent *comp) const {
- if (comp == (NodePathComponent *)NULL) {
- return TransformState::make_identity();
- } else {
- CPT(TransformState) transform = comp->get_node()->get_prev_transform();
- return r_get_net_prev_transform(comp->get_next())->compose(transform);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_get_partial_prev_transform
- // Access: Private
- // Description: Recursively determines the net "previous" transform
- // to the indicated component node from the nth node
- // above it. If n exceeds the length of the path, this
- // returns the net previous transform from the root of
- // the graph.
- ////////////////////////////////////////////////////////////////////
- CPT(TransformState) NodePath::
- r_get_partial_prev_transform(NodePathComponent *comp, int n) const {
- if (n == 0 || comp == (NodePathComponent *)NULL) {
- return TransformState::make_identity();
- } else {
- CPT(TransformState) transform = comp->get_node()->get_prev_transform();
- return r_get_partial_prev_transform(comp->get_next(), n - 1)->compose(transform);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_matches
- // Access: Private
- // Description: Finds up to max_matches matches against the given
- // path string from this node and deeper. The
- // max_matches count indicates the maximum number of
- // matches to return, or -1 not to limit the number
- // returned.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- find_matches(NodePathCollection &result, const string &path,
- int max_matches) const {
- if (is_empty()) {
- pgraph_cat.warning()
- << "Attempt to extend an empty NodePath by '" << path
- << "'.\n";
- return;
- }
- FindApproxPath approx_path;
- if (approx_path.add_string(path)) {
- find_matches(result, approx_path, max_matches);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_matches
- // Access: Private
- // Description: Finds up to max_matches matches against the given
- // approx_path from this node and deeper. The
- // max_matches count indicates the maximum number of
- // matches to return, or -1 not to limit the number
- // returned.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- find_matches(NodePathCollection &result, FindApproxPath &approx_path,
- int max_matches) const {
- if (is_empty()) {
- pgraph_cat.warning()
- << "Attempt to extend an empty NodePath by: " << approx_path << ".\n";
- return;
- }
- // We start with just one entry on the level.
- FindApproxLevelEntry *level =
- new FindApproxLevelEntry(WorkingNodePath(*this), approx_path);
- nassertv(level->_node_path.is_valid());
- find_matches(result, level, max_matches);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::find_matches
- // Access: Private
- // Description: The fundamental implementation of find_matches(),
- // given a starting level (a linked list of
- // FindApproxLevelEntry objects).
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- find_matches(NodePathCollection &result, FindApproxLevelEntry *level,
- int max_matches) const {
-
- int num_levels_remaining = _max_search_depth;
- FindApproxLevelEntry *deleted_entries = NULL;
- while (num_levels_remaining > 0 && level != NULL) {
- if (pgraph_cat.is_debug()) {
- pgraph_cat.debug()
- << "find_matches pass: " << result << ", "
- << max_matches << ", " << num_levels_remaining << "\n";
- level->write_level(pgraph_cat.debug(false), 4);
- }
- num_levels_remaining--;
- FindApproxLevelEntry *next_level = NULL;
- // For each node in the current level, build up the set of possible
- // matches in the next level.
- FindApproxLevelEntry *entry = level;
- while (entry != (FindApproxLevelEntry *)NULL) {
- if (entry->consider_node(result, next_level, max_matches, 0)) {
- // If we found the requisite number of matches, we can stop.
- // Delete all remaining entries and return immediately.
- while (entry != (FindApproxLevelEntry *)NULL) {
- FindApproxLevelEntry *next = entry->_next;
- delete entry;
- entry = next;
- }
- while (next_level != (FindApproxLevelEntry *)NULL) {
- FindApproxLevelEntry *next = next_level->_next;
- delete next_level;
- next_level = next;
- }
- while (deleted_entries != (FindApproxLevelEntry *)NULL) {
- FindApproxLevelEntry *next = deleted_entries->_next;
- delete deleted_entries;
- deleted_entries = next;
- }
- return;
- }
- // Move the entry to the delete chain so we can delete it before
- // we return from this method. (We can't delete it immediately,
- // because there might be WorkingNodePaths in the next_level
- // that reference the WorkingNodePath object within the entry.)
- FindApproxLevelEntry *next = entry->_next;
- entry->_next = deleted_entries;
- deleted_entries = entry;
- entry = next;
- }
-
- // Make sure the remaining entries from this level are added to
- // the delete chain.
- while (entry != (FindApproxLevelEntry *)NULL) {
- FindApproxLevelEntry *next = entry->_next;
- entry->_next = deleted_entries;
- deleted_entries = entry;
- entry = next;
- }
- level = next_level;
- }
- // Now it's safe to delete all entries on the delete chain.
- while (deleted_entries != (FindApproxLevelEntry *)NULL) {
- FindApproxLevelEntry *next = deleted_entries->_next;
- delete deleted_entries;
- deleted_entries = next;
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_adjust_all_priorities
- // Access: Private
- // Description: The recursive implementation of
- // adjust_all_priorities(). This walks through the
- // subgraph defined by the indicated node and below.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_adjust_all_priorities(PandaNode *node, int adjustment) {
- node->set_state(node->get_state()->adjust_all_priorities(adjustment));
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- gnode->set_geom_state(i, gnode->get_geom_state(i)->adjust_all_priorities(adjustment));
- }
- }
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- r_adjust_all_priorities(cr.get_child(i), adjustment);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_force_recompute_bounds
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_force_recompute_bounds(PandaNode *node) {
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- const Geom *geom = gnode->get_geom(i);
- // It's ok to cast away the const modifier on this Geom pointer,
- // since marking the bounding volume stale doesn't really change
- // the Geom in any substantial way.
- ((Geom *)geom)->mark_bound_stale();
- }
- }
- node->mark_bound_stale();
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- r_force_recompute_bounds(cr.get_child(i));
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_set_collide_mask
- // Access: Private
- // Description: Recursively applies the indicated collide mask to the
- // nodes at and below this node.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_set_collide_mask(PandaNode *node,
- CollideMask and_mask, CollideMask or_mask,
- TypeHandle node_type) {
- if (node->is_of_type(node_type)) {
- CollideMask into_collide_mask = node->get_into_collide_mask();
- into_collide_mask = (into_collide_mask & and_mask) | or_mask;
- node->set_into_collide_mask(into_collide_mask);
- }
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- r_set_collide_mask(cr.get_child(i), and_mask, or_mask, node_type);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_find_texture
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- Texture * NodePath::
- r_find_texture(PandaNode *node, const RenderState *state,
- const GlobPattern &glob) const {
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_R(gnode, node, NULL);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state =
- state->compose(gnode->get_geom_state(i));
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- for (int i = 0; i < ta->get_num_on_stages(); i++) {
- Texture *texture = ta->get_on_texture(ta->get_on_stage(i));
- if (texture != (Texture *)NULL) {
- if (glob.matches(texture->get_name())) {
- return texture;
- }
- }
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- CPT(RenderState) next_state = state->compose(child->get_state());
- Texture *result = r_find_texture(child, next_state, glob);
- if (result != (Texture *)NULL) {
- return result;
- }
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_find_all_textures
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_find_all_textures(PandaNode *node, const RenderState *state,
- NodePath::Textures &textures) const {
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state =
- state->compose(gnode->get_geom_state(i));
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- for (int i = 0; i < ta->get_num_on_stages(); i++) {
- Texture *texture = ta->get_on_texture(ta->get_on_stage(i));
- if (texture != (Texture *)NULL) {
- textures.insert(texture);
- }
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- CPT(RenderState) next_state = state->compose(child->get_state());
- r_find_all_textures(child, next_state, textures);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_find_texture
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- Texture * NodePath::
- r_find_texture(PandaNode *node, TextureStage *stage) const {
- // Look for a TextureAttrib on the node.
- const RenderAttrib *attrib =
- node->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- if (ta->has_on_stage(stage)) {
- return ta->get_on_texture(stage);
- }
- }
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_R(gnode, node, NULL);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state = gnode->get_geom_state(i);
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- if (ta->has_on_stage(stage)) {
- return ta->get_on_texture(stage);
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- Texture *result = r_find_texture(child, stage);
- if (result != (Texture *)NULL) {
- return result;
- }
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_find_all_textures
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_find_all_textures(PandaNode *node, TextureStage *stage,
- NodePath::Textures &textures) const {
- // Look for a TextureAttrib on the node.
- const RenderAttrib *attrib =
- node->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- if (ta->has_on_stage(stage)) {
- textures.insert(ta->get_on_texture(stage));
- }
- }
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state = gnode->get_geom_state(i);
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- if (ta->has_on_stage(stage)) {
- textures.insert(ta->get_on_texture(stage));
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- r_find_all_textures(child, stage, textures);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_find_texture_stage
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- TextureStage * NodePath::
- r_find_texture_stage(PandaNode *node, const RenderState *state,
- const GlobPattern &glob) const {
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_R(gnode, node, NULL);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state =
- state->compose(gnode->get_geom_state(i));
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- for (int i = 0; i < ta->get_num_on_stages(); i++) {
- TextureStage *texture_stage = ta->get_on_stage(i);
- if (texture_stage != (TextureStage *)NULL) {
- if (glob.matches(texture_stage->get_name())) {
- return texture_stage;
- }
- }
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- CPT(RenderState) next_state = state->compose(child->get_state());
- TextureStage *result = r_find_texture_stage(child, next_state, glob);
- if (result != (TextureStage *)NULL) {
- return result;
- }
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_find_all_texture_stages
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_find_all_texture_stages(PandaNode *node, const RenderState *state,
- NodePath::TextureStages &texture_stages) const {
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state =
- state->compose(gnode->get_geom_state(i));
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- for (int i = 0; i < ta->get_num_on_stages(); i++) {
- TextureStage *texture_stage = ta->get_on_stage(i);
- if (texture_stage != (TextureStage *)NULL) {
- texture_stages.insert(texture_stage);
- }
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- CPT(RenderState) next_state = state->compose(child->get_state());
- r_find_all_texture_stages(child, next_state, texture_stages);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_unify_texture_stages
- // Access: Private
- // Description:
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_unify_texture_stages(PandaNode *node, TextureStage *stage) {
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- node->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- CPT(RenderAttrib) new_attrib = ta->unify_texture_stages(stage);
- if (new_attrib != ta) {
- node->set_attrib(new_attrib);
- }
- }
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) state = gnode->get_geom_state(i);
- // Look for a TextureAttrib on the state.
- const RenderAttrib *attrib =
- state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta = DCAST(TextureAttrib, attrib);
- CPT(RenderAttrib) new_attrib = ta->unify_texture_stages(stage);
- if (new_attrib != ta) {
- CPT(RenderState) new_state = state->add_attrib(new_attrib);
- gnode->set_geom_state(i, new_state);
- }
- }
- }
- }
- // Now consider children.
- PandaNode::Children cr = node->get_children();
- int num_children = cr.get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = cr.get_child(i);
- r_unify_texture_stages(child, stage);
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: NodePath::r_prepare_scene
- // Access: Private
- // Description: The recursive implementation of prepare_scene.
- ////////////////////////////////////////////////////////////////////
- void NodePath::
- r_prepare_scene(PandaNode *node, const RenderState *state,
- PreparedGraphicsObjects *prepared_objects) {
- if (node->is_geom_node()) {
- GeomNode *gnode;
- DCAST_INTO_V(gnode, node);
- /*
- Not implemented yet in pgraph. Maybe we don't need this anyway.
- if (retained_mode) {
- gnode->prepare(gsg);
- }
- */
- int num_geoms = gnode->get_num_geoms();
- for (int i = 0; i < num_geoms; i++) {
- CPT(RenderState) geom_state = state->compose(gnode->get_geom_state(i));
- const RenderAttrib *attrib =
- geom_state->get_attrib(TextureAttrib::get_class_type());
- if (attrib != (const RenderAttrib *)NULL) {
- const TextureAttrib *ta;
- DCAST_INTO_V(ta, attrib);
- Texture *texture = ta->get_texture();
- if (texture != (Texture *)NULL) {
- texture->prepare(prepared_objects);
- }
- }
- }
- }
- int num_children = node->get_num_children();
- for (int i = 0; i < num_children; i++) {
- PandaNode *child = node->get_child(i);
- CPT(RenderState) child_state = state->compose(child->get_state());
- r_prepare_scene(child, child_state, prepared_objects);
- }
- }
|