Skip to content

Commit

Permalink
GRAPHICS: Move creating model entities into class Model
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 29, 2014
1 parent 36546f8 commit 9e56a2b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 61 deletions.
35 changes: 35 additions & 0 deletions src/graphics/aurora/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@

#include <OgreSceneNode.h>
#include <OgreSceneManager.h>
#include <OgreMeshManager.h>
#include <OgreEntity.h>
#include <OgreAnimation.h>
#include <OgreAnimationState.h>

#include "common/stream.h"
#include "common/uuid.h"

#include "graphics/materialman.h"

#include "graphics/aurora/model.h"
#include "graphics/aurora/meshutil.h"
Expand Down Expand Up @@ -168,6 +172,37 @@ void Model::showBoundingBox(bool show) {
}
}

Ogre::Entity *Model::createEntity(const VertexDeclaration &vertexDecl, const Ogre::MaterialPtr &material) {
// Create a mesh according to the vertex declaration

Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(Common::generateIDRandomString().c_str(), "General");
Ogre::SubMesh *subMesh = mesh->createSubMesh();

createMesh(subMesh, vertexDecl);

// Bounding box / sphere

float minX, minY, minZ, maxX, maxY, maxZ, meshRadius;
vertexDecl.getBounds(minX, minY, minZ, maxX, maxY, maxZ, meshRadius);

mesh->_setBounds(Ogre::AxisAlignedBox(minX, minY, minZ, maxX, maxY, maxZ));
mesh->_setBoundingSphereRadius(meshRadius);

// Load the mesh and create an entity for it

mesh->load();

Ogre::Entity *entity = getOgreSceneManager().createEntity(mesh);
entity->setQueryFlags(kSelectableNone);

entity->getUserObjectBindings().setUserAny("renderable", Ogre::Any((Renderable *) this));

// Assign the material to the entity
entity->setMaterial(material.isNull() ? MaterialMan.getInvisible() : material);

return entity;
}

void Model::readValue(Common::SeekableReadStream &stream, uint32 &value) {
value = stream.readUint32LE();
}
Expand Down
5 changes: 5 additions & 0 deletions src/graphics/aurora/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
#include <vector>
#include <map>

#include <OgrePrerequisites.h>

#include "common/types.h"
#include "common/ustring.h"

#include "graphics/aurora/renderable.h"
#include "graphics/aurora/meshutil.h"

namespace Ogre {
class SceneNode;
Expand Down Expand Up @@ -117,6 +120,8 @@ class Model : public Renderable {

// General loading helpers

Ogre::Entity *createEntity(const VertexDeclaration &vertexDecl, const Ogre::MaterialPtr &material);

static void readValue(Common::SeekableReadStream &stream, uint32 &value);
static void readValue(Common::SeekableReadStream &stream, float &value);

Expand Down
65 changes: 4 additions & 61 deletions src/graphics/aurora/model_nwn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <OgreSceneNode.h>
#include <OgreMesh.h>
#include <OgreEntity.h>
#include <OgreMeshManager.h>
#include <OgreRoot.h>
#include <OgreVector3.h>

Expand Down Expand Up @@ -706,36 +705,8 @@ void Model_NWN::readBinaryMesh(ParserContext &ctx) {
}
}

// Create the mesh

Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(Common::generateIDRandomString().c_str(), "General");
Ogre::SubMesh *subMesh = mesh->createSubMesh();

createMesh(subMesh, vertexDecl);

// Bounding box / sphere

float minX, minY, minZ, maxX, maxY, maxZ, meshRadius;
vertexDecl.getBounds(minX, minY, minZ, maxX, maxY, maxZ, meshRadius);

mesh->_setBounds(Ogre::AxisAlignedBox(minX, minY, minZ, maxX, maxY, maxZ));
mesh->_setBoundingSphereRadius(meshRadius);

// Load the mesh and create an entity for it

mesh->load();

Ogre::Entity *entity = getOgreSceneManager().createEntity(mesh);
entity->setQueryFlags(kSelectableNone);

entity->getUserObjectBindings().setUserAny("renderable", Ogre::Any((Renderable *) this));

// Assign a material to the entity

if (material.isNull())
material = MaterialMan.getInvisible();

entity->setMaterial(material);
// Create an entity with the mesh defined by the vertex declaration and the material
Ogre::Entity *entity = createEntity(vertexDecl, material);

// Add the entity to our lists

Expand Down Expand Up @@ -1251,36 +1222,8 @@ void Model_NWN::processASCIIMesh(ParserContext &ctx, MeshASCII &mesh) {
}
}

// Create the mesh

Ogre::MeshPtr ogreMesh = Ogre::MeshManager::getSingleton().createManual(Common::generateIDRandomString().c_str(), "General");
Ogre::SubMesh *subMesh = ogreMesh->createSubMesh();

createMesh(subMesh, vertexDecl);

// Bounding box / sphere

float minX, minY, minZ, maxX, maxY, maxZ, meshRadius;
vertexDecl.getBounds(minX, minY, minZ, maxX, maxY, maxZ, meshRadius);

ogreMesh->_setBounds(Ogre::AxisAlignedBox(minX, minY, minZ, maxX, maxY, maxZ));
ogreMesh->_setBoundingSphereRadius(meshRadius);

// Load the mesh and create an entity for it

ogreMesh->load();

Ogre::Entity *entity = getOgreSceneManager().createEntity(ogreMesh);
entity->setQueryFlags(kSelectableNone);

entity->getUserObjectBindings().setUserAny("renderable", Ogre::Any((Renderable *) this));

// Assign a material to the entity

if (material.isNull())
material = MaterialMan.getInvisible();

entity->setMaterial(material);
// Create an entity with the mesh defined by the vertex declaration and the material
Ogre::Entity *entity = createEntity(vertexDecl, material);

// Add the entity to our lists

Expand Down

0 comments on commit 9e56a2b

Please sign in to comment.