Jump to content

Mesh facet data


jerome
 Share

Recommended Posts

ok, ok, I read back the former post about the physics commented code and I found out that all the stuff about switching between the world space and the local space (then switching back) was quite complex for many users...well, far from the BJS motto : simple & powerful.

That's why I changed the final facetData API and added some methods to hide all this stuff, so now the users can do everything directly in the world space.

Thus the physics code on collision is now really simple (from the line 131) : http://www.babylonjs-playground.com/#PLPPV#10

[EDIT] scaling adaptation still respected : http://www.babylonjs-playground.com/#PLPPV#11

I guess it's ok for a PR now ... let's go to translate all this to TS.:D

 

[EDIT 2] Little (documented) physics refinement about the computation of previous position : http://www.babylonjs-playground.com/#PLPPV#12

Link to comment
Share on other sites

PR just submitted

in short :

Brand new feature : Mesh Facet Data
Examples :

mesh.updateFacetData();    // enables and computes the facet data for this mesh 
                           // this can be called on demand, if the mesh is
                           // morphed for instance, even in the render loop 


// get the index of the closest facet to (x, y, z) in the world 
var i = mesh.getClosestFacetAtCoordinates(x, y, z); 
var position = mesh.getFacetPosition(i); // returns the i-th facet world position 
var normal = mesh.getFacetNormal(i);     // returns the i-th facet world normal 
// then do stuff with these values, i.e your own physics... 

// you can even get the closest point to (x, y,z) ! 
var proj = BABYLON.Vector3.Zero(); 
i = mesh.getClosestFacetAtCoordinates(x, y, z, proj); 
// proj is (x, y, z) projected on the closest facet

 

Note : all the facet data computation are done by ComputeNormals() in the same loop, so it's really fast and doesn't impact the usual normal computation.

Link to comment
Share on other sites

Well, some test demos with always the same simple physics (on my site, waiting for the merge)

Now the updatable parametric shapes (ribbon, tube, extrusion,etc) automatically update the internal mesh partitioning when the update by the call to "CreateXXX()" with the parameter "instance". So nothing to do for the user more than to call as usual "CreateXXX()" and the facetData are updated in the same time

http://jerome.bousquie.fr/BJS/test/facetdata3.html

Moreover, you remember that the SPS is mesh, don't you ? so, as a mesh can have its facetData, a SPS can also. Like for the dynamically morphable parametric shapes, the internal facetData are automatically updated by the call to "setParticles()" if they are enabled for the SPS.

example : facetData sps (boxes and torus) vs falling ball sps : http://jerome.bousquie.fr/BJS/test/facetdata4.html

 

Link to comment
Share on other sites

I smell Tonka.  How 'bout you guys?  :)

Hey Jerome... how about we fill-up a "sandbox" with sps, and see if they play nice with EACH OTHER... when contained in that topless box.

Then I'll jump in there with my Tonka MotorGrader and plow some roads... like when I was age 4.  FUN!

Then... Snowblower Simulator 1.0  :)  So much fun ahead!  Could make pretty good bullets, too... for the carnival shooting games.  Basic collision, nothing fancy... but a FAST machine gun is possible. (not sure if facet data is needed for that, though).  Nice work, J-Man!

Link to comment
Share on other sites

Had a discussion with Jerome way back and adopted the term facets for the  triangles that form a mesh in BJS. A face is an adjacent group of facets with the same normals. The reason being for example - a box has six faces whereas in BJS it made up of twelve facets since each face is constructed from two facets. The circular caps of cylinders are faces made from many facets.

Link to comment
Share on other sites

@JohnK perfectly answered @satguru 's question (better that I would have done with my own word in english). So a facet is a basic triangle built with 3 vertices.

@BangTao : the PG you're using is one of the first of the prototype. Just wait for the feature to be pushed in the PG (and for the upcoming documentation) and then use only mesh.partitioning Subdivisions = someInteger instead. Btw, I have an idea to improve the internal partitioning (what is not a real octree, that's why the has changed since the first prototype) to auto-adjust according the axis if, say, the mesh has a big size along X and is really small along Y : a plane for instance has almost only 2 dimensions x and z, for instance, so it's not pertinent to partition its y dimensions in, say, 10 subdivisions

 

 

Link to comment
Share on other sites

that's greet .i can't wait it 

well ,would you please simplyly tell me how to run in loophttp://www.babylonjs-playground.com/#SRA5B#0

the little red ball is from (0,0,0 ) to (10,10,10),i need quickly get the closest facet to the red ball.i wanna use "for loop" ,but it did'nt check the facet every time i modified the (x,y,z)

Link to comment
Share on other sites

Please wait :)

We are still in alpha and the API is not definitive for now.

To answer your question, the method getClosestFacetAtCoordinates(x, y, z) will return the closest facet at (x, y,, z) expressed in the world and this method is also designed to be called as many times as needed, so each frame if you want or even many times per frame. Under the hood it's just a quick computation of an index, and access to an array and another light comparison between a distance fast computation.

In my example of falling balls, it's called once per particle, so 2000 times per frame for 2000 particles !

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