Jump to content

How to get the coordinates of the mesh after moving.


BangTao
 Share

Recommended Posts

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 ....

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

@Deltakosh@adamthank u ,look at these two pics.)1NH8F}@F0M3U4C%E5[%(5M.png@RQ{()G1H70DMO{M3RM(VQN.pngY{345)VO[5%@OSP8TZ23XJQ.png

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.

GIF1.gif

but if i open it :

GIF2.gifHGH181HT0IRRLTQ~UM)C[8R.png

I think i have get al the vertexes data,the ball is not at the right position///

6`CG}2PB(0FSF@WZ~JR5]2T.png

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

@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 ...

Link to comment
Share on other sites

@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
 

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

@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!

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...