Project

General

Profile

Download (45.1 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / mesh / MeshBase.java @ 46d463a4

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 d333eb6b Leszek Koltunski
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 d333eb6b Leszek Koltunski
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 6c00149d Leszek Koltunski
package org.distorted.library.mesh;
21 6a06a912 Leszek Koltunski
22 b7074bc6 Leszek Koltunski
import android.opengl.GLES30;
23 e8925fcd Leszek Koltunski
import android.opengl.Matrix;
24 f046b159 Leszek Koltunski
import android.util.Log;
25 6c00149d Leszek Koltunski
26 e8925fcd Leszek Koltunski
import org.distorted.library.effect.MatrixEffect;
27 f046b159 Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
28 9f9924f8 Leszek Koltunski
import org.distorted.library.effectqueue.EffectQueue;
29 7602a827 Leszek Koltunski
import org.distorted.library.main.InternalBuffer;
30 da681e7e Leszek Koltunski
import org.distorted.library.program.DistortedProgram;
31 a3a05347 Leszek Koltunski
import org.distorted.library.type.Static4D;
32 de77a6c5 Leszek Koltunski
import org.distorted.library.uniformblock.UniformBlockAssociation;
33
import org.distorted.library.uniformblock.UniformBlockCenter;
34 6c00149d Leszek Koltunski
35 bc2ab8c5 Leszek Koltunski
import java.io.DataOutputStream;
36 22422a76 Leszek Koltunski
import java.io.IOException;
37 bc2ab8c5 Leszek Koltunski
import java.io.DataInputStream;
38 f046b159 Leszek Koltunski
import java.nio.ByteBuffer;
39
import java.nio.ByteOrder;
40
import java.nio.FloatBuffer;
41 c90aca24 Leszek Koltunski
import java.util.ArrayList;
42 6a06a912 Leszek Koltunski
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44 e0b6c593 Leszek Koltunski
/**
45 e5ba319d Leszek Koltunski
 * Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
46 e0b6c593 Leszek Koltunski
 * <p>
47 da681e7e Leszek Koltunski
 * If you want to render to a particular shape, extend from here, construct a float array
48 7a5e538a Leszek Koltunski
 * containing per-vertex attributes, and call back setAttribs().
49 e0b6c593 Leszek Koltunski
 */
50 715e7726 Leszek Koltunski
public abstract class MeshBase
51 6a06a912 Leszek Koltunski
   {
52 a2878a67 Leszek Koltunski
   private static final int ASSOC_UBO_BINDING  = 3;
53
   private static final int CENTER_UBO_BINDING = 4;
54 46d463a4 Leszek Koltunski
   public  static final int MAX_EFFECT_COMPONENTS= 98;
55 bc208a9c Leszek Koltunski
56 227b9bca Leszek Koltunski
   // sizes of attributes of an individual vertex.
57
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
58
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
59 7a5e538a Leszek Koltunski
   private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
60 36d65d88 Leszek Koltunski
   private static final int COM_DATA_SIZE= 1; // component number, a single float
61 6f2d931d Leszek Koltunski
62
   static final int POS_ATTRIB   = 0;
63
   static final int NOR_ATTRIB   = POS_DATA_SIZE;
64 e54bfada Leszek Koltunski
   static final int TEX_ATTRIB   = 0;
65 36d65d88 Leszek Koltunski
   static final int COM_ATTRIB   = TEX_DATA_SIZE;
66 bc208a9c Leszek Koltunski
67 a2878a67 Leszek Koltunski
   static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE;  // number of attributes of a vertex (the part changed by preapply)
68
   static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE;  // number of attributes of a vertex (the 'preapply invariant' part)
69
   static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE;  // number of attributes of a transform feedback vertex
70 6a06a912 Leszek Koltunski
71 da681e7e Leszek Koltunski
   private static final int BYTES_PER_FLOAT = 4;
72 3ef3364d Leszek Koltunski
73 6f2d931d Leszek Koltunski
   private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
74
   private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
75
   private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
76 36d65d88 Leszek Koltunski
   private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT;
77 bc208a9c Leszek Koltunski
78 227b9bca Leszek Koltunski
   private static final int TRAN_SIZE  = TRAN_ATTRIBS*BYTES_PER_FLOAT;
79 e54bfada Leszek Koltunski
   private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT;
80
   private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT;
81 a51fe521 Leszek Koltunski
82 46d463a4 Leszek Koltunski
   private static final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
83
   private static final int[] mAssocBlockIndex  = new int[EffectQueue.MAIN_VARIANTS];
84
85
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
86
87
   private static boolean mUseCenters;
88
89 e54bfada Leszek Koltunski
   private boolean mShowNormals;              // when rendering this mesh, draw normal vectors?
90
   private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
91 da681e7e Leszek Koltunski
   private int mNumVertices;
92 a2878a67 Leszek Koltunski
   private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ
93 36d65d88 Leszek Koltunski
   private float[] mVertAttribs2;             // packed: TexS,TexT, Component
94 7a5e538a Leszek Koltunski
   private float mInflate;
95 78ff6ea9 Leszek Koltunski
   private final UniformBlockAssociation mUBA;
96 46d463a4 Leszek Koltunski
   private UniformBlockCenter mUBC;
97 36d65d88 Leszek Koltunski
98 71d8aba1 Leszek Koltunski
   DeferredJobs.JobNode[] mJobNode;
99 07206c71 Leszek Koltunski
100 e8925fcd Leszek Koltunski
   private static class TexComponent
101 c90aca24 Leszek Koltunski
     {
102
     private int mEndIndex;
103 78ff6ea9 Leszek Koltunski
     private final Static4D mTextureMap;
104 c90aca24 Leszek Koltunski
105 e8925fcd Leszek Koltunski
     TexComponent(int end)
106 c90aca24 Leszek Koltunski
       {
107 a3a05347 Leszek Koltunski
       mEndIndex  = end;
108
       mTextureMap= new Static4D(0,0,1,1);
109 c90aca24 Leszek Koltunski
       }
110 e8925fcd Leszek Koltunski
     TexComponent(TexComponent original)
111 c90aca24 Leszek Koltunski
       {
112
       mEndIndex = original.mEndIndex;
113 a3a05347 Leszek Koltunski
114
       float x = original.mTextureMap.get0();
115
       float y = original.mTextureMap.get1();
116
       float z = original.mTextureMap.get2();
117
       float w = original.mTextureMap.get3();
118
       mTextureMap = new Static4D(x,y,z,w);
119 0d4aae88 Leszek Koltunski
       }
120
121 a3a05347 Leszek Koltunski
     void setMap(Static4D map)
122 0d4aae88 Leszek Koltunski
       {
123 a3a05347 Leszek Koltunski
       mTextureMap.set(map.get0(),map.get1(),map.get2(),map.get3());
124 c90aca24 Leszek Koltunski
       }
125
     }
126
127 e8925fcd Leszek Koltunski
   private ArrayList<TexComponent> mTexComponent;
128
   private ArrayList<Integer> mEffComponent;
129 c90aca24 Leszek Koltunski
130 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
131 3ef3364d Leszek Koltunski
132 0f10a0b6 Leszek Koltunski
   MeshBase()
133 3ef3364d Leszek Koltunski
     {
134 e8925fcd Leszek Koltunski
     mShowNormals  = false;
135
     mInflate      = 0.0f;
136
     mTexComponent = new ArrayList<>();
137
     mEffComponent = new ArrayList<>();
138
139 71d8aba1 Leszek Koltunski
     mJobNode = new DeferredJobs.JobNode[1];
140
141 a2878a67 Leszek Koltunski
     mUBA = new UniformBlockAssociation();
142 46d463a4 Leszek Koltunski
143
     if( mUseCenters ) mUBC = new UniformBlockCenter();
144 4f81e0c8 Leszek Koltunski
145 e54bfada Leszek Koltunski
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
146
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
147 b7074bc6 Leszek Koltunski
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
148 c90aca24 Leszek Koltunski
     }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
// copy constructor
152
153 4f81e0c8 Leszek Koltunski
   MeshBase(MeshBase original, boolean deep)
154 c90aca24 Leszek Koltunski
     {
155 1fad573e Leszek Koltunski
     mShowNormals= original.mShowNormals;
156
     mInflate    = original.mInflate;
157
     mNumVertices= original.mNumVertices;
158 42571056 Leszek Koltunski
159 a2878a67 Leszek Koltunski
     mUBA = new UniformBlockAssociation(original.mUBA);
160 46d463a4 Leszek Koltunski
161
     if( mUseCenters ) mUBC = new UniformBlockCenter(original.mUBC);
162 36d65d88 Leszek Koltunski
163 4f81e0c8 Leszek Koltunski
     if( deep )
164
       {
165 71d8aba1 Leszek Koltunski
       mJobNode = new DeferredJobs.JobNode[1];
166 1fad573e Leszek Koltunski
       if( original.mJobNode[0]==null ) copy(original);
167
       else mJobNode[0] = DeferredJobs.copy(this,original);
168 4f81e0c8 Leszek Koltunski
       }
169
     else
170
       {
171 71d8aba1 Leszek Koltunski
       mJobNode      = original.mJobNode;
172
       mVBO1         = original.mVBO1;
173
       mVertAttribs1 = original.mVertAttribs1;
174 1fad573e Leszek Koltunski
       shallowCopy(original);
175 4f81e0c8 Leszek Koltunski
       }
176 cbd502ec Leszek Koltunski
177 4f81e0c8 Leszek Koltunski
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
178 42571056 Leszek Koltunski
     }
179
180 36d65d88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182 1fad573e Leszek Koltunski
   void copy(MeshBase original)
183 36d65d88 Leszek Koltunski
     {
184 1fad573e Leszek Koltunski
     shallowCopy(original);
185
186
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
187
     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
188
     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
189 36d65d88 Leszek Koltunski
     }
190
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192
193 1fad573e Leszek Koltunski
   private void shallowCopy(MeshBase original)
194 36d65d88 Leszek Koltunski
     {
195 e8925fcd Leszek Koltunski
     int texComSize = original.mTexComponent.size();
196
     mTexComponent = new ArrayList<>();
197 36d65d88 Leszek Koltunski
198 e8925fcd Leszek Koltunski
     for(int i=0; i<texComSize; i++)
199 1fad573e Leszek Koltunski
       {
200 e8925fcd Leszek Koltunski
       TexComponent comp = new TexComponent(original.mTexComponent.get(i));
201
       mTexComponent.add(comp);
202 1fad573e Leszek Koltunski
       }
203 f4c5a46e Leszek Koltunski
204 e8925fcd Leszek Koltunski
     mEffComponent = new ArrayList<>();
205
     mEffComponent.addAll(original.mEffComponent);
206
207 1fad573e Leszek Koltunski
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
208
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
209
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
210 f4c5a46e Leszek Koltunski
     }
211
212 a8dfedcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
213
214 e8925fcd Leszek Koltunski
   void mergeTexComponentsNow()
215 a8dfedcc Leszek Koltunski
     {
216 e8925fcd Leszek Koltunski
     int num = mTexComponent.size();
217 a8dfedcc Leszek Koltunski
218
     if( num>1 )
219
       {
220 e8925fcd Leszek Koltunski
       mTexComponent.clear();
221
       mTexComponent.add(new TexComponent(mNumVertices-1));
222
223
       mVBO2.invalidate();
224
       }
225
     }
226
227 c92c163c Leszek Koltunski
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
230
   void addEmptyTexComponentNow()
231
     {
232
     mTexComponent.add(new TexComponent(mNumVertices-1));
233
     }
234
235 e8925fcd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237
   void mergeEffComponentsNow()
238
     {
239
     int num = mEffComponent.size();
240
241
     if( num>1 )
242
       {
243
       mEffComponent.clear();
244
       mEffComponent.add(mNumVertices-1);
245 a8dfedcc Leszek Koltunski
246
       for(int index=0; index<mNumVertices; index++)
247
         {
248
         mVertAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = 0;
249
         }
250
251
       mVBO2.invalidate();
252
       }
253
     }
254
255 0d4aae88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
256
257 e8925fcd Leszek Koltunski
   void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
258
     {
259 62c869ad Leszek Koltunski
     float[] matrixP  = new float[16];
260
     float[] matrixV  = new float[16];
261 e8925fcd Leszek Koltunski
     float[] uniforms = new float[7];
262
     int start, end=-1, numComp = mEffComponent.size();
263
264 62c869ad Leszek Koltunski
     Matrix.setIdentityM(matrixP,0);
265
     Matrix.setIdentityM(matrixV,0);
266 e8925fcd Leszek Koltunski
     effect.compute(uniforms,0,0,0);
267 62c869ad Leszek Koltunski
     effect.apply(matrixP, matrixV, uniforms, 0);
268 e8925fcd Leszek Koltunski
269 97755c02 Leszek Koltunski
     for(int comp=0; comp<numComp; comp++)
270 e8925fcd Leszek Koltunski
       {
271 f45e4279 Leszek Koltunski
       start = end+1;
272 97755c02 Leszek Koltunski
       end   = mEffComponent.get(comp);
273 e8925fcd Leszek Koltunski
274 a2878a67 Leszek Koltunski
       if( mUBA.matchesAssociation(comp, andAssoc, equAssoc) )
275 e8925fcd Leszek Koltunski
         {
276 62c869ad Leszek Koltunski
         applyMatrixToComponent(matrixP, matrixV, start, end);
277 e8925fcd Leszek Koltunski
         }
278
       }
279
280
     mVBO1.invalidate();
281
     }
282
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
285 62c869ad Leszek Koltunski
   private void applyMatrixToComponent(float[] matrixP, float[] matrixV, int start, int end)
286 e8925fcd Leszek Koltunski
     {
287
     float x,y,z;
288
289 f45e4279 Leszek Koltunski
     for(int index=start*VERT1_ATTRIBS; index<=end*VERT1_ATTRIBS; index+=VERT1_ATTRIBS )
290 e8925fcd Leszek Koltunski
       {
291
       x = mVertAttribs1[index+POS_ATTRIB  ];
292
       y = mVertAttribs1[index+POS_ATTRIB+1];
293
       z = mVertAttribs1[index+POS_ATTRIB+2];
294
295 62c869ad Leszek Koltunski
       mVertAttribs1[index+POS_ATTRIB  ] = matrixP[0]*x + matrixP[4]*y + matrixP[ 8]*z + matrixP[12];
296
       mVertAttribs1[index+POS_ATTRIB+1] = matrixP[1]*x + matrixP[5]*y + matrixP[ 9]*z + matrixP[13];
297
       mVertAttribs1[index+POS_ATTRIB+2] = matrixP[2]*x + matrixP[6]*y + matrixP[10]*z + matrixP[14];
298 e8925fcd Leszek Koltunski
299
       x = mVertAttribs1[index+NOR_ATTRIB  ];
300
       y = mVertAttribs1[index+NOR_ATTRIB+1];
301
       z = mVertAttribs1[index+NOR_ATTRIB+2];
302
303 62c869ad Leszek Koltunski
       mVertAttribs1[index+NOR_ATTRIB  ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z;
304
       mVertAttribs1[index+NOR_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z;
305
       mVertAttribs1[index+NOR_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z;
306
307
       x = mVertAttribs1[index+NOR_ATTRIB  ];
308
       y = mVertAttribs1[index+NOR_ATTRIB+1];
309
       z = mVertAttribs1[index+NOR_ATTRIB+2];
310
311
       float len1 = (float)Math.sqrt(x*x + y*y + z*z);
312
313
       if( len1>0.0f )
314
         {
315
         mVertAttribs1[index+NOR_ATTRIB  ] /= len1;
316
         mVertAttribs1[index+NOR_ATTRIB+1] /= len1;
317
         mVertAttribs1[index+NOR_ATTRIB+2] /= len1;
318
         }
319 e8925fcd Leszek Koltunski
       }
320
     }
321
322 26671ef8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
323
324
   void setEffectAssociationNow(int component, int andAssociation, int equAssociation)
325
     {
326 a2878a67 Leszek Koltunski
     mUBA.setEffectAssociationNow(component, andAssociation, equAssociation);
327
     }
328
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
331 7a9edb92 Leszek Koltunski
   void setComponentCenterNow(int component, float x, float y, float z)
332 a2878a67 Leszek Koltunski
     {
333 46d463a4 Leszek Koltunski
     if( mUBC!=null )
334
       {
335
       mUBC.setEffectCenterNow(component, x, y, z);
336
       }
337 26671ef8 Leszek Koltunski
     }
338
339 42571056 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
340 6c00149d Leszek Koltunski
// when a derived class is done computing its mesh, it has to call this method.
341 42571056 Leszek Koltunski
342 e54bfada Leszek Koltunski
   void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
343 42571056 Leszek Koltunski
     {
344 e54bfada Leszek Koltunski
     mNumVertices = vert1Attribs.length/VERT1_ATTRIBS;
345
     mVertAttribs1= vert1Attribs;
346
     mVertAttribs2= vert2Attribs;
347 da681e7e Leszek Koltunski
348 e8925fcd Leszek Koltunski
     mTexComponent.add(new TexComponent(mNumVertices-1));
349
     mEffComponent.add(mNumVertices-1);
350 c90aca24 Leszek Koltunski
351 e54bfada Leszek Koltunski
     mVBO1.invalidate();
352
     mVBO2.invalidate();
353 42571056 Leszek Koltunski
     }
354
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356
357 1fad573e Leszek Koltunski
   void joinAttribs(MeshBase[] meshes)
358 226144d0 leszek
     {
359 0d4aae88 Leszek Koltunski
     MeshBase mesh;
360 e8925fcd Leszek Koltunski
     TexComponent comp;
361 a8dfedcc Leszek Koltunski
     int numMeshes = meshes.length;
362 e8925fcd Leszek Koltunski
     int numVertices,origVertices = mNumVertices;
363 26671ef8 Leszek Koltunski
     int origTexComponents,numTexComponents;
364 e8925fcd Leszek Koltunski
     int origEffComponents=0,numEffComponents;
365 044b5494 Leszek Koltunski
366 0d4aae88 Leszek Koltunski
     if( origVertices>0 )
367
       {
368 e8925fcd Leszek Koltunski
       origTexComponents = mTexComponent.size();
369 1fad573e Leszek Koltunski
       mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
370 e8925fcd Leszek Koltunski
       mTexComponent.get(origTexComponents-1).mEndIndex = mNumVertices-1;
371
       origEffComponents = mEffComponent.size();
372
       mEffComponent.set(origEffComponents-1,mNumVertices-1);
373 0d4aae88 Leszek Koltunski
       }
374 044b5494 Leszek Koltunski
375 e7f85322 Leszek Koltunski
     for(int i=0; i<numMeshes; i++)
376 0d4aae88 Leszek Koltunski
       {
377
       mesh = meshes[i];
378 e8925fcd Leszek Koltunski
       numTexComponents = mesh.mTexComponent.size();
379
       numEffComponents = mesh.mEffComponent.size();
380 36d65d88 Leszek Koltunski
       numVertices = mesh.mNumVertices;
381
382 1fad573e Leszek Koltunski
       int extraVerticesBefore = mNumVertices==0 ? 0:1;
383
       int extraVerticesAfter  = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1);
384 36d65d88 Leszek Koltunski
385 e8925fcd Leszek Koltunski
       for(int j=0; j<numTexComponents; j++)
386 0d4aae88 Leszek Koltunski
         {
387 e8925fcd Leszek Koltunski
         comp = new TexComponent(mesh.mTexComponent.get(j));
388 e0343804 Leszek Koltunski
         comp.mEndIndex += (extraVerticesBefore+mNumVertices);
389
         if( j==numTexComponents-1) comp.mEndIndex += extraVerticesAfter;
390 e8925fcd Leszek Koltunski
         mTexComponent.add(comp);
391
         }
392 23b733db Leszek Koltunski
393 e8925fcd Leszek Koltunski
       for(int j=0; j<numEffComponents; j++)
394
         {
395
         int index = mesh.mEffComponent.get(j);
396 e0343804 Leszek Koltunski
         index += (extraVerticesBefore+mNumVertices);
397
         if( j==numEffComponents-1 ) index += extraVerticesAfter;
398 e8925fcd Leszek Koltunski
         mEffComponent.add(index);
399
400
         if( origEffComponents<MAX_EFFECT_COMPONENTS )
401 36d65d88 Leszek Koltunski
           {
402 a2878a67 Leszek Koltunski
           mUBA.copy(origEffComponents, mesh.mUBA, j);
403 46d463a4 Leszek Koltunski
           if( mUseCenters ) mUBC.copy(origEffComponents, mesh.mUBC, j);
404 e8925fcd Leszek Koltunski
           origEffComponents++;
405 36d65d88 Leszek Koltunski
           }
406 e7f85322 Leszek Koltunski
         }
407 a8dfedcc Leszek Koltunski
408 1fad573e Leszek Koltunski
       mNumVertices += (extraVerticesBefore+numVertices+extraVerticesAfter);
409
       }
410 a8dfedcc Leszek Koltunski
411 1fad573e Leszek Koltunski
     float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
412 e54bfada Leszek Koltunski
     float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
413 1fad573e Leszek Koltunski
     numVertices = origVertices;
414 0d4aae88 Leszek Koltunski
415
     if( origVertices>0 )
416
       {
417 e8925fcd Leszek Koltunski
       System.arraycopy(mVertAttribs1,                              0, newAttribs1,                          0, VERT1_ATTRIBS*numVertices);
418
       System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS            );
419
       System.arraycopy(mVertAttribs2,                              0, newAttribs2,                          0, VERT2_ATTRIBS*numVertices);
420
       System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS            );
421 0d4aae88 Leszek Koltunski
       origVertices++;
422
423 e7f85322 Leszek Koltunski
       if( numVertices%2==1 )
424 0d4aae88 Leszek Koltunski
         {
425 1fad573e Leszek Koltunski
         System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
426 e54bfada Leszek Koltunski
         System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
427 0d4aae88 Leszek Koltunski
         origVertices++;
428
         }
429
       }
430
431 e7f85322 Leszek Koltunski
     for(int i=0; i<numMeshes; i++)
432 0d4aae88 Leszek Koltunski
       {
433
       mesh = meshes[i];
434 e7f85322 Leszek Koltunski
       numVertices = mesh.mNumVertices;
435 0d4aae88 Leszek Koltunski
436 22e60fba Leszek Koltunski
       if( origVertices>0 )
437
         {
438 e8925fcd Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
439
         System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
440 22e60fba Leszek Koltunski
         origVertices++;
441
         }
442 1fad573e Leszek Koltunski
       System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
443 e54bfada Leszek Koltunski
       System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices);
444 e7f85322 Leszek Koltunski
       origVertices+=numVertices;
445 0d4aae88 Leszek Koltunski
446 e7f85322 Leszek Koltunski
       if( i<numMeshes-1 )
447 0d4aae88 Leszek Koltunski
         {
448 1fad573e Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
449 e54bfada Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
450 0d4aae88 Leszek Koltunski
         origVertices++;
451
452 e7f85322 Leszek Koltunski
         if( numVertices%2==1 )
453 0d4aae88 Leszek Koltunski
           {
454 1fad573e Leszek Koltunski
           System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
455 e54bfada Leszek Koltunski
           System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
456 0d4aae88 Leszek Koltunski
           origVertices++;
457
           }
458
         }
459
       }
460
461
     if( origVertices!=mNumVertices )
462
       {
463
       android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
464
       }
465
466 e8925fcd Leszek Koltunski
     int endIndex, index=0, numEffComp = mEffComponent.size();
467 36d65d88 Leszek Koltunski
468 e8925fcd Leszek Koltunski
     for(int component=0; component<numEffComp; component++)
469 36d65d88 Leszek Koltunski
       {
470 e8925fcd Leszek Koltunski
       endIndex = mEffComponent.get(component);
471 36d65d88 Leszek Koltunski
472
       for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component;
473
       }
474
475 1fad573e Leszek Koltunski
     mVertAttribs1 = newAttribs1;
476 e54bfada Leszek Koltunski
     mVertAttribs2 = newAttribs2;
477 1fad573e Leszek Koltunski
     mVBO1.invalidate();
478 e54bfada Leszek Koltunski
     mVBO2.invalidate();
479 23b733db Leszek Koltunski
     }
480
481 a8dfedcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
482
// called from MeshJoined
483
484
   void join(MeshBase[] meshes)
485
     {
486 1fad573e Leszek Koltunski
     boolean immediateJoin = true;
487 a8dfedcc Leszek Koltunski
488 1fad573e Leszek Koltunski
     for (MeshBase mesh : meshes)
489 a8dfedcc Leszek Koltunski
       {
490 1fad573e Leszek Koltunski
       if (mesh.mJobNode[0] != null)
491
         {
492
         immediateJoin = false;
493
         break;
494
         }
495 a8dfedcc Leszek Koltunski
       }
496
497 1fad573e Leszek Koltunski
     if( immediateJoin ) joinAttribs(meshes);
498
     else                mJobNode[0] = DeferredJobs.join(this,meshes);
499
     }
500 a8dfedcc Leszek Koltunski
501 1fad573e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
502 a8dfedcc Leszek Koltunski
503 dbe3079d Leszek Koltunski
   void textureMap(Static4D[] maps, int startComponent)
504 1fad573e Leszek Koltunski
     {
505 e8925fcd Leszek Koltunski
     int num_comp = mTexComponent.size();
506 92403ff8 Leszek Koltunski
     if( startComponent>num_comp ) return;
507
508 1fad573e Leszek Koltunski
     int num_maps = maps.length;
509 dbe3079d Leszek Koltunski
     int min = Math.min(num_comp-startComponent, num_maps);
510 96877ab4 Leszek Koltunski
     int vertex = startComponent>0 ? mTexComponent.get(startComponent-1).mEndIndex+1 : 0;
511 1fad573e Leszek Koltunski
     Static4D newMap, oldMap;
512 e8925fcd Leszek Koltunski
     TexComponent comp;
513 1fad573e Leszek Koltunski
     float newW, newH, ratW, ratH, movX, movY;
514 a8dfedcc Leszek Koltunski
515 1fad573e Leszek Koltunski
     for(int i=0; i<min; i++)
516
       {
517
       newMap = maps[i];
518 dbe3079d Leszek Koltunski
       comp = mTexComponent.get(i+startComponent);
519 1fad573e Leszek Koltunski
520
       if( newMap!=null )
521 a8dfedcc Leszek Koltunski
         {
522 1fad573e Leszek Koltunski
         newW = newMap.get2();
523
         newH = newMap.get3();
524 a8dfedcc Leszek Koltunski
525 1fad573e Leszek Koltunski
         if( newW!=0.0f && newH!=0.0f )
526 a8dfedcc Leszek Koltunski
           {
527 1fad573e Leszek Koltunski
           oldMap = comp.mTextureMap;
528
           ratW = newW/oldMap.get2();
529
           ratH = newH/oldMap.get3();
530
           movX = newMap.get0() - ratW*oldMap.get0();
531
           movY = newMap.get1() - ratH*oldMap.get1();
532
533
           for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
534
             {
535
             mVertAttribs2[index  ] = ratW*mVertAttribs2[index  ] + movX;
536
             mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
537
             }
538
           comp.setMap(newMap);
539 a8dfedcc Leszek Koltunski
           }
540
         }
541
542 1fad573e Leszek Koltunski
       vertex= comp.mEndIndex+1;
543 a8dfedcc Leszek Koltunski
       }
544
545 1fad573e Leszek Koltunski
     mVBO2.invalidate();
546
     }
547
548 46d463a4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
549
/**
550
 * Are we going to need per-component centers (needed for correct postprocessing of concave meshes)
551
 * Switching this on allocates 16*MAX_EFFECT_COMPONENTS bytes for uniforms in the vertex shader.
552
 */
553
   public static void setUseCenters()
554
     {
555
     mUseCenters = true;
556
     }
557
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559
/**
560
 * Are we using per-component centers?
561
 */
562
   public static boolean getUseCenters()
563
     {
564
     return mUseCenters;
565
     }
566
567 1fad573e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
568 a8dfedcc Leszek Koltunski
569 e8925fcd Leszek Koltunski
   public static int getMaxEffComponents()
570 1fad573e Leszek Koltunski
     {
571 e8925fcd Leszek Koltunski
     return MAX_EFFECT_COMPONENTS;
572 1fad573e Leszek Koltunski
     }
573
574 9f9924f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
575
576
   public static void getUniforms(int programH, int variant)
577
     {
578
     mCenterBlockIndex[variant]= GLES30.glGetUniformBlockIndex(programH, "componentCenter");
579
     mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation");
580
     }
581
582 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
583
/**
584
 * Not part of public API, do not document (public only because has to be used from the main package)
585
 *
586
 * @y.exclude
587
 */
588
   public void copyTransformToVertex()
589
     {
590 e54bfada Leszek Koltunski
     ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0,
591
                                                              TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT);
592 f046b159 Leszek Koltunski
     if( buffer!=null )
593
       {
594 e54bfada Leszek Koltunski
       FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
595
       feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices);
596 0bd9f644 Leszek Koltunski
       mVBO1.updateFloat(mVertAttribs1);
597 f046b159 Leszek Koltunski
       }
