question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way of cloning a mesh so it works with a skinning material

See original GitHub issue

Skinned material need their own geometry to work. This is because the material deforms the geometry, so if you share the same geometry between two meshes with deformation, things are going to get weird (at least that’s how I understand it).

Now the problem is, if you load a mesh from a FBX or something else and it contains at some point a skinned mesh, and you need multiple instances of it, here’s what happens:

  • You call clone(); on the mesh to generate your new instances
  • The clone function doesn’t generate a new geometry, so both models share geometry, and things gets bad (the mesh doesn’t appear at all).

Here’s a code sample: I was able to replicate this problem in the webgl_loader_fbx.html demo with a simple modification: Just clone the mesh once loaded before using it, and you’ll see that the cloned version of it doesn’t work:

loader.load( 'models/fbx/xsi_man_skinning.fbx', function( originalObject ) {

	// Using a clone of the mesh, it won't work
	var object = originalObject.clone();
	object.mixer = new THREE.AnimationMixer( object );
	mixers.push( object.mixer );

	var action = object.mixer.clipAction( object.animations[ 0 ] );
	action.play();

	scene.add( object );


}, onProgress, onError );

Is there a way to fix this behaviour? Like a deep clone function that also recreates geometries?

If not, should I just write a function that recursively recreates all the meshes in my object, regenerating their geometry? Or is it a bad idea?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
donmccurdycommented, Mar 26, 2019

Following up here, https://github.com/mrdoob/three.js/pull/14494 includes a utility function to help with cloning skinned meshes:

var copy = SkeletonUtils.clone( original );

The object given as a parameter may be a SkinnedMesh or an Object3D or Scene containing one or more SkinnedMesh instances. Any bones referenced by the SkinnedMesh(es) must also be children of the given object.

3reactions
jbaicoianucommented, Jun 25, 2017

I’ve been dealing with this while working on #11603 - the problem I’ve seen is that after cloning, all your bones have new UUIDs, but the skeleton still references the UUIDs from the original model. I’ve experimented with adding a function to SkinnedMesh which remaps bone UUIDs by name, but it has problems with some models which load with nameless bones.

Will update this issue with any updates if we find a good solution while working on the other issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloning a skinned mesh - Questions - three.js forum
Issue: No way of cloning a mesh so it works with a skinning material. Skinned material need their own geometry to work. This...
Read more >
How to assign cloned material to cloned mesh - Questions
I have tried clonedMesh.material = clonedMaterial which semi works (it does create the new material, but it is not assigning the new material...
Read more >
Physical Face Cloning - YouTube
We propose a complete process for designing, simulating, and fabricating synthetic skin for an animatronics character that mimics the face ...
Read more >
Clone - Foundry Learn
Instance Clone Properties ; Instance. When enabled, each cloned item is an instance of the source mesh. Instances contain no physical geometry, but...
Read more >
Scripting API: SkinnedMeshRenderer - Unity - Manual
bones, The bones used to skin the mesh. ... Works recursively. ... DontDestroyOnLoad, Do not destroy the target Object when loading a new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found