Compare commits

...

10 Commits

Author SHA1 Message Date
Citlali del Rey 9a197dabe7
Add basic FEZ importer 2023-11-19 17:34:11 -08:00
mosfet80 6a08c39e3a Update CMakeLists.txt
updated cpp-pm/hunter to last version
2023-09-25 16:46:51 +02:00
Stephen Gold 4b193dbee3 contrib/zip/src/zip.h: correct 2 spelling errors 2023-09-25 16:28:24 +02:00
Kim Kulling f9d3e7015b Update types.h
- closes https://github.com/assimp/assimp/issues/5247
2023-09-25 14:22:00 +02:00
mosfet80 f1b8df01d5 fix variable name 2023-09-25 13:37:01 +02:00
Kim Kulling c421247be9 Update utVersion.cpp 2023-09-23 18:35:48 +02:00
Kim Kulling cebb06280d Update script_x86.iss 2023-09-23 18:35:48 +02:00
Kim Kulling 967d61edc5 Update script_x64.iss 2023-09-23 18:35:48 +02:00
Kim Kulling 997d380c3a Update script_vieweronly.iss 2023-09-23 18:35:48 +02:00
Kim Kulling 13945a5c5b Update CMakeLists.txt 2023-09-23 18:35:48 +02:00
13 changed files with 396 additions and 35 deletions

View File

@ -49,13 +49,13 @@ option(ASSIMP_HUNTER_ENABLED "Enable Hunter package manager support" OFF)
IF(ASSIMP_HUNTER_ENABLED)
include("cmake-modules/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.24.17.tar.gz"
SHA1 "e6396699e414120e32557fe92db097b7655b760b"
URL "https://github.com/cpp-pm/hunter/archive/v0.24.18.tar.gz"
SHA1 "1292e4d661e1770d6d6ca08c12c07cf34a0bf718"
)
add_definitions(-DASSIMP_USE_HUNTER)
ENDIF()
PROJECT(Assimp VERSION 5.2.6)
PROJECT(Assimp VERSION 5.3.0)
# All supported options ###############################################
@ -777,7 +777,7 @@ IF ( ASSIMP_INSTALL )
SET(CPACK_DEBIAN_PACKAGE_SECTION "libs" )
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_COMPONENTS_ALL}")
SET(CPACK_DEBIAN_PACKAGE_SUGGESTS)
SET(cPACK_DEBIAN_PACKAGE_NAME "assimp")
SET(CPACK_DEBIAN_PACKAGE_NAME "assimp")
SET(CPACK_DEBIAN_PACKAGE_REMOVE_SOURCE_FILES contrib/gtest contrib/zlib workspaces test doc obj samples packaging)
SET(CPACK_DEBIAN_PACKAGE_SOURCE_COPY svn export --force)
SET(CPACK_DEBIAN_CHANGELOG)

View File