598
     else
599
       {
600 b5be333a Leszek Koltunski
       int error = GLES30.glGetError();
601
       Log.e("mesh", "failed to map tf buffer, error="+error);
602 f046b159 Leszek Koltunski
       }
603
604 b5be333a Leszek Koltunski
     GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
605 f046b159 Leszek Koltunski
     }
606
607 1fad573e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
608
/**
609
 * Not part of public API, do not document (public only because has to be used from the main package)
610
 *
611
 * @y.exclude
612
 */
613
   public void debug()
614
     {
615
     if( mJobNode[0]!=null )
616
       {
617
       mJobNode[0].print(0);
618
       }
619
     else
620
       {
621
       android.util.Log.e("mesh", "JobNode null");
622
       }
623
     }
624
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626
/**
627
 * Not part of public API, do not document (public only because has to be used from the main package)
628
 *
629
 * @y.exclude
630
 */
631 e0343804 Leszek Koltunski
   public void printPos()
632 1fad573e Leszek Koltunski
     {
633 26671ef8 Leszek Koltunski
     StringBuilder sb = new StringBuilder();
634 1fad573e Leszek Koltunski
635
     for(int i=0; i<mNumVertices; i++)
636
       {
637
       sb.append('(');
638
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB  ]);
639
       sb.append(',');
