Smoothed models from an STL file
Smoothed models from an STL file
Hello all, I'm using jReality's oh-so-handy STL importer to load some meshes that I exported from Sketchup. They load just fine, but they're very rough. I think the point normals are screwed up or something (I'm not a graphics expert, please forgive me if I'm butchering the lingo), it looks just like rounded surfaces do when you turn off smoothShading in the polygon shader.
Do you happen to know how to fix this? Is there a smoother I can run on the component once it's loaded in from the STL?
Do you happen to know how to fix this? Is there a smoother I can run on the component once it's loaded in from the STL?
Re: Smoothed models from an STL file
can you pls post some of the images you get and if possible even add or e-mail an example STL-File. With this info and data we should be able to fix your problems.
Re: Smoothed models from an STL file
Here's the problem https://www.dropbox.com/s/w40h2zuhnfso0oo/roughFace.png,
and https://www.dropbox.com/s/d080xo4uuei6xfz/face.stl for an example STL.
and https://www.dropbox.com/s/d080xo4uuei6xfz/face.stl for an example STL.
Re: Smoothed models from an STL file
I just checked your face.stl
It looks like that some of the normals are screwed up. I'll show you some screenshots:
There is one big normal failure at the upper right side of your face and some smaller at the "grid" directly in the front of the face.
I look if I can find/create some simple .stl files to check our stl-importer
It looks like that some of the normals are screwed up. I'll show you some screenshots:
There is one big normal failure at the upper right side of your face and some smaller at the "grid" directly in the front of the face.
I look if I can find/create some simple .stl files to check our stl-importer
- Attachments
-
- Face with backface culling
- face_with_backfaceculling.png (141.11 KiB) Viewed 2194 times
-
- Face without backface culling
- face_without_backfaceculling.png (141.77 KiB) Viewed 2194 times
Re: Smoothed models from an STL file
I've checked the stl-reader-class. It seems to be ok. That means that your data is probably screwed up, when you convert it to stl.
Have you tried to convert it in an other format? obj/vrml etc.
best
andre
Have you tried to convert it in an other format? obj/vrml etc.
best
andre
Re: Smoothed models from an STL file
Huh, I hadn't even noticed that problem, but that's not really the problem I'm trying to solve at the moment. Here are screenshots to match yours, note how much more visible the polygons are for me, that's what I'm trying to solve.
FWIW I found that sketchup has a smooth operation that seems to do what I want (in sketchup), but when I export as STL and reimport it the smoothing is lost. I was going to suggest that perhaps the STL format doesn't support smoothed geometry, but for some reason your screenshots don't have the same problem.
I can try other formats, but it wouldn't surprise me if they're wrong too, I have more faith in the exporters than I do with the source model I got from the manufacturer.
FWIW I found that sketchup has a smooth operation that seems to do what I want (in sketchup), but when I export as STL and reimport it the smoothing is lost. I was going to suggest that perhaps the STL format doesn't support smoothed geometry, but for some reason your screenshots don't have the same problem.
I can try other formats, but it wouldn't surprise me if they're wrong too, I have more faith in the exporters than I do with the source model I got from the manufacturer.
- Attachments
-
- faceCulling.jpg (37.94 KiB) Viewed 2192 times
-
- faceNoCulling.jpg (37.83 KiB) Viewed 2192 times
Re: Smoothed models from an STL file
Have you already tried "flat shading" for the surface?
which jRealityviewer do you use?
In general you can enable flat shading with: "Window" -> "Left Slot" -> left click on "Faces" -> toggle "Flat Shading"
which jRealityviewer do you use?
In general you can enable flat shading with: "Window" -> "Left Slot" -> left click on "Faces" -> toggle "Flat Shading"
Re: Smoothed models from an STL file
No, I haven't tried that, "Window" -> "Left Slot" just shows a ~8px wide gray bar on the side with no controls in it of any sort. That's all I've ever seen it do, I just assumed it was something I could populate later if I saw fit. Is there another way to turn on flat shading?
I use JRViewer.display(rootNode);
I use JRViewer.display(rootNode);
Re: Smoothed models from an STL file
Try
Instead of "JRViewer.display(rootNode); "
And than again window->leftslot
Code: Select all
JRViewer v = new JRViewer();
v.addBasicUI();
v.setContent(rootnode);
v.registerPlugin(new ContentAppearance());
v.registerPlugin(new ContentLoader());
v.registerPlugin(new ContentTools());
v.startup();
And than again window->leftslot
Re: Smoothed models from an STL file
Alright, the left side panel is now useful, thanks! Unfortunately the flat shading setting there seems to do exactly the same thing as the smooth shading option in the node's Appearance; it changes whether or not the round primitives are smooth, but it does nothing to the STL shapes.
Re: Smoothed models from an STL file
FYI, I also tried loading the face.stl into JRViewer using "File->Load Content..." and got the "smooth-shading" effect shown in Andre's screenshots, including the blemishes. I can toggle to flat shading using the Appearance inspector in the Navigator window. So, it seems like the question to ask is why don't you get the same effect when you load this file.
Usually, not being able to do smooth shading means that the vertex normals are missing. They can be calculated using de.jreality.geometry.IndexedFaceSetUtility.calculateAndSetVertexNormals(IndexedFaceSet ifs), but it would be good to if, and if so, why, they are missing.
Usually, not being able to do smooth shading means that the vertex normals are missing. They can be calculated using de.jreality.geometry.IndexedFaceSetUtility.calculateAndSetVertexNormals(IndexedFaceSet ifs), but it would be good to if, and if so, why, they are missing.
jReality core developer
Re: Smoothed models from an STL file
Hmmm, I'm not sure how to use that... am I loading the model wrong?
SceneGraphComponent temp = Readers.read(new File(stlFilename));
SceneGraphComponent temp = Readers.read(new File(stlFilename));
Re: Smoothed models from an STL file
Hah, now I got it.
You are using software rendering! I switched from jogl to software-rendering and got the same results. Looks like flat-shading for softwarerendering is broken...
Which OS (Linux 32bit/64bit, windows, mac etc. ) do you use?
How do you handle jReality (eclipseproject or jars)
best
andre
You are using software rendering! I switched from jogl to software-rendering and got the same results. Looks like flat-shading for softwarerendering is broken...
Which OS (Linux 32bit/64bit, windows, mac etc. ) do you use?
How do you handle jReality (eclipseproject or jars)
best
andre
Re: Smoothed models from an STL file
The following code is executed in de.jreality.plugin.content.ContentLoader, when you load files from JRViewer menu. You can see that it creates the face and vertex normals if they are not present.
Since you are reading the file in directly, but the data file has face normals provided, you'll need to calculate the vertex normals yourself. You can do this with the following code:
after you read the file in.
Code: Select all
SceneGraphComponent read = Readers.read(Input.getInput(file));
SceneGraphComponent tempRoot = new SceneGraphComponent();
tempRoot.addChild(read);
tempRoot.accept(new SceneGraphVisitor() {
@Override
public void visit(SceneGraphComponent c) {
if (removeAppsCheckBox.isSelected() && c.getAppearance() != null) c.setAppearance(null);
c.childrenWriteAccept(this, false, false, false, false, true,
true);
}
@Override
public void visit(IndexedFaceSet i) {
if (i.getFaceAttributes(Attribute.NORMALS) == null) IndexedFaceSetUtility.calculateAndSetFaceNormals(i);
if (i.getVertexAttributes(Attribute.NORMALS) == null) IndexedFaceSetUtility.calculateAndSetVertexNormals(i);
if (smoothNormalsCheckBox.isSelected()) IndexedFaceSetUtility.assignSmoothVertexNormals(i, -1);
}
});
Code: Select all
SceneGraphComponent read = Readers.read(Input.getInput(file));
de.jreality.geometry.IndexedFaceSetUtility.calculateVertexNormals(read);
jReality core developer
Re: Smoothed models from an STL file
@Gunn Thanks! That was exactly the issue, your fix worked! And yeah, now that the faces are being smoothed that error on the upper right side is a lot more apparent.
Thanks everyone for your help!
Thanks everyone for your help!