01: /*
02: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/SceneGraphChecker.java,v 1.1 2005/04/20 21:04:21 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is Java 3D(tm) Fly Through.
11: * The Initial Developer of the Original Code is Paul Byrne.
12: * Portions created by Paul Byrne are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Paul Byrne.
16: *
17: **/
18: package org.jdesktop.j3dfly;
19:
20: import javax.media.j3d.Node;
21: import javax.media.j3d.Appearance;
22: import javax.media.j3d.Material;
23: import javax.media.j3d.Shape3D;
24: import org.jdesktop.j3d.utils.scenegraph.traverser.NodeChangeProcessor;
25: import org.jdesktop.j3d.utils.scenegraph.traverser.TreeScan;
26:
27: /**
28: * @author Paul Byrne
29: * @version $Revision: 1.1 $
30: */
31: public class SceneGraphChecker extends Object {
32:
33: private boolean hasLights;
34: private boolean needsLights;
35:
36: /** Creates new SceneGraphChecker */
37: public SceneGraphChecker() {
38: }
39:
40: /**
41: * Checks if the graph contains any geometry that requires lighting and if
42: * the graph contains any Light nodes
43: *
44: * If there is geometry expecting lights and there are no lights then return
45: * true, else return false;
46: */
47: public synchronized boolean needsLights(
48: javax.media.j3d.BranchGroup bg) {
49: NodeChangeProcessor gotLight = new NodeChangeProcessor() {
50: public boolean changeNode(Node node) {
51: if (node instanceof javax.media.j3d.Light)
52: hasLights = true;
53:
54: if (node instanceof javax.media.j3d.Shape3D) {
55: Appearance app = ((Shape3D) node).getAppearance();
56: if (app != null) {
57: Material mat = app.getMaterial();
58: if (mat != null && mat.getLightingEnable()) {
59: needsLights = true;
60: }
61: }
62: }
63: return true;
64: }
65: };
66:
67: hasLights = false;
68: needsLights = false;
69:
70: TreeScan.findNode(bg, new Class[] {
71: javax.media.j3d.Light.class,
72: javax.media.j3d.Shape3D.class }, gotLight, false, true);
73:
74: return !hasLights & needsLights;
75: }
76:
77: public boolean getHasLights() {
78: return hasLights;
79: }
80:
81: }
|