Is there a way to make graphs to surfaces

Hi,

I had joined many vertexes which are 2D mode to one graph with mesh , now I want to make it to surface by adding it texture or something.

http://imgur.com/qMx7h



I had seeked solution for long time in the API,

I am new in JME, appreciate for any suggestion.

First read this https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

Hi,nehon

Thanks for your reply.

I had read the tutorial you provide before, it is a example in how to create mesh, my mesh had created already, when use setMaterial it can just fill the line with that texture,and I want to it fill in the whole graph one texture to make it looks like floor.

Yeah i got it, but your mesh is not valid, because it’s not a surface it’s a line.

You have to create triangles, and for that you need to specify the indices of the vertices that are connected like 1,2,3 3,1,4 etc…

Hi,nehon

Yes, for this graph I can create some specific triangles to complete this purpose, but I have lots of uncertain vertices ,I want to join these vertices in some rule and then convert it to surface dynamically.

Is this possible?

Sure.

All you need are the rules. For example:

Connect to vertice added directly before and after the given vertex.

Connect to the vertices closest to the given vertex.

Connect to all vertices in a given radius.







The rest is simple.

Since the shape is not convex it is not quite as simple as that. You’d have to make sure that any new edge added was actually inside the shape.



JME doesn’t provide anything to do this sort of triangle tessellation “out of the box”. You would have to write your own as KuroSei suggests. You can probably find decent algorithms online.



I vaguely recall one where you subdivide the shape into two shapes based on a new edge connecting the two closest vertexes that do not share an edge and are not crossing another edge. Then do the same thing on the two halves and so on. But that was so long ago that it was a software renderer and I needed to watch out for really long slender triangles… and that algorithm produces pretty uniform results. There may be something simpler that doesn’t care about that restriction.



…whatever it is, it will be iterative.

Ok, seems there doesn’t have simple way.

Thanks nehon, KuroSei and pspeed .

Hi,Pspeed

Your and KuroSei suggestions are very helpful.

Could you share more detail about how to make sure that one new edge was inside the shape and one edge not crossing anther edge.

I got an idea might works, but need above two points.

I don’t have an algorithms for “edge in shape” tests handy but there are ways. An internet search might help. My memory says it’s something about traversing the outside of the shape in a specific order ( clockwise for example) and testing if an edge split would go towards the inside (ie: more clockwise) or towards the outside (less clockwise). If you order and mark the vertexes then given a vertex V you will know which is the “next” one in the border and can compare it to the new edge you are trying to create.



Edge → edge intersection is just a matter of seeing if one line segment crosses any of the others… which in 2D (like you are doing) isn’t too difficult.



Anyway… something like that. The googles will have to be your guide beyond that, I think.



Note that none of this is particularly speedy so I wouldn’t try to do it every frame or anything… but as a one time conversion every now and then it shouldn’t be too bad.

Even in 3D its not as hard as it sounds, i guess.

I had to do something similar in school once.



All you have to do it to project everything on a plane and tada. you are in the 2D-area again :slight_smile:

Works aslong, as you can project it easily. After that things are getting more complicated. But there are lots of solutions out there i guess. :slight_smile: