EzDevInfo.com

csg.js

Constructive solid geometry on meshes using BSP trees in JavaScript

Cross-section in Three.js

Does someone know a method for creating cross-section of a 3D-model in Three.js? I have a BufferGeometry and want the users to decide a plane where the cross-section should be. The BufferGeometry also have vertexcolors I wanna keep during the cross-section. The models have around 500,000 - 4,000,000 faces, and I want the cross-section to be fast. Thanks.


Source: (StackOverflow)

Three.js Mesh or Geometry content

I'm new to Three.js; Is there a way to get separate objects (elements/shells) from a Mesh or Geometry object?

If there's no native way to do that, how could I implement a method for separating faces that are not connected to an ensemble and then detaching them so they form there own Mesh object?

Background: I'm loading a 3d model and would like to be able to unify this model using ThreeBSP, I need to separate the objects before applying the boolean operations.

Thank you


Source: (StackOverflow)

Advertisements

How to convert a MeshView to a CSG object using JCSG library in JavaFX

I'm using the JCSG library for JavaFX.

I have some MeshView objects that I want to convert them into CSG objects, is there a way to achieve this?


Source: (StackOverflow)

Ray casting with CSG tree

I'm working a project in which I have to perform ray casting and use CSG trees. But I don't know how to use the CSG trees or implement it for this project. I can do the ray cast and give the final answer. My problem is really how to implement the tree and link it.


Source: (StackOverflow)

How to remove a section of a CubeGeometry?

At the moment I'm using ThreeCSG/CSG to subtract a small cube from a much larger cube. This works fine, but only the look of it changes not the actual geometry. So when using PhysiJS (Physics engine) on another cube, it doesn't fall into the hole but acts like it normally would. Click for Demo.

Is there any way I can actually remove a section from a CubeGeometry so that objects can fall into it - not just for display purposes? Thanks!


Source: (StackOverflow)

Bezier clipping

I'm trying to find/make an algorithm to compute the intersection (a new filled object) of two arbitrary filled 2D objects. The objects are defined using either lines or cubic beziers and may have holes or self-intersect. I'm aware of several existing algorithms doing the same with polygons, listed here. However, I'd like to support beziers without subdividing them into polygons, and the output should have roughly the same control points as the input in areas where there are no intersections.

This is for an interactive program to do some CSG but the clipping doesn't need to be real-time. I've searched for a while but haven't found good starting points.


Source: (StackOverflow)

Anti-Aliasing issue with MSAA, drawing CSG with depth and FBO

I have reimplemented OpenCSG for modern OpenGL version.

PixelFormatAttributes:

NSOpenGLPFAColorSize    , 24 ,
NSOpenGLPFAAlphaSize    , 8  ,
NSOpenGLPFADepthSize    , 32 ,
NSOpenGLPFAStencilSize  , 8  ,
NSOpenGLPFAAccelerated  ,
NSOpenGLPFADoubleBuffer ,
NSOpenGLPFASupersample  ,
NSOpenGLPFASampleBuffers, 1  ,
NSOpenGLPFASamples      , 4  ,

FBO specs: (tried render to FBO with multisample, but lines getting more strong and visible, look on screenshot at bottom)
- created texture with power of 2, GL_RGBA (tried GL_RGBA8 and GL_RGBA32F)
- GL_DEPTH24_STENCIL8 (tried GL_DEPTH32_STENCIL8, no result)


Simply algorithm Goldfeather:

while (i < depth complexity) {
    take channel for render
       merge layers if no free channel 
    render each layer with stencil func, mask and depth params to channel (FBO)
}
merge layers (taking texture from FBO and render objects again with applying shader below)


