Skip to content

Commit

Permalink
GRAPHICS: Add back support for NWN2 models
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 29, 2014
1 parent f48456e commit b03939e
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/graphics/aurora/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ noinst_HEADERS = \
cube.h \
model.h \
model_nwn.h \
model_nwn2.h \
model_kotor.h \
$(EMPTY)

Expand All @@ -20,5 +21,6 @@ libaurora_la_SOURCES = \
cube.cpp \
model.cpp \
model_nwn.cpp \
model_nwn2.cpp \
model_kotor.cpp \
$(EMPTY)
13 changes: 7 additions & 6 deletions src/graphics/aurora/meshutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ namespace Graphics {

namespace Aurora {

VertexDeclaration::VertexDeclaration() : faces(0), vertices(0), textures(0) {
VertexDeclaration::VertexDeclaration() : textureUVW(false), faces(0), vertices(0), textures(0) {
}

VertexDeclaration::VertexDeclaration(uint16 f, uint16 v, uint16 t) :
faces(f), vertices(v), textures(t) {
VertexDeclaration::VertexDeclaration(uint16 f, uint16 v, uint16 t, bool uvw) :
textureUVW(uvw), faces(f), vertices(v), textures(t) {

resize();
}

void VertexDeclaration::resize() {
bufferVerticesNormals.resize(vertices * 2 * 3);
bufferTexCoords.resize(vertices * textures * 2);
bufferTexCoords.resize(vertices * textures * (textureUVW ? 3 : 2));
bufferIndices.resize(faces * 3);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ void createMesh(Ogre::SubMesh *mesh, const VertexDeclaration &decl) {
}

assert (decl.bufferVerticesNormals.size() == (decl.vertices * 2 * 3));
assert (decl.bufferTexCoords.size() == (uint)(decl.vertices * decl.textures * 2));
assert (decl.bufferTexCoords.size() == (uint)(decl.vertices * decl.textures * (decl.textureUVW ? 3 : 2)));
assert (decl.bufferIndices.size() == (decl.faces * 3));

Ogre::VertexData *vertexData = new Ogre::VertexData();
Expand All @@ -108,7 +108,8 @@ void createMesh(Ogre::SubMesh *mesh, const VertexDeclaration &decl) {
vertexDecl->addElement(0, 1 * 3 * sizeof(float), Ogre::VET_FLOAT3, Ogre::VES_NORMAL);

for (uint i = 0; i < decl.textures; i++)
vertexDecl->addElement(1, i * 2 * sizeof(float), Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, i);
vertexDecl->addElement(1, i * (decl.textureUVW ? 3 : 2) * sizeof(float),
decl.textureUVW ? Ogre::VET_FLOAT3 : Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, i);

// Prepare hardware buffers

Expand Down
4 changes: 3 additions & 1 deletion src/graphics/aurora/meshutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Ogre::MeshManager &getOgreMeshManager();


struct VertexDeclaration {
bool textureUVW;

uint16 faces;
uint16 vertices;
uint16 textures;
Expand All @@ -62,7 +64,7 @@ struct VertexDeclaration {
std::vector<uint16> bufferIndices;

VertexDeclaration();
VertexDeclaration(uint16 f, uint16 v, uint16 t);
VertexDeclaration(uint16 f, uint16 v, uint16 t, bool uvw = false);

void resize();
void getBounds(float &minX, float &minY, float &minZ,
Expand Down

0 comments on commit b03939e

Please sign in to comment.