Comments (3)
What are you trying to do with so many spheres? :)
To reduce the runtime you can enable optimization. This is still a work in progress. But it should work in your case. For me it reduced the runtime to about 10-20 seconds.
Here's an example:
import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.FileUtil;
import eu.mihosoft.vrl.v3d.Sphere;
import eu.mihosoft.vrl.v3d.Transform;
import java.io.IOException;
import java.nio.file.Paths;
/**
*
* @author Michael Hoffer <[email protected]>
*/
public class Spheres {
public CSG toCSG() {
double maxR = 10;
double w = 30;
double h = 30;
double d = 30;
// optimization reduces runtime dramatically
CSG.setDefaultOptType(CSG.OptType.POLYGON_BOUND);
CSG spheres = null;
for(int i = 0;i<70;i++) {
CSG s = new Sphere(Math.random()*maxR).toCSG().
transformed(
Transform.unity().
translate(
Math.random()*w,
Math.random()*h,
Math.random()*d));
if (spheres == null) {
spheres = s;
} else {
spheres = spheres.union(s);
}
}
return spheres;
}
public static void main(String[] args) throws IOException {
FileUtil.write(Paths.get("spheres.stl"), new Spheres().toCSG().toStlString());
}
}
from jcsg.
Thanks so much for the quick response, and for the example code! I'm really enjoying using JCSG so far, thank you for creating it.
Your fix worked great, the polygons are much cleaner and the operations are much faster:
A small bug appeared when I changed the OptType, but it's easy to work around for now.
When I tried to subtract a cube from the spheres that wasn't intersecting with the spheres, I got this error:
Exception in thread "main" java.lang.RuntimeException: Please fix me! I don't know what to do?
at eu.mihosoft.vrl.v3d.Node.invert(Node.java:133)
at eu.mihosoft.vrl.v3d.CSG._differenceNoOpt(CSG.java:560)
at eu.mihosoft.vrl.v3d.CSG._differencePolygonBoundsOpt(CSG.java:550)
at eu.mihosoft.vrl.v3d.CSG.difference(CSG.java:517)
at Spheres.toCSG(Spheres.java:50)
at Spheres.main(Spheres.java:56)
I recreated the error by modifying your example code. Replace the Spheres.toCSG with:
public CSG toCSG() {
double maxR = 10;
double w = 30;
double h = 30;
double d = 30;
// optimization reduces runtime dramatically
CSG.setDefaultOptType(CSG.OptType.POLYGON_BOUND);
CSG spheres = null;
for(int i = 0;i<20;i++) {
System.out.println( "s " + i );
CSG s = new Sphere(Math.random()*maxR).toCSG().
transformed(
Transform.unity().
translate(
Math.random()*w - (w/2),
Math.random()*h - (h/2),
Math.random()*d - (d/2)
));
if (spheres == null) {
spheres = s;
} else {
spheres = spheres.union(s);
}
}
CSG box = new Cube( 100, 100, 100 ).toCSG().transformed( Transform.unity().translate( 0, 0, -110 ) );
spheres = spheres.difference( box );
return spheres;
}
Like I said, pretty easy to work around for now. Thanks again!
from jcsg.
Oh, and the reason I'm trying to union so many spheres is for 3D Printing. I was trying to recreate what I did using OpenSCAD:
from jcsg.
Related Issues (20)
- Text3d support HOT 4
- Quantizing vertices? HOT 11
- License HOT 2
- How to make a csg from complicated svg? HOT 6
- WeightedTubeSample example causes StackOverflowError HOT 1
- STL file generated for a simple Polyhedron (L shape) : one face should not be part of the model HOT 3
- CSG class : issue in OBJ file generation : faces are not saved HOT 2
- Calculate Volume of CSG
- parallelstream must not do an addAll to an ArrayList: it causes null entries HOT 1
- Stackoverflow HOT 4
- Union and Difference Coplanar Polygons HOT 4
- How to import OBJ ? HOT 5
- Creating a Polygon HOT 5
- Split in two objects after difference HOT 1
- Multiple uinions cause StackOverflow Error HOT 2
- How to set color to Java JCSG object? [JavaFX] HOT 2
- Bounds intersection not implemented
- Cylinder rotation in Z axis
- Difficulty locating .jar file download
- Why does "difference" keep parts in the CSG that don't "intersect" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jcsg.