tsDump.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. #include "platform/platform.h"
  23. #include "ts/tsShapeInstance.h"
  24. #include "ts/tsMaterialList.h"
  25. #include "core/strings/stringFunctions.h"
  26. //-------------------------------------------------------------------------------------
  27. // Dump shape structure:
  28. //-------------------------------------------------------------------------------------
  29. #define dumpLine(buffer) {str = buffer; stream.write((int)dStrlen(str),str);}
  30. void TSShapeInstance::dumpNode(Stream & stream ,S32 level, S32 nodeIndex, Vector<S32> & detailSizes)
  31. {
  32. if (nodeIndex < 0)
  33. return;
  34. // limit level to prevent overflow
  35. if (level > 160)
  36. level = 160;
  37. S32 i;
  38. const char * str;
  39. char space[512];
  40. for (i = 0; i < level*3; i++)
  41. space[i] = ' ';
  42. space[level*3] = '\0';
  43. const char *nodeName = "";
  44. const TSShape::Node & node = mShape->nodes[nodeIndex];
  45. if (node.nameIndex != -1)
  46. nodeName = mShape->getName(node.nameIndex);
  47. dumpLine(avar("%s%s", space, nodeName));
  48. // find all the objects that hang off this node...
  49. Vector<ObjectInstance*> objectList;
  50. for (i=0; i<mMeshObjects.size(); i++)
  51. if (mMeshObjects[i].nodeIndex == nodeIndex)
  52. objectList.push_back(&mMeshObjects[i]);
  53. if (objectList.size() == 0)
  54. dumpLine("\r\n");
  55. S32 spaceCount = -1;
  56. for (S32 j=0;j<objectList.size(); j++)
  57. {
  58. // should be a dynamic cast, but MSVC++ has problems with this...
  59. MeshObjectInstance * obj = (MeshObjectInstance *)(objectList[j]);
  60. if (!obj)
  61. continue;
  62. // object name
  63. const char *objectName = "";
  64. if (obj->object->nameIndex!=-1)
  65. objectName = mShape->getName(obj->object->nameIndex);
  66. // more spaces if this is the second object on this node
  67. if (spaceCount>0)
  68. {
  69. char buf[2048];
  70. dMemset(buf,' ',spaceCount);
  71. buf[spaceCount] = '\0';
  72. dumpLine(buf);
  73. }
  74. // dump object name
  75. dumpLine(avar(" --> Object %s with following details: ",objectName));
  76. // dump object detail levels
  77. for (S32 k=0; k<obj->object->numMeshes; k++)
  78. {
  79. S32 f = obj->object->startMeshIndex;
  80. if (mShape->meshes[f+k])
  81. dumpLine(avar(" %i",detailSizes[k]));
  82. }
  83. dumpLine("\r\n");
  84. // how many spaces should we prepend if we have another object on this node
  85. if (spaceCount<0)
  86. spaceCount = (S32)(dStrlen(space) + dStrlen(nodeName));
  87. if(spaceCount > 2000)
  88. spaceCount = 2000;
  89. }
  90. // search for children
  91. for (S32 k=nodeIndex+1; k<mShape->nodes.size(); k++)
  92. {
  93. if (mShape->nodes[k].parentIndex == nodeIndex)
  94. // this is our child
  95. dumpNode(stream, level+1, k, detailSizes);
  96. }
  97. }
  98. void TSShapeInstance::dump(Stream & stream)
  99. {
  100. S32 i,j,ss,od,sz;
  101. const char * name;
  102. const char * str;
  103. dumpLine("\r\nShape Hierarchy:\r\n");
  104. dumpLine("\r\n Details:\r\n");
  105. for (i=0; i<mShape->details.size(); i++)
  106. {
  107. const TSDetail & detail = mShape->details[i];
  108. name = mShape->getName(detail.nameIndex);
  109. ss = detail.subShapeNum;
  110. od = detail.objectDetailNum;
  111. sz = (S32)detail.size;
  112. if (ss >= 0)
  113. {
  114. dumpLine(avar(" %s, Subtree %i, objectDetail %i, size %i\r\n",name,ss,od,sz));
  115. }
  116. else
  117. {
  118. dumpLine(avar(" %s, AutoBillboard, size %i\r\n", name, sz));
  119. }
  120. }
  121. dumpLine("\r\n Subtrees:\r\n");
  122. for (i=0; i<mShape->subShapeFirstNode.size(); i++)
  123. {
  124. S32 a = mShape->subShapeFirstNode[i];
  125. S32 b = a + mShape->subShapeNumNodes[i];
  126. dumpLine(avar(" Subtree %i\r\n",i));
  127. // compute detail sizes for each subshape
  128. Vector<S32> detailSizes;
  129. for (S32 l=0;l<mShape->details.size(); l++)
  130. {
  131. if ((mShape->details[l].subShapeNum==i) || (mShape->details[l].subShapeNum==-1))
  132. detailSizes.push_back((S32)mShape->details[l].size);
  133. }
  134. for (j=a; j<b; j++)
  135. {
  136. const TSNode & node = mShape->nodes[j];
  137. // if the node has a parent, it'll get dumped via the parent
  138. if (node.parentIndex<0)
  139. dumpNode(stream,3,j,detailSizes);
  140. }
  141. }
  142. bool foundSkin = false;
  143. for (i=0; i<mShape->objects.size(); i++)
  144. {
  145. TSShape::Object& currentObject = mShape->objects[i];
  146. if (currentObject.nodeIndex<0) // must be a skin
  147. {
  148. if (!foundSkin)
  149. dumpLine("\r\n Skins:\r\n");
  150. foundSkin=true;
  151. const char * skinName = "";
  152. S32 nameIndex = currentObject.nameIndex;
  153. if (nameIndex>=0)
  154. skinName = mShape->getName(nameIndex);
  155. dumpLine(avar(" Skin %s with following details: ",skinName));
  156. for (S32 num=0; num<currentObject.numMeshes; num++)
  157. {
  158. if (mShape->meshes[currentObject.startMeshIndex + num])
  159. dumpLine(avar(" %i",(S32)mShape->details[num].size));
  160. }
  161. dumpLine("\r\n");
  162. }
  163. }
  164. if (foundSkin)
  165. dumpLine("\r\n");
  166. dumpLine("\r\n Sequences:\r\n");
  167. for (i = 0; i < mShape->sequences.size(); i++)
  168. {
  169. const char *name = "(none)";
  170. if (mShape->sequences[i].nameIndex != -1)
  171. name = mShape->getName(mShape->sequences[i].nameIndex);
  172. dumpLine(avar(" %3d: %s%s%s\r\n", i, name,
  173. mShape->sequences[i].isCyclic() ? " (cyclic)" : "",
  174. mShape->sequences[i].isBlend() ? " (blend)" : ""));
  175. }
  176. if (mShape->materialList)
  177. {
  178. TSMaterialList * ml = mShape->materialList;
  179. dumpLine("\r\n Material list:\r\n");
  180. for (i=0; i<(S32)ml->size(); i++)
  181. {
  182. U32 flags = ml->getFlags(i);
  183. const String& name = ml->getMaterialName(i);
  184. dumpLine(avar(
  185. " material #%i: '%s'%s.", i, name.c_str(),
  186. flags & (TSMaterialList::S_Wrap|TSMaterialList::T_Wrap) ? "" : " not tiled")
  187. );
  188. if (flags & TSMaterialList::Translucent)
  189. {
  190. if (flags & TSMaterialList::Additive)
  191. dumpLine(" Additive-translucent.")
  192. else if (flags & TSMaterialList::Subtractive)
  193. dumpLine(" Subtractive-translucent.")
  194. else
  195. dumpLine(" Translucent.")
  196. }
  197. dumpLine("\r\n");
  198. }
  199. }
  200. }