High density height map

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

High density height map

Postby sova » Tue Apr 17, 2012 6:42 am

Hello!
I am making the interaction of objects with high-density height map.
The object typically covers hundreds of samples of the height map.
The standard method of collision, which is transformation of the height map in the triangle, is too slow in my case.
(It is easy to get 500 or more triangles from the height map).

I have solved this problem by the conversion of averaged samples of the map in the surface.
The height map is smooth enough according the terms, so the surface is approximated it with sufficient accuracy.

The picture below shows a blue surface, which is convered to equilateral triangles part of height map.
The side of the triangle of this surface is 6 normal samples of height map.

surface.png
surface.png (61.54 KiB) Viewed 4983 times


I have an idea to try the calculation of the interaction of the height map with the map of the depth of the object.
It is also known as a "height map span". The picture 2 shows an example of the depth map.

bunny.png
bunny.png (5.55 KiB) Viewed 4983 times


The intersection of the object with a height map in this case is simple to calculate, the output is a two-dimensional map of the depth of interpenetration of the object and the height map.

Is it possible to introduce a set of points of the contact of the two surfaces in a physics engine?
I think it is easy to reduce the number of contact points to several dozen, averaging the values.
What should I do then? Can I pass these parameters to Newton?
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby Julio Jerez » Tue Apr 17, 2012 8:02 am

I am confuzed. I do not undernad when you say sample 6 normal psample per point

It is true the newton engine does the collsion with heighfield by conveting the elevation into faces. but is does not store the high as faces it actually satore then as elevation points.
I conver the elevation into face when it nee to read then to prosses teh collisions. has you use the heightfield collision primitive?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby sova » Tue Apr 17, 2012 9:31 am

has you use the heightfield collision primitive?

No, I don't.
I use user collision.
When collide method called I reconstruct part of surface. My code produces comparatively small ammount of triangles.

Here my function converts part of heightfield to equilateral triangles (without averaging heightfield values) Further generated mesh data passed to newton.
I think equilateral triangles better represents original surface so they more physics friendly)

Code: Select all
void equilateral_mesh_from_heightfield(Texture& hf,
      dVector& aabb_min, dVector& aabb_max,
      vector<dVector>& out_vertexes,
      vector<int>& out_indexes)
   {
      /* t_side
         |----|
         ______ _
        /\    /  |
       /  \  /   | t_h
      /____\/__ _|
      \    /\
       \  /  \
        \/____\
      */

      // triangle side
      int t_side = 6;
      int t_side_d2 = t_side / 2;
      int t_h = 5;

      // triangle size in world coordinates (0..1)
      float t_sidef = (float)t_side / hf.width();
      float t_side_d2f = (float)t_side_d2 / hf.width();
      float t_hf = (float)t_h / hf.height();

      // bounding rectangle
      int x0 = (int)(aabb_min.m_x * hf.width() / t_side);
      int y0 = (int)(aabb_min.m_y * hf.height() / t_h);
      int x1 = (int)ceilf(aabb_max.m_x * hf.width() / t_side);
      int y1 = (int)ceilf(aabb_max.m_y * hf.height() / t_h);
      x1 += 2;
      y1 += 1;

      //out_vertexes.clear();
      //out_indexes.clear();

      int width = x1-x0;
      int height = y1-y0;
      int wh = width*height;
      if(wh <= 0) return; // width or height is less than zero

      out_vertexes.reserve(wh); // TODO verify size
      out_indexes.reserve(wh);

      for(int y = y0; y < y1; ++y)
      {
         bool odd_row = y & 1;

         // odd row shift
         int x_shift = odd_row ? -t_side_d2 : 0;
         float x_shiftf = odd_row ? -t_side_d2f : 0;

         float world_yf = y * t_hf;
         bool y_last = y >= y1-1;

         for(int x = x0; x < x1; ++x)
         {
            float world_xf = x * t_sidef + x_shiftf;
            bool x_last = x >= x1-1;

            float height = height_scale * height_at(hf, x*t_side+x_shift, y*t_h);

            out_vertexes.push_back(dVector(world_xf, world_yf, height));

            if(!x_last && !y_last)
               // last row or column has no indices
            {   
               int index = out_vertexes.size() - 1; // current index

               /* adding two triangles
                  ______
                 /\ a  /
                /b \  / ewen row
               /____\/
               \ c  /\
                \  /d \ odd row
                 \/____\
               */

               if(!odd_row)
               {   // a
                  out_indexes.push_back(index);
                  out_indexes.push_back(index+1);
                  out_indexes.push_back(index+width+1);
                  // b
                  out_indexes.push_back(index);
                  out_indexes.push_back(index+width+1);
                  out_indexes.push_back(index+width);
               }
               else
               {   // c
                  out_indexes.push_back(index);
                  out_indexes.push_back(index+1);
                  out_indexes.push_back(index+width);
                  // d
                  out_indexes.push_back(index+1);
                  out_indexes.push_back(index+width+1);
                  out_indexes.push_back(index+width);
               }
            }
         }
      }
   }


