tsStatic.cpp 56 KB

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