From c56289dbfd590db685ad4dd3a04f84a14d0f183c Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 4 Mar 2013 21:53:43 +0100 Subject: [PATCH] [DEV] Add calculation of the normal and the vertex normal for mesh --- sources/ewol/renderer/resources/Mesh.cpp | 57 ++++++++++++++++++++++-- sources/ewol/renderer/resources/Mesh.h | 20 +++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/sources/ewol/renderer/resources/Mesh.cpp b/sources/ewol/renderer/resources/Mesh.cpp index 344d76e6..4808271a 100644 --- a/sources/ewol/renderer/resources/Mesh.cpp +++ b/sources/ewol/renderer/resources/Mesh.cpp @@ -69,6 +69,8 @@ class VertexNode { ewol::Mesh::Mesh(etk::UString genName) : ewol::Resource(genName), + m_enableFaceNormal(false), + m_enableVertexNormal(false), m_numberOfElments(0), m_texture1(NULL) { @@ -81,7 +83,8 @@ ewol::Mesh::Mesh(etk::UString genName) : m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLtexID = m_GLprogram->GetUniform("EW_texID"); } - ewol::resource::Keep("w", m_verticesVBO); + // this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer + ewol::resource::Keep("w-fff", m_verticesVBO); } ewol::Mesh::~Mesh(void) @@ -129,6 +132,49 @@ void ewol::Mesh::Draw(mat4& positionMatrix) glDisable(GL_DEPTH_TEST); glBindBuffer(GL_ARRAY_BUFFER,0); } +// normal calculation of the normal face is really easy : +void ewol::Mesh::CalculateNormaleFace(void) +{ + m_listFacesNormal.Clear(); + // TODO : Preallocation of the vertex : + + if( true==m_enableFaceNormal + || true==m_enableVertexNormal) { + for(int32_t iii=0 ; iii Update middle edge points position"); + //EWOL_DEBUG(" ==> Update middle edge points position"); // reposition the Middle point of the edge for(int32_t iii=0; iii Update old points position"); + //EWOL_DEBUG(" ==> Update old points position"); /* Formule de calcule : - calculate F the barycenter of k Face center nearest @@ -504,9 +553,11 @@ void ewol::Mesh::InternalSubdivide(bool smooth) EWOL_WARNING("Case not coded, result not predictible ..."); } else { vec3 newPos = (val_F + 2*val_R + (countFace-3)*val_P)/countFace; + /* if (newPos != val_P) { EWOL_DEBUG("update position : " << newPos << " <== " << val_P << " count=" << countFace); } + */ // update the position : listVertex[iii]->SetPos(newPos); } diff --git a/sources/ewol/renderer/resources/Mesh.h b/sources/ewol/renderer/resources/Mesh.h index 2ab95b6d..df7a220c 100644 --- a/sources/ewol/renderer/resources/Mesh.h +++ b/sources/ewol/renderer/resources/Mesh.h @@ -56,6 +56,9 @@ namespace ewol }; class Mesh : public ewol::Resource { + private: + bool m_enableFaceNormal; + bool m_enableVertexNormal; protected: ewol::Program* m_GLprogram; int32_t m_GLPosition; @@ -66,8 +69,10 @@ namespace ewol int32_t m_numberOfElments; protected: etk::Vector m_listVertex; //!< List of all vertex in the element - etk::Vector m_listUV; //!< List of all UV point in the mesh (for the specify texture) - etk::Vector m_listFaces; //!< List of all Face for the mesh + etk::Vector m_listUV; //!< List of all UV point in the mesh (for the specify texture) + etk::Vector m_listFaces; //!< List of all Face for the mesh + etk::Vector m_listFacesNormal; //!< List of all Face normal, when calculated + etk::Vector m_listVertexNormal; //!< List of all Face normal, when calculated protected: ewol::VirtualBufferObject* m_verticesVBO; ewol::TextureFile* m_texture1; @@ -77,7 +82,6 @@ namespace ewol virtual const char* GetType(void) { return "ewol::Mesh"; }; virtual void Draw(mat4& positionMatrix); void GenerateVBO(void); - public: // some addition basic funtion that permit to create or overwrite some caracterstics : void CreateCube(void); @@ -85,6 +89,16 @@ namespace ewol void Subdivide(int32_t numberOfTime, bool smooth); protected: void InternalSubdivide(bool smooth); + public: + void StatusFaceNormal(bool newState) { + m_enableFaceNormal = newState; + } + void StatusVertexNormal(bool newState) { + m_enableVertexNormal = newState; + } + private: + void CalculateNormaleFace(void); + void CalculateNormaleEdge(void); }; };