[DEV] mesh can be redisplayed (for .emf)
This commit is contained in:
parent
a70ca277e0
commit
aea2495886
@ -34,10 +34,10 @@ void ewol::MaterialGlId::Link(ewol::Program* _prog, const etk::UString& _baseNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
ewol::Material::Material(void) :
|
ewol::Material::Material(void) :
|
||||||
m_ambientFactor(0,0,0,0),
|
m_ambientFactor(1,1,1,1),
|
||||||
m_diffuseFactor(0,0,0,0),
|
m_diffuseFactor(0,0,0,1),
|
||||||
m_specularFactor(0,0,0,0),
|
m_specularFactor(0,0,0,1),
|
||||||
m_shininess(0),
|
m_shininess(1),
|
||||||
m_texture0(NULL)
|
m_texture0(NULL)
|
||||||
{
|
{
|
||||||
// nothing to do else ...
|
// nothing to do else ...
|
||||||
|
@ -38,6 +38,8 @@ namespace ewol
|
|||||||
vec4 m_specularFactor;
|
vec4 m_specularFactor;
|
||||||
float m_shininess;
|
float m_shininess;
|
||||||
ewol::TextureFile* m_texture0;
|
ewol::TextureFile* m_texture0;
|
||||||
|
public:
|
||||||
|
etk::Vector<uint32_t> m_listIndexFaces;
|
||||||
public:
|
public:
|
||||||
Material(void);
|
Material(void);
|
||||||
~Material(void);
|
~Material(void);
|
||||||
@ -55,6 +57,12 @@ namespace ewol
|
|||||||
m_shininess = _val;
|
m_shininess = _val;
|
||||||
}
|
}
|
||||||
void SetTexture0(const etk::UString& _filename);
|
void SetTexture0(const etk::UString& _filename);
|
||||||
|
|
||||||
|
void SetImageSize(const ivec2& _newSize) { if (m_texture0==NULL){return;} m_texture0->SetImageSize(_newSize); };
|
||||||
|
// get the reference on this image to draw nomething on it ...
|
||||||
|
egami::Image* Get(void) { if (m_texture0==NULL){return NULL;} return &m_texture0->Get(); };
|
||||||
|
// Flush the data to send it at the OpenGl system
|
||||||
|
void Flush(void) { if (m_texture0==NULL){return;} m_texture0->Flush(); };
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -265,34 +265,34 @@ bool ewol::resource::Keep(ewol::Texture*& object)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ewol::resource::Keep(ewol::Colored3DObject*& object)
|
bool ewol::resource::Keep(ewol::Colored3DObject*& _object)
|
||||||
{
|
{
|
||||||
EWOL_VERBOSE("KEEP : direct Colored3DObject");
|
EWOL_VERBOSE("KEEP : direct Colored3DObject");
|
||||||
etk::UString filename = "?metaObject?Colored3DObject";
|
etk::UString filename = "?metaObject?Colored3DObject";
|
||||||
object = static_cast<ewol::Colored3DObject*>(LocalKeep(filename));
|
_object = static_cast<ewol::Colored3DObject*>(LocalKeep(filename));
|
||||||
if (NULL != object) {
|
if (NULL != _object) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// need to crate a new one ...
|
// need to crate a new one ...
|
||||||
object = new ewol::Colored3DObject(filename);
|
_object = new ewol::Colored3DObject(filename);
|
||||||
if (NULL == object) {
|
if (NULL == _object) {
|
||||||
EWOL_ERROR("allocation error of a resource : Colored3DObject ");
|
EWOL_ERROR("allocation error of a resource : Colored3DObject ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LocalAdd(object);
|
LocalAdd(_object);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#ifdef __TARGET_OS__Android
|
#ifdef __TARGET_OS__Android
|
||||||
/**
|
/**
|
||||||
* @brief get the next power 2 if the input
|
* @brief get the next power 2 if the input
|
||||||
* @param[in] value Value that we want the next power of 2
|
* @param[in] _value Value that we want the next power of 2
|
||||||
* @return result value
|
* @return result value
|
||||||
*/
|
*/
|
||||||
static int32_t nextP2(int32_t value)
|
static int32_t nextP2(int32_t _value)
|
||||||
{
|
{
|
||||||
int32_t val=1;
|
int32_t val=1;
|
||||||
for (int32_t iii=1; iii<31; iii++) {
|
for (int32_t iii=1; iii<31; iii++) {
|
||||||
if (value <= val) {
|
if (_value <= val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
val *=2;
|
val *=2;
|
||||||
@ -305,6 +305,15 @@ static int32_t nextP2(int32_t value)
|
|||||||
bool ewol::resource::Keep(const etk::UString& _filename, ewol::TextureFile*& _object, ivec2 _size)
|
bool ewol::resource::Keep(const etk::UString& _filename, ewol::TextureFile*& _object, ivec2 _size)
|
||||||
{
|
{
|
||||||
EWOL_INFO("KEEP : TextureFile : file : " << _filename << " basic size=" << _size);
|
EWOL_INFO("KEEP : TextureFile : file : " << _filename << " basic size=" << _size);
|
||||||
|
if (_filename == "") {
|
||||||
|
_object = new ewol::TextureFile("");
|
||||||
|
if (NULL == _object) {
|
||||||
|
EWOL_ERROR("allocation error of a resource : ??TEX??");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LocalAdd(_object);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (_size.x()==0) {
|
if (_size.x()==0) {
|
||||||
_size.setX(-1);
|
_size.setX(-1);
|
||||||
//EWOL_ERROR("Error Request the image size.x() =0 ???");
|
//EWOL_ERROR("Error Request the image size.x() =0 ???");
|
||||||
|
@ -81,6 +81,23 @@ namespace ewol
|
|||||||
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);
|
||||||
|
|
||||||
|
// must became :
|
||||||
|
/*
|
||||||
|
ewol::Font* KeepFont(const etk::UString& _filename);
|
||||||
|
ewol::Program* KeepProgram(const etk::UString& _filename);
|
||||||
|
ewol::Shader* KeepShader(const etk::UString& _filename);
|
||||||
|
ewol::Texture* KeepTexture(void);
|
||||||
|
ewol::Texture* KeepTexture(const etk::UString& _filename, const ivec2& size=ivec2(-1,-1));
|
||||||
|
void AddTextureResourceCreator(pf* _plop, const etk::UString& _ext);
|
||||||
|
ewol::Audio* KeepAudio(const etk::UString& _filename, bool _inRam=false);
|
||||||
|
void AddAudioResourceCreator(pf* _plop, const etk::UString& _ext);
|
||||||
|
ewol::VirtualBufferObject* KeepVBO(const etk::UString& _accesMode);
|
||||||
|
ewol::Mesh* KeepMesh(const etk::UString& _filename);
|
||||||
|
ewol::ConfigFile* KeepConfigFile(const etk::UString& _filename);
|
||||||
|
ewol::Colored3DObject* Keep3DObject(void);
|
||||||
|
|
||||||
|
void Release(ewol::Resource*& object);
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* @brief Release a resources and free it if the Last release is call.
|
* @brief Release a resources and free it if the Last release is call.
|
||||||
* @param[in,out] object element to realease ==> is return at NULL value.
|
* @param[in,out] object element to realease ==> is return at NULL value.
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "TextureFile"
|
#define __class__ "TextureFile"
|
||||||
|
ewol::TextureFile::TextureFile(const etk::UString& _genName) :
|
||||||
|
Texture(_genName)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ewol::TextureFile::TextureFile(etk::UString _genName, const etk::UString& _tmpfileName, const ivec2& _size) :
|
ewol::TextureFile::TextureFile(etk::UString _genName, const etk::UString& _tmpfileName, const ivec2& _size) :
|
||||||
Texture(_genName)
|
Texture(_genName)
|
||||||
|
@ -22,6 +22,7 @@ namespace ewol
|
|||||||
private:
|
private:
|
||||||
vec2 m_realImageSize;
|
vec2 m_realImageSize;
|
||||||
public:
|
public:
|
||||||
|
TextureFile(const etk::UString& _genName);
|
||||||
TextureFile(etk::UString _genName, const etk::UString& _fileName, const ivec2& _size);
|
TextureFile(etk::UString _genName, const etk::UString& _fileName, const ivec2& _size);
|
||||||
~TextureFile(void) { };
|
~TextureFile(void) { };
|
||||||
virtual const char* GetType(void) { return "ewol::TextureFile"; };
|
virtual const char* GetType(void) { return "ewol::TextureFile"; };
|
||||||
|
@ -64,9 +64,7 @@ class VertexNode {
|
|||||||
|
|
||||||
ewol::Mesh::Mesh(const etk::UString& _fileName, const etk::UString& _shaderName) :
|
ewol::Mesh::Mesh(const etk::UString& _fileName, const etk::UString& _shaderName) :
|
||||||
ewol::Resource(_fileName),
|
ewol::Resource(_fileName),
|
||||||
m_enableFaceNormal(true),
|
m_normalMode(normalModeNone)
|
||||||
m_enableVertexNormal(true),
|
|
||||||
m_numberOfElments(0)
|
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Load a new mesh : '" << _fileName << "'");
|
EWOL_DEBUG("Load a new mesh : '" << _fileName << "'");
|
||||||
// get the shader resource :
|
// get the shader resource :
|
||||||
@ -122,22 +120,17 @@ ewol::Mesh::~Mesh(void)
|
|||||||
// remove dynamics dependencies :
|
// remove dynamics dependencies :
|
||||||
ewol::resource::Release(m_GLprogram);
|
ewol::resource::Release(m_GLprogram);
|
||||||
ewol::resource::Release(m_verticesVBO);
|
ewol::resource::Release(m_verticesVBO);
|
||||||
m_numberOfElments=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ewol::Mesh::Draw(mat4& positionMatrix)
|
void ewol::Mesh::Draw(mat4& positionMatrix)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Request Draw : " << m_listIndexFaces.Size() << " elements");
|
//EWOL_DEBUG("Request Draw : " << m_listFaces.GetValue(0).m_index.Size() << " elements");
|
||||||
#ifndef USE_INDEXED_MESH
|
/*
|
||||||
if (m_numberOfElments<=0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (m_listIndexFaces.Size()<=0) {
|
if (m_listIndexFaces.Size()<=0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
*/
|
||||||
if (m_GLprogram==NULL) {
|
if (m_GLprogram==NULL) {
|
||||||
EWOL_ERROR("No shader ...");
|
EWOL_ERROR("No shader ...");
|
||||||
return;
|
return;
|
||||||
@ -157,21 +150,20 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
|
|||||||
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE);
|
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE);
|
||||||
// position :
|
// position :
|
||||||
m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL);
|
m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL);
|
||||||
// position :
|
// draw lights :
|
||||||
#ifndef USE_INDEXED_MESH
|
|
||||||
m_GLprogram->SendAttributePointer(m_GLNormalFace, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_FACE_NORMAL);
|
|
||||||
#endif
|
|
||||||
// draw materials :
|
|
||||||
m_materials.GetValue(0)->Draw(m_GLprogram, m_GLMaterial);
|
|
||||||
m_light.Draw(m_GLprogram);
|
m_light.Draw(m_GLprogram);
|
||||||
|
|
||||||
#ifndef USE_INDEXED_MESH
|
int32_t nbElementDraw = 0;
|
||||||
// Request the draw od the elements :
|
for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) {
|
||||||
ewol::openGL::DrawArrays(GL_TRIANGLES, 0, m_numberOfElments);
|
if (false == m_materials.Exist(m_listFaces.GetKey(kkk))) {
|
||||||
#else
|
EWOL_WARNING("missing materials : '" << m_listFaces.GetKey(kkk) << "'");
|
||||||
ewol::openGL::DrawElements(GL_TRIANGLES, m_listIndexFaces);
|
continue;
|
||||||
EWOL_DEBUG("Draw : " << m_listIndexFaces.Size() << " elements");
|
}
|
||||||
#endif
|
m_materials[m_listFaces.GetKey(kkk)]->Draw(m_GLprogram, m_GLMaterial);
|
||||||
|
ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index);
|
||||||
|
nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size();
|
||||||
|
}
|
||||||
|
EWOL_DEBUG("Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << " elements [" << m_name << "]");
|
||||||
m_GLprogram->UnUse();
|
m_GLprogram->UnUse();
|
||||||
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
|
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||||
// TODO : UNDERSTAND why ... it is needed
|
// TODO : UNDERSTAND why ... it is needed
|
||||||
@ -179,16 +171,12 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
|
|||||||
}
|
}
|
||||||
void ewol::Mesh::Draw2(mat4& positionMatrix)
|
void ewol::Mesh::Draw2(mat4& positionMatrix)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Request Draw2 : " << m_listIndexFaces.Size() << " elements");
|
//
|
||||||
#ifndef USE_INDEXED_MESH
|
/*
|
||||||
if (m_numberOfElments<=0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (m_listIndexFaces.Size()<=0) {
|
if (m_listIndexFaces.Size()<=0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
*/
|
||||||
if (m_GLprogram==NULL) {
|
if (m_GLprogram==NULL) {
|
||||||
EWOL_ERROR("No shader ...");
|
EWOL_ERROR("No shader ...");
|
||||||
return;
|
return;
|
||||||
@ -207,20 +195,20 @@ void ewol::Mesh::Draw2(mat4& positionMatrix)
|
|||||||
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE);
|
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE);
|
||||||
// position :
|
// position :
|
||||||
m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL);
|
m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL);
|
||||||
// position :
|
|
||||||
#ifndef USE_INDEXED_MESH
|
|
||||||
m_GLprogram->SendAttributePointer(m_GLNormalFace, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_FACE_NORMAL);
|
|
||||||
#endif
|
|
||||||
m_light.Draw(m_GLprogram);
|
m_light.Draw(m_GLprogram);
|
||||||
|
|
||||||
// draw materials :
|
// draw materials :
|
||||||
m_materials.GetValue(0)->Draw(m_GLprogram, m_GLMaterial);
|
int32_t nbElementDraw = 0;
|
||||||
#ifndef USE_INDEXED_MESH
|
for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) {
|
||||||
// Request the draw od the elements :
|
if (false == m_materials.Exist(m_listFaces.GetKey(kkk))) {
|
||||||
ewol::openGL::DrawArrays(GL_TRIANGLES, 0, m_numberOfElments);
|
EWOL_WARNING("missing materials : '" << m_listFaces.GetKey(kkk) << "'");
|
||||||
#else
|
continue;
|
||||||
ewol::openGL::DrawElements(GL_TRIANGLES, m_listIndexFaces);
|
}
|
||||||
#endif
|
m_materials[m_listFaces.GetKey(kkk)]->Draw(m_GLprogram, m_GLMaterial);
|
||||||
|
ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index);
|
||||||
|
nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size();
|
||||||
|
}
|
||||||
|
EWOL_DEBUG("Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << " elements [" << m_name << "]");
|
||||||
m_GLprogram->UnUse();
|
m_GLprogram->UnUse();
|
||||||
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
|
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
|
||||||
// TODO : UNDERSTAND why ... it is needed
|
// TODO : UNDERSTAND why ... it is needed
|
||||||
@ -232,36 +220,30 @@ void ewol::Mesh::Draw2(mat4& positionMatrix)
|
|||||||
void ewol::Mesh::CalculateNormaleFace(void)
|
void ewol::Mesh::CalculateNormaleFace(void)
|
||||||
{
|
{
|
||||||
m_listFacesNormal.Clear();
|
m_listFacesNormal.Clear();
|
||||||
// TODO : Preallocation of the vertex :
|
if (m_normalMode != ewol::Mesh::normalModeFace) {
|
||||||
|
etk::Vector<Face>& tmpFaceList = m_listFaces.GetValue(0).m_faces;
|
||||||
if( true==m_enableFaceNormal
|
|
||||||
|| true==m_enableVertexNormal) {
|
|
||||||
etk::Vector<Face>& tmpFaceList = m_listFaces.GetValue(0);
|
|
||||||
for(int32_t iii=0 ; iii<tmpFaceList.Size() ; iii++) {
|
for(int32_t iii=0 ; iii<tmpFaceList.Size() ; iii++) {
|
||||||
// for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane.
|
// for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane.
|
||||||
vec3 normal = btCross(m_listVertex[tmpFaceList[iii].m_vertex[0]]-m_listVertex[tmpFaceList[iii].m_vertex[1]],
|
vec3 normal = btCross(m_listVertex[tmpFaceList[iii].m_vertex[0]]-m_listVertex[tmpFaceList[iii].m_vertex[1]],
|
||||||
m_listVertex[tmpFaceList[iii].m_vertex[1]]-m_listVertex[tmpFaceList[iii].m_vertex[2]]);
|
m_listVertex[tmpFaceList[iii].m_vertex[1]]-m_listVertex[tmpFaceList[iii].m_vertex[2]]);
|
||||||
m_listFacesNormal.PushBack(normal.normalized());
|
m_listFacesNormal.PushBack(normal.normalized());
|
||||||
}
|
}
|
||||||
|
m_normalMode = ewol::Mesh::normalModeFace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ewol::Mesh::CalculateNormaleEdge(void)
|
void ewol::Mesh::CalculateNormaleEdge(void)
|
||||||
{
|
{
|
||||||
m_listVertexNormal.Clear();
|
m_listVertexNormal.Clear();
|
||||||
// TODO : Preallocation of the vertex :
|
if (m_normalMode != ewol::Mesh::normalModeVertex) {
|
||||||
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
for(int32_t iii=0 ; iii<m_listVertex.Size() ; iii++) {
|
for(int32_t iii=0 ; iii<m_listVertex.Size() ; iii++) {
|
||||||
etk::Vector<Face>& tmpFaceList = m_listFaces.GetValue(0);
|
etk::Vector<Face>& tmpFaceList = m_listFaces.GetValue(0).m_faces;
|
||||||
vec3 normal(0,0,0);
|
vec3 normal(0,0,0);
|
||||||
// add the vertex from all the element in the list for face when the element in the face ...
|
// add the vertex from all the element in the list for face when the element in the face ...
|
||||||
for(int32_t jjj=0 ; jjj<tmpFaceList.Size() ; jjj++) {
|
for(int32_t jjj=0 ; jjj<tmpFaceList.Size() ; jjj++) {
|
||||||
if( tmpFaceList[jjj].m_vertex[0] == iii
|
if( tmpFaceList[jjj].m_vertex[0] == iii
|
||||||
|| tmpFaceList[jjj].m_vertex[1] == iii
|
|| tmpFaceList[jjj].m_vertex[1] == iii
|
||||||
|| tmpFaceList[jjj].m_vertex[2] == iii
|
|| tmpFaceList[jjj].m_vertex[2] == iii) {
|
||||||
|| ( tmpFaceList[jjj].m_nbElement == 4
|
|
||||||
&& tmpFaceList[jjj].m_vertex[3] == iii) ) {
|
|
||||||
normal += m_listFacesNormal[jjj];
|
normal += m_listFacesNormal[jjj];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,6 +253,7 @@ void ewol::Mesh::CalculateNormaleEdge(void)
|
|||||||
m_listVertexNormal.PushBack(normal.normalized());
|
m_listVertexNormal.PushBack(normal.normalized());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_normalMode = ewol::Mesh::normalModeVertex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,29 +262,36 @@ void ewol::Mesh::CalculateNormaleEdge(void)
|
|||||||
|
|
||||||
void ewol::Mesh::GenerateVBO(void)
|
void ewol::Mesh::GenerateVBO(void)
|
||||||
{
|
{
|
||||||
m_numberOfElments = 0;
|
|
||||||
// calculate the normal of all faces if needed
|
// calculate the normal of all faces if needed
|
||||||
|
if (m_normalMode == ewol::Mesh::normalModeNone) {
|
||||||
|
// when no normal detected ==> auto Generate Face normal ....
|
||||||
CalculateNormaleFace();
|
CalculateNormaleFace();
|
||||||
CalculateNormaleEdge();
|
}
|
||||||
#ifdef USE_INDEXED_MESH
|
|
||||||
// remove old elements
|
|
||||||
m_listIndexFaces.Clear();
|
|
||||||
// Generate element in 2 pass :
|
// Generate element in 2 pass :
|
||||||
// - create new index dependeng a vertex is a unique componenet of position, texture, normal
|
// - create new index dependeng a vertex is a unique componenet of position, texture, normal
|
||||||
// - the index list generation (can be dynamic ... (TODO later)
|
// - the index list generation (can be dynamic ... (TODO later)
|
||||||
etk::Vector<Face>& tmpFaceList = m_listFaces.GetValue(0);
|
for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) {
|
||||||
for (int32_t iii=0; iii<tmpFaceList.Size() ; iii++) {
|
// clean faces indexes :
|
||||||
for(int32_t indice=0 ; indice<tmpFaceList[iii].m_nbElement; indice++) {
|
m_listFaces.GetValue(kkk).m_index.Clear();
|
||||||
vec3 position = m_listVertex[tmpFaceList[iii].m_vertex[indice]];
|
FaceIndexing& tmpFaceList = m_listFaces.GetValue(kkk);
|
||||||
vec3 normal = m_listVertexNormal[tmpFaceList[iii].m_vertex[indice]];
|
for (int32_t iii=0; iii<tmpFaceList.m_faces.Size() ; iii++) {
|
||||||
vec2 texturepos(m_listUV[tmpFaceList[iii].m_uv[indice]].x(),1.0f-m_listUV[tmpFaceList[iii].m_uv[indice]].y());
|
int32_t vertexVBOId[3];
|
||||||
|
for(int32_t indice=0 ; indice<3; indice++) {
|
||||||
|
vec3 position = m_listVertex[tmpFaceList.m_faces[iii].m_vertex[indice]];
|
||||||
|
vec3 normal;
|
||||||
|
if (m_normalMode == ewol::Mesh::normalModeVertex) {
|
||||||
|
normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]];
|
||||||
|
} else {
|
||||||
|
normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[indice]];
|
||||||
|
}
|
||||||
|
vec2 texturepos(m_listUV[tmpFaceList.m_faces[iii].m_uv[indice]].x(),1.0f-m_listUV[tmpFaceList.m_faces[iii].m_uv[indice]].y());
|
||||||
// try to find it in the list :
|
// try to find it in the list :
|
||||||
bool elementFind = false;
|
bool elementFind = false;
|
||||||
for (int32_t jjj=0; jjj<m_verticesVBO->SizeOnBufferVec3(MESH_VBO_VERTICES); jjj++) {
|
for (int32_t jjj=0; jjj<m_verticesVBO->SizeOnBufferVec3(MESH_VBO_VERTICES); jjj++) {
|
||||||
if( m_verticesVBO->GetOnBufferVec3(MESH_VBO_VERTICES,jjj) == position
|
if( m_verticesVBO->GetOnBufferVec3(MESH_VBO_VERTICES,jjj) == position
|
||||||
&& m_verticesVBO->GetOnBufferVec3(MESH_VBO_VERTICES_NORMAL,jjj) == normal
|
&& m_verticesVBO->GetOnBufferVec3(MESH_VBO_VERTICES_NORMAL,jjj) == normal
|
||||||
&& m_verticesVBO->GetOnBufferVec2(MESH_VBO_TEXTURE,jjj) == texturepos) {
|
&& m_verticesVBO->GetOnBufferVec2(MESH_VBO_TEXTURE,jjj) == texturepos) {
|
||||||
tmpFaceList[iii].m_vertexVBOId[indice] = jjj;
|
vertexVBOId[indice] = jjj;
|
||||||
elementFind = true;
|
elementFind = true;
|
||||||
// stop searching ...
|
// stop searching ...
|
||||||
break;
|
break;
|
||||||
@ -311,101 +301,14 @@ void ewol::Mesh::GenerateVBO(void)
|
|||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES, position);
|
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES, position);
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL, normal);
|
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL, normal);
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, texturepos);
|
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, texturepos);
|
||||||
tmpFaceList[iii].m_vertexVBOId[indice] = m_verticesVBO->SizeOnBufferVec3(MESH_VBO_VERTICES)-1;
|
vertexVBOId[indice] = m_verticesVBO->SizeOnBufferVec3(MESH_VBO_VERTICES)-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int32_t indice=0 ; indice<3; indice++) {
|
||||||
|
tmpFaceList.m_index.PushBack(vertexVBOId[indice]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int32_t iii=0; iii<tmpFaceList.Size() ; iii++) {
|
|
||||||
m_listIndexFaces.PushBack(tmpFaceList[iii].m_vertexVBOId[0]);
|
|
||||||
m_listIndexFaces.PushBack(tmpFaceList[iii].m_vertexVBOId[1]);
|
|
||||||
m_listIndexFaces.PushBack(tmpFaceList[iii].m_vertexVBOId[2]);
|
|
||||||
#ifndef PRINT_HALF
|
|
||||||
if (tmpFaceList[iii].m_nbElement==4) {
|
|
||||||
m_listIndexFaces.PushBack(tmpFaceList[iii].m_vertexVBOId[0]);
|
|
||||||
m_listIndexFaces.PushBack(tmpFaceList[iii].m_vertexVBOId[2]);
|
|
||||||
m_listIndexFaces.PushBack(tmpFaceList[iii].m_vertexVBOId[3]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// TODO : Set a better display system, this one is the worst I known ...
|
|
||||||
for (int32_t iii=0; iii<tmpFaceList.Size() ; iii++) {
|
|
||||||
#ifdef PRINT_HALF
|
|
||||||
m_numberOfElments += 3*3;
|
|
||||||
#else
|
|
||||||
m_numberOfElments += m_listFaces[iii].m_nbElement*3;
|
|
||||||
#endif
|
|
||||||
// 2 possibilities : triangle or quad :
|
|
||||||
int32_t indice = 0;
|
|
||||||
vec2 tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES,m_listVertex[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, vec2(tmpUV.x(),1.0f-tmpUV.y()));
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
}
|
|
||||||
if(true==m_enableFaceNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]);
|
|
||||||
}
|
|
||||||
|
|
||||||
indice = 1;
|
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES,m_listVertex[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, vec2(tmpUV.x(),1.0f-tmpUV.y()));
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
}
|
|
||||||
if(true==m_enableFaceNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]);
|
|
||||||
}
|
|
||||||
|
|
||||||
indice = 2;
|
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES,m_listVertex[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, vec2(tmpUV.x(),1.0f-tmpUV.y()));
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
}
|
|
||||||
if(true==m_enableFaceNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]);
|
|
||||||
}
|
|
||||||
#ifndef PRINT_HALF
|
|
||||||
if (m_listFaces[iii].m_nbElement==4) {
|
|
||||||
indice = 0;
|
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES,m_listVertex[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, vec2(tmpUV.x(),1.0f-tmpUV.y()));
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
}
|
|
||||||
if(true==m_enableFaceNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]);
|
|
||||||
}
|
|
||||||
|
|
||||||
indice = 2;
|
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES,m_listVertex[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, vec2(tmpUV.x(),1.0f-tmpUV.y()));
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
}
|
|
||||||
if(true==m_enableFaceNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]);
|
|
||||||
}
|
|
||||||
|
|
||||||
indice = 3;
|
|
||||||
tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]];
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES,m_listVertex[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_TEXTURE, vec2(tmpUV.x(),1.0f-tmpUV.y()));
|
|
||||||
if(true==m_enableVertexNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]);
|
|
||||||
}
|
|
||||||
if(true==m_enableFaceNormal) {
|
|
||||||
m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// update all the VBO elements ...
|
// update all the VBO elements ...
|
||||||
m_verticesVBO->Flush();
|
m_verticesVBO->Flush();
|
||||||
}
|
}
|
||||||
@ -413,11 +316,11 @@ void ewol::Mesh::GenerateVBO(void)
|
|||||||
|
|
||||||
void ewol::Mesh::CreateCube(float size)
|
void ewol::Mesh::CreateCube(float size)
|
||||||
{
|
{
|
||||||
|
m_normalMode = ewol::Mesh::normalModeNone;
|
||||||
#if 0
|
#if 0
|
||||||
m_listVertex.Clear();
|
m_listVertex.Clear();
|
||||||
m_listUV.Clear();
|
m_listUV.Clear();
|
||||||
m_listFaces.Clear();
|
m_listFaces.Clear();
|
||||||
m_numberOfElments = 0;
|
|
||||||
// This is the direct generation basis on the .obj system
|
// This is the direct generation basis on the .obj system
|
||||||
/*
|
/*
|
||||||
5 6
|
5 6
|
||||||
@ -467,13 +370,9 @@ void ewol::Mesh::CreateCube(float size)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ewol::Mesh::CreateViewBox(float size)
|
void ewol::Mesh::CreateViewBox(const etk::UString& _materialName,float _size)
|
||||||
{
|
{
|
||||||
#if 0
|
m_normalMode = ewol::Mesh::normalModeNone;
|
||||||
m_listVertex.Clear();
|
|
||||||
m_listUV.Clear();
|
|
||||||
m_listFaces.Clear();
|
|
||||||
m_numberOfElments = 0;
|
|
||||||
// This is the direct generation basis on the .obj system
|
// This is the direct generation basis on the .obj system
|
||||||
/*
|
/*
|
||||||
5 6
|
5 6
|
||||||
@ -499,14 +398,14 @@ void ewol::Mesh::CreateViewBox(float size)
|
|||||||
o---------------------o
|
o---------------------o
|
||||||
0 3
|
0 3
|
||||||
*/
|
*/
|
||||||
m_listVertex.PushBack(vec3( size, -size, -size)); // 0
|
m_listVertex.PushBack(vec3( _size, -_size, -_size)); // 0
|
||||||
m_listVertex.PushBack(vec3( size, -size, size)); // 1
|
m_listVertex.PushBack(vec3( _size, -_size, _size)); // 1
|
||||||
m_listVertex.PushBack(vec3(-size, -size, size)); // 2
|
m_listVertex.PushBack(vec3(-_size, -_size, _size)); // 2
|
||||||
m_listVertex.PushBack(vec3(-size, -size, -size)); // 3
|
m_listVertex.PushBack(vec3(-_size, -_size, -_size)); // 3
|
||||||
m_listVertex.PushBack(vec3( size, size, -size)); // 4
|
m_listVertex.PushBack(vec3( _size, _size, -_size)); // 4
|
||||||
m_listVertex.PushBack(vec3( size, size, size)); // 5
|
m_listVertex.PushBack(vec3( _size, _size, _size)); // 5
|
||||||
m_listVertex.PushBack(vec3(-size, size, size)); // 6
|
m_listVertex.PushBack(vec3(-_size, _size, _size)); // 6
|
||||||
m_listVertex.PushBack(vec3(-size, size, -size)); // 7
|
m_listVertex.PushBack(vec3(-_size, _size, -_size)); // 7
|
||||||
/*
|
/*
|
||||||
o----------o----------o----------o
|
o----------o----------o----------o
|
||||||
|8 |9 |10 |11
|
|8 |9 |10 |11
|
||||||
@ -542,13 +441,26 @@ void ewol::Mesh::CreateViewBox(float size)
|
|||||||
m_listUV.PushBack(vec2(2.0/3.0, 1.0 )); // 10
|
m_listUV.PushBack(vec2(2.0/3.0, 1.0 )); // 10
|
||||||
m_listUV.PushBack(vec2(1.0 , 1.0 )); // 11
|
m_listUV.PushBack(vec2(1.0 , 1.0 )); // 11
|
||||||
|
|
||||||
m_listFaces.PushBack(Face(0,1, 1,5, 2,6, 3,2)); // 4
|
if (m_listFaces.Exist(_materialName)==false) {
|
||||||
m_listFaces.PushBack(Face(4,4, 0,0, 3,1, 7,5)); // 3
|
FaceIndexing empty;
|
||||||
m_listFaces.PushBack(Face(2,6, 6,10, 7,11, 3,7)); // 2
|
m_listFaces.Add(_materialName, empty);
|
||||||
m_listFaces.PushBack(Face(4,2, 7,3, 6,7, 5,6)); // 5
|
}
|
||||||
m_listFaces.PushBack(Face(1,5, 5,9, 6,10, 2,6)); // 1
|
{
|
||||||
m_listFaces.PushBack(Face(0,4, 4,8, 5,9, 1,5)); // 0
|
FaceIndexing& tmpElement = m_listFaces[_materialName];
|
||||||
#endif
|
tmpElement.m_faces.PushBack(Face(0,1, 1,5, 2,6)); // 4
|
||||||
|
tmpElement.m_faces.PushBack(Face(0,1, 2,6, 3,2)); // 4
|
||||||
|
tmpElement.m_faces.PushBack(Face(4,4, 0,0, 3,1)); // 3
|
||||||
|
tmpElement.m_faces.PushBack(Face(4,4, 3,1, 7,5)); // 3
|
||||||
|
tmpElement.m_faces.PushBack(Face(2,6, 6,10, 7,11)); // 2
|
||||||
|
tmpElement.m_faces.PushBack(Face(2,6, 7,11, 3,7)); // 2
|
||||||
|
tmpElement.m_faces.PushBack(Face(4,2, 7,3, 6,7)); // 5
|
||||||
|
tmpElement.m_faces.PushBack(Face(4,2, 6,7, 5,6)); // 5
|
||||||
|
tmpElement.m_faces.PushBack(Face(1,5, 5,9, 6,10)); // 1
|
||||||
|
tmpElement.m_faces.PushBack(Face(1,5, 6,10, 2,6)); // 1
|
||||||
|
tmpElement.m_faces.PushBack(Face(0,4, 4,8, 5,9)); // 0
|
||||||
|
tmpElement.m_faces.PushBack(Face(0,4, 5,9, 1,5)); // 0
|
||||||
|
}
|
||||||
|
CalculateNormaleFace();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ewol::Mesh::Subdivide(int32_t numberOfTime, bool smooth)
|
void ewol::Mesh::Subdivide(int32_t numberOfTime, bool smooth)
|
||||||
@ -816,12 +728,6 @@ void ewol::Mesh::InternalSubdivide(bool smooth)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ewol::Mesh::LoadMaterial(const etk::UString& name)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ewol::Mesh::DisplaceElement(const ewol::DisplacementTable& displacement)
|
void ewol::Mesh::DisplaceElement(const ewol::DisplacementTable& displacement)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
@ -864,6 +770,7 @@ void ewol::Mesh::DisplaceElement(const ewol::DisplacementTable& displacement)
|
|||||||
|
|
||||||
bool ewol::Mesh::LoadOBJ(const etk::UString& _fileName)
|
bool ewol::Mesh::LoadOBJ(const etk::UString& _fileName)
|
||||||
{
|
{
|
||||||
|
m_normalMode = ewol::Mesh::normalModeNone;
|
||||||
#if 0
|
#if 0
|
||||||
etk::FSNode fileName(_fileName);
|
etk::FSNode fileName(_fileName);
|
||||||
// Get the fileSize ...
|
// Get the fileSize ...
|
||||||
@ -1036,6 +943,7 @@ char* LoadNextData(char* _elementLine, int64_t _maxData, etk::FSNode& _file, boo
|
|||||||
|
|
||||||
bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
||||||
{
|
{
|
||||||
|
m_normalMode = ewol::Mesh::normalModeNone;
|
||||||
etk::FSNode fileName(_fileName);
|
etk::FSNode fileName(_fileName);
|
||||||
// Get the fileSize ...
|
// Get the fileSize ...
|
||||||
int32_t size = fileName.FileSize();
|
int32_t size = fileName.FileSize();
|
||||||
@ -1112,6 +1020,7 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if( 0 == strncmp(inputDataLine, "\tNormal(vertex) : ", 18) ) {
|
if( 0 == strncmp(inputDataLine, "\tNormal(vertex) : ", 18) ) {
|
||||||
|
m_normalMode = ewol::Mesh::normalModeVertex;
|
||||||
// find the vertex Normal list.
|
// find the vertex Normal list.
|
||||||
while (NULL != LoadNextData(inputDataLine, 2048, fileName, true) ) {
|
while (NULL != LoadNextData(inputDataLine, 2048, fileName, true) ) {
|
||||||
if (inputDataLine[0] == '\0') {
|
if (inputDataLine[0] == '\0') {
|
||||||
@ -1125,6 +1034,7 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if( 0 == strncmp(inputDataLine, "\tNormal(face) : ", 16) ) {
|
if( 0 == strncmp(inputDataLine, "\tNormal(face) : ", 16) ) {
|
||||||
|
m_normalMode = ewol::Mesh::normalModeFace;
|
||||||
// find the face Normal list.
|
// find the face Normal list.
|
||||||
while (NULL != LoadNextData(inputDataLine, 2048, fileName, true) ) {
|
while (NULL != LoadNextData(inputDataLine, 2048, fileName, true) ) {
|
||||||
if (inputDataLine[0] == '\0') {
|
if (inputDataLine[0] == '\0') {
|
||||||
@ -1150,7 +1060,7 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
|||||||
// find the material :
|
// find the material :
|
||||||
inputDataLine[len-1] = '\0';
|
inputDataLine[len-1] = '\0';
|
||||||
etk::UString materialName = inputDataLine;
|
etk::UString materialName = inputDataLine;
|
||||||
etk::Vector<Face> empty;
|
FaceIndexing empty;
|
||||||
m_listFaces.Add(materialName, empty);
|
m_listFaces.Add(materialName, empty);
|
||||||
elementID = m_listFaces.GetId(materialName);
|
elementID = m_listFaces.GetId(materialName);
|
||||||
} else {
|
} else {
|
||||||
@ -1172,9 +1082,9 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
|||||||
&vertexIndex[0], &uvIndex[0], &normalIndex[0],
|
&vertexIndex[0], &uvIndex[0], &normalIndex[0],
|
||||||
&vertexIndex[1], &uvIndex[1], &normalIndex[1],
|
&vertexIndex[1], &uvIndex[1], &normalIndex[1],
|
||||||
&vertexIndex[2], &uvIndex[2], &normalIndex[2] );
|
&vertexIndex[2], &uvIndex[2], &normalIndex[2] );
|
||||||
m_listFaces.GetValue(elementID).PushBack(Face(vertexIndex[0], uvIndex[0],
|
m_listFaces.GetValue(elementID).m_faces.PushBack(Face(vertexIndex[0], uvIndex[0], normalIndex[0],
|
||||||
vertexIndex[1], uvIndex[1],
|
vertexIndex[1], uvIndex[1], normalIndex[1],
|
||||||
vertexIndex[2], uvIndex[2]));
|
vertexIndex[2], uvIndex[2], normalIndex[2]));
|
||||||
/*
|
/*
|
||||||
EWOL_DEBUG("face :" << vertexIndex[0] << "/" << uvIndex[0] << "/" << normalIndex[0] <<
|
EWOL_DEBUG("face :" << vertexIndex[0] << "/" << uvIndex[0] << "/" << normalIndex[0] <<
|
||||||
" " << vertexIndex[1] << "/" << uvIndex[1] << "/" << normalIndex[1] <<
|
" " << vertexIndex[1] << "/" << uvIndex[1] << "/" << normalIndex[1] <<
|
||||||
@ -1184,7 +1094,7 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
|||||||
}
|
}
|
||||||
EWOL_DEBUG("Load " << m_listFaces.Size() << " faces (mode) :");
|
EWOL_DEBUG("Load " << m_listFaces.Size() << " faces (mode) :");
|
||||||
for (esize_t iii=0; iii< m_listFaces.Size(); iii++) {
|
for (esize_t iii=0; iii< m_listFaces.Size(); iii++) {
|
||||||
EWOL_DEBUG(" mat='" << m_listFaces.GetKey(iii) << "' nb faces=" << m_listFaces.GetValue(iii).Size());
|
EWOL_DEBUG(" mat='" << m_listFaces.GetKey(iii) << "' nb faces=" << m_listFaces.GetValue(iii).m_faces.Size());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1288,40 +1198,24 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* exemple of file
|
|
||||||
EMF(STRING)
|
|
||||||
# Blender v2.66 (sub 1) EMF File: 'station.blend'
|
|
||||||
Mesh : 1
|
|
||||||
Name : MainControl_mesh
|
|
||||||
Vertex : 174
|
|
||||||
0.500000 0.015097 -1.170499|-1.003113 0.010738 -1.000184|1.003173 0.013001 -0.998027|
|
|
||||||
UV-mapping :
|
|
||||||
0.964431 0.766844|0.939031 0.811940|1.050593 0.813877|0.815493 0.602993|0.783793 0.520610|
|
|
||||||
Normal(face) : 344
|
|
||||||
0.310313 -0.276298 0.909596|-0.426055 -0.318865 0.846642|-0.915346 -0.402637 -0.004953|
|
|
||||||
Face : 344
|
|
||||||
Material: 23/1/1 9/2/1 2/3/1| 18/4/2 20/5/2 1/6/2| 18/4/3 1/6/3 5/7/3|
|
|
||||||
|
|
||||||
Materials : 1
|
|
||||||
Material
|
|
||||||
Ns 96.078431
|
|
||||||
Ka 0.000000 0.000000 0.000000
|
|
||||||
Kd 0.640000 0.640000 0.640000
|
|
||||||
Ks 0.500000 0.500000 0.500000
|
|
||||||
Ni 1.000000
|
|
||||||
d 1.000000
|
|
||||||
illum 2
|
|
||||||
map_Kd station.png
|
|
||||||
|
|
||||||
- Ka - material ambient is multiplied by the texture value
|
|
||||||
- Kd - material diffuse is multiplied by the texture value
|
|
||||||
- Ks - material specular is multiplied by the texture value
|
|
||||||
- Ns - material specular exponent is multiplied by the texture value
|
|
||||||
- d - material dissolve is multiplied by the texture value
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
fileName.FileClose();
|
fileName.FileClose();
|
||||||
GenerateVBO();
|
GenerateVBO();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ewol::Mesh::AddMaterial(const etk::UString& _name, ewol::Material* _data)
|
||||||
|
{
|
||||||
|
if (NULL==_data) {
|
||||||
|
EWOL_ERROR(" can not add material with null pointer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_name=="") {
|
||||||
|
EWOL_ERROR(" can not add material with no name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// really add the material :
|
||||||
|
m_materials.Add(_name, _data);
|
||||||
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
// 4 "float" elements
|
// 4 "float" elements
|
||||||
#define MESH_VBO_COLOR (4)
|
#define MESH_VBO_COLOR (4)
|
||||||
|
|
||||||
#define USE_INDEXED_MESH
|
|
||||||
namespace ewol
|
namespace ewol
|
||||||
{
|
{
|
||||||
class DisplacementTable
|
class DisplacementTable
|
||||||
@ -104,47 +103,56 @@ namespace ewol
|
|||||||
class Face
|
class Face
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int32_t m_nbElement;
|
int32_t m_vertex[3];
|
||||||
int32_t m_vertex[4];
|
int32_t m_uv[3];
|
||||||
int32_t m_uv[4];
|
int32_t m_normal[3];
|
||||||
#ifdef USE_INDEXED_MESH
|
|
||||||
int32_t m_vertexVBOId[4]; // used to be an entry point of the rework of the dynamic generating of mesh
|
|
||||||
#endif
|
|
||||||
public:
|
public:
|
||||||
Face(void) {};
|
Face(void) {};
|
||||||
Face(int32_t v1, int32_t t1,
|
Face(int32_t v1, int32_t t1,
|
||||||
int32_t v2, int32_t t2,
|
int32_t v2, int32_t t2,
|
||||||
int32_t v3, int32_t t3)
|
int32_t v3, int32_t t3)
|
||||||
{
|
{
|
||||||
m_nbElement = 3;
|
|
||||||
m_vertex[0] = v1;
|
m_vertex[0] = v1;
|
||||||
m_uv[0] = t1;
|
|
||||||
m_vertex[1] = v2;
|
m_vertex[1] = v2;
|
||||||
m_uv[1] = t2;
|
|
||||||
m_vertex[2] = v3;
|
m_vertex[2] = v3;
|
||||||
|
m_uv[0] = t1;
|
||||||
|
m_uv[1] = t2;
|
||||||
m_uv[2] = t3;
|
m_uv[2] = t3;
|
||||||
|
m_normal[0] = -1;
|
||||||
|
m_normal[1] = -1;
|
||||||
|
m_normal[2] = -1;
|
||||||
};
|
};
|
||||||
Face(int32_t v1, int32_t t1,
|
Face(int32_t v1, int32_t t1, int32_t n1,
|
||||||
int32_t v2, int32_t t2,
|
int32_t v2, int32_t t2, int32_t n2,
|
||||||
int32_t v3, int32_t t3,
|
int32_t v3, int32_t t3, int32_t n3)
|
||||||
int32_t v4, int32_t t4)
|
|
||||||
{
|
{
|
||||||
m_nbElement = 4;
|
|
||||||
m_vertex[0] = v1;
|
m_vertex[0] = v1;
|
||||||
m_uv[0] = t1;
|
|
||||||
m_vertex[1] = v2;
|
m_vertex[1] = v2;
|
||||||
m_uv[1] = t2;
|
|
||||||
m_vertex[2] = v3;
|
m_vertex[2] = v3;
|
||||||
|
m_uv[0] = t1;
|
||||||
|
m_uv[1] = t2;
|
||||||
m_uv[2] = t3;
|
m_uv[2] = t3;
|
||||||
m_vertex[3] = v4;
|
m_normal[0] = n1;
|
||||||
m_uv[3] = t4;
|
m_normal[1] = n2;
|
||||||
|
m_normal[2] = n3;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
class FaceIndexing
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
etk::Vector<Face> m_faces;
|
||||||
|
etk::Vector<uint32_t> m_index;
|
||||||
|
};
|
||||||
class Mesh : public ewol::Resource
|
class Mesh : public ewol::Resource
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
typedef enum {
|
||||||
|
normalModeNone,
|
||||||
|
normalModeFace,
|
||||||
|
normalModeVertex,
|
||||||
|
} normalMode_te;
|
||||||
private:
|
private:
|
||||||
bool m_enableFaceNormal;
|
normalMode_te m_normalMode;
|
||||||
bool m_enableVertexNormal;
|
|
||||||
protected:
|
protected:
|
||||||
ewol::Program* m_GLprogram;
|
ewol::Program* m_GLprogram;
|
||||||
int32_t m_GLPosition;
|
int32_t m_GLPosition;
|
||||||
@ -162,11 +170,8 @@ namespace ewol
|
|||||||
etk::Vector<vec2> m_listUV; //!< List of all UV point in the mesh (for the specify texture)
|
etk::Vector<vec2> m_listUV; //!< List of all UV point in the mesh (for the specify texture)
|
||||||
etk::Vector<vec3> m_listFacesNormal; //!< List of all Face normal, when calculated
|
etk::Vector<vec3> m_listFacesNormal; //!< List of all Face normal, when calculated
|
||||||
etk::Vector<vec3> m_listVertexNormal; //!< List of all Face normal, when calculated
|
etk::Vector<vec3> m_listVertexNormal; //!< List of all Face normal, when calculated
|
||||||
etk::Hash<etk::Vector<Face> > m_listFaces; //!< List of all Face for the mesh
|
etk::Hash<FaceIndexing> m_listFaces; //!< List of all Face for the mesh
|
||||||
etk::Hash<ewol::Material*> m_materials;
|
etk::Hash<ewol::Material*> m_materials;
|
||||||
#ifdef USE_INDEXED_MESH
|
|
||||||
etk::Vector<uint32_t> m_listIndexFaces;
|
|
||||||
#endif
|
|
||||||
protected:
|
protected:
|
||||||
ewol::VirtualBufferObject* m_verticesVBO;
|
ewol::VirtualBufferObject* m_verticesVBO;
|
||||||
public:
|
public:
|
||||||
@ -181,29 +186,22 @@ namespace ewol
|
|||||||
void SetTexture(const etk::UString& myTexture);
|
void SetTexture(const etk::UString& myTexture);
|
||||||
protected:
|
protected:
|
||||||
void InternalSubdivide(bool smooth);
|
void InternalSubdivide(bool smooth);
|
||||||
public:
|
|
||||||
void StatusFaceNormal(bool newState) {
|
|
||||||
m_enableFaceNormal = newState;
|
|
||||||
}
|
|
||||||
void StatusVertexNormal(bool newState) {
|
|
||||||
m_enableVertexNormal = newState;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
void CalculateNormaleFace(void);
|
void CalculateNormaleFace(void);
|
||||||
void CalculateNormaleEdge(void);
|
void CalculateNormaleEdge(void);
|
||||||
public:
|
|
||||||
void LoadMaterial(const etk::UString& name);
|
|
||||||
/*
|
/*
|
||||||
* Element modification area :
|
* Element modification area :
|
||||||
*/
|
*/
|
||||||
public :
|
public :
|
||||||
void CreateCube(float size=1.0);
|
void CreateCube(float size=1.0);
|
||||||
void CreateViewBox(float size=1.0);
|
void CreateViewBox(const etk::UString& _materialName,float _size=1.0);
|
||||||
void Subdivide(int32_t numberOfTime, bool smooth);
|
void Subdivide(int32_t numberOfTime, bool smooth);
|
||||||
void DisplaceElement(const ewol::DisplacementTable& displacement);
|
void DisplaceElement(const ewol::DisplacementTable& displacement);
|
||||||
private:
|
private:
|
||||||
bool LoadOBJ(const etk::UString& _fileName);
|
bool LoadOBJ(const etk::UString& _fileName);
|
||||||
bool LoadEMF(const etk::UString& _fileName);
|
bool LoadEMF(const etk::UString& _fileName);
|
||||||
|
public:
|
||||||
|
void AddMaterial(const etk::UString& _name, ewol::Material* _data);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user