But I want throw out this code and compute collision directly betwen height field and object depth map (height span map). Here is the example of height span map of torus. (image taken from http://nis-lab.is.s.u-tokyo.ac.jp/nis/c ... andbox.pdf)

hsmap.png
hsmap.png (27.06 KiB) Viewed 4978 times
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby Julio Jerez » Tue Apr 17, 2012 11:00 am

Ok,
your question was this: "Is it possible to introduce a set of points of the contact of the two surfaces in a physics engine?"
if you can build the mesh in the BBox that is pass in the user mesh callback, what is the problem them?


you will have to use core 200 libraries, because I have no refactor user collision mesh for core 300 yet.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby Julio Jerez » Tue Apr 17, 2012 11:07 am

Oh I see you want to make your own contacts joint. Is that what you want? or I still do undertand?

a Planned feature for core 300, this is user defined Contacts Joints for making specil sticky contacts. In newton all contact are joints so it should eassy to add the funtionality.
Tell me if this is what you want?
If so can you first the passing teh mesh and see what happens. then we I can add that fiture if is thsi si what you need.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby sova » Tue Apr 17, 2012 11:38 am

Julio Jerez wrote:Oh I see you want to make your own contacts joint. Is that what you want?

Yes.
I want pass to physics engine points of contact calculated by myself. (Also I know penetration depth at each point)... It will be faster than compute mesh-mesh intersections.

Is no way to do it with core 200? And no way to hack? :)
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby Julio Jerez » Tue Apr 17, 2012 12:02 pm

sova wrote:Yes.
I want pass to physics engine points of contact calculated by myself. (Also I know penetration depth at each point)... It will be faster than compute mesh-mesh intersections.
Is no way to do it with core 200? And no way to hack? :)


In that case you cna use core 300, because rigt now niegeh core 200, or 300 can do that.
however since this is a funtionality palled for core 300, I sugete you start with core 300.
you have work to do until I get to teh collison shape.

you can set it all up. use the collision hieghfield (as prove of concpet) untel teh use mesh is ready.
I will re enable the user define collision mesh, and as for the feature is quite eassy for me.

basically in the matearial pair I can add a a pointe to an Use define conatct calculation.
then in the broad phase the function will check if the callback pointer is set, if it is, it will call that function with the infomation
Materail, contact jount, the two bodies and the two shapes.
there you can calculate the contact points, normal and penetration. and that should be all.
does that sound acceptable to you?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby sova » Tue Apr 17, 2012 5:57 pm

Julio, I will try core 300 and i will answer you in several days.
Thank you!
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby sova » Sat Apr 21, 2012 3:05 pm

Hi, Julio!
I have started newton 300 on arm device (single threaded).
If you add the ability to set parameters of the contact by user in newton , I'm sure I can use it.
Thank you!
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby Julio Jerez » Sun Apr 22, 2012 9:18 am

alright, I will add that feature to the material, and it will be in on teh next check in to SVN. probale in 2 to 3 days.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby Julio Jerez » Tue Apr 24, 2012 12:21 pm

I actually found a very good reason for this feature.
Now that I am working on the vehicle, I alway have a problems wi t hteh manipulation o fteh tire contacts.
tire contact has a sepecial behavior, than is vey different tthat tha of a rigid body.

In the pass the way I solved it ws by making each tire to jave his pown specil contctt joint and do ray cast or conve cats to emit the DOF.
bu that is a bug problem because when you get two vehicle tire hiting each other you have to write lot of spcial code to resuleb the dounl; copntact problem.
that is one of the reaosn I abandone the car join in core 1.00
the solution is to have a UserContact defined is issued by a material callback. that way teh car joint will no nee any specia coding.

so when I check it this sturday ther will be teh materisl will have the new callback name UserDefinedContact with a real example.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby sova » Tue May 15, 2012 7:59 am

Heh... I watch changes of code every day... past weeks with no hope... :(
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby Julio Jerez » Tue May 15, 2012 10:47 am

yes, I started the work of teh editro, and I god distarted.
I will add that this weekend. I have not forgotten
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: High density height map

Postby sova » Sun Jun 17, 2012 8:22 am

I will try to modify code myself.
Forget me)
sova
 
Posts: 23
Joined: Mon Mar 05, 2012 8:58 am

Re: High density height map

Postby Julio Jerez » Sun Jun 17, 2012 9:18 am

Oh I am sorry I have not had the time to do that.

It will be very nice of you tryng doing it yourself. It will eb a good help an dmaybe you wna to contribute to teh library.
what I can do is that I can give you some pointers as to how to go about.
I assuming you are usin the lates library core 300.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests