# Snouto

Members

89

1. ## solved Orbiting a mesh from a set initial position

Ding ding ding ding we have a winner! That fixed the problem immediately. That's both super satisfying and incredible perplexing and frustrating at the same time. Just when you think you're getting a handle on BJS something like this occupies half your day! Well I appreciate your help there @brianzinn you managed to solve two big issues for me and now the animation works as planned. Cheers!
2. ## solved Orbiting a mesh from a set initial position

Thanks dude, that easing code is exactly what I was looking for. And now that I've seen it I realise I've used it before in one of my other hundred test scripts 🙄 Following on from my test code I've been searching around more and found an article on pivot points. My code now looks like this: var onMeshPicked = function(bjsEvent) { myPickedMesh = bjsEvent.source; if(!myPickedMesh.isPickable) return; var frames = 90; // number of points if( parent===null ){ parent = myPickedMesh.parent; var CoR_At = new BABYLON.Vector3(0, parent.position.y, 0); var axis = BABYLON.Vector3.Up(); var pilotStart = new BABYLON.Vector3(parent.position.x,parent.position.y,parent.position.z); pivot = new BABYLON.TransformNode("root"); pivot.position = CoR_At; parent.parent = pivot; parent.position.y = 1.7657999992370605; var angle = 0.01; parent.yRot = new BABYLON.Animation("yRot", "rotation.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); var keyFramesR = []; keyFramesR.push({ frame: 0, value: 0 }); keyFramesR.push({ frame: 2 * frames, value: 2 * Math.PI }); parent.yRot.setKeys(keyFramesR); var easingFunction = new BABYLON.QuarticEase(); easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT); parent.yRot.setEasingFunction(easingFunction); } scene.beginDirectAnimation(pivot, [parent.yRot], 0, 2*frames, false); } That line: parent.position.y = 1.7657999992370605; is my wacky attempt to adjust the position of the mesh once it is parented to the pivot, because as soon as that happens the mesh position changes. It may well be due to the parent mesh being over sized in the blender model due to wanting to avoid recalculating the baked animation (which was done before being parented), but I've struggled to figure out what that Y figure should be since there doesn't appear to be an obvious correlation to the new position that I can see.
3. ## solved Orbiting a mesh from a set initial position

