Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Fixed sparse accessor exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Jun 7, 2018
1 parent ea5b240 commit e51790d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Core/Scripts/Extensions/glTFExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
Expand Down Expand Up @@ -166,7 +167,8 @@ public static int ExtendSparseBufferAndGetAccessorIndex<T>(this glTF gltf, int b
{
return -1;
}
var sparseValuesViewIndex = ExtendBufferAndGetViewIndex(gltf, bufferIndex, array, target);
var sparseValuesViewIndex = ExtendBufferAndGetViewIndex(gltf, bufferIndex,
sparseIndices.Select(x => array.Array[array.Offset+x]).ToArray(), target);
var accessorIndex = gltf.accessors.Count;
gltf.accessors.Add(new glTFAccessor
{
Expand Down
13 changes: 11 additions & 2 deletions Core/Scripts/IO/gltfExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ static gltfMorphTarget ExportMorphTarget(glTF gltf, int bufferIndex,
{
var blendShapeVertices = mesh.vertices;
var blendShpaeNormals = mesh.normals;
var useNormal = blendShpaeNormals != null && blendShpaeNormals.Length == blendShapeVertices.Length;
var blendShapeTangents = mesh.tangents.Select(y => (Vector3)y).ToArray();
var useTangent = blendShapeTangents != null && blendShapeTangents.Length == blendShapeVertices.Length;

var frameCount = mesh.GetBlendShapeFrameCount(j);
mesh.GetBlendShapeFrameVertices(j, frameCount - 1, blendShapeVertices, blendShpaeNormals, null);
blendShapeVertices = blendShapeVertices.Select(y => y.ReverseZ()).ToArray();
Expand All @@ -532,13 +535,19 @@ static gltfMorphTarget ExportMorphTarget(glTF gltf, int bufferIndex,
{
return
blendShapeVertices[x] != Vector3.zero
|| blendShpaeNormals[x] != Vector3.zero
|| blendShapeTangents[x] != Vector3.zero
|| (useNormal && blendShpaeNormals[x] != Vector3.zero)
|| (useTangent && blendShapeTangents[x] != Vector3.zero)
;
})
.ToArray()
;

var sparseBytes = (4 + 12 + 12 + 12) * sparseIndices.Length;
var fullBytes = (12 + 12 + 12) * blendShapeVertices.Length;
Debug.LogFormat("Export sparse: {0}/{1}bytes({2}%)",
sparseBytes, fullBytes, (int)((float)sparseBytes/fullBytes)
);

var sparseIndicesViewIndex = gltf.ExtendBufferAndGetViewIndex(bufferIndex, sparseIndices);

var blendShapePositionAccessorIndex = gltf.ExtendSparseBufferAndGetAccessorIndex(bufferIndex,
Expand Down

0 comments on commit e51790d

Please sign in to comment.