123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "platform/platform.h"
- #include "ts/tsShapeConstruct.h"
- #include "ts/tsShapeInstance.h"
- #include "ts/tsMaterialList.h"
- #include "console/consoleTypes.h"
- #include "console/engineAPI.h"
- #include "core/resourceManager.h"
- #include "core/stream/bitStream.h"
- #include "core/stream/fileStream.h"
- #include "core/stream/memStream.h"
- #include "core/fileObject.h"
- #define MAX_PATH_LENGTH 256
- //#define DEBUG_SPEW
- ConsoleDocClass(TSShapeConstructor,
- "@brief An object used to modify a DTS or COLLADA shape model after it has "
- "been loaded by Torque\n\n"
- "@ingroup gameObjects\n"
- );
- IMPLEMENT_CALLBACK(TSShapeConstructor, onLoad, void, (), (),
- "Called immediately after the DTS or DAE file has been loaded; before the "
- "shape data is available to any other object (StaticShape, Player etc). This "
- "is where you should put any post-load commands to modify the shape in-memory "
- "such as addNode, renameSequence etc.")
- IMPLEMENT_CALLBACK(TSShapeConstructor, onUnload, void, (), (),
- "Called when the DTS or DAE resource is flushed from memory. Not normally "
- "required, but may be useful to perform cleanup.")
- ImplementEnumType(TSShapeConstructorUpAxis,
- "Axis to use for upwards direction when importing from Collada.\n\n"
- "@ingroup TSShapeConstructor")
- {
- UPAXISTYPE_X_UP, "X_AXIS"
- },
- { UPAXISTYPE_Y_UP, "Y_AXIS" },
- { UPAXISTYPE_Z_UP, "Z_AXIS" },
- { UPAXISTYPE_COUNT, "DEFAULT" }
- EndImplementEnumType;
- ImplementEnumType(TSShapeConstructorLodType,
- "\n\n"
- "@ingroup TSShapeConstructor")
- {
- ColladaUtils::ImportOptions::DetectDTS, "DetectDTS"
- },
- { ColladaUtils::ImportOptions::SingleSize, "SingleSize" },
- { ColladaUtils::ImportOptions::TrailingNumber, "TrailingNumber" },
- EndImplementEnumType;
- ImplementEnumType(TSShapeConstructorAnimType,
- "\n\n"
- "@ingroup TSShapeConstructor")
- {
- ColladaUtils::ImportOptions::FrameCount, "Frames"
- },
- { ColladaUtils::ImportOptions::Seconds, "Seconds" },
- { ColladaUtils::ImportOptions::Milliseconds, "Milliseconds" },
- EndImplementEnumType;
- //-----------------------------------------------------------------------------
- String TSShapeConstructor::smCapsuleShapePath("tools/shapes/unit_capsule.dts");
- String TSShapeConstructor::smCubeShapePath("tools/shapes/unit_cube.dts");
- String TSShapeConstructor::smSphereShapePath("tools/shapes/unit_sphere.dts");
- ResourceRegisterPostLoadSignal< TSShape > TSShapeConstructor::_smAutoLoad(&TSShapeConstructor::_onTSShapeLoaded);
- ResourceRegisterUnloadSignal< TSShape > TSShapeConstructor::_smAutoUnload(&TSShapeConstructor::_onTSShapeUnloaded);
- void TSShapeConstructor::_onTSShapeLoaded(Resource< TSShape >& resource)
- {
- TSShapeConstructor* ctor = findShapeConstructorByFilename(resource.getPath().getFullPath());
- if (ctor)
- ctor->_onLoad(resource);
- if (ctor && ctor->mShape && ctor->mShape->needsReinit())
- {
- ctor->mShape->init();
- }
- }
- void TSShapeConstructor::_onTSShapeUnloaded(const Torque::Path& path, TSShape* shape)
- {
- TSShapeConstructor* ctor = findShapeConstructorByFilename(path.getFullPath());
- if (ctor && (ctor->getShape() == shape))
- ctor->_onUnload();
- }
- // TSShape names are case insensitive
- static inline bool namesEqual(const String& nameA, const String& nameB)
- {
- return nameA.equal(nameB, String::NoCase);
- }
- static void SplitSequencePathAndName(String& srcPath, String& srcName)
- {
- srcName = "";
- // Determine if there is a sequence name at the end of the source string, and
- // if so, split the filename from the sequence name
- S32 split = srcPath.find(' ', 0, String::Right);
- S32 split2 = srcPath.find('\t', 0, String::Right);
- if ((split == String::NPos) || (split2 > split))
- split = split2;
- if (split != String::NPos)
- {
- split2 = split + 1;
- while ((srcPath[split2] != '\0') && dIsspace(srcPath[split2]))
- split2++;
- // now 'split' is at the end of the path, and 'split2' is at the start of the sequence name
- srcName = srcPath.substr(split2);
- srcPath = srcPath.erase(split, srcPath.length() - split);
- }
- }
- //-----------------------------------------------------------------------------
- IMPLEMENT_CONOBJECT(TSShapeConstructor);
- TSShapeConstructor::TSShapeConstructor()
- : mLoadingShape(false)
- {
- mShapeAssetId = StringTable->EmptyString();
- mShapeAsset = StringTable->EmptyString();
- mOptions.upAxis = UPAXISTYPE_COUNT;
- mOptions.unit = -1.0f;
- mOptions.lodType = ColladaUtils::ImportOptions::TrailingNumber;
- mOptions.singleDetailSize = 2;
- mOptions.matNamePrefix = "";
- mOptions.alwaysImport = "";
- mOptions.neverImport = String(Con::getVariable("$TSShapeConstructor::neverImport"));
- mOptions.alwaysImportMesh = "";
- mOptions.neverImportMesh = String(Con::getVariable("$TSShapeConstructor::neverImportMesh"));
- mOptions.neverImportMat = String(Con::getVariable("$TSShapeConstructor::neverImportMat"));
- mOptions.ignoreNodeScale = false;
- mOptions.adjustCenter = false;
- mOptions.adjustFloor = false;
- mOptions.forceUpdateMaterials = false;
- mOptions.useDiffuseNames = false;
- mOptions.convertLeftHanded = false;
- mOptions.calcTangentSpace = false;
- mOptions.genUVCoords = false;
- mOptions.transformUVCoords = false;
- mOptions.flipUVCoords = true;
- mOptions.findInstances = false;
- mOptions.limitBoneWeights = false;
- mOptions.joinIdenticalVerts = true;
- mOptions.reverseWindingOrder = true;
- mOptions.invertNormals = false;
- mOptions.removeRedundantMats = true;
- mOptions.animTiming = ColladaUtils::ImportOptions::Seconds;
- mOptions.animFPS = 30;
- mOptions.formatScaleFactor = 1.0f;
- mShape = NULL;
- }
- TSShapeConstructor::~TSShapeConstructor()
- {
- }
- bool TSShapeConstructor::addSequenceFromField(void* obj, const char* index, const char* data)
- {
- TSShapeConstructor* pObj = static_cast<TSShapeConstructor*>(obj);
- if (data && data[0])
- pObj->mSequenceAssetIds.push_back(StringTable->insert(data));
- return false;
- }
- void TSShapeConstructor::initPersistFields()
- {
- addGroup("Media");
- addField("baseShapeAsset", TypeShapeAssetId, Offset(mShapeAssetId, TSShapeConstructor),
- "Specifies the path to the DTS or DAE file to be operated on by this object.\n"
- "Since the TSShapeConstructor script must be in the same folder as the DTS or "
- "DAE file, it is recommended to use a relative path so that the shape and "
- "script files can be copied to another location without having to modify the "
- "path.");
- endGroup("Media");
- addGroup("Collada");
- addField("upAxis", TYPEID< domUpAxisType >(), Offset(mOptions.upAxis, TSShapeConstructor),
- "Override the <up_axis> element in the COLLADA (.dae) file. No effect for DTS files.\n"
- "Set to one of the following values:\n"
- "<dl><dt>X_AXIS</dt><dd>Positive X points up. Model will be rotated into Torque's coordinate system (Z up).</dd>"
- "<dt>Y_AXIS</dt><dd>Positive Y points up. Model will be rotated into Torque's coordinate system (Z up).</dd>"
- "<dt>Z_AXIS</dt><dd>Positive Z points up. No rotation will be applied to the model.</dd>"
- "<dt>DEFAULT</dt><dd>The default value. Use the value in the .dae file (defaults to Z_AXIS if the <up_axis> element is not present).</dd></dl>");
- addField("unit", TypeF32, Offset(mOptions.unit, TSShapeConstructor),
- "Override the <unit> element in the COLLADA (.dae) file. No effect for DTS files.\n"
- "COLLADA (.dae) files usually contain a <unit> element that indicates the "
- "'real world' units that the model is described in. It means you can work "
- "in sensible and meaningful units in your modeling app.<br>\n"
- "For example, if you were modeling a small object like a cup, it might make "
- "sense to work in inches (1 MAX unit = 1 inch), but if you were modeling a "
- "building, it might make more sense to work in feet (1 MAX unit = 1 foot). "
- "If you export both models to COLLADA, T3D will automatically scale them "
- "appropriately. 1 T3D unit = 1 meter, so the cup would be scaled down by 0.0254, "
- "and the building scaled down by 0.3048, given them both the correct scale "
- "relative to each other.<br>\n"
- "Omit the field or set to -1 to use the value in the .dae file (1.0 if the "
- "<unit> element is not present)");
- addField("lodType", TYPEID< ColladaUtils::ImportOptions::eLodType >(), Offset(mOptions.lodType, TSShapeConstructor),
- "Control how the COLLADA (.dae) importer interprets LOD in the model. No effect for DTS files.\n"
- "Set to one of the following values:\n"
- "<dl><dt>DetectDTS</dt><dd>The default value. Instructs the importer to search for a 'baseXXX->startXXX' node hierarchy at the root level. If found, the importer acts as if ''TrailingNumber'' was set. Otherwise, all geometry is imported at a single detail size.</dd>"
- "<dt>SingleSize</dt><dd>All geometry is imported at a fixed detail size. Numbers at the end of geometry node's are ignored.</dd>"
- "<dt>TrailingNumber</dt><dd>Numbers at the end of geometry node's name are interpreted as the detail size (similar to DTS exporting). Geometry instances with the same base name but different trailing number are grouped into the same object.</dd>"
- "<dt>DEFAULT</dt><dd>The default value. Use the value in the .dae file (defaults to Z_AXIS if the <up_axis> element is not present).</dd></dl>");
- addField("singleDetailSize", TypeS32, Offset(mOptions.singleDetailSize, TSShapeConstructor),
- "Sets the detail size when lodType is set to SingleSize. No effect otherwise, and no effect for DTS files.\n"
- "@see lodType");
- addField("matNamePrefix", TypeRealString, Offset(mOptions.matNamePrefix, TSShapeConstructor),
- "Prefix to apply to all material map names in the COLLADA (.dae) file. No effect for DTS files.\n"
- "This field is useful to avoid material name clashes for exporters that generate generic material "
- "names like \"texture0\" or \"material1\".");
- addField("alwaysImport", TypeRealString, Offset(mOptions.alwaysImport, TSShapeConstructor),
- "TAB separated patterns of nodes to import even if in neverImport list. No effect for DTS files.\n"
- "Torque allows unwanted nodes in COLLADA (.dae) files to to be ignored "
- "during import. This field contains a TAB separated list of patterns to "
- "match node names. Any node that matches one of the patterns in the list "
- "will <b>always</b> be imported, even if it also matches the neverImport list\n"
- "@see neverImport\n\n"
- "@tsexample\n"
- "singleton TSShapeConstructor(MyShapeDae)\n"
- "{\n"
- " baseShape = \"./myShape.dae\";\n"
- " alwaysImport = \"mount*\" TAB \"eye\";\n"
- " neverImport = \"*-PIVOT\";\n"
- "}\n"
- "@endtsexample");
- addField("neverImport", TypeRealString, Offset(mOptions.neverImport, TSShapeConstructor),
- "TAB separated patterns of nodes to ignore on loading. No effect for DTS files.\n"
- "Torque allows unwanted nodes in COLLADA (.dae) files to to be ignored "
- "during import. This field contains a TAB separated list of patterns to "
- "match node names. Any node that matches one of the patterns in the list will "
- "not be imported (unless it matches the alwaysImport list.\n"
- "@see alwaysImport");
- addField("alwaysImportMesh", TypeRealString, Offset(mOptions.alwaysImportMesh, TSShapeConstructor),
- "TAB separated patterns of meshes to import even if in neverImportMesh list. No effect for DTS files.\n"
- "Torque allows unwanted meshes in COLLADA (.dae) files to to be ignored "
- "during import. This field contains a TAB separated list of patterns to "
- "match mesh names. Any mesh that matches one of the patterns in the list "
- "will <b>always</b> be imported, even if it also matches the neverImportMesh list\n"
- "@see neverImportMesh\n\n"
- "@tsexample\n"
- "singleton TSShapeConstructor(MyShapeDae)\n"
- "{\n"
- " baseShape = \"./myShape.dae\";\n"
- " alwaysImportMesh = \"body*\" TAB \"armor\" TAB \"bounds\";\n"
- " neverImportMesh = \"*-dummy\";\n"
- "}\n"
- "@endtsexample");
- addField("neverImportMesh", TypeRealString, Offset(mOptions.neverImportMesh, TSShapeConstructor),
- "TAB separated patterns of meshes to ignore on loading. No effect for DTS files.\n"
- "Torque allows unwanted meshes in COLLADA (.dae) files to to be ignored "
- "during import. This field contains a TAB separated list of patterns to "
- "match mesh names. Any mesh that matches one of the patterns in the list will "
- "not be imported (unless it matches the alwaysImportMesh list.\n"
- "@see alwaysImportMesh");
- addField("neverImportMat", TypeRealString, Offset(mOptions.neverImportMat, TSShapeConstructor),
- "TAB separated patterns of materials to ignore on loading. No effect for DTS files.\n"
- "Torque allows unwanted materials in COLLADA (.dae) files to to be ignored "
- "during import. This field contains a TAB separated list of patterns to "
- "match material names. Any material that matches one of the patterns in the list will "
- "not be imported");
- addField("ignoreNodeScale", TypeBool, Offset(mOptions.ignoreNodeScale, TSShapeConstructor),
- "Ignore <scale> elements inside COLLADA <node>s. No effect for DTS files.\n"
- "This field is a workaround for certain exporters that generate bad node "
- "scaling, and is not usually required.");
- addField("adjustCenter", TypeBool, Offset(mOptions.adjustCenter, TSShapeConstructor),
- "Translate COLLADA model on import so the origin is at the center. No effect for DTS files.");
- addField("adjustFloor", TypeBool, Offset(mOptions.adjustFloor, TSShapeConstructor),
- "Translate COLLADA model on import so origin is at the (Z axis) bottom of the model. No effect for DTS files.\n"
- "This can be used along with adjustCenter to have the origin at the "
- "center of the bottom of the model.\n"
- "@see adjustCenter");
- addField("forceUpdateMaterials", TypeBool, Offset(mOptions.forceUpdateMaterials, TSShapeConstructor),
- "Forces update of the materials." TORQUE_SCRIPT_EXTENSION " file in the same folder as the COLLADA "
- "(.dae) file, even if Materials already exist. No effect for DTS files.\n"
- "Normally only Materials that are not already defined are written to materials." TORQUE_SCRIPT_EXTENSION ".");
- // Fields added for assimp options
- addField("convertLeftHanded", TypeBool, Offset(mOptions.convertLeftHanded, TSShapeConstructor),
- "Convert to left handed coordinate system.");
- addField("calcTangentSpace", TypeBool, Offset(mOptions.calcTangentSpace, TSShapeConstructor),
- "Calculate tangents and bitangents, if possible.");
- addField("genUVCoords", TypeBool, Offset(mOptions.genUVCoords, TSShapeConstructor),
- "Convert spherical, cylindrical, box and planar mapping to proper UVs.");
- addField("transformUVCoords", TypeBool, Offset(mOptions.transformUVCoords, TSShapeConstructor),
- "Preprocess UV transformations (scaling, translation ...).");
- addField("flipUVCoords", TypeBool, Offset(mOptions.flipUVCoords, TSShapeConstructor),
- "This step flips all UV coordinates along the y-axis and adjusts material settings and bitangents accordingly.\n"
- "Assimp uses TL(0,0):BR(1,1). T3D uses TL(0,1):BR(1,0). This will be needed for most textured models.");
- addField("findInstances", TypeBool, Offset(mOptions.findInstances, TSShapeConstructor),
- "Search for instanced meshes and remove them by references to one master.");
- addField("limitBoneWeights", TypeBool, Offset(mOptions.limitBoneWeights, TSShapeConstructor),
- "Limit bone weights to 4 per vertex.");
- addField("joinIdenticalVerts", TypeBool, Offset(mOptions.joinIdenticalVerts, TSShapeConstructor),
- "Identifies and joins identical vertex data sets within all imported meshes.");
- addField("reverseWindingOrder", TypeBool, Offset(mOptions.reverseWindingOrder, TSShapeConstructor),
- "This step adjusts the output face winding order to be clockwise. The default assimp face winding order is counter clockwise.");
- addField("invertNormals", TypeBool, Offset(mOptions.invertNormals, TSShapeConstructor),
- "Reverse the normal vector direction for all normals.");
- addField("removeRedundantMats", TypeBool, Offset(mOptions.removeRedundantMats, TSShapeConstructor),
- "Removes redundant materials.");
- addField("animTiming", TYPEID< ColladaUtils::ImportOptions::eAnimTimingType >(), Offset(mOptions.animTiming, TSShapeConstructor),
- "How to import timing data as frames, seconds or milliseconds.");
- addField("animFPS", TypeS32, Offset(mOptions.animFPS, TSShapeConstructor),
- "FPS value to use if timing is set in frames and the animations does not have an fps set.");
- endGroup("Collada");
- addGroup("Sequences");
- addProtectedField("sequence", TypeStringFilename, 0, &addSequenceFromField, &emptyStringProtectedGetFn,
- "Legacy method of adding sequences to a DTS or DAE shape after loading.\n\n"
- "@tsexample\n"
- "singleton TSShapeConstructor(MyShapeDae)\n"
- "{\n"
- " baseShape = \"./myShape.dae\";\n"
- " sequence = \"../anims/root.dae root\";\n"
- " sequence = \"../anims/walk.dae walk\";\n"
- " sequence = \"../anims/jump.dsq jump\";\n"
- "}\n"
- "@endtsexample");
- endGroup("Sequences");
- Parent::initPersistFields();
- }
- void TSShapeConstructor::consoleInit()
- {
- Parent::consoleInit();
- Con::addVariable("$pref::TSShapeConstructor::CapsuleShapePath", TypeRealString, &TSShapeConstructor::smCapsuleShapePath,
- "The file path to the capsule shape used by tsMeshFit.\n\n"
- "@ingroup MeshFit\n");
- Con::addVariable("$pref::TSShapeConstructor::CubeShapePath", TypeRealString, &TSShapeConstructor::smCubeShapePath,
- "The file path to the cube shape used by tsMeshFit.\n\n"
- "@ingroup MeshFit\n");
- Con::addVariable("$pref::TSShapeConstructor::SphereShapePath", TypeRealString, &TSShapeConstructor::smSphereShapePath,
- "The file path to the sphere shape used by tsMeshFit.\n\n"
- "@ingroup MeshFit\n");
- }
- TSShapeConstructor* TSShapeConstructor::findShapeConstructorByAssetId(StringTableEntry shapeAssetId)
- {
- SimGroup* group;
- if (Sim::findObject("TSShapeConstructorGroup", group))
- {
- // Find the TSShapeConstructor object for the given shape file
- for (S32 i = 0; i < group->size(); i++)
- {
- TSShapeConstructor* tss = dynamic_cast<TSShapeConstructor*>(group->at(i));
- StringTableEntry targetAssetId = tss->getShapeAssetId();
- if(targetAssetId == shapeAssetId)
- return tss;
- }
- }
- return NULL;
- }
- TSShapeConstructor* TSShapeConstructor::findShapeConstructorByFilename(const FileName& path)
- {
- SimGroup* group;
- if (Sim::findObject("TSShapeConstructorGroup", group))
- {
- // Find the TSShapeConstructor object for the given shape file
- for (S32 i = 0; i < group->size(); i++)
- {
- TSShapeConstructor* tss = dynamic_cast<TSShapeConstructor*>(group->at(i));
- FileName shapePath = (FileName)(tss->getShapePath());
- char buf[1024];
- FileName fullShapePath = String(Platform::makeFullPathName(shapePath, buf, sizeof(buf)));
- if (shapePath.equal(path, String::NoCase) || fullShapePath.equal(path, String::NoCase))
- return tss;
- }
- }
- return NULL;
- }
- //-----------------------------------------------------------------------------
- bool TSShapeConstructor::onAdd()
- {
- if (!Parent::onAdd())
- return false;
- // Prevent multiple objects pointing at the same shape file
- TSShapeConstructor* tss = findShapeConstructorByAssetId(getShapeAssetId());
- if (tss)
- {
- Con::errorf("TSShapeConstructor::onAdd failed: %s is already referenced by "
- "another TSShapeConstructor object (%s - %d)", getShapeAssetId(),
- tss->getName(), tss->getId());
- return false;
- }
- // Add to the TSShapeConstructor group (for lookups)
- SimGroup* group;
- if (!Sim::findObject("TSShapeConstructorGroup", group))
- {
- group = new SimGroup();
- if (!group->registerObject("TSShapeConstructorGroup"))
- {
- SAFE_DELETE(group);
- Con::errorf("TSShapeConstructor::onAdd failed: Could not register "
- "TSShapeConstructorGroup");
- return false;
- }
- Sim::getRootGroup()->addObject(group);
- }
- group->addObject(this);
- // This is only here for backwards compatibility!
- //
- // If we have no sequences, it may be using the older sequence# syntax.
- // Check for dynamic fields of that pattern and add them into the sequence vector.
- /*if (mSequenceAssetIds.empty())
- {
- for ( U32 idx = 0; idx < MaxLegacySequences; idx++ )
- {
- String field = String::ToString( "sequence%d", idx );
- const char *data = getDataField( StringTable->insert(field.c_str()), NULL );
- // Break at first field not used
- if ( !data || !data[0] )
- break;
- // By pushing the field thru Con::setData for TypeStringFilename
- // we get the default filename expansion. If we didn't do this
- // then we would have unexpanded ~/ in the file paths.
- String expanded;
- Con::setData( TypeStringFilename, &expanded, 0, 1, &data );
- addSequenceFromField( this, NULL, expanded.c_str() );
- }
- }*/
- // If an instance of this shape has already been loaded, call onLoad now
- mShapeAsset = mShapeAssetId;
- if (mShapeAsset.notNull())
- {
- Resource<TSShape> shape = mShapeAsset->getShapeResource();
- if (shape)
- _onLoad(shape);
- }
- if (mShape && mShape->needsReinit())
- {
- mShape->init();
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- void TSShapeConstructor::_onLoad(TSShape* shape)
- {
- // Check if we should unload first
- if (mShape)
- _onUnload();
- #ifdef DEBUG_SPEW
- Con::printf("[TSShapeConstructor] attaching to shape '%s'", getShapePath());
- #endif
- mShape = shape;
- mChangeSet.clear();
- mLoadingShape = true;
- // Add sequences defined using field syntax
- for (S32 i = 0; i < mSequenceAssetIds.size(); i++)
- {
- if (mSequenceAssetIds[i] == StringTable->EmptyString())
- continue;
- AssetPtr<ShapeAnimationAsset> sequenceAsset = mSequenceAssetIds[i];
- if (sequenceAsset.isNull())
- continue;
- // Split the sequence path from the target sequence name
- String destName;
- String srcPath(sequenceAsset->getAnimationPath());
- SplitSequencePathAndName(srcPath, destName);
- addSequence(srcPath, destName);
- }
- // Call script function
- onLoad_callback();
- mLoadingShape = false;
- }
- //-----------------------------------------------------------------------------
- void TSShapeConstructor::_onUnload()
- {
- #ifdef DEBUG_SPEW
- Con::printf("[TSShapeConstructor] detaching from '%s'", getShapePath());
- #endif
- onUnload_callback();
- mShape = NULL;
- }
- //-----------------------------------------------------------------------------
- void TSShapeConstructor::setShapeAssetId(StringTableEntry assetId)
- {
- mShapeAssetId = assetId;
- mShapeAsset = mShapeAssetId;
- if (mShapeAsset.notNull())
- {
- Resource<TSShape> shape = mShapeAsset->getShapeResource();
- if (shape)
- _onLoad(shape);
- }
- if (mShape && mShape->needsReinit())
- {
- mShape->init();
- }
- }
- //-----------------------------------------------------------------------------
- // Storage
- bool TSShapeConstructor::writeField(StringTableEntry fieldname, const char* value)
- {
- // Ignore the sequence fields (these are written as 'addSequence' commands instead)
- if (dStrnicmp(fieldname, "sequence", 8) == 0)
- return false;
- else if (dStrnicmp(fieldname, "baseShape", 9) == 0)
- {
- // Small hack to only write the base filename (no path) since the
- // TSShapeConstructor script must be in the same folder as the model, and
- // then we can easily copy both around without having to change the field
- const char* filename = dStrrchr(value, '/');
- if (filename > value)
- {
- S32 len = dStrlen(filename);
- dMemmove((void*)(value + 1), filename, len);
- ((char*)value)[0] = '.';
- ((char*)value)[len + 1] = '\0';
- }
- return true;
- }
- return Parent::writeField(fieldname, value);
- }
- //-----------------------------------------------------------------------------
- // Console utility methods
- // These macros take care of doing node, sequence and object lookups, including
- // printing error messages to the console if the element cannot be found.
- // Check that the given index is valid (0 - max-1). If not, generate an
- // error and return.
- #define CHECK_INDEX_IN_RANGE(func, index, maxIndex, ret) \
- if ( ( index < 0 ) || ( index >= maxIndex ) ) \
- { \
- Con::errorf( "TSShapeConstructor::" #func ": index out of " \
- "range (0-%d)", maxIndex-1); \
- return ret; \
- }
- // Do a node lookup and allow the root node name ("")
- #define GET_NODE_INDEX_ALLOW_ROOT(func, var, name, ret) \
- S32 var##Index = -1; \
- if (name[0]) \
- { \
- var##Index = mShape->findNode(name); \
- if (var##Index < 0) \
- { \
- Con::errorf( "TSShapeConstructor::" #func ": Could not " \
- "find node '%s'", name); \
- return ret; \
- } \
- } \
- TSShape::Node* var = var##Index < 0 ? NULL : &(mShape->nodes[var##Index]); \
- TORQUE_UNUSED(var##Index); \
- TORQUE_UNUSED(var)
- // Do a node lookup, root node ("") is not allowed
- #define GET_NODE_INDEX_NO_ROOT(func, var, name, ret) \
- S32 var##Index = mShape->findNode(name); \
- if (var##Index < 0) \
- { \
- Con::errorf( "TSShapeConstructor::" #func ": Could not find " \
- "node '%s'", name); \
- return ret; \
- } \
- TSShape::Node* var = &(mShape->nodes[var##Index]); \
- TORQUE_UNUSED(var##Index); \
- TORQUE_UNUSED(var)
- // Do an object lookup
- #define GET_OBJECT(func, var, name, ret) \
- S32 var##Index = mShape->findObject(name); \
- if (var##Index < 0) \
- { \
- Con::errorf( "TSShapeConstructor::" #func ": Could not find " \
- "object '%s'", name); \
- return ret; \
- } \
- TSShape::Object* var = &(mShape->objects[var##Index]); \
- TORQUE_UNUSED(var##Index); \
- TORQUE_UNUSED(var)
- // Do a mesh lookup
- #define GET_MESH(func, var, name, ret) \
- TSMesh* var = mShape->findMesh(name); \
- if (!var) \
- { \
- Con::errorf( "TSShapeConstructor::" #func ": Could not find " \
- "mesh '%s'", name); \
- return ret; \
- }
- // Do a sequence lookup
- #define GET_SEQUENCE(func, var, name, ret) \
- S32 var##Index = mShape->findSequence(name); \
- if (var##Index < 0) \
- { \
- Con::errorf( "TSShapeConstructor::" #func ": Could not find " \
- "sequence named '%s'", name); \
- return ret; \
- } \
- TSShape::Sequence* var = &(mShape->sequences[var##Index]); \
- TORQUE_UNUSED(var##Index); \
- TORQUE_UNUSED(var);
- //-----------------------------------------------------------------------------
- // DUMP
- DefineTSShapeConstructorMethod(dumpShape, void, (const char* filename), (""),
- (filename), ,
- "Dump the shape hierarchy to the console or to a file. Useful for reviewing "
- "the result of a series of construction commands.\n"
- "@param filename Destination filename. If not specified, dump to console.\n\n"
- "@tsexample\n"
- "%this.dumpShape(); // dump to console\n"
- "%this.dumpShape( \"./dump.txt\" ); // dump to file\n"
- "@endtsexample\n")
- {
- TSShapeInstance* tsi = new TSShapeInstance(mShape, false);
- if (dStrEqual(filename, ""))
- {
- // Dump the constructed shape to a memory stream
- MemStream* dumpStream = new MemStream(8192);
- tsi->dump(*dumpStream);
- // Write stream to the console
- U32 end = dumpStream->getPosition();
- dumpStream->setPosition(0);
- while (dumpStream->getPosition() < end)
- {
- char line[1024];
- dumpStream->readLine((U8*)line, sizeof(line));
- Con::printf(line);
- }
- delete dumpStream;
- }
- else
- {
- // Dump constructed shape to file
- char filenameBuf[1024];
- Con::expandScriptFilename(filenameBuf, sizeof(filenameBuf), filename);
- FileStream* dumpStream = new FileStream;
- if (dumpStream->open(filenameBuf, Torque::FS::File::Write))
- {
- tsi->dump(*dumpStream);
- dumpStream->close();
- }
- else
- Con::errorf("dumpShape failed: Could not open file '%s' for writing", filenameBuf);
- delete dumpStream;
- }
- delete tsi;
- }}
- DefineTSShapeConstructorMethod(saveShape, void, (const char* filename), ,
- (filename), ,
- "Save the shape (with all current changes) to a new DTS file.\n"
- "@param filename Destination filename.\n\n"
- "@tsexample\n"
- "%this.saveShape( \"./myShape.dts\" );\n"
- "@endtsexample\n")
- {
- char filenameBuf[1024];
- Con::expandScriptFilename(filenameBuf, sizeof(filenameBuf), filename);
- FileStream* dtsStream = new FileStream;
- if (dtsStream->open(filenameBuf, Torque::FS::File::Write))
- {
- mShape->write(dtsStream);
- dtsStream->close();
- }
- else
- {
- Con::errorf("saveShape failed: Could not open '%s' for writing", filenameBuf);
- }
- delete dtsStream;
- }}
- DefineTSShapeConstructorMethod(writeChangeSet, void, (), ,
- (), ,
- "Write the current change set to a TSShapeConstructor script file. The "
- "name of the script file is the same as the model, but with ." TORQUE_SCRIPT_EXTENSION " extension. "
- "eg. myShape." TORQUE_SCRIPT_EXTENSION " for myShape.dts or myShape.dae.\n")
- {
- Torque::Path scriptPath(getShapePath());
- scriptPath.setExtension(TORQUE_SCRIPT_EXTENSION);
- // Read current file contents
- FileObject f;
- f.readMemory(scriptPath.getFullPath());
- // Write new file
- FileStream* stream;
- if ((stream = FileStream::createAndOpen(scriptPath.getFullPath(), Torque::FS::File::Write)) == NULL)
- {
- Con::errorf("Failed to write TSShapeConstructor change set to %s", scriptPath.getFullPath().c_str());
- return;
- }
- // Write existing file contents up to the start of the onLoad function
- String beginMessage(avar("function %s::onLoad(%%this)", getName()));
- String endMessage("}");
- while (!f.isEOF())
- {
- const char* buffer = (const char*)f.readLine();
- if (!String::compare(buffer, beginMessage))
- break;
- stream->writeText(buffer);
- stream->writeText("\r\n");
- }
- // Write the new contents
- if (f.isEOF())
- stream->writeText("\r\n");
- stream->writeText(beginMessage);
- stream->writeText("\r\n{\r\n");
- mChangeSet.write(mShape, *stream, scriptPath.getPath());
- stream->writeText(endMessage);
- stream->writeText("\r\n");
- // Now skip the contents of the function
- while (!f.isEOF())
- {
- const char* buffer = (const char*)f.readLine();
- if (!String::compare(buffer, endMessage))
- break;
- }
- // Write the remainder of the existing file contents
- while (!f.isEOF())
- {
- const char* buffer = (const char*)f.readLine();
- stream->writeText(buffer);
- stream->writeText("\r\n");
- }
- delete stream;
- }}
- DefineTSShapeConstructorMethod(notifyShapeChanged, void, (), ,
- (), ,
- "Notify game objects that this shape file has changed, allowing them to update "
- "internal data if needed.")
- {
- ResourceManager::get().getChangedSignal().trigger(getShapePath());
- }}
- //-----------------------------------------------------------------------------
- // NODES
- DefineTSShapeConstructorMethod(getNodeCount, S32, (), ,
- (), 0,
- "Get the total number of nodes in the shape.\n"
- "@return the number of nodes in the shape.\n\n"
- "@tsexample\n"
- "%count = %this.getNodeCount();\n"
- "@endtsexample\n")
- {
- return mShape->nodes.size();
- }}
- DefineTSShapeConstructorMethod(getNodeIndex, S32, (const char* name), ,
- (name), -1,
- "Get the index of the node.\n"
- "@param name name of the node to lookup.\n"
- "@return the index of the named node, or -1 if no such node exists.\n\n"
- "@tsexample\n"
- "// get the index of Bip01 Pelvis node in the shape\n"
- "%index = %this.getNodeIndex( \"Bip01 Pelvis\" );\n"
- "@endtsexample\n")
- {
- return mShape->findNode(name);
- }}
- DefineTSShapeConstructorMethod(getNodeName, const char*, (S32 index), ,
- (index), "",
- "Get the name of the indexed node.\n"
- "@param index index of the node to lookup (valid range is 0 - getNodeCount()-1).\n"
- "@return the name of the indexed node, or \"\" if no such node exists.\n\n"
- "@tsexample\n"
- "// print the names of all the nodes in the shape\n"
- "%count = %this.getNodeCount();\n"
- "for (%i = 0; %i < %count; %i++)\n"
- " echo(%i SPC %this.getNodeName(%i));\n"
- "@endtsexample\n")
- {
- CHECK_INDEX_IN_RANGE(getNodeName, index, mShape->nodes.size(), "");
- return mShape->getName(mShape->nodes[index].nameIndex);
- }}
- DefineTSShapeConstructorMethod(getNodeParentName, const char*, (const char* name), ,
- (name), "",
- "Get the name of the node's parent. If the node has no parent (ie. it is at "
- "the root level), return an empty string.\n"
- "@param name name of the node to query.\n"
- "@return the name of the node's parent, or \"\" if the node is at the root level\n\n"
- "@tsexample\n"
- "echo( \"Bip01 Pelvis parent = \" @ %this.getNodeParentName( \"Bip01 Pelvis \") );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_NO_ROOT(getNodeParentName, node, name, "");
- if (node->parentIndex < 0)
- return "";
- else
- return mShape->getName(mShape->nodes[node->parentIndex].nameIndex);
- }}
- DefineTSShapeConstructorMethod(setNodeParent, bool, (const char* name, const char* parentName), ,
- (name, parentName), false,
- "Set the parent of a node.\n"
- "@param name name of the node to modify\n"
- "@param parentName name of the parent node to set (use \"\" to move the node to the root level)\n"
- "@return true if successful, false if failed\n\n"
- "@tsexample\n"
- "%this.setNodeParent( \"Bip01 Pelvis\", \"start01\" );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_NO_ROOT(setNodeParent, node, name, false);
- GET_NODE_INDEX_ALLOW_ROOT(setNodeParent, parent, parentName, false);
- node->parentIndex = parentIndex;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(getNodeChildCount, S32, (const char* name), ,
- (name), 0,
- "Get the number of children of this node.\n"
- "@param name name of the node to query.\n"
- "@return the number of child nodes.\n\n"
- "@tsexample\n"
- "%count = %this.getNodeChildCount( \"Bip01 Pelvis\" );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_ALLOW_ROOT(getNodeChildCount, node, name, 0);
- Vector<S32> nodeChildren;
- mShape->getNodeChildren(nodeIndex, nodeChildren);
- return nodeChildren.size();
- }}
- DefineTSShapeConstructorMethod(getNodeChildName, const char*, (const char* name, S32 index), ,
- (name, index), "",
- "Get the name of the indexed child node.\n"
- "@param name name of the parent node to query.\n"
- "@param index index of the child node (valid range is 0 - getNodeChildName()-1).\n"
- "@return the name of the indexed child node.\n\n"
- "@tsexample\n"
- "function dumpNode( %shape, %name, %indent )\n"
- "{\n"
- " echo( %indent @ %name );\n"
- " %count = %shape.getNodeChildCount( %name );\n"
- " for ( %i = 0; %i < %count; %i++ )\n"
- " dumpNode( %shape, %shape.getNodeChildName( %name, %i ), %indent @ \" \" );\n"
- "}\n\n"
- "function dumpShape( %shape )\n"
- "{\n"
- " // recursively dump node hierarchy\n"
- " %count = %shape.getNodeCount();\n"
- " for ( %i = 0; %i < %count; %i++ )\n"
- " {\n"
- " // dump top level nodes\n"
- " %name = %shape.getNodeName( %i );\n"
- " if ( %shape.getNodeParentName( %name ) $= "" )\n"
- " dumpNode( %shape, %name, \"\" );\n"
- " }\n"
- "}\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_ALLOW_ROOT(getNodeChildName, node, name, "");
- Vector<S32> nodeChildren;
- mShape->getNodeChildren(nodeIndex, nodeChildren);
- CHECK_INDEX_IN_RANGE(getNodeChildName, index, nodeChildren.size(), "");
- return mShape->getName(mShape->nodes[nodeChildren[index]].nameIndex);
- }}
- DefineTSShapeConstructorMethod(getNodeObjectCount, S32, (const char* name), ,
- (name), 0,
- "Get the number of geometry objects attached to this node.\n"
- "@param name name of the node to query.\n"
- "@return the number of attached objects.\n\n"
- "@tsexample\n"
- "%count = %this.getNodeObjectCount( \"Bip01 Head\" );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_ALLOW_ROOT(getNodeObjectCount, node, name, 0);
- Vector<S32> nodeObjects;
- mShape->getNodeObjects(nodeIndex, nodeObjects);
- return nodeObjects.size();
- }}
- DefineTSShapeConstructorMethod(getNodeObjectName, const char*, (const char* name, S32 index), ,
- (name, index), "",
- "Get the name of the indexed object.\n"
- "@param name name of the node to query.\n"
- "@param index index of the object (valid range is 0 - getNodeObjectCount()-1).\n"
- "@return the name of the indexed object.\n\n"
- "@tsexample\n"
- "// print the names of all objects attached to the node\n"
- "%count = %this.getNodeObjectCount( \"Bip01 Head\" );\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( %this.getNodeObjectName( \"Bip01 Head\", %i ) );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_ALLOW_ROOT(getNodeObjectName, node, name, "");
- Vector<S32> nodeObjects;
- mShape->getNodeObjects(nodeIndex, nodeObjects);
- CHECK_INDEX_IN_RANGE(getNodeObjectName, index, nodeObjects.size(), "");
- return mShape->getName(mShape->objects[nodeObjects[index]].nameIndex);
- }}
- DefineTSShapeConstructorMethod(getNodeTransform, TransformF, (const char* name, bool isWorld), (false),
- (name, isWorld), TransformF::Identity,
- "Get the base (ie. not animated) transform of a node.\n"
- "@param name name of the node to query.\n"
- "@param isWorld true to get the global transform, false (or omitted) to get "
- "the local-to-parent transform.\n"
- "@return the node transform in the form \"pos.x pos.y pos.z rot.x rot.y rot.z rot.angle\".\n\n"
- "@tsexample\n"
- "%ret = %this.getNodeTransform( \"mount0\" );\n"
- "%this.setNodeTransform( \"mount4\", %ret );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_NO_ROOT(getNodeTransform, node, name, TransformF::Identity);
- // Get the node transform
- Point3F pos;
- AngAxisF aa;
- if (isWorld)
- {
- // World transform
- MatrixF mat;
- mShape->getNodeWorldTransform(nodeIndex, &mat);
- pos = mat.getPosition();
- aa.set(mat);
- }
- else
- {
- // Local transform
- pos = mShape->defaultTranslations[nodeIndex];
- const Quat16& q16 = mShape->defaultRotations[nodeIndex];
- aa.set(q16.getQuatF());
- }
- return TransformF(pos, aa);
- }}
- DefineTSShapeConstructorMethod(setNodeTransform, bool, (const char* name, TransformF txfm, bool isWorld), (false),
- (name, txfm, isWorld), false,
- "Set the base transform of a node. That is, the transform of the node when "
- "in the root (not-animated) pose.\n"
- "@param name name of the node to modify\n"
- "@param txfm transform string of the form: \"pos.x pos.y pos.z rot.x rot.y rot.z rot.angle\"\n"
- "@param isworld (optional) flag to set the local-to-parent or the global "
- "transform. If false, or not specified, the position and orientation are "
- "treated as relative to the node's parent.\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.setNodeTransform( \"mount0\", \"0 0 1 0 0 1 0\" );\n"
- "%this.setNodeTransform( \"mount0\", \"0 0 0 0 0 1 1.57\" );\n"
- "%this.setNodeTransform( \"mount0\", \"1 0 0 0 0 1 0\", true );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_NO_ROOT(setNodeTransform, node, name, false);
- Point3F pos(txfm.getPosition());
- QuatF rot(txfm.getOrientation());
- if (isWorld)
- {
- // World transform
- // Get the node's parent (if any)
- if (node->parentIndex != -1)
- {
- MatrixF mat;
- mShape->getNodeWorldTransform(node->parentIndex, &mat);
- // Pre-multiply by inverse of parent's world transform to get
- // local node transform
- mat.inverse();
- mat.mul(txfm.getMatrix());
- rot.set(mat);
- pos = mat.getPosition();
- }
- }
- if (!mShape->setNodeTransform(name, pos, rot))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(renameNode, bool, (const char* oldName, const char* newName), ,
- (oldName, newName), false,
- "Rename a node.\n"
- "@note Note that node names must be unique, so this command will fail if "
- "there is already a node with the desired name\n"
- "@param oldName current name of the node\n"
- "@param newName new name of the node\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.renameNode( \"Bip01 L Hand\", \"mount5\" );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_NO_ROOT(renameNode, node, oldName, false);
- if (!mShape->renameNode(oldName, newName))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(addNode, bool, (const char* name, const char* parentName, TransformF txfm, bool isWorld), (TransformF::Identity, false),
- (name, parentName, txfm, isWorld), false,
- "Add a new node.\n"
- "@param name name for the new node (must not already exist)\n"
- "@param parentName name of an existing node to be the parent of the new node. "
- "If empty (\"\"), the new node will be at the root level of the node hierarchy.\n"
- "@param txfm (optional) transform string of the form: \"pos.x pos.y pos.z rot.x rot.y rot.z rot.angle\"\n"
- "@param isworld (optional) flag to set the local-to-parent or the global "
- "transform. If false, or not specified, the position and orientation are "
- "treated as relative to the node's parent.\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.addNode( \"Nose\", \"Bip01 Head\", \"0 2 2 0 0 1 0\" );\n"
- "%this.addNode( \"myRoot\", \"\", \"0 0 4 0 0 1 1.57\" );\n"
- "%this.addNode( \"Nodes\", \"Bip01 Head\", \"0 2 0 0 0 1 0\", true );\n"
- "@endtsexample\n")
- {
- Point3F pos(txfm.getPosition());
- QuatF rot(txfm.getOrientation());
- if (isWorld)
- {
- // World transform
- // Get the node's parent (if any)
- S32 parentIndex = mShape->findNode(parentName);
- if (parentIndex != -1)
- {
- MatrixF mat;
- mShape->getNodeWorldTransform(parentIndex, &mat);
- // Pre-multiply by inverse of parent's world transform to get
- // local node transform
- mat.inverse();
- mat.mul(txfm.getMatrix());
- rot.set(mat);
- pos = mat.getPosition();
- }
- }
- if (!mShape->addNode(name, parentName, pos, rot))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(removeNode, bool, (const char* name), ,
- (name), false,
- "Remove a node from the shape.\n"
- "The named node is removed from the shape, including from any sequences that "
- "use the node. Child nodes and objects attached to the node are re-assigned "
- "to the node's parent.\n"
- "@param name name of the node to remove.\n"
- "@return true if successful, false otherwise.\n\n"
- "@tsexample\n"
- "%this.removeNode( \"Nose\" );\n"
- "@endtsexample\n")
- {
- GET_NODE_INDEX_NO_ROOT(removeNode, node, name, false);
- if (!mShape->removeNode(name))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- //-----------------------------------------------------------------------------
- // MATERIALS
- DefineTSShapeConstructorMethod(getTargetCount, S32, (), , (), 0,
- "Get the number of materials in the shape.\n"
- "@return the number of materials in the shape.\n\n"
- "@tsexample\n"
- "%count = %this.getTargetCount();\n"
- "@endtsexample\n")
- {
- return mShape->getTargetCount();
- }}
- DefineTSShapeConstructorMethod(getTargetName, const char*, (S32 index), ,
- (index), "",
- "Get the name of the indexed shape material.\n"
- "@param index index of the material to get (valid range is 0 - getTargetCount()-1).\n"
- "@return the name of the indexed material.\n\n"
- "@tsexample\n"
- "%count = %this.getTargetCount();\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( \"Target \" @ %i @ \": \" @ %this.getTargetName( %i ) );\n"
- "@endtsexample\n")
- {
- return mShape->getTargetName(index);
- }}
- //-----------------------------------------------------------------------------
- // OBJECTS
- DefineTSShapeConstructorMethod(getObjectCount, S32, (), , (), 0,
- "Get the total number of objects in the shape.\n"
- "@return the number of objects in the shape.\n\n"
- "@tsexample\n"
- "%count = %this.getObjectCount();\n"
- "@endtsexample\n")
- {
- return mShape->objects.size();
- }}
- DefineTSShapeConstructorMethod(getObjectName, const char*, (S32 index), ,
- (index), "",
- "Get the name of the indexed object.\n"
- "@param index index of the object to get (valid range is 0 - getObjectCount()-1).\n"
- "@return the name of the indexed object.\n\n"
- "@tsexample\n"
- "// print the names of all objects in the shape\n"
- "%count = %this.getObjectCount();\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( %i SPC %this.getObjectName( %i ) );\n"
- "@endtsexample\n")
- {
- CHECK_INDEX_IN_RANGE(getObjectName, index, mShape->objects.size(), "");
- return mShape->getName(mShape->objects[index].nameIndex);
- }}
- DefineTSShapeConstructorMethod(getObjectIndex, S32, (const char* name), ,
- (name), -1,
- "Get the index of the first object with the given name.\n"
- "@param name name of the object to get.\n"
- "@return the index of the named object.\n\n"
- "@tsexample\n"
- "%index = %this.getObjectIndex( \"Head\" );\n"
- "@endtsexample\n")
- {
- return mShape->findObject(name);
- }}
- DefineTSShapeConstructorMethod(getObjectNode, const char*, (const char* name), ,
- (name), "",
- "Get the name of the node this object is attached to.\n"
- "@param name name of the object to get.\n"
- "@return the name of the attached node, or an empty string if this "
- "object is not attached to a node (usually the case for skinned meshes).\n\n"
- "@tsexample\n"
- "echo( \"Hand is attached to \" @ %this.getObjectNode( \"Hand\" ) );\n"
- "@endtsexample\n")
- {
- GET_OBJECT(getObjectNode, obj, name, 0);
- if (obj->nodeIndex < 0)
- return "";
- else
- return mShape->getName(mShape->nodes[obj->nodeIndex].nameIndex);
- }}
- DefineTSShapeConstructorMethod(setObjectNode, bool, (const char* objName, const char* nodeName), ,
- (objName, nodeName), false,
- "Set the node an object is attached to.\n"
- "When the shape is rendered, the object geometry is rendered at the node's "
- "current transform.\n"
- "@param objName name of the object to modify\n"
- "@param nodeName name of the node to attach the object to\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.setObjectNode( \"Hand\", \"Bip01 LeftHand\" );\n"
- "@endtsexample\n")
- {
- if (!mShape->setObjectNode(objName, nodeName))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(renameObject, bool, (const char* oldName, const char* newName), ,
- (oldName, newName), false,
- "Rename an object.\n"
- "@note Note that object names must be unique, so this command will fail if "
- "there is already an object with the desired name\n"
- "@param oldName current name of the object\n"
- "@param newName new name of the object\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.renameObject( \"MyBox\", \"Box\" );\n"
- "@endtsexample\n")
- {
- if (!mShape->renameObject(oldName, newName))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(removeObject, bool, (const char* name), ,
- (name), false,
- "Remove an object (including all meshes for that object) from the shape.\n"
- "@param name name of the object to remove.\n"
- "@return true if successful, false otherwise.\n\n"
- "@tsexample\n"
- "// clear all objects in the shape\n"
- "%count = %this.getObjectCount();\n"
- "for ( %i = %count-1; %i >= 0; %i-- )\n"
- " %this.removeObject( %this.getObjectName(%i) );\n"
- "@endtsexample\n")
- {
- if (!mShape->removeObject(name))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- //-----------------------------------------------------------------------------
- // MESHES
- DefineTSShapeConstructorMethod(getMeshCount, S32, (const char* name), ,
- (name), 0,
- "Get the number of meshes (detail levels) for the specified object.\n"
- "@param name name of the object to query\n"
- "@return the number of meshes for this object.\n\n"
- "@tsexample\n"
- "%count = %this.getMeshCount( \"SimpleShape\" );\n"
- "@endtsexample\n")
- {
- GET_OBJECT(getMeshCount, obj, name, 0);
- Vector<S32> objectDetails;
- mShape->getObjectDetails(objIndex, objectDetails);
- return objectDetails.size();
- }}
- DefineTSShapeConstructorMethod(getMeshName, const char*, (const char* name, S32 index), ,
- (name, index), "",
- "Get the name of the indexed mesh (detail level) for the specified object.\n"
- "@param name name of the object to query\n"
- "@param index index of the mesh (valid range is 0 - getMeshCount()-1)\n"
- "@return the mesh name.\n\n"
- "@tsexample\n"
- "// print the names of all meshes in the shape\n"
- "%objCount = %this.getObjectCount();\n"
- "for ( %i = 0; %i < %objCount; %i++ )\n"
- "{\n"
- " %objName = %this.getObjectName( %i );\n"
- " %meshCount = %this.getMeshCount( %objName );\n"
- " for ( %j = 0; %j < %meshCount; %j++ )\n"
- " echo( %this.getMeshName( %objName, %j ) );\n"
- "}\n"
- "@endtsexample\n")
- {
- GET_OBJECT(getMeshName, obj, name, "");
- Vector<S32> objectDetails;
- mShape->getObjectDetails(objIndex, objectDetails);
- CHECK_INDEX_IN_RANGE(getMeshName, index, objectDetails.size(), "");
- static const U32 bufSize = 256;
- char* returnBuffer = Con::getReturnBuffer(bufSize);
- dSprintf(returnBuffer, bufSize, "%s %d", name, (S32)mShape->details[objectDetails[index]].size);
- return returnBuffer;
- }}
- DefineTSShapeConstructorMethod(getMeshSize, S32, (const char* name, S32 index), ,
- (name, index), -1,
- "Get the detail level size of the indexed mesh for the specified object.\n"
- "@param name name of the object to query\n"
- "@param index index of the mesh (valid range is 0 - getMeshCount()-1)\n"
- "@return the mesh detail level size.\n\n"
- "@tsexample\n"
- "// print sizes for all detail levels of this object\n"
- "%objName = \"trunk\";\n"
- "%count = %this.getMeshCount( %objName );\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( %this.getMeshSize( %objName, %i ) );\n"
- "@endtsexample\n")
- {
- GET_OBJECT(getMeshName, obj, name, -1);
- Vector<S32> objectDetails;
- mShape->getObjectDetails(objIndex, objectDetails);
- CHECK_INDEX_IN_RANGE(getMeshName, index, objectDetails.size(), -1);
- return (S32)mShape->details[objectDetails[index]].size;
- }}
- DefineTSShapeConstructorMethod(setMeshSize, bool, (const char* name, S32 size), ,
- (name, size), false,
- "Change the detail level size of the named mesh.\n"
- "@param name full name (object name + current size ) of the mesh to modify\n"
- "@param size new detail level size\n"
- "@return true if successful, false otherwise.\n\n"
- "@tsexample\n"
- "%this.setMeshSize( \"SimpleShape128\", 64 );\n"
- "@endtsexample\n")
- {
- if (!mShape->setMeshSize(name, size))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(getMeshType, const char*, (const char* name), ,
- (name), "",
- "Get the display type of the mesh.\n"
- "@param name name of the mesh to query\n"
- "@return the string returned is one of:"
- "<dl><dt>normal</dt><dd>a normal 3D mesh</dd>"
- "<dt>billboard</dt><dd>a mesh that always faces the camera</dd>"
- "<dt>billboardzaxis</dt><dd>a mesh that always faces the camera in the Z-axis</dd></dl>\n\n"
- "@tsexample\n"
- "echo( \"Mesh type is \" @ %this.getMeshType( \"SimpleShape128\" ) );\n"
- "@endtsexample\n")
- {
- GET_MESH(getMeshType, mesh, name, "normal");
- if (mesh->getFlags(TSMesh::BillboardZAxis))
- return "billboardzaxis";
- else if (mesh->getFlags(TSMesh::Billboard))
- return "billboard";
- else
- return "normal";
- }}
- DefineTSShapeConstructorMethod(setMeshType, bool, (const char* name, const char* type), ,
- (name, type), false,
- "Set the display type for the mesh.\n"
- "@param name full name (object name + detail size) of the mesh to modify\n"
- "@param type the new type for the mesh: \"normal\", \"billboard\" or \"billboardzaxis\"\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "// set the mesh to be a billboard\n"
- "%this.setMeshType( \"SimpleShape64\", \"billboard\" );\n"
- "@endtsexample\n")
- {
- GET_MESH(setMeshType, mesh, name, false);
- // Update the mesh flags
- mesh->clearFlags(TSMesh::Billboard | TSMesh::BillboardZAxis);
- if (dStrEqual(type, "billboard"))
- mesh->setFlags(TSMesh::Billboard);
- else if (dStrEqual(type, "billboardzaxis"))
- mesh->setFlags(TSMesh::Billboard | TSMesh::BillboardZAxis);
- else if (!dStrEqual(type, "normal"))
- {
- Con::printf("setMeshType: Unknown mesh type '%s'", type);
- return false;
- }
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(getMeshMaterial, const char*, (const char* name), ,
- (name), "",
- "Get the name of the material attached to a mesh. Note that only the first "
- "material used by the mesh is returned.\n"
- "@param name full name (object name + detail size) of the mesh to query\n"
- "@return name of the material attached to the mesh (suitable for use with the Material mapTo field)\n\n"
- "@tsexample\n"
- "echo( \"Mesh material is \" @ %this.sgetMeshMaterial( \"SimpleShape128\" ) );\n"
- "@endtsexample\n")
- {
- GET_MESH(getMeshMaterial, mesh, name, "");
- // Return the name of the first material attached to this mesh
- S32 matIndex = mesh->mPrimitives[0].matIndex & TSDrawPrimitive::MaterialMask;
- if ((matIndex >= 0) && (matIndex < mShape->materialList->size()))
- return mShape->materialList->getMaterialName(matIndex);
- else
- return "";
- }}
- DefineTSShapeConstructorMethod(setMeshMaterial, bool, (const char* meshName, const char* matName), ,
- (meshName, matName), false,
- "Set the name of the material attached to the mesh.\n"
- "@param meshName full name (object name + detail size) of the mesh to modify\n"
- "@param matName name of the material to attach. This could be the base name of "
- "the diffuse texture (eg. \"test_mat\" for \"test_mat.jpg\"), or the name of a "
- "Material object already defined in script.\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "// set the mesh material\n"
- "%this.setMeshMaterial( \"SimpleShape128\", \"test_mat\" );\n"
- "@endtsexample\n")
- {
- GET_MESH(setMeshMaterial, mesh, meshName, false);
- // Check if this material is already in the shape
- S32 matIndex;
- for (matIndex = 0; matIndex < mShape->materialList->size(); matIndex++)
- {
- if (dStrEqual(matName, mShape->materialList->getMaterialName(matIndex)))
- break;
- }
- if (matIndex == mShape->materialList->size())
- {
- // Add a new material to the shape
- U32 flags = TSMaterialList::S_Wrap | TSMaterialList::T_Wrap;
- mShape->materialList->push_back(matName, flags);
- }
- // Set this material for all primitives in the mesh
- for (S32 i = 0; i < mesh->mPrimitives.size(); i++)
- {
- U32 matType = mesh->mPrimitives[i].matIndex & (TSDrawPrimitive::TypeMask | TSDrawPrimitive::Indexed);
- mesh->mPrimitives[i].matIndex = (matType | matIndex);
- }
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(addMesh, bool, (const char* meshName, const char* srcShape, const char* srcMesh), ,
- (meshName, srcShape, srcMesh), false,
- "Add geometry from another DTS or DAE shape file into this shape.\n"
- "Any materials required by the source mesh are also copied into this shape.<br>\n"
- "@param meshName full name (object name + detail size) of the new mesh. If "
- "no detail size is present at the end of the name, a value of 2 is used.<br>"
- "An underscore before the number at the end of the name will be interpreted as "
- "a negative sign. eg. \"MyMesh_4\" will be interpreted as \"MyMesh-4\".\n"
- "@param srcShape name of a shape file (DTS or DAE) that contains the mesh\n"
- "@param srcMesh the full name (object name + detail size) of the mesh to "
- "copy from the DTS/DAE file into this shape</li>"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.addMesh( \"ColMesh-1\", \"./collision.dts\", \"ColMesh\", \"Col-1\" );\n"
- "%this.addMesh( \"SimpleShape10\", \"./testShape.dae\", \"MyMesh2\", "" );\n"
- "@endtsexample\n")
- {
- // Load the shape source file
- char filenameBuf[1024];
- Con::expandScriptFilename(filenameBuf, sizeof(filenameBuf), srcShape);
- Resource<TSShape> hSrcShape = ResourceManager::get().load(filenameBuf);
- if (!bool(hSrcShape))
- {
- Con::errorf("addMesh failed: Could not load source shape: '%s'", filenameBuf);
- return false;
- }
- TSShape* shape = const_cast<TSShape*>((const TSShape*)hSrcShape);
- if (!mShape->addMesh(shape, srcMesh, meshName))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(removeMesh, bool, (const char* name), ,
- (name), false,
- "Remove a mesh from the shape.\n"
- "If all geometry is removed from an object, the object is also removed.\n"
- "@param name full name (object name + detail size) of the mesh to remove\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.removeMesh( \"SimpleShape128\" );\n"
- "@endtsexample\n")
- {
- if (!mShape->removeMesh(name))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(getBounds, Box3F, (), ,
- (), Box3F::Invalid,
- "Get the bounding box for the shape.\n"
- "@return Bounding box \"minX minY minZ maxX maxY maxZ\"")
- {
- return mShape->mBounds;
- }}
- DefineTSShapeConstructorMethod(setBounds, bool, (Box3F bbox), ,
- (bbox), false,
- "Set the shape bounds to the given bounding box.\n"
- "@param Bounding box \"minX minY minZ maxX maxY maxZ\"\n"
- "@return true if successful, false otherwise\n")
- {
- // Set shape bounds
- TSShape* shape = mShape;
- shape->mBounds = bbox;
- shape->mBounds.getCenter(&shape->center);
- shape->mRadius = (shape->mBounds.maxExtents - shape->center).len();
- shape->tubeRadius = shape->mRadius;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- //-----------------------------------------------------------------------------
- // DETAILS
- DefineTSShapeConstructorMethod(getDetailLevelCount, S32, (), , (), 0,
- "Get the total number of detail levels in the shape.\n"
- "@return the number of detail levels in the shape\n")
- {
- return mShape->details.size();
- }}
- DefineTSShapeConstructorMethod(getDetailLevelName, const char*, (S32 index), ,
- (index), "",
- "Get the name of the indexed detail level.\n"
- "@param index detail level index (valid range is 0 - getDetailLevelCount()-1)\n"
- "@return the detail level name\n\n"
- "@tsexample\n"
- "// print the names of all detail levels in the shape\n"
- "%count = %this.getDetailLevelCount();\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( %i SPC %this.getDetailLevelName( %i ) );\n"
- "@endtsexample\n")
- {
- CHECK_INDEX_IN_RANGE(getDetailLevelName, index, mShape->details.size(), "");
- return mShape->getName(mShape->details[index].nameIndex);
- }}
- DefineTSShapeConstructorMethod(getDetailLevelSize, S32, (S32 index), ,
- (index), 0,
- "Get the size of the indexed detail level.\n"
- "@param index detail level index (valid range is 0 - getDetailLevelCount()-1)\n"
- "@return the detail level size\n\n"
- "@tsexample\n"
- "// print the sizes of all detail levels in the shape\n"
- "%count = %this.getDetailLevelCount();\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( \"Detail\" @ %i @ \" has size \" @ %this.getDetailLevelSize( %i ) );\n"
- "@endtsexample\n")
- {
- CHECK_INDEX_IN_RANGE(getDetailLevelSize, index, mShape->details.size(), 0);
- return (S32)mShape->details[index].size;
- }}
- DefineTSShapeConstructorMethod(getDetailLevelIndex, S32, (S32 size), ,
- (size), -1,
- "Get the index of the detail level with a given size.\n"
- "@param size size of the detail level to lookup\n"
- "@return index of the detail level with the desired size, or -1 if no such "
- "detail exists\n\n"
- "@tsexample\n"
- "if ( %this.getDetailLevelSize( 32 ) == -1 )\n"
- " echo( \"Error: This shape does not have a detail level at size 32\" );\n"
- "@endtsexample\n")
- {
- return mShape->findDetailBySize(size);
- }}
- DefineTSShapeConstructorMethod(renameDetailLevel, bool, (const char* oldName, const char* newName), ,
- (oldName, newName), false,
- "Rename a detail level.\n"
- "@note Note that detail level names must be unique, so this command will "
- "fail if there is already a detail level with the desired name\n"
- "@param oldName current name of the detail level\n"
- "@param newName new name of the detail level\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.renameDetailLevel( \"detail-1\", \"collision-1\" );\n"
- "@endtsexample\n")
- {
- if (!mShape->renameDetail(oldName, newName))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(removeDetailLevel, bool, (S32 index), ,
- (index), false,
- "Remove the detail level (including all meshes in the detail level)\n"
- "@param size size of the detail level to remove\n"
- "@return true if successful, false otherwise\n"
- "@tsexample\n"
- "%this.removeDetailLevel( 2 );\n"
- "@endtsexample\n")
- {
- if (!mShape->removeDetail(index))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(setDetailLevelSize, S32, (S32 index, S32 newSize), ,
- (index, newSize), index,
- "Change the size of a detail level."
- "@note Note that detail levels are always sorted in decreasing size order, "
- "so this command may cause detail level indices to change.\n"
- "@param index index of the detail level to modify\n"
- "@param newSize new size for the detail level\n"
- "@return new index for this detail level\n\n"
- "@tsexample\n"
- "%this.setDetailLevelSize( 2, 256 );\n"
- "@endtsexample\n")
- {
- S32 dl = mShape->setDetailSize(index, newSize);
- if (dl >= 0)
- ADD_TO_CHANGE_SET();
- return dl;
- }}
- DefineTSShapeConstructorMethod(getImposterDetailLevel, S32, (), , (), -1,
- "Get the index of the imposter (auto-billboard) detail level (if any).\n"
- "@return imposter detail level index, or -1 if the shape does not use "
- "imposters.\n\n")
- {
- for (S32 i = 0; i < mShape->details.size(); i++)
- {
- if (mShape->details[i].subShapeNum < 0)
- return i;
- }
- return -1;
- }}
- DefineTSShapeConstructorMethod(getImposterSettings, const char*, (S32 index), ,
- (index), "",
- "Get the settings used to generate imposters for the indexed detail level.\n"
- "@param index index of the detail level to query (does not need to be an "
- "imposter detail level\n"
- "@return string of the form: \"valid eqSteps pSteps dl dim poles angle\", where:"
- "<dl>"
- "<dt>valid</dt><dd>1 if this detail level generates imposters, 0 otherwise</dd>"
- "<dt>eqSteps</dt><dd>number of steps around the equator</dd>"
- "<dt>pSteps</dt><dd>number of steps between the poles</dd>"
- "<dt>dl</dt><dd>index of the detail level used to generate imposters</dd>"
- "<dt>dim</dt><dd>size (in pixels) of each imposter image</dd>"
- "<dt>poles</dt><dd>1 to include pole images, 0 otherwise</dd>"
- "<dt>angle</dt><dd>angle at which to display pole images</dd>"
- "</dl>\n\n"
- "@tsexample\n"
- "// print the imposter detail level settings\n"
- "%index = %this.getImposterDetailLevel();\n"
- "if ( %index != -1 )\n"
- " echo( \"Imposter settings: \" @ %this.getImposterSettings( %index ) );\n"
- "@endtsexample\n")
- {
- CHECK_INDEX_IN_RANGE(getImposterSettings, index, mShape->details.size(), "");
- // Return information about the detail level
- const TSShape::Detail& det = mShape->details[index];
- static const U32 bufSize = 512;
- char* returnBuffer = Con::getReturnBuffer(bufSize);
- dSprintf(returnBuffer, bufSize, "%d\t%d\t%d\t%d\t%d\t%d\t%g",
- (S32)(det.subShapeNum < 0), // isImposter
- det.bbEquatorSteps,
- det.bbPolarSteps,
- det.bbDetailLevel,
- det.bbDimension,
- det.bbIncludePoles,
- det.bbPolarAngle);
- return returnBuffer;
- }}
- DefineTSShapeConstructorMethod(addImposter, S32, (S32 size, S32 equatorSteps, S32 polarSteps, S32 dl, S32 dim, bool includePoles, F32 polarAngle), ,
- (size, equatorSteps, polarSteps, dl, dim, includePoles, polarAngle), -1,
- "Add (or edit) an imposter detail level to the shape.\n"
- "If the shape already contains an imposter detail level, this command will "
- "simply change the imposter settings\n"
- "@param size size of the imposter detail level\n"
- "@param equatorSteps defines the number of snapshots to take around the "
- "equator. Imagine the object being rotated around the vertical axis, then "
- "a snapshot taken at regularly spaced intervals.\n"
- "@param polarSteps defines the number of snapshots taken between the poles "
- "(top and bottom), at each equator step. eg. At each equator snapshot, "
- "snapshots are taken at regular intervals between the poles.\n"
- "@param dl the detail level to use when generating the snapshots. Note that "
- "this is an array index rather than a detail size. So if an object has detail "
- "sizes of: 200, 150, and 40, then setting @a dl to 1 will generate the snapshots "
- "using detail size 150.\n"
- "@param dim defines the size of the imposter images in pixels. The larger the "
- "number, the more detailed the billboard will be.\n"
- "@param includePoles flag indicating whether to include the \"pole\" snapshots. "
- "ie. the views from the top and bottom of the object.\n"
- "@param polar_angle if pole snapshots are active (@a includePoles is true), this "
- "parameter defines the camera angle (in degrees) within which to render the "
- "pole snapshot. eg. if polar_angle is set to 25 degrees, then the snapshot "
- "taken at the pole (looking directly down or up at the object) will be rendered "
- "when the camera is within 25 degrees of the pole.\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.addImposter( 2, 4, 0, 0, 64, false, 0 );\n"
- "%this.addImposter( 2, 4, 2, 0, 64, true, 10 ); // this command would edit the existing imposter detail level\n"
- "@endtsexample\n")
- {
- // Add the imposter detail level
- dl = mShape->addImposter(getShapePath(), size, equatorSteps, polarSteps, dl, dim, includePoles, polarAngle);
- if (dl != -1)
- ADD_TO_CHANGE_SET();
- return dl;
- }}
- DefineTSShapeConstructorMethod(removeImposter, bool, (), , (), false,
- "() Remove the imposter detail level (if any) from the shape.\n"
- "@return true if successful, false otherwise\n\n")
- {
- if (!mShape->removeImposter())
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- //-----------------------------------------------------------------------------
- // SEQUENCES
- DefineTSShapeConstructorMethod(getSequenceCount, S32, (), , (), 0,
- "Get the total number of sequences in the shape.\n"
- "@return the number of sequences in the shape\n\n")
- {
- return mShape->sequences.size();
- }}
- DefineTSShapeConstructorMethod(getSequenceIndex, S32, (const char* name), ,
- (name), -1,
- "Find the index of the sequence with the given name.\n"
- "@param name name of the sequence to lookup\n"
- "@return index of the sequence with matching name, or -1 if not found\n\n"
- "@tsexample\n"
- "// Check if a given sequence exists in the shape\n"
- "if ( %this.getSequenceIndex( \"walk\" ) == -1 )\n"
- " echo( \"Could not find 'walk' sequence\" );\n"
- "@endtsexample\n")
- {
- return mShape->findSequence(name);
- }}
- DefineTSShapeConstructorMethod(getSequenceName, const char*, (S32 index), ,
- (index), "",
- "Get the name of the indexed sequence.\n"
- "@param index index of the sequence to query (valid range is 0 - getSequenceCount()-1)\n"
- "@return the name of the sequence\n\n"
- "@tsexample\n"
- "// print the name of all sequences in the shape\n"
- "%count = %this.getSequenceCount();\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( %i SPC %this.getSequenceName( %i ) );\n"
- "@endtsexample\n")
- {
- CHECK_INDEX_IN_RANGE(getSequenceName, index, mShape->sequences.size(), "");
- return mShape->getName(mShape->sequences[index].nameIndex);
- }}
- DefineTSShapeConstructorMethod(getSequenceSource, const char*, (const char* name), ,
- (name), "",
- "Get information about where the sequence data came from.\n"
- "For example, whether it was loaded from an external DSQ file.\n"
- "@param name name of the sequence to query\n"
- "@return TAB delimited string of the form: \"from reserved start end total\", where:"
- "<dl>"
- "<dt>from</dt><dd>the source of the animation data, such as the path to "
- "a DSQ file, or the name of an existing sequence in the shape. This field "
- "will be empty for sequences already embedded in the DTS or DAE file.</dd>"
- "<dt>reserved</dt><dd>reserved value</dd>"
- "<dt>start</dt><dd>the first frame in the source sequence used to create this sequence</dd>"
- "<dt>end</dt><dd>the last frame in the source sequence used to create this sequence</dd>"
- "<dt>total</dt><dd>the total number of frames in the source sequence</dd>"
- "</dl>\n\n"
- "@tsexample\n"
- "// print the source for the walk animation\n"
- "echo( \"walk source:\" SPC getField( %this.getSequenceSource( \"walk\" ), 0 ) );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(getSequenceSource, seq, name, "");
- // Return information about the source data for this sequence
- static const U32 bufSize = 512;
- char* returnBuffer = Con::getReturnBuffer(bufSize);
- dSprintf(returnBuffer, bufSize, "%s\t%d\t%d\t%d",
- seq->sourceData.from.c_str(), seq->sourceData.start,
- seq->sourceData.end, seq->sourceData.total);
- return returnBuffer;
- }}
- DefineTSShapeConstructorMethod(getSequenceFrameCount, S32, (const char* name), ,
- (name), 0,
- "Get the number of keyframes in the sequence.\n"
- "@param name name of the sequence to query\n"
- "@return number of keyframes in the sequence\n\n"
- "@tsexample\n"
- "echo( \"Run has \" @ %this.getSequenceFrameCount( \"run\" ) @ \" keyframes\" );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(getSequenceFrameCount, seq, name, 0);
- return seq->numKeyframes;
- }}
- DefineTSShapeConstructorMethod(getSequencePriority, F32, (const char* name), ,
- (name), -1.0f,
- "Get the priority setting of the sequence.\n"
- "@param name name of the sequence to query\n"
- "@return priority value of the sequence\n\n")
- {
- GET_SEQUENCE(getSequencePriority, seq, name, 0.0f);
- return seq->priority;
- }}
- DefineTSShapeConstructorMethod(setSequencePriority, bool, (const char* name, F32 priority), ,
- (name, priority), false,
- "Set the sequence priority.\n"
- "@param name name of the sequence to modify\n"
- "@param priority new priority value\n"
- "@return true if successful, false otherwise\n\n")
- {
- GET_SEQUENCE(setSequencePriority, seq, name, false);
- seq->priority = priority;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(getSequenceGroundSpeed, const char*, (const char* name), ,
- (name), "",
- "Get the ground speed of the sequence.\n"
- "@note Note that only the first 2 ground frames of the sequence are "
- "examined; the speed is assumed to be constant throughout the sequence.\n"
- "@param name name of the sequence to query\n"
- "@return string of the form: \"trans.x trans.y trans.z rot.x rot.y rot.z\"\n\n"
- "@tsexample\n"
- "%speed = VectorLen( getWords( %this.getSequenceGroundSpeed( \"run\" ), 0, 2 ) );\n"
- " echo( \"Run moves at \" @ %speed @ \" units per frame\" );\n"
- "@endtsexample\n")
- {
- // Find the sequence and return the ground speed (assumed to be constant)
- GET_SEQUENCE(getSequenceGroundSpeed, seq, name, "");
- Point3F trans(0, 0, 0), rot(0, 0, 0);
- if (seq->numGroundFrames > 0)
- {
- const Point3F& p1 = mShape->groundTranslations[seq->firstGroundFrame];
- const Point3F& p2 = mShape->groundTranslations[seq->firstGroundFrame + 1];
- trans = p2 - p1;
- QuatF r1 = mShape->groundRotations[seq->firstGroundFrame].getQuatF();
- QuatF r2 = mShape->groundRotations[seq->firstGroundFrame + 1].getQuatF();
- r2 -= r1;
- MatrixF mat;
- r2.setMatrix(&mat);
- rot = mat.toEuler();
- }
- static const U32 bufSize = 256;
- char* returnBuffer = Con::getReturnBuffer(bufSize);
- dSprintf(returnBuffer, bufSize, "%g %g %g %g %g %g",
- trans.x, trans.y, trans.z, rot.x, rot.y, rot.z);
- return returnBuffer;
- }}
- DefineTSShapeConstructorMethod(setSequenceGroundSpeed, bool, (const char* name, Point3F transSpeed, Point3F rotSpeed), (Point3F::Zero),
- (name, transSpeed, rotSpeed), false,
- "Set the translation and rotation ground speed of the sequence.\n"
- "The ground speed of the sequence is set by generating ground transform "
- "keyframes. The ground translational and rotational speed is assumed to "
- "be constant for the duration of the sequence. Existing ground frames for "
- "the sequence (if any) will be replaced.\n"
- "@param name name of the sequence to modify\n"
- "@param transSpeed translational speed (trans.x trans.y trans.z) in "
- "Torque units per frame\n"
- "@param rotSpeed (optional) rotational speed (rot.x rot.y rot.z) in "
- "radians per frame. Default is \"0 0 0\"\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.setSequenceGroundSpeed( \"run\", \"5 0 0\" );\n"
- "%this.setSequenceGroundSpeed( \"spin\", \"0 0 0\", \"4 0 0\" );\n"
- "@endtsexample\n")
- {
- if (!mShape->setSequenceGroundSpeed(name, transSpeed, rotSpeed))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(getSequenceCyclic, bool, (const char* name), ,
- (name), false,
- "Check if this sequence is cyclic (looping).\n"
- "@param name name of the sequence to query\n"
- "@return true if this sequence is cyclic, false if not\n\n"
- "@tsexample\n"
- "if ( !%this.getSequenceCyclic( \"ambient\" ) )\n"
- " error( \"ambient sequence is not cyclic!\" );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(getSequenceCyclic, seq, name, false);
- return seq->isCyclic();
- }}
- DefineTSShapeConstructorMethod(setSequenceCyclic, bool, (const char* name, bool cyclic), ,
- (name, cyclic), false,
- "Mark a sequence as cyclic or non-cyclic.\n"
- "@param name name of the sequence to modify\n"
- "@param cyclic true to make the sequence cyclic, false for non-cyclic\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.setSequenceCyclic( \"ambient\", true );\n"
- "%this.setSequenceCyclic( \"shoot\", false );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(setSequenceCyclic, seq, name, false);
- // update cyclic flag
- if (cyclic != seq->isCyclic())
- {
- if (cyclic && !seq->isCyclic())
- seq->flags |= TSShape::Cyclic;
- else if (!cyclic && seq->isCyclic())
- seq->flags &= (~(TSShape::Cyclic));
- ADD_TO_CHANGE_SET();
- }
- return true;
- }}
- DefineTSShapeConstructorMethod(getSequenceBlend, const char*, (const char* name), ,
- (name), "",
- "Get information about blended sequences.\n"
- "@param name name of the sequence to query\n"
- "@return TAB delimited string of the form: \"isBlend blendSeq blendFrame\", where:"
- "<dl>"
- "<dt>blend_flag</dt><dd>a boolean flag indicating whether this sequence is a blend</dd>"
- "<dt>blend_seq_name</dt><dd>the name of the sequence that contains the reference "
- "frame (empty for blend sequences embedded in DTS files)</dd>"
- "<dt>blend_seq_frame</dt><dd>the blend reference frame (empty for blend sequences "
- "embedded in DTS files)</dd>"
- "</dl>\n"
- "@note Note that only sequences set to be blends using the setSequenceBlend "
- "command will contain the blendSeq and blendFrame information.\n\n"
- "@tsexample\n"
- "%blendData = %this.getSequenceBlend( \"look\" );\n"
- "if ( getField( %blendData, 0 ) )\n"
- " echo( \"look is a blend, reference: \" @ getField( %blendData, 1 ) );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(getSequenceBlend, seq, name, "0");
- // Return the blend information (flag reference_sequence reference_frame)
- static const U32 bufSize = 512;
- char* returnBuffer = Con::getReturnBuffer(bufSize);
- dSprintf(returnBuffer, bufSize, "%d\t%s\t%d", (int)seq->isBlend(),
- seq->sourceData.blendSeq.c_str(), seq->sourceData.blendFrame);
- return returnBuffer;
- }}
- DefineTSShapeConstructorMethod(setSequenceBlend, bool, (const char* name, bool blend, const char* blendSeq, S32 blendFrame), ,
- (name, blend, blendSeq, blendFrame), false,
- "Mark a sequence as a blend or non-blend.\n"
- "A blend sequence is one that will be added on top of any other playing "
- "sequences. This is done by storing the animated node transforms relative "
- "to a reference frame, rather than as absolute transforms.\n"
- "@param name name of the sequence to modify\n"
- "@param blend true to make the sequence a blend, false for a non-blend\n"
- "@param blendSeq the name of the sequence that contains the blend reference frame\n"
- "@param blendFrame the reference frame in the blendSeq sequence\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.setSequenceBlend( \"look\", true, \"root\", 0 );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(setSequenceBlend, seq, name, false);
- if (!mShape->setSequenceBlend(name, blend, blendSeq, blendFrame))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(renameSequence, bool, (const char* oldName, const char* newName), ,
- (oldName, newName), false,
- "Rename a sequence.\n"
- "@note Note that sequence names must be unique, so this command will fail "
- "if there is already a sequence with the desired name\n"
- "@param oldName current name of the sequence\n"
- "@param newName new name of the sequence\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.renameSequence( \"walking\", \"walk\" );\n"
- "@endtsexample\n")
- {
- GET_SEQUENCE(renameSequence, seq, oldName, false);
- if (!mShape->renameSequence(oldName, newName))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(addSequence, bool,
- (const char* source, const char* name, S32 start, S32 end, bool padRot, bool padTrans),
- (0, -1, true, false), (source, name, start, end, padRot, padTrans), false,
- "Add a new sequence to the shape.\n"
- "@param source the name of an existing sequence, or the name of a DTS or DAE "
- "shape or DSQ sequence file. When the shape file contains more than one "
- "sequence, the desired sequence can be specified by appending the name to the "
- "end of the shape file. eg. \"myShape.dts run\" would select the \"run\" "
- "sequence from the \"myShape.dts\" file.\n\n"
- "@param name name of the new sequence\n"
- "@param start (optional) first frame to copy. Defaults to 0, the first frame in the sequence.\n"
- "@param end (optional) last frame to copy. Defaults to -1, the last frame in the sequence.\n"
- "@param padRot (optional) copy root-pose rotation keys for non-animated nodes. This is useful if "
- "the source sequence data has a different root-pose to the target shape, such as if one character was "
- "in the T pose, and the other had arms at the side. Normally only nodes that are actually rotated by "
- "the source sequence have keyframes added, but setting this flag will also add keyframes for nodes "
- "that are not animated, but have a different root-pose rotation to the target shape root pose.\n"
- "@param padTrans (optional) copy root-pose translation keys for non-animated nodes. This is useful if "
- "the source sequence data has a different root-pose to the target shape, such as if one character was "
- "in the T pose, and the other had arms at the side. Normally only nodes that are actually moved by "
- "the source sequence have keyframes added, but setting this flag will also add keyframes for nodes "
- "that are not animated, but have a different root-pose position to the target shape root pose.\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.addSequence( \"./testShape.dts ambient\", \"ambient\" );\n"
- "%this.addSequence( \"./myPlayer.dae run\", \"run\" );\n"
- "%this.addSequence( \"./player_look.dsq\", \"look\", 0, -1 ); // start to end\n"
- "%this.addSequence( \"walk\", \"walk_shortA\", 0, 4 ); // start to frame 4\n"
- "%this.addSequence( \"walk\", \"walk_shortB\", 4, -1 ); // frame 4 to end\n"
- "@endtsexample\n")
- {
- String srcName;
- String srcPath(source);
- SplitSequencePathAndName(srcPath, srcName);
- if (AssetDatabase.isDeclaredAsset(srcPath))
- {
- StringTableEntry assetId = StringTable->insert(srcPath.c_str());
- StringTableEntry assetType = AssetDatabase.getAssetType(assetId);
- if (assetType == StringTable->insert("ShapeAsset"))
- {
- ShapeAsset* asset = AssetDatabase.acquireAsset<ShapeAsset>(assetId);
- srcPath = asset->getShapeFilePath();
- AssetDatabase.releaseAsset(assetId);
- }
- else if (assetType == StringTable->insert("ShapeAnimationAsset"))
- {
- ShapeAnimationAsset* asset = AssetDatabase.acquireAsset<ShapeAnimationAsset>(assetId);
- srcPath = asset->getAnimationPath();
- AssetDatabase.releaseAsset(assetId);
- }
- }
- if (!mShape->addSequence(srcPath, srcName, name, start, end, padRot, padTrans))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(removeSequence, bool, (const char* name), ,
- (name), false,
- "Remove the sequence from the shape.\n"
- "@param name name of the sequence to remove\n"
- "@return true if successful, false otherwise\n\n")
- {
- if (!mShape->removeSequence(name))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- //-----------------------------------------------------------------------------
- // TRIGGERS
- DefineTSShapeConstructorMethod(getTriggerCount, S32, (const char* name), ,
- (name), 0,
- "Get the number of triggers in the specified sequence.\n"
- "@param name name of the sequence to query\n"
- "@return number of triggers in the sequence\n\n")
- {
- GET_SEQUENCE(getTriggerCount, seq, name, 0);
- return seq->numTriggers;
- }}
- DefineTSShapeConstructorMethod(getTrigger, const char*, (const char* name, S32 index), ,
- (name, index), "",
- "Get information about the indexed trigger\n"
- "@param name name of the sequence to query\n"
- "@param index index of the trigger (valid range is 0 - getTriggerCount()-1)\n"
- "@return string of the form \"frame state\"\n\n"
- "@tsexample\n"
- "// print all triggers in the sequence\n"
- "%count = %this.getTriggerCount( \"back\" );\n"
- "for ( %i = 0; %i < %count; %i++ )\n"
- " echo( %i SPC %this.getTrigger( \"back\", %i ) );\n"
- "@endtsexample\n")
- {
- // Find the sequence and return the indexed trigger (frame and state)
- GET_SEQUENCE(getTrigger, seq, name, "");
- CHECK_INDEX_IN_RANGE(getTrigger, index, seq->numTriggers, "");
- const TSShape::Trigger& trig = mShape->triggers[seq->firstTrigger + index];
- S32 frame = trig.pos * seq->numKeyframes;
- S32 state = getBinLog2(trig.state & TSShape::Trigger::StateMask) + 1;
- if (!(trig.state & TSShape::Trigger::StateOn))
- state = -state;
- static const U32 bufSize = 32;
- char* returnBuffer = Con::getReturnBuffer(bufSize);
- dSprintf(returnBuffer, bufSize, "%d %d", frame, state);
- return returnBuffer;
- }}
- DefineTSShapeConstructorMethod(addTrigger, bool, (const char* name, S32 keyframe, S32 state), ,
- (name, keyframe, state), false,
- "Add a new trigger to the sequence.\n"
- "@param name name of the sequence to modify\n"
- "@param keyframe keyframe of the new trigger\n"
- "@param state of the new trigger\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.addTrigger( \"walk\", 3, 1 );\n"
- "%this.addTrigger( \"walk\", 5, -1 );\n"
- "@endtsexample\n")
- {
- if (!mShape->addTrigger(name, keyframe, state))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineTSShapeConstructorMethod(removeTrigger, bool, (const char* name, S32 keyframe, S32 state), ,
- (name, keyframe, state), false,
- "Remove a trigger from the sequence.\n"
- "@param name name of the sequence to modify\n"
- "@param keyframe keyframe of the trigger to remove\n"
- "@param state of the trigger to remove\n"
- "@return true if successful, false otherwise\n\n"
- "@tsexample\n"
- "%this.removeTrigger( \"walk\", 3, 1 );\n"
- "@endtsexample\n")
- {
- if (!mShape->removeTrigger(name, keyframe, state))
- return false;
- ADD_TO_CHANGE_SET();
- return true;
- }}
- DefineEngineFunction(findShapeConstructorByAssetId, S32, (const char* assetId),,
- "Attempts to find an existing TSShapeConstructor by looking up an AssetId\n"
- "@tsexample\n"
- "findConstructorByAssetId(\"MyModule:MyShape\");\n"
- "@endtsexample")
- {
- StringTableEntry assetIdSTE = StringTable->insert(assetId);
- TSShapeConstructor* tss = TSShapeConstructor::findShapeConstructorByAssetId(assetIdSTE);
- if (tss)
- return tss->getId();
- else
- return 0;
- }
- DefineEngineFunction(findShapeConstructorByFilename, S32, (const char* filename),,
- "Attempts to find an existing TSShapeConstructor by looking up a filename\n"
- "@tsexample\n"
- "findShapeConstructorByFilename(\"data/myShape.dae\");\n"
- "@endtsexample")
- {
- FileName flName = FileName(filename);
- TSShapeConstructor* tss = TSShapeConstructor::findShapeConstructorByFilename(flName);
- if (tss)
- return tss->getId();
- else
- return 0;
- }
- //-----------------------------------------------------------------------------
- // Change-Set manipulation
- TSShapeConstructor::ChangeSet::eCommandType TSShapeConstructor::ChangeSet::getCmdType(const char* name)
- {
- #define RETURN_IF_MATCH(type) if (!dStricmp(name, #type)) return Cmd##type
- RETURN_IF_MATCH(AddNode);
- else RETURN_IF_MATCH(RemoveNode);
- else RETURN_IF_MATCH(RenameNode);
- else RETURN_IF_MATCH(SetNodeTransform);
- else RETURN_IF_MATCH(SetNodeParent);
- else RETURN_IF_MATCH(AddMesh);
- else RETURN_IF_MATCH(AddPrimitive);
- else RETURN_IF_MATCH(SetMeshSize);
- else RETURN_IF_MATCH(SetMeshType);
- else RETURN_IF_MATCH(SetMeshMaterial);
- else RETURN_IF_MATCH(RemoveMesh);
- else RETURN_IF_MATCH(SetObjectNode);
- else RETURN_IF_MATCH(RenameObject);
- else RETURN_IF_MATCH(RemoveObject);
- else RETURN_IF_MATCH(SetBounds);
- else RETURN_IF_MATCH(SetDetailLevelSize);
- else RETURN_IF_MATCH(RenameDetailLevel);
- else RETURN_IF_MATCH(RemoveDetailLevel);
- else RETURN_IF_MATCH(AddImposter);
- else RETURN_IF_MATCH(RemoveImposter);
- else RETURN_IF_MATCH(AddCollisionDetail);
- else RETURN_IF_MATCH(AddSequence);
- else RETURN_IF_MATCH(RemoveSequence);
- else RETURN_IF_MATCH(RenameSequence);
- else RETURN_IF_MATCH(SetSequenceCyclic);
- else RETURN_IF_MATCH(SetSequenceBlend);
- else RETURN_IF_MATCH(SetSequencePriority);
- else RETURN_IF_MATCH(SetSequenceGroundSpeed);
- else RETURN_IF_MATCH(AddTrigger);
- else RETURN_IF_MATCH(RemoveTrigger);
- else return CmdInvalid;
- #undef RETURN_IF_MATCH
- }
- void TSShapeConstructor::ChangeSet::write(TSShape* shape, Stream& stream, const String& savePath)
- {
- // First make a copy of the change-set
- ChangeSet output;
- for (S32 i = 0; i < mCommands.size(); i++)
- output.add(mCommands[i]);
- // Remove all __backup__ sequences (used during Shape Editing)
- if (shape)
- {
- for (S32 i = 0; i < shape->sequences.size(); i++)
- {
- const char* seqName = shape->getName(shape->sequences[i].nameIndex);
- if (dStrStartsWith(seqName, "__backup__"))
- {
- Command cmd("removeSequence");
- cmd.addArgs(seqName);
- output.add(cmd);
- }
- }
- }
- // Write the final change set to the stream
- for (U32 i = 0; i < output.mCommands.size(); i++)
- {
- const Command& cmd = output.mCommands[i];
- // Write the command
- stream.writeTabs(1);
- stream.writeText("%this.");
- stream.writeText(cmd.name);
- stream.writeText("(");
- if (cmd.argc > 0)
- {
- // Use relative paths when possible
- String str(cmd.argv[0]);
- if (str.startsWith(savePath))
- {
- // Need to add "./" to a local file for the script file system. Otherwise
- // it will be assumed to be a full and complete path when it comes to loading.
- str = "./" + str.substr(savePath.length() + 1);
- }
- stream.writeText("\"");
- stream.write(str.length(), str.c_str());
- stream.writeText("\"");
- // Write remaining arguments and newline
- for (U32 j = 1; j < cmd.argc; j++)
- {
- // Use relative paths when possible
- String relStr(cmd.argv[j]);
- if (relStr.startsWith(savePath))
- relStr = relStr.substr(savePath.length() + 1);
- stream.writeText(", \"");
- stream.write(relStr.length(), relStr.c_str());
- stream.writeText("\"");
- }
- }
- stream.writeText(");\r\n");
- }
- }
- void TSShapeConstructor::ChangeSet::add( TSShapeConstructor::ChangeSet::Command& cmd )
- {
- // Lookup the command type
- cmd.type = getCmdType(cmd.name); if (cmd.type == CmdInvalid)
- return;
- // Ignore operations on __proxy__ sequences (they are only used by the shape editor)
- if (cmd.argv[0].startsWith("__proxy__") || ((cmd.type == CmdAddSequence) && cmd.argv[1].startsWith("__proxy__")))
- return;
- // Add the command to the change set (apply command specific collapsing)
- bool addCommand = true;
- switch (cmd.type)
- {
- // Node commands
- case CmdSetNodeParent: addCommand = addCmd_setNodeParent(cmd); break;
- case CmdSetNodeTransform: addCommand = addCmd_setNodeTransform(cmd); break;
- case CmdRenameNode: addCommand = addCmd_renameNode(cmd); break;
- case CmdRemoveNode: addCommand = addCmd_removeNode(cmd); break;
- // Mesh commands
- case CmdSetMeshSize: addCommand = addCmd_setMeshSize(cmd); break;
- case CmdSetMeshType: addCommand = addCmd_setMeshType(cmd); break;
- case CmdSetMeshMaterial: addCommand = addCmd_setMeshMaterial(cmd); break;
- case CmdRemoveMesh: addCommand = addCmd_removeMesh(cmd); break;
- // Object commands
- case CmdSetObjectNode: addCommand = addCmd_setObjectNode(cmd); break;
- case CmdRenameObject: addCommand = addCmd_renameObject(cmd); break;
- case CmdRemoveObject: addCommand = addCmd_removeObject(cmd); break;
- case CmdSetBounds: addCommand = addCmd_setBounds(cmd); break;
- // Detail level commands
- case CmdRenameDetailLevel: addCommand = addCmd_renameDetailLevel(cmd); break;
- case CmdRemoveDetailLevel: addCommand = addCmd_removeDetailLevel(cmd); break;
- case CmdSetDetailLevelSize: addCommand = addCmd_setDetailSize(cmd); break;
- case CmdAddImposter: addCommand = addCmd_addImposter(cmd); break;
- case CmdRemoveImposter: addCommand = addCmd_removeImposter(cmd); break;
- // Sequence commands
- case CmdAddSequence: addCommand = addCmd_addSequence(cmd); break;
- case CmdSetSequencePriority: addCommand = addCmd_setSequencePriority(cmd); break;
- case CmdSetSequenceGroundSpeed: addCommand = addCmd_setSequenceGroundSpeed(cmd); break;
- case CmdSetSequenceCyclic: addCommand = addCmd_setSequenceCyclic(cmd); break;
- case CmdSetSequenceBlend: addCommand = addCmd_setSequenceBlend(cmd); break;
- case CmdRenameSequence: addCommand = addCmd_renameSequence(cmd); break;
- case CmdRemoveSequence: addCommand = addCmd_removeSequence(cmd); break;
- case CmdAddTrigger: addCommand = addCmd_addTrigger(cmd); break;
- case CmdRemoveTrigger: addCommand = addCmd_removeTrigger(cmd); break;
- // Other commands that do not have optimizations
- default:
- break;
- }
- if (addCommand)
- mCommands.push_back(cmd);
- }
- //-----------------------------------------------------------------------------
- // NODE COMMANDS
- bool TSShapeConstructor::ChangeSet::addCmd_setNodeParent(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // No dependencies, replace the parent argument for any previous addNode or
- // setNodeParent.
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddNode:
- case CmdSetNodeParent:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Replace parent argument
- return false;
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setNodeTransform(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // No dependencies, replace the parent argument for any previous addNode or
- // setNodeParent.
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddNode:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argc = newCmd.argc + 1; // Replace transform argument
- cmd.argv[2] = newCmd.argv[1];
- cmd.argv[3] = newCmd.argv[2];
- return false;
- }
- break;
- case CmdSetNodeTransform:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd = newCmd; // Collapse successive set transform commands
- return false;
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_renameNode(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace name argument for previous addNode or renameNode, but stop
- // if the new name is already in use (can occur if 2 nodes switch names). eg.
- // A->C
- // B->A
- // C->B (cannot replace the previous A->C with A->B as 'B' is in use)
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddNode:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[0] = newCmd.argv[1]; // Replace initial name argument
- return false;
- }
- break;
- case CmdRenameNode:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive renames
- if (namesEqual(cmd.argv[0], cmd.argv[1]))
- mCommands.erase(index); // Ignore empty renames
- return false;
- }
- else if (namesEqual(cmd.argv[0], newCmd.argv[1]))
- return true; // Name is in use, cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeNode(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // No dependencies. Remove any previous command that references the node
- String nodeName(newCmd.argv[0]);
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddNode:
- if (namesEqual(cmd.argv[0], nodeName))
- {
- mCommands.erase(index); // Remove the added node
- return false;
- }
- break;
- case CmdSetNodeTransform:
- case CmdSetNodeParent:
- if (namesEqual(cmd.argv[0], nodeName))
- mCommands.erase(index); // Remove any commands that reference the removed node
- break;
- case CmdRenameNode:
- if (namesEqual(cmd.argv[1], nodeName))
- {
- nodeName = cmd.argv[0]; // Node is renamed
- mCommands.erase(index);
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // SEQUENCE COMMANDS
- bool TSShapeConstructor::ChangeSet::addCmd_addSequence(TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // For sequences added from ShapeEditor __backup sequences, search backwards for
- // any changes made to the source of the __backup sequence. If none are found,
- // use the __backup source instead of the __backup.
- const char* backupPrefix = "__backup__";
- if (!newCmd.argv[0].startsWith(backupPrefix))
- return true;
- S32 start = dStrlen(backupPrefix);
- S32 end = newCmd.argv[0].find('_', 0, String::Right);
- String sourceName = newCmd.argv[0].substr(start, end - start);
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetSequencePriority:
- case CmdSetSequenceCyclic:
- case CmdSetSequenceBlend:
- case CmdSetSequenceGroundSpeed:
- // __backup sequence source has been modified => cannot go back further
- if (namesEqual(cmd.argv[0], sourceName))
- return true;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- {
- // No changes to the __backup sequence were found
- newCmd.argv[0] = sourceName;
- return true;
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setSequencePriority(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace any previous setSequencePriority command, but stop if the
- // sequence is used as a source for addSequence (since the priority is
- // copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetSequencePriority:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive set priority commands
- return false;
- }
- break;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Sequence is used as source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setSequenceGroundSpeed(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace any previous setSequenceGroundSpeed command, but stop if the
- // sequence is used as a source for addSequence (since the priority is
- // copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetSequenceGroundSpeed:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive set ground speed commands
- return false;
- }
- break;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Sequence is used as source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setSequenceCyclic(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace any previous setSequenceCyclic command, but stop if the
- // sequence is used as a source for addSequence (since the priority is
- // copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetSequenceCyclic:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]) &&
- dAtob(cmd.argv[1]) != dAtob(newCmd.argv[1]))
- {
- mCommands.erase(index); // ignore both setCyclic commands (1 undoes the other)
- return false;
- }
- break;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Sequence is used as source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setSequenceBlend(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace any previous setSequenceBlend command, but stop if the
- // sequence is used as a source for addSequence (since the priority is
- // copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetSequenceBlend:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]) &&
- dAtob(cmd.argv[1]) != dAtob(newCmd.argv[1]) &&
- namesEqual(cmd.argv[2], newCmd.argv[2]) &&
- dAtoi(cmd.argv[3]) == dAtoi(newCmd.argv[3]))
- {
- mCommands.erase(index); // Ignore both setBlend commands (1 undoes the other)
- return false;
- }
- break;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Sequence is used as source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_renameSequence(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace name argument for previous addSequence or renameSequence, but stop
- // if the new name is already in use (can occur if 2 nodes switch names). eg.
- // A->C
- // B->A
- // C->B (cannot replace the previous A->C with A->B as 'B' is in use)
- //
- // Once a previous command is found, go forward through the command list and
- // update any references to the old name
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdRenameSequence:
- if (namesEqual(cmd.argv[0], newCmd.argv[1]) && !namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Name is in use => cannot go back further
- // fall through to common processing
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- {
- if (cmd.type == CmdRenameSequence)
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive renames
- if (namesEqual(cmd.argv[0], cmd.argv[1]))
- mCommands.erase(index); // Ignore empty renames
- }
- else if (cmd.type == CmdAddSequence)
- {
- cmd.argv[1] = newCmd.argv[1]; // Replace initial name argument
- }
- // Update any references to the old name
- for (S32 j = index + 1; j < mCommands.size(); j++)
- {
- Command& cmd2 = mCommands[j];
- switch (cmd2.type)
- {
- case CmdSetSequencePriority:
- case CmdSetSequenceCyclic:
- case CmdSetSequenceBlend:
- case CmdSetSequenceGroundSpeed:
- if (namesEqual(cmd2.argv[0], newCmd.argv[0]))
- cmd2.argv[0] = newCmd.argv[1];
- break;
- }
- }
- return false;
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeSequence(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove any previous command that references the sequence, but stop if the
- // sequence is used as a source for addSequence
- String seqName(newCmd.argv[0]);
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], seqName))
- {
- mCommands.erase(index); // Remove the added sequence
- return false;
- }
- else if (namesEqual(cmd.argv[0], seqName))
- {
- // Removed sequence is used as source for another sequence => can't
- // go back any further
- return true;
- }
- break;
- case CmdRenameSequence:
- if (namesEqual(cmd.argv[1], seqName))
- {
- seqName = cmd.argv[0]; // Sequence is renamed
- mCommands.erase(index);
- }
- break;
- case CmdSetSequencePriority:
- case CmdSetSequenceGroundSpeed:
- case CmdSetSequenceCyclic:
- case CmdSetSequenceBlend:
- case CmdAddTrigger:
- case CmdRemoveTrigger:
- if (namesEqual(cmd.argv[0], seqName))
- mCommands.erase(index); // Remove any commands that reference the removed sequence
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_addTrigger(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove a matching removeTrigger command, but stop if the sequence is used as
- // a source for addSequence (since triggers are copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdRemoveTrigger:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]) &&
- cmd.argv[1] == newCmd.argv[1] &&
- cmd.argv[2] == newCmd.argv[2])
- {
- mCommands.erase(index); // Remove previous removeTrigger command
- return false;
- }
- break;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Sequence is used as a source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeTrigger(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove a matching addTrigger command, but stop if the sequence is used as
- // a source for addSequence (since triggers are copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddTrigger:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]) &&
- cmd.argv[1] == newCmd.argv[1] &&
- cmd.argv[2] == newCmd.argv[2])
- {
- mCommands.erase(index); // Remove previous addTrigger command
- return false;
- }
- break;
- case CmdAddSequence:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- return true; // Sequence is used as a source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // MESH COMMANDS
- bool TSShapeConstructor::ChangeSet::addCmd_setMeshSize(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace size argument for previous addMesh or setMeshSize, but stop if the
- // new name is already in use (can occur if 2 nodes switch names). eg.
- // A->C
- // B->A
- // C->B (cannot replace the previous A->C with A->B as 'B' is in use)
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddMesh:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[0] = newCmd.argv[1]; // Replace initial size argument
- return false;
- }
- break;
- case CmdSetMeshSize:
- if (cmd.argv[1] == newCmd.argv[0])
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive size sets
- if (cmd.argv[0] == cmd.argv[1])
- mCommands.erase(index); // Ignore empty resizes
- return false;
- }
- else if (cmd.argv[0] == newCmd.argv[1])
- return true; // Size is in use, cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setMeshType(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace any previous setMeshType command, but stop if the mesh is used as
- // a source for addMesh (since the type is copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetMeshType:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive set type commands
- return false;
- }
- break;
- case CmdAddMesh:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- return true; // Mesh is used as source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setMeshMaterial(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace any previous setMeshMaterial command, but stop if the mesh is used as
- // a source for addMesh (since the materials are copied).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetMeshMaterial:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive set material commands
- return false;
- }
- break;
- case CmdAddMesh:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- return true; // Mesh is used as source => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeMesh(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove any previous command that references the mesh, but stop if the mesh
- // is used as a source for addMesh
- String meshName(newCmd.argv[0]);
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddMesh:
- if (namesEqual(cmd.argv[0], meshName))
- {
- mCommands.erase(index); // Remove the added mesh
- return false;
- }
- else if (namesEqual(cmd.argv[2], meshName))
- {
- // Removed mesh is used as source for another mesh => can't go back
- // any further
- return true;
- }
- break;
- case CmdAddPrimitive:
- if (namesEqual(cmd.argv[0], meshName))
- {
- mCommands.erase(index); // Remove the added primitive
- return false;
- }
- break;
- case CmdSetMeshSize:
- case CmdSetMeshType:
- case CmdSetMeshMaterial:
- if (namesEqual(cmd.argv[0], meshName))
- mCommands.erase(index); // Remove any commands that reference the removed mesh
- break;
- default:
- break;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // OBJECT COMMANDS
- bool TSShapeConstructor::ChangeSet::addCmd_setObjectNode(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // No dependencies, replace the node argument for any previous parent argument for any previous addNode or
- // setNodeParent.
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddMesh:
- {
- S32 dummy;
- if (namesEqual(String::GetTrailingNumber(cmd.argv[0], dummy), newCmd.argv[0]))
- {
- cmd.argv[3] = newCmd.argv[1]; // Replace node argument
- return false;
- }
- break;
- }
- case CmdSetObjectNode:
- if (namesEqual(cmd.argv[0], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1];
- return false;
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_renameObject(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace name argument for previous renameObject, but stop if the new name
- // is already in use (can occur if 2 objects switch names). eg.
- // A->C
- // B->A
- // C->B (cannot replace the previous A->C with A->B as 'B' is in use)
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdRenameObject:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive renames
- if (namesEqual(cmd.argv[0], cmd.argv[1]))
- mCommands.erase(index); // Ignore empty renames
- return false;
- }
- else if (namesEqual(cmd.argv[0], newCmd.argv[1]))
- return true; // Name is in use, cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeObject(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove any previous command that references the object, but stop if any
- // object mesh is used as a source for addMesh
- S32 dummy;
- String objName(newCmd.argv[0]);
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddMesh:
- if (namesEqual(String::GetTrailingNumber(cmd.argv[0], dummy), objName))
- {
- mCommands.erase(index); // Remove the added mesh
- // Must still add the removeObject command as there could be multiple
- // meshes in the object
- }
- else if (namesEqual(String::GetTrailingNumber(cmd.argv[2], dummy), objName))
- {
- // Removed mesh is used as source for another mesh => can't go back
- // any further
- return true;
- }
- break;
- case CmdRenameObject:
- if (namesEqual(cmd.argv[1], objName))
- {
- objName = cmd.argv[0]; // Object is renamed
- mCommands.erase(index);
- }
- break;
- case CmdSetObjectNode:
- if (namesEqual(cmd.argv[0], objName))
- mCommands.erase(index); // Remove any commands that reference the removed object
- break;
- case CmdSetMeshSize:
- case CmdSetMeshType:
- case CmdSetMeshMaterial:
- case CmdRemoveMesh:
- if (namesEqual(String::GetTrailingNumber(cmd.argv[0], dummy), objName))
- mCommands.erase(index); // Remove comands that reference the removed object
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setBounds(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Only the last bounds update applies, so replace any previous command.
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdSetBounds:
- mCommands.erase(index);
- break;
- default:
- break;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // DETAIL COMMANDS
- bool TSShapeConstructor::ChangeSet::addCmd_renameDetailLevel(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Replace name argument for previous renameDetailLevel, but stop if the new
- // name is already in use (can occur if 2 objects switch names). eg.
- // A->C
- // B->A
- // C->B (cannot replace the previous A->C with A->B as 'B' is in use)
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdRenameDetailLevel:
- if (namesEqual(cmd.argv[1], newCmd.argv[0]))
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive renames
- if (namesEqual(cmd.argv[0], cmd.argv[1]))
- mCommands.erase(index); // Ignore empty renames
- return false;
- }
- else if (namesEqual(cmd.argv[0], newCmd.argv[1]))
- return true; // Name is in use, cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeDetailLevel(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove any previous command that references the detail, but stop if a mesh
- // is used as a source for addMesh
- S32 detSize = dAtoi(newCmd.argv[0]);
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- S32 size;
- switch (cmd.type)
- {
- case CmdAddMesh:
- String::GetTrailingNumber(cmd.argv[2], size);
- if (size == detSize)
- {
- // Removed detail is used as source for another mesh => can't go back
- // any further
- return true;
- }
- // fall through
- case CmdAddPrimitive:
- case CmdSetMeshSize:
- case CmdSetMeshType:
- case CmdSetMeshMaterial:
- case CmdRemoveMesh:
- String::GetTrailingNumber(cmd.argv[0], size);
- if (size == detSize)
- mCommands.erase(index);
- break;
- case CmdAddImposter:
- case CmdAddCollisionDetail:
- if (dAtoi(cmd.argv[0]) == detSize)
- {
- mCommands.erase(index);
- return false;
- }
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_setDetailSize(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Similar to renameXXX. Replace size argument for previous addImposter or
- // setDetailLevelSize, but stop if the new size is already in use (can occur
- // if 2 details switch sizes). eg.
- // A->C
- // B->A
- // C->B (cannot replace the previous A->C with A->B as 'B' is in use)
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddImposter:
- if (cmd.argv[0] == newCmd.argv[0])
- {
- cmd.argv[0] = newCmd.argv[1]; // Change detail size argument
- return false;
- }
- break;
- case CmdSetDetailLevelSize:
- if (cmd.argv[1] == newCmd.argv[0])
- {
- cmd.argv[1] = newCmd.argv[1]; // Collapse successive detail size changes
- if (cmd.argv[0] == cmd.argv[1])
- mCommands.erase(index); // Ignore empty changes
- return false;
- }
- else if (cmd.argv[0] == newCmd.argv[1])
- return true; // Detail size already in use => cannot go back further
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_addImposter(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove previous removeImposter, and replace any previous addImposter. If
- // replacing, also remove any setDetailLevelSize for the old imposter
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddImposter:
- // Replace the AddImposter command, but first remove any reference to
- // the added detail level.
- for (S32 j = index + 1; j < mCommands.size(); j++)
- {
- Command& cmd2 = mCommands[j];
- if ((cmd2.type == CmdSetDetailLevelSize) &&
- cmd2.argv[0] == cmd.argv[0])
- {
- mCommands.erase(j);
- break;
- }
- }
- // Replace previous addImposter command
- cmd = newCmd;
- return false;
- case CmdRemoveImposter:
- mCommands.erase(index); // Remove previous removeImposter command
- break;
- default:
- break;
- }
- }
- return true;
- }
- bool TSShapeConstructor::ChangeSet::addCmd_removeImposter(const TSShapeConstructor::ChangeSet::Command& newCmd)
- {
- // Remove any previous addImposter, and also remove any setDetailLevelSize
- // for that imposter.
- // Always need to return true, since we could be removing imposters already
- // present in the shape (not added with addImposter).
- for (S32 index = mCommands.size() - 1; index >= 0; index--)
- {
- Command& cmd = mCommands[index];
- switch (cmd.type)
- {
- case CmdAddImposter:
- // Remove the AddImposter command, but first remove any reference to
- // the added detail level.
- for (S32 j = index + 1; j < mCommands.size(); j++)
- {
- Command& cmd2 = mCommands[j];
- if ((cmd2.type == CmdSetDetailLevelSize) &&
- cmd2.argv[0] == cmd.argv[0])
- {
- mCommands.erase(j);
- break;
- }
- }
- mCommands.erase(index);
- break;
- default:
- break;
- }
- }
- return true;
- }
- void TSShapeConstructor::onActionPerformed()
- {
- // Reinit shape if we modify stuff in the shape editor, otherwise delay
- if (!mLoadingShape)
- {
- if (mShape && mShape->needsReinit())
- {
- mShape->init();
- }
- }
- }
|