changed to coding convention

pull/2005/head
CwTCwT 2018-06-09 15:56:26 +02:00
parent 85b0026c92
commit b8facc5dae
5 changed files with 33 additions and 66 deletions

View File

@ -4,8 +4,7 @@
#include <array>
namespace Assimp {
namespace Blender
{
namespace Blender {
/**
* @brief read/convert of Structure array to memory
*/
@ -84,8 +83,7 @@ namespace Assimp {
/**
* @brief describes the size of data and the read function to be used for single CustomerData.type
*/
struct CustomDataTypeDescription
{
struct CustomDataTypeDescription {
PRead Read; ///< function to read one CustomData type element
PAlloc Alloc; ///< function to allocate n type elements
};
@ -114,8 +112,7 @@ namespace Assimp {
* other (like CD_ORCO, ...) uses arrays of rawtypes or even arrays of Structures
* use a special readfunction for that cases
*/
CustomDataTypeDescriptions customDataTypeDescriptions =
{
CustomDataTypeDescriptions customDataTypeDescriptions = {
DECL_STRUCT_CUSTOMDATATYPEDESCRIPTION(MVert),
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION,
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION,
@ -165,21 +162,17 @@ namespace Assimp {
};
bool isValidCustomDataType(const int cdtype)
{
bool isValidCustomDataType(const int cdtype) {
return cdtype >= 0 && cdtype < CD_NUMTYPES;
}
bool readCustomData(std::shared_ptr<void> &out, const CustomDataType cdtype, const size_t cnt, const FileDatabase &db)
{
if (!isValidCustomDataType(cdtype))
{
bool readCustomData(std::shared_ptr<void> &out, const CustomDataType cdtype, const size_t cnt, const FileDatabase &db) {
if (!isValidCustomDataType(cdtype)) {
throw Error((Formatter::format(), "CustomData.type ", cdtype, " out of index"));
}
const CustomDataTypeDescription cdtd = customDataTypeDescriptions[cdtype];
if (cdtd.Read && cdtd.Alloc)
{
if (cdtd.Read && cdtd.Alloc) {
// allocate cnt elements and parse them from file
out.reset(cdtd.Alloc(cnt));
return cdtd.Read(out.get(), cnt, db);
@ -187,23 +180,18 @@ namespace Assimp {
return false;
}
std::shared_ptr<CustomDataLayer> getCustomDataLayer(const CustomData &customdata, const CustomDataType cdtype, const std::string &name)
{
for (auto it = customdata.layers.begin(); it != customdata.layers.end(); ++it)
{
if (it->get()->type == cdtype && name == it->get()->name)
{
std::shared_ptr<CustomDataLayer> getCustomDataLayer(const CustomData &customdata, const CustomDataType cdtype, const std::string &name) {
for (auto it = customdata.layers.begin(); it != customdata.layers.end(); ++it) {
if (it->get()->type == cdtype && name == it->get()->name) {
return *it;
}
}
return nullptr;
}
const void * getCustomDataLayerData(const CustomData &customdata, const CustomDataType cdtype, const std::string &name)
{
const void * getCustomDataLayerData(const CustomData &customdata, const CustomDataType cdtype, const std::string &name) {
const std::shared_ptr<CustomDataLayer> pLayer = getCustomDataLayer(customdata, cdtype, name);
if (pLayer && pLayer->data)
{
if (pLayer && pLayer->data) {
return pLayer->data.get();
}
return nullptr;

View File

@ -5,11 +5,9 @@
#include <memory>
namespace Assimp {
namespace Blender
{
namespace Blender {
/* CustomData.type from Blender (2.79b) */
enum CustomDataType
{
enum CustomDataType {
CD_AUTO_FROM_NAME = -1,
CD_MVERT = 0,
#ifdef DNA_DEPRECATED

View File

@ -310,10 +310,8 @@ void Structure :: ReadField(T& out, const char* name, const FileDatabase& db) co
//--------------------------------------------------------------------------------
// field parsing for raw untyped data (like CustomDataLayer.data)
template <int error_policy>
bool Structure::ReadCustomDataPtr(std::shared_ptr<void>&out, int cdtype, const char* name, const FileDatabase& db) const
{
if (!isValidCustomDataType(cdtype))
{
bool Structure::ReadCustomDataPtr(std::shared_ptr<void>&out, int cdtype, const char* name, const FileDatabase& db) const {
if (!isValidCustomDataType(cdtype)) {
ASSIMP_LOG_ERROR("given rawtype out of index");
return false;
}
@ -322,13 +320,11 @@ bool Structure::ReadCustomDataPtr(std::shared_ptr<void>&out, int cdtype, const c
Pointer ptrval;
const Field* f;
try
{
try {
f = &(*this)[name];
// sanity check, should never happen if the genblenddna script is right
if (!(f->flags & FieldFlag_Pointer))
{
if (!(f->flags & FieldFlag_Pointer)) {
throw Error((Formatter::format(), "Field `", name, "` of structure `",
this->name, "` ought to be a pointer"));
}
@ -338,15 +334,13 @@ bool Structure::ReadCustomDataPtr(std::shared_ptr<void>&out, int cdtype, const c
// actually it is meaningless on which Structure the Convert is called
// because the `Pointer` argument triggers a special implementation.
}
catch (const Error& e)
{
catch (const Error& e) {
_defaultInitializer<error_policy>()(out, e.what());
out.reset();
}
bool readOk = true;
if (ptrval.val)
{
if (ptrval.val) {
// get block for ptr
const FileBlockHead* block = LocateFileBlockForAddress(ptrval, db);
db.reader->SetCurrentPos(block->start + static_cast<size_t>((ptrval.val - block->address.val)));
@ -366,21 +360,18 @@ bool Structure::ReadCustomDataPtr(std::shared_ptr<void>&out, int cdtype, const c
//--------------------------------------------------------------------------------
template <int error_policy, template <typename> class TOUT, typename T>
bool Structure::ReadFieldPtrVector(vector<TOUT<T>>&out, const char* name, const FileDatabase& db) const
{
bool Structure::ReadFieldPtrVector(vector<TOUT<T>>&out, const char* name, const FileDatabase& db) const {
out.clear();
const StreamReaderAny::pos old = db.reader->GetCurrentPos();
Pointer ptrval;
const Field* f;
try
{
try {
f = &(*this)[name];
// sanity check, should never happen if the genblenddna script is right
if (!(f->flags & FieldFlag_Pointer))
{
if (!(f->flags & FieldFlag_Pointer)) {
throw Error((Formatter::format(), "Field `", name, "` of structure `",
this->name, "` ought to be a pointer"));
}
@ -390,16 +381,14 @@ bool Structure::ReadFieldPtrVector(vector<TOUT<T>>&out, const char* name, const
// actually it is meaningless on which Structure the Convert is called
// because the `Pointer` argument triggers a special implementation.
}
catch (const Error& e)
{
catch (const Error& e) {
_defaultInitializer<error_policy>()(out, e.what());
out.clear();
return false;
}
if (ptrval.val)
{
if (ptrval.val) {
// find the file block the pointer is pointing to
const FileBlockHead* block = LocateFileBlockForAddress(ptrval, db);
db.reader->SetCurrentPos(block->start + static_cast<size_t>((ptrval.val - block->address.val)));
@ -407,8 +396,7 @@ bool Structure::ReadFieldPtrVector(vector<TOUT<T>>&out, const char* name, const
// I really ought to improve StreamReader to work with 64 bit indices exclusively.
const Structure& s = db.dna[f->type];
for (size_t i = 0; i < block->num; ++i)
{
for (size_t i = 0; i < block->num; ++i) {
TOUT<T> p(new T);
s.Convert(*p, db);
out.push_back(p);

View File

@ -1031,20 +1031,16 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
typedef std::map<uint32_t, TextureUVMapping> MaterialTextureUVMappings;
MaterialTextureUVMappings matTexUvMappings;
const uint32_t maxMat = static_cast<const uint32_t>(mesh->mat.size());
for (uint32_t m = 0; m < maxMat; ++m)
{
for (uint32_t m = 0; m < maxMat; ++m) {
// get material by index
const std::shared_ptr<Material> pMat = mesh->mat[m];
TextureUVMapping texuv;
const uint32_t maxTex = sizeof(pMat->mtex) / sizeof(pMat->mtex[0]);
for (uint32_t t = 0; t < maxTex; ++t)
{
if (pMat->mtex[t] && pMat->mtex[t]->uvname[0])
{
for (uint32_t t = 0; t < maxTex; ++t) {
if (pMat->mtex[t] && pMat->mtex[t]->uvname[0]) {
// get the CustomData layer for given uvname and correct type
const MLoopUV *pLoop = static_cast<const MLoopUV*>(getCustomDataLayerData(mesh->ldata, CD_MLOOPUV, pMat->mtex[t]->uvname));
if (pLoop)
{
if (pLoop) {
texuv.insert(std::make_pair(t, pLoop));
}
}
@ -1114,8 +1110,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
}
// only update written mNumVertices in last loop
// TODO why must the numVertices be incremented here?
if (m == itMatTexUvMapping->second.size() - 1)
{
if (m == itMatTexUvMapping->second.size() - 1) {
out->mNumVertices += j;
}
}

View File

@ -389,8 +389,7 @@ CustomDataLayer 104
char name 32 64
void *data 96 8
*/
struct CustomDataLayer : ElemBase
{
struct CustomDataLayer : ElemBase {
int type;
int offset;
int flag;
@ -430,8 +429,7 @@ CustomData 208
BLI_mempool *pool 192 8
CustomDataExternal *external 200 8
*/
struct CustomData : ElemBase
{
struct CustomData : ElemBase {
vector<std::shared_ptr<struct CustomDataLayer> > layers;
int typemap[42]; // CD_NUMTYPES
int pad_i1;