/* Copyright 2003-2007 ROBLOX Corporation, All Rights Reserved */ #include "stdafx.h" #include "V8World/Clump.h" #include "V8World/Primitive.h" #include "V8World/MotorJoint.h" #include "V8World/RigidJoint.h" #include "V8DataModel/JointInstance.h" namespace RBX { ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// Clump::Clump() {} Clump::~Clump() {} bool Clump::isClumpRootPrimitive(const Primitive* p) { return IndexedMesh::isUpperRoot(p); } Clump* Clump::getPrimitiveClump(Primitive* p) { return rbx_static_cast(p->getComputedUpper()); } const Clump* Clump::getConstPrimitiveClump(const Primitive* p) { return rbx_static_cast(p->getConstComputedUpper()); } // TODO: redundant code void Clump::loadConstMotors(G3D::Array& load, bool nonAnimatedOnly) const { RBXASSERT(getConstTypedLower()); const SpanningEdge* edge = getConstTypedLower()->getConstEdgeToParent(); RBXASSERT(edge); const Joint* j = rbx_static_cast(edge); if (Joint::isMotorJoint(j)) { const Motor* jointInstance = static_cast(j->getJointOwner()); if ((!nonAnimatedOnly) || (!jointInstance->getIsAnimatedJoint())) { load.append(j); } } for (int i = 0; i < numChildren(); ++i) { getConstTypedChild(i)->loadConstMotors(load, nonAnimatedOnly); } } // TODO: redundant code void Clump::loadMotors(G3D::Array& load, bool nonAnimatedOnly) { RBXASSERT(getTypedLower()); SpanningEdge* edge = getTypedLower()->getEdgeToParent(); RBXASSERT(edge); Joint* j = rbx_static_cast(edge); if (Joint::isMotorJoint(j)) { Motor* jointInstance = static_cast(j->getJointOwner()); if ((!nonAnimatedOnly) || (!jointInstance->getIsAnimatedJoint())) { load.append(j); } } for (int i = 0; i < numChildren(); ++i) { getTypedChild(i)->loadMotors(load, nonAnimatedOnly); } } ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// /* bool PrimIterator::isParent(Primitive* parentCandidate, Primitive* child, SearchType searchType) { RBXASSERT(child && parentCandidate); RBXASSERT(child->getTypedParent() == parentCandidate); Joint* joint = rbx_static_cast(child->getEdgeToParent()); RBXASSERT(Joint::isSpanningTreeJoint(joint)); switch (searchType) { case IN_CLUMP: { bool inSameClump = Joint::isRigidJoint(joint); RBXASSERT(inSameClump == (!child->getTypedUpper())); RBXASSERT(inSameClump == (child->getClump() == parentCandidate->getClump())); return inSameClump; } case IN_ASSEMBLY: { bool inSameAssembly = Joint::isKinematicJoint(joint); RBXASSERT(inSameAssembly == (child->getAssembly() == parentCandidate->getAssembly())); return inSameAssembly; } default: { RBXASSERT(0); return false; } } } Primitive* PrimIterator::findParent(Primitive* p, SearchType searchType) { Primitive* parent = p->getTypedParent(); if (parent && isParent(parent, p, searchType)) { return parent; } else { return NULL; } } Primitive* PrimIterator::findFirstChild(Primitive* p, SearchType searchType) { for (int i = 0; i < p->numChildren(); ++i) { Primitive* child = p->getTypedChild(i); if (isParent(p, child, searchType)) { return child; } } return NULL; } Primitive* PrimIterator::findNextSibling(Primitive* parent, Primitive* sibling, SearchType searchType) { Primitive* latched = NULL; for (int i = 0; i < parent->numChildren(); ++i) { Primitive* child = parent->getTypedChild(i); if (isParent(parent, child, searchType)) { if (child == sibling) { RBXASSERT(!latched); latched = child; } else { if (latched) { return child; } } } } return NULL; } Primitive* PrimIterator::findNextRelative(Primitive* parent, Primitive* p, SearchType searchType) { if (!parent) { return NULL; } else if (Primitive* sibling = findNextSibling(parent, p, searchType)) { return sibling; } else { Primitive* parentParent = findParent(parent, searchType); return findNextRelative(parentParent, parent, searchType); } } Primitive* PrimIterator::getNextPrimitive(Primitive* p, SearchType searchType) { if (Primitive* firstChild = findFirstChild(p, searchType)) { return firstChild; } else { Primitive* parent = findParent(p, searchType); return findNextRelative(parent, p, searchType); } } PrimIterator& PrimIterator::operator++() { primitive = getNextPrimitive(primitive, searchType); return *this; } */ } // namespace