Fix compiler errors and crashes with Assimp loader

This commit is contained in:
rdb 2015-06-19 21:18:28 +02:00
parent efa8633cb0
commit 945d3c4035
4 changed files with 22 additions and 9 deletions

View File

@ -25,7 +25,6 @@
#include "materialAttrib.h" #include "materialAttrib.h"
#include "textureAttrib.h" #include "textureAttrib.h"
#include "cullFaceAttrib.h" #include "cullFaceAttrib.h"
#include "lightNode.h"
#include "ambientLight.h" #include "ambientLight.h"
#include "directionalLight.h" #include "directionalLight.h"
#include "spotlight.h" #include "spotlight.h"
@ -570,12 +569,15 @@ load_light(const aiLight &light) {
aiColor3D col; aiColor3D col;
aiVector3D vec; aiVector3D vec;
PT(LightNode) lnode; PT(PandaNode) lnode;
switch (light.mType) { switch (light.mType) {
case aiLightSource_DIRECTIONAL: { case aiLightSource_DIRECTIONAL: {
PT(DirectionalLight) dlight = new DirectionalLight(name); PT(DirectionalLight) dlight = new DirectionalLight(name);
lnode = DCAST(LightNode, dlight); lnode = DCAST(PandaNode, dlight);
col = light.mColorDiffuse;
dlight->set_color(LColor(col.r, col.g, col.b, 1));
col = light.mColorSpecular; col = light.mColorSpecular;
dlight->set_specular_color(LColor(col.r, col.g, col.b, 1)); dlight->set_specular_color(LColor(col.r, col.g, col.b, 1));
@ -589,7 +591,10 @@ load_light(const aiLight &light) {
case aiLightSource_POINT: { case aiLightSource_POINT: {
PT(PointLight) plight = new PointLight(name); PT(PointLight) plight = new PointLight(name);
lnode = DCAST(LightNode, plight); lnode = DCAST(PandaNode, plight);
col = light.mColorDiffuse;
plight->set_color(LColor(col.r, col.g, col.b, 1));
col = light.mColorSpecular; col = light.mColorSpecular;
plight->set_specular_color(LColor(col.r, col.g, col.b, 1)); plight->set_specular_color(LColor(col.r, col.g, col.b, 1));
@ -604,7 +609,10 @@ load_light(const aiLight &light) {
case aiLightSource_SPOT: { case aiLightSource_SPOT: {
PT(Spotlight) plight = new Spotlight(name); PT(Spotlight) plight = new Spotlight(name);
lnode = DCAST(LightNode, plight); lnode = DCAST(PandaNode, plight);
col = light.mColorDiffuse;
plight->set_color(LColor(col.r, col.g, col.b, 1));
col = light.mColorSpecular; col = light.mColorSpecular;
plight->set_specular_color(LColor(col.r, col.g, col.b, 1)); plight->set_specular_color(LColor(col.r, col.g, col.b, 1));
@ -630,15 +638,13 @@ load_light(const aiLight &light) {
} }
// If there's an ambient color, add it as ambient light. // If there's an ambient color, add it as ambient light.
col = light.mColorAmbient;
LVecBase4 ambient (col.r, col.g, col.b, 0); LVecBase4 ambient (col.r, col.g, col.b, 0);
if (ambient != LVecBase4::zero()) { if (ambient != LVecBase4::zero()) {
PT(AmbientLight) alight = new AmbientLight(name); PT(AmbientLight) alight = new AmbientLight(name);
col = light.mColorAmbient;
alight->set_color(ambient); alight->set_color(ambient);
_root->add_child(alight); _root->add_child(alight);
} }
_root->add_child(lnode); _root->add_child(lnode);
col = light.mColorDiffuse;
lnode->set_color(LColor(col.r, col.g, col.b, 1));
} }

View File

@ -78,6 +78,11 @@ Seek(size_t offset, aiOrigin origin) {
case aiOrigin_END: case aiOrigin_END:
_istream.seekg(offset, ios::end); _istream.seekg(offset, ios::end);
break; break;
default:
// Keep compiler happy
nassertr(false, AI_FAILURE);
break;
} }
if (_istream.good()) { if (_istream.good()) {
@ -105,4 +110,5 @@ Tell() const {
size_t PandaIOStream:: size_t PandaIOStream::
Write(const void *buffer, size_t size, size_t count) { Write(const void *buffer, size_t size, size_t count) {
nassertr(false, 0); nassertr(false, 0);
return 0;
} }

View File

@ -95,5 +95,6 @@ Open(const char *file, const char *mode) {
} else { } else {
nassertr(false, NULL); // Not implemented on purpose. nassertr(false, NULL); // Not implemented on purpose.
return NULL;
} }
} }

View File

@ -30,7 +30,7 @@ public:
protected: protected:
INLINE bool attachStream(Assimp::LogStream*, unsigned int) {}; INLINE bool attachStream(Assimp::LogStream*, unsigned int) {};
INLINE bool detatchStream(Assimp::LogStream*, unsigned int) {}; INLINE bool detatchStream(Assimp::LogStream*, unsigned int) {}; // sic
void OnDebug(const char *message); void OnDebug(const char *message);
void OnError(const char *message); void OnError(const char *message);