Snouto

Members
  • Content Count

    89
  • Joined

  • Last visited

Everything posted by Snouto

  1. 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. 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. 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. Thanks for the information chaps, very helpful 👍🏻
  5. 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. [edit] 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
  6. Yo 3D dudes and dudettes I've just updated the Blender exporter and BJS to the latest versions as I was using some fairly old code. One of the first things I noticed was that my .babylon file has gone from 2.1mb down to 600kb, which is awesome, so bravo to you guys for that excellent piece of optimisation. I also noticed through first observing and then from looking about the internets that the export option to make everything Flat has vanished. I confirmed this from a post by @JCPalmer here For my project I still wish to maintain that flat look, so I understand one way to do this is via BJS code using Mesh.convertToFlatShadedMesh() I just wanted to ask if this is indeed the correct approach to reproduce the flat shading appearance from Blender? It does work for me (albeit I have to ensure the meshes I'm iterating through after load support mesh.subMeshes, otherwise a JS error is thrown) but I'm not sure this is the most optimal way. I did try adjusting the angle of the split edged modifier in Blender but that didn't appear to make the slightest bit of difference once I exported to BJS. If I stick with convertToFlatShadedMesh() when loading my scenes and objects am I incurring an additional performance hit over the old exporter approach of "Flat shade entire scene", or are these two things essentially the same outcome just with the processing occurring in different places? If the latter, how might I take care of that processing at the model level rather than the client browser? Cheers and keep up the excellent work!
  7. 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. 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. 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. 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. 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. 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. Any chance of a follow up on this stuff @davrous? Cheers
  14. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
  25. For simple movement try adding this code: BABYLON.AbstractMesh.prototype.moveTo = function (targetPos, fps, frames, done) { var ease = new BABYLON.QuadraticEase(); ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT); this.activeAnimation = BABYLON.Animation.CreateAndStartAnimation('at5', this, 'position', fps, frames, this.position, targetPos, 0, ease, done); }; This will attach a moveTo method to every mesh in your scene, and then you can simply call the function like so: myMesh.moveTo(new BABYLON.Vector3(x,y,z),24,96,function(){ console.log("Movement complete!"); }); You can extend the function to accept the easing type in the method call if you intend to have different ease effects according to situation. For rotation you may wish to look in to Quaternions, as they in general provide much smoother and more reliable results. The following is an example implementation for slerping between two quaternions, however there are probably other methods you can use for this. // set up the initial Quaternion on your mesh, as they are not created automatically myMesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll( myMesh.rotation.y, myMesh.rotation.x, myMesh.rotation.z ); // add an "indicator" mesh to your main mesh. This will be used to look at the target location, and the different between its quaternion and your mesh's quaternion then slerped to match var indicatorMesh=BABYLON.Mesh.CreateBox("meshIndicator", 0.1, scene); // add quaternion for this new mesh too indicatorMesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll( indicatorMesh.rotation.y, indicatorMesh.rotation.x, indicatorMesh.rotation.z ); // parent the indicator mesh to your main mesh indicatorMesh.parent = myMesh; // now, in a registerAfterRender function (called automatically), adjust the two quaternions. change the world/local space to suit. targetPosition it the Vector3 you want to look at scene.registerAfterRender(function () { if(myMesh.isRotating=true){ // make the indicator mesh look to the target position. This will update its quaternion. indicatorMesh.lookAt(targetPosition,0,0,0,BABYLON.Space.WORLD); // now get an integer value representing the difference between the main mesh quaternion value and the indicator mesh's quaternion value. var diff = myMesh.rotationQuaternion.subtract(indicatorMesh.rotationQuaternion).length(); // registerAfterRender fires after ever frame render, so here we can check the difference between the two quaternions and decide to do something once we meet a certain threshold. if(diff > 0.05){ // if we are still above the threshold, adjust the mesh quaternion a little. You can adjust the amount to suit. The higher the number the quicker the rotation and the faster the rotation will pass the threshold. We use Slerp here because this will spherically interpolate a value in directional vectors myMesh.rotationQuaternion = BABYLON.Quaternion.Slerp( myMesh.rotationQuaternion, indicatorMesh.rotationQuaternion, 0.035 ); else { // set the rotating flag to false to stop this loop for firing again myMesh.isRotating=false; // optionally call a function to continue processing done && done(); } } }); // somewhere in your code, start the process away targetObject=new BABYLON.Vector3(x,y,z); myMesh.isRotating=true; var done = function(){ console.log("done rotating"); };