Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-623] feat: update api to work with GLTFast 6.0 #157

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Changes from 2 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
33 changes: 15 additions & 18 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 All @@ -41,8 +40,6 @@ public override void AddPrimitive(
{
// Use Node GameObject for first Primitive
meshGo = m_Nodes[nodeIndex];
// Ready Player Me - Parent mesh to Avatar root game object
meshGo.transform.SetParent(m_Parent.transform);
HarrisonHough marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand All @@ -53,18 +50,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 +70,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