640
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+1]);
641
       sb.append(',');
642
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+2]);
643
       sb.append(") ");
644
       }
645 e0343804 Leszek Koltunski
     Log.d("mesh", sb.toString());
646
     }
647 1fad573e Leszek Koltunski
648 e0343804 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
649
/**
650
 * Not part of public API, do not document (public only because has to be used from the main package)
651
 *
652
 * @y.exclude
653
 */
654
   public void printCom()
655
     {
656
     StringBuilder sb = new StringBuilder();
657 1fad573e Leszek Koltunski
658
     for(int i=0; i<mNumVertices; i++)
659
       {
660 e0343804 Leszek Koltunski
       sb.append(mVertAttribs2[VERT2_ATTRIBS*i+COM_ATTRIB]);
661
       sb.append(' ');
662
       }
663
664
     Log.d("mesh", sb.toString());
665
     }
666
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668
/**
669
 * Not part of public API, do not document (public only because has to be used from the main package)
670
 *
671
 * @y.exclude
672
 */
673
   public void printTex()
674
     {
675
     int vert=0;
676
     int num = numTexComponents();
677
     StringBuilder sb = new StringBuilder();
678
     sb.append("tex components: ").append(num);
679
680
     for(int i=0; i<num; i++)
681
       {
682
       int end = mTexComponent.get(i).mEndIndex;
683
       sb.append("\n");
684
685
       for( ; vert<=end; vert++)
686
         {
687
         sb.append(' ');
688
         sb.append('(');
689
         sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB]);
690
         sb.append(',');
691
         sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB+1]);
