Polygons
Polygons
I'm working with polygons to reflect some data in my tool right now, using regularPolygonFactory. The problem I have is that the polygon is only rendered on one side, so the back/underside is all black and unclickable.
Is there an easy way to make a polygon with a surface on both sides?
Also, I would need the polygon to support billboarding. I'm trying to use a rotation listener so when I rotate the scene, it will use the calculateBillboardMatrix() instead of the transform set by rotation, but it doesn't seem to work too well.
Is there an easy way to make a polygon with a surface on both sides?
Also, I would need the polygon to support billboarding. I'm trying to use a rotation listener so when I rotate the scene, it will use the calculateBillboardMatrix() instead of the transform set by rotation, but it doesn't seem to work too well.
Re: Polygons
Can you pls show an example.png about your results and past the code you are using for. Then I'll have a look into it.
Re: Polygons
Here's the polygons in top and bottom view:
Top view
Bottom view
As you can see, the top is colored with a face, but the bottom is just black. Top is also clickable, bottom isn't. It's as if there's no face on the bottom part of the polygon.
I had to remove the rotationListener code and such for a build earlier, but here's how I implement the polygons at least:
Top view
Bottom view
As you can see, the top is colored with a face, but the bottom is just black. Top is also clickable, bottom isn't. It's as if there's no face on the bottom part of the polygon.
I had to remove the rotationListener code and such for a build earlier, but here's how I implement the polygons at least:
Code: Select all
private void setCoordinates(GeoPoint2D wellPickCoordinates) {
double[] vertices = new double[3];
vertices[0] = wellPickCoordinates.getEasting().meters();
vertices[1] = wellPickCoordinates.getNorthing().meters();
vertices[2] = -wellPick.getTrueVerticalDepthSubSurface().meters();
IndexedFaceSetFactory factory = Primitives.regularPolygonFactory(4, 0.0);
MatrixBuilder.euclidean().translate(vertices).scale(200, 200, 200).assignTo(this);
// Some remnants from the billboarding attempt
// SceneGraphPath cameraPath = new SceneGraphPath(getCamera(), this);
// double[] camToWellpick = cameraPath.getMatrix(null);
// getTransformation().setMatrix(LabelUtility.calculateBillboardMatrix(null, 1.0, 1.0, new double[]{0,0,0}, SwingConstants.CENTER, camToWellpick, vertices, Pn.EUCLIDEAN));
setGeometry(factory.getGeometry());
}
Re: Polygons
Sorry, but I cannot reproduce your problem. When I'm building a polygon with the PolygonFactory and displaying the geometry in a viewer I get normal results and both sides of the polygon are displayed normal, see the attached example.png (left frontside, right rearside).
Code: Select all
public class PolygonFactoryExample {
public static void main(String[] args) {
JRViewer.display(Primitives.regularPolygonFactory(4, 0.0).getGeometry());
}
}
- Attachments
-
- polygonexample.png (43.43 KiB) Viewed 1408 times
Re: Polygons
Yeah I do find it a bit weird... Anyways, I convinced the project owner that using cubes works better, so no more billboarding or dualface problems :)
Thanks for your help anyway Andre :)
Thanks for your help anyway Andre :)
Re: Polygons
Hi!
I'm experiencing the same problem as Ronin. I am importing a triangulated surface and trying to display it in our standalone viewer (pretty much followed the guide in http://www3.math.tu-berlin.de/jreality/ ... one_viewer ). I then built the surface with the indexed face set factory.
Every other triangle faces the wrong way - probably caused by them being specified in clockwise and counter-clockwise orders (haven't checked).
Is there a way to explicitly enable / disable back-face culling? My initial guess is that this is related to that - it would also explain Ronin's problems.
I'm experiencing the same problem as Ronin. I am importing a triangulated surface and trying to display it in our standalone viewer (pretty much followed the guide in http://www3.math.tu-berlin.de/jreality/ ... one_viewer ). I then built the surface with the indexed face set factory.
Every other triangle faces the wrong way - probably caused by them being specified in clockwise and counter-clockwise orders (haven't checked).
Is there a way to explicitly enable / disable back-face culling? My initial guess is that this is related to that - it would also explain Ronin's problems.
Code: Select all
public class SurfaceVisualizable extends SceneGraphComponent {
public SurfaceVisualizable(Surface tsurf) {
super("Surface");
IndexedFaceSetFactory factory = new IndexedFaceSetFactory();
factory.setGenerateFaceNormals(true);
factory.setGenerateEdgesFromFaces(true);
factory.setGenerateVertexNormals(true);
factory.setVertexCount(tsurf.vertices.size());
factory.setVertexCoordinates(tsurf.getVertexCoordinates());
factory.setFaceCount(tsurf.triangles.length);
factory.setFaceIndices(tsurf.triangles);
factory.setVertexColors(tsurf.getVertexColors()); // This gets a color for each point, which should give a smoothly gradiented surface.
factory.update();
setGeometry(factory.getGeometry());
}
}
- Attachments
-
- The problem
- screenshot culling.png (62.43 KiB) Viewed 1389 times
Re: Polygons
If SceneGraphComponent sgc lies above your geometry in the scene graph, use the following code to enable back-face culling:
You might also try this static method from IndexedFaceSetUtility to get the normals to be oriented in the same direction:
Code: Select all
Appearance ap = sgc.getAppearance();
ap.setAttribute(CommonAttributes.BACK_FACE_CULLING_ENABLED, true);
Code: Select all
makeConsistentOrientation(IndexedFaceSet ifs);
jReality core developer
P.S.: Re: Polygons
P. S. If you do use the method makeConsistentOrientation(), don't forget to also recalculate the normals using, for example, the static method (also from IndexedFaceSetUtility):
Code: Select all
calculateAndSetFaceNormals(IndexedFaceSet ifs)
jReality core developer
Re: Polygons
Thanks for a quick reply, Gunn. The methods did not help me, as the _makeConsistentOrientation did not change anything (probably returned false, but did not check that). Maybe because of the regularity in the inconsistency (50% of the triangles faced the wrong direction).
I changed the triangulation code instead, so that all polygons now face the same way. Looks beautiful now :-)
Off-topic: Have you considered publishing jReality using maven? That would really make it easier to set up jReality in a new project, including showing sources and javadoc in e.g. Eclipse.
I changed the triangulation code instead, so that all polygons now face the same way. Looks beautiful now :-)
Off-topic: Have you considered publishing jReality using maven? That would really make it easier to set up jReality in a new project, including showing sources and javadoc in e.g. Eclipse.