Skip to content

Commit

Permalink
fix compilation issues down to 2018.4
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Feb 10, 2022
1 parent 62543cb commit db514e5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class GLTFRecorderComponent : MonoBehaviour
public UnityEvent recordingStarted;
public UnityEvent<string> recordingEnded;

private double CurrentTime =>
#if UNITY_2019_1_OR_NEWER
Time.timeAsDouble;
#else
Time.time;
#endif

[ContextMenu("Start Recording")]
public virtual void StartRecording()
Expand All @@ -33,7 +39,7 @@ public virtual void StartRecording()
}

recorder = new GLTFRecorder(exportRoot, shouldRecordBlendShapes);
recorder.StartRecording(Time.timeAsDouble);
recorder.StartRecording(CurrentTime);
recordingStarted?.Invoke();

StartCoroutine(_UpdateRecording());
Expand Down Expand Up @@ -80,8 +86,8 @@ protected virtual void OnDisable()

protected virtual void UpdateRecording()
{
if(Time.timeAsDouble > recorder.LastRecordedTime)
recorder.UpdateRecording(Time.timeAsDouble);
if(CurrentTime > recorder.LastRecordedTime)
recorder.UpdateRecording(CurrentTime);
}

private IEnumerator _UpdateRecording()
Expand Down
80 changes: 48 additions & 32 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,19 @@ bool TextureHasAlphaChannel(Texture sourceTexture)
}
#endif

hasAlpha |= UnityEngine.Experimental.Rendering.GraphicsFormatUtility.HasAlphaChannel(sourceTexture.graphicsFormat);
UnityEngine.Experimental.Rendering.GraphicsFormat graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.None;
#if !UNITY_2019_1_OR_NEWER
if (sourceTexture is Texture2D tex2D)
graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetGraphicsFormat(tex2D.format, true);
#else
graphicsFormat = sourceTexture.graphicsFormat;
#endif
#if UNITY_2018_2_OR_NEWER
if(graphicsFormat != UnityEngine.Experimental.Rendering.GraphicsFormat.None)
hasAlpha |= UnityEngine.Experimental.Rendering.GraphicsFormatUtility.HasAlphaChannel(graphicsFormat);
#else
hasAlpha = true;
#endif
return hasAlpha;
}

Expand Down Expand Up @@ -2487,7 +2499,13 @@ private SamplerId ExportSampler(Texture texture)
break;
}

