tsDump.cpp 7.4 KB

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