692
         sb.append(')');
693
         }
694 1fad573e Leszek Koltunski
       }
695
696 e0343804 Leszek Koltunski
     Log.d("mesh", sb.toString());
697 1fad573e Leszek Koltunski
     }
698
699 23b733db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
700
/**
701 0d4aae88 Leszek Koltunski
 * Not part of public API, do not document (public only because has to be used from the main package)
702
 *
703
 * @y.exclude
704 23b733db Leszek Koltunski
 */
705 0d4aae88 Leszek Koltunski
   public int getTFO()
706 23b733db Leszek Koltunski
     {
707 0bd9f644 Leszek Koltunski
     return mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
708 23b733db Leszek Koltunski
     }
709
710
///////////////////////////////////////////////////////////////////////////////////////////////////
711
/**
712 0d4aae88 Leszek Koltunski
 * Not part of public API, do not document (public only because has to be used from the main package)
713
 *
714
 * @y.exclude
715 23b733db Leszek Koltunski
 */
716 0d4aae88 Leszek Koltunski
   public int getNumVertices()
717 23b733db Leszek Koltunski
     {
718 0d4aae88 Leszek Koltunski
     return mNumVertices;
719 23b733db Leszek Koltunski
     }
720
721 36d65d88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
722
/**
723
 * Not part of public API, do not document (public only because has to be used from the main package)
724
 *
725
 * @y.exclude
726
 */
