appNode.cpp 3.0 KB

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