Source Code Cross Referenced for GeometryStripArrayRetained.java in  » 6.0-JDK-Modules » java-3d » javax » media » j3d » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » javax.media.j3d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: GeometryStripArrayRetained.java,v $
003:         *
004:         * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006:         *
007:         * This code is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU General Public License version 2 only, as
009:         * published by the Free Software Foundation.  Sun designates this
010:         * particular file as subject to the "Classpath" exception as provided
011:         * by Sun in the LICENSE file that accompanied this code.
012:         *
013:         * This code is distributed in the hope that it will be useful, but WITHOUT
014:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:         * version 2 for more details (a copy is included in the LICENSE file that
017:         * accompanied this code).
018:         *
019:         * You should have received a copy of the GNU General Public License version
020:         * 2 along with this work; if not, write to the Free Software Foundation,
021:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022:         *
023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024:         * CA 95054 USA or visit www.sun.com if you need additional information or
025:         * have any questions.
026:         *
027:         * $Revision: 1.8 $
028:         * $Date: 2008/02/28 20:17:22 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import javax.vecmath.*;
035:        import java.util.ArrayList;
036:        import java.util.Vector;
037:        import com.sun.j3d.internal.ByteBufferWrapper;
038:        import com.sun.j3d.internal.BufferWrapper;
039:        import com.sun.j3d.internal.FloatBufferWrapper;
040:        import com.sun.j3d.internal.DoubleBufferWrapper;
041:
042:        /**
043:         * The GeometryStripArray object is an abstract class that is extended for
044:         * a set of GeometryArray strip primitives.  These include LINE_STRIP,
045:         * TRIANGLE_STRIP, and TRIANGLE_FAN.
046:         */
047:
048:        abstract class GeometryStripArrayRetained extends GeometryArrayRetained {
049:
050:            // Array of per-strip vertex counts
051:            int stripVertexCounts[];
052:
053:            // Array of per-strip starting index
054:            int stripStartVertexIndices[]; // start of vertices for both by-copy
055:            // and by-ref
056:            int stripStartOffsetIndices[]; // Used in byRef non_interleaved
057:
058:            // Following variables are only used in the compile mode
059:            // isCompiled = true
060:            int[] compileNumStrips;
061:            int[] compileStripCountOffset;
062:
063:            /**
064:             * Set stripVertexCount data into local array
065:             */
066:            void setStripVertexCounts(int stripVertexCounts[]) {
067:                boolean nullGeo = false;
068:
069:                int i, num = stripVertexCounts.length, total = 0;
070:                for (i = 0; i < num; i++) {
071:                    total += stripVertexCounts[i];
072:                    if (this  instanceof  LineStripArrayRetained) {
073:                        if (stripVertexCounts[i] < 2) {
074:                            throw new IllegalArgumentException(J3dI18N
075:                                    .getString("LineStripArrayRetained1"));
076:                        }
077:                    } else if (this  instanceof  TriangleStripArrayRetained) {
078:                        if (stripVertexCounts[i] < 3) {
079:                            throw new IllegalArgumentException(J3dI18N
080:                                    .getString("TriangleStripArrayRetained1"));
081:                        }
082:                    } else if (this  instanceof  TriangleFanArrayRetained) {
083:                        if (stripVertexCounts[i] < 3) {
084:                            throw new IllegalArgumentException(J3dI18N
085:                                    .getString("TriangleFanArrayRetained1"));
086:                        }
087:                    }
088:                }
089:
090:                if ((initialVertexIndex + total) > vertexCount) {
091:                    throw new IllegalArgumentException(J3dI18N
092:                            .getString("GeometryStripArray3"));
093:                }
094:                if ((initialCoordIndex + total) > vertexCount) {
095:                    throw new IllegalArgumentException(J3dI18N
096:                            .getString("GeometryStripArray7"));
097:                }
098:                if ((initialColorIndex + total) > vertexCount) {
099:                    throw new IllegalArgumentException(J3dI18N
100:                            .getString("GeometryStripArray4"));
101:                }
102:                if ((initialNormalIndex + total) > vertexCount) {
103:                    throw new IllegalArgumentException(J3dI18N
104:                            .getString("GeometryStripArray5"));
105:                }
106:                if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
107:                    if ((vertexFormat & (GeometryArray.BY_REFERENCE | vertexFormat
108:                            & GeometryArray.INTERLEAVED)) == GeometryArray.BY_REFERENCE) {
109:                        for (i = 0; i < texCoordSetCount; i++) {
110:                            if ((initialTexCoordIndex[i] + total) > vertexCount) {
111:                                throw new IllegalArgumentException(J3dI18N
112:                                        .getString("GeometryStripArray6"));
113:                            }
114:                        }
115:                    }
116:                }
117:                if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
118:                    if ((vertexFormat & (GeometryArray.BY_REFERENCE | vertexFormat
119:                            & GeometryArray.INTERLEAVED)) == GeometryArray.BY_REFERENCE) {
120:                        for (i = 0; i < vertexAttrCount; i++) {
121:                            if ((initialVertexAttrIndex[i] + total) > vertexCount) {
122:                                throw new IllegalArgumentException(J3dI18N
123:                                        .getString("GeometryStripArray8"));
124:                            }
125:                        }
126:                    }
127:                }
128:                boolean isLive = source != null && source.isLive();
129:                if (isLive) {
130:                    geomLock.getLock();
131:                }
132:                dirtyFlag |= STRIPCOUNT_CHANGED;
133:                validVertexCount = total;
134:                this .stripVertexCounts = new int[num];
135:                stripStartVertexIndices = new int[num];
136:                stripStartOffsetIndices = new int[num];
137:                stripStartOffsetIndices[0] = 0;
138:                if ((vertexFormat & (GeometryArray.BY_REFERENCE | vertexFormat
139:                        & GeometryArray.INTERLEAVED)) == GeometryArray.BY_REFERENCE) {
140:                    stripStartVertexIndices[0] = initialCoordIndex;
141:                    nullGeo = ((vertexType & GeometryArrayRetained.VERTEX_DEFINED) == 0);
142:                } else {
143:                    stripStartVertexIndices[0] = initialVertexIndex;
144:                    if ((vertexFormat & GeometryArray.INTERLEAVED) != 0) {
145:                        if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) {
146:                            nullGeo = (interLeavedVertexData == null);
147:                        } else {
148:                            nullGeo = (interleavedFloatBufferImpl == null);
149:                        }
150:                    }
151:                }
152:
153:                for (i = 0; i < num - 1; i++) {
154:                    this .stripVertexCounts[i] = stripVertexCounts[i];
155:                    stripStartVertexIndices[i + 1] = stripStartVertexIndices[i]
156:                            + stripVertexCounts[i];
157:                    stripStartOffsetIndices[i + 1] = stripStartOffsetIndices[i]
158:                            + stripVertexCounts[i];
159:                }
160:                this .stripVertexCounts[num - 1] = stripVertexCounts[num - 1];
161:                if (isLive) {
162:                    geomLock.unLock();
163:                }
164:                if (!inUpdater && isLive) {
165:                    processCoordsChanged(nullGeo);
166:                    sendDataChangedMessage(true);
167:                }
168:
169:            }
170:
171:            void unIndexify(IndexedGeometryStripArrayRetained src) {
172:                if ((src.vertexFormat & GeometryArray.USE_NIO_BUFFER) == 0) {
173:                    unIndexifyJavaArray(src);
174:                } else {
175:                    unIndexifyNIOBuffer(src);
176:                }
177:            }
178:
179:            private void unIndexifyJavaArray(
180:                    IndexedGeometryStripArrayRetained src) {
181:                int vOffset = 0, srcOffset, tOffset = 0;
182:                int base = src.initialIndexIndex;
183:                int i, j, k, index, colorStride = 0;
184:                float[] vdata = null;
185:
186:                if (((src.vertexFormat & GeometryArray.BY_REFERENCE) == 0)
187:                        || ((src.vertexFormat & GeometryArray.INTERLEAVED) != 0)) {
188:
189:                    if ((src.vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
190:                        vdata = src.vertexData;
191:                        if ((src.vertexFormat & GeometryArray.COLOR) != 0)
192:                            colorStride = 4;
193:                    } else if ((src.vertexFormat & GeometryArray.INTERLEAVED) != 0) {
194:                        vdata = src.interLeavedVertexData;
195:                        if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0)
196:                            colorStride = 4;
197:                        else if ((src.vertexFormat & GeometryArray.COLOR) != 0)
198:                            colorStride = 3;
199:                    }
200:
201:                    for (i = 0; i < src.stripIndexCounts.length; i++) {
202:                        for (j = 0; j < src.stripIndexCounts[i]; j++) {
203:                            index = j + base;
204:                            if ((vertexFormat & GeometryArray.NORMALS) != 0) {
205:                                System.arraycopy(vdata, src.indexNormal[index]
206:                                        * src.stride + src.normalOffset,
207:                                        vertexData, vOffset + normalOffset, 3);
208:                            }
209:
210:                            if (colorStride == 4) {
211:                                /*
212:                                System.err.println("vdata.length = "+vdata.length);
213:                                System.err.println("vertexData.length = "+vertexData.length);
214:                                System.err.println("src.stride = "+src.stride);
215:                                System.err.println("src.colorOffset = "+src.colorOffset);
216:                                System.err.println("index = "+index+" src.indexColor.length = "+src.indexColor.length);
217:                                System.err.println("src.indexColor[index] = "+src.indexColor[index]);
218:                                System.err.println("base = "+base);
219:                                 */
220:                                System.arraycopy(vdata, src.indexColor[index]
221:                                        * src.stride + src.colorOffset,
222:                                        vertexData, vOffset + colorOffset,
223:                                        colorStride);
224:                            } else if (colorStride == 3) {
225:                                System.arraycopy(vdata, src.indexColor[index]
226:                                        * src.stride + src.colorOffset,
227:                                        vertexData, vOffset + colorOffset,
228:                                        colorStride);
229:                                vertexData[vOffset + colorOffset + 3] = 1.0f;
230:                            }
231:
232:                            if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
233:                                for (k = 0; k < texCoordSetCount; k++) {
234:                                    System
235:                                            .arraycopy(
236:                                                    vdata,
237:                                                    (src.indexTexCoord[k][index])
238:                                                            * src.stride
239:                                                            + src.textureOffset
240:                                                            + src.texCoordSetMapOffset[k],
241:                                                    vertexData,
242:                                                    vOffset
243:                                                            + textureOffset
244:                                                            + texCoordSetMapOffset[k],
245:                                                    texCoordStride);
246:                                }
247:                            }
248:
249:                            if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
250:                                for (k = 0; k < vertexAttrCount; k++) {
251:                                    System.arraycopy(vdata,
252:                                            src.indexVertexAttr[k][index]
253:                                                    * src.stride
254:                                                    + src.vertexAttrOffsets[k],
255:                                            vertexData, vOffset
256:                                                    + vertexAttrOffsets[k],
257:                                            vertexAttrSizes[k]);
258:                                }
259:                            }
260:
261:                            if ((vertexFormat & GeometryArray.COORDINATES) != 0) {
262:                                System.arraycopy(vdata, src.indexCoord[index]
263:                                        * src.stride + src.coordinateOffset,
264:                                        vertexData, vOffset + coordinateOffset,
265:                                        3);
266:                            }
267:                            vOffset += stride;
268:                        }
269:                        base += src.stripIndexCounts[i];
270:                    }
271:                } else {
272:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
273:                        base = src.initialIndexIndex;
274:                        vOffset = normalOffset;
275:                        switch ((src.vertexType & NORMAL_DEFINED)) {
276:                        case NF:
277:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
278:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
279:                                    index = j + base;
280:                                    System.arraycopy(src.floatRefNormals,
281:                                            src.indexNormal[index] * 3,
282:                                            vertexData, vOffset, 3);
283:                                    vOffset += stride;
284:                                }
285:                                base += src.stripIndexCounts[i];
286:                            }
287:                            break;
288:                        case N3F:
289:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
290:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
291:                                    index = src.indexNormal[j + base];
292:                                    vertexData[vOffset] = src.v3fRefNormals[index].x;
293:                                    vertexData[vOffset + 1] = src.v3fRefNormals[index].y;
294:                                    vertexData[vOffset + 2] = src.v3fRefNormals[index].z;
295:                                    vOffset += stride;
296:                                }
297:                                base += src.stripIndexCounts[i];
298:                            }
299:                            break;
300:                        default:
301:                            break;
302:                        }
303:                    }
304:
305:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
306:                        base = src.initialIndexIndex;
307:                        vOffset = colorOffset;
308:                        int multiplier = 3;
309:                        if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0)
310:                            multiplier = 4;
311:
312:                        switch ((src.vertexType & COLOR_DEFINED)) {
313:                        case CF:
314:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
315:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
316:                                    index = j + base;
317:
318:                                    if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0) {
319:                                        System.arraycopy(src.floatRefColors,
320:                                                src.indexColor[index]
321:                                                        * multiplier,
322:                                                vertexData, vOffset, 4);
323:                                    } else {
324:                                        System.arraycopy(src.floatRefColors,
325:                                                src.indexColor[index]
326:                                                        * multiplier,
327:                                                vertexData, vOffset, 3);
328:                                        vertexData[vOffset + 3] = 1.0f;
329:                                    }
330:                                    vOffset += stride;
331:                                }
332:                                base += src.stripIndexCounts[i];
333:                            }
334:                            break;
335:                        case CUB:
336:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
337:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
338:                                    index = src.indexColor[j + base]
339:                                            * multiplier;
340:                                    vertexData[vOffset] = (src.byteRefColors[index] & 0xff)
341:                                            * ByteToFloatScale;
342:                                    vertexData[vOffset + 1] = (src.byteRefColors[index + 1] & 0xff)
343:                                            * ByteToFloatScale;
344:                                    ;
345:                                    vertexData[vOffset + 2] = (src.byteRefColors[index + 2] & 0xff)
346:                                            * ByteToFloatScale;
347:                                    ;
348:                                    if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0) {
349:                                        vertexData[vOffset + 3] = (src.byteRefColors[index + 3] & 0xff)
350:                                                * ByteToFloatScale;
351:                                    } else {
352:                                        vertexData[vOffset + 3] = 1.0f;
353:                                    }
354:                                    vOffset += stride;
355:                                }
356:                                base += src.stripIndexCounts[i];
357:                            }
358:                            break;
359:                        case C3F:
360:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
361:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
362:                                    index = src.indexColor[j + base];
363:                                    vertexData[vOffset] = src.c3fRefColors[index].x;
364:                                    vertexData[vOffset + 1] = src.c3fRefColors[index].y;
365:                                    vertexData[vOffset + 2] = src.c3fRefColors[index].z;
366:                                    vertexData[vOffset + 3] = 1.0f;
367:                                    vOffset += stride;
368:                                }
369:                                base += src.stripIndexCounts[i];
370:                            }
371:                            break;
372:                        case C4F:
373:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
374:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
375:                                    index = src.indexColor[j + base];
376:                                    vertexData[vOffset] = src.c4fRefColors[index].x;
377:                                    vertexData[vOffset + 1] = src.c4fRefColors[index].y;
378:                                    vertexData[vOffset + 2] = src.c4fRefColors[index].z;
379:                                    vertexData[vOffset + 3] = src.c4fRefColors[index].w;
380:                                    vOffset += stride;
381:                                }
382:                                base += src.stripIndexCounts[i];
383:                            }
384:                            break;
385:                        case C3UB:
386:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
387:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
388:                                    index = src.indexColor[j + base];
389:                                    vertexData[vOffset] = (src.c3bRefColors[index].x & 0xff)
390:                                            * ByteToFloatScale;
391:                                    vertexData[vOffset + 1] = (src.c3bRefColors[index].y & 0xff)
392:                                            * ByteToFloatScale;
393:                                    vertexData[vOffset + 2] = (src.c3bRefColors[index].z & 0xff)
394:                                            * ByteToFloatScale;
395:                                    vertexData[vOffset + 3] = 1.0f;
396:
397:                                    vOffset += stride;
398:                                }
399:                                base += src.stripIndexCounts[i];
400:                            }
401:                            break;
402:                        case C4UB:
403:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
404:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
405:                                    index = src.indexColor[j + base];
406:                                    vertexData[vOffset] = (src.c4bRefColors[index].x & 0xff)
407:                                            * ByteToFloatScale;
408:                                    vertexData[vOffset + 1] = (src.c4bRefColors[index].y & 0xff)
409:                                            * ByteToFloatScale;
410:                                    vertexData[vOffset + 2] = (src.c4bRefColors[index].z & 0xff)
411:                                            * ByteToFloatScale;
412:                                    vertexData[vOffset + 3] = (src.c4bRefColors[index].w & 0xff)
413:                                            * ByteToFloatScale;
414:                                    vOffset += stride;
415:                                }
416:                                base += src.stripIndexCounts[i];
417:                            }
418:                            break;
419:                        default:
420:                            break;
421:                        }
422:                    }
423:
424:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
425:                        base = src.initialIndexIndex;
426:                        vOffset = textureOffset;
427:                        switch ((src.vertexType & TEXCOORD_DEFINED)) {
428:                        case TF:
429:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
430:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
431:                                    index = j + base;
432:
433:                                    for (k = 0, tOffset = vOffset; k < texCoordSetCount; k++) {
434:                                        System.arraycopy(src.refTexCoords[k],
435:                                                src.indexTexCoord[k][index]
436:                                                        * texCoordStride,
437:                                                vertexData, tOffset,
438:                                                texCoordStride);
439:                                        tOffset += texCoordStride;
440:                                    }
441:                                    vOffset += stride;
442:                                }
443:                                base += src.stripIndexCounts[i];
444:                            }
445:                            break;
446:                        case T2F:
447:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
448:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
449:                                    index = j + base;
450:                                    for (k = 0, tOffset = vOffset; k < texCoordSetCount; k++) {
451:                                        srcOffset = src.indexTexCoord[k][index];
452:                                        vertexData[tOffset] = ((TexCoord2f[]) src.refTexCoords[k])[srcOffset].x;
453:                                        vertexData[tOffset + 1] = ((TexCoord2f[]) src.refTexCoords[k])[srcOffset].y;
454:                                        tOffset += texCoordStride;
455:                                    }
456:                                    vOffset += stride;
457:                                }
458:                                base += src.stripIndexCounts[i];
459:                            }
460:                            break;
461:                        case T3F:
462:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
463:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
464:                                    index = j + base;
465:                                    for (k = 0, tOffset = vOffset; k < texCoordSetCount; k++) {
466:                                        srcOffset = src.indexTexCoord[k][index];
467:                                        vertexData[tOffset] = ((TexCoord3f[]) src.refTexCoords[k])[srcOffset].x;
468:                                        vertexData[tOffset + 1] = ((TexCoord3f[]) src.refTexCoords[k])[srcOffset].y;
469:                                        vertexData[tOffset + 2] = ((TexCoord3f[]) src.refTexCoords[k])[srcOffset].z;
470:                                        tOffset += texCoordStride;
471:                                    }
472:                                    vOffset += stride;
473:                                }
474:                                base += src.stripIndexCounts[i];
475:                            }
476:                            break;
477:
478:                        default:
479:                            break;
480:                        }
481:                    }
482:
483:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
484:                        base = src.initialIndexIndex;
485:                        vOffset = 0;
486:                        switch (src.vertexType & VATTR_DEFINED) {
487:                        case AF:
488:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
489:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
490:                                    index = j + base;
491:
492:                                    for (k = 0; k < vertexAttrCount; k++) {
493:                                        System.arraycopy(
494:                                                src.floatRefVertexAttrs[k],
495:                                                src.indexVertexAttr[k][index]
496:                                                        * vertexAttrSizes[k],
497:                                                vertexData, vOffset
498:                                                        + vertexAttrOffsets[k],
499:                                                vertexAttrSizes[k]);
500:                                    }
501:                                    vOffset += stride;
502:                                }
503:                                base += src.stripIndexCounts[i];
504:                            }
505:                            break;
506:                        }
507:                    }
508:
509:                    if ((vertexFormat & GeometryArray.COORDINATES) != 0) {
510:                        vOffset = coordinateOffset;
511:                        base = src.initialIndexIndex;
512:                        switch ((src.vertexType & VERTEX_DEFINED)) {
513:                        case PF:
514:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
515:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
516:                                    index = j + base;
517:                                    System.arraycopy(src.floatRefCoords,
518:                                            src.indexCoord[index] * 3,
519:                                            vertexData, vOffset, 3);
520:                                    vOffset += stride;
521:                                }
522:                                base += src.stripIndexCounts[i];
523:                            }
524:                            break;
525:                        case PD:
526:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
527:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
528:                                    index = src.indexCoord[j + base] * 3;
529:                                    vertexData[vOffset] = (float) src.doubleRefCoords[index];
530:                                    vertexData[vOffset + 1] = (float) src.doubleRefCoords[index + 1];
531:                                    vertexData[vOffset + 2] = (float) src.doubleRefCoords[index + 2];
532:                                    vOffset += stride;
533:                                }
534:                                base += src.stripIndexCounts[i];
535:                            }
536:                            break;
537:                        case P3F:
538:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
539:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
540:                                    index = src.indexCoord[j + base];
541:                                    vertexData[vOffset] = src.p3fRefCoords[index].x;
542:                                    vertexData[vOffset + 1] = src.p3fRefCoords[index].y;
543:                                    vertexData[vOffset + 2] = src.p3fRefCoords[index].z;
544:                                    vOffset += stride;
545:                                }
546:                                base += src.stripIndexCounts[i];
547:                            }
548:                            break;
549:                        case P3D:
550:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
551:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
552:                                    index = src.indexCoord[j + base];
553:                                    vertexData[vOffset] = (float) src.p3dRefCoords[index].x;
554:                                    vertexData[vOffset + 1] = (float) src.p3dRefCoords[index].y;
555:                                    vertexData[vOffset + 2] = (float) src.p3dRefCoords[index].z;
556:                                    vOffset += stride;
557:                                }
558:                                base += src.stripIndexCounts[i];
559:                            }
560:                            break;
561:                        default:
562:                            break;
563:                        }
564:                    }
565:                }
566:            }
567:
568:            private void unIndexifyNIOBuffer(
569:                    IndexedGeometryStripArrayRetained src) {
570:                int vOffset = 0, srcOffset, tOffset = 0;
571:                int base = src.initialIndexIndex;
572:                int i, j, k, index, colorStride = 0;
573:
574:                // interleaved case 
575:                if ((src.vertexFormat & GeometryArray.INTERLEAVED) != 0) {
576:                    if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0)
577:                        colorStride = 4;
578:                    else if ((src.vertexFormat & GeometryArray.COLOR) != 0)
579:                        colorStride = 3;
580:
581:                    for (i = 0; i < src.stripIndexCounts.length; i++) {
582:                        for (j = 0; j < src.stripIndexCounts[i]; j++) {
583:                            index = j + base;
584:                            if ((vertexFormat & GeometryArray.NORMALS) != 0) {
585:                                src.interleavedFloatBufferImpl
586:                                        .position(src.indexNormal[index]
587:                                                * src.stride + src.normalOffset);
588:                                src.interleavedFloatBufferImpl.get(vertexData,
589:                                        vOffset + normalOffset, 3);
590:                            }
591:                            if (colorStride == 4) {
592:                                src.interleavedFloatBufferImpl
593:                                        .position(src.indexColor[index]
594:                                                * src.stride + src.colorOffset);
595:                                src.interleavedFloatBufferImpl.get(vertexData,
596:                                        vOffset + colorOffset, colorStride);
597:                            } else if (colorStride == 3) {
598:                                src.interleavedFloatBufferImpl
599:                                        .position(src.indexColor[index]
600:                                                * src.stride + src.colorOffset);
601:                                src.interleavedFloatBufferImpl.get(vertexData,
602:                                        vOffset + colorOffset, colorStride);
603:                                vertexData[vOffset + colorOffset + 3] = 1.0f;
604:                            }
605:
606:                            if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
607:                                for (k = 0; k < texCoordSetCount; k++) {
608:                                    src.interleavedFloatBufferImpl
609:                                            .position((src.indexTexCoord[k][index])
610:                                                    * src.stride
611:                                                    + src.textureOffset
612:                                                    + src.texCoordSetMapOffset[k]);
613:
614:                                    src.interleavedFloatBufferImpl.get(
615:                                            vertexData, vOffset + textureOffset
616:                                                    + texCoordSetMapOffset[k],
617:                                            texCoordStride);
618:                                }
619:                            }
620:
621:                            if ((vertexFormat & GeometryArray.COORDINATES) != 0) {
622:                                src.interleavedFloatBufferImpl
623:                                        .position(src.indexCoord[index]
624:                                                * src.stride
625:                                                + src.coordinateOffset);
626:                                src.interleavedFloatBufferImpl.get(vertexData,
627:                                        vOffset + coordinateOffset, 3);
628:                            }
629:                            vOffset += stride;
630:                        }
631:                        base += src.stripIndexCounts[i];
632:                    }
633:                } else {
634:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
635:                        base = src.initialIndexIndex;
636:                        vOffset = normalOffset;
637:                        if ((src.vertexType & NORMAL_DEFINED) != 0) {
638:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
639:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
640:                                    index = j + base;
641:                                    src.floatBufferRefNormals
642:                                            .position(src.indexNormal[index] * 3);
643:                                    src.floatBufferRefNormals.get(vertexData,
644:                                            vOffset, 3);
645:                                    vOffset += stride;
646:                                }
647:                                base += src.stripIndexCounts[i];
648:                            }
649:                        }
650:                    }
651:
652:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
653:                        base = src.initialIndexIndex;
654:                        vOffset = colorOffset;
655:                        int multiplier = 3;
656:                        if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0)
657:                            multiplier = 4;
658:
659:                        switch ((src.vertexType & COLOR_DEFINED)) {
660:                        case CF:
661:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
662:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
663:                                    index = j + base;
664:
665:                                    if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0) {
666:                                        src.floatBufferRefColors
667:                                                .position(src.indexColor[index]
668:                                                        * multiplier);
669:                                        src.floatBufferRefColors.get(
670:                                                vertexData, vOffset, 4);
671:
672:                                    } else {
673:                                        src.floatBufferRefColors
674:                                                .position(src.indexColor[index]
675:                                                        * multiplier);
676:                                        src.floatBufferRefColors.get(
677:                                                vertexData, vOffset, 3);
678:
679:                                        vertexData[vOffset + 3] = 1.0f;
680:                                    }
681:                                    vOffset += stride;
682:                                }
683:                                base += src.stripIndexCounts[i];
684:                            }
685:                            break;
686:                        case CUB:
687:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
688:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
689:                                    index = src.indexColor[j + base]
690:                                            * multiplier;
691:                                    vertexData[vOffset] = (src.byteBufferRefColors
692:                                            .get(index) & 0xff)
693:                                            * ByteToFloatScale;
694:                                    vertexData[vOffset + 1] = (src.byteBufferRefColors
695:                                            .get(index + 1) & 0xff)
696:                                            * ByteToFloatScale;
697:                                    ;
698:                                    vertexData[vOffset + 2] = (src.byteBufferRefColors
699:                                            .get(index + 2) & 0xff)
700:                                            * ByteToFloatScale;
701:                                    ;
702:                                    if ((src.vertexFormat & GeometryArray.WITH_ALPHA) != 0) {
703:                                        vertexData[vOffset + 3] = (src.byteBufferRefColors
704:                                                .get(index + 3) & 0xff)
705:                                                * ByteToFloatScale;
706:                                    } else {
707:                                        vertexData[vOffset + 3] = 1.0f;
708:                                    }
709:                                    vOffset += stride;
710:                                }
711:                                base += src.stripIndexCounts[i];
712:                            }
713:                            break;
714:                        default:
715:                            break;
716:                        }
717:                    }
718:
719:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
720:                        base = src.initialIndexIndex;
721:                        vOffset = textureOffset;
722:                        FloatBufferWrapper texBuffer;
723:                        if ((src.vertexType & TEXCOORD_DEFINED) != 0) {
724:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
725:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
726:                                    index = j + base;
727:
728:                                    for (k = 0, tOffset = vOffset; k < texCoordSetCount; k++) {
729:                                        texBuffer = (FloatBufferWrapper) (((J3DBuffer) (src.refTexCoordsBuffer[k]))
730:                                                .getBufferImpl());
731:                                        texBuffer
732:                                                .position(src.indexTexCoord[k][index]
733:                                                        * texCoordStride);
734:                                        texBuffer.get(vertexData, tOffset,
735:                                                texCoordStride);
736:                                        tOffset += texCoordStride;
737:                                    }
738:                                    vOffset += stride;
739:                                }
740:                                base += src.stripIndexCounts[i];
741:                            }
742:                        }
743:                    }
744:
745:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
746:                        base = src.initialIndexIndex;
747:                        vOffset = 0;
748:                        if ((src.vertexType & VATTR_DEFINED) == AF) {
749:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
750:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
751:                                    index = j + base;
752:
753:                                    for (k = 0; k < vertexAttrCount; k++) {
754:                                        int vaOffset = vOffset
755:                                                + vertexAttrOffsets[k];
756:                                        FloatBufferWrapper vaBuffer = src.floatBufferRefVertexAttrs[k];
757:                                        vaBuffer
758:                                                .position(src.indexVertexAttr[k][index]
759:                                                        * vertexAttrSizes[k]);
760:                                        vaBuffer.get(vertexData, vaOffset,
761:                                                vertexAttrSizes[k]);
762:                                    }
763:                                    vOffset += stride;
764:                                }
765:                                base += src.stripIndexCounts[i];
766:                            }
767:                        }
768:                    }
769:
770:                    if ((vertexFormat & GeometryArray.COORDINATES) != 0) {
771:                        vOffset = coordinateOffset;
772:                        base = src.initialIndexIndex;
773:                        switch ((src.vertexType & VERTEX_DEFINED)) {
774:                        case PF:
775:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
776:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
777:                                    index = j + base;
778:                                    src.floatBufferRefCoords
779:                                            .position(src.indexCoord[index] * 3);
780:                                    src.floatBufferRefCoords.get(vertexData,
781:                                            vOffset, 3);
782:
783:                                    vOffset += stride;
784:                                }
785:                                base += src.stripIndexCounts[i];
786:                            }
787:                            break;
788:                        case PD:
789:                            for (i = 0; i < src.stripIndexCounts.length; i++) {
790:                                for (j = 0; j < src.stripIndexCounts[i]; j++) {
791:                                    index = src.indexCoord[j + base] * 3;
792:                                    vertexData[vOffset] = (float) src.doubleBufferRefCoords
793:                                            .get(index);
794:                                    vertexData[vOffset + 1] = (float) src.doubleBufferRefCoords
795:                                            .get(index + 1);
796:                                    vertexData[vOffset + 2] = (float) src.doubleBufferRefCoords
797:                                            .get(index + 2);
798:                                    vOffset += stride;
799:                                }
800:                                base += src.stripIndexCounts[i];
801:                            }
802:                            break;
803:
804:                        default:
805:                            break;
806:                        }
807:                    }
808:                }
809:            }
810:
811:            /**
812:             * Get number of strips in the GeometryStripArray
813:             * @return numStrips number of strips
814:             */
815:            int getNumStrips() {
816:                return stripVertexCounts.length;
817:            }
818:
819:            /**
820:             * Get a list of vertexCounts for each strip
821:             * @param stripVertexCounts an array that will receive vertexCounts
822:             */
823:            void getStripVertexCounts(int stripVertexCounts[]) {
824:
825:                int i, num = this .stripVertexCounts.length;
826:
827:                for (i = 0; i < num; i++) {
828:                    stripVertexCounts[i] = this .stripVertexCounts[i];
829:                }
830:
831:            }
832:
833:            void getStripVertexCounts(int id, int counts[]) {
834:                int stripOffset = compileStripCountOffset[id];
835:                int stripLength = compileNumStrips[id];
836:                System.arraycopy(stripVertexCounts, stripOffset, counts, 0,
837:                        stripLength);
838:            }
839:
840:            int getNumStrips(int id) {
841:                return compileNumStrips[id];
842:            }
843:
844:            // Called only for "by-copy" geometry
845:            void mergeGeometryArrays(ArrayList list) {
846:                int numMerge = list.size();
847:                int numStrips = 0;
848:
849:                for (int i = 0; i < numMerge; i++) {
850:                    numStrips += ((GeometryStripArrayRetained) list.get(i)).stripVertexCounts.length;
851:                }
852:                stripVertexCounts = new int[numStrips];
853:                stripStartVertexIndices = new int[numStrips];
854:                stripStartOffsetIndices = new int[numStrips];
855:                int curStripOffset = 0;
856:                int curStripIndexOffset = 0, stripLength;
857:                int[] curStripVertexCounts;
858:                int[] curStripStartIndices;
859:                int[] curStripOffsetIndices;
860:
861:                compileNumStrips = new int[numMerge];
862:                compileStripCountOffset = new int[numMerge];
863:                for (int i = 0; i < numMerge; i++) {
864:                    GeometryStripArrayRetained strip = (GeometryStripArrayRetained) list
865:                            .get(i);
866:                    curStripVertexCounts = strip.stripVertexCounts;
867:                    curStripStartIndices = strip.stripStartVertexIndices;
868:                    curStripOffsetIndices = strip.stripStartOffsetIndices;
869:                    stripLength = curStripVertexCounts.length;
870:                    compileNumStrips[i] = stripLength;
871:                    compileStripCountOffset[i] = curStripOffset;
872:                    System.arraycopy(curStripVertexCounts, 0,
873:                            stripVertexCounts, curStripOffset, stripLength);
874:                    // Can't just copy StartIndices, have to update to reflect
875:                    // updated vertex position on the merged vertexData
876:                    for (int j = 0; j < stripLength; j++) {
877:                        stripStartVertexIndices[j + curStripOffset] = curStripStartIndices[j]
878:                                + curStripIndexOffset;
879:                        stripStartOffsetIndices[j + curStripOffset] = curStripOffsetIndices[j]
880:                                + curStripIndexOffset;
881:                    }
882:                    curStripOffset += stripLength;
883:                    curStripIndexOffset += strip.validVertexCount;
884:                }
885:                // Assign the merged validVertexCount
886:                validVertexCount = curStripIndexOffset;
887:
888:                // call the super to merge the vertex data
889:                super.mergeGeometryArrays(list);
890:            }
891:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.