GRIM/EMI: Add drawing of meshes

This only adds in drawing of meshes, textures are still not
done, and skeletal animation is fully missing, however, this
commit marks the first one where anything 3D is visible
in EMI.
This commit is contained in:
Einar Johan T. Sømåen 2011-12-30 12:53:49 +01:00
parent 85b99d5c64
commit 3b87c4f66b
7 changed files with 64 additions and 2 deletions

View File

@ -36,6 +36,7 @@
#include "engines/grim/costume/head.h"
#include "engines/grim/costume/main_model_component.h"
#include "engines/grim/costume/colormap_component.h"
#include "engines/grim/costume/emimesh_component.h"
#include "engines/grim/costume/keyframe_component.h"
#include "engines/grim/costume/mesh_component.h"
#include "engines/grim/costume/lua_var_component.h"
@ -344,7 +345,7 @@ Component *Costume::loadComponentEMI(Component *parent, int parentID, const char
if (FROM_BE_32(tag) == MKTAG('m','e','s','h')) {
Debug::warning(Debug::Costumes, "Actor::loadComponentEMI Implement MESH-handling: %s" , name);
//return new EMIMeshComponent(parent, parentID, name, prevComponent, tag);
return new EMIMeshComponent(parent, parentID, name, prevComponent, tag);
} else if (FROM_BE_32(tag) == MKTAG('s','k','e','l')) {
Debug::warning(Debug::Costumes, "Actor::loadComponentEMI Implement SKEL-handling: %s" , name);
//return new ModelComponent(parent, parentID, name, prevComponent, tag);

View File

@ -41,6 +41,8 @@ class PrimitiveObject;
class Font;
class TextObject;
class Material;
class EMIModel;
class EMIMeshFace;
class ModelNode;
class Mesh;
class MeshFace;
@ -106,6 +108,7 @@ public:
virtual void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis) = 0;
virtual void translateViewpointFinish() = 0;
virtual void drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face) = 0;
virtual void drawModelFace(const MeshFace *face, float *vertices, float *vertNormals, float *textureVerts) = 0;
virtual void drawSprite(const Sprite *sprite) = 0;

View File

@ -40,6 +40,7 @@
#include "engines/grim/lipsync.h"
#include "engines/grim/bitmap.h"
#include "engines/grim/primitives.h"
#include "engines/grim/modelemi.h"
#include "engines/grim/model.h"
#include "engines/grim/set.h"
@ -426,6 +427,34 @@ void GfxOpenGL::set3DMode() {
glDepthFunc(GL_LESS);
}
void GfxOpenGL::drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face) {
int *indices = (int*)face->_indexes;
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glBegin(GL_TRIANGLES);
for (int j = 0; j < face->_faceLength * 3; j++) {
int index = indices[j];
if (face->_hasTexture) {
glTexCoord2f(model->_texVerts[index].getX(), model->_texVerts[index].getY());
}
glColor4ub(model->_colorMap[index].r,model->_colorMap[index].g,model->_colorMap[index].b,model->_colorMap[index].a);
Math::Vector3d normal = model->_normals[index];
Math::Vector3d vertex = model->_vertices[index];
// Transform vertices (or maybe we should have done this already?)
glNormal3fv(normal.getData());
glVertex3fv(vertex.getData());
}
glEnd();
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
glColor3f(1.0f,1.0f,1.0f);
}
void GfxOpenGL::drawModelFace(const MeshFace *face, float *vertices, float *vertNormals, float *textureVerts) {
// Support transparency in actor objects, such as the message tube
// in Manny's Office

View File

@ -78,6 +78,7 @@ public:
void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis);
void translateViewpointFinish();
void drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face);
void drawModelFace(const MeshFace *face, float *vertices, float *vertNormals, float *textureVerts);
void drawSprite(const Sprite *sprite);

View File

@ -34,6 +34,7 @@
#include "engines/grim/lipsync.h"
#include "engines/grim/bitmap.h"
#include "engines/grim/primitives.h"
#include "engines/grim/modelemi.h"
#include "engines/grim/model.h"
#include "engines/grim/set.h"
@ -467,6 +468,32 @@ void GfxTinyGL::getShadowColor(byte *r, byte *g, byte *b) {
*b = _shadowColorB;
}
void GfxTinyGL::drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face) {
int *indices = (int*)face->_indexes;
tglDisable(TGL_DEPTH_TEST);
tglDisable(TGL_ALPHA_TEST);
tglBegin(TGL_TRIANGLES);
for (int j = 0; j < face->_faceLength * 3; j++) {
int index = indices[j];
if (face->_hasTexture) {
tglTexCoord2f(model->_texVerts[index].getX(), model->_texVerts[index].getY());
}
//tglColor4ub(model->_colorMap[index].r,model->_colorMap[index].g,model->_colorMap[index].b,model->_colorMap[index].a);
Math::Vector3d normal = model->_normals[index];
Math::Vector3d vertex = model->_vertices[index];
tglNormal3f(normal.x(), normal.y(), normal.z());
tglVertex3f(vertex.x(), vertex.y(), vertex.z());
}
tglEnd();
tglEnable(TGL_DEPTH_TEST);
tglEnable(TGL_ALPHA_TEST);
}
void GfxTinyGL::drawModelFace(const MeshFace *face, float *vertices, float *vertNormals, float *textureVerts) {
tglNormal3fv(const_cast<float *>(face->_normal.getData()));
tglBegin(TGL_POLYGON);

View File

@ -69,6 +69,7 @@ public:
void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis);
void translateViewpointFinish();
void drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face);
void drawModelFace(const MeshFace *face, float *vertices, float *vertNormals, float *textureVerts);
void drawSprite(const Sprite *sprite);

View File

@ -196,7 +196,7 @@ void EMIModel::draw() {
// We will need to add a call to the skeleton, to get the modified vertices, but for now,
// I'll be happy with just static drawing
for(int i = 0; i < _numFaces; i++) {
//g_driver->drawEMIModelFace(this, &_faces[i]);
g_driver->drawEMIModelFace(this, &_faces[i]);
}
}