I would like to apply a nice shading to my surfaces and so I activated SMOOTH_SHADING. But it works not with my "IndexedFaceSetFactory", only with the "IndexedFaceSet" of Primitives.sphere(). Why doesn't work SMOOTH_SHADING with my own geometry?
The appended source code shows the problem.
Many thanks and best regards, Joe
Code: Select all
import javax.swing.JFrame;
import de.jreality.geometry.IndexedFaceSetFactory;
import de.jreality.geometry.Primitives;
import de.jreality.scene.Appearance;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.shader.CommonAttributes;
import de.jreality.ui.viewerapp.ViewerApp;
public class Test {
public static void main(String[] arguments){
double[][] verticesArray = new double[][]{
{-1.5, -1.0, -1.0}, {-1.0, -1.0, 0.0}, {0.0, -1.0, 0.5}, { 1.0, -1.0, 0.0}, { 1.5, -1.0, -1.0},
{ 1.5, 1.0, -1.0}, { 1.0, 1.0, 0.0}, {0.0, 1.0, 0.5}, {-1.0, 1.0, 0.0}, {-1.5, 1.0, -1.0}};
int[][] faceIndicesArray = new int[][]{{0, 1, 8, 9}, {1, 2, 7, 8}, {2, 3, 6, 7}, {3, 4, 5, 6}};
IndexedFaceSetFactory indexedFaceSetFactory = new IndexedFaceSetFactory();
indexedFaceSetFactory.setVertexCount(verticesArray.length);
indexedFaceSetFactory.setVertexCoordinates(verticesArray);
indexedFaceSetFactory.setFaceCount(faceIndicesArray.length);
indexedFaceSetFactory.setFaceIndices(faceIndicesArray);
indexedFaceSetFactory.setGenerateFaceNormals(true);
indexedFaceSetFactory.update();
SceneGraphComponent sceneGraphComponent = new SceneGraphComponent();
sceneGraphComponent.setGeometry(indexedFaceSetFactory.getGeometry());
//sceneGraphComponent.setGeometry(Primitives.sphere(5));
Appearance appearance = new Appearance();
appearance.setAttribute(CommonAttributes.VERTEX_DRAW, false);
appearance.setAttribute(CommonAttributes.EDGE_DRAW, false);
appearance.setAttribute(CommonAttributes.TUBES_DRAW, false);
appearance.setAttribute(CommonAttributes.FACE_DRAW, true);
appearance.setAttribute(CommonAttributes.LIGHTING_ENABLED, true);
appearance.setAttribute(CommonAttributes.POLYGON_SHADER + "." + CommonAttributes.SMOOTH_SHADING, true);
sceneGraphComponent.setAppearance(appearance);
ViewerApp viewerApp = new ViewerApp(sceneGraphComponent);
JFrame frame = new JFrame();
frame.getContentPane().add(viewerApp.getViewingComponent());
frame.setSize(512, 512);
frame.validate();
frame.setVisible(true);
}
}