[DEV] update loader
This commit is contained in:
parent
1c4e81bdba
commit
3ad1725f54
@ -40,12 +40,12 @@ ememory::SharedPtr<ege::PhysicsShape> ege::PhysicsShape::create(const std::strin
|
|||||||
|
|
||||||
|
|
||||||
bool ege::PhysicsShape::parse(const char* _line) {
|
bool ege::PhysicsShape::parse(const char* _line) {
|
||||||
if(strncmp(_line, "origin : ", 9) == 0) {
|
if(strncmp(_line, "origin:", 7) == 0) {
|
||||||
sscanf(&_line[9], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] );
|
sscanf(&_line[9], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] );
|
||||||
EGE_VERBOSE(" Origin=" << m_origin);
|
EGE_VERBOSE(" Origin=" << m_origin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(strncmp(_line, "rotate : ", 9) == 0) {
|
if(strncmp(_line, "rotate:", 7) == 0) {
|
||||||
sscanf(&_line[9], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] );
|
sscanf(&_line[9], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] );
|
||||||
EGE_VERBOSE(" rotate=" << m_quaternion);
|
EGE_VERBOSE(" rotate=" << m_quaternion);
|
||||||
return true;
|
return true;
|
||||||
|
@ -102,7 +102,7 @@ void ege::resource::Mesh::clean() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//#define DISPLAY_NB_VERTEX_DISPLAYED
|
#define DISPLAY_NB_VERTEX_DISPLAYED
|
||||||
|
|
||||||
void ege::resource::Mesh::draw(mat4& _positionMatrix,
|
void ege::resource::Mesh::draw(mat4& _positionMatrix,
|
||||||
bool _enableDepthTest,
|
bool _enableDepthTest,
|
||||||
@ -391,6 +391,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[m_listFaces.getKey(kkk)] == nullptr) {
|
||||||
|
EGE_ERROR("Can not get material : " << m_listFaces.getKey(kkk) << " pointer value: " << size_t(m_materials[m_listFaces.getKey(kkk)].get()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch (m_materials[m_listFaces.getKey(kkk)]->getRenderMode()) {
|
switch (m_materials[m_listFaces.getKey(kkk)]->getRenderMode()) {
|
||||||
case gale::openGL::renderMode::triangle:
|
case gale::openGL::renderMode::triangle:
|
||||||
case gale::openGL::renderMode::triangleStrip:
|
case gale::openGL::renderMode::triangleStrip:
|
||||||
|
@ -122,7 +122,6 @@ static void removeEndLine(char* _val) {
|
|||||||
enum emfModuleMode {
|
enum emfModuleMode {
|
||||||
EMFModuleNone,
|
EMFModuleNone,
|
||||||
EMFModuleMesh,
|
EMFModuleMesh,
|
||||||
EMFModuleMeshNamed,
|
|
||||||
EMFModuleMeshVertex,
|
EMFModuleMeshVertex,
|
||||||
EMFModuleMeshUVMapping,
|
EMFModuleMeshUVMapping,
|
||||||
EMFModuleMeshNormalVertex,
|
EMFModuleMeshNormalVertex,
|
||||||
@ -133,8 +132,10 @@ enum emfModuleMode {
|
|||||||
EMFModuleMeshPhysicsNamed,
|
EMFModuleMeshPhysicsNamed,
|
||||||
EMFModuleMesh_END,
|
EMFModuleMesh_END,
|
||||||
EMFModuleMaterial,
|
EMFModuleMaterial,
|
||||||
EMFModuleMaterialNamed,
|
|
||||||
EMFModuleMaterial_END,
|
EMFModuleMaterial_END,
|
||||||
|
EMFModulePhysics,
|
||||||
|
EMFModulePhysicsNamed,
|
||||||
|
EMFModulePhysics_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO : rework with string line extractor
|
// TODO : rework with string line extractor
|
||||||
@ -175,6 +176,10 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
|||||||
// physical shape:
|
// physical shape:
|
||||||
ememory::SharedPtr<ege::PhysicsShape> physics;
|
ememory::SharedPtr<ege::PhysicsShape> physics;
|
||||||
bool haveUVMapping = false;
|
bool haveUVMapping = false;
|
||||||
|
size_t offsetVertexId = 0;
|
||||||
|
size_t offsetUV = 0;
|
||||||
|
size_t offsetFaceNormal = 0;
|
||||||
|
size_t offsetVertexNormal = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
int32_t level = countIndent(fileName);
|
int32_t level = countIndent(fileName);
|
||||||
if (level == 0) {
|
if (level == 0) {
|
||||||
@ -186,13 +191,30 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
|||||||
if(strncmp(inputDataLine, "Mesh:", 5) == 0) {
|
if(strncmp(inputDataLine, "Mesh:", 5) == 0) {
|
||||||
currentMode = EMFModuleMesh;
|
currentMode = EMFModuleMesh;
|
||||||
removeEndLine(inputDataLine);
|
removeEndLine(inputDataLine);
|
||||||
currentMeshName = inputDataLine + 5;
|
currentMeshName = inputDataLine + 6;
|
||||||
currentMode = EMFModuleMeshNamed;
|
EGE_VERBOSE("Parse Mesh: " << currentMeshName);
|
||||||
EGE_VERBOSE("Parse Mesh :" << currentMeshName);
|
offsetVertexId = m_listVertex.size();
|
||||||
|
offsetUV = m_listUV.size();
|
||||||
|
offsetFaceNormal = m_listFacesNormal.size();
|
||||||
|
offsetVertexNormal = m_listVertexNormal.size();
|
||||||
|
|
||||||
} else if(strncmp(inputDataLine, "Materials:", 9) == 0) {
|
} else if(strncmp(inputDataLine, "Materials:", 9) == 0) {
|
||||||
currentMode = EMFModuleMaterial;
|
currentMode = EMFModuleMaterial;
|
||||||
EGE_VERBOSE("Parse Material :");
|
// add previous material:
|
||||||
|
if( materialName != ""
|
||||||
|
&& material != nullptr) {
|
||||||
|
m_materials.add(materialName, material);
|
||||||
|
materialName = "";
|
||||||
|
material = nullptr;
|
||||||
|
}
|
||||||
|
material = ememory::makeShared<ege::Material>();
|
||||||
|
removeEndLine(inputDataLine);
|
||||||
|
materialName = inputDataLine + 10;
|
||||||
|
EGE_VERBOSE("Parse Material: " << materialName);
|
||||||
|
} else if(strncmp(inputDataLine, "Physics:", 8) == 0) {
|
||||||
|
currentMode = EMFModulePhysics;
|
||||||
|
removeEndLine(inputDataLine);
|
||||||
|
EGE_VERBOSE("Parse global Physics: ");
|
||||||
} else {
|
} else {
|
||||||
currentMode = EMFModuleNone;
|
currentMode = EMFModuleNone;
|
||||||
}
|
}
|
||||||
@ -227,7 +249,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
|||||||
EGE_VERBOSE(" Physics ...");
|
EGE_VERBOSE(" Physics ...");
|
||||||
} else {
|
} else {
|
||||||
EGE_ERROR(" Unknow mesh property '"<<inputDataLine<<"'");
|
EGE_ERROR(" Unknow mesh property '"<<inputDataLine<<"'");
|
||||||
currentMode = EMFModuleMeshNamed;
|
currentMode = EMFModuleMesh;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -292,7 +314,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
|||||||
}
|
}
|
||||||
case EMFModuleMeshNormalFace: {
|
case EMFModuleMeshNormalFace: {
|
||||||
EGE_ERROR("Change mode in face mode ...");
|
EGE_ERROR("Change mode in face mode ...");
|
||||||
m_normalMode = normalModeFace;
|
m_normalMode = normalModeFace; // 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) != nullptr) {
|
while (loadNextData(inputDataLine, 2048, fileName, true, true) != nullptr) {
|
||||||
@ -349,11 +371,38 @@ bool ege::resource::Mesh::loadEMF(const std::string& _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] );
|
||||||
|
vertexIndex[0] += offsetVertexId;
|
||||||
|
vertexIndex[1] += offsetVertexId;
|
||||||
|
vertexIndex[2] += offsetVertexId;
|
||||||
|
uvIndex[0] += offsetUV;
|
||||||
|
uvIndex[1] += offsetUV;
|
||||||
|
uvIndex[2] += offsetUV;
|
||||||
|
if (m_normalMode == normalModeFace) {
|
||||||
|
normalIndex[0] += offsetFaceNormal;
|
||||||
|
normalIndex[1] += offsetFaceNormal;
|
||||||
|
normalIndex[2] += offsetFaceNormal;
|
||||||
|
} else {
|
||||||
|
normalIndex[0] += offsetVertexNormal;
|
||||||
|
normalIndex[1] += offsetVertexNormal;
|
||||||
|
normalIndex[2] += offsetVertexNormal;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sscanf(inputDataLine, "%d/%d %d/%d %d/%d",
|
sscanf(inputDataLine, "%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] );
|
||||||
|
vertexIndex[0] += offsetVertexId;
|
||||||
|
vertexIndex[1] += offsetVertexId;
|
||||||
|
vertexIndex[2] += offsetVertexId;
|
||||||
|
if (m_normalMode == normalModeFace) {
|
||||||
|
normalIndex[0] += offsetFaceNormal;
|
||||||
|
normalIndex[1] += offsetFaceNormal;
|
||||||
|
normalIndex[2] += offsetFaceNormal;
|
||||||
|
} else {
|
||||||
|
normalIndex[0] += offsetVertexNormal;
|
||||||
|
normalIndex[1] += offsetVertexNormal;
|
||||||
|
normalIndex[2] += offsetVertexNormal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_listFaces.getValue(meshFaceMaterialID).m_faces.push_back(Face(vertexIndex[0], uvIndex[0], normalIndex[0],
|
m_listFaces.getValue(meshFaceMaterialID).m_faces.push_back(Face(vertexIndex[0], uvIndex[0], normalIndex[0],
|
||||||
vertexIndex[1], uvIndex[1], normalIndex[1],
|
vertexIndex[1], uvIndex[1], normalIndex[1],
|
||||||
@ -404,33 +453,14 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (currentMode >= EMFModuleMaterial && currentMode <= EMFModuleMaterial_END) {
|
} else if ( currentMode >= EMFModuleMaterial
|
||||||
|
&& 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) == nullptr) {
|
if (loadNextData(inputDataLine, 2048, fileName, true) == nullptr) {
|
||||||
// reach end of file ...
|
// reach end of file ...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
removeEndLine(inputDataLine);
|
removeEndLine(inputDataLine);
|
||||||
if (level == 1) {
|
|
||||||
// add previous material :
|
|
||||||
if( materialName != ""
|
|
||||||
&& material != nullptr) {
|
|
||||||
m_materials.add(materialName, material);
|
|
||||||
materialName = "";
|
|
||||||
material = nullptr;
|
|
||||||
}
|
|
||||||
material = ememory::makeShared<ege::Material>();
|
|
||||||
materialName = inputDataLine;
|
|
||||||
currentMode = EMFModuleMaterialNamed;
|
|
||||||
EGE_VERBOSE(" "<< materialName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// level >1
|
|
||||||
if (currentMode != EMFModuleMaterialNamed) {
|
|
||||||
EGE_WARNING(" Unknow element ..."<< level);
|
|
||||||
jumpEndLine(fileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (material == nullptr) {
|
if (material == nullptr) {
|
||||||
EGE_ERROR("material allocation error");
|
EGE_ERROR("material allocation error");
|
||||||
jumpEndLine(fileName);
|
jumpEndLine(fileName);
|
||||||
@ -491,9 +521,35 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
|||||||
} else {
|
} else {
|
||||||
EGE_ERROR("unknow material property ... : '" << inputDataLine << "'");
|
EGE_ERROR("unknow material property ... : '" << inputDataLine << "'");
|
||||||
}
|
}
|
||||||
|
} else if ( currentMode >= EMFModulePhysics
|
||||||
|
&& currentMode <= EMFModulePhysics_END) {
|
||||||
|
if (loadNextData(inputDataLine, 2048, fileName, true, false, false) == nullptr) {
|
||||||
|
// reach end of file ...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
removeEndLine(inputDataLine);
|
||||||
|
if (level == 1) {
|
||||||
|
EGE_ERROR("Load shape : " << inputDataLine);
|
||||||
|
physics = ege::PhysicsShape::create(inputDataLine);
|
||||||
|
if (physics == nullptr) {
|
||||||
|
EGE_ERROR("Allocation error when creating physical shape ...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
addPhysicElement(physics);
|
||||||
|
EGE_VERBOSE(" " << m_physics.size() << " " << inputDataLine);
|
||||||
|
currentMode = EMFModulePhysicsNamed;
|
||||||
|
} else if (currentMode == EMFModulePhysicsNamed) {
|
||||||
|
if (physics == nullptr) {
|
||||||
|
EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (physics->parse(inputDataLine) == false) {
|
||||||
|
EGE_ERROR("ERROR when parsing :'" << inputDataLine << "' in physical shape ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// unknow ...
|
// unknow ...
|
||||||
EGE_WARNING("Unknow type of line == > jump end of line ... ");
|
EGE_WARNING("Unknow type of line == > jump end of line ... " << inputDataLine);
|
||||||
jumpEndLine(fileName);
|
jumpEndLine(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user