Browse Source

Fix Assimp to not give negative light direction. Fix FOV handling for spot lights in AssetImporter. Added error prints to Editor if fails to execute AssetImporter. Closes #669.

Lasse Öörni 10 năm trước cách đây
mục cha
commit
0c48c9df87

+ 5 - 2
Source/ThirdParty/Assimp/code/ASELoader.cpp

@@ -43,6 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *  @brief Implementation of the ASE importer class
  */
 
+// Modified by Lasse Oorni for Urho3D
+
 #include "AssimpPCH.h"
 #ifndef ASSIMP_BUILD_NO_ASE_IMPORTER
 
@@ -449,8 +451,9 @@ void ASEImporter::BuildLights()
 
 			// The direction is encoded in the transformation matrix of the node. 
 			// In 3DS MAX the light source points into negative Z direction if 
-			// the node transformation is the identity. 
-			out->mDirection = aiVector3D(0.f,0.f,-1.f);
+			// the node transformation is the identity.
+            // Urho3D: lights should use positive Z as local direction
+			out->mDirection = aiVector3D(0.f,0.f,1.f);
 
 			out->mName.Set(in.mName);
 			switch (in.mLightType)

+ 5 - 1
Source/ThirdParty/Assimp/code/BlenderLoader.cpp

@@ -42,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /** @file  BlenderLoader.cpp
  *  @brief Implementation of the Blender3D importer class.
  */
+
+// Modified by Lasse Oorni for Urho3D
+
 #include "AssimpPCH.h"
 
 //#define ASSIMP_BUILD_NO_COMPRESSED_BLEND
@@ -1024,7 +1027,8 @@ aiLight* BlenderImporter::ConvertLight(const Scene& in, const Object* obj, const
 	        out->mType = aiLightSource_DIRECTIONAL;
 
 	        // blender orients directional lights as facing toward -z
-	        out->mDirection = aiVector3D(0.f, 0.f, -1.f);
+            // Urho3D: lights should use positive Z as local direction
+	        out->mDirection = aiVector3D(0.f, 0.f, 1.f);
 	        break;
 	    default:
 	        break;

+ 4 - 1
Source/ThirdParty/Assimp/code/ColladaLoader.cpp

@@ -41,6 +41,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 /** @file Implementation of the Collada loader */
 
+// Modified by Lasse Oorni for Urho3D
+
 #include "AssimpPCH.h"
 #ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
 
@@ -318,7 +320,8 @@ void ColladaLoader::BuildLightsForNode( const ColladaParser& pParser, const Coll
 		out->mType = (aiLightSourceType)srcLight->mType;
 
 		// collada lights point in -Z by default, rest is specified in node transform
-		out->mDirection = aiVector3D(0.f,0.f,-1.f);
+        // Urho3D: lights should use positive Z as local direction
+        out->mDirection = aiVector3D(0.f, 0.f,1.f);
 
 		out->mAttenuationConstant = srcLight->mAttConstant;
 		out->mAttenuationLinear = srcLight->mAttLinear;

+ 1 - 1
Source/Tools/AssetImporter/AssetImporter.cpp

@@ -1415,7 +1415,7 @@ void BuildAndSaveScene(OutScene& scene, bool asPrefab)
                 break;
             case aiLightSource_SPOT:
                 outLight->SetLightType(LIGHT_SPOT);
-                outLight->SetFov(light->mAngleOuterCone * M_RADTODEG);
+                outLight->SetFov(light->mAngleOuterCone * 0.5f * M_RADTODEG);
                 break;
             case aiLightSource_POINT:
                 outLight->SetLightType(LIGHT_POINT);

+ 4 - 0
bin/Data/Scripts/Editor/EditorImport.as

@@ -55,6 +55,8 @@ void ImportModel(const String&in fileName)
 
         FocusNode(newNode);
     }
+    else
+        log.Error("Failed to execute AssetImporter to import model");
 }
 
 void ImportScene(const String&in fileName)
@@ -88,6 +90,8 @@ void ImportScene(const String&in fileName)
             fileSystem.Delete(tempSceneName);
             UpdateWindowTitle();
         }
+        else
+            log.Error("Failed to execute AssetImporter to import scene");
     }
 }