- scene::IMeshSceneNode *parent_mesh = NULL;
- if(getParent()->getMeshSceneNode())
- parent_mesh = getParent()->getMeshSceneNode();
- scene::IAnimatedMeshSceneNode *parent_animated_mesh = NULL;
- if(getParent()->getAnimatedMeshSceneNode())
- parent_animated_mesh = getParent()->getAnimatedMeshSceneNode();
- scene::IBillboardSceneNode *parent_sprite = NULL;
- if(getParent()->getSpriteSceneNode())
- parent_sprite = getParent()->getSpriteSceneNode();
-
- scene::IBoneSceneNode *parent_bone = NULL;
- if(parent_animated_mesh && m_attachment_bone != "")
- {
- parent_bone =
- parent_animated_mesh->getJointNode(m_attachment_bone.c_str());
- }
- // The spaghetti code below makes sure attaching works if either the
- // parent or child is a spritenode, meshnode, or animatedmeshnode
- // TODO: Perhaps use polymorphism here to save code duplication
- if(m_meshnode)
- {
- if(parent_bone)
- {
- m_meshnode->setParent(parent_bone);
- m_meshnode->setPosition(m_attachment_position);
- m_meshnode->setRotation(m_attachment_rotation);
- m_meshnode->updateAbsolutePosition();
- }
- else
- {
- if(parent_mesh)
- {
- m_meshnode->setParent(parent_mesh);
- m_meshnode->setPosition(m_attachment_position);
- m_meshnode->setRotation(m_attachment_rotation);
- m_meshnode->updateAbsolutePosition();
- }
- else if(parent_animated_mesh) {
- m_meshnode->setParent(parent_animated_mesh);
- m_meshnode->setPosition(m_attachment_position);
- m_meshnode->setRotation(m_attachment_rotation);
- m_meshnode->updateAbsolutePosition();
- }
- else if(parent_sprite) {
- m_meshnode->setParent(parent_sprite);
- m_meshnode->setPosition(m_attachment_position);
- m_meshnode->setRotation(m_attachment_rotation);
- m_meshnode->updateAbsolutePosition();
- }
- }
- }
- if(m_animated_meshnode)
- {
- if(parent_bone)
- {
- m_animated_meshnode->setParent(parent_bone);
- m_animated_meshnode->setPosition(m_attachment_position);
- m_animated_meshnode->setRotation(m_attachment_rotation);
- m_animated_meshnode->updateAbsolutePosition();
- }
- else
- {
- if(parent_mesh)
- {
- m_animated_meshnode->setParent(parent_mesh);
- m_animated_meshnode->setPosition(m_attachment_position);
- m_animated_meshnode->setRotation(m_attachment_rotation);
- m_animated_meshnode->updateAbsolutePosition();
- } else if(parent_animated_mesh) {
- m_animated_meshnode->setParent(parent_animated_mesh);
- m_animated_meshnode->setPosition(m_attachment_position);
- m_animated_meshnode->setRotation(m_attachment_rotation);
- m_animated_meshnode->updateAbsolutePosition();
- } else if(parent_sprite) {
- m_animated_meshnode->setParent(parent_sprite);
- m_animated_meshnode->setPosition(m_attachment_position);
- m_animated_meshnode->setRotation(m_attachment_rotation);
- m_animated_meshnode->updateAbsolutePosition();
- }
- }