727 9f9924f8 Leszek Koltunski
   public void send(int programH, int variant)
728 36d65d88 Leszek Koltunski
     {
729 a2878a67 Leszek Koltunski
     int indexA = mUBA.getIndex();
730
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA);
731 9f9924f8 Leszek Koltunski
     GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING);
732 a2878a67 Leszek Koltunski
733 46d463a4 Leszek Koltunski
     if( mUseCenters )
734
       {
735
       int indexC = mUBC.getIndex();
736
       GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
737
       GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING);
738
       }
739 36d65d88 Leszek Koltunski
     }
740
741 044b5494 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
742 6c00149d Leszek Koltunski
/**
743
 * Not part of public API, do not document (public only because has to be used from the main package)
744
 *
745
 * @y.exclude
746
 */
747 da681e7e Leszek Koltunski
   public void bindVertexAttribs(DistortedProgram program)
748 6c00149d Leszek Koltunski
     {
749 71d8aba1 Leszek Koltunski
     if( mJobNode[0]!=null )
750 f046b159 Leszek Koltunski
       {
751 71d8aba1 Leszek Koltunski
       mJobNode[0].execute();  // this will set itself to null
752 bc2ab8c5 Leszek Koltunski
/*
753
       try
754
         {
755
         String name = "/sdcard/"+mNumVertices+".dmesh";
756 7a9edb92 Leszek Koltunski
         DataOutputStream dos = new DataOutputStream(new java.io.FileOutputStream(name));
757 bc2ab8c5 Leszek Koltunski
         write(dos);
758 9f28e9b6 Leszek Koltunski
         android.util.Log.e("mesh", "file written: "+name);
759 bc2ab8c5 Leszek Koltunski
         }
760 7a9edb92 Leszek Koltunski
       catch(java.io.FileNotFoundException ex)
761 bc2ab8c5 Leszek Koltunski
         {
762
         android.util.Log.e("mesh", "file not found exception: "+ex.toString());
763
         }
764
 */
765 f046b159 Leszek Koltunski
       }
766
767 0bd9f644 Leszek Koltunski
     int index1 = mVBO1.createImmediatelyFloat(mNumVertices*VERT1_SIZE, mVertAttribs1);
768
     int index2 = mVBO2.createImmediatelyFloat(mNumVertices*VERT2_SIZE, mVertAttribs2);
769 22e60fba Leszek Koltunski
770 e54bfada Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 );
771
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS);
772
     GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR);
773
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 );
774 a2878a67 Leszek Koltunski
     GLES30.glVertexAttribPointer(program.mAttribute[2], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
775
     GLES30.glVertexAttribPointer(program.mAttribute[3], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
776 b7074bc6 Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
777 da681e7e Leszek Koltunski
     }
778
779
///////////////////////////////////////////////////////////////////////////////////////////////////
780
/**
781
 * Not part of public API, do not document (public only because has to be used from the main package)
782
 *
783
 * @y.exclude
784
 */
785
   public void bindTransformAttribs(DistortedProgram program)
786
     {
787 0bd9f644 Leszek Koltunski
     int index = mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
788 22e60fba Leszek Koltunski
789 b7074bc6 Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index );
790
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
791
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
792 6c00149d Leszek Koltunski
     }
793
794 7a5e538a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
795
/**
796
 * Not part of public API, do not document (public only because has to be used from the main package)
797
 *
798
 * @y.exclude
799
 */
800
   public void setInflate(float inflate)
801
     {
802
     mInflate = inflate;
803
     }
804
805
///////////////////////////////////////////////////////////////////////////////////////////////////
806
/**
807
 * Not part of public API, do not document (public only because has to be used from the main package)
808
 *
809
 * @y.exclude
810
 */
811
   public float getInflate()
812
     {
813
     return mInflate;
814
     }
815
816 466450b5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
817 54ce4c6f Leszek Koltunski
// Return the number of bytes read.
818 22422a76 Leszek Koltunski
819 54ce4c6f Leszek Koltunski
   int read(DataInputStream stream)
