assimp/code/AssetLib/Unreal/UnrealLoader.cpp

520 lines
18 KiB
C++
Raw Permalink Normal View History

/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
2022-01-10 20:13:43 +00:00
Copyright (c) 2006-2022, assimp team
All rights reserved.
2015-05-19 03:52:10 +00:00
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
2015-05-19 03:52:10 +00:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2015-05-19 03:52:10 +00:00
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2015-05-19 03:52:10 +00:00
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2015-05-19 03:52:10 +00:00
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file UnrealLoader.cpp
* @brief Implementation of the UNREAL (*.3D) importer class
*
* Sources:
* http://local.wasp.uwa.edu.au/~pbourke/dataformats/unreal/
*/
#ifndef ASSIMP_BUILD_NO_3D_IMPORTER
#include "AssetLib/Unreal/UnrealLoader.h"
#include "PostProcessing/ConvertToLHProcess.h"
#include <assimp/ParsingUtils.h>
2020-03-28 08:48:55 +00:00
#include <assimp/StreamReader.h>
#include <assimp/fast_atof.h>
2020-03-28 08:48:55 +00:00
#include <assimp/importerdesc.h>
#include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/IOSystem.hpp>
2020-03-28 08:48:55 +00:00
#include <assimp/Importer.hpp>
2021-09-13 20:38:20 +00:00
#include <cstdint>
2020-03-28 08:48:55 +00:00
#include <memory>
using namespace Assimp;
2020-01-16 19:25:47 +00:00
namespace Unreal {
2020-03-28 08:48:55 +00:00
/*
2020-01-16 19:25:47 +00:00
0 = Normal one-sided
1 = Normal two-sided
2 = Translucent two-sided
3 = Masked two-sided
4 = Modulation blended two-sided
8 = Placeholder triangle for weapon positioning (invisible)
2022-01-18 21:29:55 +00:00
*/
2020-01-16 19:25:47 +00:00
enum MeshFlags {
2020-03-28 08:48:55 +00:00
MF_NORMAL_OS = 0,
MF_NORMAL_TS = 1,
MF_NORMAL_TRANS_TS = 2,
MF_NORMAL_MASKED_TS = 3,
MF_NORMAL_MOD_TS = 4,
MF_WEAPON_PLACEHOLDER = 8
2020-01-16 19:25:47 +00:00
};
// a single triangle
struct Triangle {
2020-03-28 08:48:55 +00:00
uint16_t mVertex[3]; // Vertex indices
char mType; // James' Mesh Type
char mColor; // Color for flat and Gourand Shaded
unsigned char mTex[3][2]; // Texture UV coordinates
unsigned char mTextureNum; // Source texture offset
char mFlags; // Unreal Mesh Flags (unused)
unsigned int matIndex;
2020-01-16 19:25:47 +00:00
};
// temporary representation for a material
struct TempMat {
2020-03-28 08:48:55 +00:00
TempMat() :
type(MF_NORMAL_OS), tex(), numFaces(0) {}
2020-01-16 19:25:47 +00:00
2020-03-28 08:48:55 +00:00
explicit TempMat(const Triangle &in) :
type((Unreal::MeshFlags)in.mType), tex(in.mTextureNum), numFaces(0) {}
2020-01-16 19:25:47 +00:00
2020-03-28 08:48:55 +00:00
// type of mesh
Unreal::MeshFlags type;
2020-01-16 19:25:47 +00:00
2020-03-28 08:48:55 +00:00
// index of texture
unsigned int tex;
2020-01-16 19:25:47 +00:00
2020-03-28 08:48:55 +00:00
// number of faces using us
unsigned int numFaces;
2020-01-16 19:25:47 +00:00
2020-03-28 08:48:55 +00:00
// for std::find
bool operator==(const TempMat &o) {
return (tex == o.tex && type == o.type);
}
2020-01-16 19:25:47 +00:00
};
struct Vertex {
2020-03-28 08:48:55 +00:00
int32_t X : 11;
int32_t Y : 11;
int32_t Z : 10;
2020-01-16 19:25:47 +00:00
};
// UNREAL vertex compression
inline void CompressVertex(const aiVector3D &v, uint32_t &out) {
2020-03-28 08:48:55 +00:00
union {
Vertex n;
int32_t t;
};
t = 0;
2020-03-28 08:48:55 +00:00
n.X = (int32_t)v.x;
n.Y = (int32_t)v.y;
n.Z = (int32_t)v.z;
::memcpy(&out, &t, sizeof(int32_t));
2020-01-16 19:25:47 +00:00
}
// UNREAL vertex decompression
inline void DecompressVertex(aiVector3D &v, int32_t in) {
2020-03-28 08:48:55 +00:00
union {
Vertex n;
int32_t i;
};
i = in;
v.x = (float)n.X;
v.y = (float)n.Y;
v.z = (float)n.Z;
2020-01-16 19:25:47 +00:00
}
} // end namespace Unreal
static const aiImporterDesc desc = {
2015-05-19 03:57:13 +00:00
"Unreal Mesh Importer",
"",
"",
"",
aiImporterFlags_SupportTextFlavour,
0,
0,
0,
0,
"3d uc"
};
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
2020-03-28 08:48:55 +00:00
UnrealImporter::UnrealImporter() :
2022-01-18 20:37:49 +00:00
mConfigFrameID(0), mConfigHandleFlags(true) {
// empty
}
// ------------------------------------------------------------------------------------------------
2015-05-19 03:52:10 +00:00
// Destructor, private as well
UnrealImporter::~UnrealImporter() = default;
// ------------------------------------------------------------------------------------------------
2015-05-19 03:52:10 +00:00
// Returns whether the class can handle the format of the given file.
2022-01-18 21:29:55 +00:00
bool UnrealImporter::CanRead(const std::string & filename, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const {
return SimpleExtensionCheck(filename, "3d", "uc");
}
// ------------------------------------------------------------------------------------------------
// Build a string of all file extensions supported
2020-03-28 08:48:55 +00:00
const aiImporterDesc *UnrealImporter::GetInfo() const {
2015-05-19 03:57:13 +00:00
return &desc;
}
// ------------------------------------------------------------------------------------------------
// Setup configuration properties for the loader
2020-03-28 08:48:55 +00:00
void UnrealImporter::SetupProperties(const Importer *pImp) {
2015-05-19 03:57:13 +00:00
// The
// AI_CONFIG_IMPORT_UNREAL_KEYFRAME option overrides the
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
2020-03-28 08:48:55 +00:00
mConfigFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_KEYFRAME, -1);
if (static_cast<unsigned int>(-1) == mConfigFrameID) {
mConfigFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME, 0);
2015-05-19 03:57:13 +00:00
}
// AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, default is true
2020-03-28 08:48:55 +00:00
mConfigHandleFlags = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, 1));
}
// ------------------------------------------------------------------------------------------------
2015-05-19 03:52:10 +00:00
// Imports the given file into the given scene structure.
2020-03-28 08:48:55 +00:00
void UnrealImporter::InternReadFile(const std::string &pFile,
aiScene *pScene, IOSystem *pIOHandler) {
2015-05-19 03:57:13 +00:00
// For any of the 3 files being passed get the three correct paths
// First of all, determine file extension
std::string::size_type pos = pFile.find_last_of('.');
std::string extension = GetExtension(pFile);
2020-03-28 08:48:55 +00:00
std::string d_path, a_path, uc_path;
if (extension == "3d") {
2015-05-19 03:57:13 +00:00
// jjjj_d.3d
// jjjj_a.3d
pos = pFile.find_last_of('_');
if (std::string::npos == pos) {
throw DeadlyImportError("UNREAL: Unexpected naming scheme");
}
2020-03-28 08:48:55 +00:00
extension = pFile.substr(0, pos);
} else {
extension = pFile.substr(0, pos);
2015-05-19 03:57:13 +00:00
}
// build proper paths
2020-03-28 08:48:55 +00:00
d_path = extension + "_d.3d";
a_path = extension + "_a.3d";
uc_path = extension + ".uc";
2015-05-19 03:57:13 +00:00
ASSIMP_LOG_DEBUG("UNREAL: data file is ", d_path);
ASSIMP_LOG_DEBUG("UNREAL: aniv file is ", a_path);
ASSIMP_LOG_DEBUG("UNREAL: uc file is ", uc_path);
2015-05-19 03:57:13 +00:00
// and open the files ... we can't live without them
2017-10-05 08:56:13 +00:00
std::unique_ptr<IOStream> p(pIOHandler->Open(d_path));
2015-05-19 03:57:13 +00:00
if (!p)
throw DeadlyImportError("UNREAL: Unable to open _d file");
StreamReaderLE d_reader(pIOHandler->Open(d_path));
const uint16_t numTris = d_reader.GetI2();
const uint16_t numVert = d_reader.GetI2();
d_reader.IncPtr(44);
if (!numTris || numVert < 3)
throw DeadlyImportError("UNREAL: Invalid number of vertices/triangles");
// maximum texture index
unsigned int maxTexIdx = 0;
// collect triangles
std::vector<Unreal::Triangle> triangles(numTris);
2020-03-28 08:48:55 +00:00
for (auto &tri : triangles) {
for (unsigned int i = 0; i < 3; ++i) {
2015-05-19 03:57:13 +00:00
tri.mVertex[i] = d_reader.GetI2();
2020-03-28 08:48:55 +00:00
if (tri.mVertex[i] >= numTris) {
2018-04-19 14:48:43 +00:00
ASSIMP_LOG_WARN("UNREAL: vertex index out of range");
2015-05-19 03:57:13 +00:00
tri.mVertex[i] = 0;
}
}
tri.mType = d_reader.GetI1();
// handle mesh flagss?
2020-03-28 08:48:55 +00:00
if (mConfigHandleFlags)
2015-05-19 03:57:13 +00:00
tri.mType = Unreal::MF_NORMAL_OS;
else {
// ignore MOD and MASKED for the moment, treat them as two-sided
if (tri.mType == Unreal::MF_NORMAL_MOD_TS || tri.mType == Unreal::MF_NORMAL_MASKED_TS)
tri.mType = Unreal::MF_NORMAL_TS;
}
d_reader.IncPtr(1);
2020-03-28 08:48:55 +00:00
for (unsigned int i = 0; i < 3; ++i)
for (unsigned int i2 = 0; i2 < 2; ++i2)
2015-05-19 03:57:13 +00:00
tri.mTex[i][i2] = d_reader.GetI1();
tri.mTextureNum = d_reader.GetI1();
2020-03-28 08:48:55 +00:00
maxTexIdx = std::max(maxTexIdx, (unsigned int)tri.mTextureNum);
2015-05-19 03:57:13 +00:00
d_reader.IncPtr(1);
}
2017-10-05 08:56:13 +00:00
p.reset(pIOHandler->Open(a_path));
2015-05-19 03:57:13 +00:00
if (!p)
throw DeadlyImportError("UNREAL: Unable to open _a file");
StreamReaderLE a_reader(pIOHandler->Open(a_path));
// read number of frames
const uint32_t numFrames = a_reader.GetI2();
2020-03-28 08:48:55 +00:00
if (mConfigFrameID >= numFrames) {
2015-05-19 03:57:13 +00:00
throw DeadlyImportError("UNREAL: The requested frame does not exist");
2020-03-08 20:24:01 +00:00
}
2015-05-19 03:57:13 +00:00
uint32_t st = a_reader.GetI2();
2020-03-28 08:48:55 +00:00
if (st != numVert * 4u)
2015-05-19 03:57:13 +00:00
throw DeadlyImportError("UNREAL: Unexpected aniv file length");
// skip to our frame
2020-03-28 08:48:55 +00:00
a_reader.IncPtr(mConfigFrameID * numVert * 4);
2015-05-19 03:57:13 +00:00
// collect vertices
std::vector<aiVector3D> vertices(numVert);
2020-03-28 08:48:55 +00:00
for (auto &vertex : vertices) {
2015-05-19 03:57:13 +00:00
int32_t val = a_reader.GetI4();
2020-03-28 08:48:55 +00:00
Unreal::DecompressVertex(vertex, val);
2015-05-19 03:57:13 +00:00
}
// list of textures.
2020-03-28 08:48:55 +00:00
std::vector<std::pair<unsigned int, std::string>> textures;
2015-05-19 03:57:13 +00:00
// allocate the output scene
2020-03-28 08:48:55 +00:00
aiNode *nd = pScene->mRootNode = new aiNode();
2015-05-19 03:57:13 +00:00
nd->mName.Set("<UnrealRoot>");
// we can live without the uc file if necessary
2020-03-28 08:48:55 +00:00
std::unique_ptr<IOStream> pb(pIOHandler->Open(uc_path));
if (pb) {
2015-05-19 03:57:13 +00:00
std::vector<char> _data;
2020-03-28 08:48:55 +00:00
TextFileToBuffer(pb.get(), _data);
const char *data = &_data[0];
2015-05-19 03:57:13 +00:00
2020-03-28 08:48:55 +00:00
std::vector<std::pair<std::string, std::string>> tempTextures;
2015-05-19 03:57:13 +00:00
// do a quick search in the UC file for some known, usually texture-related, tags
2020-03-28 08:48:55 +00:00
for (; *data; ++data) {
if (TokenMatchI(data, "#exec", 5)) {
2015-05-19 03:57:13 +00:00
SkipSpacesAndLineEnd(&data);
// #exec TEXTURE IMPORT [...] NAME=jjjjj [...] FILE=jjjj.pcx [...]
2020-03-28 08:48:55 +00:00
if (TokenMatchI(data, "TEXTURE", 7)) {
2015-05-19 03:57:13 +00:00
SkipSpacesAndLineEnd(&data);
2020-03-28 08:48:55 +00:00
if (TokenMatchI(data, "IMPORT", 6)) {
tempTextures.emplace_back();
2020-03-28 08:48:55 +00:00
std::pair<std::string, std::string> &me = tempTextures.back();
for (; !IsLineEnd(*data); ++data) {
if (!::ASSIMP_strincmp(data, "NAME=", 5)) {
const char *d = data += 5;
for (; !IsSpaceOrNewLine(*data); ++data)
;
me.first = std::string(d, (size_t)(data - d));
} else if (!::ASSIMP_strincmp(data, "FILE=", 5)) {
const char *d = data += 5;
for (; !IsSpaceOrNewLine(*data); ++data)
;
me.second = std::string(d, (size_t)(data - d));
2015-05-19 03:57:13 +00:00
}
}
if (!me.first.length() || !me.second.length())
tempTextures.pop_back();
}
}
// #exec MESHMAP SETTEXTURE MESHMAP=box NUM=1 TEXTURE=Jtex1
// #exec MESHMAP SCALE MESHMAP=box X=0.1 Y=0.1 Z=0.2
2020-03-28 08:48:55 +00:00
else if (TokenMatchI(data, "MESHMAP", 7)) {
2015-05-19 03:57:13 +00:00
SkipSpacesAndLineEnd(&data);
2020-03-28 08:48:55 +00:00
if (TokenMatchI(data, "SETTEXTURE", 10)) {
2015-05-19 03:57:13 +00:00
textures.emplace_back();
2020-03-28 08:48:55 +00:00
std::pair<unsigned int, std::string> &me = textures.back();
2015-05-19 03:57:13 +00:00
2020-03-28 08:48:55 +00:00
for (; !IsLineEnd(*data); ++data) {
if (!::ASSIMP_strincmp(data, "NUM=", 4)) {
2015-05-19 03:57:13 +00:00
data += 4;
2020-03-28 08:48:55 +00:00
me.first = strtoul10(data, &data);
} else if (!::ASSIMP_strincmp(data, "TEXTURE=", 8)) {
2015-05-19 03:57:13 +00:00
data += 8;
const char *d = data;
2020-03-28 08:48:55 +00:00
for (; !IsSpaceOrNewLine(*data); ++data)
;
me.second = std::string(d, (size_t)(data - d));
2015-05-19 03:57:13 +00:00
// try to find matching path names, doesn't care if we don't find them
2020-03-28 08:48:55 +00:00
for (std::vector<std::pair<std::string, std::string>>::const_iterator it = tempTextures.begin();
it != tempTextures.end(); ++it) {
if ((*it).first == me.second) {
2015-05-19 03:57:13 +00:00
me.second = (*it).second;
break;
}
}
}
}
2020-03-28 08:48:55 +00:00
} else if (TokenMatchI(data, "SCALE", 5)) {
for (; !IsLineEnd(*data); ++data) {
if (data[0] == 'X' && data[1] == '=') {
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.a1);
} else if (data[0] == 'Y' && data[1] == '=') {
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);
2015-05-19 03:57:13 +00:00
}
}
}
}
}
}
2020-03-28 08:48:55 +00:00
} else {
2018-04-19 14:48:43 +00:00
ASSIMP_LOG_ERROR("Unable to open .uc file");
2015-05-19 03:57:13 +00:00
}
std::vector<Unreal::TempMat> materials;
2020-03-28 08:48:55 +00:00
materials.reserve(textures.size() * 2 + 5);
2015-05-19 03:57:13 +00:00
// find out how many output meshes and materials we'll have and build material indices
2020-03-28 08:48:55 +00:00
for (Unreal::Triangle &tri : triangles) {
2015-05-19 03:57:13 +00:00
Unreal::TempMat mat(tri);
2020-03-28 08:48:55 +00:00
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(), materials.end(), mat);
2015-05-19 03:57:13 +00:00
if (nt == materials.end()) {
// add material
tri.matIndex = static_cast<unsigned int>(materials.size());
2015-05-19 03:57:13 +00:00
mat.numFaces = 1;
materials.push_back(mat);
++pScene->mNumMeshes;
2020-03-28 08:48:55 +00:00
} else {
tri.matIndex = static_cast<unsigned int>(nt - materials.begin());
2015-05-19 03:57:13 +00:00
++nt->numFaces;
}
}
if (!pScene->mNumMeshes) {
throw DeadlyImportError("UNREAL: Unable to find valid mesh data");
}
// allocate meshes and bind them to the node graph
2020-03-28 08:48:55 +00:00
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials = pScene->mNumMeshes];
2015-05-19 03:57:13 +00:00
2020-03-28 08:48:55 +00:00
nd->mNumMeshes = pScene->mNumMeshes;
2015-05-19 03:57:13 +00:00
nd->mMeshes = new unsigned int[nd->mNumMeshes];
2020-03-28 08:48:55 +00:00
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
aiMesh *m = pScene->mMeshes[i] = new aiMesh();
2015-05-19 03:57:13 +00:00
m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
const unsigned int num = materials[i].numFaces;
2020-03-28 08:48:55 +00:00
m->mFaces = new aiFace[num];
m->mVertices = new aiVector3D[num * 3];
m->mTextureCoords[0] = new aiVector3D[num * 3];
2015-05-19 03:57:13 +00:00
nd->mMeshes[i] = i;
// create materials, too
2020-03-28 08:48:55 +00:00
aiMaterial *mat = new aiMaterial();
2015-05-19 03:57:13 +00:00
pScene->mMaterials[i] = mat;
// all white by default - texture rulez
2020-03-28 08:48:55 +00:00
aiColor3D color(1.f, 1.f, 1.f);
2015-05-19 03:57:13 +00:00
aiString s;
2020-03-28 08:48:55 +00:00
::ai_snprintf(s.data, MAXLEN, "mat%u_tx%u_", i, materials[i].tex);
2015-05-19 03:57:13 +00:00
// set the two-sided flag
if (materials[i].type == Unreal::MF_NORMAL_TS) {
const int twosided = 1;
2020-03-28 08:48:55 +00:00
mat->AddProperty(&twosided, 1, AI_MATKEY_TWOSIDED);
::strcat(s.data, "ts_");
} else
::strcat(s.data, "os_");
2015-05-19 03:57:13 +00:00
// make TRANS faces 90% opaque that RemRedundantMaterials won't catch us
2020-03-28 08:48:55 +00:00
if (materials[i].type == Unreal::MF_NORMAL_TRANS_TS) {
2015-05-19 03:57:13 +00:00
const float opac = 0.9f;
2020-03-28 08:48:55 +00:00
mat->AddProperty(&opac, 1, AI_MATKEY_OPACITY);
::strcat(s.data, "tran_");
} else
::strcat(s.data, "opaq_");
2015-05-19 03:57:13 +00:00
// a special name for the weapon attachment point
if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
2020-03-28 08:48:55 +00:00
s.length = ::ai_snprintf(s.data, MAXLEN, "$WeaponTag$");
color = aiColor3D(0.f, 0.f, 0.f);
2015-05-19 03:57:13 +00:00
}
// set color and name
2020-03-28 08:48:55 +00:00
mat->AddProperty(&color, 1, AI_MATKEY_COLOR_DIFFUSE);
2020-01-16 19:25:47 +00:00
s.length = static_cast<ai_uint32>(::strlen(s.data));
2020-03-28 08:48:55 +00:00
mat->AddProperty(&s, AI_MATKEY_NAME);
2015-05-19 03:57:13 +00:00
// set texture, if any
const unsigned int tex = materials[i].tex;
2020-03-28 08:48:55 +00:00
for (std::vector<std::pair<unsigned int, std::string>>::const_iterator it = textures.begin(); it != textures.end(); ++it) {
2015-05-19 03:57:13 +00:00
if ((*it).first == tex) {
s.Set((*it).second);
2020-03-28 08:48:55 +00:00
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
2015-05-19 03:57:13 +00:00
break;
}
}
}
// fill them.
2016-05-22 10:50:29 +00:00
for (const Unreal::Triangle &tri : triangles) {
2015-05-19 03:57:13 +00:00
Unreal::TempMat mat(tri);
2020-03-28 08:48:55 +00:00
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(), materials.end(), mat);
2015-05-19 03:57:13 +00:00
2020-03-28 08:48:55 +00:00
aiMesh *mesh = pScene->mMeshes[nt - materials.begin()];
aiFace &f = mesh->mFaces[mesh->mNumFaces++];
f.mIndices = new unsigned int[f.mNumIndices = 3];
2015-05-19 03:57:13 +00:00
2020-03-28 08:48:55 +00:00
for (unsigned int i = 0; i < 3; ++i, mesh->mNumVertices++) {
2015-05-19 03:57:13 +00:00
f.mIndices[i] = mesh->mNumVertices;
2020-03-28 08:48:55 +00:00
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);
2015-05-19 03:57:13 +00:00
}
}
// convert to RH
MakeLeftHandedProcess hero;
hero.Execute(pScene);
FlipWindingOrderProcess flipper;
flipper.Execute(pScene);
}
#endif // !! ASSIMP_BUILD_NO_3D_IMPORTER