if(texture.mipmapCount > 1)
var mipmapCount = 1;
#if UNITY_2019_2_OR_NEWER
mipmapCount = texture.mipmapCount;
#else
if (texture is Texture2D tex2D) mipmapCount = tex2D.mipmapCount;
#endif
if(mipmapCount > 1)
{
switch (texture.filterMode)
{
Expand Down Expand Up @@ -2527,7 +2545,7 @@ private SamplerId ExportSampler(Texture texture)
return samplerId;
}

#region Accessors Export
#region Accessors Export

private AccessorId ExportAccessor(byte[] arr)
{
Expand Down Expand Up @@ -3190,7 +3208,7 @@ private BufferViewId ExportBufferView(uint byteOffset, uint byteLength, uint byt
return id;
}

#endregion
#endregion

public MaterialId GetMaterialId(GLTFRoot root, Material materialObj)
{
Expand Down Expand Up @@ -3289,32 +3307,6 @@ protected static DrawMode GetDrawMode(MeshTopology topology)
throw new Exception("glTF does not support Unity mesh topology: " + topology);
}


public enum AnimationKeyRotationType
{
Unknown,
Quaternion,
Euler
};

private struct TargetCurveSet
{
public AnimationCurve[] translationCurves;
public AnimationCurve[] rotationCurves;
public AnimationCurve[] scaleCurves;
public AnimationKeyRotationType rotationType;
public Dictionary<string, AnimationCurve> weightCurves;

public void Init()
{
translationCurves = new AnimationCurve[3];
rotationCurves = new AnimationCurve[4];
scaleCurves = new AnimationCurve[3];
weightCurves = new Dictionary<string, AnimationCurve>();
}
}


// Parses Animation/Animator component and generate a glTF animation for the active clip
// This may need additional work to fully support animatorControllers
public void ExportAnimationFromNode(ref Transform transform)
Expand Down Expand Up @@ -3413,6 +3405,30 @@ void ExportAnimationClips(Transform nodeTransform, AnimationClip[] clips, Animat

#if UNITY_ANIMATION

public enum AnimationKeyRotationType
{
Unknown,
Quaternion,
Euler
}

private struct TargetCurveSet
{
public AnimationCurve[] translationCurves;
public AnimationCurve[] rotationCurves;
public AnimationCurve[] scaleCurves;
public AnimationKeyRotationType rotationType;
public Dictionary<string, AnimationCurve> weightCurves;

public void Init()
{
translationCurves = new AnimationCurve[3];
rotationCurves = new AnimationCurve[4];
scaleCurves = new AnimationCurve[3];
weightCurves = new Dictionary<string, AnimationCurve>();
}
}

private void ConvertClipToGLTFAnimation(ref AnimationClip clip, ref Transform transform, ref GLTF.Schema.GLTFAnimation animation, float speed = 1f)
{
// Generate GLTF.Schema.AnimationChannel and GLTF.Schema.AnimationSampler
Expand Down Expand Up @@ -3472,7 +3488,7 @@ private void ConvertClipToGLTFAnimation(ref AnimationClip clip, ref Transform tr

private void CollectClipCurves(AnimationClip clip, ref Dictionary<string, TargetCurveSet> targetCurves)
{
#if UNITY_EDITOR
#if UNITY_EDITOR
foreach (var binding in UnityEditor.AnimationUtility.GetCurveBindings(clip))
{
AnimationCurve curve = UnityEditor.AnimationUtility.GetEditorCurve(clip, binding);
Expand Down Expand Up @@ -3533,7 +3549,7 @@ private void CollectClipCurves(AnimationClip clip, ref Dictionary<string, Target
}
targetCurves[binding.path] = current;
}
#endif
#endif
}

private void GenerateMissingCurves(float endTime, ref Transform tr, ref Dictionary<string, TargetCurveSet> targetCurvesBinding)
Expand Down
10 changes: 4 additions & 6 deletions UnityGLTF/Assets/UnityGLTF/Runtime/UnityGLTFScripts.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"name": "UnityGLTFScripts",
"rootNamespace": "",
"references": [
"GUID:40f39bff7bc9be34182ebe488fcf8228",
"GUID:3d354272d3f2f4c3387dbccbaebd0f60",
"GUID:f06555f75b070af458a003d92f9efb00"
"GLTFSerialization",
"Unity.Timeline",
"Ktx"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"GLTFSerialization.dll"
],
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [
Expand Down
2 changes: 2 additions & 0 deletions UnityGLTF/Assets/UnityGLTF/Tests/Runtime/GLTFBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GLTFBenchmark : MonoBehaviour
public int NumberOfIterations = 5;
public bool SaveCSV = true;

#if UNITY_WEBREQUEST
IEnumerator Start ()
{
var timer = new System.Diagnostics.Stopwatch();
Expand Down Expand Up @@ -76,5 +77,6 @@ IEnumerator Start ()
}
}
}
#endif
}
#endif
7 changes: 2 additions & 5 deletions UnityGLTF/Assets/UnityGLTF/Tests/Runtime/GLTFRootTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using NUnit.Framework;


// todo blgross port to base layer
// todo blgross port to base layer
#if false
public class GLTFRootTest {

Expand All @@ -21,4 +18,4 @@ public void TestMinimumGLTF()
Assert.AreEqual(testRoot.Asset.Version, "2.0");
}
}
#endif
#endif
1 change: 1 addition & 0 deletions UnityGLTF/Assets/UnityGLTF/Tests/UnityGLTFTests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"references": [
"UnityGLTFScripts",
"UnityGLTFEditor",
"GLTFSerialization",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
],
Expand Down

0 comments on commit db514e5

Please sign in to comment.