Merge branch 'master' into patch-13

pull/1576/head
Kim Kulling 2017-11-18 20:36:05 +01:00 committed by GitHub
commit 65d6daa414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 108 additions and 47 deletions

View File

@ -186,7 +186,7 @@ IF( UNIX )
IF( ${OPERATING_SYSTEM} MATCHES "Android")
ELSE()
IF ( CMAKE_SIZEOF_VOID_P EQUAL 4) # only necessary for 32-bit linux
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 )
#ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 )
ENDIF()
ENDIF()

View File

@ -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
}

View File

@ -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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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);

View File

@ -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;

View File

@ -45,13 +45,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
#include "FIReader.hpp"
#include "StringUtils.h"
// Workaround for issue #1361
// https://github.com/assimp/assimp/issues/1361
#ifdef __ANDROID__
#define _GLIBCXX_USE_C99 1
# define _GLIBCXX_USE_C99 1
#endif
#include "FIReader.hpp"
#include "Exceptional.h"
#include <assimp/IOStream.hpp>
#include <assimp/types.h>
@ -485,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));
@ -503,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));
@ -685,7 +691,7 @@ public:
if (intValue) {
return intValue->value.size() == 1 ? intValue->value.front() : 0;
}
return stoi(attr->value->toString());
return atoi(attr->value->toString().c_str());
}
virtual int getAttributeValueAsInt(int idx) const /*override*/ {
@ -696,7 +702,7 @@ public:
if (intValue) {
return intValue->value.size() == 1 ? intValue->value.front() : 0;
}
return stoi(attributes[idx].value->toString());
return atoi(attributes[idx].value->toString().c_str());
}
virtual float getAttributeValueAsFloat(const char* name) const /*override*/ {
@ -708,7 +714,7 @@ public:
if (floatValue) {
return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
}
return stof(attr->value->toString());
return atof(attr->value->toString().c_str());
}
virtual float getAttributeValueAsFloat(int idx) const /*override*/ {
@ -719,7 +725,7 @@ public:
if (floatValue) {
return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
}
return stof(attributes[idx].value->toString());
return atof(attributes[idx].value->toString().c_str());
}
virtual const char* getNodeName() const /*override*/ {
@ -984,13 +990,13 @@ private:
if (index < 32) {
FIDecoder *decoder = defaultDecoder[index];
if (!decoder) {
throw DeadlyImportError("Invalid encoding algorithm index " + std::to_string(index));
throw DeadlyImportError("Invalid encoding algorithm index " + to_string(index));
}
return decoder->decode(dataP, len);
}
else {
if (index - 32 >= vocabulary.encodingAlgorithmTable.size()) {
throw DeadlyImportError("Invalid encoding algorithm index " + std::to_string(index));
throw DeadlyImportError("Invalid encoding algorithm index " + to_string(index));
}
std::string uri = vocabulary.encodingAlgorithmTable[index - 32];
auto it = decoderMap.find(uri);
@ -1014,12 +1020,12 @@ private:
alphabet = "0123456789-:TZ ";
break;
default:
throw DeadlyImportError("Invalid restricted alphabet index " + std::to_string(index));
throw DeadlyImportError("Invalid restricted alphabet index " + to_string(index));
}
}
else {
if (index - 16 >= vocabulary.restrictedAlphabetTable.size()) {
throw DeadlyImportError("Invalid restricted alphabet index " + std::to_string(index));
throw DeadlyImportError("Invalid restricted alphabet index " + to_string(index));
}
alphabet = vocabulary.restrictedAlphabetTable[index - 16];
}
@ -1027,7 +1033,7 @@ private:
utf8::utf8to32(alphabet.begin(), alphabet.end(), back_inserter(alphabetUTF32));
std::string::size_type alphabetLength = alphabetUTF32.size();
if (alphabetLength < 2) {
throw DeadlyImportError("Invalid restricted alphabet length " + std::to_string(alphabetLength));
throw DeadlyImportError("Invalid restricted alphabet length " + to_string(alphabetLength));
}
std::string::size_type bitsPerCharacter = 1;
while ((1ull << bitsPerCharacter) <= alphabetLength) {

View File

@ -46,12 +46,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef INCLUDED_AI_FI_READER_H
#define INCLUDED_AI_FI_READER_H
#ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
//#include <wchar.h>
#include <string>
#include <memory>
#include <cerrno>
#include <cwchar>
#include <memory>
#include <vector>
#include <cstdint>
//#include <stdio.h>
//#include <cstdint>
#include <irrXML.h>
namespace Assimp {
@ -176,4 +180,6 @@ FIReader::~FIReader() {
}// namespace Assimp
#endif // #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
#endif // INCLUDED_AI_FI_READER_H

View File

@ -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);
}

View File

@ -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;

View File

@ -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
@ -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)
@ -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

View File

@ -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);
@ -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);

View File

@ -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 <>
@ -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);