@ -0,0 +1,293 @@
#ifndef ASSIMP_BUILD_NO_FEZ_IMPORTER
#include "FezLoader.h"
#include <filesystem>
#include <assimp/Importer.hpp>
#include <assimp/DefaultLogger.hpp>
#include <assimp/importerdesc.h>
#include <assimp/ParsingUtils.h>
#include <assimp/XmlParser.h>
#include <assimp/IOSystem.hpp>
#include <assimp/scene.h>
namespace Assimp {
static const aiImporterDesc desc = {
"FEZ Importer",
"Kayden",
"",
"Unfinished.",
aiImporterFlags_Experimental | aiImporterFlags_LimitedSupport | aiImporterFlags_SupportTextFlavour,
0,
0,
0,
0,
"xml",
};
static const aiVector3D gc_normals[] = { {-1.f, 0.f, 0.f}, {0.f, -1.f, 0.f}, {0.f, 0.f, -1.f},
{1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 0.f, 1.f} };
static const ai_real gc_orient[] = {
AI_MATH_PI, -AI_MATH_HALF_PI, 0,AI_MATH_HALF_PI,
};
FezLoader::FezLoader() = default;
FezLoader::~FezLoader() = default;
bool FezLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool) const {
// TODO: Read single art objects too
static const char *tokens[] = { "<Level" };
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens));
}
const aiImporterDesc *FezLoader::GetInfo() const {
return &desc;
};
void FezLoader::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
// Store filename
mFileName = pFile;
// Find asset directory (two levels up)
mFezAssetDir = std::filesystem::path(pFile).parent_path().parent_path();
// Open file for reading
std::unique_ptr<IOStream> levelFile;
levelFile.reset(pIOHandler->Open(pFile));
// generate a XML reader for it
if (!mLevelParser.parse(levelFile.get())) {
throw DeadlyImportError("Unable to read level file, malformed XML");
}
// Load trile sets
auto levelRoot = mLevelParser.getRootNode().child("Level");
auto levelName = std::string(levelRoot.attribute("name").as_string());
// Fill in root node
pScene->mRootNode = new aiNode(levelName);
// Get trile set name in lowercase (all the files from export are lowercased)
auto trileSetName = std::string(levelRoot.attribute("trileSetName").as_string());
trileSetName = ai_tolower(trileSetName);
// Find and read trile set XML file
std::unique_ptr<IOStream> trileFile;
trileFile.reset(pIOHandler->Open(mFezAssetDir / "trile sets" / (trileSetName + ".xml")));
if (!mTrileParser.parse(trileFile.get())) {
throw DeadlyImportError("Unable to read trile file, malformed XML");
}
ASSIMP_LOG_VERBOSE_DEBUG("Parsed trile set ", mTrileParser.getRootNode().child("TrileSet").attribute("name").as_string());
// Place triles and their XML nodes into map
auto triles = mTrileParser.getRootNode().child("TrileSet").child("Triles");
for (auto t : triles.children()) {
if (std::string(t.name()) != "TrileEntry") {
ASSIMP_LOG_WARN("Unknown tag found in TrileSet XML.");
continue;
}
auto key = t.attribute("key").as_int(-1);
if (key == -1) {
ASSIMP_LOG_ERROR("Trile found with an invalid key or non-int key. This could be bad!");
continue;
}
auto trile = t.child("Trile");
if (mTriles.count(key)) {
ASSIMP_LOG_WARN("Duplicate trile key found, skipping...");
continue;
}
mTriles[key] = trile;
}
ASSIMP_LOG_VERBOSE_DEBUG("Loaded ", mTriles.size(), " triles from the set.");
// Create children, one for the triles
auto trileRoot = new aiNode("Triles");
pScene->mRootNode->addChildren(1, &trileRoot);
// Begin filling out trile emplacements
auto xmlTrileT = levelRoot.child("Triles");
for (auto t : xmlTrileT.children()) {
if (std::string(t.name()) != "Entry") {
ASSIMP_LOG_WARN("Unknown tag found in Level Triles XML.");
continue;
}
auto instance = t.child("TrileInstance");
if (instance.empty()) {
ASSIMP_LOG_WARN("Trile instance not found in a node.");
continue;
}
auto trileID = instance.attribute("trileId").as_int(-1);
if (trileID == -1) {
ASSIMP_LOG_WARN("Trile instance found without a valid trileId!");
continue;
}
auto meshID = GetTrileMeshFromId(trileID);
// Create node, link found mesh
auto trileNode = new aiNode();
trileNode->mNumMeshes = 1;
trileNode->mMeshes = new unsigned int[1];
trileNode->mMeshes[0] = meshID;
auto pos = GetFezVec3(instance.child("Position"));
auto orient = instance.attribute("orientation").as_int(0);
// Create transformation matrix
aiMatrix4x4 transform = aiMatrix4x4::Translation(pos, transform);
aiMatrix4x4 rotate = aiMatrix4x4::RotationY(gc_orient[orient], rotate);
trileNode->mTransformation = transform * rotate;
trileRoot->addChildren(1, &trileNode);
}
// Fill in meshes from vector
pScene->mNumMeshes = mTrileMeshes.size();
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
for (int i = 0; i < mTrileMeshes.size(); i++) {
pScene->mMeshes[i] = mTrileMeshes[i];
}
// Create material
pScene->mNumMaterials = 1;
pScene->mMaterials = new aiMaterial * [1];
auto myMat = new aiMaterial();
aiString matName("TrileSet");
myMat->AddProperty(&matName, AI_MATKEY_NAME);
aiString texturePath(std::string(mFezAssetDir / "trile sets" / (trileSetName + ".png")));
// Create embedded texture ref
auto trileTex = new aiTexture();
trileTex->mFilename = texturePath;
// PNG file, compressed
strcpy(trileTex->achFormatHint, "png");
trileTex->mHeight = 0;
// Open texture file for reading
std::unique_ptr<IOStream> texFile;
texFile.reset(pIOHandler->Open(mFezAssetDir / "trile sets" / (trileSetName + ".png")));
// Create buffer, read data, store into texture instance
auto texDat = new unsigned char[texFile->FileSize()];
trileTex->mWidth = texFile->FileSize();
texFile->Read(texDat, 1, texFile->FileSize());
trileTex->pcData = (aiTexel*)texDat;
// Store embedded texture into scene
pScene->mNumTextures = 1;
pScene->mTextures = new aiTexture *[1];
pScene->mTextures[0] = trileTex;
// Put ref into material
aiString tName("*0");
myMat->AddProperty(&tName, AI_MATKEY_TEXTURE(aiTextureType_BASE_COLOR, 0));
//store material in scene
pScene->mMaterials[0] = myMat;
}
unsigned int FezLoader::GetTrileMeshFromId(const int trileId) {
if (auto search = mTrileMap.find(trileId); search != mTrileMap.end()) {
return search->second;
}
// We need to create an aiMesh instance and add it to the vector.
auto trileXML = mTriles.at(trileId);
auto mesh = new aiMesh();
auto xmlSIIP = trileXML.child("Geometry").child("ShaderInstancedIndexedPrimitives");
// TODO: check type="TriangleList"
auto xmlVerts = xmlSIIP.child("Vertices");
auto xmlIdx = xmlSIIP.child("Indices");
struct vpnti {
aiVector3D pos;
int normal;
aiVector3D texCoord;
};
std::vector<vpnti> vertex;
// TODO: check handedness/orientation
for (auto v : xmlVerts.children()) {
auto pos = GetFezVec3(v.child("Position"));
auto normal = v.child("Normal").text().as_int();
auto texCoord = GetFezVec3(v.child("TextureCoord").child("Vector2"), true);
texCoord.y = 1 - texCoord.y;
vertex.push_back({pos, normal, texCoord});
}
// Collect indices into array
std::vector<unsigned int> idx;
for (auto i : xmlIdx.children()) {
auto id = i.text().as_uint();
idx.push_back(id);
}
// Populate mFaces with all triangles
mesh->mNumFaces = idx.size() / 3;
mesh->mFaces = new aiFace[mesh->mNumFaces];
// Iterate in sets of 3s.
for (int i = 0; i < idx.size(); i += 3) {
mesh->mFaces[i/3].mNumIndices = 3;
mesh->mFaces[i/3].mIndices = new unsigned int[3] {
idx.at(i),
idx.at(i+2),
idx.at(i+1),
};
}
// Now populate vertices
mesh->mNumVertices = vertex.size();
mesh->mVertices = new aiVector3D[vertex.size()];
mesh->mNormals = new aiVector3D[vertex.size()];
mesh->mTextureCoords[0] = new aiVector3D[vertex.size()];
for (int i = 0; i < vertex.size(); i++) {
auto v = vertex.at(i);
mesh->mVertices[i] = v.pos;
mesh->mNormals[i] = gc_normals[v.normal];
mesh->mTextureCoords[0][i] = v.texCoord;
}
// Only one material for all triles.
mesh->mMaterialIndex = 0;
// Add entry to trile map and add mesh to vector
mTrileMap[trileId] = mTrileMeshes.size();
mTrileMeshes.push_back(mesh);
return mTrileMap[trileId];
}
aiVector3D FezLoader::GetFezVec3(const XmlNode &t, bool direct) {
if (direct) {
return {t.attribute("x").as_float(), t.attribute("y").as_float(), t.attribute("z").as_float()};
} else {
auto c = t.child("Vector3");
return {c.attribute("x").as_float(), c.attribute("y").as_float(), c.attribute("z").as_float()};
}
}
aiVector2D FezLoader::GetFezVec2(const XmlNode &t, bool direct) {
if (direct) {
return {t.attribute("x").as_float(), t.attribute("y").as_float()};
} else {
auto c = t.child("Vector2");
return {c.attribute("x").as_float(), c.attribute("y").as_float()};
}
}
}
#endif