In shader I have code for merging (result texture from FBO overlaps on top of rendering for testing, in OpenCSG it's setupProjectiveTexture):

     vec2 ndcPos = gl_FragCoord.xy / sizetexture.xy;
     vec4 maskColor = texture2D(maskTexture, ndcPos.xy);
     if (maskColor[channel] < 0.5) {
        discard;
     }

enter image description here

Looks like after FBO getting not enough clear texture or not right size.

EDIT:
Those lines appears only in overlapping places of subtracting mesh.

EDIT 2:
Fixed with rendering to non MSAA FBO and applying FXAA on result.


Source: (StackOverflow)

Meshing a construcitve solid geometry (CSG)

I have many geometric primitives (100) which cut a cube. This could be modelled using CSG. Now I need a relatively coarse tetra mesh for finite element simulations. For generating the mesh I came across netgen (see the picture). But netgen will give me mesh with 2 million+ elements which can not be handled by the FE program I am using. Are there any reliable programs that could do this job? I already tried to only mesh the surface and coarsen it somehow but without any success.


Source: (StackOverflow)

POVray: How to reliably create nice merges of objects merely touching on the surface?

What I'm doing

I have a scene which algorithmically draws a prism with a hexagonal cross-section and n layers of such prisms surrounding the center one, such that all the prisms together make a larger hexagon shape.

Now, each row of prisms is displaced from the next by a multiple of sqrt(3)/2 (because the dimensions of one prism are <1,sqrt(3)>, because sin(120/2°) = sqrt(3)/2).

I imagine that the float values of the resulting positions in relation to the dimensions of the prisms do not always exactly coincide in a way that produces zero gap between the objects. Hence, I don't get a smooth, uniform shape when I wrap the whole thing up in a merge and assign it a transparent glassy material. Depending on the value of n, I get jittery weirdness at the edges inside the merge object, or shadows of some surfaces, or both.

This is a snippet from the comment block at the beginning of my code which explains the scene in ASCII art:

       __
    __/  \__
 __/  \ 1/  \__
/  \13/  \ 6/  \
\17/  \ 2/  \10/
/  \14/  \ 7/  \      #3 is at <0,0,0>
\18/  \ 3/  \11/
/  \15/  \ 8/  \
\19/  \ 4/  \12/
   \16/  \ 9/
      \ 5/

The entire code is too long to paste here, but it's available here. It is probably also very painful to read, because I am a bad coder and because POVray doesn't have #for loops.

My question(s)

  • How do I account for the unpredictability and imprecision of float values in making merges of mathematically positioned objects which only touch on the surface but do not overlap?
  • Is this even supposed to work the way I want it to in POVray?
  • Am I doing something very stupid here?

Source: (StackOverflow)

Intersection of two section planes

I'm trying to find an algorithm to cut a 3D object using two (or more) section planes. The object should only be cut where both section planes are cutting. So consider the following abcd rectangle that is intersected by two section planes: s0 and s1; s1 cuts towards the right and s0 cuts towards the top. What I would like is to have the resulting ajikcd shape.

.        |s1
. a______j_________b  ^
. |      |         |  |
. |- - - i - - - - |k- - s0
. |      |         |  
. d----------------c
.        |->

This is a quite simplistic example but I hope it will make it clear what I'm trying to accomplish. In addition, this should be done in 3D.

Does anybody know of any library that does that, or an algorithm to do it? This seems like an non-trivial problem that someone must have solved before me! :)

I must add that I know how to do the basics (intersection of plane with face/plane/edge). What I can't see is whether there is a smart way to solve all possible cases (in this one, two faces must be added, but in some other only one face might be created, etc.), or if you should handle them separately.

Another thing I should add is that I'm not concerned about the rendering part, I know how to do it with OpenGL with clipping planes. What I want is to be able to compute the new topology of the object.


Source: (StackOverflow)

Carve CSG Library

Has anyone successfully compiled and used the Carve CSG library? I'm trying to use it in a project and I haven't been able to get it to work. Also, the documentation is pretty terrible. I've been looking at the Blender source and it appears to use Carve successfully, but I've been having trouble replicating it.

Here's the code I've been attempting to use, just to create a cube to use with Carve:

std::vector<carve::geom3d::Vector> vertices;

