Fixed clang's casting issue and MSVC's buffer allocation problem
parent
60e9157699
commit
0ff3e40157
|
@ -96,13 +96,14 @@ static const aiImporterDesc desc = {
|
||||||
|
|
||||||
// workaround: the SDK expects a C callback, but we want to use Assimp::IOSystem to implement that
|
// workaround: the SDK expects a C callback, but we want to use Assimp::IOSystem to implement that
|
||||||
extern "C" {
|
extern "C" {
|
||||||
struct Assimp::IOSystem* m3dimporter_pIOHandler;
|
void* m3dimporter_pIOHandler;
|
||||||
|
|
||||||
unsigned char *m3dimporter_readfile(char *fn, unsigned int *size) {
|
unsigned char *m3dimporter_readfile(char *fn, unsigned int *size) {
|
||||||
ai_assert( nullptr != fn );
|
ai_assert( nullptr != fn );
|
||||||
ai_assert( nullptr != size );
|
ai_assert( nullptr != size );
|
||||||
std::string file(fn);
|
std::string file(fn);
|
||||||
std::unique_ptr<Assimp::IOStream> pStream( m3dimporter_pIOHandler->Open( file, "rb"));
|
std::unique_ptr<Assimp::IOStream> pStream(
|
||||||
|
(reinterpret_cast<Assimp::IOSystem*>(m3dimporter_pIOHandler))->Open( file, "rb"));
|
||||||
size_t fileSize = pStream->FileSize();
|
size_t fileSize = pStream->FileSize();
|
||||||
// should be allocated with malloc(), because the library will call free() to deallocate
|
// should be allocated with malloc(), because the library will call free() to deallocate
|
||||||
unsigned char *data = (unsigned char*)malloc(fileSize);
|
unsigned char *data = (unsigned char*)malloc(fileSize);
|
||||||
|
@ -179,7 +180,8 @@ void M3DImporter::InternReadFile( const std::string &file, aiScene* pScene, IOSy
|
||||||
if( fileSize < 8 ) {
|
if( fileSize < 8 ) {
|
||||||
throw DeadlyImportError( "M3D-file " + file + " is too small." );
|
throw DeadlyImportError( "M3D-file " + file + " is too small." );
|
||||||
}
|
}
|
||||||
unsigned char data[fileSize];
|
std::unique_ptr<unsigned char[]> _buffer (new unsigned char[fileSize]);
|
||||||
|
unsigned char *data( _buffer.get() );
|
||||||
if(fileSize != pStream->Read(data,1,fileSize)) {
|
if(fileSize != pStream->Read(data,1,fileSize)) {
|
||||||
throw DeadlyImportError( "Failed to read the file " + file + "." );
|
throw DeadlyImportError( "Failed to read the file " + file + "." );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1987,7 +1987,7 @@ M3D_INDEX _m3d_gettx(m3d_t *model, m3dread_t readfilecb, m3dfree_t freecb, char
|
||||||
i = strlen(fn);
|
i = strlen(fn);
|
||||||
if(i < 5 || fn[i - 4] != '.') {
|
if(i < 5 || fn[i - 4] != '.') {
|
||||||
fn2 = (char*)M3D_MALLOC(i + 5);
|
fn2 = (char*)M3D_MALLOC(i + 5);
|
||||||
if(!fn2) { model->errcode = M3D_ERR_ALLOC; return -1U; }
|
if(!fn2) { model->errcode = M3D_ERR_ALLOC; return (M3D_INDEX)-1U; }
|
||||||
memcpy(fn2, fn, i);
|
memcpy(fn2, fn, i);
|
||||||
memcpy(fn2+i, ".png", 5);
|
memcpy(fn2+i, ".png", 5);
|
||||||
buff = (*readfilecb)(fn2, &len);
|
buff = (*readfilecb)(fn2, &len);
|
||||||
|
@ -2005,12 +2005,12 @@ M3D_INDEX _m3d_gettx(m3d_t *model, m3dread_t readfilecb, m3dfree_t freecb, char
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!buff) return -1U;
|
if(!buff) return (M3D_INDEX)-1U;
|
||||||
i = model->numtexture++;
|
i = model->numtexture++;
|
||||||
model->texture = (m3dtx_t*)M3D_REALLOC(model->texture, model->numtexture * sizeof(m3dtx_t));
|
model->texture = (m3dtx_t*)M3D_REALLOC(model->texture, model->numtexture * sizeof(m3dtx_t));
|
||||||
if(!model->texture) {
|
if(!model->texture) {
|
||||||
if(freecb) (*freecb)(buff);
|
if(freecb) (*freecb)(buff);
|
||||||
model->errcode = M3D_ERR_ALLOC; return -1U;
|
model->errcode = M3D_ERR_ALLOC; return (M3D_INDEX)-1U;
|
||||||
}
|
}
|
||||||
model->texture[i].w = model->texture[i].h = 0; model->texture[i].d = NULL;
|
model->texture[i].w = model->texture[i].h = 0; model->texture[i].d = NULL;
|
||||||
if(buff[0] == 0x89 && buff[1] == 'P' && buff[2] == 'N' && buff[3] == 'G') {
|
if(buff[0] == 0x89 && buff[1] == 'P' && buff[2] == 'N' && buff[3] == 'G') {
|
||||||
|
@ -2038,7 +2038,7 @@ M3D_INDEX _m3d_gettx(m3d_t *model, m3dread_t readfilecb, m3dfree_t freecb, char
|
||||||
M3D_FREE(model->texture[i].d);
|
M3D_FREE(model->texture[i].d);
|
||||||
model->errcode = M3D_ERR_UNKIMG;
|
model->errcode = M3D_ERR_UNKIMG;
|
||||||
model->numtexture--;
|
model->numtexture--;
|
||||||
return -1U;
|
return (M3D_INDEX)-1U;
|
||||||
}
|
}
|
||||||
model->texture[i].name = fn;
|
model->texture[i].name = fn;
|
||||||
return i;
|
return i;
|
||||||
|
@ -3198,7 +3198,7 @@ m3db_t *m3d_pose(m3d_t *model, M3D_INDEX actionid, uint32_t msec)
|
||||||
p = &model->vertex[ret[i].ori];
|
p = &model->vertex[ret[i].ori];
|
||||||
f = &model->vertex[tmp[i].ori];
|
f = &model->vertex[tmp[i].ori];
|
||||||
v = &model->vertex[j];
|
v = &model->vertex[j];
|
||||||
d = (p->w * f->w + p->x * f->x + p->y * f->y + p->z * f->z < 0) ? -1 : 1;
|
d = (p->w * f->w + p->x * f->x + p->y * f->y + p->z * f->z < 0) ? (M3D_FLOAT)-1.0 : (M3D_FLOAT)1.0;
|
||||||
v->x = p->x + t * (d*f->x - p->x);
|
v->x = p->x + t * (d*f->x - p->x);
|
||||||
v->y = p->y + t * (d*f->y - p->y);
|
v->y = p->y + t * (d*f->y - p->y);
|
||||||
v->z = p->z + t * (d*f->z - p->z);
|
v->z = p->z + t * (d*f->z - p->z);
|
||||||
|
@ -4419,7 +4419,7 @@ namespace M3D {
|
||||||
!this->model->material[idx].prop) return -1.0f;
|
!this->model->material[idx].prop) return -1.0f;
|
||||||
for (int i = 0; i < this->model->material[idx].numprop; i++) {
|
for (int i = 0; i < this->model->material[idx].numprop; i++) {
|
||||||
if (this->model->material[idx].prop[i].type == type)
|
if (this->model->material[idx].prop[i].type == type)
|
||||||
return this->model->material[idx].prop[i].value.num;
|
return this->model->material[idx].prop[i].value.fnum;
|
||||||
}
|
}
|
||||||
return -1.0f;
|
return -1.0f;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue