#include "DotScene.h"
void BlenderBullet::loadScene(){
::parseDotScene("scene1.scene", "General", mSceneMgr);
int n = mSceneMgr->getRootSceneNode()->numChildren();
for(int i = 0; i < n; i++){
Ogre::Node *nd = mSceneMgr->getRootSceneNode()->getChild(i);
std::cout << "Node " << nd->getName() << std::endl;
Ogre::SceneNode *snd = dynamic_cast<Ogre::SceneNode *>(nd);
if(snd){
int m = snd->numAttachedObjects();
for(int j = 0; j < m; j++){
Ogre::MovableObject *obj = snd->getAttachedObject(j);
std::cout << "\tEntity " << obj->getName() << std::endl;
Ogre::Entity *ent = dynamic_cast<Ogre::Entity *>(obj);
if(ent){
OgreBulletCollisions::CollisionShape *shape = 0;
OgreBulletDynamics::RigidBody *body =
new OgreBulletDynamics::RigidBody(snd->getName(), m_world);
if (snd->getName().compare("s_Ground") == 0){
shape =new OgreBulletCollisions::StaticPlaneCollisionShape(
Ogre::Vector3::UNIT_Y, snd->getPosition().y);
body->setStaticShape(shape, 0.1, 0.8);
}
else if(snd->getName().find("_S_") != Ogre::String::npos){
Ogre::Sphere bound = ent->getWorldBoundingSphere();
shape = new OgreBulletCollisions::SphereCollisionShape(
1.01*bound.getRadius());
}
else if(snd->getName().find("_B_") != Ogre::String::npos){
Ogre::AxisAlignedBox bound = ent->getWorldBoundingBox();
Ogre::Vector3 desiredSize = 1.01*(bound.getMaximum() -
bound.getMinimum());
shape = new OgreBulletCollisions::BoxCollisionShape(
desiredSize*snd->getScale());
}
else if(snd->getName().find("_C_") != Ogre::String::npos){
Ogre::Sphere bound = ent->getWorldBoundingSphere();
Ogre::Vector3 desiredSize = bound.getRadius()*snd->getScale();
shape = new OgreBulletCollisions::CylinderCollisionShape(
desiredSize*1.01, Ogre::Vector3::UNIT_Y);
}
else {
Ogre::AxisAlignedBox bound = ent->getWorldBoundingBox();
Ogre::Vector3 desiredSize = 1.01*(bound.getMaximum() -
bound.getMinimum());
Ogre::Matrix4 transform= Ogre::Matrix4::IDENTITY;;
transform.setScale(desiredSize*snd->getScale());
OgreBulletCollisions::StaticMeshToShapeConverter makeShape(
ent, transform);
shape = makeShape.createConvexDecomposition();
}
if(snd->getName().find("s_") == 0){
body->setStaticShape(shape, 0.1, 0.8,
snd->_getDerivedPosition());
} else {
body->setShape(snd, shape, 0.1, 0.8, 1,
snd->_getDerivedPosition());
}
m_bodies.push_back(body);
m_shapes.push_back(shape);
} } } } }