appNode.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "ts/loader/appNode.h"
  23. AppNode::AppNode()
  24. {
  25. mName = NULL;
  26. mParentName = NULL;
  27. }
  28. AppNode::~AppNode()
  29. {
  30. dFree( mName );
  31. dFree( mParentName );
  32. // delete children and meshes
  33. for (S32 i = 0; i < mChildNodes.size(); i++)
  34. delete mChildNodes[i];
  35. for (S32 i = 0; i < mMeshes.size(); i++)
  36. delete mMeshes[i];
  37. }
  38. S32 AppNode::getNumMesh()
  39. {
  40. if (mMeshes.size() == 0)
  41. buildMeshList();
  42. return mMeshes.size();
  43. }
  44. AppMesh* AppNode::getMesh(S32 idx)
  45. {
  46. return (idx < getNumMesh() && idx >= 0) ? mMeshes[idx] : NULL;
  47. }
  48. S32 AppNode::getNumChildNodes()
  49. {
  50. if (mChildNodes.size() == 0)
  51. buildChildList();
  52. return mChildNodes.size();
  53. }
  54. AppNode * AppNode::getChildNode(S32 idx)
  55. {
  56. return (idx < getNumChildNodes() && idx >= 0) ? mChildNodes[idx] : NULL;
  57. }
  58. bool AppNode::isBillboard()
  59. {
  60. return !dStrnicmp(getName(),"BB::",4) || !dStrnicmp(getName(),"BB_",3) || isBillboardZAxis();
  61. }
  62. bool AppNode::isBillboardZAxis()
  63. {
  64. return !dStrnicmp(getName(),"BBZ::",5) || !dStrnicmp(getName(),"BBZ_",4);
  65. }
  66. bool AppNode::isDummy()
  67. {
  68. // naming convention should work well enough...
  69. // ...but can override this method if one wants more
  70. return !dStrnicmp(getName(), "dummy", 5);
  71. }
  72. bool AppNode::isBounds()
  73. {
  74. // naming convention should work well enough...
  75. // ...but can override this method if one wants more
  76. return !dStricmp(getName(), "bounds");
  77. }
  78. bool AppNode::isSequence()
  79. {
  80. // naming convention should work well enough...
  81. // ...but can override this method if one wants more
  82. return !dStrnicmp(getName(), "Sequence", 8);
  83. }
  84. bool AppNode::isRoot()
  85. {
  86. // we assume root node isn't added, so this is never true
  87. // but allow for possibility (by overriding this method)
  88. // so that isParentRoot still works.
  89. return false;
  90. }