Alright errybody This is a question more about maths than anything else, and i'm terrible at maths so I'm hoping someone (maybe @Wingnut) can help me here. My scene is loaded from a blender export, which in itself is partially an imported FBX from C4D (still waiting on that C4D exporter boys!). I have a mesh within the scene that has a set position, and I want to allow it to orbit in a circle when clicked or tapped by the user. Fundamentally this is fine and I have most of the logic in place, but I'm struggling to figure out how to make it animate from it's initial position. All of the example code I've seen make the object jump to a calculated first position and then animate, which is not what I want. Has anyone got some sweet ninja code that I can borrow steal that will do what I need? Additionally is there a convenient technique or built in method to add easing to the beginAnimation call, or to the calculated keyframes? Cheers! Here's my current code: var onMeshPicked = function(bjsEvent) { myPickedMesh = bjsEvent.source; var frames = 90; // number of points var parent = myPickedMesh.parent; parent.indexPoint = 0; var p=0; var points = []; var radius = 2; for (var i = 0; i < frames; i++) { // calculate the keyframes points.push( new BABYLON.Vector3((radius + Math.sin(i*Math.PI/frames))* Math.cos(2*i*Math.PI/frames), parent.position.y, ( radius + Math.sin(i*Math.PI/frames)) * Math.sin(2*i*Math.PI/frames))); } parent.points=points; var path3d = new BABYLON.Path3D(points); var tangents = path3d.getTangents(); //array of tangents to the curve var normals = path3d.getNormals(); //array of normals to the curve var binormals = path3d.getBinormals(); //array of binormals to curve parent.animationPosition = new BABYLON.Animation("animPos", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); parent.animationRotation = new BABYLON.Animation("animRot", "rotationQuaternion", 30, BABYLON.Animation.ANIMATIONTYPE_QUATERNION, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); var keysPosition = []; var keysRotation = []; for(i = 0,p=frames; i < p; i++) { keysPosition.push({ frame: i, value: parent.points[i] }); keysRotation.push({ frame: i, value: BABYLON.Quaternion.RotationQuaternionFromAxis(normals[i], binormals[i], tangents[i]) }); } parent.animationPosition.setKeys(keysPosition); parent.animationRotation.setKeys(keysRotation); scene.beginDirectAnimation(parent, [parent.animationPosition,parent.animationRotation], 0, frames, false, 0.25,null); };
4. ## Flat Mesh from Blender

Thanks for the information chaps, very helpful 👍🏻
5. ## Flat Mesh from Blender

Sigh....I hate myself sometimes. Tried a bunch of angles except god-damn 0. Okay so that works on a couple of the meshes in my scene that need it. Here's the thing though, whereas before it was super convenient to be able to apply the flat mesh across the whole scene it seems now I have to choose individual meshes and set the EdgeSplit manually. If i was only doing this one time that would probably be fine but in my case I am receiving regular updates to the FBX model I'm importing and so every time I import a new FBX I'm going to have to manually go through every mesh and set the EdgeSplit again. This is less than optimal, plus I'm really lazy. Since there is also the script option I mentioned earlier, if I were to simply use Mesh.convertToFlatShadedMesh only and skip setting EdgeSplits across dozens of meshes in Blender, am I going to experience a significant performance or quality drop/difference in the browser? I can accept a bit of a performance drop right at the start as my code iterates each mesh and fires that JS command, but is there any knock-on effect to my scene after that process completes? Just asking so I understand my options. Cheers JCP.  Another option springs to mind, and that is to use a simple python script within Blender to auto add an EdgeSplit modifier to all meshes: import bpy for obj in bpy.data.objects: if obj.type == "MESH": edgeSplit = obj.modifiers.new("EdgeSplit", type = "EDGE_SPLIT") edgeSplit.split_angle = 0 bpy.context.scene.update() I'd still like to reduce the amount of steps I need to take every time an FBX is imported so would appreciate some further information as asked above. Cheers

7. ## Animating a child mesh from Blender to BJS

Okay, never mind, regarding the previous post it was being caused by the animation export options not being checked. I found this post by @JCPalmer which led me to try checking those new animation options, and wouldn't you just know it it worked instantly after that. JCP - you're alright with me. Good lad. 👍 So for the time being, at least I know I can do the C4D -> BJS route with animations kept intact. Yet even when setting the camera export options as I've just described in my original Helicopter scene, it still doesn't work properly. I must be doing something wrong in Blender, so I'll put this issue on hold until I'm working with a proper scene and if the problem arises again I'll necro the thread. Thanks again everyone.
8. ## Animating a child mesh from Blender to BJS

Okay so this is slightly off the original topic, but here's a very simple animation test. It was created in C4D, exported to FBX, imported in to Blender, then exported to BJS. In blender the animation appeared fine, but once in BJS it went sideways. Here's the video of the scene in blender - you can see visually how the animation should behave. It's just two objects, each with a baked animation. blender.mov Here's a PG using the exported BJS file. Notice how it just aint right, yo. https://www.babylonjs-playground.com/#02YH29 It appears as though the keyframe animation of the cube trumps that of the sphere, to the extent that even if you comment out the animation of the cube in the PG code, the movement of the sphere mimics that of the cube's animation, which is clearly wrong. I get the feeling this either isn't possible, or I'm doing something wildly incorrect here. Happy to hear your thoughts! Cheers test.blend
9. ## Animating a child mesh from Blender to BJS

Thanks for the replies chaps, I'll have a look at your suggestions and come back with any further questions. @JCPalmer thanks for the tip, seems a bit... steampunk.... but I'll defo take a look at that
10. ## Animating a child mesh from Blender to BJS

Yo party dudes Here I am, still at this damn project, still struggling with everyday issues (yo). Latest in a long list of probably-easy-but-hard-for-me questions is regarding animation. To set the scene (arf!), lets assume I have a Blender file with an empty parent object. Inside are two child objects; helicopter_body, and helicopter_props. What I'd like to do is, in Blender, animate the _props object so it looks like the chopper blades are spinning. Then in BJS animate the parent and children. Okay so once I have a simple prop rotation animation set in the dope sheet, if I export the scene and load in to BJS, what I see is that the position of the props is all kinds of wrong and the animation itself isn't working like I can see in Blender. Q1: Is this possible? Can I have a parent object animated with BJS with one of the children running a Blender animation independently? If so, what could be going wrong? I tried applying position and rotation/scale but that didn't change much. Q2: Also are there any obvious issues if I were to create a scene in C4D with animations (how's that exporter going btw?), export to FBX including animations, load the fbx in to blender then export to BJS? I can see in this page http://doc.babylonjs.com/resources/blender#animation that you're saying every single animated object should be produced as a seperate babylon file. Q3: why is that? Q4: And would that mean I have to use several sceneloader.append calls to bring all the different models in to the base scene? Cheers! blend_anim.mov
11. ## Animation and Spatial Audio

No worries @davrous I'll work with what I've got and if the "powers that be" (i.e. the client) decide the effect needs work I'll come back to you with a PG. Cheers!
12. ## Animation and Spatial Audio

Thanks for the information @davrous - my reasons for needing such behaviour are quite specific to my project and probably not likely to be needed elsewhere, but to answer your question I wanted to have a visual representation in my scene of audio playing at a particular location. To do this I'm simply updating the Y scale of a mesh in time to one of the frequency channels, but since the analyser only works when the audio can be heard this means that from afar my mesh does nothing and the effect is lost. It's not vitally important though. I'm still interested in understanding what updates to the Arc camera you were planning on making to the spatial audio set up (added to the roadmap here https://github.com/BabylonJS/Babylon.js/issues/4001). I feel like I might be missing out on an important update for the spatial audio to work exactly as intended with my use case, but it's equally possible you had some other updates to make that won't make a huge difference to me. If they are significant and important updates would it be possible to expedite and release the work quickly? Cheers
13. ## Animation and Spatial Audio