820 10836924 Leszek Koltunski
     {
821 bc2ab8c5 Leszek Koltunski
     byte[] buffer = new byte[BYTES_PER_FLOAT*4];
822
     int version, numEff, numTex;
823 22422a76 Leszek Koltunski
824 7a9edb92 Leszek Koltunski
     //////////////////////////////////////////////////////////////////////////////////////////
825
     // read version, number of vertices, number of tex components, number of effect components
826
     //////////////////////////////////////////////////////////////////////////////////////////
827
828 22422a76 Leszek Koltunski
     try
829
       {
830 bc2ab8c5 Leszek Koltunski
       stream.read(buffer);
831
       ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
832 22422a76 Leszek Koltunski
833 bc2ab8c5 Leszek Koltunski
       version = byteBuf.getInt(0);
834 22422a76 Leszek Koltunski
835 a2878a67 Leszek Koltunski
       if( version==1 || version==2 )
836 22422a76 Leszek Koltunski
         {
837 bc2ab8c5 Leszek Koltunski
         mNumVertices= byteBuf.getInt(4);
838
         numTex      = byteBuf.getInt(8);
839
         numEff      = byteBuf.getInt(12);
840 22422a76 Leszek Koltunski
         }
841
       else
842
         {
843 bc2ab8c5 Leszek Koltunski
         android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
844 54ce4c6f Leszek Koltunski
         return 0;
845 22422a76 Leszek Koltunski
         }
846
       }
847
     catch(IOException e)
848
       {
849 bc2ab8c5 Leszek Koltunski
       android.util.Log.e("mesh", "IOException1 trying to read file: "+e.toString());
850 54ce4c6f Leszek Koltunski
       return 0;
851 22422a76 Leszek Koltunski
       }
852
853 7a9edb92 Leszek Koltunski
     //////////////////////////////////////////////////////////////////////////////////////////
854
     // read contents of all texture and effect components
855
     //////////////////////////////////////////////////////////////////////////////////////////
856
857 bc2ab8c5 Leszek Koltunski
     if( mNumVertices>0 && numEff>0 && numTex>0 )
858 22422a76 Leszek Koltunski
       {
859
       int size = numEff+TEX_COMP_SIZE*numTex;
860
       float[] tmp = new float[size];
861 bc2ab8c5 Leszek Koltunski
       mVertAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
862
       mVertAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
863 22422a76 Leszek Koltunski
864 a2878a67 Leszek Koltunski
       // version 1 had extra 3 floats (the 'inflate' vector) in its vert1 array
865 7a9edb92 Leszek Koltunski
       int vert1InFile = version==2 ? VERT1_ATTRIBS : VERT1_ATTRIBS+3;
866
       // ... and there was no center.
867
       int centerSize  = version==2 ? 3*numEff : 0;
868 a2878a67 Leszek Koltunski
869 7a9edb92 Leszek Koltunski
       buffer = new byte[BYTES_PER_FLOAT*(size + centerSize + mNumVertices*(vert1InFile+VERT2_ATTRIBS))];
870 22422a76 Leszek Koltunski
871 bc2ab8c5 Leszek Koltunski
       try
872
         {
873
         stream.read(buffer);
874
         }
875
       catch(IOException e)
876
         {
877
         android.util.Log.e("mesh", "IOException2 trying to read file: "+e.toString());
878 54ce4c6f Leszek Koltunski
         return 0;
879 bc2ab8c5 Leszek Koltunski
         }
880
881
       ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
882
       FloatBuffer floatBuf = byteBuf.asFloatBuffer();
883 22422a76 Leszek Koltunski
884 bc2ab8c5 Leszek Koltunski
       floatBuf.get(tmp,0,size);
885 a2878a67 Leszek Koltunski
886 22422a76 Leszek Koltunski
       TexComponent tex;
887
       int index, texComp;
888
       float x, y, z, w;
889
890
       for(texComp=0; texComp<numTex; texComp++)
891
         {
892
         index = (int)tmp[TEX_COMP_SIZE*texComp];
893
894
         x= tmp[TEX_COMP_SIZE*texComp+1];
895
         y= tmp[TEX_COMP_SIZE*texComp+2];
896
         z= tmp[TEX_COMP_SIZE*texComp+3];
897
         w= tmp[TEX_COMP_SIZE*texComp+4];
898
899
         tex = new TexComponent(index);
900
         tex.setMap(new Static4D(x,y,z,w));
901 10836924 Leszek Koltunski
902 22422a76 Leszek Koltunski
         mTexComponent.add(tex);
903
         }
904
905
       for(int effComp=0; effComp<numEff; effComp++)
906
         {
907
         index = (int)tmp[TEX_COMP_SIZE*texComp + effComp ];
908
         mEffComponent.add(index);
909
         }
910 7a9edb92 Leszek Koltunski
911
       //////////////////////////////////////////////////////////////////////////////////////////
912
       // read vert1 array, vert2 array and (if version>1) the component centers.
913
       //////////////////////////////////////////////////////////////////////////////////////////
914
915
       switch(version)
916
         {
917
         case 1 : index = floatBuf.position();
918
919
                  for(int vert=0; vert<mNumVertices; vert++)
920
                    {
921
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB  ] = floatBuf.get(index+POS_ATTRIB  );
922
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+1] = floatBuf.get(index+POS_ATTRIB+1);
923
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+2] = floatBuf.get(index+POS_ATTRIB+2);
924
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB  ] = floatBuf.get(index+NOR_ATTRIB  );
925
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+1] = floatBuf.get(index+NOR_ATTRIB+1);
926
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+2] = floatBuf.get(index+NOR_ATTRIB+2);
927
                    index+=vert1InFile;
928
                    }
929
                  floatBuf.position(index);
930
                  break;
931
         case 2 : float[] centers = new float[3*numEff];
932
                  floatBuf.get(centers,0,3*numEff);
933
934 46d463a4 Leszek Koltunski
                  if( mUseCenters )
935 7a9edb92 Leszek Koltunski
                    {
936 46d463a4 Leszek Koltunski
                    for(int eff=0; eff<numEff; eff++)
937
                      {
938
                      mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]);
939
                      }
940 7a9edb92 Leszek Koltunski
                    }
941
942
                  floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices);
943
                  break;
944
         default: android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
945
                  return 0;
946
         }
947
948
       floatBuf.get(mVertAttribs2, 0, VERT2_ATTRIBS*mNumVertices);
949 22422a76 Leszek Koltunski
       }
950 54ce4c6f Leszek Koltunski
951
     return BYTES_PER_FLOAT*( 4 + numEff+TEX_COMP_SIZE*numTex + VERT1_ATTRIBS*mNumVertices + VERT2_ATTRIBS*mNumVertices );
952 10836924 Leszek Koltunski
     }
953
954 524e4fe7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
955
/**
956
 * @y.exclude
957
 */
958
   public int getLastVertexEff(int effComponent)
959
     {
960
     if( effComponent>=0 && effComponent<mTexComponent.size() )
961
       {
962
       return mEffComponent.get(effComponent);
963
       }
964
965
     return 0;
966
     }
967
968
///////////////////////////////////////////////////////////////////////////////////////////////////
969
/**
970
 * @y.exclude
971
 */
972
   public int getLastVertexTex(int texComponent)
973
     {
974
     if( texComponent>=0 && texComponent<mTexComponent.size() )
975
       {
976
       return mTexComponent.get(texComponent).mEndIndex;
977
       }
978
979
     return 0;
980
     }
981
982 22422a76 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
983
// PUBLIC API
984 10836924 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
985
/**
986 22422a76 Leszek Koltunski
 * Write the Mesh to a File.
987 10836924 Leszek Koltunski
 */
988 bc2ab8c5 Leszek Koltunski
   public void write(DataOutputStream stream)
