001: /*
002: * $RCSfile: Shape.java,v $
003: *
004: * @(#)Shape.java 1.45 99/03/11 14:58:12
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:07:02 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043: import javax.media.j3d.BoundingBox;
044: import javax.media.j3d.Shape3D;
045:
046: /** Description of the Class */
047: public class Shape extends NonSharedNode {
048:
049: //exposedField
050: SFNode appearance;
051: SFNode geometry;
052:
053: int numTris = 0;
054: boolean ifsChangeable = false;
055:
056: /**
057: *Constructor for the Shape object
058: *
059: *@param loader Description of the Parameter
060: */
061: public Shape(Loader loader) {
062: super (loader);
063: appearance = new SFNode(null);
064: geometry = new SFNode(null);
065:
066: initFields();
067: }
068:
069: /**
070: *Constructor for the Shape object
071: *
072: *@param loader Description of the Parameter
073: *@param appearancenode Description of the Parameter
074: *@param geonode Description of the Parameter
075: */
076: public Shape(Loader loader, SFNode appearancenode, SFNode geonode) {
077: super (loader);
078: appearance = appearancenode;
079: geometry = geonode;
080:
081: initFields();
082: }
083:
084: /** Description of the Method */
085: void initFields() {
086: appearance.init(this , FieldSpec, Field.EXPOSED_FIELD,
087: "appearance");
088: geometry.init(this , FieldSpec, Field.EXPOSED_FIELD, "geometry");
089: }
090:
091: /** Description of the Method */
092: public void initImpl() {
093: Appearance appNode = (Appearance) appearance.node;
094: Geometry geomNode = (Geometry) geometry.node;
095: implNode = null;
096:
097: if (appNode == null) {
098: appNode = new Appearance(loader);
099: appNode.initImpl();
100: }
101: if (geomNode instanceof Text) {
102: Text textNode = (Text) geomNode;
103: implNode = textNode.createText2D(appNode.impl);
104: implReady = true;
105: } else if (geomNode instanceof GroupGeom) {
106: implNode = ((GroupGeom) geomNode)
107: .initGroupImpl(appNode.impl);
108: implReady = true;
109: } else {
110: if (geomNode != null) {
111: javax.media.j3d.Geometry geom = geomNode.getImplGeom();
112: if (geom != null) {
113: if (appearance.node == null) {
114: implNode = new Shape3D(geom);
115: } else {
116: implNode = new Shape3D(geom, appNode.impl);
117: }
118: }
119: }
120: if ((appNode != null) && (geomNode != null)) {
121: appNode.numUses++;
122: if (appNode.haveTexture && !geomNode.haveTexture()) {
123: // need to to a texGen
124: appNode.setTexGen(geomNode.getBoundingBox());
125: }
126:
127: if (geomNode instanceof Ownable) {
128: // set the ifs owner to this
129: ((Ownable) geomNode).setOwner(this );
130: if (((Ownable) geomNode).getSolid() == false) {
131: javax.media.j3d.PolygonAttributes pa = appNode.impl
132: .getPolygonAttributes();
133: if (pa == null) {
134: pa = new javax.media.j3d.PolygonAttributes();
135: // set a default pa then
136: appNode.impl.setPolygonAttributes(pa);
137: }
138: appNode.impl
139: .getPolygonAttributes()
140: .setCullFace(
141: javax.media.j3d.PolygonAttributes.CULL_NONE);
142: appNode.impl.getPolygonAttributes()
143: .setBackFaceNormalFlip(true);
144: }
145: }
146: if ((geomNode instanceof IndexedLineSet)
147: || (geomNode instanceof PointSet)) {
148: javax.media.j3d.Material material = appNode.impl
149: .getMaterial();
150: if (material == null) {
151: material = new javax.media.j3d.Material();
152: appNode.impl.setMaterial(material);
153: }
154: material.setLightingEnable(false);
155: }
156: }
157:
158: if (defName == null) {
159: // If not a DEF'd node, null out those references to free up
160: // the memory
161: if (loader.debug) {
162: System.out
163: .println("Shape.initImpl(): nulling refrences");
164: }
165: geometry.node = null;
166: appearance.node = null;
167: }
168: implReady = true;
169: }
170: if (implNode != null) {
171: //implNode.setCapability(javax.media.j3d.Node.ALLOW_BOUNDS_READ);
172: //implNode.setCapability(
173: // javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ);
174: numTris = geomNode.getNumTris();
175: if (ifsChangeable) {
176: ((Shape3D) implNode)
177: .setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
178: ((Shape3D) implNode)
179: .setCapability(Shape3D.ALLOW_GEOMETRY_READ);
180: }
181: }
182: }
183:
184: /**
185: * Gets the numTris attribute of the Shape object
186: *
187: *@return The numTris value
188: */
189: public int getNumTris() {
190: //if (loader.debug) {
191: // System.out.println("Shape num tris: " + numTris);
192: //}
193: return numTris;
194: }
195:
196: /**
197: * Description of the Method
198: *
199: *@return Description of the Return Value
200: */
201: public Object clone() {
202: if (loader.debug) {
203: System.out.println("Shape.clone() called");
204: }
205: Shape retval = new Shape(loader, (SFNode) appearance.clone(),
206: (SFNode) geometry.clone());
207: if (loader.debug) {
208: System.out.println("Shape.clone() returns "
209: + retval.toStringId() + " = " + retval);
210: }
211: return retval;
212: }
213:
214: /**
215: * Gets the type attribute of the Shape object
216: *
217: *@return The type value
218: */
219: public String getType() {
220: return "Shape";
221: }
222:
223: /**
224: * Description of the Method
225: *
226: *@param eventInName Description of the Parameter
227: *@param time Description of the Parameter
228: */
229: public void notifyMethod(String eventInName, double time) {
230: if (eventInName.equals("geometry")) {
231: if (implReady && (implNode == null)) {
232: // TODO: node needs to get attached to parent.
233: initImpl();
234: } else {
235: if ((implNode instanceof Shape3D)
236: && !(geometry.node instanceof GroupGeom)) {
237: try {
238: //Shape3D s = (Shape3D)implNode;
239: //((Shape3D)implNode).setGeometry(
240: //((Geometry)geometry.node).getImplGeom());
241: initImpl();
242: } catch (NullPointerException npe) {
243: System.out.println(npe);
244: }
245: } else {
246: System.err
247: .println("Shape: Unimplemented case replacing geometry");
248: }
249: }
250: } else if (eventInName.equals("appearance")) {
251: if (implNode != null) {
252: Appearance app = (Appearance) appearance.node;
253: if (implNode instanceof Shape3D) {
254: ((Shape3D) implNode).setAppearance(app.impl);
255: } else {
256: System.err
257: .println("Shape: Unimplemented case replacing appearance");
258: }
259: }
260: } else if (eventInName.equals("route_ifs_changeable")) {
261: ifsChangeable = true;
262: }
263: }
264:
265: /**
266: * Description of the Method
267: *
268: *@return Description of the Return Value
269: */
270: public String toStringBody() {
271: String retval = "Shape {\n";
272: if (appearance.node != null) {
273: retval += "appearance " + appearance;
274: }
275: if (geometry.node != null) {
276: retval += "geometry " + geometry;
277: }
278: retval += "}";
279: return retval;
280: }
281:
282: }
|