Compare commits

...

8 Commits

Author SHA1 Message Date
Kim Kulling
9a9e4b4a59 Update ObjTools.h 2025-12-25 21:42:41 +01:00
Kim Kulling
ea7f710d70 Update glTF2Asset.h 2025-12-25 21:34:49 +01:00
Kim Kulling
93f3c38ceb Refactor ObjFileParser for improved readability#
Refactor handling of cstype section end and material descriptor parsing.
2025-12-25 21:03:29 +01:00
Kim Kulling
0a9cefe943 Refactor insideCstype condition for clarity 2025-12-25 21:01:46 +01:00
Kim Kulling
daa6d64227 Clean up commented code in ObjFileParser.cpp
Removed commented-out code related to material name parsing.
2025-12-25 20:56:55 +01:00
Kim Kulling
04946cc0f4 Add new presents 2025-12-08 23:43:28 +01:00
Kim Kulling
30c4784619 Use constexpr 2025-11-24 20:13:43 +01:00
Kim Kulling
f7d2de1efc Replace string copy by using pure iterators. 2025-11-23 20:16:40 +01:00
4 changed files with 84 additions and 51 deletions

View File

@@ -1,17 +1,54 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "assimp",
"binaryDir": "${sourceDir}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"ASSIMP_BUILD_ASSIMP_TOOLS": "OFF"
}
},
"configurePresets": [
{
"name": "assimp_with_tools",
"binaryDir": "${sourceDir}",
"cacheVariables": {
"ASSIMP_BUILD_ASSIMP_TOOLS" : "ON"
}
}
]
{
"name": "assimp_static",
"binaryDir": "${sourceDir}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_SHARED_LIBS": "OFF",
"ASSIMP_BUILD_ASSIMP_TOOLS": "OFF",
"ASSIMP_DOUBLE_PRECISION": "ON"
}
},
{
"name": "assimp_double_precision",
"binaryDir": "${sourceDir}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"ASSIMP_BUILD_ASSIMP_TOOLS": "OFF",
"ASSIMP_DOUBLE_PRECISION": "ON"
}
},
{
"name": "assimp_with_tools",
"binaryDir": "${sourceDir}",
"cacheVariables": {
"ASSIMP_BUILD_ASSIMP_TOOLS": "ON"
}
},
{
"name": "assimp_all",
"binaryDir": "${sourceDir}",
"cacheVariables": {
"ASSIMP_BUILD_ASSIMP_TOOLS": "ON",
"ASSIMP_BUILD_SAMPLES": "ON",
"ASSIMP_BUILD_DOCS": "ON"
}
}
]
}

View File

@@ -139,11 +139,12 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
// handle c-stype section end (http://paulbourke.net/dataformats/obj/)
if (insideCstype) {
switch (*m_DataIt) {
case 'e': {
std::string name;
getNameNoSpace(m_DataIt, m_DataItEnd, name);
insideCstype = name != "end";
} break;
case 'e': {
char *name{nullptr};
size_t len{0};
getNameNoSpace(m_DataIt, m_DataItEnd, &name, len);
insideCstype = !(len == 3 && strncmp(name, "end", 3) == 0);
} break;
}
goto pf_skip_line;
}
@@ -198,32 +199,23 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
case 'u': // Parse a material desc. setter
{
std::string name;
char *name{nullptr};
size_t len{ 0 };
getNameNoSpace(m_DataIt, m_DataItEnd, &name, len);
getNameNoSpace(m_DataIt, m_DataItEnd, name);
size_t nextSpace = name.find(' ');
if (nextSpace != std::string::npos)
name = name.substr(0, nextSpace);
if (name == "usemtl") {
if (strncmp(name, "usemtl", len) == 0) {
getMaterialDesc();
}
} break;
case 'm': // Parse a material library or merging group ('mg')
{
std::string name;
getNameNoSpace(m_DataIt, m_DataItEnd, name);
size_t nextSpace = name.find(' ');
if (nextSpace != std::string::npos)
name = name.substr(0, nextSpace);
if (name == "mg")
char *name{nullptr};
size_t len{ 0 };
getNameNoSpace(m_DataIt, m_DataItEnd, &name, len);
if (strncmp(name, "mg", len) == 0)
getGroupNumberAndResolution();
else if (name == "mtllib")
else if (strncmp(name, "mtllib", len) == 0)
getMaterialLib();
else
goto pf_skip_line;
@@ -246,9 +238,11 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
case 'c': // handle cstype section start
{
std::string name;
getNameNoSpace(m_DataIt, m_DataItEnd, name);
insideCstype = name == "cstype";
//std::string name;
char *name{nullptr};
size_t len{0};
getNameNoSpace(m_DataIt, m_DataItEnd, &name, len);
insideCstype = strncmp(name, "cstype", len) == 0;
goto pf_skip_line;
}

View File

@@ -177,31 +177,37 @@ inline char_t getName(char_t it, char_t end, std::string &name) {
* @return Current-iterator with new position
*/
template <class char_t>
inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) {
name = "";
inline char_t getNameNoSpace(char_t it, char_t end, char **name, size_t &len) {
*name = nullptr;
len = 0;
if (isEndOfBuffer(it, end)) {
return end;
}
char *pStart = &(*it);
while (&(*it) > pStart && (isEndOfBuffer(it, end) || IsLineEnd(*it) || IsSpaceOrNewLine(*it))) {
--it;
--len;
}
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it) && !IsSpaceOrNewLine(*it)) {
++it;
++len;
}
while (isEndOfBuffer(it, end) || IsLineEnd(*it) || IsSpaceOrNewLine(*it)) {
--it;
--len;
}
++it;
++len;
// Get name
// if there is no name, and the previous char is a separator, come back to start
while (&(*it) < pStart) {
++it;
++len;
}
std::string strName(pStart, &(*it));
if (!strName.empty()) {
name = strName;
}
*name = pStart;
return it;
}
@@ -239,7 +245,7 @@ inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length)
*/
template <class char_t>
inline char_t getFloat(char_t it, char_t end, ai_real &value) {
static const size_t BUFFERSIZE = 1024;
static constexpr size_t BUFFERSIZE = 1024;
char buffer[BUFFERSIZE] = {};
it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE);
value = (ai_real)fast_atof(buffer);

View File

@@ -58,8 +58,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GLTF2ASSET_H_INC
#define GLTF2ASSET_H_INC
//#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER)
#include <assimp/Exceptional.h>
#include <algorithm>
@@ -1283,6 +1281,4 @@ inline std::string getContextForErrorMessages(const std::string &id, const std::
// Include the implementation of the methods
#include "glTF2Asset.inl"
//#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
#endif // GLTF2ASSET_H_INC