Skip to content

Commit

Permalink
remove rotation offset for now, seems to be incorrect for the general…
Browse files Browse the repository at this point in the history
… export case
  • Loading branch information
hybridherbst committed Nov 19, 2020
1 parent e066a5d commit 0dcdeae
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void SaveGLB(string path, string fileName)
{
_shouldUseInternalBufferForImages = true;
string fullPath = Path.Combine(path, Path.ChangeExtension(fileName, "glb"));

using (FileStream glbFile = new FileStream(fullPath, FileMode.Create))
{
SaveGLBToStream(glbFile, fileName);
Expand Down Expand Up @@ -251,10 +251,10 @@ public void SaveGLBToStream(Stream stream, string sceneName)
TextWriter jsonWriter = new StreamWriter(jsonStream, Encoding.ASCII);

// rotate 180°
if(_rootTransforms.Length > 1)
if(_rootTransforms.Length > 1)
Debug.LogWarning("Exporting multiple selected objects will most likely fail with the current rotation flip to match USDZ behaviour. Make sure to select a single root transform before export.");
foreach(var t in _rootTransforms)
t.rotation = Quaternion.Euler(0,180,0) * t.rotation;
// foreach(var t in _rootTransforms)
// t.rotation = Quaternion.Euler(0,180,0) * t.rotation;

_root.Scene = ExportScene(sceneName, _rootTransforms);
if (ExportAnimations)
Expand Down Expand Up @@ -304,8 +304,8 @@ public void SaveGLBToStream(Stream stream, string sceneName)

writer.Flush();

foreach(var t in _rootTransforms)
t.rotation = Quaternion.Euler(0,-180,0) * t.rotation;
// foreach(var t in _rootTransforms)
// t.rotation = Quaternion.Euler(0,-180,0) * t.rotation;
}

/// <summary>
Expand Down Expand Up @@ -369,10 +369,10 @@ public void SaveGLTFandBin(string path, string fileName)
_bufferWriter = new BinaryWriter(binFile);

// rotate 180°
if(_rootTransforms.Length > 1)
if(_rootTransforms.Length > 1)
Debug.LogWarning("Exporting multiple selected objects will most likely fail with the current rotation flip to match USDZ behaviour. Make sure to select a single root transform before export.");
foreach(var t in _rootTransforms)
t.rotation *= Quaternion.Euler(0,180,0);
// foreach(var t in _rootTransforms)
// t.rotation *= Quaternion.Euler(0,180,0);

_root.Scene = ExportScene(fileName, _rootTransforms);
if (ExportAnimations)
Expand Down Expand Up @@ -403,8 +403,8 @@ public void SaveGLTFandBin(string path, string fileName)
#endif
ExportImages(path);

foreach(var t in _rootTransforms)
t.rotation *= Quaternion.Euler(0,-180,0);
// foreach(var t in _rootTransforms)
// t.rotation *= Quaternion.Euler(0,-180,0);
}

private void ExportImages(string outputPath)
Expand Down Expand Up @@ -549,7 +549,7 @@ private string ConstructImageFilenamePath(Texture2D texture, string outputPath,
else if (!enforceExtension.StartsWith(".") && !filenamePath.EndsWith(enforceExtension))
filenamePath += "." + enforceExtension;
}
return filenamePath;
return filenamePath;
}

private SceneId ExportScene(string name, Transform[] rootObjTransforms)
Expand Down Expand Up @@ -919,7 +919,7 @@ private MeshId ExportMesh(string name, GameObject[] primitives)
mesh.Primitives.AddRange(meshPrimitives);
}
}

var id = new MeshId
{
Id = _root.Meshes.Count,
Expand Down Expand Up @@ -987,7 +987,7 @@ private MeshPrimitive[] ExportPrimitive(GameObject gameObject, GLTFMesh mesh)

AccessorId aPosition = null, aNormal = null, aTangent = null,
aTexcoord0 = null, aTexcoord1 = null, aColor0 = null;

aPosition = ExportAccessor(SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.vertices, SchemaExtensions.CoordinateSpaceConversionScale));

