appNode.cpp

Engine/source/ts/loader/appNode.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "ts/loader/appNode.h"
 25
 26AppNode::AppNode()
 27{
 28   mName = NULL;
 29   mParentName = NULL;
 30   mParentIndex = 0;
 31}
 32
 33AppNode::~AppNode()
 34{
 35   dFree( mName );
 36   dFree( mParentName );
 37
 38   // delete children and meshes
 39   for (S32 i = 0; i < mChildNodes.size(); i++)
 40      delete mChildNodes[i];
 41   for (S32 i = 0; i < mMeshes.size(); i++)
 42      delete mMeshes[i];
 43}
 44
 45S32 AppNode::getNumMesh()
 46{
 47   if (mMeshes.size() == 0)
 48      buildMeshList();
 49   return mMeshes.size();
 50}
 51
 52AppMesh* AppNode::getMesh(S32 idx)
 53{
 54   return (idx < getNumMesh() && idx >= 0) ? mMeshes[idx] : NULL;
 55}
 56
 57S32 AppNode::getNumChildNodes()
 58{
 59   if (mChildNodes.size() == 0)
 60      buildChildList();
 61   return mChildNodes.size();
 62}
 63
 64AppNode * AppNode::getChildNode(S32 idx)
 65{
 66   return (idx < getNumChildNodes() && idx >= 0) ? mChildNodes[idx] : NULL;
 67}
 68
 69bool AppNode::isBillboard()
 70{
 71   return !dStrnicmp(getName(),"BB::",4) || !dStrnicmp(getName(),"BB_",3) || isBillboardZAxis();
 72}
 73
 74bool AppNode::isBillboardZAxis()
 75{
 76   return !dStrnicmp(getName(),"BBZ::",5) || !dStrnicmp(getName(),"BBZ_",4);
 77}
 78
 79bool AppNode::isDummy()
 80{
 81   // naming convention should work well enough...
 82   // ...but can override this method if one wants more
 83   return !dStrnicmp(getName(), "dummy", 5);
 84}
 85
 86bool AppNode::isBounds()
 87{
 88   // naming convention should work well enough...
 89   // ...but can override this method if one wants more
 90   return !dStricmp(getName(), "bounds");
 91}
 92
 93bool AppNode::isSequence()
 94{
 95   // naming convention should work well enough...
 96   // ...but can override this method if one wants more
 97   return !dStrnicmp(getName(), "Sequence", 8);
 98}
 99
100bool AppNode::isRoot()
101{
102   // we assume root node isn't added, so this is never true
103   // but allow for possibility (by overriding this method)
104   // so that isParentRoot still works.
105   return false;
106}
107