View File

@ -0,0 +1,40 @@
#ifndef AI_FEZLOADER_H_INC
#define AI_FEZLOADER_H_INC
#include <assimp/BaseImporter.h>
#include <assimp/XmlParser.h>
#include <assimp/mesh.h>
#include <map>
#include <filesystem>
namespace Assimp {
class FezLoader : public BaseImporter {
public:
FezLoader();
~FezLoader() override;
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const override;
protected:
const aiImporterDesc *GetInfo() const override;
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
unsigned int GetTrileMeshFromId(const int trileId);
aiVector3D GetFezVec3(const XmlNode &t, bool direct = false);
aiVector2D GetFezVec2(const XmlNode &t, bool direct = false);
private:
std::filesystem::path mFezAssetDir;
std::string mFileName;
XmlParser mLevelParser;
XmlParser mTrileParser;
std::map<int, XmlNode> mTriles;
std::map<int, unsigned int> mTrileMap;
std::vector<aiMesh*> mTrileMeshes;
};
}
#endif

View File

@ -0,0 +1,8 @@
//
// Created by Kayden Tebau on 2023-10-18.
//
#ifndef ASSIMP_BUILD_NO_FEZ_IMPORTER
#include "FezParser.h"
#endif

View File

@ -0,0 +1,13 @@
//
// Created by Kayden Tebau on 2023-10-18.
//
#ifndef ASSIMP_FEZPARSER_H
#define ASSIMP_FEZPARSER_H
namespace Assimp {
class FezParser {
};
}
#endif // ASSIMP_FEZPARSER_H

