Skip to content

Commit f03687d

Browse files
mvaligurskyMartin Valigursky
andauthored
[Fix] Fixes skining using render component meshes imported using hierarchy in Editor (playcanvas#3350)
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 5a56cb2 commit f03687d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/resources/container.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class ContainerResource {
116116
if (gltfNode.hasOwnProperty('skin')) {
117117
skinedMeshInstances.push({
118118
meshInstance: meshInstance,
119-
skin: skins[gltfNode.skin],
120119
rootBone: root,
121120
entity: entity
122121
});
@@ -194,8 +193,7 @@ class ContainerResource {
194193

195194
// now that the hierarchy is created, create skin instances and resolve bones using the hierarchy
196195
skinedMeshInstances.forEach((data) => {
197-
data.meshInstance.mesh.skin = data.skin;
198-
data.meshInstance.skinInstance = SkinInstanceCache.createCachedSkinedInstance(data.skin, data.rootBone, data.entity);
196+
data.meshInstance.skinInstance = SkinInstanceCache.createCachedSkinedInstance(data.meshInstance.mesh.skin, data.rootBone, data.entity);
199197
});
200198

201199
// return the scene hierarachy created from scene clones

src/resources/parser/glb-parser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,18 @@ const createLights = function (gltf, nodes, options) {
16081608
return lights;
16091609
};
16101610

1611+
// link skins to the meshes
1612+
const linkSkins = function (gltf, renders, skins) {
1613+
gltf.nodes.forEach((gltfNode) => {
1614+
if (gltfNode.hasOwnProperty('mesh') && gltfNode.hasOwnProperty('skin')) {
1615+
const meshGroup = renders[gltfNode.mesh].meshes;
1616+
meshGroup.forEach((mesh) => {
1617+
mesh.skin = skins[gltfNode.skin];
1618+
});
1619+
}
1620+
});
1621+
};
1622+
16111623
// create engine resources from the downloaded GLB data
16121624
const createResources = function (device, gltf, bufferViews, textureAssets, options, callback) {
16131625
const preprocess = options && options.global && options.global.preprocess;
@@ -1639,6 +1651,9 @@ const createResources = function (device, gltf, bufferViews, textureAssets, opti
16391651
renders[i].meshes = meshes[i];
16401652
}
16411653

1654+
// link skins to meshes
1655+
linkSkins(gltf, renders, skins);
1656+
16421657
const result = new GlbResources(gltf);
16431658
result.nodes = nodes;
16441659
result.scenes = scenes;

0 commit comments

Comments
 (0)