Babylon Playground strange behavior

Hi guys,

I’m very new to BabylonJS, and I’ve been experimenting since a few days… this is my first post here :slight_smile:

I have a problem with animations, and tried to make a Babylon Playground demo to explain what I’m trying to do to you guys, and ask for enlightment.

But I’m having problems on the Playground wayyyyyy before having finished my demo and being able to ask for help about animations :frowning:

The playground is here : https://playground.babylonjs.com/#WGZLGJ#3897

It seems to be working in the state I put it, BUT, if you uncomment any of the following lines :

  • anim_sticker_come = animationGroups[0];
  • anim_sticker_go = animationGroups[1];
  • skeleton = skeletons[0];

It will stop working… It’s working locally though, so I don’t really understand what happens.
Any idea ? I think I’m missing something pretty big for my very basic demo to fail so early ?

And other questions related to this basic example :

  • locally, I used “ImportMesh” instead of “Append”, and it works. In the playground, it doesn’t. Know why ?
  • how come I get a message “You must at least create a camera” when there’s already a camera in the scene ?
  • if I add “const scene = createScene();” below my current code, I get an error “r.initFunction is not a function”

I really think I misunderstood something big, it seems a lot of things are working locally, but not on the playground :confused:

Thanks for your help guys !

importMesh and Append do not have the same callback one will have meshes in it and the other a scene object.

I d advise not indexing in the result but using scene.getMeshById(…) in your callback so no more issues :slight_smile:

2 Likes

ImportMesh callback SceneLoader | Babylon.js Documentation (babylonjs.com): its arguments are meshes, particleSystems, animationGroups, etc…
Append callback SceneLoader | Babylon.js Documentation (babylonjs.com) only has the scene as argument.

As Seb mentioned, to access the objects from the scene, you can use getYYYbyId series of functions.

For the camera bit, you have to keep in mind that the function called on ImportMesh/Append is a callback, which means it will only execute once the model is loaded. That means that the scene returned by createScene doesn’t have a camera at its moment of creation, only a while after once the mesh is loaded. A solution in this case would be to move the createDefaultCameraOrLight to outside the callback.

And for the last point, it’s not needed to call the createScene function on the playground, only define it. The playground takes care of the rest. :slight_smile:

Here’s a fixed version of the playground (noticed the variables didn’t have keywords also, don’t forget this part!): glTF Loader Demo | Babylon.js Playground (babylonjs.com)

If you have any other questions, don’t hesitate to ask. :smiley:

2 Likes

Understood ! Thanks for your help :slight_smile:
The question I was initially here for was about animations (more precisely : how to play only a small part of an imported skeleton animation), but I think I figured it out ! I just didn’t understand at first that the range of the animation wasn’t the same in the gbl file than in my 3Ds max scene, I was trying to play frames 75 → 100, because the animation is 100 frames long in 3ds max, but I then noticed when opening my file in the sandbox, that the animation was only 1.6 frames long here :slight_smile:

My final goal is to control animation with the page scroll, and not time, I’ll let you know (in an other thread) if I bump in other issues in the journey :wink:

1 Like

That’s a pretty interesting project, do keep us updated with any questions and cool results! :smiley:

Hi ! I just came accross this post while browsing my babylonjs activity and remembered you asked for update, soooo…

The website is now online, I made a post last week in the Projects category :slight_smile:

https://forum.babylonjs.com/t/website-with-babylon-animation-on-scroll/27748

Or the website directly : https://larouget.com/

Thanks for the help back then :slight_smile:

1 Like

Aaaah it makes me INSANELY HAPPY to see a beautiful finished project like this! :heart_eyes:

1 Like

Niceeee and cause I am in France it is mandatory I taste it :slight_smile:

1 Like

Hehe, good idea :slight_smile: They’ve got some pretty good beers !
The common ones, like the blond, are good but not exceptionnal.
But the uncommon ones are very interesting :slight_smile:

1 Like