View File

@ -364,6 +364,13 @@ ADD_ASSIMP_IMPORTER( COLLADA
AssetLib/Collada/ColladaParser.h
)
ADD_ASSIMP_IMPORTER( FEZ
AssetLib/FEZ/FezLoader.cpp
AssetLib/FEZ/FezLoader.h
AssetLib/FEZ/FezParser.cpp
AssetLib/FEZ/FezParser.h
)
ADD_ASSIMP_IMPORTER( DXF
AssetLib/DXF/DXFLoader.cpp
AssetLib/DXF/DXFLoader.h

View File

@ -55,6 +55,9 @@ corresponding preprocessor flag to selectively disable formats.
// Importers
// (include_new_importers_here)
// ------------------------------------------------------------------------------------------------
#ifndef ASSIMP_BUILD_NO_FEZ_IMPORTER
#include "AssetLib/FEZ/FezLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_X_IMPORTER
#include "AssetLib/X/XFileImporter.h"
#endif
@ -230,6 +233,9 @@ void GetImporterInstanceList(std::vector<BaseImporter *> &out) {
// (register_new_importers_here)
// ----------------------------------------------------------------------------
out.reserve(64);
#if (!defined ASSIMP_BUILD_NO_FEZ_IMPORTER)
out.push_back(new FezLoader());
#endif
#if (!defined ASSIMP_BUILD_NO_X_IMPORTER)
out.push_back(new XFileImporter());
#endif

View File

@ -83,9 +83,9 @@ typedef long ssize_t; /* byte count or error */
#define ZIP_EFWRITE -29 // fwrite error
/**
* Looks up the error message string coresponding to an error number.
* Looks up the error message string corresponding to an error number.
* @param errnum error number
* @return error message string coresponding to errnum or NULL if error is not
* @return error message string corresponding to errnum or NULL if error is not
* found.
*/
extern const char *zip_strerror(int errnum);

View File

@ -73,14 +73,8 @@ typedef uint32_t ai_uint32;
#ifdef __cplusplus
#ifdef ASSIMP_USE_HUNTER
# include <utf8.h>
#else
# include "../contrib/utf8cpp/source/utf8.h"
#endif
#include <cstring>
#include <new> // for std::nothrow_t
#include <new> // for std::nothrow_t
#include <string> // for aiString::Set(const std::string&)
namespace Assimp {
@ -88,16 +82,16 @@ namespace Assimp {
namespace Intern {
// --------------------------------------------------------------------
/** @brief Internal helper class to utilize our internal new/delete
* routines for allocating object of this and derived classes.
*
* By doing this you can safely share class objects between Assimp
* and the application - it works even over DLL boundaries. A good
* example is the #IOSystem where the application allocates its custom
* #IOSystem, then calls #Importer::SetIOSystem(). When the Importer
* destructs, Assimp calls operator delete on the stored #IOSystem.
* If it lies on a different heap than Assimp is working with,
* the application is determined to crash.
*/
* routines for allocating object of this and derived classes.
*
* By doing this you can safely share class objects between Assimp
* and the application - it works even over DLL boundaries. A good
* example is the #IOSystem where the application allocates its custom
* #IOSystem, then calls #Importer::SetIOSystem(). When the Importer
* destructs, Assimp calls operator delete on the stored #IOSystem.
* If it lies on a different heap than Assimp is working with,
* the application is determined to crash.
*/
// --------------------------------------------------------------------
#ifndef SWIG
struct ASSIMP_API AllocateFromAssimpHeap {

View File

@ -2,7 +2,7 @@
[Setup]
AppName=Open Asset Import Library - Viewer
AppVerName=Open Asset Import Library - Viewer (v5.2.6)
AppVerName=Open Asset Import Library - Viewer (v5.3.0)
DefaultDirName={pf}\AssimpView
DefaultGroupName=AssimpView
UninstallDisplayIcon={app}\bin\x86\assimp.exe
@ -13,8 +13,8 @@ WizardImageFile=compiler:WizModernImage-IS.BMP
WizardSmallImageFile=compiler:WizModernSmallImage-IS.BMP
LicenseFile=License.rtf
OutputBaseFileName=assimp-view-5.0-setup
VersionInfoVersion=5.2.6.0
VersionInfoTextVersion=5.2.6
VersionInfoVersion=5.3.0.0
VersionInfoTextVersion=5.3.0
VersionInfoCompany=Assimp Development Team
ArchitecturesInstallIn64BitMode=x64

View File

@ -2,7 +2,7 @@
[Setup]
AppName=Open Asset Import Library - SDK
AppVerName=Open Asset Import Library - SDK (v5.2.6)
AppVerName=Open Asset Import Library - SDK (v5.3.0)
DefaultDirName={pf}\Assimp
DefaultGroupName=Assimp
UninstallDisplayIcon={app}\bin\x64\assimp.exe
@ -13,8 +13,8 @@ WizardImageFile=compiler:WizModernImage-IS.BMP
WizardSmallImageFile=compiler:WizModernSmallImage-IS.BMP
LicenseFile=License.rtf
OutputBaseFileName=assimp-sdk-5.2.6-setup
VersionInfoVersion=5.2.6.0
VersionInfoTextVersion=5.2.6
VersionInfoVersion=5.3.0.0
VersionInfoTextVersion=5.3.0
VersionInfoCompany=Assimp Development Team
ArchitecturesInstallIn64BitMode=x64

View File

@ -2,7 +2,7 @@
[Setup]
AppName=Open Asset Import Library - SDK
AppVerName=Open Asset Import Library - SDK (v5.2.6)
AppVerName=Open Asset Import Library - SDK (v5.3.0)
DefaultDirName={pf}\Assimp
DefaultGroupName=Assimp
UninstallDisplayIcon={app}\bin\x86\assimp.exe
@ -13,8 +13,8 @@ WizardImageFile=compiler:WizModernImage-IS.BMP
WizardSmallImageFile=compiler:WizModernSmallImage-IS.BMP
LicenseFile=License.rtf
OutputBaseFileName=assimp-sdk-5.2.6-setup
VersionInfoVersion=5.2.5.6
VersionInfoTextVersion=5.2.6
VersionInfoVersion=5.3.0.
VersionInfoTextVersion=5.3.0
VersionInfoCompany=Assimp Development Team
;ArchitecturesInstallIn64BitMode=x64

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2023, assimp team
All rights reserved.
@ -53,7 +53,7 @@ TEST_F( utVersion, aiGetLegalStringTest ) {
}
TEST_F( utVersion, aiGetVersionMinorTest ) {
EXPECT_EQ(aiGetVersionMinor(), 2U);
EXPECT_EQ(aiGetVersionMinor(), 3U);
}
TEST_F( utVersion, aiGetVersionMajorTest ) {
@ -61,7 +61,7 @@ TEST_F( utVersion, aiGetVersionMajorTest ) {
}
TEST_F( utVersion, aiGetVersionPatchTest ) {
EXPECT_EQ(aiGetVersionPatch(), 6U );
EXPECT_EQ(aiGetVersionPatch(), 0U );
}
TEST_F( utVersion, aiGetCompileFlagsTest ) {