-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chenmiwei
committed
Sep 27, 2021
1 parent
22689c8
commit 9b1b34e
Showing
8 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
package/com.unity.formats.usd/Dependencies/USD.NET.Unity/Geometry/LightSample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using UnityEngine; | ||
|
||
namespace USD.NET.Unity | ||
{ | ||
[System.Serializable] | ||
public class LightSampleBase : XformSample | ||
{ | ||
// Core Light parameters | ||
public Color color; | ||
public float intensity; | ||
public LightShadows shadowType; | ||
|
||
public LightSampleBase() | ||
{ | ||
} | ||
|
||
public void CopyFromLight(UnityEngine.Light light, bool convertTransformToUsd = true) | ||
{ | ||
color = light.color; | ||
intensity = light.intensity; | ||
shadowType = light.shadows; | ||
|
||
var tr = light.transform; | ||
transform = UnityEngine.Matrix4x4.TRS(tr.localPosition, | ||
tr.localRotation, | ||
tr.localScale); | ||
if (convertTransformToUsd) | ||
{ | ||
ConvertTransform(); | ||
} | ||
} | ||
|
||
public void CopyToLight(UnityEngine.Light light, bool setTransform) | ||
{ | ||
light.color = color; | ||
light.intensity = intensity; | ||
light.shadows = shadowType; | ||
|
||
if (setTransform) | ||
{ | ||
var tr = light.transform; | ||
var xf = transform; | ||
UnityTypeConverter.SetTransform(xf, tr); | ||
} | ||
} | ||
} | ||
|
||
[System.Serializable] | ||
[UsdSchema("DistantLight")] | ||
public class DistantLightSample : LightSampleBase | ||
{ | ||
public DistantLightSample() | ||
{ | ||
} | ||
|
||
public DistantLightSample(UnityEngine.Light fromLight) | ||
{ | ||
base.CopyFromLight(fromLight); | ||
} | ||
|
||
new public void CopyToLight(UnityEngine.Light light, bool setTransform) | ||
{ | ||
light.type = LightType.Directional; | ||
base.CopyToLight(light, setTransform); | ||
} | ||
} | ||
|
||
[System.Serializable] | ||
[UsdSchema("SphereLight")] | ||
public class PointLightSample : LightSampleBase | ||
{ | ||
// Core Light parameters | ||
public float range; | ||
|
||
public PointLightSample() | ||
{ | ||
} | ||
|
||
public PointLightSample(UnityEngine.Light fromLight) | ||
{ | ||
range = fromLight.range; | ||
base.CopyFromLight(fromLight); | ||
} | ||
|
||
new public void CopyToLight(UnityEngine.Light light, bool setTransform) | ||
{ | ||
light.type = LightType.Point; | ||
light.range = range; | ||
base.CopyToLight(light, setTransform); | ||
} | ||
} | ||
|
||
[System.Serializable] | ||
[UsdSchema("RectLight")] | ||
public class RectLightSample : LightSampleBase | ||
{ | ||
public RectLightSample() | ||
{ | ||
} | ||
|
||
public RectLightSample(UnityEngine.Light fromLight) | ||
{ | ||
base.CopyFromLight(fromLight); | ||
} | ||
|
||
new public void CopyToLight(UnityEngine.Light light, bool setTransform) | ||
{ | ||
light.type = LightType.Rectangle; | ||
base.CopyToLight(light, setTransform); | ||
} | ||
} | ||
|
||
[System.Serializable] | ||
[UsdSchema("DiskLight")] | ||
public class DiskLightSample : LightSampleBase | ||
{ | ||
public DiskLightSample() | ||
{ | ||
} | ||
|
||
public DiskLightSample(UnityEngine.Light fromLight) | ||
{ | ||
base.CopyFromLight(fromLight); | ||
} | ||
|
||
new public void CopyToLight(UnityEngine.Light light, bool setTransform) | ||
{ | ||
light.type = LightType.Disc; | ||
base.CopyToLight(light, setTransform); | ||
} | ||
} | ||
} |
Empty file.
18 changes: 18 additions & 0 deletions
18
package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/LightImporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
|
||
using UnityEngine; | ||
using USD.NET.Unity; | ||
|
||
namespace Unity.Formats.USD | ||
{ | ||
public static class LightImporter<T> where T : LightSampleBase | ||
{ | ||
public static void BuildLight(T usdLight, | ||
GameObject go, | ||
SceneImportOptions options) | ||
{ | ||
var light = ImporterBase.GetOrAddComponent<Light>(go); | ||
usdLight.CopyToLight(light, setTransform: false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters