Skip to content

Commit 42037b2

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into UNI-24636-1.2.0b1-forum-release
# Conflicts: # Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs # CMakeLists.txt
2 parents 4fb67bf + 73c2c32 commit 42037b2

File tree

4 files changed

+157
-10
lines changed

4 files changed

+157
-10
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ public static Material DefaultMaterial {
124124
}
125125
static Material s_defaultMaterial = null;
126126

127+
static Dictionary<UnityEngine.LightType, FbxLight.EType> MapLightType = new Dictionary<UnityEngine.LightType, FbxLight.EType> () {
128+
{ UnityEngine.LightType.Directional, FbxLight.EType.eDirectional },
129+
{ UnityEngine.LightType.Spot, FbxLight.EType.eSpot },
130+
{ UnityEngine.LightType.Point, FbxLight.EType.ePoint },
131+
{ UnityEngine.LightType.Area, FbxLight.EType.eArea },
132+
};
133+
127134
/// <summary>
128135
/// Gets the version number of the FbxExporters plugin from the readme.
129136
/// </summary>
@@ -838,6 +845,76 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
838845
return true;
839846
}
840847

848+
/// <summary>
849+
/// Exports light component.
850+
/// Supported types: point, spot and directional
851+
/// Cookie => Gobo
852+
/// </summary>
853+
protected bool ExportLight (GameObject unityGo, FbxScene fbxScene, FbxNode fbxNode)
854+
{
855+
Light unityLight = unityGo.GetComponent<Light> ();
856+
857+
if (unityLight == null)
858+
return false;
859+
860+
FbxLight.EType fbxLightType;
861+
862+
// Is light type supported?
863+
if (!MapLightType.TryGetValue (unityLight.type, out fbxLightType))
864+
return false;
865+
866+
FbxLight fbxLight = FbxLight.Create (fbxScene.GetFbxManager (), unityLight.name);
867+
868+
// Set the type of the light.
869+
fbxLight.LightType.Set(fbxLightType);
870+
871+
switch (unityLight.type)
872+
{
873+
case LightType.Directional : {
874+
break;
875+
}
876+
case LightType.Spot : {
877+
// Set the angle of the light's spotlight cone in degrees.
878+
fbxLight.InnerAngle.Set(unityLight.spotAngle);
879+
fbxLight.OuterAngle.Set(unityLight.spotAngle);
880+
break;
881+
}
882+
case LightType.Point : {
883+
break;
884+
}
885+
case LightType.Area : {
886+
// TODO: areaSize: The size of the area light by scaling the node XY
887+
break;
888+
}
889+
}
890+
// The color of the light.
891+
var unityLightColor = unityLight.color;
892+
fbxLight.Color.Set (new FbxDouble3(unityLightColor.r, unityLightColor.g, unityLightColor.b));
893+
894+
// Set the Intensity of a light is multiplied with the Light color.
895+
fbxLight.Intensity.Set (unityLight.intensity * UnitScaleFactor /*compensate for Maya scaling by system units*/ );
896+
897+
// Set the range of the light.
898+
// applies-to: Point & Spot
899+
// => FarAttenuationStart, FarAttenuationEnd
900+
fbxLight.FarAttenuationStart.Set (0.01f /* none zero start */);
901+
fbxLight.FarAttenuationEnd.Set(unityLight.range*UnitScaleFactor);
902+
903+
// shadows Set how this light casts shadows
904+
// applies-to: Point & Spot
905+
bool unityLightCastShadows = unityLight.shadows != LightShadows.None;
906+
fbxLight.CastShadows.Set (unityLightCastShadows);
907+
908+
fbxNode.SetNodeAttribute (fbxLight);
909+
910+
// set +90 post rotation on x to counteract for FBX light's facing -Y direction by default
911+
fbxNode.SetPostRotation(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(90,0,0));
912+
// have to set rotation active to true in order for post rotation to be applied
913+
fbxNode.SetRotationActive (true);
914+
915+
return true;
916+
}
917+
841918
/// <summary>
842919
/// configures default camera for the scene
843920
/// </summary>
@@ -911,8 +988,14 @@ protected int ExportComponents (
911988
}
912989

913990
// export camera, but only if no mesh was exported
991+
bool exportedCamera = false;
914992
if (!exportedMesh) {
915-
ExportCamera (unityGo, fbxScene, fbxNode);
993+
exportedCamera = ExportCamera (unityGo, fbxScene, fbxNode);
994+
}
995+
996+
// export light, but only if no mesh or camera was exported
997+
if (!exportedMesh && !exportedCamera) {
998+
ExportLight (unityGo, fbxScene, fbxNode);
916999
}
9171000

9181001
if (Verbose)

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,6 @@ private Camera ExportCamera(string filename, GameObject cameraObj){
365365
return ExportComponent<Camera> (filename, cameraObj);
366366
}
367367

