[DEV] update new etk Uri API

This commit is contained in:
Edouard DUPIN 2018-10-23 22:19:31 +02:00
parent 02c8b0ec81
commit 486998fb35
6 changed files with 122 additions and 132 deletions

View File

@ -83,14 +83,14 @@ void ege::Material::setShininess(float _val) {
m_shininess = _val; m_shininess = _val;
} }
void ege::Material::setTexture0(const etk::String& _filename) { void ege::Material::setTexture0(const etk::Uri& _uri) {
ivec2 tmpSize(256, 256); ivec2 tmpSize(256, 256);
if (_filename != "") { if (_uri.isEmpty() == false) {
// prevent overloard error : // prevent overloard error :
ememory::SharedPtr<ewol::resource::Texture> tmpCopy = m_texture0; ememory::SharedPtr<ewol::resource::Texture> tmpCopy = m_texture0;
m_texture0 = ewol::resource::TextureFile::create(_filename, tmpSize); m_texture0 = ewol::resource::TextureFile::create(_uri, tmpSize);
if (m_texture0 == null) { if (m_texture0 == null) {
EGE_ERROR("Can not load specific texture : " << _filename); EGE_ERROR("Can not load specific texture : " << _uri);
// retreave previous texture: // retreave previous texture:
m_texture0 = tmpCopy; m_texture0 = tmpCopy;
if (m_texture0 != null) { if (m_texture0 != null) {

View File

@ -49,7 +49,7 @@ namespace ege {
void setRenderMode(enum gale::openGL::renderMode _val); void setRenderMode(enum gale::openGL::renderMode _val);
enum gale::openGL::renderMode getRenderModeOpenGl(); enum gale::openGL::renderMode getRenderModeOpenGl();
enum gale::openGL::renderMode getRenderMode(); enum gale::openGL::renderMode getRenderMode();
void setTexture0(const etk::String& _filename); void setTexture0(const etk::Uri& _uri);
void setTexture0Magic(const ivec2& _size); void setTexture0Magic(const ivec2& _size);
void setImageSize(const ivec2& _newSize); void setImageSize(const ivec2& _newSize);
// get the reference on this image to draw nomething on it ... // get the reference on this image to draw nomething on it ...

View File

@ -8,7 +8,7 @@
#include <ege/resource/Mesh.hpp> #include <ege/resource/Mesh.hpp>
#include <gale/resource/Manager.hpp> #include <gale/resource/Manager.hpp>
#include <gale/renderer/openGL/openGL-include.hpp> #include <gale/renderer/openGL/openGL-include.hpp>
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <ege/resource/tools/viewBox.hpp> #include <ege/resource/tools/viewBox.hpp>
#include <ege/resource/tools/isoSphere.hpp> #include <ege/resource/tools/isoSphere.hpp>
#include <ege/resource/tools/icoSphere.hpp> #include <ege/resource/tools/icoSphere.hpp>
@ -31,8 +31,8 @@ ege::resource::Mesh::Mesh() :
addResourceType("ege::resource::Mesh"); addResourceType("ege::resource::Mesh");
} }
void ege::resource::Mesh::init(const etk::String& _fileName, const etk::String& _shaderName) { void ege::resource::Mesh::init(const etk::Uri& _fileName, const etk::Uri& _shaderName) {
gale::Resource::init(_fileName); gale::Resource::init(_fileName.getString());
EGE_VERBOSE("Load a new mesh : '" << _fileName << "'"); EGE_VERBOSE("Load a new mesh : '" << _fileName << "'");
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
@ -63,18 +63,18 @@ void ege::resource::Mesh::init(const etk::String& _fileName, const etk::String&
return; return;
} }
// TO facilitate some debugs we add a name of the VBO: // TO facilitate some debugs we add a name of the VBO:
m_verticesVBO->setName("[VBO] of " + _fileName); m_verticesVBO->setName("[VBO] of " + _fileName.getString());
// load the curent file : // load the curent file :
etk::String tmpName = etk::toLower(_fileName); etk::String extention = etk::toLower(_fileName.getPath().getExtention());
// select the corect loader : // select the corect loader :
if (etk::end_with(tmpName, ".obj") == true) { if (extention == "obj") {
if (loadOBJ(_fileName) == false) { if (loadOBJ(_fileName) == false) {
EGE_ERROR("Error To load OBJ file " << tmpName ); EGE_ERROR("Error To load OBJ file " << _fileName );
return; return;
} }
} else if (etk::end_with(tmpName, ".emf") ) { } else if (extention == "emf") {
if (loadEMF(_fileName) == false) { if (loadEMF(_fileName) == false) {
EGE_ERROR("Error To load EMF file " << tmpName ); EGE_ERROR("Error To load EMF file " << _fileName );
return; return;
} }
//EGE_CRITICAL("Load a new mesh : '" << _fileName << "' (end)"); //EGE_CRITICAL("Load a new mesh : '" << _fileName << "' (end)");
@ -407,6 +407,10 @@ void ege::resource::Mesh::generateVBO() {
// clean faces indexes : // clean faces indexes :
m_listFaces.getValue(kkk).m_index.clear(); m_listFaces.getValue(kkk).m_index.clear();
int32_t nbIndicInFace = 3; int32_t nbIndicInFace = 3;
if (m_materials.exist(m_listFaces.getKey(kkk)) == false) {
EGE_WARNING("missing materials : '" << m_listFaces.getKey(kkk) << "' not in " << m_materials.getKeys() );
continue;
}
if (m_materials[m_listFaces.getKey(kkk)] == null) { if (m_materials[m_listFaces.getKey(kkk)] == null) {
EGE_ERROR("Can not get material : " << m_listFaces.getKey(kkk) << " pointer value: " << size_t(m_materials[m_listFaces.getKey(kkk)].get())); EGE_ERROR("Can not get material : " << m_listFaces.getKey(kkk) << " pointer value: " << size_t(m_materials[m_listFaces.getKey(kkk)].get()));
continue; continue;
@ -532,7 +536,8 @@ void ege::resource::Mesh::addMaterial(const etk::String& _name, ememory::SharedP
EGE_ERROR(" can not add material with no name"); EGE_ERROR(" can not add material with no name");
return; return;
} }
// really add the material : // really add the material:
EGE_WARNING("Add material: " << _name);
m_materials.add(_name, _data); m_materials.add(_name, _data);
} }

View File

@ -118,13 +118,13 @@ namespace ege {
ememory::SharedPtr<gale::resource::VirtualBufferObject> m_verticesVBO; ememory::SharedPtr<gale::resource::VirtualBufferObject> m_verticesVBO;
protected: protected:
Mesh(); Mesh();
void init(const etk::String& _fileName="---", void init(const etk::Uri& _fileName="---",
//const etk::String& _shaderName="DATA:///textured3D2.prog" //const etk::String& _shaderName="DATA:///textured3D2.prog"
const etk::String& _shaderName="DATA:///material3D.prog" const etk::Uri& _shaderName="DATA:///material3D.prog"
); );
public: public:
virtual ~Mesh(); virtual ~Mesh();
DECLARE_RESOURCE_NAMED_FACTORY(Mesh); DECLARE_RESOURCE_URI_FACTORY(Mesh);
public: public:
virtual void draw(mat4& _positionMatrix, bool _enableDepthTest=true, bool _enableDepthUpdate=true); virtual void draw(mat4& _positionMatrix, bool _enableDepthTest=true, bool _enableDepthUpdate=true);
virtual void draw(mat4& _positionMatrix, virtual void draw(mat4& _positionMatrix,
@ -144,8 +144,8 @@ namespace ege {
void createViewBox(const etk::String& _materialName,float _size=1.0); void createViewBox(const etk::String& _materialName,float _size=1.0);
void createIcoSphere(const etk::String& _materialName,float _size=1.0, int32_t _subdivision=3); void createIcoSphere(const etk::String& _materialName,float _size=1.0, int32_t _subdivision=3);
private: private:
bool loadOBJ(const etk::String& _fileName); bool loadOBJ(const etk::Uri& _fileName);
bool loadEMF(const etk::String& _fileName); bool loadEMF(const etk::Uri& _fileName);
public: public:
void addMaterial(const etk::String& _name, ememory::SharedPtr<ege::Material> _data); void addMaterial(const etk::String& _name, ememory::SharedPtr<ege::Material> _data);
public: public:

View File

@ -6,25 +6,25 @@
#include <ege/debug.hpp> #include <ege/debug.hpp>
#include <ege/resource/Mesh.hpp> #include <ege/resource/Mesh.hpp>
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
static void jumpEndLine(etk::FSNode& _file) { static void jumpEndLine(ememory::SharedPtr<etk::io::Interface>& _file) {
char current=_file.fileGet(); char current=_file->get();
while( current != '\0' while( current != '\0'
&& current != '\n') { && current != '\n') {
//printf("%c", current); //printf("%c", current);
current=_file.fileGet(); current=_file->get();
} }
} }
static int32_t countIndent(etk::FSNode& _file) { static int32_t countIndent(ememory::SharedPtr<etk::io::Interface>& _file) {
int32_t nbIndent=0; int32_t nbIndent=0;
int32_t nbSpacesTab=0; int32_t nbSpacesTab=0;
int32_t nbChar=0; int32_t nbChar=0;
//EGE_DEBUG(" start count Indent"); //EGE_DEBUG(" start count Indent");
for(char current=_file.fileGet(); current != '\0'; current=_file.fileGet()) { for(char current=_file->get(); current != '\0'; current=_file->get()) {
nbChar++; nbChar++;
//EGE_DEBUG("parse : " << current); //EGE_DEBUG("parse : " << current);
if (current == '\t') { if (current == '\t') {
@ -46,18 +46,17 @@ static int32_t countIndent(etk::FSNode& _file) {
} }
} }
//EGE_DEBUG("indent : " << nbIndent); //EGE_DEBUG("indent : " << nbIndent);
_file.fileSeek(-nbChar, etk::seekNode_current); _file->seek(-nbChar, etk::io::SeekMode::Current);
return nbIndent; return nbIndent;
} }
static char* loadNextData(char* _elementLine, static bool loadNextData(etk::String& _elementLine,
int64_t _maxData, int64_t _maxData,
etk::FSNode& _file, ememory::SharedPtr<etk::io::Interface>& _file,
bool _removeTabs=false, bool _removeTabs=false,
bool _stopColomn=false, bool _stopColomn=false,
bool _stopPipe=true) { bool _stopPipe=true) {
memset(_elementLine, 0, _maxData); _elementLine.clear();
char * element = _elementLine;
int64_t outSize = 0; int64_t outSize = 0;
/* /*
if (m_zipReadingOffset >= m_zipContent->size()) { if (m_zipReadingOffset >= m_zipContent->size()) {
@ -65,12 +64,11 @@ static char* loadNextData(char* _elementLine,
return null; return null;
} }
*/ */
char current = _file.fileGet(); char current = _file->get();
while (current != '\0') { while (current != '\0') {
if( _removeTabs == false if( _removeTabs == false
|| element != _elementLine) { || _elementLine.isEmpty() == false) {
*element = current; _elementLine.pushBack(current);
element++;
} }
if( current == '\n' if( current == '\n'
|| current == '\r' || current == '\r'
@ -79,42 +77,32 @@ static char* loadNextData(char* _elementLine,
|| ( current == ':' || ( current == ':'
&& _stopColomn == true) ) && _stopColomn == true) )
{ {
*element = '\0';
//EGE_DEBUG(" plop : '" << _elementLine << "'" ); //EGE_DEBUG(" plop : '" << _elementLine << "'" );
return _elementLine; return true;
} else if( element == _elementLine } else if( _elementLine.isEmpty() == true
&& current != '\t') { && current != '\t') {
*element = current; _elementLine.pushBack(current);
element++;
} }
// check maxData size ... // check maxData size ...
if (outSize >= _maxData-1) { if (outSize >= _maxData-1) {
*element = '\0'; return true;
return _elementLine;
} }
current = _file.fileGet(); current = _file->get();
} }
if (outSize == 0) { if (outSize == 0) {
return null; return false;
} else { } else {
// send last line // send last line
return _elementLine; return true;
} }
return null; return false;
} }
static void removeEndLine(char* _val) { static void removeEndLine(etk::String& _value) {
int32_t len = strlen(_val); while ( _value.size() > 0
if( len>0 && ( _value.back() == '\n'
&& ( _val[len-1] == '\n' || _value.back() == '\r') ) {
|| _val[len-1] == '\r' ) ) { _value.popBack();
_val[len-1] = '\0';
}
len--;
if( len>0
&& ( _val[len-1] == '\n'
|| _val[len-1] == '\r') ) {
_val[len-1] = '\0';
} }
} }
@ -139,26 +127,26 @@ enum emfModuleMode {
}; };
// TODO : rework with string line extractor // TODO : rework with string line extractor
bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) { bool ege::resource::Mesh::loadEMF(const etk::Uri& _fileName) {
m_checkNormal = true; m_checkNormal = true;
m_normalMode = ege::resource::Mesh::normalMode::none; m_normalMode = ege::resource::Mesh::normalMode::none;
etk::FSNode fileName(_fileName); ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_fileName);
// get the fileSize ... // get the fileSize ...
int32_t size = fileName.fileSize(); int32_t size = fileIO->size();
if (size == 0 ) { if (fileIO == null ) {
EGE_ERROR("No data in the file named='" << fileName << "'"); EGE_ERROR("CAn not get the file named='" << _fileName << "'");
return false; return false;
} }
if (fileName.fileOpenRead() == false) { if (fileIO->open(etk::io::OpenMode::Read) == false) {
EGE_ERROR("Can not find the file name='" << fileName << "'"); EGE_ERROR("Can not find the file name='" << _fileName << "'");
return false; return false;
} }
char inputDataLine[2048]; etk::String inputDataLine;
// load the first line : // load the first line :
fileName.fileGets(inputDataLine, 2048); fileIO->gets(inputDataLine);
if(strncmp(inputDataLine, "EMF(STRING)", 11) == 0) { if (inputDataLine.startWith("EMF(STRING)") == true) {
// parse in string mode ... // parse in string mode ...
} else if (strncmp(inputDataLine, "EMF(BINARY)", 11) == 0) { } else if (inputDataLine.startWith("EMF(BINARY)") == true) {
EGE_ERROR(" file binary mode is not supported now : 'EMF(BINARY)'"); EGE_ERROR(" file binary mode is not supported now : 'EMF(BINARY)'");
return false; return false;
} else { } else {
@ -166,7 +154,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
return false; return false;
} }
enum emfModuleMode currentMode = EMFModuleNone; enum emfModuleMode currentMode = EMFModuleNone;
EGE_VERBOSE("Start parsing Mesh file : " << fileName); EGE_VERBOSE("Start parsing Mesh file : " << _fileName);
// mesh global param : // mesh global param :
etk::String currentMeshName = ""; etk::String currentMeshName = "";
int32_t meshFaceMaterialID = -1; int32_t meshFaceMaterialID = -1;
@ -181,14 +169,14 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
size_t offsetFaceNormal = 0; size_t offsetFaceNormal = 0;
size_t offsetVertexNormal = 0; size_t offsetVertexNormal = 0;
while (1) { while (1) {
int32_t level = countIndent(fileName); int32_t level = countIndent(fileIO);
if (level == 0) { if (level == 0) {
// new section ... // new section ...
if (loadNextData(inputDataLine, 2048, fileName) == null) { if (loadNextData(inputDataLine, 2048, fileIO) == false) {
// reach end of file ... // reach end of file ...
break; break;
} }
if(strncmp(inputDataLine, "Mesh:", 5) == 0) { if(inputDataLine.startWith("Mesh:") == true) {
currentMode = EMFModuleMesh; currentMode = EMFModuleMesh;
removeEndLine(inputDataLine); removeEndLine(inputDataLine);
currentMeshName = inputDataLine + 6; currentMeshName = inputDataLine + 6;
@ -198,7 +186,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
offsetFaceNormal = m_listFacesNormal.size(); offsetFaceNormal = m_listFacesNormal.size();
offsetVertexNormal = m_listVertexNormal.size(); offsetVertexNormal = m_listVertexNormal.size();
//EGE_ERROR("new offset: " << offsetVertexId << " " << offsetUV << " " << offsetFaceNormal << " " << offsetVertexNormal); //EGE_ERROR("new offset: " << offsetVertexId << " " << offsetUV << " " << offsetFaceNormal << " " << offsetVertexNormal);
} else if(strncmp(inputDataLine, "Materials:", 9) == 0) { } else if(inputDataLine.startWith("Materials:") == true) {
currentMode = EMFModuleMaterial; currentMode = EMFModuleMaterial;
// add previous material: // add previous material:
if( materialName != "" if( materialName != ""
@ -209,9 +197,9 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
} }
material = ememory::makeShared<ege::Material>(); material = ememory::makeShared<ege::Material>();
removeEndLine(inputDataLine); removeEndLine(inputDataLine);
materialName = inputDataLine + 10; materialName = inputDataLine.extract(10, etk::String::npos);
EGE_VERBOSE("Parse Material: " << materialName); EGE_VERBOSE("Parse Material: " << materialName);
} else if(strncmp(inputDataLine, "Physics:", 8) == 0) { } else if(inputDataLine.startWith("Physics:") == true) {
currentMode = EMFModulePhysics; currentMode = EMFModulePhysics;
removeEndLine(inputDataLine); removeEndLine(inputDataLine);
EGE_VERBOSE("Parse global Physics: "); EGE_VERBOSE("Parse global Physics: ");
@ -223,32 +211,32 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
&& currentMode <= EMFModuleMesh_END) { && currentMode <= EMFModuleMesh_END) {
if (level == 1) { if (level == 1) {
// In the mesh level 2 the line size must not exced 2048 // In the mesh level 2 the line size must not exced 2048
if (loadNextData(inputDataLine, 2048, fileName, true) == null) { if (loadNextData(inputDataLine, 2048, fileIO, true) == false) {
// reach end of file ... // reach end of file ...
break; break;
} }
removeEndLine(inputDataLine); removeEndLine(inputDataLine);
if(strncmp(inputDataLine, "Vertex", 6) == 0) { if(inputDataLine.startWith("Vertex") == true) {
currentMode = EMFModuleMeshVertex; currentMode = EMFModuleMeshVertex;
EGE_VERBOSE(" Vertex ..."); EGE_VERBOSE(" Vertex ...");
} else if(strncmp(inputDataLine, "UV-mapping", 10) == 0) { } else if(inputDataLine.startWith("UV-mapping") == true) {
currentMode = EMFModuleMeshUVMapping; currentMode = EMFModuleMeshUVMapping;
haveUVMapping = true; haveUVMapping = true;
EGE_VERBOSE(" UV-mapping ..."); EGE_VERBOSE(" UV-mapping ...");
} else if(strncmp(inputDataLine, "Normal(vertex)", 14) == 0) { } else if(inputDataLine.startWith("Normal(vertex)") == true) {
currentMode = EMFModuleMeshNormalVertex; currentMode = EMFModuleMeshNormalVertex;
EGE_VERBOSE(" Normal(vertex) ..."); EGE_VERBOSE(" Normal(vertex) ...");
} else if(strncmp(inputDataLine, "Normal(face)", 12) == 0) { } else if(inputDataLine.startWith("Normal(face)") == true) {
currentMode = EMFModuleMeshNormalFace; currentMode = EMFModuleMeshNormalFace;
EGE_VERBOSE(" Normal(face) ..."); EGE_VERBOSE(" Normal(face) ...");
} else if(strncmp(inputDataLine, "Face", 4) == 0) { } else if(inputDataLine.startWith("Face") == true) {
currentMode = EMFModuleMeshFace; currentMode = EMFModuleMeshFace;
EGE_VERBOSE(" Face ..."); EGE_VERBOSE(" Face ...");
} else if(strncmp(inputDataLine, "Physics", 7) == 0) { } else if(inputDataLine.startWith("Physics") == true) {
currentMode = EMFModuleMeshPhysics; currentMode = EMFModuleMeshPhysics;
EGE_VERBOSE(" Physics ..."); EGE_VERBOSE(" Physics ...");
} else { } else {
EGE_ERROR(" Unknow mesh property '"<<inputDataLine<<"'"); EGE_ERROR(" Unknow mesh property '" << inputDataLine << "'");
currentMode = EMFModuleMesh; currentMode = EMFModuleMesh;
} }
continue; continue;
@ -257,19 +245,18 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
switch (currentMode) { switch (currentMode) {
default: default:
EGE_ERROR("Unknow ... "<< level); EGE_ERROR("Unknow ... "<< level);
jumpEndLine(fileName); jumpEndLine(fileIO);
break; break;
case EMFModuleMeshVertex: { case EMFModuleMeshVertex: {
vec3 vertex(0,0,0); vec3 vertex(0,0,0);
while (loadNextData(inputDataLine, 2048, fileName, true, true) != null) { while (loadNextData(inputDataLine, 2048, fileIO, true, true) == true) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
sscanf(inputDataLine, "%f %f %f", &vertex.m_floats[0], &vertex.m_floats[1], &vertex.m_floats[2] ); sscanf(&inputDataLine[0], "%f %f %f", &vertex.m_floats[0], &vertex.m_floats[1], &vertex.m_floats[2] );
m_listVertex.pushBack(vertex); m_listVertex.pushBack(vertex);
int32_t len = strlen(inputDataLine)-1; if( inputDataLine.back() == '\n'
if( inputDataLine[len] == '\n' || inputDataLine.back() == '\r') {
|| inputDataLine[len] == '\r') {
break; break;
} }
} }
@ -278,15 +265,14 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
} }
case EMFModuleMeshUVMapping: { case EMFModuleMeshUVMapping: {
vec2 uvMap(0,0); vec2 uvMap(0,0);
while (loadNextData(inputDataLine, 2048, fileName, true, true) != null) { while (loadNextData(inputDataLine, 2048, fileIO, true, true) == true) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
sscanf(inputDataLine, "%f %f", &uvMap.m_floats[0], &uvMap.m_floats[1]); sscanf(&inputDataLine[0], "%f %f", &uvMap.m_floats[0], &uvMap.m_floats[1]);
m_listUV.pushBack(uvMap); m_listUV.pushBack(uvMap);
int32_t len = strlen(inputDataLine)-1; if( inputDataLine.back() == '\n'
if( inputDataLine[len] == '\n' || inputDataLine.back() == '\r') {
|| inputDataLine[len] == '\r') {
break; break;
} }
} }
@ -297,15 +283,14 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
m_normalMode = ege::resource::Mesh::normalMode::vertex; m_normalMode = ege::resource::Mesh::normalMode::vertex;
vec3 normal(0,0,0); vec3 normal(0,0,0);
// find the vertex Normal list. // find the vertex Normal list.
while (loadNextData(inputDataLine, 2048, fileName, true, true) != null) { while (loadNextData(inputDataLine, 2048, fileIO, true, true) == true) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
sscanf(inputDataLine, "%f %f %f", &normal.m_floats[0], &normal.m_floats[1], &normal.m_floats[2] ); sscanf(&inputDataLine[0], "%f %f %f", &normal.m_floats[0], &normal.m_floats[1], &normal.m_floats[2] );
m_listVertexNormal.pushBack(normal); m_listVertexNormal.pushBack(normal);
int32_t len = strlen(inputDataLine)-1; if( inputDataLine.back() == '\n'
if( inputDataLine[len] == '\n' || inputDataLine.back() == '\r') {
|| inputDataLine[len] == '\r') {
break; break;
} }
} }
@ -317,15 +302,14 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
m_normalMode = ege::resource::Mesh::normalMode::face; // TODO : check if it is the same mode of display the normal from the start of the file m_normalMode = ege::resource::Mesh::normalMode::face; // TODO : check if it is the same mode of display the normal from the start of the file
vec3 normal(0,0,0); vec3 normal(0,0,0);
// find the face Normal list. // find the face Normal list.
while (loadNextData(inputDataLine, 2048, fileName, true, true) != null) { while (loadNextData(inputDataLine, 2048, fileIO, true, true) == true) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
sscanf(inputDataLine, "%f %f %f", &normal.m_floats[0], &normal.m_floats[1], &normal.m_floats[2] ); sscanf(&inputDataLine[0], "%f %f %f", &normal.m_floats[0], &normal.m_floats[1], &normal.m_floats[2] );
m_listFacesNormal.pushBack(normal); m_listFacesNormal.pushBack(normal);
int32_t len = strlen(inputDataLine)-1; if( inputDataLine.back() == '\n'
if( inputDataLine[len] == '\n' || inputDataLine.back() == '\r') {
|| inputDataLine[len] == '\r') {
break; break;
} }
} }
@ -336,7 +320,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
case EMFModuleMeshFaceMaterial: case EMFModuleMeshFaceMaterial:
if (level == 2) { if (level == 2) {
//Find mesh name ... //Find mesh name ...
if (loadNextData(inputDataLine, 2048, fileName, true) == null) { if (loadNextData(inputDataLine, 2048, fileIO, true) == false) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -350,7 +334,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
meshFaceMaterialID = m_listFaces.getId(inputDataLine); meshFaceMaterialID = m_listFaces.getId(inputDataLine);
EGE_VERBOSE(" " << inputDataLine); EGE_VERBOSE(" " << inputDataLine);
} else if (currentMode == EMFModuleMeshFaceMaterial) { } else if (currentMode == EMFModuleMeshFaceMaterial) {
while (loadNextData(inputDataLine, 2048, fileName, true, true) != null) { while (loadNextData(inputDataLine, 2048, fileIO, true, true) == true) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
// end of line // end of line
break; break;
@ -369,7 +353,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
normalIndex[1] = 0; normalIndex[1] = 0;
normalIndex[2] = 0; normalIndex[2] = 0;
if (haveUVMapping == true) { if (haveUVMapping == true) {
sscanf(inputDataLine, "%d/%d/%d %d/%d/%d %d/%d/%d", sscanf(&inputDataLine[0], "%d/%d/%d %d/%d/%d %d/%d/%d",
&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] );
@ -389,7 +373,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
normalIndex[2] += offsetVertexNormal; normalIndex[2] += offsetVertexNormal;
} }
} else { } else {
sscanf(inputDataLine, "%d/%d %d/%d %d/%d", sscanf(&inputDataLine[0], "%d/%d %d/%d %d/%d",
&vertexIndex[0], &normalIndex[0], &vertexIndex[0], &normalIndex[0],
&vertexIndex[1], &normalIndex[1], &vertexIndex[1], &normalIndex[1],
&vertexIndex[2], &normalIndex[2] ); &vertexIndex[2], &normalIndex[2] );
@ -414,9 +398,8 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
" " << vertexIndex[1] << "/" << uvIndex[1] << "/" << normalIndex[1] << " " << vertexIndex[1] << "/" << uvIndex[1] << "/" << normalIndex[1] <<
" " << vertexIndex[2] << "/" << uvIndex[2] << "/" << normalIndex[2]); " " << vertexIndex[2] << "/" << uvIndex[2] << "/" << normalIndex[2]);
*/ */
int32_t len = strlen(inputDataLine)-1; if( inputDataLine.back() == '\n'
if( inputDataLine[len] == '\n' || inputDataLine.back() == '\r') {
|| inputDataLine[len] == '\r') {
break; break;
} }
} }
@ -424,12 +407,12 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
} else { } else {
// insert element without material ... // insert element without material ...
EGE_ERROR(" try to add face without material selection ..."); EGE_ERROR(" try to add face without material selection ...");
jumpEndLine(fileName); jumpEndLine(fileIO);
} }
break; break;
case EMFModuleMeshPhysics: case EMFModuleMeshPhysics:
case EMFModuleMeshPhysicsNamed: case EMFModuleMeshPhysicsNamed:
if (loadNextData(inputDataLine, 2048, fileName, true, false, false) == null) { if (loadNextData(inputDataLine, 2048, fileIO, true, false, false) == false) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -448,7 +431,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ..."); EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ...");
continue; continue;
} }
if (physics->parse(inputDataLine) == false) { if (physics->parse(&inputDataLine[0]) == false) {
EGE_ERROR("ERROR when parsing :'" << inputDataLine << "' in physical shape ..."); EGE_ERROR("ERROR when parsing :'" << inputDataLine << "' in physical shape ...");
} }
} }
@ -458,22 +441,22 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
} else if ( currentMode >= EMFModuleMaterial } else if ( currentMode >= EMFModuleMaterial
&& currentMode <= EMFModuleMaterial_END) { && currentMode <= EMFModuleMaterial_END) {
// all material element is stored on 1 line (size < 2048) // all material element is stored on 1 line (size < 2048)
if (loadNextData(inputDataLine, 2048, fileName, true) == null) { if (loadNextData(inputDataLine, 2048, fileIO, true) == false) {
// reach end of file ... // reach end of file ...
break; break;
} }
removeEndLine(inputDataLine); removeEndLine(inputDataLine);
if (material == null) { if (material == null) {
EGE_ERROR("material allocation error"); EGE_ERROR("material allocation error");
jumpEndLine(fileName); jumpEndLine(fileIO);
continue; continue;
} }
if(strncmp(inputDataLine,"Ns ",3) == 0) { if(inputDataLine.startWith("Ns ") == true) {
float tmpVal=0; float tmpVal=0;
sscanf(&inputDataLine[3], "%f", &tmpVal); sscanf(&inputDataLine[3], "%f", &tmpVal);
material->setShininess(tmpVal); material->setShininess(tmpVal);
EGE_VERBOSE(" Shininess " << tmpVal); EGE_VERBOSE(" Shininess " << tmpVal);
} else if(strncmp(inputDataLine,"Ka ",3) == 0) { } else if(inputDataLine.startWith("Ka ") == true) {
float tmpVal1=0; float tmpVal1=0;
float tmpVal2=0; float tmpVal2=0;
float tmpVal3=0; float tmpVal3=0;
@ -481,7 +464,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1); vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1);
material->setAmbientFactor(tmp); material->setAmbientFactor(tmp);
EGE_VERBOSE(" AmbientFactor " << tmp); EGE_VERBOSE(" AmbientFactor " << tmp);
} else if(strncmp(inputDataLine,"Kd ",3) == 0) { } else if(inputDataLine.startWith("Kd ") == true) {
float tmpVal1=0; float tmpVal1=0;
float tmpVal2=0; float tmpVal2=0;
float tmpVal3=0; float tmpVal3=0;
@ -492,7 +475,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1); vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1);
material->setDiffuseFactor(tmp); material->setDiffuseFactor(tmp);
EGE_ERROR(" DiffuseFactor " << tmp); EGE_ERROR(" DiffuseFactor " << tmp);
} else if(strncmp(inputDataLine,"Ks ",3) == 0) { } else if(inputDataLine.startWith("Ks ") == true) {
float tmpVal1=0; float tmpVal1=0;
float tmpVal2=0; float tmpVal2=0;
float tmpVal3=0; float tmpVal3=0;
@ -500,25 +483,27 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1); vec4 tmp(tmpVal1, tmpVal2, tmpVal3, 1);
material->setSpecularFactor(tmp); material->setSpecularFactor(tmp);
EGE_VERBOSE(" SpecularFactor " << tmp); EGE_VERBOSE(" SpecularFactor " << tmp);
} else if(strncmp(inputDataLine,"Ni ",3) == 0) { } else if(inputDataLine.startWith("Ni ") == true) {
float tmpVal=0; float tmpVal=0;
sscanf(&inputDataLine[3], "%f", &tmpVal); sscanf(&inputDataLine[3], "%f", &tmpVal);
// TODO : ... // TODO : ...
EGE_VERBOSE(" Ni " << tmpVal); EGE_VERBOSE(" Ni " << tmpVal);
} else if(strncmp(inputDataLine,"d ",2) == 0) { } else if(inputDataLine.startWith("d ") == true) {
float tmpVal=0; float tmpVal=0;
sscanf(&inputDataLine[2], "%f", &tmpVal); sscanf(&inputDataLine[2], "%f", &tmpVal);
// TODO : ... // TODO : ...
EGE_VERBOSE(" d " << tmpVal); EGE_VERBOSE(" d " << tmpVal);
} else if(strncmp(inputDataLine,"illum ",6) == 0) { } else if(inputDataLine.startWith("illum ") == true) {
int tmpVal=0; int tmpVal=0;
sscanf(&inputDataLine[6], "%d", &tmpVal); sscanf(&inputDataLine[6], "%d", &tmpVal);
// TODO : ... // TODO : ...
EGE_VERBOSE(" illum " << tmpVal); EGE_VERBOSE(" illum " << tmpVal);
} else if(strncmp(inputDataLine,"map_Kd ",7) == 0) { } else if(inputDataLine.startWith("map_Kd ") == true) {
material->setTexture0(fileName.getRelativeFolder() + &inputDataLine[7]); etk::Uri tmpTexture = _fileName;
tmpTexture.setPath(_fileName.getPath().getParent() / &inputDataLine[7]);
material->setTexture0(tmpTexture);
EGE_VERBOSE(" Texture " << &inputDataLine[7]); EGE_VERBOSE(" Texture " << &inputDataLine[7]);
} else if(strncmp(inputDataLine,"renderMode ",11) == 0) { } else if(inputDataLine.startWith("renderMode ") == true) {
gale::openGL::renderMode mode; gale::openGL::renderMode mode;
etk::from_string(mode, &inputDataLine[11]); etk::from_string(mode, &inputDataLine[11]);
material->setRenderMode(mode); material->setRenderMode(mode);
@ -528,7 +513,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
} }
} else if ( currentMode >= EMFModulePhysics } else if ( currentMode >= EMFModulePhysics
&& currentMode <= EMFModulePhysics_END) { && currentMode <= EMFModulePhysics_END) {
if (loadNextData(inputDataLine, 2048, fileName, true, false, false) == null) { if (loadNextData(inputDataLine, 2048, fileIO, true, false, false) == false) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -548,14 +533,14 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ..."); EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ...");
continue; continue;
} }
if (physics->parse(inputDataLine) == false) { if (physics->parse(&inputDataLine[0]) == false) {
EGE_ERROR("ERROR when parsing :'" << inputDataLine << "' in physical shape ..."); EGE_ERROR("ERROR when parsing :'" << inputDataLine << "' in physical shape ...");
} }
} }
} else { } else {
// unknow ... // unknow ...
EGE_WARNING("Unknow type of line == > jump end of line ... " << inputDataLine); EGE_WARNING("Unknow type of line == > jump end of line ... " << inputDataLine);
jumpEndLine(fileName); jumpEndLine(fileIO);
} }
} }
} }
@ -568,7 +553,7 @@ bool ege::resource::Mesh::loadEMF(const etk::String& _fileName) {
} }
EGE_VERBOSE("Stop parsing Mesh file"); EGE_VERBOSE("Stop parsing Mesh file");
fileName.fileClose(); fileIO->close();
EGE_VERBOSE("New mesh : "); EGE_VERBOSE("New mesh : ");
EGE_VERBOSE(" nb vertex: " << m_listVertex.size()); EGE_VERBOSE(" nb vertex: " << m_listVertex.size());

View File

@ -8,7 +8,7 @@
#include <ege/resource/Mesh.hpp> #include <ege/resource/Mesh.hpp>
bool ege::resource::Mesh::loadOBJ(const etk::String& _fileName) { bool ege::resource::Mesh::loadOBJ(const etk::Uri& _fileName) {
m_normalMode = ege::resource::Mesh::normalMode::none; m_normalMode = ege::resource::Mesh::normalMode::none;
#if 0 #if 0
etk::FSNode fileName(_fileName); etk::FSNode fileName(_fileName);