From a0cee6d856e0407afd6bceed61ecb87fc8d8202c Mon Sep 17 00:00:00 2001 From: xemuth Date: Sat, 22 Aug 2020 17:17:23 +0000 Subject: [PATCH] SurfaceCtrl: working demo git-svn-id: svn://ultimatepp.org/upp/trunk@14881 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/SurfaceCtrl/MagicCamera.h | 2 +- bazaar/SurfaceCtrl/Mesh.h | 4 ++++ bazaar/SurfaceCtrl/Object3D.cpp | 33 +++++++++++++++++++++++++++++--- bazaar/SurfaceCtrl/Object3D.h | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/bazaar/SurfaceCtrl/MagicCamera.h b/bazaar/SurfaceCtrl/MagicCamera.h index 0e86dcc8d..e31bba036 100644 --- a/bazaar/SurfaceCtrl/MagicCamera.h +++ b/bazaar/SurfaceCtrl/MagicCamera.h @@ -13,7 +13,7 @@ namespace Upp{ glm::vec3 UnProject2(float winX, float winY,float winZ)const noexcept; public: MagicCamera(){} - MagicCamera& Init(){transform.SetPosition(0, 10, 20); focus = glm::vec3(0.0f,0.0f,0.0f); return *this;} + MagicCamera& Init(){transform.SetPosition(0, 0, 20); focus = glm::vec3(0.0f,0.0f,0.0f); return *this;} glm::mat4 GetProjectionMatrix()const noexcept; glm::mat4 GetViewMatrix()const noexcept; diff --git a/bazaar/SurfaceCtrl/Mesh.h b/bazaar/SurfaceCtrl/Mesh.h index 598cf04ee..0fae4bfb2 100644 --- a/bazaar/SurfaceCtrl/Mesh.h +++ b/bazaar/SurfaceCtrl/Mesh.h @@ -45,6 +45,7 @@ class Mesh : public Moveable{ Material material; //The material object is a representation of material property of the object (it change how light affect it) + unsigned int textureIndice = 0; /** All stuff about texture @@ -102,6 +103,9 @@ class Mesh : public Moveable{ } } + Mesh& SetTextureIndice(unsigned int indice){textureIndice = indice; return *this;} + unsigned int GetTextureIndice(){return textureIndice;} + Material& GetMaterial(){return material;} void SetName(const Upp::String& n){name = n;} diff --git a/bazaar/SurfaceCtrl/Object3D.cpp b/bazaar/SurfaceCtrl/Object3D.cpp index 242b1de51..e0fa3ea8a 100644 --- a/bazaar/SurfaceCtrl/Object3D.cpp +++ b/bazaar/SurfaceCtrl/Object3D.cpp @@ -135,6 +135,7 @@ bool Object3D::LoadModel(const String& Filename, Color color, unsigned int pFlag */ bool Object3D::InitFromScene(const aiScene* pScene, const String& Filename){ meshes.AddN(pScene->mNumMeshes); + textures.AddN(pScene->mNumMaterials); //Add Texture vector init here // Initialise les maillages de la scène, un par un @@ -146,7 +147,7 @@ bool Object3D::InitFromScene(const aiScene* pScene, const String& Filename){ } void Object3D::InitMesh(unsigned int Index, const aiMesh* paiMesh){ //For texture / material data - //meshes[Index].MaterialIndex = paiMesh->mMaterialIndex; + meshes[Index].SetTextureIndice(paiMesh->mMaterialIndex); Vector& vertices = meshes[Index].GetVertices(); Vector& normals = meshes[Index].GetNormals(); @@ -195,8 +196,34 @@ void Object3D::InitMesh(unsigned int Index, const aiMesh* paiMesh){ } } bool Object3D::InitMaterials(const aiScene* pScene, const String& Filename){ - //TODO - return true; + bool Ret = false; + for (unsigned int i = 0 ; i < pScene->mNumMaterials ; i++) { + const aiMaterial* pMaterial = pScene->mMaterials[i]; + textures[i] = NULL; + if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0) { + aiString Path; + + if (pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { + //std::string FullPath = Dir + "/" + Path.data; + + //LOAD texture here: + //m_Textures[i] = new Texture(GL_TEXTURE_2D, FullPath.c_str()); + + /*if (!textures[i]->Load()) { + printf("Error loading texture '%s'\n", FullPath.c_str()); + delete m_Textures[i]; + m_Textures[i] = NULL; + Ret = false; + }*/ + } + } + if (!textures[i]) { + //textures[i] = new Texture(GL_TEXTURE_2D, "../Content/white.png"); + //Ret = textures[i]->Load(); + } + } + // return Ret; + return true; } diff --git a/bazaar/SurfaceCtrl/Object3D.h b/bazaar/SurfaceCtrl/Object3D.h index a354725c1..1bb68dffd 100644 --- a/bazaar/SurfaceCtrl/Object3D.h +++ b/bazaar/SurfaceCtrl/Object3D.h @@ -45,6 +45,7 @@ class Object3D : public Upp::Moveable{ int ID; Vector meshes; + Vector textures; //Vector carrying all texture of the object, every meshes refer to it via one iterator bool loaded = false; bool moved = false;