diff options
-rw-r--r-- | SConstruct | 4 | ||||
-rw-r--r-- | application.cpp | 5 | ||||
-rwxr-xr-x | assimp.cpp | 124 |
3 files changed, 131 insertions, 2 deletions
@@ -1,5 +1,5 @@ env = Environment( - LIBS = ['ARgsub_lite', 'ARvideo', 'AR', 'png'], + LIBS = ['ARgsub_lite', 'ARvideo', 'AR', 'assimp'], ) common_sources = ['application.cpp', 'pattern.cpp', 'texture.cpp', 'texturesdl.cpp'] @@ -13,3 +13,5 @@ else: env.Append(LIBS = ['GL', 'GLU', 'SDL', 'SDLmain', 'gstreamer-0.10']) env.Program('foo', ['foo.cpp'] + common_sources) + +env.Program('assimp', ['assimp.cpp'] + common_sources) diff --git a/application.cpp b/application.cpp index b49bcb9..a77577a 100644 --- a/application.cpp +++ b/application.cpp @@ -60,8 +60,11 @@ Application::Application() { } // Setup double buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32); + // Get our surface - surface = SDL_SetVideoMode(xsize * 2, ysize * 2, 32, flags); + surface = SDL_SetVideoMode(xsize, ysize, 32, flags); if(!surface) { throw(std::runtime_error("Video mode set failed")); } diff --git a/assimp.cpp b/assimp.cpp new file mode 100755 index 0000000..c00c96b --- /dev/null +++ b/assimp.cpp @@ -0,0 +1,124 @@ +#include <stdexcept> +#include <iostream> + +#include "pattern.h" +#include "application.h" + +#include "texturesdl.h" + +#include <assimp/assimp.hpp> +#include <assimp/aiScene.h> +#include <assimp/aiPostProcess.h> + +Assimp::Importer* importer; + +class FiskPattern : public Pattern { + private: + const aiScene* scene; + + Texture** textures; + + public: + FiskPattern() : Pattern("patt.jon") { + scene = importer->ReadFile("tewi.x", 0); + + if(scene) { + std::cout << "Loaded model: " << scene->mNumMeshes << " meshes, " << scene->mNumMaterials << " materials." << std::endl; + for(int i = 0; i < scene->mNumMaterials; i++) { + aiMaterial* material = scene->mMaterials[i]; + + std::cout << "Material " << i << ": " << material->mNumProperties << " properties." << std::endl; + + for(int j = 0; j < material->mNumProperties; j++) { + aiMaterialProperty* property = material->mProperties[j]; + + std::cout << " " << std::string(property->mKey.data, property->mKey.length) << ": " << std::string(property->mData, property->mDataLength) << std::endl; + } + + } + + for(int i = 0; i < scene->mNumMeshes; i++) { + aiMesh* mesh = scene->mMeshes[i]; + + std::cout << "Mesh " << i << ": mMaterialIndex = " << mesh->mMaterialIndex << "." << std::endl; + + } + + } else { + std::cerr << "Failed to import model." << std::endl << importer->GetErrorString() << std::endl; + } + + Texture* tex_face = new TextureSDL("TEWI_face_01.bmp"); + Texture* tex_hair = new TextureSDL("TEWI_Hair_01.bmp"); + Texture* tex_body = new TextureSDL("TEWI_Body_01.bmp"); + Texture* tex_hair2 = new TextureSDL("TEWI_Hair_02.bmp"); + Texture* tex_body2 = new TextureSDL("TEWI_Body_02.bmp"); + + + textures = new Texture*[10]; + + textures[1] = tex_face; + textures[2] = tex_hair; + textures[3] = tex_body; + textures[4] = tex_body; + textures[5] = tex_body; + textures[6] = tex_body; + textures[7] = tex_body; + textures[8] = tex_hair; + textures[9] = new TextureSDL("gradient.png"); + + patt_width = 50.0; + } + + protected: + virtual void draw() { + double gl_para[16]; + arglCameraView(patt_trans_kake, gl_para, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadMatrixd(gl_para); + + //glTranslatef(0.0, -8.0, 0.0); + + glRotatef(90, 1, 0, 0); + + //glColor4f(1, 0, 0, 0.5); + glPolygonMode(GL_FRONT, GL_FILL); + + for(int i = 0; i < 6; i++) { // scene->mNumMeshes + aiMesh* mesh = scene->mMeshes[i]; + + glBindTexture(GL_TEXTURE_2D, textures[mesh->mMaterialIndex]->tex()); + + for(int j = 0; j < mesh->mNumFaces; j++) { + aiFace* face = &mesh->mFaces[j]; + + glBegin(GL_POLYGON); + for(int k = 0; k < face->mNumIndices; k++) { + aiVector3D* texcoord = &mesh->mTextureCoords[0][face->mIndices[k]]; + glTexCoord2f(texcoord->x, 2 - texcoord->y); + aiVector3D* vertice = &mesh->mVertices[face->mIndices[k]]; + glVertex3f(vertice->x, vertice->y, vertice->z); + } + glEnd(); + } + } + + } +}; + +int main(int argc, char **argv) { + try { + Application* app = new Application(); + + Assimp::Importer _importer; + importer = &_importer; + + app->patt = new FiskPattern(); + + app->run(); + } catch(std::runtime_error e) { + std::cerr << "Exception caught: " << e.what() << std::endl; + } + return 0; +} |