01: /*
02: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/SceneGraphChecker.java,v 1.1 2005/04/20 22:20:48 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 the Java 3D(tm) Scene Graph Editor.
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.j3dedit.scenegrapheditor;
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: public class SceneGraphChecker extends Object {
28:
29: private boolean hasLights;
30: private boolean needsLights;
31:
32: /** Creates new SceneGraphChecker */
33: public SceneGraphChecker() {
34: }
35:
36: /**
37: * Checks if the graph contains any geometry that requires lighting and if
38: * the graph contains any Light nodes
39: *
40: * If there is geometry expecting lights and there are no lights then return
41: * true, else return false;
42: */
43: public synchronized boolean needsLights(
44: javax.media.j3d.BranchGroup bg) {
45: NodeChangeProcessor gotLight = new NodeChangeProcessor() {
46: public boolean changeNode(Node node) {
47: if (node instanceof javax.media.j3d.Light)
48: hasLights = true;
49:
50: if (node instanceof javax.media.j3d.Shape3D) {
51: Appearance app = ((Shape3D) node).getAppearance();
52: if (app != null) {
53: Material mat = app.getMaterial();
54: if (mat != null && mat.getLightingEnable()) {
55: needsLights = true;
56: }
57: }
58: }
59: return true;
60: }
61: };
62:
63: hasLights = false;
64: needsLights = false;
65:
66: TreeScan.findNode(bg, new Class[] {
67: javax.media.j3d.Light.class,
68: javax.media.j3d.Shape3D.class }, gotLight, false, true);
69:
70: return !hasLights & needsLights;
71: }
72:
73: }
|