Can Geometry vertex data be shared across three.js Ribbons? - three.js

I have a large set of vertices generated by interpolation of heart contours extracted from cardiac MRI slices which form a generally cylindrical shape. In the current (C++) visualization, the vertex data is held in a single array and each lateral strip in the model is rendered as a triangle strip.
I am wondering if there is a way to share Geometry vertex data across multiple Ribbons and avoid having to create separate Geometry objects for each strip (thereby duplicating vertex data).

Related

How to determine the relationship between faces, bend angles, etc from a iges CAD model

Hie guys I'm working on an web app for feature extraction from an IGES(file format) CAD model. I have extracted and stored all the entities from the iges file e.g shell entity, face entity, loop, edges, and vertex entity. Also I managed to draw the model using three.js.
I followed the the algorithms in the document here until the point where we extract feature from the model itself. The document assumes that the edge between two faces is a line and so calculating the angles and edge concavity becomes easy:
The algorithm used is as follows:
In my case, however, the edge between the faces is a semi cylindrical in shape and this edge is detected by the app(I guess because of the entities in the iges file) as having 4 faces( the outer & inner faces and the faces on the sides). When I draw the wireframe model this is what is displayed:
I would like your help in finding the best algorithm to find the angles between two faces without using the edge face in the process just like in the first image( i.e as if the edge is just a line).
How do you calculate the edge direction( as stated in the above document)
THANK YOU.

Identifying object overlaps in a 3D space

I have a set of 3D objects (points, triangles, lines). I would like to split these objects where they overlap. In order to do this, I want to compare each pair of objects which overlaps in 3D space.
I only need to do the operation once, though the new split objects need to be added to the list of 3D objects to check for further overlaps.
Is there an efficient data structure to put the objects into to do this kind of iteration? Would the cost of builidng such a structure be greater than sorting the objects along one axis and iterating a front and back axis coordinate to keep track of overlapping objects.

What's the main difference between B-Rep and Mesh index represation