Any chance of a follow up on this stuff @davrous? Cheers
14. ## Is there a way to know if an imported model comes with animation?

Someone can probably confirm this but as I understand it, you can check the imported mesh's animations array property. If it's null or length==0, you don't have an animation. Something like: if( MESH_NAME.animations && MESH_NAME.animations.length > 0 ) // you've got an animation
15. ## Animation and Spatial Audio

On a seperate note but still related to spatial audio, i've just noticed that using the audio analyser with spatial audio only works if the audio can be heard. So for example if the spatial audio is at a distance that means audio can not be heard, then the soundtrack to which the sound is attached will not create any data for the analyser to use. Is there something going on under the hood with spatial audio whereby maybe audio.pause is being called when out of range, to save on resources perhaps?
16. ## Animation and Spatial Audio

Indeed you are correct that does work well, but if you recall the original purpose of this thread was to discuss spatial audio in the context of an arc camera attached to a mesh and the mesh then animated. You seemed to acknowledge that using spatial audio in this way would require changes to the arc camera and added it to your 3.3 milestone. I then made a change in the code at my side, but I'm not sure whether this is the change you have added to your 3.3 milestone or if you intended to do something more, and that's really what I'm following up here. With regards to my observations of my scene it could simply be my crappy ears not hearing things properly, but I just wanted to be sure the custom implementation I have now is in fact what you intend to add later (i.e. I'm not missing something).
17. ## Animation and Spatial Audio

Is there any way I can get the arc camera spatial audio update added sooner rather than later? Just noticed the 3.3 timeline is up until september 2018, which is well beyond my needs. @Deltakosh when you said earlier that support for the arc rotate camera was needed, what exactly is it missing at the moment? Like I mentioned in a subsequent comment I can hear the audio kicking in while using my arc camera. I have reservations about whether the audio is playing correctly, in the sense that it starts when it should and increases in volume as it approaches the source, and that the range of the audio is accurate. I'm sure I've heard other audio playing at the same time that shouldn't be within earshot, and i'm not at all convinced the sound starts, stops and the volume adjusts as it should. Are these the issues you're thinking of? Cheers
18. ## Animation and Spatial Audio

So by your example, max distance would equal the radius of the spheres in your scene I.e. half the sphere diameter? If I had a cube of height,width,depth = 5 each would max distance then be 2.5 if we assume the sound is attached to the mesh (does attaching to a mesh centre the sound in the mesh?)
19. ## Animation and Spatial Audio

An additional question: When we create spatial audio we define as such: new BABYLON.Sound("Music", "sounds/sound.wav", scene, null, { loop: true, autoplay: true, spatialSound:true, maxDistance:1.5, volume:0.3 }); The docs say the value of maxDistance - 1.5 here - is also in units. How does this distance value relate to e.g. diameter of a sphere of 5, what would the maxDistance value need to be to ensure the audio starts to play the moment the edge of the sphere is encountered?
20. ## Animation and Spatial Audio

By the way, maybe I'm missing something here but as I mentioned in my first post spatial audio appeared to work fine (at least, with my limited tests) using the ArcRotateCamera so long as one moves the camera manually. It's only when the camera is parented and then the parent animated that the spatial audio has issues. If the issue is that this setup would work fine with any other camera then fine, I just wanted to be absolutely clear here. p.s. do you need my home address for the contributor patches @Wingnutmentioned?
21. ## Animation and Spatial Audio

Thanks guys. So I've made the following change in my Babylon.max.js code (from line 4066 in your source code linked above): var matrix = listeningCamera.getWorldMatrix(); var world_position = BABYLON.Vector3.TransformCoordinates(listeningCamera.position, matrix); audioEngine.audioContext.listener.setPosition(world_position.x, world_position.y, world_position.z); and it seems to work fine, but can you see any issues with this patch? I'm wondering what the cost of calculating the world matrix and then transforming the camera's position using this matrix will be on the rendering pipeline. I need my scene to run smooth on all devices including mobile so if this is likely to cause a performance hit I'll have to think of a different approach.
22. ## Custom controls based on grid

For the first link I was referring to the specific comment I've linked to, where DK says "However for future reference, as DK mentioned - I always use a parent node to provide the coordinate system by which objects are animated.". I throwing ideas at you hoping something will stick As for the second post, I don't know, but you could try and let us know the results.
23. ## Animation and Spatial Audio

Does anyone know if there's a reason why spatial audio doesn't work when animating a camera towards a mesh that has an audio source either attached or placed in the same position? My project has an Arc Camera parented to a mesh, which is then animated around a scene. I've set up end points where the camera parent will animate to, with the idea being as soon as it approaches the centre of the target position the spatial audio will kick in. However, in practice this doesn't appear to ever happen and in fact the only way I seem able to get it to work at all is if I manually zoom or move the arc camera past these audio zones. Any thoughts anyone?
24. ## Custom controls based on grid

Oh you wanted locale movement? Sorry, I didn't read the full thread closely enough. Maybe this will help ? p.s. check this out if you need to convert from world to local