989 10836924 Leszek Koltunski
     {
990 22422a76 Leszek Koltunski
     TexComponent tex;
991
992
     int numTex = mTexComponent.size();
993
     int numEff = mEffComponent.size();
994
995 bc2ab8c5 Leszek Koltunski
     try
996 22422a76 Leszek Koltunski
       {
997 a2878a67 Leszek Koltunski
       stream.writeInt(2);  // version
998 bc2ab8c5 Leszek Koltunski
       stream.writeInt(mNumVertices);
999
       stream.writeInt(numTex);
1000
       stream.writeInt(numEff);
1001 22422a76 Leszek Koltunski
1002 bc2ab8c5 Leszek Koltunski
       for(int i=0; i<numTex; i++)
1003
         {
1004
         tex = mTexComponent.get(i);
1005 22422a76 Leszek Koltunski
1006 bc2ab8c5 Leszek Koltunski
         stream.writeFloat((float)tex.mEndIndex);
1007
         stream.writeFloat(tex.mTextureMap.get0());
1008
         stream.writeFloat(tex.mTextureMap.get1());
1009
         stream.writeFloat(tex.mTextureMap.get2());
1010
         stream.writeFloat(tex.mTextureMap.get3());
1011
         }
1012 22422a76 Leszek Koltunski
1013 bc2ab8c5 Leszek Koltunski
       for(int i=0; i<numEff; i++)
1014
         {
1015
         stream.writeFloat((float)mEffComponent.get(i));
1016
         }
1017 10836924 Leszek Koltunski
1018 46d463a4 Leszek Koltunski
       float[] centers = mUseCenters ? mUBC.getBackingArray() : new float[4*numEff];
1019 7a9edb92 Leszek Koltunski
1020
       for(int i=0; i<numEff; i++)
1021
         {
1022
         stream.writeFloat(centers[4*i  ]);
1023
         stream.writeFloat(centers[4*i+1]);
1024
         stream.writeFloat(centers[4*i+2]);
1025
         }
1026
1027 bc2ab8c5 Leszek Koltunski
       ByteBuffer vertBuf1 = ByteBuffer.allocate(VERT1_SIZE*mNumVertices);
1028
       vertBuf1.asFloatBuffer().put(mVertAttribs1);
1029
       ByteBuffer vertBuf2 = ByteBuffer.allocate(VERT2_SIZE*mNumVertices);
1030
       vertBuf2.asFloatBuffer().put(mVertAttribs2);
1031
1032
       stream.write(vertBuf1.array());
1033
       stream.write(vertBuf2.array());
1034 22422a76 Leszek Koltunski
       }
1035 bc2ab8c5 Leszek Koltunski
     catch(IOException ex)
1036 22422a76 Leszek Koltunski
       {
1037 bc2ab8c5 Leszek Koltunski
       android.util.Log.e("mesh", "IOException trying to write a mesh: "+ex.toString());
1038 22422a76 Leszek Koltunski
       }
1039 10836924 Leszek Koltunski
     }
1040
1041
///////////////////////////////////////////////////////////////////////////////////////////////////
1042 3fc9327a Leszek Koltunski
/**
1043
 * When rendering this Mesh, do we want to render the Normal vectors as well?
1044 420836fc leszek
 * <p>
1045
 * Will work only on OpenGL ES >= 3.0 devices.
1046 3fc9327a Leszek Koltunski
 *
1047
 * @param show Controls if we render the Normal vectors or not.
1048
 */
1049
   public void setShowNormals(boolean show)
1050
     {
1051 b7074bc6 Leszek Koltunski
     mShowNormals = show;
1052 3fc9327a Leszek Koltunski
     }
1053 466450b5 Leszek Koltunski
1054 6c00149d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1055
/**
1056
 * When rendering this mesh, should we also draw the normal vectors?
1057
 *
1058
 * @return <i>true</i> if we do render normal vectors
1059
 */
1060
   public boolean getShowNormals()
1061
     {
1062
     return mShowNormals;
1063
     }
1064
1065 a8dfedcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1066
/**
1067 e8925fcd Leszek Koltunski
 * Merge all texture components of this Mesh into a single one.
1068 a8dfedcc Leszek Koltunski
 */
1069 e8925fcd Leszek Koltunski
   public void mergeTexComponents()
1070 a8dfedcc Leszek Koltunski
     {
1071 1fad573e Leszek Koltunski
     if( mJobNode[0]==null )
1072 a8dfedcc Leszek Koltunski
       {
1073 e8925fcd Leszek Koltunski
       mergeTexComponentsNow();
1074 a8dfedcc Leszek Koltunski
       }
1075
     else
1076
       {
1077 e8925fcd Leszek Koltunski
       mJobNode[0] = DeferredJobs.mergeTex(this);
1078
       }
1079
     }
1080
1081
///////////////////////////////////////////////////////////////////////////////////////////////////
1082
/**
1083
 * Merge all effect components of this Mesh into a single one.
1084
 */
1085
   public void mergeEffComponents()
1086
     {
1087
     if( mJobNode[0]==null )
1088
       {
1089
       mergeEffComponentsNow();
1090
       }
1091
     else
1092
       {
1093
       mJobNode[0] = DeferredJobs.mergeEff(this);
1094 a8dfedcc Leszek Koltunski
       }
1095
     }
1096
1097 466450b5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1098
/**
1099
 * Release all internal resources.
1100
 */
1101
   public void markForDeletion()
1102
     {
1103 e54bfada Leszek Koltunski
     mVertAttribs1 = null;
1104
     mVertAttribs2 = null;
1105 466450b5 Leszek Koltunski
1106 e54bfada Leszek Koltunski
     mVBO1.markForDeletion();
1107
     mVBO2.markForDeletion();
1108 466450b5 Leszek Koltunski
     mTFO.markForDeletion();
1109 8b36dabf Leszek Koltunski
     mUBA.markForDeletion();
1110 46d463a4 Leszek Koltunski
1111
     if( mUBC!=null )
1112
       {
1113
       mUBC.markForDeletion();
1114
       }
1115 466450b5 Leszek Koltunski
     }
1116 fa8bc998 Leszek Koltunski
1117 e8925fcd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1118
/**
1119
 * Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
1120
 * <p>
1121
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effect
1122
 * contains any Dynamics, they will be evaluated at 0.
1123
 *
1124
 * @param effect List of Matrix Effects to apply to the Mesh.
1125
 * @param andAssoc 'Logical AND' association which defines which components will be affected.
1126
 * @param equAssoc 'equality' association which defines which components will be affected.
1127
 */
1128
   public void apply(MatrixEffect effect, int andAssoc, int equAssoc)
1129
     {
1130
     if( mJobNode[0]==null )
1131
       {
1132
       applyMatrix(effect,andAssoc,equAssoc);
1133
       }
1134
     else
1135
       {
1136
       mJobNode[0] = DeferredJobs.matrix(this,effect,andAssoc,equAssoc);
1137
       }
1138
     }
1139
1140 fa8bc998 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1141
/**
1142 f046b159 Leszek Koltunski
 * Apply a Vertex Effect to the vertex mesh.
1143 fa8bc998 Leszek Koltunski
 * <p>
1144 c90aca24 Leszek Koltunski
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effects
1145 f046b159 Leszek Koltunski
 * contain any Dynamics, the Dynamics will be evaluated at 0.
1146 fa8bc998 Leszek Koltunski
 *
1147 f046b159 Leszek Koltunski
 * We would call this several times building up a list of Effects to do. This list of effects gets
1148
 * lazily executed only when the Mesh is used for rendering for the first time.
1149 e172985c Leszek Koltunski
 *
1150 f046b159 Leszek Koltunski
 * @param effect Vertex Effect to apply to the Mesh.
1151 fa8bc998 Leszek Koltunski
 */
1152 f046b159 Leszek Koltunski
   public void apply(VertexEffect effect)
