tsStatic.cpp 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #include "platform/platform.h"
  27. #include "T3D/tsStatic.h"
  28. #include "core/resourceManager.h"
  29. #include "core/stream/bitStream.h"
  30. #include "scene/sceneRenderState.h"
  31. #include "scene/sceneManager.h"
  32. #include "scene/sceneObjectLightingPlugin.h"
  33. #include "lighting/lightManager.h"
  34. #include "math/mathIO.h"
  35. #include "ts/tsShapeInstance.h"
  36. #include "ts/tsMaterialList.h"
  37. #include "console/consoleTypes.h"
  38. #include "T3D/shapeBase.h"
  39. #include "sim/netConnection.h"
  40. #include "gfx/gfxDevice.h"
  41. #include "gfx/gfxTransformSaver.h"
  42. #include "ts/tsRenderState.h"
  43. #include "collision/boxConvex.h"
  44. #include "T3D/physics/physicsPlugin.h"
  45. #include "T3D/physics/physicsBody.h"
  46. #include "T3D/physics/physicsCollision.h"
  47. #include "materials/materialDefinition.h"
  48. #include "materials/materialManager.h"
  49. #include "materials/matInstance.h"
  50. #include "materials/materialFeatureData.h"
  51. #include "materials/materialFeatureTypes.h"
  52. #include "console/engineAPI.h"
  53. #include "T3D/accumulationVolume.h"
  54. #include "math/mTransform.h"
  55. #include "gui/editor/inspector/group.h"
  56. #include "console/typeValidators.h"
  57. using namespace Torque;
  58. extern bool gEditingMission;
  59. #ifdef TORQUE_AFX_ENABLED
  60. #include "afx/ce/afxZodiacMgr.h"
  61. #endif
  62. IMPLEMENT_CO_NETOBJECT_V1(TSStatic);
  63. ConsoleDocClass(TSStatic,
  64. "@brief A static object derived from a 3D model file and placed within the game world.\n\n"
  65. "TSStatic is the most basic 3D shape in Torque. Unlike StaticShape it doesn't make use of "
  66. "a datablock. It derrives directly from SceneObject. This makes TSStatic extremely light "
  67. "weight, which is why the Tools use this class when you want to drop in a DTS or DAE object.\n\n"
  68. "While a TSStatic doesn't provide any motion -- it stays were you initally put it -- it does allow for "
  69. "a single ambient animation sequence to play when the object is first added to the scene.\n\n"
  70. "@tsexample\n"
  71. "new TSStatic(Team1Base) {\n"
  72. " shapeName = \"art/shapes/desertStructures/station01.dts\";\n"
  73. " playAmbient = \"1\";\n"
  74. " receiveSunLight = \"1\";\n"
  75. " receiveLMLighting = \"1\";\n"
  76. " useCustomAmbientLighting = \"0\";\n"
  77. " customAmbientLighting = \"0 0 0 1\";\n"
  78. " collisionType = \"Visible Mesh\";\n"
  79. " decalType = \"Collision Mesh\";\n"
  80. " allowPlayerStep = \"1\";\n"
  81. " renderNormals = \"0\";\n"
  82. " forceDetail = \"-1\";\n"
  83. " position = \"315.18 -180.418 244.313\";\n"
  84. " rotation = \"0 0 1 195.952\";\n"
  85. " scale = \"1 1 1\";\n"
  86. " isRenderEnabled = \"true\";\n"
  87. " canSaveDynamicFields = \"1\";\n"
  88. "};\n"
  89. "@endtsexample\n"
  90. "@ingroup gameObjects\n"
  91. );
  92. bool TSStatic::smUseStaticObjectFade = false;
  93. F32 TSStatic::smStaticObjectFadeStart = 50;
  94. F32 TSStatic::smStaticObjectFadeEnd = 75;
  95. F32 TSStatic::smStaticObjectUnfadeableSize = 75;
  96. TSStatic::TSStatic()
  97. :
  98. cubeDescId(0),
  99. reflectorDesc(NULL)
  100. {
  101. mNetFlags.set(Ghostable | ScopeAlways);
  102. mTypeMask |= StaticObjectType | StaticShapeObjectType;
  103. mShapeInstance = NULL;
  104. mPlayAmbient = true;
  105. mAmbientThread = NULL;
  106. mAllowPlayerStep = false;
  107. mConvexList = new Convex;
  108. mRenderNormalScalar = 0;
  109. mForceDetail = -1;
  110. mMeshCulling = false;
  111. mUseOriginSort = false;
  112. mUseAlphaFade = false;
  113. mAlphaFadeStart = 100.0f;
  114. mAlphaFadeEnd = 150.0f;
  115. mInvertAlphaFade = false;
  116. mAlphaFade = 1.0f;
  117. mPhysicsRep = NULL;
  118. mCollisionType = CollisionMesh;
  119. mDecalType = CollisionMesh;
  120. mIgnoreZodiacs = false;
  121. mHasGradients = false;
  122. mInvertGradientRange = false;
  123. mGradientRangeUser.set(0.0f, 180.0f);
  124. #ifdef TORQUE_AFX_ENABLED
  125. afxZodiacData::convertGradientRangeFromDegrees(mGradientRange, mGradientRangeUser);
  126. #endif
  127. mAnimOffset = 0.0f;
  128. mAnimSpeed = 1.0f;
  129. INIT_ASSET(Shape);
  130. }
  131. TSStatic::~TSStatic()
  132. {
  133. delete mConvexList;
  134. mConvexList = NULL;
  135. }
  136. ImplementEnumType(TSMeshType,
  137. "Type of mesh data available in a shape.\n"
  138. "@ingroup gameObjects")
  139. {
  140. TSStatic::None, "None", "No mesh data."
  141. },
  142. { TSStatic::Bounds, "Bounds", "Bounding box of the shape." },
  143. { TSStatic::CollisionMesh, "Collision Mesh", "Specifically desingated \"collision\" meshes." },
  144. { TSStatic::VisibleMesh, "Visible Mesh", "Rendered mesh polygons." },
  145. EndImplementEnumType;
  146. FRangeValidator percentValidator(0.0f, 1.0f);
  147. F32 AnimSpeedMax = 4.0f;
  148. FRangeValidator speedValidator(0.0f, AnimSpeedMax);
  149. void TSStatic::initPersistFields()
  150. {
  151. addFieldV("AnimOffset", TypeF32, Offset(mAnimOffset, TSStatic), &percentValidator,
  152. "Percent Animation Offset.");
  153. addFieldV("AnimSpeed", TypeF32, Offset(mAnimSpeed, TSStatic), &speedValidator,
  154. "Percent Animation Speed.");
  155. addGroup("Shape");
  156. INITPERSISTFIELD_SHAPEASSET(Shape, TSStatic, "Model to use for this TSStatic");
  157. addProtectedField("shapeName", TypeShapeFilename, Offset(mShapeName, TSStatic),
  158. &TSStatic::_setShapeData, &defaultProtectedGetFn,
  159. "%Path and filename of the model file (.DTS, .DAE) to use for this TSStatic. Legacy field. Any loose files assigned here will attempt to be auto-imported in as an asset.", AbstractClassRep::FIELD_HideInInspectors);
  160. endGroup("Shape");
  161. addGroup("Materials");
  162. addProtectedField("skin", TypeRealString, Offset(mAppliedSkinName, TSStatic), &_setFieldSkin, &_getFieldSkin,
  163. "@brief The skin applied to the shape.\n\n"
  164. "'Skinning' the shape effectively renames the material targets, allowing "
  165. "different materials to be used on different instances of the same model.\n\n"
  166. "Any material targets that start with the old skin name have that part "
  167. "of the name replaced with the new skin name. The initial old skin name is "
  168. "\"base\". For example, if a new skin of \"blue\" was applied to a model "
  169. "that had material targets <i>base_body</i> and <i>face</i>, the new targets "
  170. "would be <i>blue_body</i> and <i>face</i>. Note that <i>face</i> was not "
  171. "renamed since it did not start with the old skin name of \"base\".\n\n"
  172. "To support models that do not use the default \"base\" naming convention, "
  173. "you can also specify the part of the name to replace in the skin field "
  174. "itself. For example, if a model had a material target called <i>shapemat</i>, "
  175. "we could apply a new skin \"shape=blue\", and the material target would be "
  176. "renamed to <i>bluemat</i> (note \"shape\" has been replaced with \"blue\").\n\n"
  177. "Multiple skin updates can also be applied at the same time by separating "
  178. "them with a semicolon. For example: \"base=blue;face=happy_face\".\n\n"
  179. "Material targets are only renamed if an existing Material maps to that "
  180. "name, or if there is a diffuse texture in the model folder with the same "
  181. "name as the new target.\n\n");
  182. endGroup("Materials");
  183. addGroup("Rendering");
  184. addField("playAmbient", TypeBool, Offset(mPlayAmbient, TSStatic),
  185. "Enables automatic playing of the animation sequence named \"ambient\" (if it exists) when the TSStatic is loaded.");
  186. addField("meshCulling", TypeBool, Offset(mMeshCulling, TSStatic),
  187. "Enables detailed culling of meshes within the TSStatic. Should only be used "
  188. "with large complex shapes like buildings which contain many submeshes.");
  189. addField("originSort", TypeBool, Offset(mUseOriginSort, TSStatic),
  190. "Enables translucent sorting of the TSStatic by its origin instead of the bounds.");
  191. endGroup("Rendering");
  192. addGroup("Reflection");
  193. addField("cubeReflectorDesc", TypeRealString, Offset(cubeDescName, TSStatic),
  194. "References a ReflectorDesc datablock that defines performance and quality properties for dynamic reflections.\n");
  195. endGroup("Reflection");
  196. addGroup("Collision");
  197. addField("collisionType", TypeTSMeshType, Offset(mCollisionType, TSStatic),
  198. "The type of mesh data to use for collision queries.");
  199. addField("decalType", TypeTSMeshType, Offset(mDecalType, TSStatic),
  200. "The type of mesh data used to clip decal polygons against.");
  201. addField("allowPlayerStep", TypeBool, Offset(mAllowPlayerStep, TSStatic),
  202. "@brief Allow a Player to walk up sloping polygons in the TSStatic (based on the collisionType).\n\n"
  203. "When set to false, the slightest bump will stop the player from walking on top of the object.\n");
  204. endGroup("Collision");
  205. addGroup("AlphaFade");
  206. addField("alphaFadeEnable", TypeBool, Offset(mUseAlphaFade, TSStatic), "Turn on/off Alpha Fade");
  207. addField("alphaFadeStart", TypeF32, Offset(mAlphaFadeStart, TSStatic), "Distance of start Alpha Fade");
  208. addField("alphaFadeEnd", TypeF32, Offset(mAlphaFadeEnd, TSStatic), "Distance of end Alpha Fade");
  209. addField("alphaFadeInverse", TypeBool, Offset(mInvertAlphaFade, TSStatic), "Invert Alpha Fade's Start & End Distance");
  210. endGroup("AlphaFade");
  211. addGroup("Debug");
  212. addField("renderNormals", TypeF32, Offset(mRenderNormalScalar, TSStatic),
  213. "Debug rendering mode shows the normals for each point in the TSStatic's mesh.");
  214. addField("forceDetail", TypeS32, Offset(mForceDetail, TSStatic),
  215. "Forces rendering to a particular detail level.");
  216. endGroup("Debug");
  217. addGroup("AFX");
  218. addField("ignoreZodiacs", TypeBool, Offset(mIgnoreZodiacs, TSStatic));
  219. addField("useGradientRange", TypeBool, Offset(mHasGradients, TSStatic));
  220. addField("gradientRange", TypePoint2F, Offset(mGradientRangeUser, TSStatic));
  221. addField("invertGradientRange", TypeBool, Offset(mInvertGradientRange, TSStatic));
  222. endGroup("AFX");
  223. Parent::initPersistFields();
  224. }
  225. void TSStatic::consoleInit()
  226. {
  227. Parent::consoleInit();
  228. // Vars for debug rendering while the RoadEditor is open, only used if smEditorOpen is true.
  229. Con::addVariable("$pref::useStaticObjectFade", TypeBool, &TSStatic::smUseStaticObjectFade, "Indicates if all statics should utilize the distance-based object fadeout logic.\n");
  230. Con::addVariable("$pref::staticObjectFadeStart", TypeF32, &TSStatic::smStaticObjectFadeStart, "Distance at which static object fading begins if $pref::useStaticObjectFade is on.\n");
  231. Con::addVariable("$pref::staticObjectFadeEnd", TypeF32, &TSStatic::smStaticObjectFadeEnd, "Distance at which static object fading should have fully faded if $pref::useStaticObjectFade is on.\n");
  232. Con::addVariable("$pref::staticObjectUnfadeableSize", TypeF32, &TSStatic::smStaticObjectUnfadeableSize, "Size of object where if the bounds is at or bigger than this, it will be ignored in the $pref::useStaticObjectFade logic. Useful for very large, distance-important objects.\n");
  233. }
  234. bool TSStatic::_setFieldSkin(void* object, const char* index, const char* data)
  235. {
  236. TSStatic* ts = static_cast<TSStatic*>(object);
  237. if (ts)
  238. ts->setSkinName(data);
  239. return false;
  240. }
  241. const char* TSStatic::_getFieldSkin(void* object, const char* data)
  242. {
  243. TSStatic* ts = static_cast<TSStatic*>(object);
  244. return ts ? ts->mSkinNameHandle.getString() : "";
  245. }
  246. void TSStatic::inspectPostApply()
  247. {
  248. // Apply any transformations set in the editor
  249. Parent::inspectPostApply();
  250. if (isServerObject())
  251. {
  252. setMaskBits(-1);
  253. prepCollision();
  254. }
  255. _updateShouldTick();
  256. }
  257. bool TSStatic::onAdd()
  258. {
  259. PROFILE_SCOPE(TSStatic_onAdd);
  260. if (isServerObject())
  261. {
  262. // Handle the old "usePolysoup" field
  263. SimFieldDictionary* fieldDict = getFieldDictionary();
  264. if (fieldDict)
  265. {
  266. StringTableEntry slotName = StringTable->insert("usePolysoup");
  267. SimFieldDictionary::Entry* entry = fieldDict->findDynamicField(slotName);
  268. if (entry)
  269. {
  270. // Was "usePolysoup" set?
  271. bool usePolysoup = dAtob(entry->value);
  272. // "usePolysoup" maps to the new VisibleMesh type
  273. if (usePolysoup)
  274. mCollisionType = VisibleMesh;
  275. // Remove the field in favor on the new "collisionType" field
  276. fieldDict->setFieldValue(slotName, "");
  277. }
  278. }
  279. }
  280. if (!Parent::onAdd())
  281. return false;
  282. // Setup the shape.
  283. if (!_createShape())
  284. {
  285. Con::errorf("TSStatic::onAdd() - Shape creation failed!");
  286. return false;
  287. }
  288. setRenderTransform(mObjToWorld);
  289. // Register for the resource change signal.
  290. //ResourceManager::get().getChangedSignal().notify(this, &TSStatic::_onResourceChanged);
  291. addToScene();
  292. if (isClientObject())
  293. {
  294. mCubeReflector.unregisterReflector();
  295. if (reflectorDesc)
  296. mCubeReflector.registerReflector(this, reflectorDesc);
  297. }
  298. _updateShouldTick();
  299. // Accumulation and environment mapping
  300. if (isClientObject() && mShapeInstance)
  301. {
  302. AccumulationVolume::addObject(this);
  303. }
  304. return true;
  305. }
  306. bool TSStatic::_createShape()
  307. {
  308. // Cleanup before we create.
  309. mCollisionDetails.clear();
  310. mDecalDetails.clear();
  311. mDecalDetailsPtr = 0;
  312. mLOSDetails.clear();
  313. SAFE_DELETE(mPhysicsRep);
  314. SAFE_DELETE(mShapeInstance);
  315. mAmbientThread = NULL;
  316. mShape = NULL;
  317. if(!mShapeAsset.isNull())
  318. {
  319. //Special-case handling, usually because we set noShape
  320. mShape = mShapeAsset->getShapeResource();
  321. }
  322. if (!mShape)
  323. {
  324. Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
  325. return false;
  326. }
  327. if (isClientObject() &&
  328. !mShape->preloadMaterialList(mShape.getPath()) &&
  329. NetConnection::filesWereDownloaded())
  330. return false;
  331. mObjBox = mShape->mBounds;
  332. resetWorldBox();
  333. mShapeInstance = new TSShapeInstance(mShape, isClientObject());
  334. if (isClientObject())
  335. mShapeInstance->cloneMaterialList();
  336. if (isGhost())
  337. {
  338. // Reapply the current skin
  339. mAppliedSkinName = "";
  340. reSkin();
  341. }
  342. prepCollision();
  343. // Find the "ambient" animation if it exists
  344. S32 ambientSeq = mShape->findSequence("ambient");
  345. if (ambientSeq > -1 && !mAmbientThread)
  346. mAmbientThread = mShapeInstance->addThread();
  347. if ( mAmbientThread )
  348. mShapeInstance->setSequence(mAmbientThread, ambientSeq, mAnimOffset);
  349. // Resolve CubeReflectorDesc.
  350. if (cubeDescName.isNotEmpty())
  351. {
  352. Sim::findObject(cubeDescName, reflectorDesc);
  353. }
  354. else if (cubeDescId > 0)
  355. {
  356. Sim::findObject(cubeDescId, reflectorDesc);
  357. }
  358. //Set up the material slot vars for easy manipulation
  359. /*S32 materialCount = mShape->materialList->getMaterialNameList().size(); //mMeshAsset->getMaterialCount();
  360. //Temporarily disabled until fixup of materialName->assetId lookup logic is sorted for easy persistance
  361. if (isServerObject())
  362. {
  363. char matFieldName[128];
  364. for (U32 i = 0; i < materialCount; i++)
  365. {
  366. StringTableEntry materialname = StringTable->insert(mShape->materialList->getMaterialName(i).c_str());
  367. dSprintf(matFieldName, 128, "MaterialSlot%d", i);
  368. StringTableEntry matFld = StringTable->insert(matFieldName);
  369. setDataField(matFld, NULL, materialname);
  370. }
  371. }*/
  372. return true;
  373. }
  374. void TSStatic::onDynamicModified(const char* slotName, const char* newValue)
  375. {
  376. if (FindMatch::isMatch("materialslot*", slotName, false))
  377. {
  378. if (!getShape())
  379. return;
  380. S32 slot = -1;
  381. String outStr(String::GetTrailingNumber(slotName, slot));
  382. if (slot == -1)
  383. return;
  384. //Safe to assume the inbound value for the material will be a MaterialAsset, so lets do a lookup on the name
  385. MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(newValue);
  386. if (!matAsset)
  387. return;
  388. bool found = false;
  389. for (U32 i = 0; i < mChangingMaterials.size(); i++)
  390. {
  391. if (mChangingMaterials[i].slot == slot)
  392. {
  393. mChangingMaterials[i].matAsset = matAsset;
  394. mChangingMaterials[i].assetId = newValue;
  395. found = true;
  396. }
  397. }
  398. if (!found)
  399. {
  400. matMap newMatMap;
  401. newMatMap.slot = slot;
  402. newMatMap.matAsset = matAsset;
  403. newMatMap.assetId = newValue;
  404. mChangingMaterials.push_back(newMatMap);
  405. }
  406. setMaskBits(MaterialMask);
  407. }
  408. Parent::onDynamicModified(slotName, newValue);
  409. }
  410. void TSStatic::prepCollision()
  411. {
  412. // Let the client know that the collision was updated
  413. setMaskBits(UpdateCollisionMask);
  414. // Allow the ShapeInstance to prep its collision if it hasn't already
  415. if (mShapeInstance)
  416. mShapeInstance->prepCollision();
  417. // Cleanup any old collision data
  418. mCollisionDetails.clear();
  419. mDecalDetails.clear();
  420. mDecalDetailsPtr = 0;
  421. mLOSDetails.clear();
  422. mConvexList->nukeList();
  423. if (mCollisionType == CollisionMesh || mCollisionType == VisibleMesh)
  424. {
  425. mShape->findColDetails(mCollisionType == VisibleMesh, &mCollisionDetails, &mLOSDetails);
  426. if (mDecalType == mCollisionType)
  427. {
  428. mDecalDetailsPtr = &mCollisionDetails;
  429. }
  430. else if (mDecalType == CollisionMesh || mDecalType == VisibleMesh)
  431. {
  432. mShape->findColDetails(mDecalType == VisibleMesh, &mDecalDetails, 0);
  433. mDecalDetailsPtr = &mDecalDetails;
  434. }
  435. }
  436. else if (mDecalType == CollisionMesh || mDecalType == VisibleMesh)
  437. {
  438. mShape->findColDetails(mDecalType == VisibleMesh, &mDecalDetails, 0);
  439. mDecalDetailsPtr = &mDecalDetails;
  440. }
  441. _updatePhysics();
  442. }
  443. void TSStatic::_updatePhysics()
  444. {
  445. SAFE_DELETE(mPhysicsRep);
  446. if (!PHYSICSMGR || mCollisionType == None)
  447. return;
  448. PhysicsCollision* colShape = NULL;
  449. if (mCollisionType == Bounds)
  450. {
  451. MatrixF offset(true);
  452. offset.setPosition(mShape->center);
  453. colShape = PHYSICSMGR->createCollision();
  454. colShape->addBox(getObjBox().getExtents() * 0.5f * mObjScale, offset);
  455. }
  456. else
  457. colShape = mShape->buildColShape(mCollisionType == VisibleMesh, getScale());
  458. if (colShape)
  459. {
  460. PhysicsWorld* world = PHYSICSMGR->getWorld(isServerObject() ? "server" : "client");
  461. mPhysicsRep = PHYSICSMGR->createBody();
  462. mPhysicsRep->init(colShape, 0, 0, this, world);
  463. mPhysicsRep->setTransform(getTransform());
  464. }
  465. }
  466. void TSStatic::onRemove()
  467. {
  468. SAFE_DELETE(mPhysicsRep);
  469. // Accumulation
  470. if (isClientObject() && mShapeInstance)
  471. {
  472. if (mShapeInstance->hasAccumulation())
  473. AccumulationVolume::removeObject(this);
  474. }
  475. mConvexList->nukeList();
  476. removeFromScene();
  477. // Remove the resource change signal.
  478. //ResourceManager::get().getChangedSignal().remove(this, &TSStatic::_onResourceChanged);
  479. delete mShapeInstance;
  480. mShapeInstance = NULL;
  481. mAmbientThread = NULL;
  482. if (isClientObject())
  483. mCubeReflector.unregisterReflector();
  484. Parent::onRemove();
  485. }
  486. void TSStatic::_onResourceChanged(const Torque::Path& path)
  487. {
  488. if (path != Path(mShapeName))
  489. return;
  490. _createShape();
  491. _updateShouldTick();
  492. }
  493. void TSStatic::onShapeChanged()
  494. {
  495. _createShape();
  496. _updateShouldTick();
  497. }
  498. void TSStatic::setSkinName(const char* name)
  499. {
  500. if (!isGhost())
  501. {
  502. if (name[0] != '\0')
  503. {
  504. // Use tags for better network performance
  505. // Should be a tag, but we'll convert to one if it isn't.
  506. if (name[0] == StringTagPrefixByte)
  507. mSkinNameHandle = NetStringHandle(U32(dAtoi(name + 1)));
  508. else
  509. mSkinNameHandle = NetStringHandle(name);
  510. }
  511. else
  512. mSkinNameHandle = NetStringHandle();
  513. setMaskBits(SkinMask);
  514. }
  515. }
  516. void TSStatic::reSkin()
  517. {
  518. if (isGhost() && mShapeInstance)
  519. {
  520. if (mSkinNameHandle.isValidString())
  521. {
  522. mShapeInstance->resetMaterialList();
  523. Vector<String> skins;
  524. String(mSkinNameHandle.getString()).split(";", skins);
  525. for (S32 i = 0; i < skins.size(); i++)
  526. {
  527. String oldSkin(mAppliedSkinName.c_str());
  528. String newSkin(skins[i]);
  529. // Check if the skin handle contains an explicit "old" base string. This
  530. // allows all models to support skinning, even if they don't follow the
  531. // "base_xxx" material naming convention.
  532. S32 split = newSkin.find('='); // "old=new" format skin?
  533. if (split != String::NPos)
  534. {
  535. oldSkin = newSkin.substr(0, split);
  536. newSkin = newSkin.erase(0, split + 1);
  537. }
  538. else
  539. {
  540. oldSkin = "";
  541. }
  542. mShapeInstance->reSkin(newSkin, oldSkin);
  543. mAppliedSkinName = newSkin;
  544. }
  545. }
  546. else
  547. {
  548. mShapeInstance->reSkin("", mAppliedSkinName);
  549. mAppliedSkinName = "";
  550. }
  551. }
  552. }
  553. void TSStatic::processTick(const Move* move)
  554. {
  555. if ( isServerObject() && mPlayAmbient && mAmbientThread )
  556. {
  557. mShapeInstance->setTimeScale(mAmbientThread, mAnimSpeed);
  558. mShapeInstance->advanceTime( TickSec, mAmbientThread );
  559. }
  560. if (isMounted())
  561. {
  562. MatrixF mat(true);
  563. mMount.object->getMountTransform(mMount.node, mMount.xfm, &mat);
  564. setTransform(mat);
  565. }
  566. }
  567. void TSStatic::interpolateTick(F32 delta)
  568. {
  569. }
  570. void TSStatic::advanceTime(F32 dt)
  571. {
  572. if ( mPlayAmbient && mAmbientThread )
  573. {
  574. mShapeInstance->setTimeScale(mAmbientThread, mAnimSpeed);
  575. mShapeInstance->advanceTime( dt, mAmbientThread );
  576. }
  577. if (isMounted())
  578. {
  579. MatrixF mat(true);
  580. mMount.object->getRenderMountTransform(dt, mMount.node, mMount.xfm, &mat);
  581. setRenderTransform(mat);
  582. }
  583. }
  584. void TSStatic::_updateShouldTick()
  585. {
  586. bool shouldTick = (mPlayAmbient && mAmbientThread) || isMounted();
  587. if (isTicking() != shouldTick)
  588. setProcessTick(shouldTick);
  589. }
  590. void TSStatic::prepRenderImage(SceneRenderState* state)
  591. {
  592. if (!mShapeInstance)
  593. return;
  594. Point3F cameraOffset;
  595. getRenderTransform().getColumn(3, &cameraOffset);
  596. cameraOffset -= state->getDiffuseCameraPosition();
  597. F32 dist = cameraOffset.len();
  598. if (dist < 0.01f)
  599. dist = 0.01f;
  600. if (mUseAlphaFade)
  601. {
  602. mAlphaFade = 1.0f;
  603. if ((mAlphaFadeStart < mAlphaFadeEnd) && mAlphaFadeStart > 0.1f)
  604. {
  605. if (mInvertAlphaFade)
  606. {
  607. if (dist <= mAlphaFadeStart)
  608. {
  609. return;
  610. }
  611. if (dist < mAlphaFadeEnd)
  612. {
  613. mAlphaFade = ((dist - mAlphaFadeStart) / (mAlphaFadeEnd - mAlphaFadeStart));
  614. }
  615. }
  616. else
  617. {
  618. if (dist >= mAlphaFadeEnd)
  619. {
  620. return;
  621. }
  622. if (dist > mAlphaFadeStart)
  623. {
  624. mAlphaFade -= ((dist - mAlphaFadeStart) / (mAlphaFadeEnd - mAlphaFadeStart));
  625. }
  626. }
  627. }
  628. }
  629. else if (smUseStaticObjectFade)
  630. {
  631. F32 boundsLen = getWorldSphere().radius;
  632. if (boundsLen < smStaticObjectUnfadeableSize)
  633. {
  634. F32 distAdjust = (boundsLen) / (smStaticObjectUnfadeableSize);
  635. distAdjust = 1 - distAdjust;
  636. dist *= distAdjust;
  637. mAlphaFade = 1.0f;
  638. if ((smStaticObjectFadeStart < smStaticObjectFadeEnd) && smStaticObjectFadeStart > 0.1f)
  639. {
  640. if (dist >= smStaticObjectFadeEnd)
  641. {
  642. return;
  643. }
  644. if (dist > smStaticObjectFadeStart)
  645. {
  646. mAlphaFade -= ((dist - smStaticObjectFadeStart) / (smStaticObjectFadeEnd - smStaticObjectFadeStart));
  647. }
  648. }
  649. }
  650. }
  651. F32 invScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z));
  652. // If we're currently rendering our own reflection we
  653. // don't want to render ourselves into it.
  654. if (mCubeReflector.isRendering())
  655. return;
  656. if (mForceDetail == -1)
  657. mShapeInstance->setDetailFromDistance(state, dist * invScale);
  658. else
  659. mShapeInstance->setCurrentDetail(mForceDetail);
  660. if (mShapeInstance->getCurrentDetail() < 0)
  661. return;
  662. GFXTransformSaver saver;
  663. // Set up our TS render state.
  664. TSRenderState rdata;
  665. rdata.setSceneState(state);
  666. rdata.setFadeOverride(1.0f);
  667. rdata.setOriginSort(mUseOriginSort);
  668. if (mCubeReflector.isEnabled())
  669. rdata.setCubemap(mCubeReflector.getCubemap());
  670. // Acculumation
  671. rdata.setAccuTex(mAccuTex);
  672. // If we have submesh culling enabled then prepare
  673. // the object space frustum to pass to the shape.
  674. Frustum culler;
  675. if (mMeshCulling)
  676. {
  677. culler = state->getCullingFrustum();
  678. MatrixF xfm(true);
  679. xfm.scale(Point3F::One / getScale());
  680. xfm.mul(getRenderWorldTransform());
  681. xfm.mul(culler.getTransform());
  682. culler.setTransform(xfm);
  683. rdata.setCuller(&culler);
  684. }
  685. // We might have some forward lit materials
  686. // so pass down a query to gather lights.
  687. LightQuery query;
  688. query.init(getWorldSphere());
  689. rdata.setLightQuery(&query);
  690. MatrixF mat = getRenderTransform();
  691. mat.scale(mObjScale);
  692. GFX->setWorldMatrix(mat);
  693. if (state->isDiffusePass() && mCubeReflector.isEnabled() && mCubeReflector.getOcclusionQuery())
  694. {
  695. RenderPassManager* pass = state->getRenderPass();
  696. OccluderRenderInst* ri = pass->allocInst<OccluderRenderInst>();
  697. ri->type = RenderPassManager::RIT_Occluder;
  698. ri->query = mCubeReflector.getOcclusionQuery();
  699. mObjToWorld.mulP(mObjBox.getCenter(), &ri->position);
  700. ri->scale.set(mObjBox.getExtents());
  701. ri->orientation = pass->allocUniqueXform(mObjToWorld);
  702. ri->isSphere = false;
  703. state->getRenderPass()->addInst(ri);
  704. }
  705. if (mShapeInstance)
  706. {
  707. mShapeInstance->animate();
  708. if (mUseAlphaFade || smUseStaticObjectFade)
  709. {
  710. mShapeInstance->setAlphaAlways(mAlphaFade);
  711. S32 s = mShapeInstance->mMeshObjects.size();
  712. for (S32 x = 0; x < s; x++)
  713. {
  714. mShapeInstance->mMeshObjects[x].visible = mAlphaFade;
  715. }
  716. }
  717. }
  718. mShapeInstance->render(rdata);
  719. #ifdef TORQUE_AFX_ENABLED
  720. if (!mIgnoreZodiacs && mDecalDetailsPtr != 0)
  721. afxZodiacMgr::renderPolysoupZodiacs(state, this);
  722. #endif
  723. if (mRenderNormalScalar > 0)
  724. {
  725. ObjectRenderInst* ri = state->getRenderPass()->allocInst<ObjectRenderInst>();
  726. ri->renderDelegate.bind(this, &TSStatic::_renderNormals);
  727. ri->type = RenderPassManager::RIT_Editor;
  728. state->getRenderPass()->addInst(ri);
  729. }
  730. }
  731. void TSStatic::_renderNormals(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat)
  732. {
  733. PROFILE_SCOPE(TSStatic_RenderNormals);
  734. GFXTransformSaver saver;
  735. MatrixF mat = getRenderTransform();
  736. mat.scale(mObjScale);
  737. GFX->multWorld(mat);
  738. S32 dl = mShapeInstance->getCurrentDetail();
  739. mShapeInstance->renderDebugNormals(mRenderNormalScalar, dl);
  740. }
  741. void TSStatic::onScaleChanged()
  742. {
  743. Parent::onScaleChanged();
  744. if (mPhysicsRep)
  745. {
  746. // If the editor is enabled delay the scale operation
  747. // by a few milliseconds so that we're not rebuilding
  748. // during an active scale drag operation.
  749. if (gEditingMission)
  750. mPhysicsRep->queueCallback(500, Delegate<void()>(this, &TSStatic::_updatePhysics));
  751. else
  752. _updatePhysics();
  753. }
  754. setMaskBits(ScaleMask);
  755. }
  756. void TSStatic::setTransform(const MatrixF& mat)
  757. {
  758. Parent::setTransform(mat);
  759. if (!isMounted())
  760. setMaskBits(TransformMask);
  761. if (mPhysicsRep)
  762. mPhysicsRep->setTransform(mat);
  763. // Accumulation
  764. if (isClientObject() && mShapeInstance)
  765. {
  766. if (mShapeInstance->hasAccumulation())
  767. AccumulationVolume::updateObject(this);
  768. }
  769. // Since this is a static it's render transform changes 1
  770. // to 1 with it's collision transform... no interpolation.
  771. setRenderTransform(mat);
  772. }
  773. U32 TSStatic::packUpdate(NetConnection* con, U32 mask, BitStream* stream)
  774. {
  775. U32 retMask = Parent::packUpdate(con, mask, stream);
  776. if (stream->writeFlag(mask & TransformMask))
  777. mathWrite(*stream, getTransform());
  778. if (stream->writeFlag(mask & ScaleMask))
  779. {
  780. // Only write one bit if the scale is one.
  781. if (stream->writeFlag(mObjScale != Point3F::One))
  782. mathWrite(*stream, mObjScale);
  783. }
  784. if (stream->writeFlag(mask & UpdateCollisionMask))
  785. stream->write((U32)mCollisionType);
  786. if (stream->writeFlag(mask & SkinMask))
  787. con->packNetStringHandleU(stream, mSkinNameHandle);
  788. if (stream->writeFlag(mask & AdvancedStaticOptionsMask))
  789. {
  790. PACK_ASSET(con, Shape);
  791. stream->write((U32)mDecalType);
  792. stream->writeFlag(mAllowPlayerStep);
  793. stream->writeFlag(mMeshCulling);
  794. stream->writeFlag(mUseOriginSort);
  795. stream->write(mRenderNormalScalar);
  796. stream->write(mForceDetail);
  797. if (stream->writeFlag(mAnimOffset != 0.0f))
  798. stream->writeFloat(mAnimOffset, 7);
  799. if (stream->writeFlag(mAnimSpeed != 1.0f))
  800. stream->writeSignedFloat(mAnimSpeed / AnimSpeedMax, 7);
  801. stream->writeFlag(mPlayAmbient);
  802. }
  803. if (stream->writeFlag(mUseAlphaFade))
  804. {
  805. stream->write(mAlphaFadeStart);
  806. stream->write(mAlphaFadeEnd);
  807. stream->write(mInvertAlphaFade);
  808. }
  809. stream->writeFlag(mIgnoreZodiacs);
  810. if (stream->writeFlag(mHasGradients))
  811. {
  812. stream->writeFlag(mInvertGradientRange);
  813. stream->write(mGradientRange.x);
  814. stream->write(mGradientRange.y);
  815. }
  816. if (mLightPlugin)
  817. retMask |= mLightPlugin->packUpdate(this, AdvancedStaticOptionsMask, con, mask, stream);
  818. if (stream->writeFlag(reflectorDesc != NULL))
  819. {
  820. stream->writeRangedU32(reflectorDesc->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
  821. }
  822. stream->write(mOverrideColor);
  823. if (stream->writeFlag(mask & MaterialMask))
  824. {
  825. stream->writeInt(mChangingMaterials.size(), 16);
  826. for (U32 i = 0; i < mChangingMaterials.size(); i++)
  827. {
  828. stream->writeInt(mChangingMaterials[i].slot, 16);
  829. NetStringHandle matNameStr = mChangingMaterials[i].assetId.c_str();
  830. con->packNetStringHandleU(stream, matNameStr);
  831. }
  832. //mChangingMaterials.clear();
  833. }
  834. return retMask;
  835. }
  836. void TSStatic::unpackUpdate(NetConnection* con, BitStream* stream)
  837. {
  838. Parent::unpackUpdate(con, stream);
  839. if (stream->readFlag()) // TransformMask
  840. {
  841. MatrixF mat;
  842. mathRead(*stream, &mat);
  843. setTransform(mat);
  844. setRenderTransform(mat);
  845. }
  846. if (stream->readFlag()) // ScaleMask
  847. {
  848. if (stream->readFlag())
  849. {
  850. VectorF scale;
  851. mathRead(*stream, &scale);
  852. setScale(scale);
  853. }
  854. else
  855. setScale(Point3F::One);
  856. }
  857. if (stream->readFlag()) // UpdateCollisionMask
  858. {
  859. U32 collisionType = CollisionMesh;
  860. stream->read(&collisionType);
  861. // Handle it if we have changed CollisionType's
  862. if ((MeshType)collisionType != mCollisionType)
  863. {
  864. mCollisionType = (MeshType)collisionType;
  865. if (isProperlyAdded() && mShapeInstance)
  866. prepCollision();
  867. }
  868. }
  869. if (stream->readFlag()) // SkinMask
  870. {
  871. NetStringHandle skinDesiredNameHandle = con->unpackNetStringHandleU(stream);;
  872. if (mSkinNameHandle != skinDesiredNameHandle)
  873. {
  874. mSkinNameHandle = skinDesiredNameHandle;
  875. reSkin();
  876. }
  877. }
  878. if (stream->readFlag()) // AdvancedStaticOptionsMask
  879. {
  880. UNPACK_ASSET(con, Shape);
  881. stream->read((U32*)&mDecalType);
  882. mAllowPlayerStep = stream->readFlag();
  883. mMeshCulling = stream->readFlag();
  884. mUseOriginSort = stream->readFlag();
  885. stream->read(&mRenderNormalScalar);
  886. stream->read(&mForceDetail);
  887. if (stream->readFlag())
  888. mAnimOffset = stream->readFloat(7);
  889. if (stream->readFlag())
  890. mAnimSpeed = stream->readSignedFloat(7) * AnimSpeedMax;
  891. mPlayAmbient = stream->readFlag();
  892. //update our shape, figuring that it likely changed
  893. _createShape();
  894. }
  895. mUseAlphaFade = stream->readFlag();
  896. if (mUseAlphaFade)
  897. {
  898. stream->read(&mAlphaFadeStart);
  899. stream->read(&mAlphaFadeEnd);
  900. stream->read(&mInvertAlphaFade);
  901. }
  902. mIgnoreZodiacs = stream->readFlag();
  903. mHasGradients = stream->readFlag();
  904. if (mHasGradients)
  905. {
  906. mInvertGradientRange = stream->readFlag();
  907. stream->read(&mGradientRange.x);
  908. stream->read(&mGradientRange.y);
  909. }
  910. if (mLightPlugin)
  911. {
  912. mLightPlugin->unpackUpdate(this, con, stream);
  913. }
  914. if (stream->readFlag())
  915. {
  916. cubeDescId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
  917. }
  918. stream->read(&mOverrideColor);
  919. if (stream->readFlag())
  920. {
  921. mChangingMaterials.clear();
  922. U32 materialCount = stream->readInt(16);
  923. for (U32 i = 0; i < materialCount; i++)
  924. {
  925. matMap newMatMap;
  926. newMatMap.slot = stream->readInt(16);
  927. newMatMap.assetId = String(con->unpackNetStringHandleU(stream).getString());
  928. //do the lookup, now
  929. newMatMap.matAsset = AssetDatabase.acquireAsset<MaterialAsset>(newMatMap.assetId);
  930. mChangingMaterials.push_back(newMatMap);
  931. }
  932. updateMaterials();
  933. }
  934. if (isProperlyAdded())
  935. _updateShouldTick();
  936. set_special_typing();
  937. }
  938. //----------------------------------------------------------------------------
  939. bool TSStatic::castRay(const Point3F& start, const Point3F& end, RayInfo* info)
  940. {
  941. if (mCollisionType == None)
  942. return false;
  943. if (!mShapeInstance)
  944. return false;
  945. if (mCollisionType == Bounds)
  946. {
  947. F32 fst;
  948. if (!mObjBox.collideLine(start, end, &fst, &info->normal))
  949. return false;
  950. info->t = fst;
  951. info->object = this;
  952. info->point.interpolate(start, end, fst);
  953. info->material = NULL;
  954. return true;
  955. }
  956. else
  957. {
  958. RayInfo shortest = *info;
  959. RayInfo localInfo;
  960. shortest.t = 1e8f;
  961. localInfo.generateTexCoord = info->generateTexCoord;
  962. for (U32 i = 0; i < mLOSDetails.size(); i++)
  963. {
  964. mShapeInstance->animate(mLOSDetails[i]);
  965. if (mShapeInstance->castRayOpcode(mLOSDetails[i], start, end, &localInfo))
  966. {
  967. localInfo.object = this;
  968. if (localInfo.t < shortest.t)
  969. shortest = localInfo;
  970. }
  971. }
  972. if (shortest.object == this)
  973. {
  974. // Copy out the shortest time...
  975. *info = shortest;
  976. return true;
  977. }
  978. }
  979. return false;
  980. }
  981. bool TSStatic::castRayRendered(const Point3F& start, const Point3F& end, RayInfo* info)
  982. {
  983. if (!mShapeInstance)
  984. return false;
  985. // Cast the ray against the currently visible detail
  986. RayInfo localInfo;
  987. if (info && info->generateTexCoord)
  988. localInfo.generateTexCoord = true;
  989. bool res = mShapeInstance->castRayOpcode(mShapeInstance->getCurrentDetail(), start, end, &localInfo);
  990. if (res)
  991. {
  992. *info = localInfo;
  993. info->object = this;
  994. return true;
  995. }
  996. return false;
  997. }
  998. bool TSStatic::buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF&)
  999. {
  1000. if (!mShapeInstance)
  1001. return false;
  1002. // This is safe to set even if we're not outputing
  1003. polyList->setTransform(&mObjToWorld, mObjScale);
  1004. polyList->setObject(this);
  1005. if (context == PLC_Export)
  1006. {
  1007. // Use highest detail level
  1008. S32 dl = 0;
  1009. // Try to call on the client so we can export materials
  1010. if (isServerObject() && getClientObject())
  1011. dynamic_cast<TSStatic*>(getClientObject())->mShapeInstance->buildPolyList(polyList, dl);
  1012. else
  1013. mShapeInstance->buildPolyList(polyList, dl);
  1014. }
  1015. else if (context == PLC_Selection)
  1016. {
  1017. // Use the last rendered detail level
  1018. S32 dl = mShapeInstance->getCurrentDetail();
  1019. mShapeInstance->buildPolyListOpcode(dl, polyList, box);
  1020. }
  1021. else
  1022. {
  1023. // Figure out the mesh type we're looking for.
  1024. MeshType meshType = (context == PLC_Decal) ? mDecalType : mCollisionType;
  1025. if (meshType == None)
  1026. return false;
  1027. else if (meshType == Bounds)
  1028. polyList->addBox(mObjBox);
  1029. else if (meshType == VisibleMesh)
  1030. mShapeInstance->buildPolyList(polyList, 0);
  1031. else if (context == PLC_Decal && mDecalDetailsPtr != 0)
  1032. {
  1033. for (U32 i = 0; i < mDecalDetailsPtr->size(); i++)
  1034. mShapeInstance->buildPolyListOpcode((*mDecalDetailsPtr)[i], polyList, box);
  1035. }
  1036. else
  1037. {
  1038. // Everything else is done from the collision meshes
  1039. // which may be built from either the visual mesh or
  1040. // special collision geometry.
  1041. for (U32 i = 0; i < mCollisionDetails.size(); i++)
  1042. mShapeInstance->buildPolyListOpcode(mCollisionDetails[i], polyList, box);
  1043. }
  1044. }
  1045. return true;
  1046. }
  1047. bool TSStatic::buildExportPolyList(ColladaUtils::ExportData* exportData, const Box3F& box, const SphereF&)
  1048. {
  1049. if (!mShapeInstance)
  1050. return false;
  1051. if (mCollisionType == Bounds)
  1052. {
  1053. ColladaUtils::ExportData::colMesh* colMesh;
  1054. exportData->colMeshes.increment();
  1055. colMesh = &exportData->colMeshes.last();
  1056. colMesh->mesh.setTransform(&mObjToWorld, mObjScale);
  1057. colMesh->mesh.setObject(this);
  1058. colMesh->mesh.addBox(mObjBox);
  1059. colMesh->colMeshName = String::ToString("ColBox%d-1", exportData->colMeshes.size());
  1060. }
  1061. else if (mCollisionType == VisibleMesh)
  1062. {
  1063. ColladaUtils::ExportData::colMesh* colMesh;
  1064. exportData->colMeshes.increment();
  1065. colMesh = &exportData->colMeshes.last();
  1066. colMesh->mesh.setTransform(&mObjToWorld, mObjScale);
  1067. colMesh->mesh.setObject(this);
  1068. mShapeInstance->buildPolyList(&colMesh->mesh, 0);
  1069. colMesh->colMeshName = String::ToString("ColMesh%d-1", exportData->colMeshes.size());
  1070. }
  1071. else if (mCollisionType == CollisionMesh)
  1072. {
  1073. // Everything else is done from the collision meshes
  1074. // which may be built from either the visual mesh or
  1075. // special collision geometry.
  1076. for (U32 i = 0; i < mCollisionDetails.size(); i++)
  1077. {
  1078. ColladaUtils::ExportData::colMesh* colMesh;
  1079. exportData->colMeshes.increment();
  1080. colMesh = &exportData->colMeshes.last();
  1081. colMesh->mesh.setTransform(&mObjToWorld, mObjScale);
  1082. colMesh->mesh.setObject(this);
  1083. mShapeInstance->buildPolyListOpcode(mCollisionDetails[i], &colMesh->mesh, box);
  1084. colMesh->colMeshName = String::ToString("ColMesh%d-1", exportData->colMeshes.size());
  1085. }
  1086. }
  1087. //Next, process the LOD levels and materials.
  1088. if (isServerObject() && getClientObject())
  1089. {
  1090. TSStatic* clientShape = dynamic_cast<TSStatic*>(getClientObject());
  1091. exportData->meshData.increment();
  1092. //Prep a meshData for this shape in particular
  1093. ColladaUtils::ExportData::meshLODData* meshData = &exportData->meshData.last();
  1094. //Fill out the info we'll need later to actually append our mesh data for the detail levels during the processing phase
  1095. meshData->shapeInst = clientShape->mShapeInstance;
  1096. meshData->originatingObject = this;
  1097. meshData->meshTransform = mObjToWorld;
  1098. meshData->scale = mObjScale;
  1099. //Iterate over all our detail levels
  1100. for (U32 i = 0; i < clientShape->mShapeInstance->getNumDetails(); i++)
  1101. {
  1102. TSShape::Detail detail = clientShape->mShapeInstance->getShape()->details[i];
  1103. String detailName = String::ToLower(clientShape->mShapeInstance->getShape()->getName(detail.nameIndex));
  1104. //Skip it if it's a collision or line of sight element
  1105. if (detailName.startsWith("col") || detailName.startsWith("los"))
  1106. continue;
  1107. meshData->meshDetailLevels.increment();
  1108. ColladaUtils::ExportData::detailLevel* curDetail = &meshData->meshDetailLevels.last();
  1109. //Make sure we denote the size this detail level has
  1110. curDetail->size = getNextPow2(detail.size);
  1111. }
  1112. }
  1113. return true;
  1114. }
  1115. void TSStatic::buildConvex(const Box3F& box, Convex* convex)
  1116. {
  1117. if (mCollisionType == None)
  1118. return;
  1119. if (mShapeInstance == NULL)
  1120. return;
  1121. // These should really come out of a pool
  1122. mConvexList->collectGarbage();
  1123. if (mCollisionType == Bounds)
  1124. {
  1125. // Just return a box convex for the entire shape...
  1126. Convex* cc = 0;
  1127. CollisionWorkingList& wl = convex->getWorkingList();
  1128. for (CollisionWorkingList* itr = wl.wLink.mNext; itr != &wl; itr = itr->wLink.mNext)
  1129. {
  1130. if (itr->mConvex->getType() == BoxConvexType &&
  1131. itr->mConvex->getObject() == this)
  1132. {
  1133. cc = itr->mConvex;
  1134. break;
  1135. }
  1136. }
  1137. if (cc)
  1138. return;
  1139. // Create a new convex.
  1140. BoxConvex* cp = new BoxConvex;
  1141. mConvexList->registerObject(cp);
  1142. convex->addToWorkingList(cp);
  1143. cp->init(this);
  1144. mObjBox.getCenter(&cp->mCenter);
  1145. cp->mSize.x = mObjBox.len_x() / 2.0f;
  1146. cp->mSize.y = mObjBox.len_y() / 2.0f;
  1147. cp->mSize.z = mObjBox.len_z() / 2.0f;
  1148. }
  1149. else // CollisionMesh || VisibleMesh
  1150. {
  1151. TSStaticPolysoupConvex::smCurObject = this;
  1152. for (U32 i = 0; i < mCollisionDetails.size(); i++)
  1153. mShapeInstance->buildConvexOpcode(mObjToWorld, mObjScale, mCollisionDetails[i], box, convex, mConvexList);
  1154. TSStaticPolysoupConvex::smCurObject = NULL;
  1155. }
  1156. }
  1157. SceneObject* TSStaticPolysoupConvex::smCurObject = NULL;
  1158. TSStaticPolysoupConvex::TSStaticPolysoupConvex()
  1159. : box(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f),
  1160. normal(0.0f, 0.0f, 0.0f, 0.0f),
  1161. idx(0),
  1162. mesh(NULL)
  1163. {
  1164. mType = TSPolysoupConvexType;
  1165. for (U32 i = 0; i < 4; ++i)
  1166. {
  1167. verts[i].set(0.0f, 0.0f, 0.0f);
  1168. }
  1169. }
  1170. Point3F TSStaticPolysoupConvex::support(const VectorF& vec) const
  1171. {
  1172. F32 bestDot = mDot(verts[0], vec);
  1173. const Point3F* bestP = &verts[0];
  1174. for (S32 i = 1; i < 4; i++)
  1175. {
  1176. F32 newD = mDot(verts[i], vec);
  1177. if (newD > bestDot)
  1178. {
  1179. bestDot = newD;
  1180. bestP = &verts[i];
  1181. }
  1182. }
  1183. return *bestP;
  1184. }
  1185. Box3F TSStaticPolysoupConvex::getBoundingBox() const
  1186. {
  1187. Box3F wbox = box;
  1188. wbox.minExtents.convolve(mObject->getScale());
  1189. wbox.maxExtents.convolve(mObject->getScale());
  1190. mObject->getTransform().mul(wbox);
  1191. return wbox;
  1192. }
  1193. Box3F TSStaticPolysoupConvex::getBoundingBox(const MatrixF& mat, const Point3F& scale) const
  1194. {
  1195. AssertISV(false, "TSStaticPolysoupConvex::getBoundingBox(m,p) - Not implemented. -- XEA");
  1196. return box;
  1197. }
  1198. void TSStaticPolysoupConvex::getPolyList(AbstractPolyList* list)
  1199. {
  1200. // Transform the list into object space and set the pointer to the object
  1201. MatrixF i(mObject->getTransform());
  1202. Point3F iS(mObject->getScale());
  1203. list->setTransform(&i, iS);
  1204. list->setObject(mObject);
  1205. // Add only the original collision triangle
  1206. S32 base = list->addPoint(verts[0]);
  1207. list->addPoint(verts[2]);
  1208. list->addPoint(verts[1]);
  1209. list->begin(0, (U32)idx ^ (uintptr_t)mesh);
  1210. list->vertex(base + 2);
  1211. list->vertex(base + 1);
  1212. list->vertex(base + 0);
  1213. list->plane(base + 0, base + 1, base + 2);
  1214. list->end();
  1215. }
  1216. void TSStaticPolysoupConvex::getFeatures(const MatrixF& mat, const VectorF& n, ConvexFeature* cf)
  1217. {
  1218. cf->material = 0;
  1219. cf->mObject = mObject;
  1220. // For a tetrahedron this is pretty easy... first
  1221. // convert everything into world space.
  1222. Point3F tverts[4];
  1223. mat.mulP(verts[0], &tverts[0]);
  1224. mat.mulP(verts[1], &tverts[1]);
  1225. mat.mulP(verts[2], &tverts[2]);
  1226. mat.mulP(verts[3], &tverts[3]);
  1227. // points...
  1228. S32 firstVert = cf->mVertexList.size();
  1229. cf->mVertexList.increment(); cf->mVertexList.last() = tverts[0];
  1230. cf->mVertexList.increment(); cf->mVertexList.last() = tverts[1];
  1231. cf->mVertexList.increment(); cf->mVertexList.last() = tverts[2];
  1232. cf->mVertexList.increment(); cf->mVertexList.last() = tverts[3];
  1233. // edges...
  1234. cf->mEdgeList.increment();
  1235. cf->mEdgeList.last().vertex[0] = firstVert + 0;
  1236. cf->mEdgeList.last().vertex[1] = firstVert + 1;
  1237. cf->mEdgeList.increment();
  1238. cf->mEdgeList.last().vertex[0] = firstVert + 1;
  1239. cf->mEdgeList.last().vertex[1] = firstVert + 2;
  1240. cf->mEdgeList.increment();
  1241. cf->mEdgeList.last().vertex[0] = firstVert + 2;
  1242. cf->mEdgeList.last().vertex[1] = firstVert + 0;
  1243. cf->mEdgeList.increment();
  1244. cf->mEdgeList.last().vertex[0] = firstVert + 3;
  1245. cf->mEdgeList.last().vertex[1] = firstVert + 0;
  1246. cf->mEdgeList.increment();
  1247. cf->mEdgeList.last().vertex[0] = firstVert + 3;
  1248. cf->mEdgeList.last().vertex[1] = firstVert + 1;
  1249. cf->mEdgeList.increment();
  1250. cf->mEdgeList.last().vertex[0] = firstVert + 3;
  1251. cf->mEdgeList.last().vertex[1] = firstVert + 2;
  1252. // triangles...
  1253. cf->mFaceList.increment();
  1254. cf->mFaceList.last().normal = PlaneF(tverts[2], tverts[1], tverts[0]);
  1255. cf->mFaceList.last().vertex[0] = firstVert + 2;
  1256. cf->mFaceList.last().vertex[1] = firstVert + 1;
  1257. cf->mFaceList.last().vertex[2] = firstVert + 0;
  1258. cf->mFaceList.increment();
  1259. cf->mFaceList.last().normal = PlaneF(tverts[1], tverts[0], tverts[3]);
  1260. cf->mFaceList.last().vertex[0] = firstVert + 1;
  1261. cf->mFaceList.last().vertex[1] = firstVert + 0;
  1262. cf->mFaceList.last().vertex[2] = firstVert + 3;
  1263. cf->mFaceList.increment();
  1264. cf->mFaceList.last().normal = PlaneF(tverts[2], tverts[1], tverts[3]);
  1265. cf->mFaceList.last().vertex[0] = firstVert + 2;
  1266. cf->mFaceList.last().vertex[1] = firstVert + 1;
  1267. cf->mFaceList.last().vertex[2] = firstVert + 3;
  1268. cf->mFaceList.increment();
  1269. cf->mFaceList.last().normal = PlaneF(tverts[0], tverts[2], tverts[3]);
  1270. cf->mFaceList.last().vertex[0] = firstVert + 0;
  1271. cf->mFaceList.last().vertex[1] = firstVert + 2;
  1272. cf->mFaceList.last().vertex[2] = firstVert + 3;
  1273. // All done!
  1274. }
  1275. void TSStatic::onMount(SceneObject* obj, S32 node)
  1276. {
  1277. Parent::onMount(obj, node);
  1278. _updateShouldTick();
  1279. }
  1280. void TSStatic::onUnmount(SceneObject* obj, S32 node)
  1281. {
  1282. Parent::onUnmount(obj, node);
  1283. setMaskBits(TransformMask);
  1284. _updateShouldTick();
  1285. }
  1286. U32 TSStatic::getNumDetails()
  1287. {
  1288. if (isServerObject() && getClientObject())
  1289. {
  1290. TSStatic* clientShape = dynamic_cast<TSStatic*>(getClientObject());
  1291. return clientShape->mShapeInstance->getNumDetails();
  1292. }
  1293. return 0;
  1294. };
  1295. void TSStatic::updateMaterials()
  1296. {
  1297. if (mChangingMaterials.empty() || !mShapeInstance)
  1298. return;
  1299. TSMaterialList* pMatList = mShapeInstance->getMaterialList();
  1300. String path;
  1301. if (mShapeAsset->isAssetValid())
  1302. path = mShapeAsset->getShapeFileName();
  1303. else
  1304. path = mShapeName;
  1305. pMatList->setTextureLookupPath(path);
  1306. bool found = false;
  1307. const Vector<String>& materialNames = pMatList->getMaterialNameList();
  1308. for (S32 i = 0; i < materialNames.size(); i++)
  1309. {
  1310. if (found)
  1311. break;
  1312. for (U32 m = 0; m < mChangingMaterials.size(); m++)
  1313. {
  1314. if (mChangingMaterials[m].slot == i)
  1315. {
  1316. //Fetch the actual material asset
  1317. pMatList->renameMaterial(i, mChangingMaterials[m].matAsset->getMaterialDefinitionName());
  1318. found = true;
  1319. break;
  1320. }
  1321. }
  1322. }
  1323. mChangingMaterials.clear();
  1324. // Initialize the material instances
  1325. mShapeInstance->initMaterialList();
  1326. }
  1327. void TSStatic::getUtilizedAssets(Vector<StringTableEntry>* usedAssetsList)
  1328. {
  1329. if(!mShapeAsset.isNull() && mShapeAsset->getAssetId() != ShapeAsset::smNoShapeAssetFallback)
  1330. usedAssetsList->push_back_unique(mShapeAsset->getAssetId());
  1331. }
  1332. //------------------------------------------------------------------------
  1333. //These functions are duplicated in tsStatic and shapeBase.
  1334. //They each function a little differently; but achieve the same purpose of gathering
  1335. //target names/counts without polluting simObject.
  1336. void TSStatic::onInspect(GuiInspector* inspector)
  1337. {
  1338. if (mShapeAsset == nullptr)
  1339. return;
  1340. //Put the GameObject group before everything that'd be gameobject-effecting, for orginazational purposes
  1341. GuiInspectorGroup* materialGroup = inspector->findExistentGroup(StringTable->insert("Materials"));
  1342. if (!materialGroup)
  1343. return;
  1344. GuiControl* stack = dynamic_cast<GuiControl*>(materialGroup->findObjectByInternalName(StringTable->insert("Stack")));
  1345. //Do this on both the server and client
  1346. S32 materialCount = mShapeAsset->getShape()->materialList->getMaterialNameList().size(); //mMeshAsset->getMaterialCount();
  1347. if (isServerObject())
  1348. {
  1349. //we need to update the editor
  1350. /*for (U32 i = 0; i < mFields.size(); i++)
  1351. {
  1352. //find any with the materialslot title and clear them out
  1353. if (FindMatch::isMatch("MaterialSlot*", mFields[i].mFieldName, false))
  1354. {
  1355. setDataField(mFields[i].mFieldName, NULL, "");
  1356. mFields.erase(i);
  1357. continue;
  1358. }
  1359. }*/
  1360. //next, get a listing of our materials in the shape, and build our field list for them
  1361. char matFieldName[128];
  1362. for (U32 i = 0; i < materialCount; i++)
  1363. {
  1364. StringTableEntry materialname = StringTable->insert(mShapeAsset->getShape()->materialList->getMaterialName(i).c_str());
  1365. AssetPtr<MaterialAsset> matAsset;
  1366. if(MaterialAsset::getAssetByMaterialName(materialname, &matAsset) == MaterialAsset::Ok)
  1367. {
  1368. dSprintf(matFieldName, 128, "MaterialSlot%d", i);
  1369. GuiInspectorField* fieldGui = materialGroup->constructField(TypeMaterialAssetPtr);
  1370. fieldGui->init(inspector, materialGroup);
  1371. fieldGui->setSpecialEditField(true);
  1372. fieldGui->setTargetObject(this);
  1373. StringTableEntry fldnm = StringTable->insert(matFieldName);
  1374. fieldGui->setSpecialEditVariableName(fldnm);
  1375. fieldGui->setInspectorField(NULL, fldnm);
  1376. fieldGui->setDocs("");
  1377. if (fieldGui->registerObject())
  1378. {
  1379. StringTableEntry fieldValue = matAsset->getAssetId();
  1380. //Check if we'd already actually changed it, and display the modified value
  1381. for (U32 c = 0; c < mChangingMaterials.size(); c++)
  1382. {
  1383. if (mChangingMaterials[c].slot == i)
  1384. {
  1385. fieldValue = StringTable->insert(mChangingMaterials[i].assetId.c_str());
  1386. break;
  1387. }
  1388. }
  1389. fieldGui->setValue(fieldValue);
  1390. stack->addObject(fieldGui);
  1391. }
  1392. else
  1393. {
  1394. SAFE_DELETE(fieldGui);
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. DefineEngineMethod(TSStatic, getTargetName, const char*, (S32 index), (0),
  1401. "Get the name of the indexed shape material.\n"
  1402. "@param index index of the material to get (valid range is 0 - getTargetCount()-1).\n"
  1403. "@return the name of the indexed material.\n"
  1404. "@see getTargetCount()\n")
  1405. {
  1406. TSStatic* obj = dynamic_cast<TSStatic*> (object);
  1407. if (obj)
  1408. {
  1409. // Try to use the client object (so we get the reskinned targets in the Material Editor)
  1410. if ((TSStatic*)obj->getClientObject())
  1411. obj = (TSStatic*)obj->getClientObject();
  1412. return obj->getShapeInstance()->getTargetName(index);
  1413. }
  1414. return "";
  1415. }
  1416. DefineEngineMethod(TSStatic, getTargetCount, S32, (), ,
  1417. "Get the number of materials in the shape.\n"
  1418. "@return the number of materials in the shape.\n"
  1419. "@see getTargetName()\n")
  1420. {
  1421. TSStatic* obj = dynamic_cast<TSStatic*> (object);
  1422. if (obj)
  1423. {
  1424. // Try to use the client object (so we get the reskinned targets in the Material Editor)
  1425. if ((TSStatic*)obj->getClientObject())
  1426. obj = (TSStatic*)obj->getClientObject();
  1427. return obj->getShapeInstance()->getTargetCount();
  1428. }
  1429. return -1;
  1430. }
  1431. // This method is able to change materials per map to with others. The material that is being replaced is being mapped to
  1432. // unmapped_mat as a part of this transition
  1433. DefineEngineMethod(TSStatic, changeMaterial, void, (const char* mapTo, Material* oldMat, Material* newMat), ("", nullAsType<Material*>(), nullAsType<Material*>()),
  1434. "@brief Change one of the materials on the shape.\n\n"
  1435. "This method changes materials per mapTo with others. The material that "
  1436. "is being replaced is mapped to unmapped_mat as a part of this transition.\n"
  1437. "@note Warning, right now this only sort of works. It doesn't do a live "
  1438. "update like it should.\n"
  1439. "@param mapTo the name of the material target to remap (from getTargetName)\n"
  1440. "@param oldMat the old Material that was mapped \n"
  1441. "@param newMat the new Material to map\n\n"
  1442. "@tsexample\n"
  1443. "// remap the first material in the shape\n"
  1444. "%mapTo = %obj.getTargetName( 0 );\n"
  1445. "%obj.changeMaterial( %mapTo, 0, MyMaterial );\n"
  1446. "@endtsexample\n")
  1447. {
  1448. // if no valid new material, theres no reason for doing this
  1449. if (!newMat)
  1450. {
  1451. Con::errorf("TSShape::changeMaterial failed: New material does not exist!");
  1452. return;
  1453. }
  1454. TSMaterialList* shapeMaterialList = object->getShapeResource()->materialList;
  1455. // Check the mapTo name exists for this shape
  1456. S32 matIndex = shapeMaterialList->getMaterialNameList().find_next(String(mapTo));
  1457. if (matIndex < 0)
  1458. {
  1459. Con::errorf("TSShape::changeMaterial failed: Invalid mapTo name '%s'", mapTo);
  1460. return;
  1461. }
  1462. // Lets remap the old material off, so as to let room for our current material room to claim its spot
  1463. if (oldMat)
  1464. oldMat->mMapTo = String("unmapped_mat");
  1465. newMat->mMapTo = mapTo;
  1466. // Map the material by name in the matmgr
  1467. MATMGR->mapMaterial(mapTo, newMat->getName());
  1468. // Replace instances with the new material being traded in. Lets make sure that we only
  1469. // target the specific targets per inst, this is actually doing more than we thought
  1470. delete shapeMaterialList->mMatInstList[matIndex];
  1471. shapeMaterialList->mMatInstList[matIndex] = newMat->createMatInstance();
  1472. // Finish up preparing the material instances for rendering
  1473. const GFXVertexFormat* flags = getGFXVertexFormat<GFXVertexPNTTB>();
  1474. FeatureSet features = MATMGR->getDefaultFeatures();
  1475. shapeMaterialList->getMaterialInst(matIndex)->init(features, flags);
  1476. }
  1477. DefineEngineMethod(TSStatic, getModelFile, const char*, (), ,
  1478. "@brief Get the model filename used by this shape.\n\n"
  1479. "@return the shape filename\n\n"
  1480. "@tsexample\n"
  1481. "// Acquire the model filename used on this shape.\n"
  1482. "%modelFilename = %obj.getModelFile();\n"
  1483. "@endtsexample\n"
  1484. )
  1485. {
  1486. return object->getShape();
  1487. }
  1488. void TSStatic::set_special_typing()
  1489. {
  1490. if (mCollisionType == VisibleMesh || mCollisionType == CollisionMesh)
  1491. mTypeMask |= InteriorLikeObjectType;
  1492. else
  1493. mTypeMask &= ~InteriorLikeObjectType;
  1494. }
  1495. void TSStatic::onStaticModified(const char* slotName, const char* newValue)
  1496. {
  1497. #ifdef TORQUE_AFX_ENABLED
  1498. if (slotName == afxZodiacData::GradientRangeSlot)
  1499. {
  1500. afxZodiacData::convertGradientRangeFromDegrees(mGradientRange, mGradientRangeUser);
  1501. return;
  1502. }
  1503. #endif
  1504. set_special_typing();
  1505. }
  1506. void TSStatic::setSelectionFlags(U8 flags)
  1507. {
  1508. Parent::setSelectionFlags(flags);
  1509. if (!mShapeInstance || !isClientObject())
  1510. return;
  1511. if (!mShapeInstance->ownMaterialList())
  1512. return;
  1513. TSMaterialList* pMatList = mShapeInstance->getMaterialList();
  1514. for (S32 j = 0; j < pMatList->size(); j++)
  1515. {
  1516. BaseMatInstance* bmi = pMatList->getMaterialInst(j);
  1517. bmi->setSelectionHighlighting(needsSelectionHighlighting());
  1518. }
  1519. }
  1520. void TSStatic::getNodeTransform(const char *nodeName, const MatrixF &xfm, MatrixF *outMat)
  1521. {
  1522. S32 nodeIDx = getShapeResource()->findNode(nodeName);
  1523. MatrixF mountTransform = mShapeInstance->mNodeTransforms[nodeIDx];
  1524. mountTransform.mul(xfm);
  1525. const Point3F &scale = getScale();
  1526. // The position of the mount point needs to be scaled.
  1527. Point3F position = mountTransform.getPosition();
  1528. position.convolve(scale);
  1529. mountTransform.setPosition(position);
  1530. // Also we would like the object to be scaled to the model.
  1531. outMat->mul(mObjToWorld, mountTransform);
  1532. return;
  1533. }
  1534. DefineEngineMethod(TSStatic, getNodeTransform, TransformF, (const char *nodeName), ,
  1535. "@brief Get the world transform of the specified mount slot.\n\n"
  1536. "@param slot Image slot to query\n"
  1537. "@return the mount transform\n\n")
  1538. {
  1539. MatrixF xf(true);
  1540. object->getNodeTransform(nodeName, MatrixF::Identity, &xf);
  1541. return xf;
  1542. }