what's a good way or algorithm to extrude a 2D mesh to 3D? - opengl

I have a 2d mesh defined by a list of vertices and triangles that I'm rendering in a 3D engine. For this example let's say it looks like a car tire off its rim. So a fat circle with a hole in it. I want to extrude this into a 3d mesh and render it in a game engine. I know I can just copy the vertices and and translate them along the z-axis to get the back face. But then I'm not sure how to define the triangles for the sides and sides of the middle opening.
I read this How To Extrude a Flat 2D Mesh, Giving it Depth
But I am not hand defining the mesh so I don't know ahead of time where my boundaries are. I can see that if I knew my vertex boundaries and their order, that I could maybe walk around the edge and make triangles between the two faces. But I don't know their order around the edge yet.
Anyway I haven't quite wrapped my head around a good approach for this yet and thought someone might have some advice.
Thanks!

Related

Algorithm to constrain moving point onto 3d surface

I'm not really sure where to start looking for info about this question, so I'm asking here. Hopefully it's not too general. I've written a particle library in C++ and am trying to add the ability to constrain particles to the surface of a mesh. Not a rigid constraint though -- I want particles to be able to slide over the surface when affected by forces.
So, imagine I have an arbitrary concave mesh with n triangular faces. I then have a 3d point (particle) located on one of the faces. A apply a directional force to that particle to get it moving, but I want it to move along the topology of the surface, not simply move linearly through space. It should move smoothly over the surface and always be touching a triangle of the mesh.
I've thought about moving the particle linearly at first, and then snapping it to the closest point on the surface, but that would run into a lot of problems, like the particle might snap to other non-contiguous parts of the mesh simply because they happen to be a shorter distance to the particle after it's been moved by the force.
Then I thought about checking its barycentric coordinates and using them to determine which adjacent triangle it should move onto, if it leaves the bounds of its current triangle...but that seems like a hugely inefficient solution riddled with other problems (like if the force moves the particle past the bounds of all adjacent triangles as well).
Then I thought about using UVW coordinates to figure out where the particle would move to, but that wouldn't work either.
Any ideas?
Here's an image to help illustrate the problem:

OpenGL - parameterized meshes

Given a human 3D model, I want to change its shape by giving parameters, like height, waist, bust etc.
From what I gathered, the 3D model should have some 'hooks' around the areas I can change.
Any pointers for this would be very helpful through OpenGL, Three.js or any other means. I don't want to do it in Blender or other 3D manipulation tools. I want it done programatically.
Here's a Sample 3D model
What you should do is "tag" a group of vertices together.
Then apply a vertex shader to those groups, which changes the position of the vertices to shrink/expand the mesh.
One way to do this is to place a point inside the mesh, and give it a radius. This pretty much means you're creating a sphere.
Run the shader on all the vertices inside the sphere.
What the shader should do is "inflate" the sphere - moving the vertices away from the center point.
Just transform each vertice away from the center by a certain ammount.
(Make a vector from the center to the current vertice, continue the vector, and move the vertice there.
This should work well for the belly.
Another shader you can do is to stretch the mesh vertically (for the person's height).
This is more straightforward.
Just run on all vertices and add to their height.
How much to add - that's what you should figure out. My intuition says it can't be a constant - I think it's a linear function but I'm not sure.

calculating normals for quad mesh

I have a struct QUAD that stores 4 pointers to 4 VECTOR3D (which contains 3 floats) so that I can draw the quad mesh.
From what I understand is whenever I draw a mesh, I need normal as well to properly light/shade a mesh and it's relatively easy when it's a mesh laying on a plain, using normal per face.
When I have 2 by 2 quad meshes laying on XZ coordinate and tried to raise it's centre (0,0,0) by a certain point, say (0, 4, 0) it would start to form real 3D shapes, then I need to calculate normals again. I'm having hard time understanding how and what is to be to calculated normals. As expected, the 3D shape shades like it's still a flat mesh, so it does not represent real shape. One of the explanation says I need to calculate normals per vertex instead of per face.
Does it mean I need to calculate normals for all corners of mesh? once i have normals what would i do? I was still using old glBegin glEnd methods but now I feel like i need to use DrawArray method. I'm deeply confused and I'm pretty sure I don't make much sound but i'd much appreciate your help.
If you need flat looking surface then your normals will be normals to the quad plane. If you need "soft looking" surface you need to blend(read this and watch this cool simple video) normals - that will add sort of gradient.

Fill curved object with color

I am new to OpenGL.
I want to draw an object which has 4 vertices. It is like a quad object, but for bottom side I need to draw an arc. Other sides are connected with straight lines. I want to fill the object.
Can anybody guide me to do this please?
Triangulate your shape and render those triangles any way you prefer (immediate mode / VBO / VAO).
Convert your arc shape into segments. Number of vertices depends on detalization/smoothness you want to achieve.
Triangulate the shape. With simple shapes, like this one, you can do it manually in code (draw it on paper like I did and write down vertices indexes that form triangles). With more complicated shapes you could use a triangulation algorithms (available on Net). When shapes are even more complicated (i.e. animal outline) - you might need to use special 2D/3D modelling software just to make them, and it will do triangulation in there.
Render the triangles.

Why is there no circle or ellipse primitive in OpenGL?

Circles are one of the basics geometric entities. Yet there is no primitives defined in OpenGL for this, like lines or polygons. Why so? It's a little annoying to include custom headers for this all the time!
Any specific reason to omit it?
While circles may be basic shapes they aren't as basic as points, lines or triangles when it comes to rasterisation. The first graphic cards with 3D acceleration were designed to do one thing very well, rasterise triangles (and lines and points because they were trivial to add). Adding any more complex shapes would have made the card a lot more expensive while adding only little functionality.
But there's another reason for not including circles/ellipses. They don't connect. You can't build a 3D model out of them and you can't connect triangles to them without adding gaps or overlapping parts. So for circles to be useful you also need other shapes like curves and other more advanced surfaces (e.g. NURBS). Circles alone are only useful as "big points" which can also be done with a quad and a circle shaped texture, or triangles.
If you are using "custom headers" for circles you should be aware that those probably create a triangle model that form your "circles".
Because historically, video cards have rendered points, lines, and triangles.
You calculate curves using short enough lines so the video card doesn't have to.
Because graphic cards operate on 3-dimensional points, lines and triangles. A circle requires curves or splines. It cannot be perfectly represented by a "normal" 3D primitive, only approximated as an N-gon (so it will look like a circle at a certain distance). If you want a circle, write the routine yourself (it isn't hard to do). Either draw it as an N-gon, or make a square (2 triangles) and cut a circle out of it it using fragment shader (you can get a perfect circle this way).
You could always use gluSphere (if a three-dimensional shape is what you're looking for).
If you want to draw a two-dimensional circle you're stuck with custom methods. I'd go with a triangle fan.
The primitives are called primitives for a reason :)