Skip to content

Commit

Permalink
Merge pull request #377 from blackberry-gaming/next-dgough
Browse files Browse the repository at this point in the history
Next dgough
  • Loading branch information
seanpaultaylor committed Apr 30, 2012
2 parents ebf1527 + 9473e89 commit cc40fee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
15 changes: 13 additions & 2 deletions gameplay/src/MeshSkin.cpp
Expand Up @@ -57,7 +57,7 @@ Joint* MeshSkin::getJoint(const char* id) const
return NULL;
}

MeshSkin* MeshSkin::clone() const
MeshSkin* MeshSkin::clone(NodeCloneContext &context) const
{
MeshSkin* skin = new MeshSkin();
skin->_bindShape = _bindShape;
Expand All @@ -67,7 +67,18 @@ MeshSkin* MeshSkin::clone() const
skin->setJointCount(jointCount);

assert(skin->_rootNode == NULL);
skin->_rootNode = _rootNode->clone();

// Check if the root node has already been cloned.
if (Node* rootNode = context.findClonedNode(_rootNode))
{
skin->_rootNode = rootNode;
rootNode->addRef();
}
else
{
skin->_rootNode = _rootNode->cloneRecursive(context);
}

Node* node = skin->_rootNode->findNode(_rootJoint->getId());
assert(node);
skin->_rootJoint = static_cast<Joint*>(node);
Expand Down
4 changes: 3 additions & 1 deletion gameplay/src/MeshSkin.h
Expand Up @@ -134,9 +134,11 @@ class MeshSkin : public Transform::Listener
/**
* Clones the MeshSkin and the joints that it references.
*
* @param context The clone context.
*
* @return The newly created MeshSkin.
*/
MeshSkin* clone() const;
MeshSkin* clone(NodeCloneContext &context) const;

/**
* Sets the number of joints that can be stored in this skin.
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/Model.cpp
Expand Up @@ -354,7 +354,7 @@ Model* Model::clone(NodeCloneContext &context)
Model* model = Model::create(getMesh());
if (getSkin())
{
model->setSkin(getSkin()->clone());
model->setSkin(getSkin()->clone(context));
}
Material* materialClone = getMaterial()->clone(context);
model->setMaterial(materialClone); // TODO: Don't forget material parts
Expand Down
10 changes: 7 additions & 3 deletions gameplay/src/Node.cpp
Expand Up @@ -866,10 +866,16 @@ Node* Node::cloneRecursive(NodeCloneContext &context) const
{
Node* copy = cloneSingleNode(context);

Node* lastChild = NULL;
for (Node* child = getFirstChild(); child != NULL; child = child->getNextSibling())
{
lastChild = child;
}
// Loop through the nodes backwards because addChild adds the node to the front.
for (Node* child = lastChild; child != NULL; child = child->getPreviousSibling())
{
Node* childCopy = child->cloneRecursive(context);
copy->addChild(childCopy); // TODO: Does child order matter?
copy->addChild(childCopy);
childCopy->release();
}
return copy;
Expand All @@ -880,8 +886,6 @@ void Node::cloneInto(Node* node, NodeCloneContext &context) const
Transform::cloneInto(node, context);

// TODO: Clone the rest of the node data.
//node->setCamera(getCamera());
//node->setLight(getLight());

if (Camera* camera = getCamera())
{
Expand Down

0 comments on commit cc40fee

Please sign in to comment.