001: package com.db.geometry.updater;
002:
003: import java.nio.*;
004:
005: import javax.vecmath.*;
006: import javax.media.j3d.*;
007:
008: /**
009: *
010: * @author Michael Nischt - zero@monoid.net
011: */
012: public class GeometryVertexUpdater implements GeometryUpdater {
013:
014: private Vertex vertex;
015: private VertexUpdater vertexUpdater;
016:
017: /** Creates a new instance of VertexGeometryUpdater */
018: public GeometryVertexUpdater() {
019: this (new VertexUpdater() {
020: public void updateVertex(int index, Vertex vertex) {
021: }
022: });
023: }
024:
025: /** Creates a new instance of VertexGeometryUpdater */
026: public GeometryVertexUpdater(VertexUpdater vertexUpdater) {
027: this .setVertexUpdater(vertexUpdater);
028: }
029:
030: public VertexUpdater getVertexUpdater() {
031: return this .vertexUpdater;
032: }
033:
034: public void setVertexUpdater(VertexUpdater vertexUpdater) {
035: this .vertexUpdater = vertexUpdater;
036: }
037:
038: public void updateData(javax.media.j3d.Geometry geometry) {
039: GeometryArray geomArray = (GeometryArray) geometry;
040:
041: int vertexCount = geomArray.getVertexCount();
042: int vertexFormat = geomArray.getVertexFormat();
043: int texCoordSetCount = geomArray.getTexCoordSetCount();
044:
045: if (this .vertex == null
046: || this .vertex.getVertexFormat() != vertexFormat
047: || this .vertex.getTexCoordSetCount() != texCoordSetCount) {
048: this .vertex = new Vertex(vertexFormat, texCoordSetCount);
049: }
050:
051: // BY_REFERENCE
052: if ((vertexFormat & GeometryArray.BY_REFERENCE) == GeometryArray.BY_REFERENCE) {
053: // BY_REFERENCE & USE_NIO_BUFFER
054: if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) == GeometryArray.USE_NIO_BUFFER) {
055: // BY_REFERENCE & USE_NIO_BUFFER & INTERLEAVED
056: if ((vertexFormat & GeometryArray.INTERLEAVED) == GeometryArray.INTERLEAVED) {
057: this .updateInterleavedRefNIO(geomArray);
058: }
059: // BY_REFERENCE & USE_NIO_BUFFER & !INTERLEAVED
060: else {
061: this .updateRefNIO(geomArray);
062: }
063: }
064: // BY_REFERENCE & !USE_NIO_BUFFER
065: else {
066: // BY_REFERENCE & !USE_NIO_BUFFER & INTERLEAVED
067: if ((vertexFormat & GeometryArray.INTERLEAVED) == GeometryArray.INTERLEAVED) {
068: this .updateInterleavedRef(geomArray);
069: }
070: // BY_REFERENCE & !USE_NIO_BUFFER & !INTERLEAVED
071: else {
072: this .updateRef(geomArray);
073: }
074: }
075: }
076: // !BY_REFERENCE & !USE_NIO_BUFFER & !INTERLEAVED
077: else {
078: this .update(geomArray);
079: }
080: }
081:
082: private void updateInterleavedRefNIO(GeometryArray geomArray) {
083: int vertexCount = geomArray.getVertexCount();
084: int vertexFormat = geomArray.getVertexFormat();
085: int texCoordSetCount = geomArray.getTexCoordSetCount();
086:
087: FloatBuffer intBuf = (FloatBuffer) geomArray
088: .getInterleavedVertexBuffer().getBuffer();
089: intBuf.rewind();
090: int index = 0;
091: for (int i = 0; i < vertexCount; i++) {
092: int pos = intBuf.position();
093: // read TEXTURE_COORDINATES
094: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
095: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
096: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
097: for (int j = 0; j < texCoordSetCount; j++) {
098: intBuf.get(this .vertex.getTextureCoordinate(j));
099: }
100: }
101: // read COLOR
102: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
103: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
104: intBuf.get(this .vertex.getColor());
105: }
106: // read NORMAL
107: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
108: intBuf.get(this .vertex.getNormal());
109: }
110: // read COORDINATES
111: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
112: intBuf.get(this .vertex.getCoordinate());
113: }
114:
115: // VERTEX UPDATE
116: this .vertexUpdater.updateVertex(i, this .vertex);
117:
118: intBuf.position(pos);
119: // write TEXTURE_COORDINATES
120: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
121: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
122: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
123: for (int j = 0; j < texCoordSetCount; j++) {
124: intBuf.put(this .vertex.getTextureCoordinate(j));
125: }
126: }
127: // write COLOR
128: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
129: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
130: intBuf.put(this .vertex.getColor());
131: }
132: // write NORMAL
133: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
134: intBuf.put(this .vertex.getNormal());
135: }
136: // write COORDINATES
137: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
138: intBuf.put(this .vertex.getCoordinate());
139: }
140: }
141:
142: intBuf.rewind();
143:
144: }
145:
146: private void updateInterleavedRef(GeometryArray geomArray) {
147: int vertexCount = geomArray.getVertexCount();
148: int vertexFormat = geomArray.getVertexFormat();
149: int texCoordSetCount = geomArray.getTexCoordSetCount();
150:
151: float[] inter = geomArray.getInterleavedVertices();
152: int index = 0;
153: for (int i = 0; i < vertexCount; i++) {
154: int pos = index;
155: // read TEXTURE_COORDINATES
156: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
157: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
158: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
159: for (int j = 0; j < texCoordSetCount; j++) {
160: float[] tCoords = this .vertex
161: .getTextureCoordinate(j);
162: for (int k = 0; k < tCoords.length; k++) {
163: tCoords[k] = inter[index++];
164: }
165: }
166: }
167: // read COLOR
168: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
169: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
170: float[] color = this .vertex.getColor();
171: for (int k = 0; k < color.length; k++) {
172: color[k] = inter[index++];
173: }
174: }
175: // read TEXTURE_NORMAL
176: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
177: float[] normal = this .vertex.getNormal();
178: normal[0] = inter[index++];
179: normal[1] = inter[index++];
180: normal[2] = inter[index++];
181: }
182: // read TEXTURE_COORDINATE
183: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
184: float[] coord = this .vertex.getCoordinate();
185: coord[0] = inter[index++];
186: coord[1] = inter[index++];
187: coord[2] = inter[index++];
188: }
189:
190: // UPDATE
191: this .vertexUpdater.updateVertex(i, this .vertex);
192:
193: index = pos;
194: // write TEXTURE_COORDINATES
195: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
196: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
197: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
198: for (int j = 0; j < texCoordSetCount; j++) {
199: float[] tCoords = this .vertex
200: .getTextureCoordinate(j);
201: for (int k = 0; k < tCoords.length; k++) {
202: inter[index++] = tCoords[k];
203: }
204: }
205: }
206: // write COLOR
207: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
208: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
209: float[] color = this .vertex.getColor();
210: for (int k = 0; k < color.length; k++) {
211: inter[index++] = color[k];
212: }
213: }
214: // write TEXTURE_NORMAL
215: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
216: float[] normal = this .vertex.getNormal();
217: inter[index++] = normal[0];
218: inter[index++] = normal[1];
219: inter[index++] = normal[2];
220: }
221: // write TEXTURE_COORDINATE
222: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
223: float[] coord = this .vertex.getCoordinate();
224: inter[index++] = coord[0];
225: inter[index++] = coord[1];
226: inter[index++] = coord[2];
227: }
228:
229: }
230:
231: }
232:
233: private void updateRefNIO(GeometryArray geomArray) {
234: int vertexCount = geomArray.getVertexCount();
235: int vertexFormat = geomArray.getVertexFormat();
236: int texCoordSetCount = geomArray.getTexCoordSetCount();
237:
238: FloatBuffer coordBufFloat = null;
239: DoubleBuffer coordBufDouble = null;
240: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
241: Buffer cBuf = geomArray.getCoordRefBuffer().getBuffer();
242: if (cBuf instanceof FloatBuffer) {
243: coordBufFloat = (FloatBuffer) cBuf;
244: coordBufFloat.rewind();
245: } else {
246: coordBufDouble = (DoubleBuffer) cBuf;
247: coordBufDouble.rewind();
248: }
249: }
250:
251: FloatBuffer normalBufFloat = null;
252: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
253: normalBufFloat = (FloatBuffer) geomArray
254: .getNormalRefBuffer().getBuffer();
255: normalBufFloat.rewind();
256: }
257:
258: FloatBuffer colorBufFloat = null;
259: ByteBuffer colorBufByte = null;
260: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
261: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
262: Buffer cBuf = geomArray.getColorRefBuffer().getBuffer();
263: if (cBuf instanceof FloatBuffer) {
264: colorBufFloat = (FloatBuffer) cBuf;
265: colorBufFloat.rewind();
266: } else {
267: colorBufByte = (ByteBuffer) cBuf;
268: colorBufByte.rewind();
269: }
270: }
271:
272: FloatBuffer[] texCoordBufFloat = null;
273: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
274: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
275: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
276: texCoordBufFloat = new FloatBuffer[texCoordSetCount];
277: for (int i = 0; i < texCoordSetCount; i++) {
278: texCoordBufFloat[i] = (FloatBuffer) geomArray
279: .getTexCoordRefBuffer(i).getBuffer();
280: texCoordBufFloat[i].rewind();
281: }
282: }
283:
284: for (int i = 0; i < vertexCount; i++) {
285: // read COORDINATE
286: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
287: if (coordBufFloat != null) {
288: coordBufFloat.get(this .vertex.getCoordinate());
289: coordBufFloat.mark();
290: } else {
291: float[] coord = this .vertex.getCoordinate();
292: coord[0] = (float) coordBufDouble.get();
293: coord[1] = (float) coordBufDouble.get();
294: coord[2] = (float) coordBufDouble.get();
295: coordBufDouble.mark();
296: }
297: }
298: // read NORMAL
299: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
300: normalBufFloat.get(this .vertex.getNormal());
301: normalBufFloat.mark();
302: }
303: // read COLOR
304: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
305: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
306: if (colorBufFloat != null) {
307: colorBufFloat.get(this .vertex.getColor());
308: colorBufFloat.mark();
309: } else {
310: float[] color = this .vertex.getColor();
311: for (int k = 0; k < color.length; k++) {
312: color[k] = (float) colorBufByte.get() / 255.0f;
313: }
314: colorBufByte.mark();
315: }
316: }
317: // read TEXTURE_COORDINATE
318: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
319: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
320: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
321: for (int k = 0; k < texCoordSetCount; k++) {
322: texCoordBufFloat[k].get(this .vertex
323: .getTextureCoordinate(k));
324: texCoordBufFloat[k].mark();
325: }
326: }
327:
328: // UODATE
329: this .vertexUpdater.updateVertex(i, this .vertex);
330:
331: // write COORDINATE
332: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
333: if (coordBufFloat != null) {
334: coordBufFloat.reset();
335: coordBufFloat.put(this .vertex.getCoordinate());
336:
337: } else {
338: coordBufDouble.reset();
339: float[] coord = this .vertex.getCoordinate();
340: coordBufDouble.put(coord[0]);
341: coordBufDouble.put(coord[1]);
342: coordBufDouble.put(coord[2]);
343: }
344: }
345: // write NORMAL
346: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
347: normalBufFloat.reset();
348: normalBufFloat.put(this .vertex.getNormal());
349: }
350: // write COLOR
351: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
352: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
353: if (colorBufFloat != null) {
354: colorBufFloat.reset();
355: colorBufFloat.put(this .vertex.getColor());
356: } else {
357: float[] color = this .vertex.getColor();
358: colorBufByte.reset();
359: for (int k = 0; k < color.length; k++) {
360: colorBufByte.put((byte) (color[k] * 255.0f));
361: }
362: }
363: }
364: // write TEXTURE_COORDINATE
365: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
366: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
367: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
368: for (int k = 0; k < texCoordSetCount; k++) {
369: texCoordBufFloat[k].reset();
370: texCoordBufFloat[k].put(this .vertex
371: .getTextureCoordinate(k));
372: }
373: }
374: }
375:
376: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
377: if (coordBufFloat != null) {
378: coordBufFloat.rewind();
379: } else {
380: coordBufDouble.rewind();
381: }
382: }
383:
384: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
385: normalBufFloat = (FloatBuffer) geomArray
386: .getNormalRefBuffer().getBuffer();
387: }
388:
389: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
390: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
391: if (colorBufFloat != null) {
392: colorBufFloat.rewind();
393: } else {
394: colorBufByte.rewind();
395: }
396: }
397:
398: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
399: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
400: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
401: texCoordBufFloat = new FloatBuffer[texCoordSetCount];
402: for (int i = 0; i < texCoordSetCount; i++) {
403: texCoordBufFloat[i].rewind();
404: }
405: }
406: }
407:
408: private void updateRef(GeometryArray geomArray) {
409: int vertexCount = geomArray.getVertexCount();
410: int vertexFormat = geomArray.getVertexFormat();
411: int texCoordSetCount = geomArray.getTexCoordSetCount();
412:
413: float[] coordsFloat = null;
414: double[] coordsDouble = null;
415: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
416: coordsFloat = geomArray.getCoordRefFloat();
417: coordsDouble = geomArray.getCoordRefDouble();
418: }
419:
420: float[] normalsFloat = null;
421: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
422: normalsFloat = geomArray.getNormalRefFloat();
423: }
424:
425: float[] colorsFloat = null;
426: byte[] colorsByte = null;
427: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
428: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
429: colorsFloat = geomArray.getColorRefFloat();
430: colorsByte = geomArray.getColorRefByte();
431: }
432:
433: float[][] texCoordsFloat = null;
434: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
435: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
436: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
437: texCoordsFloat = new float[texCoordSetCount][0];
438: for (int i = 0; i < texCoordSetCount; i++) {
439: texCoordsFloat[i] = geomArray.getTexCoordRefFloat(i);
440: }
441: }
442:
443: for (int i = 0; i < vertexCount; i++) {
444: // read COORDINATE
445: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
446: if (coordsFloat != null) {
447: float[] coord = this .vertex.getCoordinate();
448: coord[0] = coordsFloat[3 * i + 0];
449: coord[1] = coordsFloat[3 * i + 1];
450: coord[2] = coordsFloat[3 * i + 2];
451: } else {
452: float[] coord = this .vertex.getCoordinate();
453: coord[0] = (float) coordsDouble[3 * i + 0];
454: coord[1] = (float) coordsDouble[3 * i + 1];
455: coord[2] = (float) coordsDouble[3 * i + 2];
456: }
457: }
458: // read NORMAL
459: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
460: float[] normal = this .vertex.getNormal();
461: normal[0] = normalsFloat[3 * i + 0];
462: normal[1] = normalsFloat[3 * i + 1];
463: normal[2] = normalsFloat[3 * i + 2];
464: }
465: // read COLOR
466: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
467: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
468: float[] color = this .vertex.getColor();
469: if (colorsFloat != null) {
470: for (int k = 0; k < color.length; k++) {
471: color[k] = colorsFloat[color.length * i + k];
472: }
473: } else {
474: for (int k = 0; k < color.length; k++) {
475: color[k] = (float) colorsByte[color.length * i
476: + k] / 255.0f;
477: }
478: }
479: }
480: // read TEXTURE_COORDINATE
481: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
482: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
483: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
484: for (int k = 0; k < texCoordSetCount; k++) {
485: float[] texCoord = this .vertex
486: .getTextureCoordinate(k);
487: for (int l = 0; l < texCoord.length; l++) {
488: texCoord[l] = texCoordsFloat[k][texCoord.length
489: * i + l];
490: }
491: }
492: }
493:
494: // UODATE
495: this .vertexUpdater.updateVertex(i, this .vertex);
496:
497: // write COORDINATE
498: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
499: if (coordsFloat != null) {
500: float[] coord = this .vertex.getCoordinate();
501: coordsFloat[3 * i + 0] = coord[0];
502: coordsFloat[3 * i + 1] = coord[1];
503: coordsFloat[3 * i + 2] = coord[2];
504: } else {
505: float[] coord = this .vertex.getCoordinate();
506: coordsDouble[3 * i + 0] = coord[0];
507: coordsDouble[3 * i + 1] = coord[1];
508: coordsDouble[3 * i + 2] = coord[2];
509: }
510: }
511: // write NORMAL
512: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
513: float[] normal = this .vertex.getNormal();
514: normalsFloat[3 * i + 0] = normal[0];
515: normalsFloat[3 * i + 1] = normal[1];
516: normalsFloat[3 * i + 2] = normal[2];
517: }
518: // write COLOR
519: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
520: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
521: if (colorsFloat != null) {
522: float[] color = this .vertex.getColor();
523: for (int k = 0; k < color.length; k++) {
524: colorsFloat[color.length * i + k] = color[k];
525: }
526: } else {
527: float[] color = this .vertex.getColor();
528: for (int k = 0; k < color.length; k++) {
529: colorsByte[color.length * i + k] = (byte) (color[k] * 255.0f);
530: }
531: }
532: }
533: // write TEXTURE_COORDINATE
534: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
535: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
536: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
537: for (int k = 0; k < texCoordSetCount; k++) {
538: float[] texCoord = this .vertex
539: .getTextureCoordinate(k);
540: for (int l = 0; l < texCoord.length; l++) {
541: texCoordsFloat[k][texCoord.length * i + l] = texCoord[l];
542: }
543: }
544: }
545: }
546: }
547:
548: private void update(GeometryArray geomArray) {
549: int vertexCount = geomArray.getVertexCount();
550: int vertexFormat = geomArray.getVertexFormat();
551: int texCoordSetCount = geomArray.getTexCoordSetCount();
552:
553: for (int i = 0; i < vertexCount; i++) {
554: // read COORDINATE
555: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
556: geomArray.getCoordinate(i, this .vertex.getCoordinate());
557: }
558: // read NORMAL
559: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
560: geomArray.getNormal(i, this .vertex.getNormal());
561: }
562: // read COLOR
563: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
564: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
565: geomArray.getColor(i, this .vertex.getColor());
566: }
567: // read TEXTURE_COORDINATE
568: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
569: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
570: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
571: for (int j = 0; j < texCoordSetCount; j++) {
572: geomArray.getTextureCoordinate(j, i, this .vertex
573: .getTextureCoordinate(j));
574: }
575: }
576:
577: // UPDATE
578: this .vertexUpdater.updateVertex(i, this .vertex);
579:
580: // write COORDINATE
581: if ((vertexFormat & GeometryArray.COORDINATES) == GeometryArray.COORDINATES) {
582: geomArray.setCoordinate(i, this .vertex.getCoordinate());
583: }
584: // write NORMAL
585: if ((vertexFormat & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
586: geomArray.setNormal(i, this .vertex.getNormal());
587: }
588: // write COLOR
589: if (((vertexFormat & GeometryArray.COLOR_3) == GeometryArray.COLOR_3)
590: || ((vertexFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4)) {
591: geomArray.setColor(i, this .vertex.getColor());
592: }
593: // write TEXTURE_COORDINATE
594: if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2)
595: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) == GeometryArray.TEXTURE_COORDINATE_3)
596: || ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) == GeometryArray.TEXTURE_COORDINATE_4)) {
597: for (int j = 0; j < texCoordSetCount; j++) {
598: geomArray.setTextureCoordinate(j, i, this.vertex
599: .getTextureCoordinate(j));
600: }
601: }
602: }
603:
604: }
605:
606: }
|