if (meshObj.normals.Length != 0)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ private MaterialId ExportMaterial(Material materialObj)
materialObj.GetInt("_Cull") == (float)CullMode.Off;

if(materialObj.IsKeywordEnabled("_EMISSION"))
{
{
if (materialObj.HasProperty("_EmissionColor"))
{
material.EmissiveFactor = materialObj.GetColor("_EmissionColor").ToNumericsColorRaw();
Expand Down Expand Up @@ -1665,7 +1665,7 @@ private string GetImageOutputPath(Texture texture)
}
}
else
{
{
filenamePath = Path.GetFileName(filenamePath);
if (!isGltfCompatible)
{
Expand Down Expand Up @@ -1777,7 +1777,7 @@ private ImageId ExportImageInternalBuffer(UnityEngine.Texture texture, TextureMa
bool wasAbleToExportFromDisk = false;

if(TryExportTexturesFromDisk && TryGetTextureDataFromDisk(texture, out string path, out byte[] imageBytes))
{
{
if(IsPng(path))
{
image.MimeType = "image/png";
Expand Down Expand Up @@ -2581,12 +2581,12 @@ private void convertClipToGLTFAnimation(ref AnimationClip clip, ref Transform tr
bool haveAnimation = positions != null || rotations != null || scales != null;

if(haveAnimation)
{
{
AccessorId timeAccessor = ExportAccessor(times);

// Translation
if(positions != null)
{
{
AnimationChannel Tchannel = new AnimationChannel();
AnimationChannelTarget TchannelTarget = new AnimationChannelTarget();
TchannelTarget.Path = GLTFAnimationChannelPath.translation;
Expand All @@ -2613,7 +2613,7 @@ private void convertClipToGLTFAnimation(ref AnimationClip clip, ref Transform tr
}

if(rotations != null)
{
{
// Rotation
AnimationChannel Rchannel = new AnimationChannel();
AnimationChannelTarget RchannelTarget = new AnimationChannelTarget();
Expand Down Expand Up @@ -2641,7 +2641,7 @@ private void convertClipToGLTFAnimation(ref AnimationClip clip, ref Transform tr
}

if(scales != null)
{
{
// Scale
AnimationChannel Schannel = new AnimationChannel();
AnimationChannelTarget SchannelTarget = new AnimationChannelTarget();
Expand Down Expand Up @@ -2737,7 +2737,7 @@ private void CollectClipCurves(AnimationClip clip, ref Dictionary<string, Target
}
#endif
}

private void GenerateMissingCurves(float endTime, ref Transform tr, ref Dictionary<string, TargetCurveSet> targetCurvesBinding)
{
foreach (string target in targetCurvesBinding.Keys)
Expand Down Expand Up @@ -2851,7 +2851,7 @@ private void BakeCurveSet(TargetCurveSet curveSet, float length, int bakingFrame
scales[i] = new Vector3(curveSet.scaleCurves[0].Evaluate(currentTime), curveSet.scaleCurves[1].Evaluate(currentTime), curveSet.scaleCurves[2].Evaluate(currentTime));

if(haveRotationKeys)
{
{
if (curveSet.rotationType == AnimationKeyRotationType.Euler)
{
Quaternion eulerToQuat = Quaternion.Euler(curveSet.rotationCurves[0].Evaluate(currentTime), curveSet.rotationCurves[1].Evaluate(currentTime), curveSet.rotationCurves[2].Evaluate(currentTime));
Expand Down Expand Up @@ -3291,7 +3291,7 @@ private AccessorId ExportAccessor(Matrix4x4[] arr)
_bufferWriter.Write(col.W);
}
}

uint byteLength = CalculateAlignment((uint)_bufferWriter.BaseStream.Position - byteOffset, 4);

accessor.BufferView = ExportBufferView((uint)byteOffset, (uint)byteLength);
Expand Down

0 comments on commit 0dcdeae

Please sign in to comment.