[DEV] change the mesh properties and add a basic subdivider
This commit is contained in:
parent
c53664d973
commit
71aefe981c
@ -15,7 +15,6 @@ varying vec2 f_texcoord;
|
|||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
|
gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
|
||||||
//gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0);
|
|
||||||
// set texture output coord
|
// set texture output coord
|
||||||
f_texcoord = EW_texture2d;
|
f_texcoord = EW_texture2d;
|
||||||
// set output color :
|
// set output color :
|
||||||
|
@ -14,7 +14,6 @@ varying vec2 f_texcoord;
|
|||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
|
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
|
||||||
//gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord3d, 1.0);
|
|
||||||
// set texture output coord
|
// set texture output coord
|
||||||
f_texcoord = EW_texture2d;
|
f_texcoord = EW_texture2d;
|
||||||
// set output color :
|
// set output color :
|
||||||
|
@ -10,5 +10,4 @@ varying vec2 f_texcoord;
|
|||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
gl_FragColor = texture2D(EW_texID, f_texcoord);
|
gl_FragColor = texture2D(EW_texID, f_texcoord);
|
||||||
//gl_FragColor = vec4(1.0,1.0,0.2,0.6);
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ varying vec2 f_texcoord;
|
|||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
|
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
|
||||||
//gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord3d, 1.0);
|
|
||||||
// set texture output coord
|
// set texture output coord
|
||||||
f_texcoord = EW_texture2d;
|
f_texcoord = EW_texture2d;
|
||||||
}
|
}
|
||||||
|
2
external/etk
vendored
2
external/etk
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 951a94c0d9cb72b558f0152e76dd44c2b2818791
|
Subproject commit 79fdf1119cf3edf34d842ff26a840c2677adbdfa
|
@ -310,6 +310,7 @@ bool ewol::resource::Keep(const etk::UString& filename, ewol::TextureFile*& obje
|
|||||||
if (NULL != object) {
|
if (NULL != object) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
EWOL_INFO(" ==> create new one...");
|
||||||
// need to crate a new one ...
|
// need to crate a new one ...
|
||||||
object = new ewol::TextureFile(TmpFilename, filename, size2);
|
object = new ewol::TextureFile(TmpFilename, filename, size2);
|
||||||
if (NULL == object) {
|
if (NULL == object) {
|
||||||
@ -328,7 +329,23 @@ bool ewol::resource::Keep(const etk::UString& filename, ewol::MeshObj*& object)
|
|||||||
}
|
}
|
||||||
object = new ewol::MeshObj(filename);
|
object = new ewol::MeshObj(filename);
|
||||||
if (NULL == object) {
|
if (NULL == object) {
|
||||||
EWOL_ERROR("allocation error of a resource : ??Mesh.obj??");
|
EWOL_ERROR("allocation error of a resource : ??Mesh.obj??" << filename);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LocalAdd(object);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ewol::resource::Keep(const etk::UString& meshName, ewol::Mesh*& object)
|
||||||
|
{
|
||||||
|
object = static_cast<ewol::Mesh*>(LocalKeep(meshName));
|
||||||
|
if (NULL != object) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
object = new ewol::Mesh(meshName);
|
||||||
|
if (NULL == object) {
|
||||||
|
EWOL_ERROR("allocation error of a resource : ??Mesh??" << meshName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LocalAdd(object);
|
LocalAdd(object);
|
||||||
@ -434,6 +451,7 @@ void ewol::resource::Release(ewol::Texture*& object)
|
|||||||
void ewol::resource::Release(ewol::TextureFile*& object)
|
void ewol::resource::Release(ewol::TextureFile*& object)
|
||||||
{
|
{
|
||||||
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
|
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
|
||||||
|
//EWOL_INFO("RELEASE : TextureFile : nb=" << object2->GetCounter());
|
||||||
Release(object2);
|
Release(object2);
|
||||||
object = NULL;
|
object = NULL;
|
||||||
}
|
}
|
||||||
@ -445,6 +463,13 @@ void ewol::resource::Release(ewol::MeshObj*& object)
|
|||||||
object = NULL;
|
object = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ewol::resource::Release(ewol::Mesh*& object)
|
||||||
|
{
|
||||||
|
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
|
||||||
|
Release(object2);
|
||||||
|
object = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void ewol::resource::Release(ewol::ConfigFile*& object)
|
void ewol::resource::Release(ewol::ConfigFile*& object)
|
||||||
{
|
{
|
||||||
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
|
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
|
||||||
|
@ -74,6 +74,7 @@ namespace ewol
|
|||||||
bool Keep(const etk::UString& filename, ewol::TextureFile*& object, ivec2 size);
|
bool Keep(const etk::UString& filename, ewol::TextureFile*& object, ivec2 size);
|
||||||
bool Keep(const etk::UString& accesMode, ewol::VirtualBufferObject*& object);
|
bool Keep(const etk::UString& accesMode, ewol::VirtualBufferObject*& object);
|
||||||
bool Keep(const etk::UString& filename, ewol::MeshObj*& object);
|
bool Keep(const etk::UString& filename, ewol::MeshObj*& object);
|
||||||
|
bool Keep(const etk::UString& meshName, ewol::Mesh*& object);
|
||||||
bool Keep(const etk::UString& filename, ewol::ConfigFile*& object);
|
bool Keep(const etk::UString& filename, ewol::ConfigFile*& object);
|
||||||
bool Keep(ewol::Colored3DObject*& object);
|
bool Keep(ewol::Colored3DObject*& object);
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ namespace ewol
|
|||||||
void Release(ewol::TextureFile*& object);
|
void Release(ewol::TextureFile*& object);
|
||||||
void Release(ewol::VirtualBufferObject*& object);
|
void Release(ewol::VirtualBufferObject*& object);
|
||||||
void Release(ewol::MeshObj*& object);
|
void Release(ewol::MeshObj*& object);
|
||||||
|
void Release(ewol::Mesh*& object);
|
||||||
void Release(ewol::ConfigFile*& object);
|
void Release(ewol::ConfigFile*& object);
|
||||||
void Release(ewol::Colored3DObject*& object);
|
void Release(ewol::Colored3DObject*& object);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,16 @@
|
|||||||
#include <ewol/renderer/ResourceManager.h>
|
#include <ewol/renderer/ResourceManager.h>
|
||||||
|
|
||||||
|
|
||||||
|
// 3 "float" elements
|
||||||
|
#define MESH_VBO_VERTICES (0)
|
||||||
|
// 2 "float" elements
|
||||||
|
#define MESH_VBO_TEXTURE (1)
|
||||||
|
// 4 "float" elements
|
||||||
|
#define MESH_VBO_COLOR (2)
|
||||||
|
// 3 "float" elements
|
||||||
|
#define MESH_VBO_NORMAL (3)
|
||||||
|
|
||||||
|
|
||||||
ewol::Mesh::Mesh(etk::UString genName) :
|
ewol::Mesh::Mesh(etk::UString genName) :
|
||||||
ewol::Resource(genName),
|
ewol::Resource(genName),
|
||||||
m_numberOfElments(0),
|
m_numberOfElments(0),
|
||||||
@ -21,7 +31,6 @@ ewol::Mesh::Mesh(etk::UString genName) :
|
|||||||
m_GLPosition = 0;
|
m_GLPosition = 0;
|
||||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||||
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
|
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
|
||||||
// m_GLColor = m_GLprogram->GetAttribute("EW_color");
|
|
||||||
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
|
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
|
||||||
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
|
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
|
||||||
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
|
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
|
||||||
@ -65,11 +74,9 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
|
|||||||
// TextureID
|
// TextureID
|
||||||
m_GLprogram->SetTexture0(m_GLtexID, m_texture1->GetId());
|
m_GLprogram->SetTexture0(m_GLtexID, m_texture1->GetId());
|
||||||
// position :
|
// position :
|
||||||
m_GLprogram->SendAttributePointer(m_GLPosition, 3/*x,y,z*/, m_verticesVBO, 0);
|
m_GLprogram->SendAttributePointer(m_GLPosition, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES);
|
||||||
// Texture :
|
// Texture :
|
||||||
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, 1);
|
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE);
|
||||||
// color :
|
|
||||||
//m_GLprogram->SendAttributePointer(m_GLColor, 4/*r,g,b,a*/, m_verticesVBO, 2);
|
|
||||||
// Request the draw od the elements :
|
// Request the draw od the elements :
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_numberOfElments);
|
glDrawArrays(GL_TRIANGLES, 0, m_numberOfElments);
|
||||||
m_GLprogram->UnUse();
|
m_GLprogram->UnUse();
|
||||||
@ -77,70 +84,287 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER,0);
|
glBindBuffer(GL_ARRAY_BUFFER,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for debugging ...
|
||||||
|
//#define PRINT_HALF (1)
|
||||||
|
|
||||||
void ewol::Mesh::GenerateVBO(void)
|
void ewol::Mesh::GenerateVBO(void)
|
||||||
{
|
{
|
||||||
m_numberOfElments = 0;
|
m_numberOfElments = 0;
|
||||||
// TODO : Set a better display system, this one is the worst I known ...
|
// TODO : Set a better display system, this one is the worst I known ...
|
||||||
for (int32_t iii=0; iii<m_listFaces.Size() ; iii++) {
|
for (int32_t iii=0; iii<m_listFaces.Size() ; iii++) {
|
||||||
m_numberOfElments += m_listFaces[iii].m_nbElement;
|
#ifdef PRINT_HALF
|
||||||
|
m_numberOfElments += 3*3;
|
||||||
|
#else
|
||||||
|
m_numberOfElments += m_listFaces[iii].m_nbElement*3;
|
||||||
|
#endif
|
||||||
// 2 possibilities : triangle or quad :
|
// 2 possibilities : triangle or quad :
|
||||||
int32_t indice = 0;
|
int32_t indice = 0;
|
||||||
vec3 tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
vec3 tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
||||||
vec2 tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
vec2 tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.x());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.y());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.z());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.z());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(tmpUV.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(tmpUV.x());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(1.0f-tmpUV.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(1.0f-tmpUV.y());
|
||||||
|
|
||||||
indice = 1;
|
indice = 1;
|
||||||
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.x());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.y());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.z());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.z());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(tmpUV.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(tmpUV.x());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(1.0f-tmpUV.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(1.0f-tmpUV.y());
|
||||||
|
|
||||||
indice = 2;
|
indice = 2;
|
||||||
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.x());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.y());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.z());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.z());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(tmpUV.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(tmpUV.x());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(1.0f-tmpUV.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(1.0f-tmpUV.y());
|
||||||
|
#ifndef PRINT_HALF
|
||||||
if (m_listFaces[iii].m_nbElement==4) {
|
if (m_listFaces[iii].m_nbElement==4) {
|
||||||
indice = 0;
|
indice = 0;
|
||||||
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.x());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.y());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.z());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.z());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(tmpUV.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(tmpUV.x());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(1.0f-tmpUV.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(1.0f-tmpUV.y());
|
||||||
|
|
||||||
indice = 2;
|
indice = 2;
|
||||||
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.x());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.y());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.z());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.z());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(tmpUV.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(tmpUV.x());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(1.0f-tmpUV.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(1.0f-tmpUV.y());
|
||||||
|
|
||||||
indice = 3;
|
indice = 3;
|
||||||
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
tmpPos = m_listVertex[m_listFaces[iii].m_vertex[indice]];
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.x());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.y());
|
||||||
m_verticesVBO->GetRefBuffer(0).PushBack(tmpPos.z());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_VERTICES).PushBack(tmpPos.z());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(tmpUV.x());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(tmpUV.x());
|
||||||
m_verticesVBO->GetRefBuffer(1).PushBack(1.0f-tmpUV.y());
|
m_verticesVBO->GetRefBuffer(MESH_VBO_TEXTURE).PushBack(1.0f-tmpUV.y());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// update all the VBO elements ...
|
// update all the VBO elements ...
|
||||||
m_verticesVBO->Flush();
|
m_verticesVBO->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ewol::Mesh::CreateCube(void)
|
||||||
|
{
|
||||||
|
m_listVertex.Clear();
|
||||||
|
m_listUV.Clear();
|
||||||
|
m_listFaces.Clear();
|
||||||
|
m_numberOfElments = 0;
|
||||||
|
// This is the direct generation basis on the .obj system
|
||||||
|
/*
|
||||||
|
5 6
|
||||||
|
o---------------------o
|
||||||
|
/. /|
|
||||||
|
/ . / |
|
||||||
|
/ . / |
|
||||||
|
/ . / |
|
||||||
|
/ . / |
|
||||||
|
4 / . / |
|
||||||
|
o---------------------o |
|
||||||
|
| . |7 |
|
||||||
|
| . | |
|
||||||
|
| . | |
|
||||||
|
| . | |
|
||||||
|
| o..............|......o
|
||||||
|
| . 1 | / 2
|
||||||
|
| . | /
|
||||||
|
| . | /
|
||||||
|
| . | /
|
||||||
|
| . | /
|
||||||
|
|. |/
|
||||||
|
o---------------------o
|
||||||
|
0 3
|
||||||
|
*/
|
||||||
|
m_listVertex.PushBack(vec3( 1.0, -1.0, -1.0)); // 0
|
||||||
|
m_listVertex.PushBack(vec3( 1.0, -1.0, 1.0)); // 1
|
||||||
|
m_listVertex.PushBack(vec3(-1.0, -1.0, 1.0)); // 2
|
||||||
|
m_listVertex.PushBack(vec3(-1.0, -1.0, -1.0)); // 3
|
||||||
|
m_listVertex.PushBack(vec3( 1.0, 1.0, -1.0)); // 4
|
||||||
|
m_listVertex.PushBack(vec3( 1.0, 1.0, 1.0)); // 5
|
||||||
|
m_listVertex.PushBack(vec3(-1.0, 1.0, 1.0)); // 6
|
||||||
|
m_listVertex.PushBack(vec3(-1.0, 1.0, -1.0)); // 7
|
||||||
|
|
||||||
|
m_listUV.PushBack(vec2(0.0, 0.0));
|
||||||
|
m_listUV.PushBack(vec2(1.0, 0.0));
|
||||||
|
m_listUV.PushBack(vec2(1.0, 1.0));
|
||||||
|
m_listUV.PushBack(vec2(0.0, 1.0));
|
||||||
|
|
||||||
|
m_listFaces.PushBack(Face(0,0, 1,1, 2,2, 3,3));
|
||||||
|
m_listFaces.PushBack(Face(4,0, 0,1, 3,2, 7,3));
|
||||||
|
m_listFaces.PushBack(Face(2,0, 6,1, 7,2, 3,3));
|
||||||
|
m_listFaces.PushBack(Face(4,0, 7,1, 6,2, 5,3));
|
||||||
|
m_listFaces.PushBack(Face(1,0, 5,1, 6,2, 2,3));
|
||||||
|
m_listFaces.PushBack(Face(0,0, 4,1, 5,2, 1,3));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::Mesh::SetTexture(const etk::UString& myTexture)
|
||||||
|
{
|
||||||
|
ivec2 tmpSize(256, 256);
|
||||||
|
// prevent overloard error :
|
||||||
|
ewol::TextureFile* tmpCopy = m_texture1;
|
||||||
|
m_texture1 = NULL;
|
||||||
|
if (false == ewol::resource::Keep(myTexture, m_texture1, tmpSize)) {
|
||||||
|
EWOL_ERROR("Can not load specific texture : " << myTexture);
|
||||||
|
// retreave previous texture:
|
||||||
|
m_texture1 = tmpCopy;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NULL != tmpCopy) {
|
||||||
|
// really release previous texture. In case of same texture loading, then we did not have reload it .. just increase and decrease index...
|
||||||
|
ewol::resource::Release(tmpCopy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::Mesh::Subdivide(int32_t numberOfTime, bool smooth)
|
||||||
|
{
|
||||||
|
for(int32_t iii=0; iii<numberOfTime ; iii++) {
|
||||||
|
InternalSubdivide(smooth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t CreateOrGetNewPointId(const vec3& point, etk::Vector<vec3>& list)
|
||||||
|
{
|
||||||
|
for (int32_t iii=0; iii<list.Size(); iii++) {
|
||||||
|
if (list[iii] == point) {
|
||||||
|
return iii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.PushBack(point);
|
||||||
|
return list.Size()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t CreateOrGetNewTexId(const vec2& point, etk::Vector<vec2>& list)
|
||||||
|
{
|
||||||
|
for (int32_t iii=0; iii<list.Size(); iii++) {
|
||||||
|
if (list[iii] == point) {
|
||||||
|
return iii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.PushBack(point);
|
||||||
|
return list.Size()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::Mesh::InternalSubdivide(bool smooth)
|
||||||
|
{
|
||||||
|
//Copy the mesh for modify this one and not his parrent (that one is needed for smoothing)
|
||||||
|
etk::Vector<vec3> listVertex(m_listVertex);
|
||||||
|
etk::Vector<vec2> listUV(m_listUV);
|
||||||
|
etk::Vector<Face> listFaces; // no face here ...
|
||||||
|
etk::Vector<int32_t> listElementHalfPoint(16);// preallocate at 16..
|
||||||
|
etk::Vector<int32_t> listElementHalfUV(16);// preallocate at 16..
|
||||||
|
|
||||||
|
for (int32_t iii=0; iii<m_listFaces.Size() ; iii++) {
|
||||||
|
vec3 centerPoint;
|
||||||
|
vec2 centerTex;
|
||||||
|
if (3==m_listFaces[iii].m_nbElement) {
|
||||||
|
// create the center point:
|
||||||
|
centerPoint = ( m_listVertex[m_listFaces[iii].m_vertex[0]]
|
||||||
|
+ m_listVertex[m_listFaces[iii].m_vertex[1]]
|
||||||
|
+ m_listVertex[m_listFaces[iii].m_vertex[2]] ) / vec3(3,3,3);
|
||||||
|
// create the center Texture coord:
|
||||||
|
centerTex = ( listUV[m_listFaces[iii].m_uv[0]]
|
||||||
|
+ listUV[m_listFaces[iii].m_uv[1]]
|
||||||
|
+ listUV[m_listFaces[iii].m_uv[2]] ) / vec2(3,3);
|
||||||
|
/*
|
||||||
|
|
||||||
|
o o
|
||||||
|
/ \ / \
|
||||||
|
/ \ / \
|
||||||
|
/ \ / \
|
||||||
|
/ \ / \
|
||||||
|
/ \ ==> o.. ..o
|
||||||
|
/ \ / ''o'' \
|
||||||
|
/ \ / | \
|
||||||
|
/ \ / | \
|
||||||
|
/ \ / | \
|
||||||
|
o-------------------o o---------o---------o
|
||||||
|
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
// create the center point:
|
||||||
|
centerPoint = ( m_listVertex[m_listFaces[iii].m_vertex[0]]
|
||||||
|
+ m_listVertex[m_listFaces[iii].m_vertex[1]]
|
||||||
|
+ m_listVertex[m_listFaces[iii].m_vertex[2]]
|
||||||
|
+ m_listVertex[m_listFaces[iii].m_vertex[3]] ) / vec3(4,4,4);
|
||||||
|
// create the center Texture coord:
|
||||||
|
centerTex = ( listUV[m_listFaces[iii].m_uv[0]]
|
||||||
|
+ listUV[m_listFaces[iii].m_uv[1]]
|
||||||
|
+ listUV[m_listFaces[iii].m_uv[2]]
|
||||||
|
+ listUV[m_listFaces[iii].m_uv[3]] ) / vec2(4,4);
|
||||||
|
/*
|
||||||
|
|
||||||
|
o---------------------o o----------o----------o
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | ==> o----------o----------o
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
| | | | |
|
||||||
|
o---------------------o o----------o----------o
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t newCenterVertexID = CreateOrGetNewPointId(centerPoint, listVertex);
|
||||||
|
int32_t newCenterTexID = CreateOrGetNewTexId(centerTex, listUV);
|
||||||
|
|
||||||
|
listElementHalfPoint.Clear();
|
||||||
|
listElementHalfUV.Clear();
|
||||||
|
// generate list f the forder elements
|
||||||
|
for (int32_t jjj=0; jjj<m_listFaces[iii].m_nbElement ; jjj++) {
|
||||||
|
// for the last element finding at the good position...
|
||||||
|
int32_t cyclicID = (jjj+1) % m_listFaces[iii].m_nbElement;
|
||||||
|
|
||||||
|
listElementHalfPoint.PushBack(m_listFaces[iii].m_vertex[jjj]);
|
||||||
|
listElementHalfUV.PushBack(m_listFaces[iii].m_uv[jjj]);
|
||||||
|
// calculate and add middle point :
|
||||||
|
vec3 middlePoint = ( m_listVertex[m_listFaces[iii].m_vertex[jjj]]
|
||||||
|
+ m_listVertex[m_listFaces[iii].m_vertex[cyclicID]] ) / 2.0f;
|
||||||
|
int32_t newMiddleVertexID = CreateOrGetNewPointId(middlePoint, listVertex);
|
||||||
|
listElementHalfPoint.PushBack(newMiddleVertexID);
|
||||||
|
// create the center Texture coord:
|
||||||
|
vec2 middleTex = ( listUV[m_listFaces[iii].m_uv[jjj]]
|
||||||
|
+ listUV[m_listFaces[iii].m_uv[cyclicID]]) / 2.0f;
|
||||||
|
int32_t newMiddleTexID = CreateOrGetNewTexId(middleTex, listUV);
|
||||||
|
listElementHalfUV.PushBack(newMiddleTexID);
|
||||||
|
}
|
||||||
|
// generate faces:
|
||||||
|
for (int32_t jjj=0; jjj<listElementHalfPoint.Size() ; jjj+=2) {
|
||||||
|
int32_t cyclicID = (jjj-1 + listElementHalfPoint.Size()) % listElementHalfPoint.Size();
|
||||||
|
listFaces.PushBack(Face(listElementHalfPoint[jjj], listElementHalfUV[jjj],
|
||||||
|
listElementHalfPoint[jjj+1], listElementHalfUV[jjj+1],
|
||||||
|
newCenterVertexID, newCenterTexID,
|
||||||
|
listElementHalfPoint[cyclicID], listElementHalfUV[cyclicID]) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO SMOOTH :
|
||||||
|
if (true==smooth) {
|
||||||
|
|
||||||
|
}
|
||||||
|
// copy all the element in the internal structure :
|
||||||
|
m_listVertex = listVertex;
|
||||||
|
m_listUV = listUV;
|
||||||
|
m_listFaces = listFaces;
|
||||||
|
}
|
||||||
|
@ -27,38 +27,50 @@ namespace ewol
|
|||||||
int32_t m_nbElement;
|
int32_t m_nbElement;
|
||||||
int32_t m_vertex[4];
|
int32_t m_vertex[4];
|
||||||
int32_t m_uv[4];
|
int32_t m_uv[4];
|
||||||
|
public:
|
||||||
|
Face(void) {};
|
||||||
|
Face(int32_t v1, int32_t t1,
|
||||||
|
int32_t v2, int32_t t2,
|
||||||
|
int32_t v3, int32_t t3)
|
||||||
|
{
|
||||||
|
m_nbElement = 3;
|
||||||
|
m_vertex[0] = v1;
|
||||||
|
m_uv[0] = t1;
|
||||||
|
m_vertex[1] = v2;
|
||||||
|
m_uv[1] = t2;
|
||||||
|
m_vertex[2] = v3;
|
||||||
|
m_uv[2] = t3;
|
||||||
|
};
|
||||||
|
Face(int32_t v1, int32_t t1,
|
||||||
|
int32_t v2, int32_t t2,
|
||||||
|
int32_t v3, int32_t t3,
|
||||||
|
int32_t v4, int32_t t4)
|
||||||
|
{
|
||||||
|
m_nbElement = 4;
|
||||||
|
m_vertex[0] = v1;
|
||||||
|
m_uv[0] = t1;
|
||||||
|
m_vertex[1] = v2;
|
||||||
|
m_uv[1] = t2;
|
||||||
|
m_vertex[2] = v3;
|
||||||
|
m_uv[2] = t3;
|
||||||
|
m_vertex[3] = v4;
|
||||||
|
m_uv[3] = t4;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
class Mesh : public ewol::Resource
|
class Mesh : public ewol::Resource
|
||||||
{
|
{
|
||||||
// 3 "float" elements
|
|
||||||
#define MESH_VBO_VERTICES (0)
|
|
||||||
// 2 "float" elements
|
|
||||||
#define MESH_VBO_TEXTURE (1)
|
|
||||||
// 4 "float" elements
|
|
||||||
#define MESH_VBO_COLOR (2)
|
|
||||||
// 3 "float" elements
|
|
||||||
#define MESH_VBO_NORMAL (3)
|
|
||||||
// TODO : Use indice system ...
|
|
||||||
protected:
|
protected:
|
||||||
ewol::Program* m_GLprogram;
|
ewol::Program* m_GLprogram;
|
||||||
int32_t m_GLPosition;
|
int32_t m_GLPosition;
|
||||||
int32_t m_GLMatrix;
|
int32_t m_GLMatrix;
|
||||||
int32_t m_GLColor;
|
|
||||||
int32_t m_GLtexture;
|
int32_t m_GLtexture;
|
||||||
int32_t m_GLtexID;
|
int32_t m_GLtexID;
|
||||||
int32_t m_bufferOfset;
|
int32_t m_bufferOfset;
|
||||||
int32_t m_numberOfElments;
|
int32_t m_numberOfElments;
|
||||||
protected:
|
protected:
|
||||||
etk::Vector<vec3> m_listVertex;
|
etk::Vector<vec3> m_listVertex; //!< List of all vertex in the element
|
||||||
etk::Vector<vec2> m_listUV;
|
etk::Vector<vec2> m_listUV; //!< List of all UV point in the mesh (for the specify texture)
|
||||||
etk::Vector<Face> m_listFaces;
|
etk::Vector<Face> m_listFaces; //!< List of all Face for the mesh
|
||||||
|
|
||||||
public: // For display storage : (not really usable for mathématical division and other ...
|
|
||||||
etk::Vector<uint32_t> m_indices;
|
|
||||||
etk::Vector<vec3> m_vertices;
|
|
||||||
etk::Vector<vec2> m_uvTextures;
|
|
||||||
etk::Vector<vec3> m_normals;
|
|
||||||
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
|
|
||||||
protected:
|
protected:
|
||||||
ewol::VirtualBufferObject* m_verticesVBO;
|
ewol::VirtualBufferObject* m_verticesVBO;
|
||||||
ewol::TextureFile* m_texture1;
|
ewol::TextureFile* m_texture1;
|
||||||
@ -69,6 +81,13 @@ namespace ewol
|
|||||||
virtual void Draw(mat4& positionMatrix);
|
virtual void Draw(mat4& positionMatrix);
|
||||||
void GenerateVBO(void);
|
void GenerateVBO(void);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// some addition basic funtion that permit to create or overwrite some caracterstics :
|
||||||
|
void CreateCube(void);
|
||||||
|
void SetTexture(const etk::UString& myTexture);
|
||||||
|
void Subdivide(int32_t numberOfTime, bool smooth);
|
||||||
|
protected:
|
||||||
|
void InternalSubdivide(bool smooth);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,20 +85,21 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Face tmpFace;
|
|
||||||
tmpFace.m_nbElement = 3;
|
|
||||||
tmpFace.m_vertex[0] = vertexIndex[0];
|
|
||||||
tmpFace.m_uv[0] = uvIndex[0];
|
|
||||||
tmpFace.m_vertex[1] = vertexIndex[1];
|
|
||||||
tmpFace.m_uv[1] = uvIndex[1];
|
|
||||||
tmpFace.m_vertex[2] = vertexIndex[2];
|
|
||||||
tmpFace.m_uv[2] = uvIndex[2];
|
|
||||||
if (true==quadMode) {
|
if (true==quadMode) {
|
||||||
tmpFace.m_nbElement++;
|
m_listFaces.PushBack(Face(vertexIndex[0]-1, uvIndex[0]-1,
|
||||||
tmpFace.m_vertex[3] = vertexIndex[3];
|
vertexIndex[1]-1, uvIndex[1]-1,
|
||||||
tmpFace.m_uv[3] = uvIndex[3];
|
vertexIndex[2]-1, uvIndex[2]-1,
|
||||||
|
vertexIndex[3]-1, uvIndex[3]-1));
|
||||||
|
} else {
|
||||||
|
m_listFaces.PushBack(Face(vertexIndex[0]-1, uvIndex[0]-1,
|
||||||
|
vertexIndex[1]-1, uvIndex[1]-1,
|
||||||
|
vertexIndex[2]-1, uvIndex[2]-1));
|
||||||
}
|
}
|
||||||
m_listFaces.PushBack(tmpFace);
|
/*
|
||||||
|
EWOL_DEBUG(" plop : " << tmpFace.m_nbElement << " ? " << m_listFaces[m_listFaces.Size()-1].m_nbElement);
|
||||||
|
EWOL_DEBUG(" : " << tmpFace.m_vertex[0] << " ? " << m_listFaces[m_listFaces.Size()-1].m_vertex[0]);
|
||||||
|
EWOL_DEBUG(" : " << tmpFace.m_uv[0] << " ? " << m_listFaces[m_listFaces.Size()-1].m_uv[0]);
|
||||||
|
*/
|
||||||
} else if (inputDataLine[0]=='s') {
|
} else if (inputDataLine[0]=='s') {
|
||||||
// ??? : s off
|
// ??? : s off
|
||||||
} else if (inputDataLine[0]=='#') {
|
} else if (inputDataLine[0]=='#') {
|
||||||
@ -120,15 +121,7 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
|
|||||||
inputDataLine[strlen(inputDataLine)-1] = '\0';
|
inputDataLine[strlen(inputDataLine)-1] = '\0';
|
||||||
}
|
}
|
||||||
etk::UString tmpVal(&inputDataLine[7]);
|
etk::UString tmpVal(&inputDataLine[7]);
|
||||||
ivec2 tmpSize(256, 256);
|
SetTexture(fileName.GetRelativeFolder() + tmpVal);
|
||||||
if (NULL != m_texture1) {
|
|
||||||
EWOL_INFO("Release previous loaded texture ... ");
|
|
||||||
ewol::resource::Release(m_texture1);
|
|
||||||
}
|
|
||||||
etk::UString tmpFilename = fileName.GetRelativeFolder() + tmpVal;
|
|
||||||
if (false == ewol::resource::Keep(tmpFilename, m_texture1, tmpSize)) {
|
|
||||||
EWOL_ERROR("Can not load specific texture : " << tmpVal);
|
|
||||||
}
|
|
||||||
} else if( inputDataLine[0]=='m'
|
} else if( inputDataLine[0]=='m'
|
||||||
&& inputDataLine[1]=='t'
|
&& inputDataLine[1]=='t'
|
||||||
&& inputDataLine[2]=='l'
|
&& inputDataLine[2]=='l'
|
||||||
|
@ -59,15 +59,15 @@ void ewol::VirtualBufferObject::RemoveContext(void)
|
|||||||
{
|
{
|
||||||
if (true==m_exist) {
|
if (true==m_exist) {
|
||||||
EWOL_INFO("VBO: Remove [" << m_uniqueId << "] OGl_Id=" << m_vbo[0]
|
EWOL_INFO("VBO: Remove [" << m_uniqueId << "] OGl_Id=" << m_vbo[0]
|
||||||
<< "/" << m_vbo[1]
|
<< "/" << m_vbo[1]
|
||||||
<< "/" << m_vbo[2]
|
<< "/" << m_vbo[2]
|
||||||
<< "/" << m_vbo[3]
|
<< "/" << m_vbo[3]
|
||||||
<< "/" << m_vbo[4]
|
<< "/" << m_vbo[4]
|
||||||
<< "/" << m_vbo[5]
|
<< "/" << m_vbo[5]
|
||||||
<< "/" << m_vbo[6]
|
<< "/" << m_vbo[6]
|
||||||
<< "/" << m_vbo[7]
|
<< "/" << m_vbo[7]
|
||||||
<< "/" << m_vbo[8]
|
<< "/" << m_vbo[8]
|
||||||
<< "/" << m_vbo[9]);
|
<< "/" << m_vbo[9]);
|
||||||
glDeleteBuffers(m_nbVBO, m_vbo);
|
glDeleteBuffers(m_nbVBO, m_vbo);
|
||||||
m_exist = false;
|
m_exist = false;
|
||||||
for (int32_t iii=0; iii<NB_VBO_MAX; iii++) {
|
for (int32_t iii=0; iii<NB_VBO_MAX; iii++) {
|
||||||
|
@ -33,7 +33,7 @@ namespace ewol
|
|||||||
* @brief Constructor of this VBO.
|
* @brief Constructor of this VBO.
|
||||||
* @param[in] accesMode Acces mode : ???
|
* @param[in] accesMode Acces mode : ???
|
||||||
*/
|
*/
|
||||||
VirtualBufferObject(const etk::UString& accesMode, int32_t nbElement=4);
|
VirtualBufferObject(const etk::UString& accesMode, int32_t nbElement=2);
|
||||||
/**
|
/**
|
||||||
* @brief Destructor of this VBO.
|
* @brief Destructor of this VBO.
|
||||||
*/
|
*/
|
||||||
|
@ -90,9 +90,9 @@ LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \
|
|||||||
../data/textured3D.frag:textured3D.frag \
|
../data/textured3D.frag:textured3D.frag \
|
||||||
../data/textured3D.vert:textured3D.vert \
|
../data/textured3D.vert:textured3D.vert \
|
||||||
\
|
\
|
||||||
../data/textured3D.prog:textured3D2.prog \
|
../data/textured3D2.prog:textured3D2.prog \
|
||||||
../data/textured3D.frag:textured3D2.frag \
|
../data/textured3D2.frag:textured3D2.frag \
|
||||||
../data/textured3D.vert:textured3D2.vert \
|
../data/textured3D2.vert:textured3D2.vert \
|
||||||
\
|
\
|
||||||
../data/color.prog:color.prog \
|
../data/color.prog:color.prog \
|
||||||
../data/color.frag:color.frag \
|
../data/color.frag:color.frag \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user