Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Runtime/Scripts/AccessorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ enum AccessorUsage
Rotation = 1 << 11,
Scale = 1 << 12,
Weight = 1 << 13,
RequiredForInstantiation = 1 << 14
RequiredForInstantiation = 1 << 14,
Pointer = 1 << 15,
}

abstract class AccessorDataBase
Expand Down
74 changes: 74 additions & 0 deletions Runtime/Scripts/AnimationCameraGameObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace GLTFast {
public class AnimationCameraGameObject : MonoBehaviour {
public Camera targetCamera;
public bool orthographic;
public float localScale;

public float nearClipPlane;
float nearClipPlaneOld;
public float farClipPlane;
float farClipPlaneOld;

public float xMag;
public float yMag;
float xMagOld;
float yMagOld;

public float fov;
float fovOld;

void OnEnable() {
if (targetCamera == null) {
Debug.LogError("Target camera not set on animated camera!");
}
}

void LateUpdate() {
bool orthoChanged = false;
if(farClipPlane != farClipPlaneOld) {
if(orthographic) {
orthoChanged = true;
farClipPlane = farClipPlane >= 0 ? farClipPlane : float.MaxValue;
}
targetCamera.farClipPlane = localScale * farClipPlane;
farClipPlaneOld = farClipPlane;
}

if(nearClipPlane != nearClipPlaneOld) {
targetCamera.nearClipPlane = localScale * nearClipPlane;
nearClipPlaneOld = nearClipPlane;
orthoChanged = true;
}

if(xMag != xMagOld) {
xMagOld = xMag;
orthoChanged = true;
}

if(yMag != yMagOld) {
yMagOld = yMag;
orthoChanged = true;
}

if(fov != fovOld) {
targetCamera.fieldOfView = fov * Mathf.Rad2Deg;
fovOld = fov;
}

if(orthographic && orthoChanged) {
targetCamera.projectionMatrix = Matrix4x4.Ortho(
-xMag,
xMag,
-yMag,
yMag,
nearClipPlane,
farClipPlane
);
}
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/AnimationCameraGameObject.cs.meta

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

324 changes: 324 additions & 0 deletions Runtime/Scripts/AnimationData.cs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Runtime/Scripts/AnimationData.cs.meta

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

518 changes: 414 additions & 104 deletions Runtime/Scripts/AnimationUtils.cs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Runtime/Scripts/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public enum Extension
/// <see href="https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md">KHR_texture_transform</see> glTF extension
/// </summary>
TextureTransform,
/// <summary>
/// <see href="https://github.com/ux3d/glTF/blob/extensions/KHR_animation_pointer/extensions/2.0/Khronos/KHR_animation_pointer/README.md">KHR_texture_transform</see> glTF extension
/// </summary>
AnimationPointer
}

/// <summary>
Expand Down Expand Up @@ -104,6 +108,10 @@ public static class ExtensionName
/// <see href="https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_lights_punctual">KHR_lights_punctual</see> glTF extension
/// </summary>
public const string LightsPunctual = "KHR_lights_punctual";
/// <summary>
/// <see href="https://github.com/ux3d/glTF/blob/extensions/KHR_animation_pointer/extensions/2.0/Khronos/KHR_animation_pointer/README.md">KHR_texture_transform</see> glTF extension
/// </summary>
public const string AnimationPointer = "KHR_animation_pointer";

/// <summary>
/// Returns the official name of the glTF extension
Expand All @@ -114,6 +122,8 @@ public static string GetName(this Extension extension)
{
switch (extension)
{
case Extension.AnimationPointer:
return AnimationPointer;
case Extension.DracoMeshCompression:
return DracoMeshCompression;
case Extension.LightsPunctual:
Expand Down
21 changes: 21 additions & 0 deletions Runtime/Scripts/GameObjectInstantiator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ string cameraName
cam.nearClipPlane = nearClipPlane * localScale;
cam.farClipPlane = farClipPlane * localScale;

#if UNITY_ANIMATION
var camAnim = cam.transform.parent.gameObject.AddComponent<AnimationCameraGameObject>();
camAnim.orthographic = false;
camAnim.localScale = localScale;
camAnim.targetCamera = cam;
camAnim.fov = cam.fieldOfView;
camAnim.nearClipPlane = nearClipPlane;
camAnim.farClipPlane = farClipPlane;
#endif

// // If the aspect ratio is given and does not match the
// // screen's aspect ratio, the viewport rect is reduced
// // to match the glTFs aspect ratio (box fit)
Expand Down Expand Up @@ -431,6 +441,17 @@ string cameraName
farValue
);

#if UNITY_ANIMATION
var camAnim = cam.transform.parent.gameObject.AddComponent<AnimationCameraGameObject>();
camAnim.orthographic = true;
camAnim.localScale = localScale;
camAnim.targetCamera = cam;
camAnim.xMag = horizontal;
camAnim.yMag = vertical;
camAnim.nearClipPlane = nearClipPlane;
camAnim.farClipPlane = farValue;
#endif

// // If the aspect ratio does not match the
// // screen's aspect ratio, the viewport rect is reduced
// // to match the glTFs aspect ratio (box fit)
Expand Down
Loading