apply code-conventions to unrealloader
parent
27e1a20efe
commit
9b83d74830
|
@ -51,23 +51,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "Unreal/UnrealLoader.h"
|
#include "Unreal/UnrealLoader.h"
|
||||||
#include "PostProcessing/ConvertToLHProcess.h"
|
#include "PostProcessing/ConvertToLHProcess.h"
|
||||||
|
|
||||||
#include <assimp/StreamReader.h>
|
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
|
#include <assimp/StreamReader.h>
|
||||||
#include <assimp/fast_atof.h>
|
#include <assimp/fast_atof.h>
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/importerdesc.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/importerdesc.h>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
namespace Unreal {
|
namespace Unreal {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0 = Normal one-sided
|
0 = Normal one-sided
|
||||||
1 = Normal two-sided
|
1 = Normal two-sided
|
||||||
2 = Translucent two-sided
|
2 = Translucent two-sided
|
||||||
|
@ -76,78 +76,78 @@ namespace Unreal {
|
||||||
8 = Placeholder triangle for weapon positioning (invisible)
|
8 = Placeholder triangle for weapon positioning (invisible)
|
||||||
*/
|
*/
|
||||||
enum MeshFlags {
|
enum MeshFlags {
|
||||||
MF_NORMAL_OS = 0,
|
MF_NORMAL_OS = 0,
|
||||||
MF_NORMAL_TS = 1,
|
MF_NORMAL_TS = 1,
|
||||||
MF_NORMAL_TRANS_TS = 2,
|
MF_NORMAL_TRANS_TS = 2,
|
||||||
MF_NORMAL_MASKED_TS = 3,
|
MF_NORMAL_MASKED_TS = 3,
|
||||||
MF_NORMAL_MOD_TS = 4,
|
MF_NORMAL_MOD_TS = 4,
|
||||||
MF_WEAPON_PLACEHOLDER = 8
|
MF_WEAPON_PLACEHOLDER = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
// a single triangle
|
// a single triangle
|
||||||
struct Triangle {
|
struct Triangle {
|
||||||
uint16_t mVertex[3]; // Vertex indices
|
uint16_t mVertex[3]; // Vertex indices
|
||||||
char mType; // James' Mesh Type
|
char mType; // James' Mesh Type
|
||||||
char mColor; // Color for flat and Gourand Shaded
|
char mColor; // Color for flat and Gourand Shaded
|
||||||
unsigned char mTex[3][2]; // Texture UV coordinates
|
unsigned char mTex[3][2]; // Texture UV coordinates
|
||||||
unsigned char mTextureNum; // Source texture offset
|
unsigned char mTextureNum; // Source texture offset
|
||||||
char mFlags; // Unreal Mesh Flags (unused)
|
char mFlags; // Unreal Mesh Flags (unused)
|
||||||
unsigned int matIndex;
|
unsigned int matIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
// temporary representation for a material
|
// temporary representation for a material
|
||||||
struct TempMat {
|
struct TempMat {
|
||||||
TempMat() :
|
TempMat() :
|
||||||
type(), tex(), numFaces(0) {}
|
type(MF_NORMAL_OS), tex(), numFaces(0) {}
|
||||||
|
|
||||||
explicit TempMat(const Triangle &in) :
|
explicit TempMat(const Triangle &in) :
|
||||||
type((Unreal::MeshFlags)in.mType), tex(in.mTextureNum), numFaces(0) {}
|
type((Unreal::MeshFlags)in.mType), tex(in.mTextureNum), numFaces(0) {}
|
||||||
|
|
||||||
// type of mesh
|
// type of mesh
|
||||||
Unreal::MeshFlags type;
|
Unreal::MeshFlags type;
|
||||||
|
|
||||||
// index of texture
|
// index of texture
|
||||||
unsigned int tex;
|
unsigned int tex;
|
||||||
|
|
||||||
// number of faces using us
|
// number of faces using us
|
||||||
unsigned int numFaces;
|
unsigned int numFaces;
|
||||||
|
|
||||||
// for std::find
|
// for std::find
|
||||||
bool operator==(const TempMat &o) {
|
bool operator==(const TempMat &o) {
|
||||||
return (tex == o.tex && type == o.type);
|
return (tex == o.tex && type == o.type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
int32_t X : 11;
|
int32_t X : 11;
|
||||||
int32_t Y : 11;
|
int32_t Y : 11;
|
||||||
int32_t Z : 10;
|
int32_t Z : 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
// UNREAL vertex compression
|
// UNREAL vertex compression
|
||||||
inline void CompressVertex(const aiVector3D &v, uint32_t &out) {
|
inline void CompressVertex(const aiVector3D &v, uint32_t &out) {
|
||||||
union {
|
union {
|
||||||
Vertex n;
|
Vertex n;
|
||||||
int32_t t;
|
int32_t t;
|
||||||
};
|
};
|
||||||
t = 0;
|
t = 0;
|
||||||
n.X = (int32_t)v.x;
|
n.X = (int32_t)v.x;
|
||||||
n.Y = (int32_t)v.y;
|
n.Y = (int32_t)v.y;
|
||||||
n.Z = (int32_t)v.z;
|
n.Z = (int32_t)v.z;
|
||||||
::memcpy(&out, &t, sizeof(int32_t));
|
::memcpy(&out, &t, sizeof(int32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// UNREAL vertex decompression
|
// UNREAL vertex decompression
|
||||||
inline void DecompressVertex(aiVector3D &v, int32_t in) {
|
inline void DecompressVertex(aiVector3D &v, int32_t in) {
|
||||||
union {
|
union {
|
||||||
Vertex n;
|
Vertex n;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
};
|
};
|
||||||
i = in;
|
i = in;
|
||||||
|
|
||||||
v.x = (float)n.X;
|
v.x = (float)n.X;
|
||||||
v.y = (float)n.Y;
|
v.y = (float)n.Y;
|
||||||
v.z = (float)n.Z;
|
v.z = (float)n.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Unreal
|
} // end namespace Unreal
|
||||||
|
@ -165,79 +165,70 @@ static const aiImporterDesc desc = {
|
||||||
"3d uc"
|
"3d uc"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
UnrealImporter::UnrealImporter()
|
UnrealImporter::UnrealImporter() :
|
||||||
: configFrameID (0)
|
mConfigFrameID(0), mConfigHandleFlags(true) {}
|
||||||
, configHandleFlags (true)
|
|
||||||
{}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Destructor, private as well
|
// Destructor, private as well
|
||||||
UnrealImporter::~UnrealImporter()
|
UnrealImporter::~UnrealImporter() {}
|
||||||
{}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
bool UnrealImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
|
bool UnrealImporter::CanRead(const std::string &pFile, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const {
|
||||||
{
|
return SimpleExtensionCheck(pFile, "3d", "uc");
|
||||||
return SimpleExtensionCheck(pFile,"3d","uc");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Build a string of all file extensions supported
|
// Build a string of all file extensions supported
|
||||||
const aiImporterDesc* UnrealImporter::GetInfo () const
|
const aiImporterDesc *UnrealImporter::GetInfo() const {
|
||||||
{
|
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Setup configuration properties for the loader
|
// Setup configuration properties for the loader
|
||||||
void UnrealImporter::SetupProperties(const Importer* pImp)
|
void UnrealImporter::SetupProperties(const Importer *pImp) {
|
||||||
{
|
|
||||||
// The
|
// The
|
||||||
// AI_CONFIG_IMPORT_UNREAL_KEYFRAME option overrides the
|
// AI_CONFIG_IMPORT_UNREAL_KEYFRAME option overrides the
|
||||||
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
||||||
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_KEYFRAME,-1);
|
mConfigFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_KEYFRAME, -1);
|
||||||
if(static_cast<unsigned int>(-1) == configFrameID) {
|
if (static_cast<unsigned int>(-1) == mConfigFrameID) {
|
||||||
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
|
mConfigFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, default is true
|
// AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, default is true
|
||||||
configHandleFlags = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS,1));
|
mConfigHandleFlags = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void UnrealImporter::InternReadFile( const std::string& pFile,
|
void UnrealImporter::InternReadFile(const std::string &pFile,
|
||||||
aiScene* pScene, IOSystem* pIOHandler)
|
aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
{
|
|
||||||
// For any of the 3 files being passed get the three correct paths
|
// For any of the 3 files being passed get the three correct paths
|
||||||
// First of all, determine file extension
|
// First of all, determine file extension
|
||||||
std::string::size_type pos = pFile.find_last_of('.');
|
std::string::size_type pos = pFile.find_last_of('.');
|
||||||
std::string extension = GetExtension(pFile);
|
std::string extension = GetExtension(pFile);
|
||||||
|
|
||||||
std::string d_path,a_path,uc_path;
|
std::string d_path, a_path, uc_path;
|
||||||
if (extension == "3d") {
|
if (extension == "3d") {
|
||||||
// jjjj_d.3d
|
// jjjj_d.3d
|
||||||
// jjjj_a.3d
|
// jjjj_a.3d
|
||||||
pos = pFile.find_last_of('_');
|
pos = pFile.find_last_of('_');
|
||||||
if (std::string::npos == pos) {
|
if (std::string::npos == pos) {
|
||||||
throw DeadlyImportError("UNREAL: Unexpected naming scheme");
|
throw DeadlyImportError("UNREAL: Unexpected naming scheme");
|
||||||
}
|
}
|
||||||
extension = pFile.substr(0,pos);
|
extension = pFile.substr(0, pos);
|
||||||
}
|
} else {
|
||||||
else {
|
extension = pFile.substr(0, pos);
|
||||||
extension = pFile.substr(0,pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// build proper paths
|
// build proper paths
|
||||||
d_path = extension+"_d.3d";
|
d_path = extension + "_d.3d";
|
||||||
a_path = extension+"_a.3d";
|
a_path = extension + "_a.3d";
|
||||||
uc_path = extension+".uc";
|
uc_path = extension + ".uc";
|
||||||
|
|
||||||
ASSIMP_LOG_DEBUG_F( "UNREAL: data file is ", d_path);
|
ASSIMP_LOG_DEBUG_F("UNREAL: data file is ", d_path);
|
||||||
ASSIMP_LOG_DEBUG_F("UNREAL: aniv file is ", a_path);
|
ASSIMP_LOG_DEBUG_F("UNREAL: aniv file is ", a_path);
|
||||||
ASSIMP_LOG_DEBUG_F("UNREAL: uc file is ", uc_path);
|
ASSIMP_LOG_DEBUG_F("UNREAL: uc file is ", uc_path);
|
||||||
|
|
||||||
|
@ -258,11 +249,11 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
|
|
||||||
// collect triangles
|
// collect triangles
|
||||||
std::vector<Unreal::Triangle> triangles(numTris);
|
std::vector<Unreal::Triangle> triangles(numTris);
|
||||||
for (auto & tri : triangles) {
|
for (auto &tri : triangles) {
|
||||||
for (unsigned int i = 0; i < 3;++i) {
|
for (unsigned int i = 0; i < 3; ++i) {
|
||||||
|
|
||||||
tri.mVertex[i] = d_reader.GetI2();
|
tri.mVertex[i] = d_reader.GetI2();
|
||||||
if (tri.mVertex[i] >= numTris) {
|
if (tri.mVertex[i] >= numTris) {
|
||||||
ASSIMP_LOG_WARN("UNREAL: vertex index out of range");
|
ASSIMP_LOG_WARN("UNREAL: vertex index out of range");
|
||||||
tri.mVertex[i] = 0;
|
tri.mVertex[i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +261,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
tri.mType = d_reader.GetI1();
|
tri.mType = d_reader.GetI1();
|
||||||
|
|
||||||
// handle mesh flagss?
|
// handle mesh flagss?
|
||||||
if (configHandleFlags)
|
if (mConfigHandleFlags)
|
||||||
tri.mType = Unreal::MF_NORMAL_OS;
|
tri.mType = Unreal::MF_NORMAL_OS;
|
||||||
else {
|
else {
|
||||||
// ignore MOD and MASKED for the moment, treat them as two-sided
|
// ignore MOD and MASKED for the moment, treat them as two-sided
|
||||||
|
@ -279,12 +270,12 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
d_reader.IncPtr(1);
|
d_reader.IncPtr(1);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 3;++i)
|
for (unsigned int i = 0; i < 3; ++i)
|
||||||
for (unsigned int i2 = 0; i2 < 2;++i2)
|
for (unsigned int i2 = 0; i2 < 2; ++i2)
|
||||||
tri.mTex[i][i2] = d_reader.GetI1();
|
tri.mTex[i][i2] = d_reader.GetI1();
|
||||||
|
|
||||||
tri.mTextureNum = d_reader.GetI1();
|
tri.mTextureNum = d_reader.GetI1();
|
||||||
maxTexIdx = std::max(maxTexIdx,(unsigned int)tri.mTextureNum);
|
maxTexIdx = std::max(maxTexIdx, (unsigned int)tri.mTextureNum);
|
||||||
d_reader.IncPtr(1);
|
d_reader.IncPtr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,63 +286,64 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
|
|
||||||
// read number of frames
|
// read number of frames
|
||||||
const uint32_t numFrames = a_reader.GetI2();
|
const uint32_t numFrames = a_reader.GetI2();
|
||||||
if (configFrameID >= numFrames) {
|
if (mConfigFrameID >= numFrames) {
|
||||||
throw DeadlyImportError("UNREAL: The requested frame does not exist");
|
throw DeadlyImportError("UNREAL: The requested frame does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t st = a_reader.GetI2();
|
uint32_t st = a_reader.GetI2();
|
||||||
if (st != numVert*4u)
|
if (st != numVert * 4u)
|
||||||
throw DeadlyImportError("UNREAL: Unexpected aniv file length");
|
throw DeadlyImportError("UNREAL: Unexpected aniv file length");
|
||||||
|
|
||||||
// skip to our frame
|
// skip to our frame
|
||||||
a_reader.IncPtr(configFrameID *numVert*4);
|
a_reader.IncPtr(mConfigFrameID * numVert * 4);
|
||||||
|
|
||||||
// collect vertices
|
// collect vertices
|
||||||
std::vector<aiVector3D> vertices(numVert);
|
std::vector<aiVector3D> vertices(numVert);
|
||||||
for (auto &vertex : vertices) {
|
for (auto &vertex : vertices) {
|
||||||
int32_t val = a_reader.GetI4();
|
int32_t val = a_reader.GetI4();
|
||||||
Unreal::DecompressVertex(vertex ,val);
|
Unreal::DecompressVertex(vertex, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
// list of textures.
|
// list of textures.
|
||||||
std::vector< std::pair<unsigned int, std::string> > textures;
|
std::vector<std::pair<unsigned int, std::string>> textures;
|
||||||
|
|
||||||
// allocate the output scene
|
// allocate the output scene
|
||||||
aiNode* nd = pScene->mRootNode = new aiNode();
|
aiNode *nd = pScene->mRootNode = new aiNode();
|
||||||
nd->mName.Set("<UnrealRoot>");
|
nd->mName.Set("<UnrealRoot>");
|
||||||
|
|
||||||
// we can live without the uc file if necessary
|
// we can live without the uc file if necessary
|
||||||
std::unique_ptr<IOStream> pb (pIOHandler->Open(uc_path));
|
std::unique_ptr<IOStream> pb(pIOHandler->Open(uc_path));
|
||||||
if (pb.get()) {
|
if (pb.get()) {
|
||||||
|
|
||||||
std::vector<char> _data;
|
std::vector<char> _data;
|
||||||
TextFileToBuffer(pb.get(),_data);
|
TextFileToBuffer(pb.get(), _data);
|
||||||
const char* data = &_data[0];
|
const char *data = &_data[0];
|
||||||
|
|
||||||
std::vector< std::pair< std::string,std::string > > tempTextures;
|
std::vector<std::pair<std::string, std::string>> tempTextures;
|
||||||
|
|
||||||
// do a quick search in the UC file for some known, usually texture-related, tags
|
// do a quick search in the UC file for some known, usually texture-related, tags
|
||||||
for (;*data;++data) {
|
for (; *data; ++data) {
|
||||||
if (TokenMatchI(data,"#exec",5)) {
|
if (TokenMatchI(data, "#exec", 5)) {
|
||||||
SkipSpacesAndLineEnd(&data);
|
SkipSpacesAndLineEnd(&data);
|
||||||
|
|
||||||
// #exec TEXTURE IMPORT [...] NAME=jjjjj [...] FILE=jjjj.pcx [...]
|
// #exec TEXTURE IMPORT [...] NAME=jjjjj [...] FILE=jjjj.pcx [...]
|
||||||
if (TokenMatchI(data,"TEXTURE",7)) {
|
if (TokenMatchI(data, "TEXTURE", 7)) {
|
||||||
SkipSpacesAndLineEnd(&data);
|
SkipSpacesAndLineEnd(&data);
|
||||||
|
|
||||||
if (TokenMatchI(data,"IMPORT",6)) {
|
if (TokenMatchI(data, "IMPORT", 6)) {
|
||||||
tempTextures.push_back(std::pair< std::string,std::string >());
|
tempTextures.push_back(std::pair<std::string, std::string>());
|
||||||
std::pair< std::string,std::string >& me = tempTextures.back();
|
std::pair<std::string, std::string> &me = tempTextures.back();
|
||||||
for (;!IsLineEnd(*data);++data) {
|
for (; !IsLineEnd(*data); ++data) {
|
||||||
if (!::ASSIMP_strincmp(data,"NAME=",5)) {
|
if (!::ASSIMP_strincmp(data, "NAME=", 5)) {
|
||||||
const char *d = data+=5;
|
const char *d = data += 5;
|
||||||
for (;!IsSpaceOrNewLine(*data);++data);
|
for (; !IsSpaceOrNewLine(*data); ++data)
|
||||||
me.first = std::string(d,(size_t)(data-d));
|
;
|
||||||
}
|
me.first = std::string(d, (size_t)(data - d));
|
||||||
else if (!::ASSIMP_strincmp(data,"FILE=",5)) {
|
} else if (!::ASSIMP_strincmp(data, "FILE=", 5)) {
|
||||||
const char *d = data+=5;
|
const char *d = data += 5;
|
||||||
for (;!IsSpaceOrNewLine(*data);++data);
|
for (; !IsSpaceOrNewLine(*data); ++data)
|
||||||
me.second = std::string(d,(size_t)(data-d));
|
;
|
||||||
|
me.second = std::string(d, (size_t)(data - d));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!me.first.length() || !me.second.length())
|
if (!me.first.length() || !me.second.length())
|
||||||
|
@ -360,65 +352,61 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
// #exec MESHMAP SETTEXTURE MESHMAP=box NUM=1 TEXTURE=Jtex1
|
// #exec MESHMAP SETTEXTURE MESHMAP=box NUM=1 TEXTURE=Jtex1
|
||||||
// #exec MESHMAP SCALE MESHMAP=box X=0.1 Y=0.1 Z=0.2
|
// #exec MESHMAP SCALE MESHMAP=box X=0.1 Y=0.1 Z=0.2
|
||||||
else if (TokenMatchI(data,"MESHMAP",7)) {
|
else if (TokenMatchI(data, "MESHMAP", 7)) {
|
||||||
SkipSpacesAndLineEnd(&data);
|
SkipSpacesAndLineEnd(&data);
|
||||||
|
|
||||||
if (TokenMatchI(data,"SETTEXTURE",10)) {
|
if (TokenMatchI(data, "SETTEXTURE", 10)) {
|
||||||
|
|
||||||
textures.push_back(std::pair<unsigned int, std::string>());
|
textures.push_back(std::pair<unsigned int, std::string>());
|
||||||
std::pair<unsigned int, std::string>& me = textures.back();
|
std::pair<unsigned int, std::string> &me = textures.back();
|
||||||
|
|
||||||
for (;!IsLineEnd(*data);++data) {
|
for (; !IsLineEnd(*data); ++data) {
|
||||||
if (!::ASSIMP_strincmp(data,"NUM=",4)) {
|
if (!::ASSIMP_strincmp(data, "NUM=", 4)) {
|
||||||
data += 4;
|
data += 4;
|
||||||
me.first = strtoul10(data,&data);
|
me.first = strtoul10(data, &data);
|
||||||
}
|
} else if (!::ASSIMP_strincmp(data, "TEXTURE=", 8)) {
|
||||||
else if (!::ASSIMP_strincmp(data,"TEXTURE=",8)) {
|
|
||||||
data += 8;
|
data += 8;
|
||||||
const char *d = data;
|
const char *d = data;
|
||||||
for (;!IsSpaceOrNewLine(*data);++data);
|
for (; !IsSpaceOrNewLine(*data); ++data)
|
||||||
me.second = std::string(d,(size_t)(data-d));
|
;
|
||||||
|
me.second = std::string(d, (size_t)(data - d));
|
||||||
|
|
||||||
// try to find matching path names, doesn't care if we don't find them
|
// try to find matching path names, doesn't care if we don't find them
|
||||||
for (std::vector< std::pair< std::string,std::string > >::const_iterator it = tempTextures.begin();
|
for (std::vector<std::pair<std::string, std::string>>::const_iterator it = tempTextures.begin();
|
||||||
it != tempTextures.end(); ++it) {
|
it != tempTextures.end(); ++it) {
|
||||||
if ((*it).first == me.second) {
|
if ((*it).first == me.second) {
|
||||||
me.second = (*it).second;
|
me.second = (*it).second;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (TokenMatchI(data, "SCALE", 5)) {
|
||||||
else if (TokenMatchI(data,"SCALE",5)) {
|
|
||||||
|
|
||||||
for (;!IsLineEnd(*data);++data) {
|
for (; !IsLineEnd(*data); ++data) {
|
||||||
if (data[0] == 'X' && data[1] == '=') {
|
if (data[0] == 'X' && data[1] == '=') {
|
||||||
data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.a1);
|
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.a1);
|
||||||
}
|
} else if (data[0] == 'Y' && data[1] == '=') {
|
||||||
else if (data[0] == 'Y' && data[1] == '=') {
|
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.b2);
|
||||||
data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.b2);
|
} else if (data[0] == 'Z' && data[1] == '=') {
|
||||||
}
|
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.c3);
|
||||||
else if (data[0] == 'Z' && data[1] == '=') {
|
|
||||||
data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.c3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ASSIMP_LOG_ERROR("Unable to open .uc file");
|
ASSIMP_LOG_ERROR("Unable to open .uc file");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Unreal::TempMat> materials;
|
std::vector<Unreal::TempMat> materials;
|
||||||
materials.reserve(textures.size()*2+5);
|
materials.reserve(textures.size() * 2 + 5);
|
||||||
|
|
||||||
// find out how many output meshes and materials we'll have and build material indices
|
// find out how many output meshes and materials we'll have and build material indices
|
||||||
for (Unreal::Triangle &tri : triangles) {
|
for (Unreal::Triangle &tri : triangles) {
|
||||||
Unreal::TempMat mat(tri);
|
Unreal::TempMat mat(tri);
|
||||||
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(),materials.end(),mat);
|
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(), materials.end(), mat);
|
||||||
if (nt == materials.end()) {
|
if (nt == materials.end()) {
|
||||||
// add material
|
// add material
|
||||||
tri.matIndex = static_cast<unsigned int>(materials.size());
|
tri.matIndex = static_cast<unsigned int>(materials.size());
|
||||||
|
@ -426,9 +414,8 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
materials.push_back(mat);
|
materials.push_back(mat);
|
||||||
|
|
||||||
++pScene->mNumMeshes;
|
++pScene->mNumMeshes;
|
||||||
}
|
} else {
|
||||||
else {
|
tri.matIndex = static_cast<unsigned int>(nt - materials.begin());
|
||||||
tri.matIndex = static_cast<unsigned int>(nt-materials.begin());
|
|
||||||
++nt->numFaces;
|
++nt->numFaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,65 +425,65 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate meshes and bind them to the node graph
|
// allocate meshes and bind them to the node graph
|
||||||
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
|
||||||
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = pScene->mNumMeshes];
|
pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials = pScene->mNumMeshes];
|
||||||
|
|
||||||
nd->mNumMeshes = pScene->mNumMeshes;
|
nd->mNumMeshes = pScene->mNumMeshes;
|
||||||
nd->mMeshes = new unsigned int[nd->mNumMeshes];
|
nd->mMeshes = new unsigned int[nd->mNumMeshes];
|
||||||
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
|
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
|
||||||
aiMesh* m = pScene->mMeshes[i] = new aiMesh();
|
aiMesh *m = pScene->mMeshes[i] = new aiMesh();
|
||||||
m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||||
|
|
||||||
const unsigned int num = materials[i].numFaces;
|
const unsigned int num = materials[i].numFaces;
|
||||||
m->mFaces = new aiFace [num];
|
m->mFaces = new aiFace[num];
|
||||||
m->mVertices = new aiVector3D [num*3];
|
m->mVertices = new aiVector3D[num * 3];
|
||||||
m->mTextureCoords[0] = new aiVector3D [num*3];
|
m->mTextureCoords[0] = new aiVector3D[num * 3];
|
||||||
|
|
||||||
nd->mMeshes[i] = i;
|
nd->mMeshes[i] = i;
|
||||||
|
|
||||||
// create materials, too
|
// create materials, too
|
||||||
aiMaterial* mat = new aiMaterial();
|
aiMaterial *mat = new aiMaterial();
|
||||||
pScene->mMaterials[i] = mat;
|
pScene->mMaterials[i] = mat;
|
||||||
|
|
||||||
// all white by default - texture rulez
|
// all white by default - texture rulez
|
||||||
aiColor3D color(1.f,1.f,1.f);
|
aiColor3D color(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
aiString s;
|
aiString s;
|
||||||
::ai_snprintf( s.data, MAXLEN, "mat%u_tx%u_",i,materials[i].tex );
|
::ai_snprintf(s.data, MAXLEN, "mat%u_tx%u_", i, materials[i].tex);
|
||||||
|
|
||||||
// set the two-sided flag
|
// set the two-sided flag
|
||||||
if (materials[i].type == Unreal::MF_NORMAL_TS) {
|
if (materials[i].type == Unreal::MF_NORMAL_TS) {
|
||||||
const int twosided = 1;
|
const int twosided = 1;
|
||||||
mat->AddProperty(&twosided,1,AI_MATKEY_TWOSIDED);
|
mat->AddProperty(&twosided, 1, AI_MATKEY_TWOSIDED);
|
||||||
::strcat(s.data,"ts_");
|
::strcat(s.data, "ts_");
|
||||||
}
|
} else
|
||||||
else ::strcat(s.data,"os_");
|
::strcat(s.data, "os_");
|
||||||
|
|
||||||
// make TRANS faces 90% opaque that RemRedundantMaterials won't catch us
|
// make TRANS faces 90% opaque that RemRedundantMaterials won't catch us
|
||||||
if (materials[i].type == Unreal::MF_NORMAL_TRANS_TS) {
|
if (materials[i].type == Unreal::MF_NORMAL_TRANS_TS) {
|
||||||
const float opac = 0.9f;
|
const float opac = 0.9f;
|
||||||
mat->AddProperty(&opac,1,AI_MATKEY_OPACITY);
|
mat->AddProperty(&opac, 1, AI_MATKEY_OPACITY);
|
||||||
::strcat(s.data,"tran_");
|
::strcat(s.data, "tran_");
|
||||||
}
|
} else
|
||||||
else ::strcat(s.data,"opaq_");
|
::strcat(s.data, "opaq_");
|
||||||
|
|
||||||
// a special name for the weapon attachment point
|
// a special name for the weapon attachment point
|
||||||
if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
|
if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
|
||||||
s.length = ::ai_snprintf( s.data, MAXLEN, "$WeaponTag$" );
|
s.length = ::ai_snprintf(s.data, MAXLEN, "$WeaponTag$");
|
||||||
color = aiColor3D(0.f,0.f,0.f);
|
color = aiColor3D(0.f, 0.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set color and name
|
// set color and name
|
||||||
mat->AddProperty(&color,1,AI_MATKEY_COLOR_DIFFUSE);
|
mat->AddProperty(&color, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
s.length = static_cast<ai_uint32>(::strlen(s.data));
|
s.length = static_cast<ai_uint32>(::strlen(s.data));
|
||||||
mat->AddProperty(&s,AI_MATKEY_NAME);
|
mat->AddProperty(&s, AI_MATKEY_NAME);
|
||||||
|
|
||||||
// set texture, if any
|
// set texture, if any
|
||||||
const unsigned int tex = materials[i].tex;
|
const unsigned int tex = materials[i].tex;
|
||||||
for (std::vector< std::pair< unsigned int, std::string > >::const_iterator it = textures.begin();it != textures.end();++it) {
|
for (std::vector<std::pair<unsigned int, std::string>>::const_iterator it = textures.begin(); it != textures.end(); ++it) {
|
||||||
if ((*it).first == tex) {
|
if ((*it).first == tex) {
|
||||||
s.Set((*it).second);
|
s.Set((*it).second);
|
||||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -505,17 +492,17 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||||
// fill them.
|
// fill them.
|
||||||
for (const Unreal::Triangle &tri : triangles) {
|
for (const Unreal::Triangle &tri : triangles) {
|
||||||
Unreal::TempMat mat(tri);
|
Unreal::TempMat mat(tri);
|
||||||
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(),materials.end(),mat);
|
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(), materials.end(), mat);
|
||||||
|
|
||||||
aiMesh* mesh = pScene->mMeshes[nt-materials.begin()];
|
aiMesh *mesh = pScene->mMeshes[nt - materials.begin()];
|
||||||
aiFace& f = mesh->mFaces[mesh->mNumFaces++];
|
aiFace &f = mesh->mFaces[mesh->mNumFaces++];
|
||||||
f.mIndices = new unsigned int[f.mNumIndices = 3];
|
f.mIndices = new unsigned int[f.mNumIndices = 3];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 3;++i,mesh->mNumVertices++) {
|
for (unsigned int i = 0; i < 3; ++i, mesh->mNumVertices++) {
|
||||||
f.mIndices[i] = mesh->mNumVertices;
|
f.mIndices[i] = mesh->mNumVertices;
|
||||||
|
|
||||||
mesh->mVertices[mesh->mNumVertices] = vertices[ tri.mVertex[i] ];
|
mesh->mVertices[mesh->mNumVertices] = vertices[tri.mVertex[i]];
|
||||||
mesh->mTextureCoords[0][mesh->mNumVertices] = aiVector3D( tri.mTex[i][0] / 255.f, 1.f - tri.mTex[i][1] / 255.f, 0.f);
|
mesh->mTextureCoords[0][mesh->mNumVertices] = aiVector3D(tri.mTex[i][0] / 255.f, 1.f - tri.mTex[i][1] / 255.f, 0.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,41 +62,38 @@ public:
|
||||||
*
|
*
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
**/
|
**/
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** @brief Called by Importer::GetExtensionList()
|
/** @brief Called by Importer::GetExtensionList()
|
||||||
*
|
*
|
||||||
* See #BaseImporter::GetInfo for the details
|
* See #BaseImporter::GetInfo for the details
|
||||||
*/
|
*/
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc *GetInfo() const;
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** @brief Setup properties for the importer
|
/** @brief Setup properties for the importer
|
||||||
*
|
*
|
||||||
* See BaseImporter::SetupProperties() for details
|
* See BaseImporter::SetupProperties() for details
|
||||||
*/
|
*/
|
||||||
void SetupProperties(const Importer* pImp);
|
void SetupProperties(const Importer *pImp);
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** @brief Imports the given file into the given scene structure.
|
/** @brief Imports the given file into the given scene structure.
|
||||||
*
|
*
|
||||||
* See BaseImporter::InternReadFile() for details
|
* See BaseImporter::InternReadFile() for details
|
||||||
*/
|
*/
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||||
IOSystem* pIOHandler);
|
IOSystem *pIOHandler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! frame to be loaded
|
//! frame to be loaded
|
||||||
uint32_t configFrameID;
|
uint32_t mConfigFrameID;
|
||||||
|
|
||||||
//! process surface flags
|
//! process surface flags
|
||||||
bool configHandleFlags;
|
bool mConfigHandleFlags;
|
||||||
|
|
||||||
}; // !class UnrealImporter
|
}; // !class UnrealImporter
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue