Skip to content

Commit

Permalink
Merge branch 'master' into fix_android
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkulling committed Nov 18, 2017
2 parents a8e65a1 + 864a080 commit 1a1d96d
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 33 deletions.
6 changes: 6 additions & 0 deletions code/BlenderDNA.h
Expand Up @@ -92,6 +92,12 @@ struct Error : DeadlyImportError {
* descendents. It serves as base class for all data structure fields. */
// -------------------------------------------------------------------------------
struct ElemBase {
ElemBase()
: dna_type(nullptr)
{
// empty
}

virtual ~ElemBase() {
// empty
}
Expand Down
43 changes: 31 additions & 12 deletions code/BlenderScene.cpp
Expand Up @@ -59,7 +59,9 @@ template <> void Structure :: Convert<Object> (
{

ReadField<ErrorPolicy_Fail>(dest.id,"id",db);
ReadField<ErrorPolicy_Fail>((int&)dest.type,"type",db);
int temp = 0;
ReadField<ErrorPolicy_Fail>(temp,"type",db);
dest.type = static_cast<Assimp::Blender::Object::Type>(temp);
ReadFieldArray2<ErrorPolicy_Warn>(dest.obmat,"obmat",db);
ReadFieldArray2<ErrorPolicy_Warn>(dest.parentinv,"parentinv",db);
ReadFieldArray<ErrorPolicy_Warn>(dest.parsubstr,"parsubstr",db);
Expand Down Expand Up @@ -100,14 +102,21 @@ template <> void Structure :: Convert<MTex> (
) const
{

ReadField<ErrorPolicy_Igno>((short&)dest.mapto,"mapto",db);
ReadField<ErrorPolicy_Igno>((int&)dest.blendtype,"blendtype",db);
int temp_short = 0;
ReadField<ErrorPolicy_Igno>(temp_short,"mapto",db);
dest.mapto = static_cast<Assimp::Blender::MTex::MapType>(temp_short);
int temp = 0;
ReadField<ErrorPolicy_Igno>(temp,"blendtype",db);
dest.blendtype = static_cast<Assimp::Blender::MTex::BlendType>(temp);
ReadFieldPtr<ErrorPolicy_Igno>(dest.object,"*object",db);
ReadFieldPtr<ErrorPolicy_Igno>(dest.tex,"*tex",db);
ReadFieldArray<ErrorPolicy_Igno>(dest.uvname,"uvname",db);
ReadField<ErrorPolicy_Igno>((int&)dest.projx,"projx",db);
ReadField<ErrorPolicy_Igno>((int&)dest.projy,"projy",db);
ReadField<ErrorPolicy_Igno>((int&)dest.projz,"projz",db);
ReadField<ErrorPolicy_Igno>(temp,"projx",db);
dest.projx = static_cast<Assimp::Blender::MTex::Projection>(temp);
ReadField<ErrorPolicy_Igno>(temp,"projy",db);
dest.projy = static_cast<Assimp::Blender::MTex::Projection>(temp);
ReadField<ErrorPolicy_Igno>(temp,"projz",db);
dest.projx = static_cast<Assimp::Blender::MTex::Projection>(temp);
ReadField<ErrorPolicy_Igno>(dest.mapping,"mapping",db);
ReadFieldArray<ErrorPolicy_Igno>(dest.ofs,"ofs",db);
ReadFieldArray<ErrorPolicy_Igno>(dest.size,"size",db);
Expand Down Expand Up @@ -190,7 +199,9 @@ template <> void Structure :: Convert<Lamp> (
{

ReadField<ErrorPolicy_Fail>(dest.id,"id",db);
ReadField<ErrorPolicy_Fail>((int&)dest.type,"type",db);
int temp = 0;
ReadField<ErrorPolicy_Fail>(temp,"type",db);
dest.type = static_cast<Assimp::Blender::Lamp::Type>(temp);
ReadField<ErrorPolicy_Igno>(dest.flags,"flags",db);
ReadField<ErrorPolicy_Igno>(dest.colormodel,"colormodel",db);
ReadField<ErrorPolicy_Igno>(dest.totex,"totex",db);
Expand All @@ -204,7 +215,8 @@ template <> void Structure :: Convert<Lamp> (
ReadField<ErrorPolicy_Igno>(dest.spotblend,"spotblend",db);
ReadField<ErrorPolicy_Igno>(dest.att1,"att1",db);
ReadField<ErrorPolicy_Igno>(dest.att2,"att2",db);
ReadField<ErrorPolicy_Igno>((int&)dest.falloff_type,"falloff_type",db);
ReadField<ErrorPolicy_Igno>(temp,"falloff_type",db);
dest.falloff_type = static_cast<Assimp::Blender::Lamp::FalloffType>(temp);
ReadField<ErrorPolicy_Igno>(dest.sun_brightness,"sun_brightness",db);
ReadField<ErrorPolicy_Igno>(dest.area_size,"area_size",db);
ReadField<ErrorPolicy_Igno>(dest.area_sizey,"area_sizey",db);
Expand Down Expand Up @@ -693,8 +705,12 @@ template <> void Structure :: Convert<Tex> (
const FileDatabase& db
) const
{
ReadField<ErrorPolicy_Igno>((short&)dest.imaflag,"imaflag",db);
ReadField<ErrorPolicy_Fail>((int&)dest.type,"type",db);
short temp_short = 0;
ReadField<ErrorPolicy_Igno>(temp_short,"imaflag",db);
dest.imaflag = static_cast<Assimp::Blender::Tex::ImageFlags>(temp_short);
int temp = 0;
ReadField<ErrorPolicy_Fail>(temp,"type",db);
dest.type = static_cast<Assimp::Blender::Tex::Type>(temp);
ReadFieldPtr<ErrorPolicy_Warn>(dest.ima,"*ima",db);

db.reader->IncPtr(size);
Expand All @@ -708,8 +724,11 @@ template <> void Structure :: Convert<Camera> (
{

ReadField<ErrorPolicy_Fail>(dest.id,"id",db);
ReadField<ErrorPolicy_Warn>((int&)dest.type,"type",db);
ReadField<ErrorPolicy_Warn>((int&)dest.flag,"flag",db);
int temp = 0;
ReadField<ErrorPolicy_Warn>(temp,"type",db);
dest.type = static_cast<Assimp::Blender::Camera::Type>(temp);
ReadField<ErrorPolicy_Warn>(temp,"flag",db);
dest.flag = static_cast<Assimp::Blender::Camera::Type>(temp);
ReadField<ErrorPolicy_Warn>(dest.lens,"lens",db);
ReadField<ErrorPolicy_Warn>(dest.sensor_x,"sensor_x",db);
ReadField<ErrorPolicy_Igno>(dest.clipsta,"clipsta",db);
Expand Down
8 changes: 8 additions & 0 deletions code/BlenderScene.h
Expand Up @@ -225,6 +225,14 @@ struct TFace : ElemBase {

// -------------------------------------------------------------------------------
struct MTFace : ElemBase {
MTFace()
: flag(0)
, mode(0)
, tile(0)
, unwrap(0)
{
}

float uv[4][2] FAIL;
char flag;
short mode;
Expand Down
8 changes: 6 additions & 2 deletions code/FIReader.cpp
Expand Up @@ -487,7 +487,9 @@ struct FIFloatDecoder: public FIDecoder {
value.reserve(numFloats);
for (size_t i = 0; i < numFloats; ++i) {
int v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
value.push_back(*(float*)&v);
float f;
memcpy(&f, &v, 4);
value.push_back(f);
data += 4;
}
return FIFloatValue::create(std::move(value));
Expand All @@ -505,7 +507,9 @@ struct FIDoubleDecoder: public FIDecoder {
for (size_t i = 0; i < numDoubles; ++i) {
long long b0 = data[0], b1 = data[1], b2 = data[2], b3 = data[3], b4 = data[4], b5 = data[5], b6 = data[6], b7 = data[7];
long long v = (b0 << 56) | (b1 << 48) | (b2 << 40) | (b3 << 32) | (b4 << 24) | (b5 << 16) | (b6 << 8) | b7;
value.push_back(*(double*)&v);
double f;
memcpy(&f, &v, 8);
value.push_back(f);
data += 8;
}
return FIDoubleValue::create(std::move(value));
Expand Down
4 changes: 3 additions & 1 deletion code/MDLMaterialLoader.cpp
Expand Up @@ -665,7 +665,9 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
if (0.0f != pcMatIn->Power)
{
iShadingMode = (int)aiShadingMode_Phong;
pcMatOut->AddProperty<float>(&pcMatIn->Power,1,AI_MATKEY_SHININESS);
// pcMatIn is packed, we can't form pointers to its members
float power = pcMatIn->Power;
pcMatOut->AddProperty<float>(&power,1,AI_MATKEY_SHININESS);
}
pcMatOut->AddProperty<int>(&iShadingMode,1,AI_MATKEY_SHADING_MODEL);
}
Expand Down
8 changes: 4 additions & 4 deletions code/ValidateDataStructure.cpp
Expand Up @@ -334,28 +334,28 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh)
case 1:
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POINT))
{
ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimtiveTypes "
ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimitiveTypes "
"does not report the POINT flag",i);
}
break;
case 2:
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_LINE))
{
ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimtiveTypes "
ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimitiveTypes "
"does not report the LINE flag",i);
}
break;
case 3:
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE))
{
ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimtiveTypes "
ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimitiveTypes "
"does not report the TRIANGLE flag",i);
}
break;
default:
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POLYGON))
{
this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimtiveTypes "
this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimitiveTypes "
"does not report the POLYGON flag",i);
}
break;
Expand Down
9 changes: 6 additions & 3 deletions contrib/Open3DGC/o3dgcBinaryStream.h
Expand Up @@ -231,7 +231,8 @@ namespace o3dgc
float ReadFloat32Bin(unsigned long & position) const
{
unsigned long value = ReadUInt32Bin(position);
float fvalue = *((float *)(&value));
float fvalue;
memcpy(&fvalue, &value, 4);
return fvalue;
}
unsigned long ReadUInt32Bin(unsigned long & position) const
Expand Down Expand Up @@ -261,7 +262,8 @@ namespace o3dgc

void WriteFloat32ASCII(float value)
{
unsigned long uiValue = *((unsigned long *)(&value));
unsigned long uiValue;
memcpy(&uiValue, &value, 4);
WriteUInt32ASCII(uiValue);
}
void WriteUInt32ASCII(unsigned long position, unsigned long value)
Expand Down Expand Up @@ -314,7 +316,8 @@ namespace o3dgc
float ReadFloat32ASCII(unsigned long & position) const
{
unsigned long value = ReadUInt32ASCII(position);
float fvalue = *((float *)(&value));
float fvalue;
memcpy(&fvalue, &value, 4);
return fvalue;
}
unsigned long ReadUInt32ASCII(unsigned long & position) const
Expand Down
16 changes: 8 additions & 8 deletions test/unit/utObjImportExport.cpp
Expand Up @@ -294,12 +294,12 @@ TEST_F(utObjImportExport, relative_indices_Test) {
const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);

EXPECT_EQ(scene->mNumMeshes, 1);
EXPECT_EQ(scene->mNumMeshes, 1U);
const aiMesh *mesh = scene->mMeshes[0];
EXPECT_EQ(mesh->mNumVertices, 4);
EXPECT_EQ(mesh->mNumFaces, 1);
EXPECT_EQ(mesh->mNumVertices, 4U);
EXPECT_EQ(mesh->mNumFaces, 1U);
const aiFace face = mesh->mFaces[0];
EXPECT_EQ(face.mNumIndices, 4);
EXPECT_EQ(face.mNumIndices, 4U);
for (unsigned int i = 0; i < face.mNumIndices; ++i)
{
EXPECT_EQ(face.mIndices[i], i);
Expand All @@ -318,12 +318,12 @@ TEST_F(utObjImportExport, homogeneous_coordinates_Test) {
const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);

EXPECT_EQ(scene->mNumMeshes, 1);
EXPECT_EQ(scene->mNumMeshes, 1U);
const aiMesh *mesh = scene->mMeshes[0];
EXPECT_EQ(mesh->mNumVertices, 3);
EXPECT_EQ(mesh->mNumFaces, 1);
EXPECT_EQ(mesh->mNumVertices, 3U);
EXPECT_EQ(mesh->mNumFaces, 1U);
const aiFace face = mesh->mFaces[0];
EXPECT_EQ(face.mNumIndices, 3);
EXPECT_EQ(face.mNumIndices, 3U);
const aiVector3D vertice = mesh->mVertices[0];
EXPECT_EQ(vertice.x, -1.0f);
EXPECT_EQ(vertice.y, 0.0f);
Expand Down
17 changes: 14 additions & 3 deletions tools/assimp_cmd/WriteDumb.cpp
Expand Up @@ -177,6 +177,17 @@ inline uint32_t Write<aiVector3D>(const aiVector3D& v)
return t;
}

// -----------------------------------------------------------------------------------
// Serialize a color value
template <>
inline uint32_t Write<aiColor3D>(const aiColor3D& v)
{
uint32_t t = Write<float>(v.r);
t += Write<float>(v.g);
t += Write<float>(v.b);
return t;
}

// -----------------------------------------------------------------------------------
// Serialize a color value
template <>
Expand Down Expand Up @@ -566,9 +577,9 @@ uint32_t WriteBinaryLight(const aiLight* l)
len += Write<float>(l->mAttenuationQuadratic);
}

len += Write<aiVector3D>((const aiVector3D&)l->mColorDiffuse);
len += Write<aiVector3D>((const aiVector3D&)l->mColorSpecular);
len += Write<aiVector3D>((const aiVector3D&)l->mColorAmbient);
len += Write<aiColor3D>(l->mColorDiffuse);
len += Write<aiColor3D>(l->mColorSpecular);
len += Write<aiColor3D>(l->mColorAmbient);

if (l->mType == aiLightSource_SPOT) {
len += Write<float>(l->mAngleInnerCone);
Expand Down

0 comments on commit 1a1d96d

Please sign in to comment.