Skip to content
Open
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
19 changes: 16 additions & 3 deletions Runtime/Scripts/GLTFSceneImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,18 @@ protected virtual async Task ConstructNode(Node node, int nodeIndex, Cancellatio
nodeObj.transform.localRotation = rotation;
nodeObj.transform.localScale = scale;


Bounds TransformBounds(Matrix4x4 matrix, Bounds bounds)
{
var extents = bounds.extents;
var ax = matrix.MultiplyVector(new Vector3(extents.x, 0, 0));
var ay = matrix.MultiplyVector(new Vector3(0, extents.y, 0));
var az = matrix.MultiplyVector(new Vector3(0, 0, extents.z));
var x = Mathf.Abs(ax.x) + Mathf.Abs(ay.x) + Mathf.Abs(az.x);
var y = Mathf.Abs(ax.y) + Mathf.Abs(ay.y) + Mathf.Abs(az.y);
var z = Mathf.Abs(ax.z) + Mathf.Abs(ay.z) + Mathf.Abs(az.z);

return new Bounds(matrix.MultiplyPoint3x4(bounds.center), new Vector3(x, y, z) * 2f);
}

async Task CreateNodeComponentsAndChilds(bool ignoreMesh = false, bool onlyMesh = false)
{
Expand Down Expand Up @@ -1048,8 +1059,10 @@ async Task CreateNodeComponentsAndChilds(bool ignoreMesh = false, bool onlyMesh
if (node.Skin != null)
await SetupBones(node.Skin.Value, renderer, cancellationToken);

// morph target weights
if (weights != null)
renderer.localBounds = renderer.rootBone == null ? unityMesh.bounds : TransformBounds(renderer.rootBone.worldToLocalMatrix * renderer.transform.localToWorldMatrix, unityMesh.bounds);

// morph target weights
if (weights != null)
{
for (int i = 0; i < weights.Count; ++i)
{
Expand Down