vertices.push_back(carve::geom::VECTOR(+1.0, +1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, +1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, -1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(+1.0, -1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(+1.0, +1.0, -1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, +1.0, -1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, -1.0, -1.0));
vertices.push_back(carve::geom::VECTOR(+1.0, -1.0, -1.0));

std::vector<int> f;
int numfaces = 6;

f.push_back(4);
f.push_back(0);
f.push_back(1);
f.push_back(2);
f.push_back(3);

f.push_back(4);
f.push_back(7);
f.push_back(6);
f.push_back(5);
f.push_back(4);

f.push_back(4);
f.push_back(0);
f.push_back(4);
f.push_back(5);
f.push_back(1);

f.push_back(4);
f.push_back(1);
f.push_back(5);
f.push_back(6);
f.push_back(2);

f.push_back(4);
f.push_back(2);
f.push_back(6);
f.push_back(7);
f.push_back(3);

f.push_back(4);
f.push_back(3);
f.push_back(7);
f.push_back(4);
f.push_back(0);

carve::mesh::MeshSet<3> *poly = new carve::mesh::MeshSet<3> (vertices, numfaces, f);

It seems to be getting stuck on the last line, falling into a long-running loop, then seg-faulting.


Source: (StackOverflow)

Construct 3D geometry with PHP?

I need to construct 3D models for use with Three.js, but I need to do CSG (Constructive Solid Geometry) operations on them too. I managed to use the ThreeCSG.js library for this, but I find this to be quite slow (about 5 seconds to slice about 30 holes from a complex shape).

Somehow I need to cache the geometry that is constructed, but since the construction of 3D geometry now happens only on the client side in the browser (with Javascript) I have no way of doing this on the server, which uses PHP.

  • Are there any 3D libraries in PHP (that can do CSG as well) ?
  • What's the best way to pre-calculate 3D models for later use in Three.js ?

Source: (StackOverflow)

Three.js CSG library causes uncaught TypeError

I've started creating nice 3d objects with Three.js. Now I'm trying to do a subtract as in the given example at: https://github.com/stemkoski/stemkoski.github.com/blob/master/Three.js/CSG.html But I'm getting an error in the library:

Uncaught TypeError: undefined is not a function ThreeCSG.js:215
window.ThreeBSP.ThreeBSP.toMesh                 ThreeCSG.js:215

What I'm trying to achieve is a quarter of a circle that a smaller circle is subtracted from it (so as to create the form of a bow).

Here's the plunkr. http://plnkr.co/edit/lUxq0Oh1aXbRVd4c2rKG?p=preview

Any idea why the error is caused?


Source: (StackOverflow)

ThreeCSG.js minimal example

I am trying to learn ThreeCSG.js, the javascript Constructive Solid Geometry front-end to Three.js. I thought I would start by copying a minimal example from the web. I tried to save a local copy of Chandler Prall's amazing little javascript Constructive Solid Geometry example using ThreeCSG.js from the site

https://stemkoski.github.io/Three.js/CSG.html

When I made a local copy of the page (using Chrome's Save as webpage, complete command), I found that the checkerboard texture file was missing. I got the following javascript console error:

Failed to load resource: net::ERR_FILE_NOT_FOUND

with the full path name of the (missing) jpg file. When I manually downloaded the jpg file and put it where Chrome was looking for the jpg file, I got a different error:

The cross-origin image at file:///C:/tmp/images/checkerboard.jpg may not be loaded.

My browser is Chrome 43.0.2357.134, Windows 7 64. I ran into similar problems with IE. Thinking it might be a bug/feature of three.js, I tried the most recent version of three.min.js, but got syntax errors. (The example uses an older version of threecsg.js, and the API has changed.)

What am I doing wrong?


Source: (StackOverflow)

Subtracting Geometry in Three.js (or really, 3D programming in general)

I'm currently working on a small project with which I need to subtract a rectangular area of a cube on mousemove (think, an indented area for placing a door on a house). The 'door' would be 'placed' on click, but would need to be 'visualized' while the user is deciding its location; in reality, nothing changes except the fact that the user is no longer moving it around.

The issue here is finding an efficient way of allowing a user to move the door around, while it interacts and modifies the house mesh. I've been toying with CSG for Three.js, but I'm thinking that there might be a better algorithm for my use case. I feel it would be really costly to remove the cube from the scene, convert it to a CSG mesh, subtract, then convert back to a mesh and add it back into the scene on every frame until the user decides its location.

Is CSG the wrong approach here? Should I modify the vertices directly? If so, how would I go about calculating/adding the vertices needed to create an 'indention' in the square? Really, I'm looking for what game and 3D application programmers consider best practice for handling a case like this. How does an application like SketchUp handle things like pushing/pulling geometry?

Thanks.


Source: (StackOverflow)