Hi. First of all thanks a lot for your great work. I've used FabianCSG, and it works well, but it's kind of slow, and I need to use it in an animation, so I thought I'd give your version a try. Now, I've made a new project, and copied the source files and assets into the project, but it's giving me loads of errors. I've attached 2 screenshots of my project structures and examples of the errors I'm getting. Thanks in advance.
Regards,
Wazir
As I mentioned on the CSG website, I do all my development and testing using the Eclipse IDE and do not use the jMonkey IDE. I am guessing you are hitting configuration differences between the two different tools, especially in regards to the active version of jMonkey source code I am using, and dependencies of my CSG code on Java 1.8.
I will try some experiments with the jMonkey IDE and will post back to this thread again if I find anything.
FYI -- the CSG code is rather compute and resource intensive. My code may be a tad more efficient than the original Fabian code, but the inherent nature of the beast may make CSG processing unsuitable for dynamic, animation processing.
Thanks for your interest.
Yes I realized that and now I'm decimating my models to lower polygon count
as much as I can without losing shape, and after that even fabianCSG runs
much better, but more efficient code is still welcome.
Last edit: justry 2015-08-05
I Forgot to mention that I updated my JDK to 8 in an attempt to get it to
work, but after updating I still got the same errors.
Any developments so far?
Due to my inexperience with the jMonkey IDE, I have no idea why/where the errors are coming from.
So I have created a .jar file with all the required class files and posted it to the "Files" section of this SourceForge project.
My simple test of including the jar in the Libraries section of my jMonkey IDE project worked just fine. I hope it also works for you. Basically -- punt the source and just use the .jar
Let me know how things are going for you. I am very curious to learn if you get any performance improvements by using this code.
Ok, so I've added the jar and JME3 shows no errors. However once I run the program, I get the following stack trace:
java.lang.UnsupportedClassVersionError: net/wcomohundro/jme3/csg/CSGGeometry : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Exception in thread "main" Java Result: 1
The code and jar are still reliant on java 1.8. If I run my jMonkey IDE project with the default 1.7, I get the exact same error. (as much as I like Java, it has always been rather deficient when reporting exactly what is going wrong when there is a class loading problem.)
I changed the jdk settings in the "Libraries" section of Project : Properties to use java 1.8 and my test case ran without errors. Let me know.
Ok, it runs but then gives me a null pointer exception at "regenerate()". I'm posting the stack trace and my code below, but first I have a question which might help shed some light: what happens if I'm intersecting two meshes that don't initially intersect? because when the program first runs, the two objects are not in collision, but collide as the program proceeds.
Here is the stack trace:
java.lang.NullPointerException
at net.wcomohundro.jme3.csg.CSGShape.fromMesh(CSGShape.java:415)
at net.wcomohundro.jme3.csg.CSGShape.getPolygons(CSGShape.java:255)
at net.wcomohundro.jme3.csg.CSGShape.intersection(CSGShape.java:352)
at net.wcomohundro.jme3.csg.CSGGeometry.regenerate(CSGGeometry.java:208)
at mygame.Main.simpleUpdate(Main.java:239) (the regenerate() line)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:745)
Here is my code:
rootNode.detachChild(aGeometry);
aGeometry = new CSGGeometry();
ArrayList<geometry> g = new ArrayList<geometry>();
GeometryBatchFactory.gatherGeoms(heart, g);
Mesh m = new Mesh();
GeometryBatchFactory.mergeGeometries(g, m);
CSGShape aSphere = new CSGShape( "heart", m );
aGeometry.addShape( aSphere, CSGGeometry.CSGOperator.UNION );
ArrayList<geometry> g2 = new ArrayList<geometry>();
GeometryBatchFactory.gatherGeoms(view, g2);
Mesh m2 = new Mesh();
GeometryBatchFactory.mergeGeometries(g2, m2);
CSGShape aCube = new CSGShape( "view", m2 );
aGeometry.addShape( aCube, CSGGeometry.CSGOperator.INTERSECTION );
aGeometry.regenerate();
aGeometry.rotate(probe.getLocalRotation().inverse());
aGeometry.setLocalTranslation(0f,0f,9f);
rootNode.attachChild(aGeometry);</geometry></geometry></geometry></geometry>
1) The NULL pointer is occurring where CSG is trying to pull Texture Coordinate info out of the TexCoord buffer of the mesh. CSG assumes that any mesh given is based on a simple list of triangles with each triangle vertex providing a Position, a Normal, and a Texture Coordinate. The failure point seems to imply the current mesh has no TexCoord buffer. Is that possible?
NOTE that CSG operates on a clone of the original shape. There is a comment in Geometry.clone() that the mesh is handled specially if it is marked as being a software animated mesh (something about BindPosePosition, which means nothing to me) Any chance something like this could be impacting the processing?
2) Union, Intersection, and Difference between non-overlapping shapes work as expected. A Union gives you two disconnected pieces, the Intersection is an empty shape (zero polygons), and the Difference is just the first shape unchanged.
3) I have never tried putting CSG processing directly into the Update loop itself. That should drive your framerate into the dirt. I will be curious to hear what kind of performance you end up with.
Interesting. I actually had a similar error with FabianCSG, although in that case the error message was much plainer, and I easily followed the error tree up to the offending line, which was the exact same method you mentioned. I don't know why this happens, but it seems to be something wrong I'm doing in Blender. I used the default material initially, but after the error message I assigned a material, and made sure to check the "export materials" and "export UVs" options when exporting to obj, but it still gave me the error: a nullPointerException when attempting to locate the UV vector coordinates of vertices. I imported the mesh into Sketchup and re-exported as obj, and it worked! I eventually had to alter the FabianCSG code and set at the UV vectors to the default 0,0,0 in order to get the code to work with Blender-exported obj files, since I don't need materials anyway. I still don't know the cause of the original problem however.
I'm out of town today, but tomorrow I'll try running my new mesh through Sketchup like before and see if that fixes this problem too.
Since my code is a rework/reimplementation of the Fabian code, it is no surprise that you could encounter similar errors.
You are obviously much more conversant with the various 3D construction tools than I am. I am basically a Java coder trying to leverage CSG to build up visually complex models from simple, programmetric elements, rather than using 3D construction tools to hand-build models.
Excuse my 3D ignorance, but is there a reasonable default UV value for a missing TextureCoordinate? I thought the UV mapping was an integral part of any 3D model and that the model was not useful without the UV values.
If a 0,0 default value is meaningful, I can certainly upgrade the "fromMesh" processing to supply it if the underlying mesh has no UV data. Let me know.
Well, it depends on what you mean by "meaningful". It's not supposed to be meaningful. You might as well use any other value, and you would still get the same result as long as your mesh does not have a UV texture applied. UV mapping is essentially a way to map a 2d graphic such as an image, onto a 3d object, where U and V are used in lieu of the X and Y coordinates when wrapped around the 3d object. This means for example that you can paint over a 3d object using a brush, and when you export your 3d object, the paint is saved as a regular image (usually jpg), and the end program (in this case jMonkey) loads this image, and wraps it around the mesh as dictated by the UV coordinates.
If you're using a plain, solid material such as white for example, UV coordinates mean nothing to you, because the model is just white all over, so you can basically use any vector value. I used 0,0,0 just to be able to call the method without leaving out a parameter. I could have used 1,1,1 or 3,1,6 with similar results. You could catch the nullPointerException when trying to get the UV coordinates from a mesh without UV material, and set them to whatever fixed value you want.
I have rebuilt the .jar to include an enhancement that accounts for a NULL TexCoord buffer in a mesh, and supplies a default 0,0 UV value as needed. I don't have a test case for this, all I could do was desk-check the code. Let me know if it works.
"fromMesh" should now be a bit more vocal about any mesh it does not like.
Also - check out Ticket 2 about an on-going visual problem I am dealing with.
If you finally get things going, I would appreciate any suggestions about how to speed things up.
Ok, I tried the new build, and it gives me this error:
java.lang.IllegalArgumentException: Mesh lacking Type.TexCoord buffer
at net.wcomohundro.jme3.csg.CSGShape.fromMesh(CSGShape.java:418)
at net.wcomohundro.jme3.csg.CSGShape.getPolygons(CSGShape.java:257)
at net.wcomohundro.jme3.csg.CSGShape.intersection(CSGShape.java:357)
at net.wcomohundro.jme3.csg.CSGGeometry.regenerate(CSGGeometry.java:229)
at mygame.csg.simpleUpdate(csg.java:240)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:745)
I tried exporting my mesh through sketchup, and it runs, albeit very slow, and no CSG geometry is displayed, and keeps giving lots of messages like this:
Aug 14, 2015 10:10:56 PM net.wcomohundro.jme3.csg.CSGVertex <init>
SEVERE: Bogus Normal: (0.0, -0.60621744, -0.35), 0.6999997</init>
Try the 14082015 rebuild I just posted.
I fixed the problem with the missing TexCoord buffer (I hope) and should have eliminated the Bogus Normal messages you are getting.
I also switched off the structural debug checking by default (which might speed things up a tiny bit)
Ok now it runs blender exported meshes, but still gives me bogus normals, and no resultant CSG geometry is displayed.
Very odd - the Aug14 build was supposed to have turned the 'normal' check off altogether.
Could you attach your mesh to this thread so that I could run my own simple test against it?
Sure. These are the two meshes I'm trying to intersect, along with the material for one of them. The other one's material is created programmatically in jme3.
I've actually come up with a workaround that lets me achieve the effect I need without needing to use CSG at all, by using shaders and frustum culling, but I still want to get to the bottom of this too.
Last edit: justry 2015-08-18
That helped tremendously. Your 'view' mesh exposed a critical mis-understanding on my part of how the 'normalDot' value within CSGPlane is supposed to work. This has been fixed with the latest build
WCOmoCSG-b18082015-j18.jar
I created a simple harness to run your test. While nothing moves, it does produce an 'intersection' that seems to be what one would expect from the two given objects.
I don't understand, it still gives me bogus errors, although the message's changed a bit now:
WARNING: Bogus COPLANAR polygon[42] net.wcomohundro.jme3.csg.CSGPolygon@3e87b7 - 3(net.wcomohundro.jme3.csg.CSGPlane@fb4c48 - (-0.0, 0.0, 0.0)(0.0))
Sorry for taking so long to post back, things have been hectic at work these past few days.
I get something similar with my test using your meshes, but it does not seem to affect the final rendering.
I am working to eliminate undesirable 'artifacts' from the CSG generation process, so there are a lot of internal checks looking for polygons/triangles that are not what I would expect. This is such a case, and the polygon in question will be excluded from subsequent processing. That is why the message posts as a WARNING, not an ERROR. Again -- the final rendering should still take place.
Are you getting any reasonable output?
Since I have seen nothing posted here for a while, I am assuming you have abandoned this CSG code as an approach for your problem. Good luck with what ever you have decided to use.
FYI - the newest jar is Java 1.7 compliant and fits better into the jMonkey SDK. Also, I have implemented a new processing algorithm that eliminates the 'artifact' problem.
Oh, I'm terribly sorry. Yes in fact I've done away with CSG altogether, not just your code, and finished and even released my program. I'm still willing to help you test your code however because I think people like you make the world a better place and ask for nothing in return. It's just that I've been so busy that the whole issue kind of slipped my mind. I'll download the latest jar once I get off from work and get back to you with the results.
Sorry again!
Ok, I tried the new jar, and I get this error when I try to run the program:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NoClassDefFoundError: com/jme3/scene/plugins/blender/math/Vector3d
at net.wcomohundro.jme3.csg.CSGTempVars.<init>(CSGTempVars.java:75)
at net.wcomohundro.jme3.csg.CSGTempVars.get(CSGTempVars.java:59)
at net.wcomohundro.jme3.csg.CSGGeometry.regenerate(CSGGeometry.java:195)
at net.wcomohundro.jme3.csg.CSGGeometry.regenerate(CSGGeometry.java:184)
at VirtualEcho.csg.simpleUpdate(csg.java:230)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.jme3.scene.plugins.blender.math.Vector3d
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more</init>
Also remember the errors I used to get in my original post? They're back when I open any of the source files.