I definitely need some help with this. Let’s just say I have an arbitrary mesh that is just a quad:
[java]
Vector3f[] vertices = new Vector3f[4];
vertices[0] = new Vector3f(minX, minY, minZ); // bottom left
vertices[1] = new Vector3f(maxX, minY, minZ); // bottom right
vertices[2] = new Vector3f(minX, maxY, maxZ); // top left
vertices[3] = new Vector3f(maxX, maxY, maxZ); // top right
[/java]
(I know how to create custom meshes from following the Custom Mesh tutorial.)
But I’m not quite sure how to extrude this. I would need to compute new vertex coordinates and generate the sides and top (so really, we’d end up with a cube… I’m not trying to extrude anything more complicated than a cube).
I thought that maybe using localToWorld(…) would help… but I think I need someone to start me in the right direction.
- find top square by adding +10 at y.
- Connect bottom square with top. Jme has triangle’s so you must think how to form a quad from 2 triangles.
My pseudocode for 2 :
a) For every 2 nearby vertices on “bottom”
b) connect them with the corresponding one on “top”
c) now you formed a triangle.
d) perform a,b,c for "top towards bottom. Now you have a quad.
I wanted to do something similar but i was stuck on step a) for every 2 nearby vertices.
I found it hard because a vertex has 2 points that is “nearby” so i didnt know which one to choose.
Anyone else have any ideas ?
But that approach suggests that “y” is up. I need to find the solution for an arbitrary case…
you extrude towards y = “up”, then you can rotate if you dont like.
No, I want to extrude in the direction of the normal to the plane.
a ok then do :
topPosition = position.add( normal );
Are you trying to make a game or a 3d modeling editor :roll:?!..
if he implements bevel he would be able to create custom meshes for enemies.
Plus gain knowledge vital for working with custom meshes.
I seem to have solved this:
- Calculate the normal to the quad you want to extrude.
- Scale the normal by the extrusion length.
- Add the normal to the quad vertices to generate the new “top” vertices (i.e., top of the extrusion).
- Create the new faces (quads) from the original quad vertices and the newly generated vertices, by creating triangles as described in the Custom Mesh tutorial.
Thanks.
and how did you implement step 4 ?
I edited steps 3 & 4 to try to clarify. Does it help?
ok i see now how it can work, i didnt pay attention in custom mesh tutorial when it was talking about converting triangles to quads, thx