I know B-Rep (ParaSolid) is the popular solid representation. From my past experience, I always touch the triangle mesh representation like OBJ, STL file format. I am wondering why B-Rep is better than mesh representation? What's the main difference?
A boundary representation (b-rep) solid modeler uses a combination of precise geometry and boundary topology to represent objects such as solids (3d manifolds), surfaces (2d manifolds) and wires (1d manifolds).
The salient property of a b-rep is that it represents geometry precisely. Faces of the b-rep are defined by the equations of the surfaces associated with the face. Edges are represented with precise curves, often the curve of intersection of its adjacent faces. (Sometimes approximate curves are used when precise curves are too difficult to compute or when faces don't fit together exactly--this is called a "tolerant" model).
Because the underlying geometry of a b-rep is precise, the model can be queried (in principle) to arbitrary precision. For example, if you have a b-rep of a box with a cylindrical hole through it, you can query the volume of the box to an arbitrary precision. With a tessellated model you can only compute the volume to the precision of the tessellation, which can never represent the cylindrical hole exactly.
Another benefit of b-reps is they tend to be much more compact than tessellated models. As a simple example, a sphere represented as a b-rep has a single face associated with the geometry of the sphere. It only takes a center and radius to define that sphere, and a few bytes more for the b-rep data structure to support it. A tessellated model of a sphere may have many vertices, each with 3 coordinates.
Diving a little deeper, Boolean operations on a tessellation are problematic, since the facets on one of the bodies may not line up with the facets on the other. There needs to be some sort of rectification process which will add complexity and inaccuracy to the combined model. No such problem occurs with b-reps, since new curves can be computed as intersections of the surfaces that underlie the intersecting faces.
On the other hand, tessellated models are becoming more popular now that the technology of manipulating them is maturing. For example, with discrete differential geometry and discrete spectral methods we can manipulate the meshes in a Boolean in a way that minimizes the local changes to discrete curvature, or we can manipulate regions of the tessellation with simple controls that move many points.
Another benefit of tessellated models is they are better for scanned data. If you scan a human face, there is no need to try to find precise surfaces to represent the data, the tessellated image is good enough.
First of all, better for what?
For example, for 3D printing, or pure visualization purposes mesh representation is better suited.
B-Rep preserves the underlying geometry (surfaces, curves, points), as well as connectivity between model's topological items (faces, edges, vertices). Thus, allowing richer operation (feature) set: filleting, blending, etc.

2D geometry outline shader

I want to create a shader to outline 2D geometry. I'm using OpenGL ES2.0. I don't want to use a convolution filter, as the outline is not dependent on the texture, and it is too slow (I tried rendering the textured geometry to another texture, and then drawing that with the convolution shader). I've also tried doing 2 passes, the first being single colorded overscaled geometry to represent an oultine, and then normal drawing on top, but this results in different thicknesses or unaligned outlines. I've looking into how silhouette's in cel-shading are done but they are all calculated using normals and lights, which I don't use at all.
I'm using Box2D for physics, and have "destructable" objects with multiple fixtures. At any point an object can be broken down (fixtures deleted), and I want to the outline to follow the new outter counter.
I'm doing the drawing with a vertex buffer that matches the vertices of the fixtures, preset texture coordinates, and indices to draw triangles. When a fixture is removed, it's associated indices in the index buffer are set to 0, so no triangles are drawn there anymore.
The following image shows what this looks like for one object when it is fully intact.
The red points are the vertex positions (texturing isn't shown), the black lines are the fixtures, and the blue lines show the seperation of how the triangles are drawn. The gray outline is what I would like the outline to look like in any case.
This image shows the same object with a few fixtures removed.
Is this possible to do this in a vertex shader (or in combination with other simple methods)? Any help would be appreciated.
Thanks :)
Assuming you're able to do something about those awkward points that are slightly inset from the corners (eg, if you numbered the points in English-reading order, with the first being '1', point 6 would be one)...
If a point is interior then if you list all the polygon edges connected to it in clockwise order, each pair of edges in sequence will have a polygon in common. If any two edges don't have a polygon in common then it's an exterior point.
Starting from any exterior point you can then get the whole outline by first walking in any direction and subsequently along any edge that connects to an exterior point you haven't visited yet (or, alternatively, that isn't the edge you walked along just now).
Starting from an existing outline and removing some parts, you can obviously start from either exterior point that used to connect to another but no longer does and just walk from there until you get to the other.
You can't handle this stuff in a shader under ES because you don't get connectivity information.
I think the best you could do in a shader is to expand the geometry by pushing vertices outward along their surface normals. Supposing that your data structure is a list of rectangles, each described by, say, a centre, a width and a height, you could achieve the same thing by drawing each with the same centre but with a small amount added to the width and height.
To be completely general you'd need to store normals at vertices, but also to update them as geometry is removed. So there'd be some pushing of new information from the CPU but it'd be relatively limited.

What is the most efficient way to send my geometry to glsl?

In my scene I have a tree of meshes. Each mesh contains a transformation matrix, a list of vertices, normals, uvs and a list of child meshes.
I would like to send my geometry in an 'array of structures' to glsl using a VBO, but I don't know how to handle updating each mesh's matrix in the event of a parent mesh's matrix transformation. Should I traverse the mesh tree and add a matrix for every vertex every frame? Should I premultiply the vertices each frame? Should I hold a list of matrices in a uniform and reference the current vertex's matrix by index? Should I use one glDrawArrays or glDrawElements for every mesh?
The 'standard' approach would be to use on glDraw call per mesh.
For each mesh, you feed its transform matrix in a single uniform that is applied for the whole mesh. This matrix is then used in the vertex shader to transform the mesh from 'object space' to 'clip space'.
Having multiple matrices for one mesh (or draw call) is generally used for non-rigid transformations on meshes (deformations induced by bones for example).
Another approach, depending on the number of meshes you have to draw, would be to use 'hardware instancing'. Where you can draw a similar mesh multiple times, providing an array of matrices, and let the hardware pick the according matrix given the instanceID being drawn.

Resources