Posted by
tamb20 on
Oct 21, 2015; 4:04am
URL: https://forum.jogamp.org/Issue-with-shading-the-cubic-tp4035539.html
Hi
Is there any class to shade 3D object.
The method I used is
public BranchGroup shading() {
BranchGroup shadeGroup = new BranchGroup();
shadeGroup.setCapability(BranchGroup.ALLOW_DETACH);
TransformGroup transGroup = new TransformGroup();
transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
shadeGroup.addChild(transGroup);
BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0), 100);
Color3f white = new Color3f(0.15f, 0.15f, 0.15f);
// Set up the ambient light
AmbientLight ambientLightNode = new AmbientLight(white);
ambientLightNode.setInfluencingBounds(bounds);
shadeGroup.addChild(ambientLightNode);
// Set up the directional lights
Vector3f light1Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
Vector3f light2Direction = new Vector3f(1.0f, -1.0f, -1.0f);
Vector3f light3Direction = new Vector3f(1.0f, 1.0f, 1.0f);
Vector3f light4Direction = new Vector3f(-1.0f, 1.0f, 1.0f);
Color3f light1color = new Color3f(0.5f, 0.5f, 0.5f);
Color3f light2color = new Color3f(0.3f, 0.3f, 0.3f);
Color3f light3color = new Color3f(0.3f, 0.3f, 0.3f);
Color3f light4color = new Color3f(0.3f, 0.3f, 0.3f);
DirectionalLight light1 = new DirectionalLight(light1color,
light1Direction);
light1.setInfluencingBounds(bounds);
shadeGroup.addChild(light1);
DirectionalLight light2 = new DirectionalLight(light2color,
light2Direction);
light2.setInfluencingBounds(bounds);
shadeGroup.addChild(light2);
DirectionalLight light3 = new DirectionalLight(light3color,
light3Direction);
light3.setInfluencingBounds(bounds);
shadeGroup.addChild(light3);
DirectionalLight light4 = new DirectionalLight(light4color,
light4Direction);
light4.setInfluencingBounds(bounds);
shadeGroup.addChild(light4);
System.out.println("\r\n-----Shading-----");
for (STL_TriInfo triInfo : triangleMap.getMap().values()) {
LinkedList<Integer> tri_ptids = triInfo.getPointIds();
double[][] points = new double[4][3];
double[][] normals = new double[4][3];
for (int i = 0; i < tri_ptids.size(); i++) {
Integer pt_ids = (Integer) tri_ptids.get(i);
normals[i] = pointMap.pt_normal(triangleMap, pt_ids);
MathTools.normalize(normals[i]);
STL_PointInfo ptinf = pointMap.getPointInfo(pt_ids);
points[i] = ptinf.getCurPos();
}
VSTriangle vstri = new VSTriangle(points, normals);
vstri.setCapability(Node.ENABLE_PICK_REPORTING);
PickTool.setCapabilities(vstri, PickTool.INTERSECT_FULL);
transGroup.addChild(vstri);
}
shadeGroup.compile();
return shadeGroup;
}
After I shade it it appears there are some issue with it and not shade properly. How I can solve it?