Jump to content

Cloning skeleton on iOS copies references


ozRocker
 Share

Recommended Posts

I've successfully cloned a mesh and its skeleton with this code:

this.mesh = Assets.avatar.clone(JSON.idx);
this.mesh.skeleton = Assets.avatar.skeleton.clone(JSON.idx);

I then run an animation like this:

this.mesh.skeleton.beginAnimation("Idle",true,1);

This works well on Windows browsers.  I can have 10 people moving about with their own separate animations.  Some running, some walking and some idle.  However, this doesn't work on iPhone and iPad.  If I animate one of the meshes then all of them will activate the same animation.  If one is running then ALL of them will be running.  Its as if they are all referencing the same animation.  Does anyone know how I can get this to work on iPhone?

Link to comment
Share on other sites

So I checked the console on the iPhone and I got these 3 errors.  Would that have something to do with the funny animation cloning?

 

BJS - [00:06:48]: Unable to compile effect with current defines. Trying next fallback.
_ErrorEnabledbabylon.2.3.js:2:14458
_prepareEffectbabylon.2.3.js:11:23999
(anonymous function)babylon.2.3.js:11:21243
_loadFragmentShaderbabylon.2.3.js:11:22517
(anonymous function)babylon.2.3.js:11:21212
_loadVertexShaderbabylon.2.3.js:11:22187
tbabylon.2.3.js:11:21176
createEffectbabylon.2.3.js:3:9525
isReadybabylon.2.3.js:12:14980
isReadybabylon.2.3.js:8:5960
_checkIsReadybabylon.2.3.js:8:7032
(anonymous function)babylon.2.3.js:8:7227

BJS - [00:06:48]: Vertex shader:default
_ErrorEnabledbabylon.2.3.js:2:14458
_dumpShadersNamebabylon.2.3.js:11:23078
_prepareEffectbabylon.2.3.js:11:24093
(anonymous function)babylon.2.3.js:11:21243
_loadFragmentShaderbabylon.2.3.js:11:22517
(anonymous function)babylon.2.3.js:11:21212
_loadVertexShaderbabylon.2.3.js:11:22187
tbabylon.2.3.js:11:21176
createEffectbabylon.2.3.js:3:9525
isReadybabylon.2.3.js:12:14980
isReadybabylon.2.3.js:8:5960
_checkIsReadybabylon.2.3.js:8:7032
(anonymous function)babylon.2.3.js:8:7227

BJS - [00:06:48]: Fragment shader:default
_ErrorEnabledbabylon.2.3.js:2:14458
_dumpShadersNamebabylon.2.3.js:11:23120
_prepareEffectbabylon.2.3.js:11:24093
(anonymous function)babylon.2.3.js:11:21243
_loadFragmentShaderbabylon.2.3.js:11:22517
(anonymous function)babylon.2.3.js:11:21212
_loadVertexShaderbabylon.2.3.js:11:22187
tbabylon.2.3.js:11:21176
createEffectbabylon.2.3.js:3:9525
isReadybabylon.2.3.js:12:14980
isReadybabylon.2.3.js:8:5960
_checkIsReadybabylon.2.3.js:8:7032
(anonymous function)babylon.2.3.js:8:7227

 

Link to comment
Share on other sites

56 minutes ago, Deltakosh said:

Can you try to turn software bones on and check how it looks on your PC?

yeh, if I turn on software bones on the PC then they are all sharing animation.  so I guess with software bones you can't clone animations?

Link to comment
Share on other sites

ok, thanks man!  Is it better for performance if I just clone and use shaders?  I could do this by simply removing bones from the hands.  This is the source of the errors in iOS.  I have too many bones for my puny iPhone RAM

Link to comment
Share on other sites

oz,

Your assumptions about iPhone's memory are not really correct.  The problem is WebGL 1.0 has a minimum required # of Vector4 uniforms of 128.  Each bone requires 4 of these.  Desktop implementations typically exceed this minimum, but IOS & other mobile platforms do not.  That means that absolute max # of bones for WebGL 1.0 on mobile platforms is 128 / 4 = 32.

In practice, you also need uniforms for other things, so depending on other parts of your scene, the best you can get is about 22.

As of yesterday, you can set the maximum # of lights on your materials.  Prior to this, it was fixed at 4.  If you have a single light that moves with the camera, try material.maxSimultaneousLights = 1;  I do not know how many uniforms you will pick up.  It might depend on the light type.

In WebGL 2.0, based on OpenGL ES3, you can now have vertex uniform buffers (in addition to uniforms, I think).  Looks like the max size of one will hold 32 bones, but you can have up to 12 total.  Using buffers will eliminate many bone limitations.  Having a buffer also cuts down on the number of calls to pass uniforms in multiple ways: 

  • Obviously, 1 call for 32 bones is a 32X decrease.
  • If these buffers can be shared across meshes (think:  body, hair, teeth, tongue, eyes, clothes, shoes).  This would result in an additional 6X decrease.
  • Vertex shaders require bone info, regardless of no movement in progress.  As buffers, you only need to update them when something has changed.

Apple supports OpenGL ES3 on processors A5 to present.  Doubt they ever increase WebGL 1.0 amounts.  Why would they?

I am not sure what DK has I'm mind.  Maybe a hard limit of 12, 32 bone skeletons per scene.

So to recap, ram problem wrong, api problem right, drop your lights for now.

Link to comment
Share on other sites

  • 1 year later...
On 5/1/2016 at 10:36 AM, Deltakosh said:

var avatar2 = avatar1.clone();

            
var newGeometry = avatar1.geometry.copy("newgeom");         
newGeometry.applyToMesh(avatar2);
               
avatar2.computeBonesUsingShaders = false;

 

 

I skimmed your sample (http://www.babylonjs-playground.com/#GTHTR#1) and this was incredibly useful for getting the mesh to clone properly on mobile. 

Unfortunately, once I use geometry.copy, the subMesh data is lost and I am unable to apply my multi-material. (I have subMeshes[2] on the original, but only subMeshes[1] on the clone) such that the textures are screwed up. 
On the other hand, if I don't do the geometrycopy, I am unable to have unique animations on the clones.

Is there some way of doing geometry copy, but maintaining the subMesh data? 
Thanks in advance for the help! :)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...