From 2fb07823f1b66b8f812d96a5b82d1cc69199f049 Mon Sep 17 00:00:00 2001 From: Calvin Hsu Date: Tue, 1 Oct 2013 13:21:26 -0700 Subject: [PATCH] Add basic light and camera support * Convert point and directional light * Convert perspective camera Not suppoted: * Spotlight, area lights * Perspective camera fov angle / focal length * Orthogonal camera --- code/BlenderLoader.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index 4bad638e2..3a8bb868e 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -958,19 +958,41 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co } // ------------------------------------------------------------------------------------------------ -aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* /*obj*/, const Camera* /*mesh*/, ConversionData& /*conv_data*/) +aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, const Camera* camera, ConversionData& /*conv_data*/) { ScopeGuard out(new aiCamera()); - - return NULL ; //out.dismiss(); + out->mName = obj->id.name+2; + out->mPosition = aiVector3D(0.f, 0.f, 0.f); + out->mUp = aiVector3D(0.f, 1.f, 0.f); + out->mLookAt = aiVector3D(0.f, 0.f, -1.f); + return out.dismiss(); } // ------------------------------------------------------------------------------------------------ -aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* /*obj*/, const Lamp* /*mesh*/, ConversionData& /*conv_data*/) +aiLight* BlenderImporter::ConvertLight(const Scene& in, const Object* obj, const Lamp* lamp, ConversionData& conv_data) { ScopeGuard out(new aiLight()); + out->mName = obj->id.name+2; - return NULL ; //out.dismiss(); + switch (lamp->type) + { + case Lamp::Type_Local: + out->mType = aiLightSource_POINT; + break; + case Lamp::Type_Sun: + out->mType = aiLightSource_DIRECTIONAL; + + // blender orients directional lights as facing toward -z + out->mDirection = aiVector3D(0.f, 0.f, -1.f); + break; + default: + break; + } + + out->mColorAmbient = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; + out->mColorSpecular = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; + out->mColorDiffuse = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; + return out.dismiss(); } // ------------------------------------------------------------------------------------------------