bisectmesh() function?

Blitz3D Forums/Blitz3D Programming/bisectmesh() function?

Axel Wheeler(Posted 2008) [#1]
To blow stuff up real good, it would be interesting to have a function that bisects a mesh along some random plane, leaving you with two meshes. Then you can do it again on each half, etc. In conjunction with particles this could enliven those explosions with unique chunks of stuff flying around.

Is there a function out there already? I couldn't find one.

an example in partial pseudocode:

function bisectmesh(oldmesh)
  origpitch#=entitypitch(oldmesh)
  origyaw#=entityyaw(oldmesh)
  origroll#=entityroll(oldmesh)
  ;The above is so we can move it back when we're done

  my#=entityy(oldmesh);  
 
  rotateentity(oldmesh,rnd(360),rnd(360),rnd(360))
  
  newmesh=CreateMesh()

  for each vertex:
    if VertexY(...) < my# then move this vertex to the new mesh
  next

  ...

end function


Of course triangles have to by moved as well.

The problem is the exposed area of both meshes; if the object is hollow (like a car or tank, for example) then a copymesh()/flipmesh() could be the easiest solution. If it is a rock, however, you have to create new triangles between assorted existing vertices, which I don't want to do if it's been done already.

Hence my question here today.

Thanks in advance.


_33(Posted 2008) [#2]
I wanted to do a function like this but didn't have the skills. There is something similar in the code archive made by big10p, only the "in-between" triangles are missing. But otherwise, it truncates a model by a given plane.


srcoder(Posted 2008) [#3]
Sounds like a fun project.
BSP maps slice geometry exactly across a plane and creates two triangles from any triangle that bisects the plane (it creates the additional vertex from a edge/plane intersect calculation) That would give a very clean cut and would make it slightly easier to calculate the vertices/faces to make up the "hole".
Anyone know of code to do that?


Axel Wheeler(Posted 2008) [#4]
_33: Wow. That's pretty close to what I was looking for, and better written than mine would have been. I've been browsing his code archive articles; there are several good ones in there.

He does calculate the missing vertices, just doesn't close them with triangles (his purpose was to create a smooth edge). It should be pretty simple to close the gap.

srcoder: Thanks for the tip. I'll check that out too.


Stevie G(Posted 2008) [#5]

It should be pretty simple to close the gap.



It isn't really. You should look at some of the triangulation routines in the archives. Basically, you would need to create a list of the vertices which lie on the intersection plane, in clockwise order IIRC and pass them to the triangulate function.

Getting them in the correct order is probably the most difficult part. Thinking about it, you could find the center of all the vertices which sit on the plane and store each vertex angle to the center point. Then sort this list based on it's angle. This would probably only work with simple convex shapes.

Stevie


Axel Wheeler(Posted 2008) [#6]
Clever idea. I was assuming (hoping, really) two things:

1. It would be possible to grab the new vertices into a list as they are created; then I don't have to find them.

2. That the vertices are created in order around the gap, thus making it easy to link adjacent pairs to a central vertex (or to a selected one of the new vertixes - that's how cylinder caps are done).

Even if 2 is not true, it should be possible to iterate through the triangles looking for those with exactly two of the new vertices; these would be adjacent. From that you could get the order. Wait - you no longer need the order; each set of new vertices in an triangle...

Wait, make it simpler, for each new triangle created it creates another one linking the two new vertices to the center vertex (yes it must be convex).


Ricky Smith(Posted 2008) [#7]
Depending on the complexity of the models, the routines to calculate this on the fly would probably cause too much slowdown in a real time situation. Especially if you have a large amount of explosions. You would also have to recalculate the uv coordinates and vertex normals etc.
It would be much more efficient to create and texture the mesh pieces in a modeller and then use these as particles.


Axel Wheeler(Posted 2008) [#8]
big10p's function is quite fast; and we're talking exploding rocks here so they're probably not that complex except for maybe the original one.

The problem with the loaded media approach is they cause a big problem; players abandon games when they start looking too samey. When each explosion has the same identical chunks as the previous ones, something is wrong.

You're right that time management would be important. You could create a list of pending breaks and do only one per frame.

But just think about it; RoadWar; you blast the car in front of you and a chunk of its fender flies back and hits your car. And, the chunks (completely unique) are still lying there for you to hit each lap. Awesome!


Axel Wheeler(Posted 2008) [#9]
A thought on concave meshes (u-shaped, bowl shaped, etc.) in which separate sections are cut apart. The following method should solve part of it:

- Collect the new vertices
- Identify adjacencies by examining triangles
- Follow adjacencies around the loop
- If there are any vertices left over, then you have another section in a concave mesh, so continue until all the vertices are accounted for.

This also allows you to place your central vertex within each loop correctly. Granted, if the loop itself is concave you still need to detect that (using your method of angle checking perhaps) and try to find an acceptable point. This is a difficult problem that would need to be solved for any serious applications such as a modeller.

Do any modellers have a "knife" function like this?

Some game ideas:

A rather gruesome Samurai game concept comes to mind ... make your own gibs!

Or how about... Sandwich Maker Pro! Slice the bread, the ham, the cheese, and position it all together. Sounds like a big seller... :D

Maybe you have to slice up monsters and make sandwiches out of them!!! (Of course they keep attacking with whatever remaining body parts they have) Eat the sandwich to restore health. The sliced areas chould have the stylized internal bone organ structure textured in.

I never knew I was such a sicko!


Stevie G(Posted 2008) [#10]

The problem with the loaded media approach is they cause a big problem; players abandon games when they start looking too samey. When each explosion has the same identical chunks as the previous ones, something is wrong.



I think you're better sticking to this approach. There is no reason you can't make several versions of the same object with different breakable parts for some variation. For realtime use, the method you're suggesting will be slower than a week in the jail unless your meshes are very simple.


_33(Posted 2008) [#11]
Axel Wheeler, if you manage to program that routine, I'm interested in the source :P


Naughty Alien(Posted 2008) [#12]
in Crysis, every breakable tree is actually already cut inside modeling program in to bunch of smaller pieces..there is no on the fly cut off things..


Axel Wheeler(Posted 2008) [#13]
_33: Ok, I'll let you know if I get it together.

Thanks for the advice, everyone!