Skip to content

Commit

Permalink
Merge branch 'main' into shader_khr_texture_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Jan 31, 2024
2 parents 8240412 + db4df38 commit 2f6c293
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 53 deletions.
8 changes: 5 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

### ? - ?

##### Additions :tada:
##### Fixes :wrench:

- Improved `KHR_texture_transform` extension by moving it from native to Unity. This makes the texture transformations more efficient and reliable. The shader now handles the scale and offset values.
- Removed the "Universal Additional Camera Data" script from DynamicCamera, as it shows up as a missing script in other render pipelines.
- Fixed a bug where adding a `CesiumSubScene` as the child of an existing `CesiumGeoreference` in editor would cause the parent `CesiumGeoreference` to have its coordinates reset to the default.
- Fixed the "DynamicCamera is not nested inside a game object with a CesiumGeoreference" warning when adding a new DynamicCamera in the editor.
- `KHR_texture_transform` is now applied in ShaderGraph, instead of being baked directly into texture coordinates.

### v1.7.1 - 2023-12-14

Expand All @@ -19,7 +22,6 @@
- Added support for multiple Cesium ion servers by creating `CesiumIonServer` assets.

In addition to the above, this release updates [cesium-native](https://github.com/CesiumGS/cesium-native) from v0.27.3 to v0.27.4. See the [changelog](https://github.com/CesiumGS/cesium-native/blob/main/CHANGES.md) for a complete list of changes in cesium-native.
>>>>>>> main

### v1.6.4 - 2023-10-26

Expand Down
3 changes: 1 addition & 2 deletions Editor/CesiumEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,8 @@ public static CesiumCameraController CreateDynamicCamera()

GameObject dynamicCameraPrefab = Resources.Load<GameObject>("DynamicCamera");
GameObject dynamicCameraObject =
UnityEngine.Object.Instantiate(dynamicCameraPrefab);
UnityEngine.Object.Instantiate(dynamicCameraPrefab, georeference.gameObject.transform);
dynamicCameraObject.name = "DynamicCamera";
dynamicCameraObject.transform.parent = georeference.gameObject.transform;

Undo.RegisterCreatedObjectUndo(dynamicCameraObject, "Create DynamicCamera");

Expand Down
8 changes: 8 additions & 0 deletions EditorTests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions EditorTests/CesiumEditorTests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "CesiumEditorTests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"CesiumRuntime",
"Unity.Mathematics"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions EditorTests/CesiumEditorTests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions EditorTests/TestCesiumSubScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using CesiumForUnity;
using NUnit.Framework;
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;

public class TestCesiumSubScene
{
[UnityTest]
public IEnumerator AddingSubSceneCopiesGeoreferenceCoordinates()
{
GameObject goGeoreference = new GameObject("Georeference");
CesiumGeoreference georeference = goGeoreference.AddComponent<CesiumGeoreference>();
georeference.SetOriginLongitudeLatitudeHeight(-55.0, 55.0, 1000.0);

GameObject goSubScene = new GameObject("SubScene");
goSubScene.transform.parent = goGeoreference.transform;
CesiumSubScene subScene = goSubScene.AddComponent<CesiumSubScene>();

yield return null;

Assert.AreEqual(-55.0, georeference.longitude);
Assert.AreEqual(55.0, georeference.latitude);
Assert.AreEqual(1000.0, georeference.height);
Assert.AreEqual(georeference.longitude, subScene.longitude);
Assert.AreEqual(georeference.latitude, subScene.latitude);
Assert.AreEqual(georeference.height, subScene.height);
}

[UnityTest]
public IEnumerator ModifyingSubsceneModifiesParentGeoreference()
{
GameObject goGeoreference = new GameObject("Georeference");
CesiumGeoreference georeference = goGeoreference.AddComponent<CesiumGeoreference>();
georeference.SetOriginLongitudeLatitudeHeight(-55.0, 55.0, 1000.0);

GameObject goSubScene = new GameObject("SubScene");
goSubScene.transform.parent = goGeoreference.transform;
CesiumSubScene subScene = goSubScene.AddComponent<CesiumSubScene>();

yield return null;

subScene.SetOriginLongitudeLatitudeHeight(-10.0, 10.0, 100.0);

yield return null;

Assert.AreEqual(subScene.longitude, -10.0);
Assert.AreEqual(subScene.latitude, 10.0);
Assert.AreEqual(subScene.height, 100.0);

Assert.AreEqual(georeference.longitude, -10.0);
Assert.AreEqual(georeference.latitude, 10.0);
Assert.AreEqual(georeference.height, 100.0);
}
}
11 changes: 11 additions & 0 deletions EditorTests/TestCesiumSubScene.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Reinterop~/CppType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static CppType FromCSharp(CppGenerationContext context, ITypeSymbol type)
if (named != null && named.Name == "Nullable" && named.TypeArguments.Length == 1)
{
CppType nullabledType = CppType.FromCSharp(context, named.TypeArguments[0]);
if (nullabledType.Kind == InteropTypeKind.BlittableStruct)
if (nullabledType.Kind == InteropTypeKind.BlittableStruct || nullabledType.Kind == InteropTypeKind.Primitive)
return new CppType(InteropTypeKind.Nullable, new[] {"std"}, "optional", new[] { nullabledType }, 0, "<optional>");
}

Expand Down Expand Up @@ -463,6 +463,7 @@ public string GetConversionToInteropType(CppGenerationContext context, string va
return $"::std::uint32_t({variableName})";
case InteropTypeKind.EnumFlags:
return $"{variableName}.underlying_value()";
case InteropTypeKind.Primitive:
case InteropTypeKind.BlittableStruct:
if (this.Flags.HasFlag(CppTypeFlags.Reference))
return $"&{variableName}";
Expand All @@ -473,7 +474,6 @@ public string GetConversionToInteropType(CppGenerationContext context, string va
return $"{variableName}.has_value() ? &{variableName}.value() : nullptr";
else
return variableName;
case InteropTypeKind.Primitive:
case InteropTypeKind.Unknown:
default:
return variableName;
Expand Down
6 changes: 4 additions & 2 deletions Reinterop~/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static (string Name, string Content) CreateCSharpDelegateInit(
CSharpType csReturnType = CSharpType.FromSymbol(context, returnType);
CSharpType csInteropReturnType = csReturnType.AsInteropTypeReturn();

// Rewrite methods that return a blittable struct to instead taking a pointer to one.
// Rewrite methods that return a blittable struct to instead take a pointer to one.
// See Interop.RewriteStructReturn in this file for the C++ side of this and more
// explanation of why it's needed.
bool hasStructRewrite = false;
Expand Down Expand Up @@ -600,7 +600,9 @@ public static bool RewriteStructReturn(ref IEnumerable<(string ParameterName, st

return true;
}
else if (returnType.Kind == InteropTypeKind.Nullable && interopReturnType.Kind == InteropTypeKind.BlittableStruct)
else if (returnType.Kind == InteropTypeKind.Nullable &&
(interopReturnType.Kind == InteropTypeKind.BlittableStruct ||
interopReturnType.Kind == InteropTypeKind.Primitive))
{
CppType originalInteropReturnType = interopReturnType;
interopReturnType = CppType.UInt8;
Expand Down
69 changes: 60 additions & 9 deletions Runtime/CesiumSubScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ public double ecefZ
[NonSerialized]
internal CesiumGeoreference _parentGeoreference;

#if UNITY_EDITOR
// The coordinates of the parent CesiumGeoreference before being changed by `UpdateOrigin`.
// This is used when adding a CesiumSubScene component to a GameObject. Since `OnEnable`
// runs before `Reset`, it will force the georeference to move to the default coordinates
// of CesiumSubScene, which is undesired. But there's no way to modify `OnEnable` to
// distinguish whether the subscene was just added or already existed in the scene.
// Instead, we need to store the georeference's previous values during `OnEnable`,
// so that we can move it back during `Reset`.
[NonSerialized]
private double3 _oldParentCoordinates = double3.zero;

[NonSerialized]
private CesiumGeoreferenceOriginAuthority _oldParentOriginAuthority;
#endif

/// <summary>
/// Sets the origin of the coordinate system to particular <see cref="ecefX"/>, <see cref="ecefY"/>,
/// <see cref="ecefZ"/> coordinates in the Earth-Centered, Earth-Fixed (ECEF) frame.
Expand Down Expand Up @@ -231,6 +246,17 @@ public void SetOriginLongitudeLatitudeHeight(double longitude, double latitude,
this.originAuthority = CesiumGeoreferenceOriginAuthority.LongitudeLatitudeHeight;
}

private void CopyParentCoordinates()
{
this._longitude = this._parentGeoreference.longitude;
this._latitude = this._parentGeoreference.latitude;
this._height = this._parentGeoreference.height;

this._ecefX = this._parentGeoreference.ecefX;
this._ecefY = this._parentGeoreference.ecefY;
this._ecefZ = this._parentGeoreference.ecefZ;
}

private void DetachFromParentIfNeeded()
{
if (this._parentGeoreference != null)
Expand Down Expand Up @@ -263,6 +289,7 @@ private void OnValidate()
this.UpdateOrigin();
}

#if UNITY_EDITOR
/// <summary>
/// Called by the Editor when the user chooses to "reset" the component.
/// The implementation here makes sure the newly-reset values for the serialized
Expand All @@ -271,7 +298,24 @@ private void OnValidate()
private void Reset()
{
this.UpdateParentReference();

// The default coordinates for the CesiumSubScene component should be the coordinates of its parent, if possible.
// This means adding the component as the child of an existing CesiumGeoreference won't reset the parent's coordinates.
if (this._parentGeoreference != null)
{
if (this._oldParentOriginAuthority == CesiumGeoreferenceOriginAuthority.EarthCenteredEarthFixed)
{
this._parentGeoreference.SetOriginEarthCenteredEarthFixed(this._oldParentCoordinates.x, this._oldParentCoordinates.y, this._oldParentCoordinates.z);
}
else
{
this._parentGeoreference.SetOriginLongitudeLatitudeHeight(this._oldParentCoordinates.x, this._oldParentCoordinates.y, this._oldParentCoordinates.z);
}

this.CopyParentCoordinates();
}
}
#endif

private void OnEnable()
{
Expand All @@ -291,6 +335,19 @@ private void OnEnable()
scene.gameObject.SetActive(false);
}

#if UNITY_EDITOR
// The parent's previous coordinates are saved here in case they have to be reverted in the editor during `Reset`
this._oldParentOriginAuthority = this._parentGeoreference.originAuthority;
if (this._oldParentOriginAuthority == CesiumGeoreferenceOriginAuthority.EarthCenteredEarthFixed)
{
this._oldParentCoordinates = new double3(this._parentGeoreference.ecefX, this._parentGeoreference.ecefY, this._parentGeoreference.ecefZ);
}
else
{
this._oldParentCoordinates = new double3(this._parentGeoreference.longitude, this._parentGeoreference.latitude, this._parentGeoreference.height);
}
#endif

this.UpdateOrigin();
}

Expand All @@ -310,13 +367,7 @@ private void OnParentChanged()

// Update our origin to our parent georef, maintain our origin authority,
// and copy both sets of reference coordinates. No need to calculate any of this again
this._longitude = this._parentGeoreference.longitude;
this._latitude = this._parentGeoreference.latitude;
this._height = this._parentGeoreference.height;

this._ecefX = this._parentGeoreference.ecefX;
this._ecefY = this._parentGeoreference.ecefY;
this._ecefZ = this._parentGeoreference.ecefZ;
this.CopyParentCoordinates();
}

private void OnDisable()
Expand Down Expand Up @@ -386,7 +437,7 @@ public void UpdateOrigin()
}
}

#if UNITY_EDITOR
#if UNITY_EDITOR
private void OnDrawGizmos()
{
if (this._showActivationRadius)
Expand All @@ -396,6 +447,6 @@ private void OnDrawGizmos()
Gizmos.DrawWireSphere(this.transform.position, (float)this._activationRadius);
}
}
#endif
#endif
}
}
34 changes: 0 additions & 34 deletions Runtime/Resources/DynamicCamera.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ GameObject:
- component: {fileID: 5627069538230183851}
- component: {fileID: 5627069538230183848}
- component: {fileID: 5627069538230183849}
- component: {fileID: 5627069538230183850}
- component: {fileID: 7346015802769307894}
- component: {fileID: 7574593196070563001}
- component: {fileID: 1447381297153131539}
Expand Down Expand Up @@ -89,39 +88,6 @@ AudioListener:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5627069538230183846}
m_Enabled: 1
--- !u!114 &5627069538230183850
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5627069538230183846}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 1
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
--- !u!114 &7346015802769307894
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit 2f6c293

Please sign in to comment.