forked from hharrison/java3d-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeometryArray.java
More file actions
7467 lines (6571 loc) · 307 KB
/
Copy pathGeometryArray.java
File metadata and controls
7467 lines (6571 loc) · 307 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package org.scijava.java3d;
import org.scijava.vecmath.Color3b;
import org.scijava.vecmath.Color3f;
import org.scijava.vecmath.Color4b;
import org.scijava.vecmath.Color4f;
import org.scijava.vecmath.Point2f;
import org.scijava.vecmath.Point3d;
import org.scijava.vecmath.Point3f;
import org.scijava.vecmath.Point4f;
import org.scijava.vecmath.TexCoord2f;
import org.scijava.vecmath.TexCoord3f;
import org.scijava.vecmath.TexCoord4f;
import org.scijava.vecmath.Vector3f;
/**
* The GeometryArray object contains separate arrays of positional
* coordinates, colors, normals, texture coordinates, and vertex
* attributes that
* describe point, line, or polygon geometry. This class is extended
* to create the various primitive types (such as lines,
* triangle strips, etc.).
* Vertex data may be passed to this geometry array in one of two
* ways: by copying the data into the array using the existing
* methods, or by passing a reference to the data.
* <p>
* <ul>
* <li>
* <b>By Copying:</b>
* The existing methods for setting positional coordinates, colors,
* normals, texture coordinates, and vertex attributes
* (such as <code>setCoordinate</code>,
* <code>setColors</code>, etc.) copy the data into this
* GeometryArray. This is appropriate for many applications and
* offers an application much flexibility in organizing its data.
* This is the default mode.
* </li>
* <li><b>By Reference:</b>
* A new set of methods in Java 3D version 1.2 allows data to be
* accessed by reference, directly from the user's arrays. To use
* this feature, set the <code>BY_REFERENCE</code> bit in the
* <code>vertexFormat</code> field of the constructor for this
* GeometryArray. In this mode, the various set methods for
* coordinates, normals, colors, texture coordinates, and vertex attributes
* are not used.
* Instead, new methods are used to set a reference to user-supplied
* coordinate, color, normal, texture coordinate, and vertex attribute
* arrays (such as
* <code>setCoordRefFloat</code>, <code>setColorRefFloat</code>,
* etc.). Data in any array that is referenced by a live or compiled
* GeometryArray object may only be modified via the
* <code>updateData</code> method (subject to the
* <code>ALLOW_REF_DATA_WRITE</code> capability bit). Applications
* must exercise care not to violate this rule. If any referenced
* geometry data is modified outside of the <code>updateData</code>
* method, the results are undefined.
* </li>
* </ul>
* <p>
* All colors used in the geometry array object must be in the range [0.0,1.0].
* Values outside this range will cause undefined results.
* All normals used in the geometry array object must be unit length
* vectors. That is their geometric length must be 1.0. Normals that
* are not unit length vectors will cause undefined results.
* <p>
* Note that the term <i>coordinate</i>, as used in the method names
* and method descriptions, actually refers to a set of <i>x</i>,
* <i>y</i>, and <i>z</i> coordinates representing the position of a
* single vertex. The term <i>coordinates</i> (plural) is used to
* indicate sets of <i>x</i>, <i>y</i>, and <i>z</i> coordinates for
* multiple vertices. This is somewhat at odds with the mathematical
* definition of a coordinate, but is used as a convenient shorthand.
* Similarly, the term <i>texture coordinate</i> is used to indicate a
* set of texture coordinates for a single vertex, while the term
* <i>texture coordinates</i> (plural) is used to indicate sets of
* texture coordinates for multiple vertices.
*/
public abstract class GeometryArray extends Geometry {
/**
* Specifies that this GeometryArray allows reading the array of
* coordinates.
*/
public static final int
ALLOW_COORDINATE_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_COORDINATE_READ;
/**
* Specifies that this GeometryArray allows writing the array of
* coordinates.
*/
public static final int
ALLOW_COORDINATE_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_COORDINATE_WRITE;
/**
* Specifies that this GeometryArray allows reading the array of
* colors.
*/
public static final int
ALLOW_COLOR_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_COLOR_READ;
/**
* Specifies that this GeometryArray allows writing the array of
* colors.
*/
public static final int
ALLOW_COLOR_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_COLOR_WRITE;
/**
* Specifies that this GeometryArray allows reading the array of
* normals.
*/
public static final int
ALLOW_NORMAL_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_NORMAL_READ;
/**
* Specifies that this GeometryArray allows writing the array of
* normals.
*/
public static final int
ALLOW_NORMAL_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_NORMAL_WRITE;
/**
* Specifies that this GeometryArray allows reading the array of
* texture coordinates.
*/
public static final int
ALLOW_TEXCOORD_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_TEXCOORD_READ;
/**
* Specifies that this GeometryArray allows writing the array of
* texture coordinates.
*/
public static final int
ALLOW_TEXCOORD_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_TEXCOORD_WRITE;
/**
* Specifies that this GeometryArray allows reading the array of
* vertex attributes.
*
* @since Java 3D 1.4
*/
public static final int
ALLOW_VERTEX_ATTR_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_VERTEX_ATTR_READ;
/**
* Specifies that this GeometryArray allows writing the array of
* vertex attributes.
*
* @since Java 3D 1.4
*/
public static final int
ALLOW_VERTEX_ATTR_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_VERTEX_ATTR_WRITE;
/**
* Specifies that this GeometryArray allows reading the count or
* initial index information for this object.
*/
public static final int
ALLOW_COUNT_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_COUNT_READ;
/**
* Specifies that this GeometryArray allows writing the count or
* initial index information for this object.
*
* @since Java 3D 1.2
*/
public static final int
ALLOW_COUNT_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_COUNT_WRITE;
/**
* Specifies that this GeometryArray allows reading the vertex format
* information for this object.
*/
public static final int
ALLOW_FORMAT_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_FORMAT_READ;
/**
* Specifies that this GeometryArray allows reading the geometry
* data reference information for this object. This is only used in
* by-reference geometry mode.
*
* @since Java 3D 1.2
*/
public static final int
ALLOW_REF_DATA_READ = CapabilityBits.GEOMETRY_ARRAY_ALLOW_REF_DATA_READ;
private static final int J3D_1_2_ALLOW_REF_DATA_READ =
CapabilityBits.J3D_1_2_GEOMETRY_ARRAY_ALLOW_REF_DATA_READ;
/**
* Specifies that this GeometryArray allows writing the geometry
* data reference information for this object. It also enables
* writing the referenced data itself, via the GeometryUpdater
* interface. This is only used in by-reference geometry mode.
*
* @since Java 3D 1.2
*/
public static final int
ALLOW_REF_DATA_WRITE = CapabilityBits.GEOMETRY_ARRAY_ALLOW_REF_DATA_WRITE;
/**
* Specifies that this GeometryArray contains an array of coordinates.
* This bit must be set.
*/
public static final int COORDINATES = 0x01;
/**
* Specifies that this GeometryArray contains an array of normals.
*/
public static final int NORMALS = 0x02;
/**
* Specifies that this GeometryArray contains an array of colors.
*/
static final int COLOR = 0x04;
/**
* Specifies that this GeometryArray's colors contain alpha.
*/
static final int WITH_ALPHA = 0x08;
/**
* Specifies that this GeometryArray contains an array of colors without alpha.
*/
public static final int COLOR_3 = COLOR;
/**
* Specifies that this GeometryArray contains an array of colors with alpha.
* This takes precedence over COLOR_3.
*/
public static final int COLOR_4 = COLOR | WITH_ALPHA;
/**
* Specifies that this GeometryArray contains one or more arrays of
* 2D texture coordinates.
*/
public static final int TEXTURE_COORDINATE_2 = 0x20;
/**
* Specifies that this GeometryArray contains one or more arrays of
* 3D texture coordinates.
* This takes precedence over TEXTURE_COORDINATE_2.
*/
public static final int TEXTURE_COORDINATE_3 = 0x40;
/**
* Specifies that this GeometryArray contains one or more arrays of
* 4D texture coordinates.
* This takes precedence over TEXTURE_COORDINATE_2 and TEXTURE_COORDINATE_3.
*
* @since Java 3D 1.3
*/
public static final int TEXTURE_COORDINATE_4 = 0x400;
static final int TEXTURE_COORDINATE = TEXTURE_COORDINATE_2 |
TEXTURE_COORDINATE_3 |
TEXTURE_COORDINATE_4;
/**
* Specifies that the position, color, normal, and texture coordinate
* data for this GeometryArray are accessed by reference.
*
* @since Java 3D 1.2
*/
public static final int BY_REFERENCE = 0x80;
/**
* Specifies that the position, color, normal, and texture
* coordinate data for this GeometryArray are accessed via a single
* interleaved, floating-point array reference. All of the data
* values for each vertex are stored in consecutive memory
* locations. This flag is only valid in conjunction with the
* <code>BY_REFERENCE</code> flag.
*
* @since Java 3D 1.2
*/
public static final int INTERLEAVED = 0x100;
/**
* Specifies that geometry by-reference data for this
* GeometryArray, whether interleaved or non-interleaved, is
* accessed via J3DBuffer objects that wrap NIO Buffer objects,
* rather than float, double, byte, or TupleXX arrays. This flag
* is only valid in conjunction with the <code>BY_REFERENCE</code>
* flag.
*
* @see J3DBuffer
* @see #setCoordRefBuffer(J3DBuffer)
* @see #setColorRefBuffer(J3DBuffer)
* @see #setNormalRefBuffer(J3DBuffer)
* @see #setTexCoordRefBuffer(int,J3DBuffer)
* @see #setVertexAttrRefBuffer(int,J3DBuffer)
* @see #setInterleavedVertexBuffer(J3DBuffer)
*
* @since Java 3D 1.3
*/
public static final int USE_NIO_BUFFER = 0x800;
/**
* Specifies that only the coordinate indices are used for indexed
* geometry arrays. In this mode, the values from the coordinate
* index array are used as a single set of index values to access
* the vertex data for all five vertex components (coord, color,
* normal, texCoord, and vertexAttr). The color, normal, texCoord,
* and vertexAttr index arrays are neither allocated nor used. Any
* attempt to access the color, normal, texCoord,
* or vertexAttr index arrays will result in a NullPointerException.
* This flag is only valid for indexed geometry arrays
* (subclasses of IndexedGeometryArray).
*
* @since Java 3D 1.3
*/
public static final int USE_COORD_INDEX_ONLY = 0x200;
/**
* Specifies that this GeometryArray contains one or more arrays of
* vertex attributes. These attributes are used in programmable
* shading.
*
* @since Java 3D 1.4
*/
public static final int VERTEX_ATTRIBUTES = 0x1000;
//NVaidya
/**
* Specifies that the indices in this GeometryArray
* are accessed by reference. This flag is only valid for
* indexed geometry arrays (subclasses of IndexedGeometryArray) and only
* when used in conjunction with the <code>BY_REFERENCE</code> and
* <code>USE_COORD_INDEX_ONLY</code> flags.
*
* @since Java 3D 1.5
*/
public static final int BY_REFERENCE_INDICES = 0x2000;
// Used to keep track of the last bit (for adding new bits only)
private static final int LAST_FORMAT_BIT = 0x2000;
// Scratch arrays for converting Point[234]f to TexCoord[234]f
private TexCoord2f [] texCoord2fArray = null;
private TexCoord3f [] texCoord3fArray = null;
private TexCoord4f [] texCoord4fArray = null;
private TexCoord2f texCoord2fScratch = null;
private TexCoord3f texCoord3fScratch = null;
private static final int[] defTexCoordMap = { 0 };
// Array for setting default read capabilities
private static final int[] readCapabilities = {
ALLOW_COLOR_READ,
ALLOW_COORDINATE_READ,
ALLOW_COUNT_READ,
ALLOW_FORMAT_READ,
ALLOW_NORMAL_READ,
ALLOW_REF_DATA_READ,
ALLOW_TEXCOORD_READ,
ALLOW_VERTEX_ATTR_READ
};
// non-public, no parameter constructor
GeometryArray() {
// set default read capabilities
setDefaultReadCapabilities(readCapabilities);
}
//NVaidya
/**
* Constructs an empty GeometryArray object with the specified
* number of vertices and vertex format. Defaults are used
* for all other parameters. The default values are as follows:
* <ul>
* texCoordSetCount : 1<br>
* texCoordSetMap : { 0 }<br>
* vertexAttrCount : 0<br>
* vertexAttrSizes : null<br>
* validVertexCount : vertexCount<br>
* initialVertexIndex : 0<br>
* initialCoordIndex : 0<br>
* initialColorIndex : 0<br>
* initialNormalIndex : 0<br>
* initialTexCoordIndex : 0<br>
* initialVertexAttrIndex : 0<br>
* all data array values : 0.0<br>
* all data array references : null<br>
* </ul>
*
* @param vertexCount the number of vertex elements in this GeometryArray
* @param vertexFormat a mask indicating which components are
* present in each vertex. This is specified as one or more
* individual flags that are bitwise "OR"ed together to describe
* the per-vertex data.
* The flags include: <code>COORDINATES</code>, to signal the inclusion of
* vertex positions--always present; <code>NORMALS</code>, to signal
* the inclusion of per vertex normals; one of <code>COLOR_3</code> or
* <code>COLOR_4</code>, to signal the inclusion of per vertex
* colors (without or with alpha information); one of
* <code>TEXTURE_COORDINATE_2</code>, <code>TEXTURE_COORDINATE_3</code>
* or <code>TEXTURE_COORDINATE_4</code>,
* to signal the
* inclusion of per-vertex texture coordinates (2D, 3D or 4D);
* <code>BY_REFERENCE</code>, to indicate that the data is passed
* by reference
* rather than by copying; <code>INTERLEAVED</code>, to indicate
* that the referenced
* data is interleaved in a single array;
* <code>USE_NIO_BUFFER</code>, to indicate that the referenced data
* is accessed via a J3DBuffer object that wraps an NIO buffer;
* <code>USE_COORD_INDEX_ONLY</code>,
* to indicate that only the coordinate indices are used for indexed
* geometry arrays;
* <code>BY_REFERENCE_INDICES</code>, to indicate
* that the indices are accessed by reference in indexed
* geometry arrays.<p>
*
* @exception IllegalArgumentException if vertexCount < 0
*
* @exception IllegalArgumentException if vertexFormat does <b>not</b>
* include <code>COORDINATES</code>
*
* @exception IllegalArgumentException if the <code>USE_COORD_INDEX_ONLY</code>
* bit or the <code>BY_REFERENCE_INDICES</code> bit is set for
* non-indexed geometry arrays (that is, GeometryArray objects
* that are not a subclass of IndexedGeometryArray)
*
* @exception IllegalArgumentException if the <code>INTERLEAVED</code>
* bit is set without the <code>BY_REFERENCE</code> bit being set
*
* @exception IllegalArgumentException if the <code>USE_NIO_BUFFER</code>
* bit is set without the <code>BY_REFERENCE</code> bit being set
*
* @exception IllegalArgumentException if the <code>INTERLEAVED</code>
* bit and the <code>VERTEX_ATTRIBUTES</code> bit are both set
*
* @exception IllegalArgumentException if the
* <code>BY_REFERENCE_INDICES</code>
* bit is set without the <code>BY_REFERENCE</code> and
* <code>USE_COORD_INDEX_ONLY</code> bits being set
*/
public GeometryArray(int vertexCount, int vertexFormat) {
this(vertexCount, vertexFormat,
((vertexFormat & TEXTURE_COORDINATE) != 0 ? 1 : 0),
((vertexFormat & TEXTURE_COORDINATE) != 0 ? defTexCoordMap : null));
}
//NVaidya
/**
* Constructs an empty GeometryArray object with the specified
* number of vertices, vertex format, number of texture coordinate
* sets, and texture coordinate mapping array. Defaults are used
* for all other parameters.
*
* @param vertexCount the number of vertex elements in this
* GeometryArray<p>
*
* @param vertexFormat a mask indicating which components are
* present in each vertex. This is specified as one or more
* individual flags that are bitwise "OR"ed together to describe
* the per-vertex data.
* The flags include: <code>COORDINATES</code>, to signal the inclusion of
* vertex positions--always present; <code>NORMALS</code>, to signal
* the inclusion of per vertex normals; one of <code>COLOR_3</code> or
* <code>COLOR_4</code>, to signal the inclusion of per vertex
* colors (without or with alpha information); one of
* <code>TEXTURE_COORDINATE_2</code> or <code>TEXTURE_COORDINATE_3</code>
* or <code>TEXTURE_COORDINATE_4</code>,
* to signal the
* inclusion of per-vertex texture coordinates (2D , 3D or 4D);
* <code>BY_REFERENCE</code>, to indicate that the data is passed
* by reference
* rather than by copying; <code>INTERLEAVED</code>, to indicate
* that the referenced
* data is interleaved in a single array;
* <code>USE_NIO_BUFFER</code>, to indicate that the referenced data
* is accessed via a J3DBuffer object that wraps an NIO buffer;
* <code>USE_COORD_INDEX_ONLY</code>,
* to indicate that only the coordinate indices are used for indexed
* geometry arrays;
* <code>BY_REFERENCE_INDICES</code>, to indicate
* that the indices are accessed by reference in indexed
* geometry arrays.<p>
*
* @param texCoordSetCount the number of texture coordinate sets
* in this GeometryArray object. If <code>vertexFormat</code>
* does not include one of <code>TEXTURE_COORDINATE_2</code> or
* <code>TEXTURE_COORDINATE_3</code>, the
* <code>texCoordSetCount</code> parameter is not used.<p>
*
* <a name="texCoordSetMap">
* @param texCoordSetMap an array that maps texture coordinate
* sets to texture units. The array is indexed by texture unit
* number for each texture unit in the associated Appearance
* object. The values in the array specify the texture coordinate
* set within this GeometryArray object that maps to the
* corresponding texture
* unit. All elements within the array must be less than
* <code>texCoordSetCount</code>. A negative value specifies that
* no texture coordinate set maps to the texture unit
* corresponding to the index. If there are more texture units in
* any associated Appearance object than elements in the mapping
* array, the extra elements are assumed to be -1. The same
* texture coordinate set may be used for more than one texture
* unit. Each texture unit in every associated Appearance must
* have a valid source of texture coordinates: either a
* non-negative texture coordinate set must be specified in the
* mapping array or texture coordinate generation must be enabled.
* Texture coordinate generation will take precedence for those
* texture units for which a texture coordinate set is specified
* and texture coordinate generation is enabled. If
* <code>vertexFormat</code> does not include one of
* <code>TEXTURE_COORDINATE_2</code> or
* <code>TEXTURE_COORDINATE_3</code> or
* <code>TEXTURE_COORDINATE_4</code>, the
* <code>texCoordSetMap</code> array is not used. The following example
* illustrates the use of the <code>texCoordSetMap</code> array.
*
* <p>
* <ul>
* <table BORDER=1 CELLSPACING=2 CELLPADDING=2>
* <tr>
* <td><center><b>Index</b></center></td>
* <td><center><b>Element</b></center></td>
* <td><b>Description</b></td>
* </tr>
* <tr>
* <td><center>0</center></td>
* <td><center>1</center></td>
* <td>Use tex coord set 1 for tex unit 0</td>
* </tr>
* <tr>
* <td><center>1</center></td>
* <td><center>-1</center></td>
* <td>Use no tex coord set for tex unit 1</td>
* </tr>
* <tr>
* <td><center>2</center></td>
* <td><center>0</center></td>
* <td>Use tex coord set 0 for tex unit 2</td>
* </tr>
* <tr>
* <td><center>3</center></td>
* <td><center>1</center></td>
* <td>Reuse tex coord set 1 for tex unit 3</td>
* </tr>
* </table>
* </ul>
* <p>
*
* @exception IllegalArgumentException if vertexCount < 0
*
* @exception IllegalArgumentException if vertexFormat does <b>not</b>
* include <code>COORDINATES</code>
*
* @exception IllegalArgumentException if the <code>USE_COORD_INDEX_ONLY</code>
* bit or the <code>BY_REFERENCE_INDICES</code> bit is set for
* non-indexed geometry arrays (that is, GeometryArray objects
* that are not a subclass of IndexedGeometryArray)
*
* @exception IllegalArgumentException if the <code>INTERLEAVED</code>
* bit is set without the <code>BY_REFERENCE</code> bit being set
*
* @exception IllegalArgumentException if the <code>USE_NIO_BUFFER</code>
* bit is set without the <code>BY_REFERENCE</code> bit being set
*
* @exception IllegalArgumentException if the <code>INTERLEAVED</code>
* bit and the <code>VERTEX_ATTRIBUTES</code> bit are both set
*
* @exception IllegalArgumentException if the
* <code>BY_REFERENCE_INDICES</code>
* bit is set without the <code>BY_REFERENCE</code> and
* <code>USE_COORD_INDEX_ONLY</code> bits being set
*
* @exception IllegalArgumentException if
* <code>texCoordSetCount < 0</code>
*
* @exception IllegalArgumentException if any element in
* <code>texCoordSetMap[] >= texCoordSetCount</code>.
*
* @since Java 3D 1.2
*/
public GeometryArray(int vertexCount,
int vertexFormat,
int texCoordSetCount,
int[] texCoordSetMap) {
this(vertexCount, vertexFormat, texCoordSetCount, texCoordSetMap, 0, null);
}
//NVaidya
/**
* Constructs an empty GeometryArray object with the specified
* number of vertices, vertex format, number of texture coordinate
* sets, texture coordinate mapping array, vertex attribute count,
* and vertex attribute sizes array.
*
* @param vertexCount the number of vertex elements in this
* GeometryArray<p>
*
* @param vertexFormat a mask indicating which components are
* present in each vertex. This is specified as one or more
* individual flags that are bitwise "OR"ed together to describe
* the per-vertex data.
* The flags include: <code>COORDINATES</code>, to signal the inclusion of
* vertex positions--always present; <code>NORMALS</code>, to signal
* the inclusion of per vertex normals; one of <code>COLOR_3</code> or
* <code>COLOR_4</code>, to signal the inclusion of per vertex
* colors (without or with alpha information); one of
* <code>TEXTURE_COORDINATE_2</code> or <code>TEXTURE_COORDINATE_3</code>
* or <code>TEXTURE_COORDINATE_4</code>,
* to signal the
* inclusion of per-vertex texture coordinates (2D , 3D or 4D);
* <code>VERTEX_ATTRIBUTES</code>, to signal
* the inclusion of one or more arrays of vertex attributes;
* <code>BY_REFERENCE</code>, to indicate that the data is passed
* by reference
* rather than by copying; <code>INTERLEAVED</code>, to indicate
* that the referenced
* data is interleaved in a single array;
* <code>USE_NIO_BUFFER</code>, to indicate that the referenced data
* is accessed via a J3DBuffer object that wraps an NIO buffer;
* <code>USE_COORD_INDEX_ONLY</code>,
* to indicate that only the coordinate indices are used for indexed
* geometry arrays;
* <code>BY_REFERENCE_INDICES</code>, to indicate
* that the indices are accessed by reference in indexed
* geometry arrays.<p>
*
* @param texCoordSetCount the number of texture coordinate sets
* in this GeometryArray object. If <code>vertexFormat</code>
* does not include one of <code>TEXTURE_COORDINATE_2</code> or
* <code>TEXTURE_COORDINATE_3</code>, the
* <code>texCoordSetCount</code> parameter is not used.<p>
*
* <a name="texCoordSetMap">
* @param texCoordSetMap an array that maps texture coordinate
* sets to texture units. The array is indexed by texture unit
* number for each texture unit in the associated Appearance
* object. The values in the array specify the texture coordinate
* set within this GeometryArray object that maps to the
* corresponding texture
* unit. All elements within the array must be less than
* <code>texCoordSetCount</code>. A negative value specifies that
* no texture coordinate set maps to the texture unit
* corresponding to the index. If there are more texture units in
* any associated Appearance object than elements in the mapping
* array, the extra elements are assumed to be -1. The same
* texture coordinate set may be used for more than one texture
* unit. Each texture unit in every associated Appearance must
* have a valid source of texture coordinates: either a
* non-negative texture coordinate set must be specified in the
* mapping array or texture coordinate generation must be enabled.
* Texture coordinate generation will take precedence for those
* texture units for which a texture coordinate set is specified
* and texture coordinate generation is enabled. If
* <code>vertexFormat</code> does not include one of
* <code>TEXTURE_COORDINATE_2</code> or
* <code>TEXTURE_COORDINATE_3</code> or
* <code>TEXTURE_COORDINATE_4</code>, the
* <code>texCoordSetMap</code> array is not used. The following example
* illustrates the use of the <code>texCoordSetMap</code> array.
*
* <p>
* <ul>
* <table BORDER=1 CELLSPACING=2 CELLPADDING=2>
* <tr>
* <td><center><b>Index</b></center></td>
* <td><center><b>Element</b></center></td>
* <td><b>Description</b></td>
* </tr>
* <tr>
* <td><center>0</center></td>
* <td><center>1</center></td>
* <td>Use tex coord set 1 for tex unit 0</td>
* </tr>
* <tr>
* <td><center>1</center></td>
* <td><center>-1</center></td>
* <td>Use no tex coord set for tex unit 1</td>
* </tr>
* <tr>
* <td><center>2</center></td>
* <td><center>0</center></td>
* <td>Use tex coord set 0 for tex unit 2</td>
* </tr>
* <tr>
* <td><center>3</center></td>
* <td><center>1</center></td>
* <td>Reuse tex coord set 1 for tex unit 3</td>
* </tr>
* </table>
* </ul>
* <p>
*
* @param vertexAttrCount the number of vertex attributes
* in this GeometryArray object. If <code>vertexFormat</code>
* does not include <code>VERTEX_ATTRIBUTES</code>, the
* <code>vertexAttrCount</code> parameter must be 0.<p>
*
* @param vertexAttrSizes is an array that specifes the size of
* each vertex attribute. Each element in the array specifies the
* number of components in the attribute, from 1 to 4. The length
* of the array must be equal to <code>vertexAttrCount</code>.<p>
*
* @exception IllegalArgumentException if vertexCount < 0
*
* @exception IllegalArgumentException if vertexFormat does <b>not</b>
* include <code>COORDINATES</code>
*
* @exception IllegalArgumentException if the <code>USE_COORD_INDEX_ONLY</code>
* bit or the <code>BY_REFERENCE_INDICES</code> bit is set for
* non-indexed geometry arrays (that is, GeometryArray objects
* that are not a subclass of IndexedGeometryArray)
*
* @exception IllegalArgumentException if the <code>INTERLEAVED</code>
* bit is set without the <code>BY_REFERENCE</code> bit being set
*
* @exception IllegalArgumentException if the <code>USE_NIO_BUFFER</code>
* bit is set without the <code>BY_REFERENCE</code> bit being set
*
* @exception IllegalArgumentException if the <code>INTERLEAVED</code>
* bit and the <code>VERTEX_ATTRIBUTES</code> bit are both set
*
* @exception IllegalArgumentException if the
* <code>BY_REFERENCE_INDICES</code>
* bit is set without the <code>BY_REFERENCE</code> and
* <code>USE_COORD_INDEX_ONLY</code> bits being set
*
* @exception IllegalArgumentException if
* <code>texCoordSetCount < 0</code>
*
* @exception IllegalArgumentException if any element in
* <code>texCoordSetMap[] >= texCoordSetCount</code>.
*
* @exception IllegalArgumentException if
* <code>vertexAttrCount > 0</code> and the
* <code>VERTEX_ATTRIBUTES</code> bit is not set
*
* @exception IllegalArgumentException if
* <code>vertexAttrCount < 0</code>
*
* @exception IllegalArgumentException if
* <code>vertexAttrSizes.length != vertexAttrCount</code>
*
* @exception IllegalArgumentException if any element in
* <code>vertexAttrSizes[]</code> is <code>< 1</code> or
* <code>> 4</code>.
*
* @since Java 3D 1.4
*/
public GeometryArray(int vertexCount,
int vertexFormat,
int texCoordSetCount,
int[] texCoordSetMap,
int vertexAttrCount,
int[] vertexAttrSizes) {
if (vertexCount < 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray96"));
if (texCoordSetCount < 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray124"));
if (vertexAttrCount < 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray125"));
if ((vertexFormat & COORDINATES) == 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray0"));
if ((vertexFormat & INTERLEAVED) != 0 &&
(vertexFormat & BY_REFERENCE) == 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray80"));
if ((vertexFormat & INTERLEAVED) != 0 &&
(vertexFormat & VERTEX_ATTRIBUTES) != 0) {
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray128"));
}
if ((vertexFormat & USE_COORD_INDEX_ONLY) != 0 &&
!(this instanceof IndexedGeometryArray)) {
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray135"));
}
//NVaidya
if ((vertexFormat & BY_REFERENCE_INDICES) != 0) {
if (!(this instanceof IndexedGeometryArray))
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray136"));
if ((vertexFormat & BY_REFERENCE) == 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray137"));
if ((vertexFormat & USE_COORD_INDEX_ONLY) == 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray138"));
}
if ((vertexFormat & USE_NIO_BUFFER) != 0 &&
(vertexFormat & BY_REFERENCE) == 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray117"));
if ((vertexFormat & TEXTURE_COORDINATE) != 0) {
if (texCoordSetMap == null)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray106"));
if (texCoordSetCount == 0)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray107"));
for (int i = 0; i < texCoordSetMap.length; i++) {
if (texCoordSetMap[i] >= texCoordSetCount)
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray108"));
}
if ((vertexFormat & TEXTURE_COORDINATE_2) != 0) {
texCoord2fArray = new TexCoord2f[1];
texCoord2fScratch = new TexCoord2f();
}
else if ((vertexFormat & TEXTURE_COORDINATE_3) != 0) {
texCoord3fArray = new TexCoord3f[1];
texCoord3fScratch = new TexCoord3f();
}
else if ((vertexFormat & TEXTURE_COORDINATE_4) != 0) {
texCoord4fArray = new TexCoord4f[1];
}
}
if ((vertexFormat & VERTEX_ATTRIBUTES) != 0) {
if (vertexAttrCount > 0) {
if (vertexAttrCount != vertexAttrSizes.length) {
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray132"));
}
for (int i = 0; i < vertexAttrSizes.length; i++) {
if (vertexAttrSizes[i] < 1 || vertexAttrSizes[i] > 4) {
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray133"));
}
}
} else {
if (vertexAttrSizes != null && vertexAttrSizes.length != 0) {
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray132"));
}
}
} else {
if (vertexAttrCount > 0) {
throw new IllegalArgumentException(J3dI18N.getString("GeometryArray131"));
}
}
// set default read capabilities
setDefaultReadCapabilities(readCapabilities);
((GeometryArrayRetained)this.retained).createGeometryArrayData(
vertexCount, vertexFormat,
texCoordSetCount, texCoordSetMap,
vertexAttrCount, vertexAttrSizes);
}
//------------------------------------------------------------------
// Common methods
//------------------------------------------------------------------
/**
* Retrieves the number of vertices in this GeometryArray
* @return number of vertices in this GeometryArray
* @exception CapabilityNotSetException if the appropriate capability is
* not set and this object is part of a live or compiled scene graph
*/
public int getVertexCount() {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_COUNT_READ))
throw new CapabilityNotSetException(J3dI18N.getString("GeometryArray1"));
return ((GeometryArrayRetained)this.retained).getVertexCount();
}
/**
* Retrieves the vertexFormat of this GeometryArray
* @return format of vertices in this GeometryArray
* @exception CapabilityNotSetException if the appropriate capability is
* not set and this object is part of a live or compiled scene graph
*/
public int getVertexFormat() {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_FORMAT_READ))
throw new CapabilityNotSetException(J3dI18N.getString("GeometryArray2"));
return ((GeometryArrayRetained)this.retained).getVertexFormat();
}
/**
* Retrieves the number of texture coordinate sets in this
* GeometryArray object.
*
* @return the number of texture coordinate sets
* in this GeometryArray object
*
* @since Java 3D 1.2
*/
public int getTexCoordSetCount() {
return ((GeometryArrayRetained)this.retained).getTexCoordSetCount();
}
/**
* Retrieves the length of the texture coordinate set mapping
* array of this GeometryArray object.
*
* @return the length of the texture coordinate set mapping
* array of this GeometryArray object
*
* @since Java 3D 1.2
*/
public int getTexCoordSetMapLength() {
return ((GeometryArrayRetained)this.retained).getTexCoordSetMapLength();
}
/**
* Retrieves the texture coordinate set mapping
* array from this GeometryArray object.
*
* @param texCoordSetMap an array that will receive a copy of the
* texture coordinate set mapping array. The array must be large
* enough to hold all entries of the texture coordinate set
* mapping array.
*
* @since Java 3D 1.2
*/
public void getTexCoordSetMap(int[] texCoordSetMap) {
((GeometryArrayRetained)this.retained).getTexCoordSetMap(texCoordSetMap);
}
/**
* Retrieves the number of vertex attributes in this GeometryArray
* object.
*
* @return the number of vertex attributes in this GeometryArray
* object
*
* @since Java 3D 1.4
*/
public int getVertexAttrCount() {
return ((GeometryArrayRetained)this.retained).getVertexAttrCount();
}
/**
* Retrieves the vertex attribute sizes array from this
* GeometryArray object.
*
* @param vertexAttrSizes an array that will receive a copy of
* the vertex attribute sizes array. The array must hold at least
* <code>vertexAttrCount</code> elements.
*
* @since Java 3D 1.4
*/
public void getVertexAttrSizes(int[] vertexAttrSizes) {
((GeometryArrayRetained)this.retained).getVertexAttrSizes(vertexAttrSizes);
}
/**
* Updates geometry array data that is accessed by reference.
* This method calls the updateData method of the specified
* GeometryUpdater object to synchronize updates to vertex
* data that is referenced by this GeometryArray object.
* Applications that wish to modify such data must perform all
* updates via this method.
* <p>