1153 fa8bc998 Leszek Koltunski
     {
1154 71d8aba1 Leszek Koltunski
     mJobNode[0] = DeferredJobs.vertex(this,effect);
1155 c90aca24 Leszek Koltunski
     }
1156
1157
///////////////////////////////////////////////////////////////////////////////////////////////////
1158
/**
1159 a3a05347 Leszek Koltunski
 * Sets texture maps for (some of) the components of this mesh.
1160 c90aca24 Leszek Koltunski
 * <p>
1161 a3a05347 Leszek Koltunski
 * Format: ( x of lower-left corner, y of lower-left corner, width, height ).
1162
 * For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
1163 0d4aae88 Leszek Koltunski
 * upper-left quadrant of the texture.
1164 a3a05347 Leszek Koltunski
 * <p>
1165
 * Probably the most common user case would be sending as many maps as there are components in this
1166
 * Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
1167
 * to null (those will be ignored as well). So if there are 5 components, and we want to set the map
1168
 * of the 2nd and 4rd one, call this with
1169
 * maps = new Static4D[4]
1170
 * maps[0] = null
1171
 * maps[1] = the map for the 2nd component
1172
 * maps[2] = null
1173
 * maps[3] = the map for the 4th component
1174
 *
1175
 * A map's width and height have to be non-zero (but can be negative!)
1176 e172985c Leszek Koltunski
 *
1177 dbe3079d Leszek Koltunski
 * @param maps            List of texture maps to apply to the texture's components.
1178
 * @param startComponent  the component the first of the maps refers to.
1179 c90aca24 Leszek Koltunski
 */
1180 dbe3079d Leszek Koltunski
   public void setTextureMap(Static4D[] maps, int startComponent)
1181 c90aca24 Leszek Koltunski
     {
1182 1fad573e Leszek Koltunski
     if( mJobNode[0]==null )
1183 ea88d502 Leszek Koltunski
       {
1184 dbe3079d Leszek Koltunski
       textureMap(maps,startComponent);
1185 1fad573e Leszek Koltunski
       }
1186
     else
1187
       {
1188 dbe3079d Leszek Koltunski
       mJobNode[0] = DeferredJobs.textureMap(this,maps,startComponent);
1189 ea88d502 Leszek Koltunski
       }
1190 fa8bc998 Leszek Koltunski
     }
1191 9099e567 Leszek Koltunski
1192 e172985c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1193
/**
1194
 * Return the texture map of one of the components.
1195
 *
1196
 * @param component The component number whose texture map we want to retrieve.
1197
 */
1198
   public Static4D getTextureMap(int component)
1199
     {
1200 e8925fcd Leszek Koltunski
     return (component>=0 && component<mTexComponent.size()) ? mTexComponent.get(component).mTextureMap : null;
1201 e172985c Leszek Koltunski
     }
1202 cbd502ec Leszek Koltunski
1203
///////////////////////////////////////////////////////////////////////////////////////////////////
1204
/**
1205 1e672c1d Leszek Koltunski
 * Set Effect association.
1206 bc208a9c Leszek Koltunski
 *
1207 1e672c1d Leszek Koltunski
 * This creates an association between a Component of this Mesh and a Vertex Effect.
1208 2aeb75aa Leszek Koltunski
 * One can set two types of associations - an 'logical and' and a 'equal' associations and the Effect
1209
 * will only be active on vertices of Components such that
1210 36d65d88 Leszek Koltunski
 *
1211 2aeb75aa Leszek Koltunski
 * (effect andAssoc) & (component andAssoc) != 0 || (effect equAssoc) == (mesh equAssoc)
1212 36d65d88 Leszek Koltunski
 *
1213
 * (see main_vertex_shader)
1214 bc208a9c Leszek Koltunski
 *
1215
 * The point: this way we can configure the system so that each Vertex Effect acts only on a certain
1216 1e672c1d Leszek Koltunski
 * subset of a Mesh, thus potentially significantly reducing the number of render calls.
1217 cbd502ec Leszek Koltunski
 */
1218 26671ef8 Leszek Koltunski
   public void setEffectAssociation(int component, int andAssociation, int equAssociation)
1219
     {
1220
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1221
       {
1222
       if( mJobNode[0]==null )
1223
         {
1224
         setEffectAssociationNow(component, andAssociation, equAssociation);
1225
         }
1226
       else
1227
         {
1228
         mJobNode[0] = DeferredJobs.effectAssoc(this,component,andAssociation,equAssociation);
1229
         }
1230
       }
1231
     }
1232 bc208a9c Leszek Koltunski
1233 7a9edb92 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1234
/**
1235
 * Set center of a Component.
1236
 *
1237
 * A 'center' of a (effect) component is a 3D point in space. The array of centers gets sent to
1238
 * the vertex shader as a Uniform Buffer Object; in the vertex shader we can then use it to compute
1239
 * the 'Inflation' of the whole Mesh per-component. 'Inflation' is needed by postprocess effects to
1240
 * add the 'halo' around an object.
1241
 *
1242
 * This is all 'per-component' so that a user has a chance to make the halo look right in case of
1243
 * non-convex meshes: then we need to ensure that each component of such a mesh is a convex
1244
 * sub-mesh with its center being more-or-less the center of gravity of the sub-mesh.
1245
 */
1246
   public void setComponentCenter(int component, float centerX, float centerY, float centerZ)
1247
     {
1248
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1249
       {
1250
       if( mJobNode[0]==null )
1251
         {
1252
         setComponentCenterNow(component, centerX, centerY, centerZ);
1253
         }
1254
       else
1255
         {
1256
         mJobNode[0] = DeferredJobs.componentCenter(this,component,centerX, centerY, centerZ);
1257
         }
1258
       }
1259
     }
1260
1261 c92c163c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1262
/**
1263
 * Adds an empty (no vertices) texture component to the end of the text component list.
1264
 *
1265
 * Sometimes we want to do this to have several Meshes with equal number of tex components each.
1266
 */
1267
   public void addEmptyTexComponent()
1268
     {
1269
      if( mJobNode[0]==null )
1270
       {
1271
       addEmptyTexComponentNow();
1272
       }
1273
     else
1274
       {
1275
       mJobNode[0] = DeferredJobs.addEmptyTex(this);
1276
       }
1277
     }
1278
1279 524e4fe7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1280
/**
1281
 * Return the number of texture components, i.e. individual subsets of the whole set of vertices
1282
 * which can be independently textured.
1283
 *
1284
 * @return The number of Texture Components of this Mesh.
1285
 */
1286
   public int numTexComponents()
1287
     {
1288
     return mTexComponent.size();
1289
     }
1290
1291
///////////////////////////////////////////////////////////////////////////////////////////////////
1292
/**
1293
 * Return the number of 'effect' components, i.e. individual subsets of the whole set of vertices
1294
 * to which a VertexEffect can be addressed, independently of other vertices.
1295
 *
1296
 * @return The number of Effect Components of this Mesh.
1297
 */
1298
   public int numEffComponents()
1299
     {
1300
     return mEffComponent.size();
1301
     }
1302
1303 bc208a9c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1304
/**
1305 4f81e0c8 Leszek Koltunski
 * Copy the Mesh.
1306
 *
1307
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
1308 a2878a67 Leszek Koltunski
 *             and normals (the rest, in particular the mVertAttribs2 containing texture
1309 36d65d88 Leszek Koltunski
 *             coordinates and effect associations, is always deep copied)
1310 bc208a9c Leszek Koltunski
 */
1311 4f81e0c8 Leszek Koltunski
   public abstract MeshBase copy(boolean deep);
1312 bc208a9c Leszek Koltunski
   }