Skip to content

Commit

Permalink
[SDK-623] feat: update api to work with GLTFast 6.0 (#157)
Browse files Browse the repository at this point in the history
- This PR includes updates to support GLTF 6.0 it is a breaking change and it seems there isn't an elegant way to add or handle backwards compatibility.
  • Loading branch information
HarrisonHough authored Nov 21, 2023
1 parent ac4adb9 commit 5088225
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [5.0.0] - UNRELEASED

### Updated
- updated to GLTFast 6.0.1 by @harrisonhough in [#XXX]()

## [4.0.1] - 2023.11.14

### Fixed
Expand Down
31 changes: 15 additions & 16 deletions Runtime/GLTF/GltFastGameObjectInstantiator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public GltFastGameObjectInstantiator(
public override void AddPrimitive(
uint nodeIndex,
string meshName,
Mesh mesh,
int[] materialIndices,
MeshResult meshResult,
uint[] joints = null,
uint? rootJoint = null,
float[] morphTargetWeights = null,
Expand Down Expand Up @@ -53,18 +52,18 @@ public override void AddPrimitive(

Renderer renderer;

var hasMorphTargets = mesh.blendShapeCount > 0;
var hasMorphTargets = meshResult.mesh.blendShapeCount > 0;
if (joints == null && !hasMorphTargets)
{
var meshFilter = meshGo.AddComponent<MeshFilter>();
meshFilter.mesh = mesh;
var meshRenderer = meshGo.AddComponent<MeshRenderer>();
renderer = meshRenderer;
var mf = meshGo.AddComponent<MeshFilter>();
mf.mesh = meshResult.mesh;
var mr = meshGo.AddComponent<MeshRenderer>();
renderer = mr;
}
else
{
var skinnedMeshRenderer = meshGo.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.updateWhenOffscreen = m_Settings.SkinUpdateWhenOffscreen;
var smr = meshGo.AddComponent<SkinnedMeshRenderer>();
smr.updateWhenOffscreen = m_Settings.SkinUpdateWhenOffscreen;
if (joints != null)
{
var bones = new Transform[joints.Length];
Expand All @@ -73,28 +72,28 @@ public override void AddPrimitive(
var jointIndex = joints[j];
bones[j] = m_Nodes[jointIndex].transform;
}
skinnedMeshRenderer.bones = bones;
smr.bones = bones;
if (rootJoint.HasValue)
{
skinnedMeshRenderer.rootBone = m_Nodes[rootJoint.Value].transform;
smr.rootBone = m_Nodes[rootJoint.Value].transform;
}
}
skinnedMeshRenderer.sharedMesh = mesh;
smr.sharedMesh = meshResult.mesh;
if (morphTargetWeights != null)
{
for (var i = 0; i < morphTargetWeights.Length; i++)
{
var weight = morphTargetWeights[i];
skinnedMeshRenderer.SetBlendShapeWeight(i, weight);
smr.SetBlendShapeWeight(i, weight);
}
}
renderer = skinnedMeshRenderer;
renderer = smr;
}

var materials = new Material[materialIndices.Length];
var materials = new Material[meshResult.materialIndices.Length];
for (var index = 0; index < materials.Length; index++)
{
Material material = m_Gltf.GetMaterial(materialIndices[index]) ?? m_Gltf.GetDefaultMaterial();
var material = m_Gltf.GetMaterial(meshResult.materialIndices[index]) ?? m_Gltf.GetDefaultMaterial();
materials[index] = material;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"changelogUrl": "https://github.com/readyplayerme/rpm-unity-sdk-core/blob/main/CHANGELOG.md",
"licensesUrl": "https://github.com/readyplayerme/rpm-unity-sdk-core/blob/main/LICENSE.md",
"dependencies": {
"com.unity.cloud.gltfast": "5.0.4",
"com.unity.cloud.gltfast": "6.0.1",
"com.unity.nuget.newtonsoft-json": "3.0.2"
},
"keywords": [
Expand Down

0 comments on commit 5088225

Please sign in to comment.