Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / MeshBase.java @ 80961fc1

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