How are curved quads rendered efficiently? - performance

A common industry standard is to utilize quads rather than triangles or ngons in 3d topology.
I understand that quads deform better and can be subdivided easily but I have noticed nearly all professional models have quads with curved lines.
To my understanding, curved lines must be broken down into many triangles which would mean a higher poly count which is generally a bad thing.
How are curved quads rendered such that they are preferred over triangles?
EDIT: Below are two examples of the geometry I'm referring to

Related

How to cover a rectangle area with irregular shapes and no holes

I have detailed, highly irregular shapes like these:
and I'm looking for a way to make them cover a rectangle area with no holes and minimal blend/cover between shapes. Limited up-scaling and free rotation is also allowed.
I searched through packaging and covering algorithms but there is not a lot of information about irregular shapes and every one I looked at assumes shapes cannot blend. In my case this is acceptable.
Given above shapes one solution would look something like this:
To achieve above result shapes have been transalted, rotated and scaled.
Given:
All shapes can be scaled up and down (max 2x) and rotated
Shapes can overlap
Part of shape can be outside of rectangle
Shapes don't have holes in them
Do you know an algo that could solve this?

Differential or intersection of islands of 2D polygons in different layers

I have a 2D layer/section containing the 2D polygons colored in shades of green.
I have another layer containing the 2D polygons colored in shades of blue.
I intend to figure out how different are the two layers. Maybe extracting the layers differential. Can anybody provide an algorithm, library or a hint? I took a look at CGAL, but not quite sure which package to try out.
Unclear the kind of comparison you want to do.
Assuming you want the geometric intersection of the triangulations, an easy solution is to intersect all polygons pairwise. (If the number of triangles is large, use some acceleration technique to avoid all comparisons.)
If you need the triangulated intersection, you can use a clipping algorithm (Sutherland–Hodgman) and triangulate the resulting polygons, which can range in shape from triangles to hexagons. Fortunately, they are convex.

Is there a way to change the way geometry is drawn in Three.js?

I'm new to WebGL and OpenGL. I've worked with an OpenGL library elsewhere that gives me the options of choosing how my geometry is "drawn". For example I can select triangles, quads, line_loop, points, etc.
My question is: based on my research so far, Three.js removed the option for quads due to rendering issues. Are there any other options on how geometric shapes are drawn?
Here's a graph depicting what I mean: http://www.opentk.com/files/tmp/persistent/opentk/files/GeometricPrimitiveTypes.gif
Polygons and Quads are pretty much useless, because your typical rasterizer (software or GPU) can deal only with convex, coplanar primitives. It's easy to construct a quad or polygon that's concave or not coplanar or both. Hence quads and polygons have been removed from modern OpenGL. Triangles, in any form are safe though, there's no way for a triangle to be concave or not coplanar.

WEBGL Draw pixels inside vertices position

I am new to the WebGL and shaders world, and I was wondering what the best way for me to paint only the pixels within a path. I have the positions 2d of each point and I would like to fill with a color inside the path.
2D Positions
Fill
Could someone give me a direction? Thanks!
Unlike the canvas 2d API to do this in WebGL requires you to triangulate the path. WebGL only draws points (squares), lines, and triangles. Everything else (circles, paths, 3d models) is up to you to creatively use those 3 primitives.
In your case you need turn your path into a set of triangles. There are tons of algorithms to do that. Each one has tradeoffs, some only handle convex paths, some don't handle holes, some add more points in the middle and some don't. Some are faster than others. There are also libraries that do it like this one for example
It's kind of a big topic arguably too big to go into detail here. Other SO questions about it already have answers.
Once you do have the path turned into triangles then it's pretty straightforward to pass those triangles into WebGL and have them drawn.
Plenty of answers on SO already cover that as well. Examples
Drawing parametric shapes in webGL (without three.js)
Or you might prefer some tutorials
There is a simple triangulation (mesh generation) for your case. First sort all your vertices into CCW order. Then calculate the middle point of all vertices. Then iterate over your sorted vertices, and push a triangle made of the middle point, the point at vertices[index] and the point at vertices[index+1] to the mesh.

Algorithm to produce rounded edges and corners in a 3D mesh

Starting with a 3D mesh, how would you give a rounded appearance to the edges and corners between the polygons of that mesh?
Without wishing to discourage other approaches, here's how I'm currently approaching the problem:
Given the mesh for a regular polyhedron, I can give the mesh's edges a rounded appearance by scaling each polygon along its plane and connecting the edges using cylinder segments such that each cylinder is tangent to each polygon where it meets that polygon.
Here's an example involving a cube:
Here's the cube after scaling its polygons:
Here's the cube after connecting the polygons' edges using cylinders:
What I'm having trouble with is figuring out how to deal with the corners between polygons, especially in cases where more than three edges meet at each corner. I'd also like an algorithm that works for all closed polyhedra instead of just those that are regular.
I post this as an answer because I can't put images into comments.
Sattle point
Here's an image of two brothers camping:
They placed their simple tents right beside each other in the middle of a steep walley (that's one bad place for tents, but thats not the point), so one end of each tent points upwards. At the point where the four squares meet you have a sattle point. The two edges on top of each tent can be rounded normally as well as the two downward edges. But at the sattle point you have different curvature in both directions and therefore its not possible to use a sphere. This rules out Svante's solution.
Selfintersection
The following image shows some 3D polygons if viewed from the side. Its some sharp thing with a hole drilled into it from the other side. The left image shows it before, the right after rounding.
.
The mass thats get removed from the sharp edge containts the end of the drill hole.
There is someething else to see here. The drill holes sides might be very large polygons (lets say it's not a hole but a slit). Still you only get small radii at the top. you can't just scale your polygons, you have to take into account the neighboring polygon.
Convexity
You say you're only removing mass, this is only true if your geometry is convex. Look at the image you posted. But now assume that the viewer is inside the volume. The radii turn away from you and therefore add mass.
NURBS
I'm not a nurbs specialist my self. But the constraints would look something like this:
The corners of the nurbs patch must be at the same position as the corners of the scaled-down polygons. The normal vectors of the nurb surface at the corners must be equal to the normal of the polygon. This should be sufficent to gurarantee that the nurb edge will be a straight line following the polygon edge. The normals also ensure that no visible edges will result at the border between polygon and nurbs patch.
I'd just do the math myself. nurbs are just polygons. You'll have some unknown coefficients and your constraints. This gives you a system of equations (often linear) that you can solve.
Is there any upper bound on the number of faces, that meet at that corner?
You might you might employ concepts from CAGD, especially Non-Uniform Rational B-Splines (NURBS) might be of interest for you.
Your current approach - glueing some fixed geometrical primitives might be too inflexible to solve the problem. NURBS require some mathematical work to get used to, but might be more suitable for your needs.
Extrapolating your cylinder-edge approach, the corners should be spheres, resp. sphere segments, that have the same radius as the cylinders meeting there and the centre at the intersection of the cylinders' axes.
Here we have a single C++ header for generating triangulated rounded 3D boxes. The code is in C++ but also easy to transplant to other coding languages. Also it's easy to be modified for other primitives like quads.
https://github.com/nepluno/RoundCornerBox
As #Raymond suggests, I also think that the nepluno repo provides a very good implementation to solve this issue; efficient and simple.
To complete his answer, I just wrote a solution to this issue in JS, based on the BabylonJS 3D engine. This solution can be found here, and can be quite easily replaced by another 3D engine:
https://playground.babylonjs.com/#AY7B23

Resources