001: /*
002: * $RCSfile: IndexedLineSet.java,v $
003: *
004: * @(#)IndexedLineSet.java 1.19 98/11/05 20:34:34
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:06:56 $
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.GeometryArray;
045: import javax.media.j3d.LineStripArray;
046:
047: /** Description of the Class */
048: public class IndexedLineSet extends Geometry {
049:
050: LineStripArray impl;
051: BoundingBox bounds;
052:
053: SFNode color;
054: SFNode coord;
055:
056: MFInt32 colorIndex;
057: SFBool colorPerVertex;
058: MFInt32 coordIndex;
059:
060: int vertexFormat = 0;
061: int numIndices = 0;
062: int numLines = 0;
063: boolean haveColor = false;
064: int[] lineSizes;
065: int[] implCoordIndex = null;
066: int[] implColorIndex = null;
067: Coordinate coordNode = null;
068: Color colorNode = null;
069:
070: /**
071: *Constructor for the IndexedLineSet object
072: *
073: *@param loader Description of the Parameter
074: */
075: public IndexedLineSet(Loader loader) {
076: super (loader);
077: colorPerVertex = new SFBool(true);
078: color = new SFNode();
079: coord = new SFNode();
080: colorIndex = new MFInt32();
081: coordIndex = new MFInt32();
082: initFields();
083: }
084:
085: /**
086: *Constructor for the IndexedLineSet object
087: *
088: *@param loader Description of the Parameter
089: *@param coord Description of the Parameter
090: *@param coordIndex Description of the Parameter
091: *@param color Description of the Parameter
092: *@param colorIndex Description of the Parameter
093: *@param colorPerVertex Description of the Parameter
094: */
095: public IndexedLineSet(Loader loader, SFNode coord,
096: MFInt32 coordIndex, SFNode color, MFInt32 colorIndex,
097: SFBool colorPerVertex) {
098: super (loader);
099: this .coord = coord;
100: this .coordIndex = coordIndex;
101: this .color = color;
102: this .colorIndex = colorIndex;
103: this .colorPerVertex = colorPerVertex;
104: initFields();
105: }
106:
107: /** Description of the Method */
108: public void initImpl() {
109: if ((coord != null) && (coord.node instanceof Coordinate)
110: && (coordIndex.size != 0)) {
111: coordNode = (Coordinate) coord.node;
112: vertexFormat = GeometryArray.COORDINATES;
113: numLines = coordIndex.primCount();
114: numIndices = coordIndex.indexCount();
115: lineSizes = new int[numLines];
116: implCoordIndex = new int[numIndices];
117: coordIndex.fillImplArrays(lineSizes, implCoordIndex);
118:
119: if ((color != null) && (color.node instanceof Color)) {
120: colorNode = (Color) color.node;
121: vertexFormat |= javax.media.j3d.GeometryArray.COLOR_3;
122: haveColor = true;
123: if (colorPerVertex.value == false) {
124: if (colorIndex.size == 0) {
125: implColorIndex = new int[numIndices];
126: int curIndex = 0;
127: for (int j = 0; j < numLines; j++) {
128: for (int i = 0; i < lineSizes[j]; i++) {
129: implColorIndex[curIndex++] = j;
130: }
131: }
132: } else {
133: // color per line
134: if (colorIndex.size != numLines) {
135: System.out
136: .println("ILS: colorIndex.size = "
137: + colorIndex.size
138: + " != numLines = "
139: + numLines);
140: }
141: implColorIndex = new int[numIndices];
142: int curIndex = 0;
143: for (int j = 0; j < numLines; j++) {
144: for (int i = 0; i < lineSizes[j]; i++) {
145: implColorIndex[curIndex++] = colorIndex.value[j];
146: }
147: }
148: }
149: } else {
150: if (colorIndex.size == 0) {
151: implColorIndex = implCoordIndex;
152: } else {
153: implColorIndex = new int[numIndices];
154: if (!coordIndex.fillImplArraysTest(lineSizes,
155: implColorIndex)) {
156: // TODO: throw exception
157: }
158: // TODO: test that size of color vals is correct
159: }
160: }
161: }
162:
163: // Don't use indexed data, since SDRC (and probably others) use
164: // the same geometry for many different primitives, leading
165: // to many different copies of the coords. Instead, unindexify
166: // before creating the impl.
167:
168: float[] implCoords = new float[3 * numIndices];
169: for (int i = 0; i < numIndices; i++) {
170: int implBase = i * 3;
171: int indexBase = implCoordIndex[i] * 3;
172: implCoords[implBase] = coordNode.point.value[indexBase];
173: implCoords[implBase + 1] = coordNode.point.value[indexBase + 1];
174: implCoords[implBase + 2] = coordNode.point.value[indexBase + 2];
175: }
176:
177: impl = new LineStripArray(numIndices, vertexFormat,
178: lineSizes);
179: impl.setCoordinates(0, implCoords);
180:
181: if (haveColor) {
182: float[] implColors = new float[3 * numIndices];
183: for (int i = 0; i < numIndices; i++) {
184: int implBase = i * 3;
185: int indexBase = implColorIndex[i] * 3;
186: implColors[implBase] = colorNode.color.vals[indexBase];
187: implColors[implBase + 1] = colorNode.color.vals[indexBase + 1];
188: implColors[implBase + 2] = colorNode.color.vals[indexBase + 2];
189: }
190: impl.setColors(0, implColors);
191: }
192:
193: bounds = coordNode.point.getBoundingBox();
194: }
195: }
196:
197: /**
198: * Description of the Method
199: *
200: *@param eventInName Description of the Parameter
201: *@param time Description of the Parameter
202: */
203: public void notifyMethod(String eventInName, double time) {
204: if (eventInName.equals("colorIndex")
205: || eventInName.equals("coordIndex")) {
206: initImpl();
207: }
208: }
209:
210: /**
211: * Description of the Method
212: *
213: *@return Description of the Return Value
214: */
215: public Object clone() {
216: return new IndexedLineSet(loader, (SFNode) coord.clone(),
217: (MFInt32) coordIndex.clone(), (SFNode) color.clone(),
218: (MFInt32) colorIndex.clone(), (SFBool) colorPerVertex
219: .clone());
220: }
221:
222: /**
223: * Gets the type attribute of the IndexedLineSet object
224: *
225: *@return The type value
226: */
227: public String getType() {
228: return "IndexedLineSet";
229: }
230:
231: /** Description of the Method */
232: void initFields() {
233: coord.init(this , FieldSpec, Field.EXPOSED_FIELD, "coord");
234: coordIndex.init(this , FieldSpec, Field.EVENT_IN, "coordIndex");
235: color.init(this , FieldSpec, Field.EXPOSED_FIELD, "color");
236: colorIndex.init(this , FieldSpec, Field.EVENT_IN, "colorIndex");
237: colorPerVertex.init(this , FieldSpec, Field.FIELD,
238: "colorPerVertex");
239: }
240:
241: /**
242: * Gets the implGeom attribute of the IndexedLineSet object
243: *
244: *@return The implGeom value
245: */
246: public javax.media.j3d.Geometry getImplGeom() {
247: return (javax.media.j3d.Geometry) impl;
248: }
249:
250: /**
251: * Gets the boundingBox attribute of the IndexedLineSet object
252: *
253: *@return The boundingBox value
254: */
255: public javax.media.j3d.BoundingBox getBoundingBox() {
256: return bounds;
257: }
258:
259: /**
260: * Description of the Method
261: *
262: *@return Description of the Return Value
263: */
264: public boolean haveTexture() {
265: return false;//!
266: }
267:
268: /**
269: * Gets the numTris attribute of the IndexedLineSet object
270: *
271: *@return The numTris value
272: */
273: public int getNumTris() {
274: return 0;
275: }
276:
277: }
|