From 3b87c4f66b69c1f4df1715e09bb5c906011b605b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Johan=20T=2E=20S=C3=B8ma=CC=8Aen?= Date: Fri, 30 Dec 2011 12:53:49 +0100 Subject: [PATCH] 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. --- engines/grim/costume.cpp | 3 ++- engines/grim/gfx_base.h | 3 +++ engines/grim/gfx_opengl.cpp | 29 +++++++++++++++++++++++++++++ engines/grim/gfx_opengl.h | 1 + engines/grim/gfx_tinygl.cpp | 27 +++++++++++++++++++++++++++ engines/grim/gfx_tinygl.h | 1 + engines/grim/modelemi.cpp | 2 +- 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/engines/grim/costume.cpp b/engines/grim/costume.cpp index b9275c7d606..087e5fb23a4 100644 --- a/engines/grim/costume.cpp +++ b/engines/grim/costume.cpp @@ -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); diff --git a/engines/grim/gfx_base.h b/engines/grim/gfx_base.h index 65ffe0ffb09..cc6f8813333 100644 --- a/engines/grim/gfx_base.h +++ b/engines/grim/gfx_base.h @@ -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; diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index 9554c8ec4fb..fe38490750d 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -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 diff --git a/engines/grim/gfx_opengl.h b/engines/grim/gfx_opengl.h index 6efc1011198..76456e85ed3 100644 --- a/engines/grim/gfx_opengl.h +++ b/engines/grim/gfx_opengl.h @@ -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); diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index a5a13162655..f8965c88eb4 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -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(face->_normal.getData())); tglBegin(TGL_POLYGON); diff --git a/engines/grim/gfx_tinygl.h b/engines/grim/gfx_tinygl.h index ee1910320cd..c78daca883a 100644 --- a/engines/grim/gfx_tinygl.h +++ b/engines/grim/gfx_tinygl.h @@ -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); diff --git a/engines/grim/modelemi.cpp b/engines/grim/modelemi.cpp index dd4912f969e..18ec9f7c203 100644 --- a/engines/grim/modelemi.cpp +++ b/engines/grim/modelemi.cpp @@ -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]); } }