368-
private void CompareCameraValues(Camera camera, Camera fbxCamera, float delta=0.001f){
369-
Assert.AreEqual (camera.orthographic, fbxCamera.orthographic);
370-
Assert.AreEqual (camera.fieldOfView, fbxCamera.fieldOfView, delta);
371-
Assert.AreEqual (camera.nearClipPlane, fbxCamera.nearClipPlane, delta);
372-
Assert.AreEqual (camera.farClipPlane, fbxCamera.farClipPlane, delta);
373-
}
374-
375368
/// <summary>
376369
/// Exports the GameObject and returns component of type T.
377370
/// </summary>
@@ -389,6 +382,62 @@ private T ExportComponent<T>(string filename, GameObject obj) where T : Componen
389382
return fbxComponent;
390383
}
391384

385+
private void CompareCameraValues(Camera camera, Camera fbxCamera, float delta=0.001f){
386+
Assert.AreEqual (camera.orthographic, fbxCamera.orthographic);
387+
Assert.AreEqual (camera.fieldOfView, fbxCamera.fieldOfView, delta);
388+
Assert.AreEqual (camera.nearClipPlane, fbxCamera.nearClipPlane, delta);
389+
Assert.AreEqual (camera.farClipPlane, fbxCamera.farClipPlane, delta);
390+
}
391+
392+
[Test]
393+
public void TestExportLight()
394+
{
395+
// create a Unity light
396+
GameObject lightObj = new GameObject("TestLight");
397+
Light light = lightObj.AddComponent<Light> ();
398+
399+
light.type = LightType.Spot;
400+
light.spotAngle = 55.4f;
401+
light.color = Color.blue;
402+
light.intensity = 2.3f;
403+
light.range = 45;
404+
light.shadows = LightShadows.Soft;
405+
406+
string filename = GetRandomFbxFilePath ();
407+
var fbxLight = ExportComponent<Light> (filename, lightObj);
408+
CompareLightValues (light, fbxLight);
409+
410+
light.type = LightType.Point;
411+
light.color = Color.red;
412+
light.intensity = 0.4f;
413+
light.range = 120;
414+
light.shadows = LightShadows.Hard;
415+
416+
filename = GetRandomFbxFilePath ();
417+
fbxLight = ExportComponent<Light> (filename, lightObj);
418+
CompareLightValues (light, fbxLight);
419+
}
420+
421+
private void CompareLightValues(Light light, Light fbxLight, float delta=0.001f){
422+
Assert.AreEqual (light.type, fbxLight.type);
423+
if (light.type == LightType.Spot) {
424+
Assert.AreEqual (light.spotAngle, fbxLight.spotAngle, delta);
425+
}
426+
Assert.AreEqual (light.color, fbxLight.color);
427+
Assert.AreEqual (light.intensity, fbxLight.intensity, delta);
428+
Assert.AreEqual (light.range, fbxLight.range, delta);
429+
430+
// compare shadows
431+
// make sure that if we exported without shadows, don't import with shadows
432+
if (light.shadows == LightShadows.None) {
433+
Assert.AreEqual (LightShadows.None, fbxLight.shadows);
434+
} else {
435+
Assert.AreNotEqual (LightShadows.None, fbxLight.shadows);
436+
}
437+
438+
Assert.IsTrue (light.transform.rotation == fbxLight.transform.rotation);
439+
}
440+
392441
[Test]
393442
public void TestComponentAttributeExport()
394443
{

Assets/FbxExporters/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Copyright (c) 2017 Unity Technologies. All rights reserved.
55

66
See LICENSE.txt file for full license information.
77

8-
VERSION: sprint30
8+
VERSION: 1.2.0b1
99

1010
Requirements
1111
------------

RELEASE_NOTES.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RELEASE NOTES
1+
RELEASE NOTES
22

33
**Version**: 1.2.0b1
44

@@ -22,6 +22,21 @@ A "Run Component Updater" button will appear in the FBX export settings inspecto
2222
Clicking the button will repair all prefabs and scene files serialized as text.
2323
To repair binary files, first convert asset serialization mode to "Force Text" in Editor Settings (Edit->Project Settings->Editor).
2424

25+
**Version**: sprint36
26+
27+
NEW FEATURES
28+
*FbxExporter: Don't export visibility
29+
30+
FIXES
31+
*FbxPrefabAutoUpdater: Now accepts updates to RectTransforms
32+
*FbxExporter: Fix so camera exports with correct rotation
33+
*MayaIntegration: Fix so the "SendToUnity" button in Maya is hidden on startup
34+
*FbxPrefabAutoUpdater: Fix updating gameObjects with missing components
35+
*UnityIntegration: Catch and print installation errors from 3D applications
36+
*FbxExporter: Fix incorrect scaling when importing into Maya
37+
*FbxExportSettings: Fix vendor location environmnet variable pointing to empty folder
38+
*MaxIntegration: Reset export path on new scene
39+
2540
**Version**: sprint35
2641

2742
NEW FEATURES

0 commit comments

Comments
 (0)