BangTao Posted January 17, 2017 Share Posted January 17, 2017 seems like i should recomputed the coordinates every time i changed the mesh's position(after move or after animation). i can't get the position use the method(↓) mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind) i don't know how to deal with it.Can some body give me some advices or PG? Thx......Problems never stop coming for me .... Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 17, 2017 Share Posted January 17, 2017 I give my apologies to you now but I personally can no longer help you for the reasons given in these topics I know if is very frustrating for you to keep getting problems but for me I am not getting enough information to help you further. I hope others might be able to help. Quote Link to comment Share on other sites More sharing options...
BangTao Posted January 17, 2017 Author Share Posted January 17, 2017 Thank u anyway.and you are very nice! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 17, 2017 Share Posted January 17, 2017 You need to understand first what the local space is (where the positions are set) and what the world space is (where these positions are translated according to what we call the mesh world matrix). Please have read and a look at all this material before : https://www.davrous.com/2013/06/13/tutorial-series-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-typescript-or-javascript/ Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 17, 2017 Share Posted January 17, 2017 Hi guys! Hey BT, you might want to try mesh.bakeCurrentTransformIntoVertices(); In psuedo: move mesh and/or... scale mesh and/or... position mesh then... mesh.bakeCurrentTransformIntoVertices() This sets mesh.position, .rotation, and .scaling all to 0, but keeps mesh state unchanged. Lastly... var myMovedVerts = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind) The vertex positions (the myMovedVerts data) will NOW be changed... matching new mesh transformations. They have changed because you "baked" the vertices... to match the new mesh .position, .rotation, and .scaling. Maybe this helps. Hope so. Please learn to create playground examples, if possible, as JohnK asks. When forum helpers can "see the problem"... in a BJS playground example, it is much easier for us to help. Do your best. thanks! BangTao 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 17, 2017 Share Posted January 17, 2017 Hello just to be sure. You do not want to move a mesh like mesh.position.x = ... ? Can you explain what you want to achieve? Quote Link to comment Share on other sites More sharing options...
adam Posted January 18, 2017 Share Posted January 18, 2017 If you are working with positions that you get from mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind) You'll need to use: BABYLON.Vector3.TransformCoordinates or BABYLON.Vector3.TransformCoordinatesRef to transform the positions from local space to world space. http://www.babylonjs-playground.com/#GAY2K#0 BangTao and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
BangTao Posted January 18, 2017 Author Share Posted January 18, 2017 @Deltakosh@adamthank u ,look at these two pics. I wanna add event (get current all vertexes data )to every frame(from 0 to 100) of the animation.and i did what @Wingnut says,but the position not correct,when i annotation the code. //getKeyFrameEvents(mod,states,C); it like this. but if i open it : I think i have get al the vertexes data,the ball is not at the right position/// Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 18, 2017 Share Posted January 18, 2017 I'm not sure i understand everything that's going on here, or why.. but, why not just change the mesh.position.y? http://www.babylonjs-playground.com/#1NF8VG#1 babylonJs is awesome. Quote Link to comment Share on other sites More sharing options...
BangTao Posted January 18, 2017 Author Share Posted January 18, 2017 it's like http://www.babylonjs-playground.com/#251XZI#0 ,,,the y get large~~~~~~i wanna attach events to animations (every frame) to do something ...but i don't know how to add these evens Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 18, 2017 Share Posted January 18, 2017 @BangTao you can get the current frame of the animation like this; http://www.babylonjs-playground.com/#251XZI#4 Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 18, 2017 Share Posted January 18, 2017 The previous PG I did for you http://www.babylonjs-playground.com/#9WUJN#17 did already showed you how to add an event to an animation. However now you have given me an playground of your own to work from I can help a little further but please try to read and understand any code given in help and how you might learn from it for your own use.. First of all scene.registerBeforeRender and creating an animation are two completely different ways of animating an object and you do not use both at the same time. The following PG just uses your animation and I have removed the scene.registerBeforeRender loop and have added events on some frames http://www.babylonjs-playground.com/#251XZI#5 This PG just uses the scene.registerBeforeRender loop and I have removed the animation and actions are undertaken at different render counts http://www.babylonjs-playground.com/#251XZI#6 Please study these two playgrounds how they are different to each other and how they are different to yours. Also as far as I can see mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind) as no relevance at all to what you are trying to achieve. This I have removed from both the PGs above. Please, please, please try to read some of the tutorials you have been given links to, if English is a problem can you find anybody to help you with the translation? Quote Link to comment Share on other sites More sharing options...
BangTao Posted January 18, 2017 Author Share Posted January 18, 2017 @JohnKI know,and i have learned a lot with your help,i know how to add event.how to create animation and so on,,,but ....if there r many event to add,then i wanna use loop to achieve what i want( http://www.babylonjs-playground.com/#251XZI#7),but it didn't work.and then i write some recursive function,and can add event just like the "loop".but there there's a new problem which is the last post ... Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 18, 2017 Share Posted January 18, 2017 The problem here is a javascipt one rather than a BJS one. Something to do with callback functions or passing parameters to an anonymous function or something like that - beyond my capabilities however. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 18, 2017 Share Posted January 18, 2017 @BangTao This is because the for..loop is long over and the index (or " i ") value is 4 by the time any of the events are fired, so all boxes are created at the same position, we can by-pass this by using a function to create the event, this way we save a local "copy" of the index value inside the function and are able to save it to each event.http://www.babylonjs-playground.com/#251XZI#10 Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 18, 2017 Share Posted January 18, 2017 @BangTao just realised that the animationEvent stores the frame number as a property so can do this http://www.babylonjs-playground.com/#251XZI#11 However depending on what events you want to happen on each frame this might not be the way to go about it. You might be able to do what you want without animationevents and just use a collection of animations. Would you please draw some key frames showing the objects you want to animate and where they are in the key frames and what they might look like. At least please try to describe in words For example Plane circles around the sky every few seconds it drops a parachute which falls to the ground Quote Link to comment Share on other sites More sharing options...
BangTao Posted January 19, 2017 Author Share Posted January 19, 2017 @aWeirdo@JohnK for (var i = 0; i < mod.animations[0].getKeys().length; i++) { newEvent(i); } function newEvent(i) { mod.animations[0].addEvent(new BABYLON.AnimationEvent(i, function () { get2dData(copyNewVertexes(mod.animations[0].getKeys()[i].value.x,mod.animations[0].getKeys()[i].value.y,mod.animations[0].getKeys()[i].value.z)); }, true)); } function copyNewVertexes(x,y,z){ var verticesTemp = []; var count =0; for(var i=0;i<verticesOrigin.length;i++){ verticesTemp[count++]=verticesOrigin[i]+x; verticesTemp[count++]=verticesOrigin[i+1]+y; verticesTemp[count++]=verticesOrigin[i+2]+z; i+=2; } verticesAll.push(verticesTemp); return verticesTemp; } Thank you,i finally make it with your help! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 19, 2017 Share Posted January 19, 2017 Glad you made what you wanted pity we never saw the final version in a playground. Quote Link to comment Share on other sites More sharing options...
adam Posted January 19, 2017 Share Posted January 19, 2017 Yes, please show us the result. Quote Link to comment Share on other sites More sharing options...
BangTao Posted January 19, 2017 Author Share Posted January 19, 2017 @JohnK@adamfinally,here.just a simples.http://www.babylonjs-playground.com/#251XZI#16 JohnK 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.