1 /*
2  * $RCSfile: TriangleStripArray.java,v $
3  *
4  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This code is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 only, as
9  * published by the Free Software Foundation.  Sun designates this
10  * particular file as subject to the "Classpath" exception as provided
11  * by Sun in the LICENSE file that accompanied this code.
12  *
13  * This code is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16  * version 2 for more details (a copy is included in the LICENSE file that
17  * accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License version
20  * 2 along with this work; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24  * CA 95054 USA or visit www.sun.com if you need additional information or
25  * have any questions.
26  *
27  * $Revision: 1.6 $
28  * $Date: 2008/02/28 20:17:32 $
29  * $State: Exp $
30  */
31 
32 package javax.media.j3d;
33 
34 
35 /**
36  * The TriangleStripArray object draws an array of vertices as a set of
37  * connected triangle strips.  An array of per-strip vertex counts specifies
38  * where the separate strips appear in the vertex array.
39  * For every strip in the set,
40  * each vertex, beginning with the third vertex in the array,
41  * defines a triangle to be drawn using the current vertex and
42  * the two previous vertices.
43  */
44 
45 public class TriangleStripArray extends GeometryStripArray {
46 
47     // non-public, no parameter constructor
TriangleStripArray()48     TriangleStripArray() {}
49 
50     /**
51      * Constructs an empty TriangleStripArray object using the
52      * specified parameters.
53      *
54      * @param vertexCount
55      * see {@link GeometryArray#GeometryArray(int,int)}
56      * for a description of this parameter.
57      *
58      * @param vertexFormat
59      * see {@link GeometryArray#GeometryArray(int,int)}
60      * for a description of this parameter.
61      *
62      * @param stripVertexCounts
63      * see {@link GeometryStripArray#GeometryStripArray(int,int,int[])}
64      * for a description of this parameter.
65      *
66      * @exception IllegalArgumentException if vertexCount is less than 3
67      * or any element in the stripVertexCounts array is less than 3
68      * ;<br>
69      * See {@link GeometryStripArray#GeometryStripArray(int,int,int[])}
70      * for more exceptions that can be thrown
71      */
TriangleStripArray(int vertexCount, int vertexFormat, int stripVertexCounts[])72     public TriangleStripArray(int vertexCount,
73 			      int vertexFormat,
74 			      int stripVertexCounts[]) {
75 
76 	super(vertexCount, vertexFormat, stripVertexCounts);
77 
78         if (vertexCount < 3 )
79 	    throw new IllegalArgumentException(J3dI18N.getString("TriangleStripArray0"));
80     }
81 
82     /**
83      * Constructs an empty TriangleStripArray object using the
84      * specified parameters.
85      *
86      * @param vertexCount
87      * see {@link GeometryArray#GeometryArray(int,int,int,int[])}
88      * for a description of this parameter.
89      *
90      * @param vertexFormat
91      * see {@link GeometryArray#GeometryArray(int,int,int,int[])}
92      * for a description of this parameter.
93      *
94      * @param texCoordSetCount
95      * see {@link GeometryArray#GeometryArray(int,int,int,int[])}
96      * for a description of this parameter.
97      *
98      * @param texCoordSetMap
99      * see {@link GeometryArray#GeometryArray(int,int,int,int[])}
100      * for a description of this parameter.
101      *
102      * @param stripVertexCounts
103      * see {@link GeometryStripArray#GeometryStripArray(int,int,int,int[],int[])}
104      * for a description of this parameter.
105      *
106      * @exception IllegalArgumentException if vertexCount is less than 3
107      * or any element in the stripVertexCounts array is less than 3
108      * ;<br>
109      * See {@link GeometryStripArray#GeometryStripArray(int,int,int,int[],int[])}
110      * for more exceptions that can be thrown
111      *
112      * @since Java 3D 1.2
113      */
TriangleStripArray(int vertexCount, int vertexFormat, int texCoordSetCount, int[] texCoordSetMap, int stripVertexCounts[])114     public TriangleStripArray(int vertexCount,
115 			      int vertexFormat,
116 			      int texCoordSetCount,
117 			      int[] texCoordSetMap,
118 			      int stripVertexCounts[]) {
119 
120 	super(vertexCount, vertexFormat,
121 	      texCoordSetCount, texCoordSetMap,
122 	      stripVertexCounts);
123 
124         if (vertexCount < 3 )
125 	    throw new IllegalArgumentException(J3dI18N.getString("TriangleStripArray0"));
126     }
127 
128     /**
129      * Constructs an empty TriangleStripArray object using the
130      * specified parameters.
131      *
132      * @param vertexCount
133      * see {@link GeometryArray#GeometryArray(int,int,int,int[],int,int[])}
134      * for a description of this parameter.
135      *
136      * @param vertexFormat
137      * see {@link GeometryArray#GeometryArray(int,int,int,int[],int,int[])}
138      * for a description of this parameter.
139      *
140      * @param texCoordSetMap
141      * see {@link GeometryArray#GeometryArray(int,int,int,int[],int,int[])}
142      * for a description of this parameter.
143      *
144      * @param vertexAttrCount
145      * see {@link GeometryArray#GeometryArray(int,int,int,int[],int,int[])}
146      * for a description of this parameter.
147      *
148      * @param vertexAttrSizes
149      * see {@link GeometryArray#GeometryArray(int,int,int,int[],int,int[])}
150      * for a description of this parameter.
151      *
152      * @param stripVertexCounts
153      * see {@link GeometryStripArray#GeometryStripArray(int,int,int,int[],int,int[],int[])}
154      * for a description of this parameter.
155      *
156      * @exception IllegalArgumentException if vertexCount is less than 3
157      * or any element in the stripVertexCounts array is less than 3
158      * ;<br>
159      * See {@link GeometryStripArray#GeometryStripArray(int,int,int,int[],int,int[],int[])}
160      * for more exceptions that can be thrown
161      *
162      * @since Java 3D 1.4
163      */
TriangleStripArray(int vertexCount, int vertexFormat, int texCoordSetCount, int[] texCoordSetMap, int vertexAttrCount, int[] vertexAttrSizes, int[] stripVertexCounts)164     public TriangleStripArray(int vertexCount,
165 			      int vertexFormat,
166 			      int texCoordSetCount,
167 			      int[] texCoordSetMap,
168 			      int vertexAttrCount,
169 			      int[] vertexAttrSizes,
170 			      int[] stripVertexCounts) {
171 
172 	super(vertexCount, vertexFormat,
173 	      texCoordSetCount, texCoordSetMap,
174 	      vertexAttrCount, vertexAttrSizes,
175 	      stripVertexCounts);
176 
177         if (vertexCount < 3 )
178 	    throw new IllegalArgumentException(J3dI18N.getString("TriangleStripArray0"));
179     }
180 
181     /**
182      * Creates the retained mode TriangleStripArrayRetained object that this
183      * TriangleStripArray object will point to.
184      */
createRetained()185     void createRetained() {
186 	this.retained = new TriangleStripArrayRetained();
187 	this.retained.setSource(this);
188     }
189 
190 
191     /**
192      * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
193      */
cloneNodeComponent()194     public NodeComponent cloneNodeComponent() {
195         TriangleStripArrayRetained rt = (TriangleStripArrayRetained) retained;
196         int stripcounts[] = new int[rt.getNumStrips()];
197         rt.getStripVertexCounts(stripcounts);
198         int texSetCount = rt.getTexCoordSetCount();
199         int[] texMap = null;
200         int vertexAttrCount = rt.getVertexAttrCount();
201         int[] vertexAttrSizes = null;
202         if (texSetCount > 0) {
203             texMap = new int[rt.getTexCoordSetMapLength()];
204             rt.getTexCoordSetMap(texMap);
205         }
206         if (vertexAttrCount > 0) {
207             vertexAttrSizes = new int[vertexAttrCount];
208             rt.getVertexAttrSizes(vertexAttrSizes);
209         }
210         TriangleStripArray t = new TriangleStripArray(rt.getVertexCount(),
211                 rt.getVertexFormat(),
212                 texSetCount,
213                 texMap,
214                 vertexAttrCount,
215                 vertexAttrSizes,
216                 stripcounts);
217         t.duplicateNodeComponent(this);
218         return t;
219      }
220 }
221