Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / MeshBase.java @ 7a9edb92

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// 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
// Distorted is distributed in the hope that it will be useful,                                  //
12
// 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
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.mesh;
21

    
22
import android.opengl.GLES30;
23
import android.opengl.Matrix;
24
import android.util.Log;
25

    
26
import org.distorted.library.effect.MatrixEffect;
27
import org.distorted.library.effect.VertexEffect;
28
import org.distorted.library.main.InternalBuffer;
29
import org.distorted.library.program.DistortedProgram;
30
import org.distorted.library.type.Static4D;
31

    
32
import java.io.DataOutputStream;
33
import java.io.IOException;
34
import java.io.DataInputStream;
35
import java.nio.ByteBuffer;
36
import java.nio.ByteOrder;
37
import java.nio.FloatBuffer;
38
import java.util.ArrayList;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
/**
42
 * Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
43
 * <p>
44
 * If you want to render to a particular shape, extend from here, construct a float array
45
 * containing per-vertex attributes, and call back setAttribs().
46
 */
47
public abstract class MeshBase
48
   {
49
   private static final int ASSOC_UBO_BINDING  = 3;
50
   private static final int CENTER_UBO_BINDING = 4;
51
           static final int MAX_EFFECT_COMPONENTS= 100;
52

    
53
   // sizes of attributes of an individual vertex.
54
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
55
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
56
   private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
57
   private static final int COM_DATA_SIZE= 1; // component number, a single float
58

    
59
   static final int POS_ATTRIB   = 0;
60
   static final int NOR_ATTRIB   = POS_DATA_SIZE;
61
   static final int TEX_ATTRIB   = 0;
62
   static final int COM_ATTRIB   = TEX_DATA_SIZE;
63

    
64
   static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE;  // number of attributes of a vertex (the part changed by preapply)
65
   static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE;  // number of attributes of a vertex (the 'preapply invariant' part)
66
   static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE;  // number of attributes of a transform feedback vertex
67

    
68
   private static final int BYTES_PER_FLOAT = 4;
69

    
70
   private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
71
   private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
72
   private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
73
   private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT;
74

    
75
   private static final int TRAN_SIZE  = TRAN_ATTRIBS*BYTES_PER_FLOAT;
76
   private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT;
77
   private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT;
78

    
79
   private boolean mShowNormals;              // when rendering this mesh, draw normal vectors?
80
   private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
81
   private int mNumVertices;
82
   private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ
83
   private float[] mVertAttribs2;             // packed: TexS,TexT, Component
84
   private float mInflate;
85
   private UniformBlockAssociation mUBA;
86
   private UniformBlockCenter mUBC;
87

    
88
   DeferredJobs.JobNode[] mJobNode;
89

    
90
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
91

    
92
   private static class TexComponent
93
     {
94
     private int mEndIndex;
95
     private Static4D mTextureMap;
96

    
97
     TexComponent(int end)
98
       {
99
       mEndIndex  = end;
100
       mTextureMap= new Static4D(0,0,1,1);
101
       }
102
     TexComponent(TexComponent original)
103
       {
104
       mEndIndex = original.mEndIndex;
105

    
106
       float x = original.mTextureMap.get0();
107
       float y = original.mTextureMap.get1();
108
       float z = original.mTextureMap.get2();
109
       float w = original.mTextureMap.get3();
110
       mTextureMap = new Static4D(x,y,z,w);
111
       }
112

    
113
     void setMap(Static4D map)
114
       {
115
       mTextureMap.set(map.get0(),map.get1(),map.get2(),map.get3());
116
       }
117
     }
118

    
119
   private ArrayList<TexComponent> mTexComponent;
120
   private ArrayList<Integer> mEffComponent;
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
   MeshBase()
125
     {
126
     mShowNormals  = false;
127
     mInflate      = 0.0f;
128
     mTexComponent = new ArrayList<>();
129
     mEffComponent = new ArrayList<>();
130

    
131
     mJobNode = new DeferredJobs.JobNode[1];
132

    
133
     mUBA = new UniformBlockAssociation();
134
     mUBC = new UniformBlockCenter();
135

    
136
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
137
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
138
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
139
     }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
// copy constructor
143

    
144
   MeshBase(MeshBase original, boolean deep)
145
     {
146
     mShowNormals= original.mShowNormals;
147
     mInflate    = original.mInflate;
148
     mNumVertices= original.mNumVertices;
149

    
150
     mUBA = new UniformBlockAssociation(original.mUBA);
151
     mUBC = new UniformBlockCenter(original.mUBC);
152

    
153
     if( deep )
154
       {
155
       mJobNode = new DeferredJobs.JobNode[1];
156
       if( original.mJobNode[0]==null ) copy(original);
157
       else mJobNode[0] = DeferredJobs.copy(this,original);
158
       }
159
     else
160
       {
161
       mJobNode      = original.mJobNode;
162
       mVBO1         = original.mVBO1;
163
       mVertAttribs1 = original.mVertAttribs1;
164
       shallowCopy(original);
165
       }
166

    
167
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
168
     }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
   void copy(MeshBase original)
173
     {
174
     shallowCopy(original);
175

    
176
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
177
     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
178
     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
179
     mVBO1.invalidate();
180
     }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
   private void shallowCopy(MeshBase original)
185
     {
186
     int texComSize = original.mTexComponent.size();
187
     mTexComponent = new ArrayList<>();
188

    
189
     for(int i=0; i<texComSize; i++)
190
       {
191
       TexComponent comp = new TexComponent(original.mTexComponent.get(i));
192
       mTexComponent.add(comp);
193
       }
194

    
195
     mEffComponent = new ArrayList<>();
196
     mEffComponent.addAll(original.mEffComponent);
197

    
198
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
199
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
200
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
201
     mVBO2.invalidate();
202
     }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
   void mergeTexComponentsNow()
207
     {
208
     int num = mTexComponent.size();
209

    
210
     if( num>1 )
211
       {
212
       mTexComponent.clear();
213
       mTexComponent.add(new TexComponent(mNumVertices-1));
214

    
215
       mVBO2.invalidate();
216
       }
217
     }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
   void mergeEffComponentsNow()
222
     {
223
     int num = mEffComponent.size();
224

    
225
     if( num>1 )
226
       {
227
       mEffComponent.clear();
228
       mEffComponent.add(mNumVertices-1);
229

    
230
       for(int index=0; index<mNumVertices; index++)
231
         {
232
         mVertAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = 0;
233
         }
234

    
235
       mVBO2.invalidate();
236
       }
237
     }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

    
241
   void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
242
     {
243
     float[] matrixP  = new float[16];
244
     float[] matrixV  = new float[16];
245
     float[] uniforms = new float[7];
246
     int start, end=-1, numComp = mEffComponent.size();
247

    
248
     Matrix.setIdentityM(matrixP,0);
249
     Matrix.setIdentityM(matrixV,0);
250
     effect.compute(uniforms,0,0,0);
251
     effect.apply(matrixP, matrixV, uniforms, 0);
252

    
253
     for(int comp=0; comp<numComp; comp++)
254
       {
255
       start = end+1;
256
       end   = mEffComponent.get(comp);
257

    
258
       if( mUBA.matchesAssociation(comp, andAssoc, equAssoc) )
259
         {
260
         applyMatrixToComponent(matrixP, matrixV, start, end);
261
         }
262
       }
263

    
264
     mVBO1.invalidate();
265
     }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
   private void applyMatrixToComponent(float[] matrixP, float[] matrixV, int start, int end)
270
     {
271
     float x,y,z;
272

    
273
     for(int index=start*VERT1_ATTRIBS; index<=end*VERT1_ATTRIBS; index+=VERT1_ATTRIBS )
274
       {
275
       x = mVertAttribs1[index+POS_ATTRIB  ];
276
       y = mVertAttribs1[index+POS_ATTRIB+1];
277
       z = mVertAttribs1[index+POS_ATTRIB+2];
278

    
279
       mVertAttribs1[index+POS_ATTRIB  ] = matrixP[0]*x + matrixP[4]*y + matrixP[ 8]*z + matrixP[12];
280
       mVertAttribs1[index+POS_ATTRIB+1] = matrixP[1]*x + matrixP[5]*y + matrixP[ 9]*z + matrixP[13];
281
       mVertAttribs1[index+POS_ATTRIB+2] = matrixP[2]*x + matrixP[6]*y + matrixP[10]*z + matrixP[14];
282

    
283
       x = mVertAttribs1[index+NOR_ATTRIB  ];
284
       y = mVertAttribs1[index+NOR_ATTRIB+1];
285
       z = mVertAttribs1[index+NOR_ATTRIB+2];
286

    
287
       mVertAttribs1[index+NOR_ATTRIB  ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z;
288
       mVertAttribs1[index+NOR_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z;
289
       mVertAttribs1[index+NOR_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z;
290

    
291
       x = mVertAttribs1[index+NOR_ATTRIB  ];
292
       y = mVertAttribs1[index+NOR_ATTRIB+1];
293
       z = mVertAttribs1[index+NOR_ATTRIB+2];
294

    
295
       float len1 = (float)Math.sqrt(x*x + y*y + z*z);
296

    
297
       if( len1>0.0f )
298
         {
299
         mVertAttribs1[index+NOR_ATTRIB  ] /= len1;
300
         mVertAttribs1[index+NOR_ATTRIB+1] /= len1;
301
         mVertAttribs1[index+NOR_ATTRIB+2] /= len1;
302
         }
303
       }
304
     }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
   void setEffectAssociationNow(int component, int andAssociation, int equAssociation)
309
     {
310
     mUBA.setEffectAssociationNow(component, andAssociation, equAssociation);
311
     }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

    
315
   void setComponentCenterNow(int component, float x, float y, float z)
316
     {
317
     mUBC.setEffectCenterNow(component, x, y, z);
318
     }
319

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321
// when a derived class is done computing its mesh, it has to call this method.
322

    
323
   void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
324
     {
325
     mNumVertices = vert1Attribs.length/VERT1_ATTRIBS;
326
     mVertAttribs1= vert1Attribs;
327
     mVertAttribs2= vert2Attribs;
328

    
329
     mTexComponent.add(new TexComponent(mNumVertices-1));
330
     mEffComponent.add(mNumVertices-1);
331

    
332
     mVBO1.invalidate();
333
     mVBO2.invalidate();
334
     }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
   void joinAttribs(MeshBase[] meshes)
339
     {
340
     MeshBase mesh;
341
     TexComponent comp;
342
     int numMeshes = meshes.length;
343
     int numVertices,origVertices = mNumVertices;
344
     int origTexComponents,numTexComponents;
345
     int origEffComponents=0,numEffComponents;
346

    
347
     if( origVertices>0 )
348
       {
349
       origTexComponents = mTexComponent.size();
350
       mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
351
       mTexComponent.get(origTexComponents-1).mEndIndex = mNumVertices-1;
352
       origEffComponents = mEffComponent.size();
353
       mEffComponent.set(origEffComponents-1,mNumVertices-1);
354
       }
355

    
356
     for(int i=0; i<numMeshes; i++)
357
       {
358
       mesh = meshes[i];
359
       numTexComponents = mesh.mTexComponent.size();
360
       numEffComponents = mesh.mEffComponent.size();
361
       numVertices = mesh.mNumVertices;
362

    
363
       int extraVerticesBefore = mNumVertices==0 ? 0:1;
364
       int extraVerticesAfter  = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1);
365

    
366
       for(int j=0; j<numTexComponents; j++)
367
         {
368
         comp = new TexComponent(mesh.mTexComponent.get(j));
369
         comp.mEndIndex += (extraVerticesBefore+mNumVertices);
370
         if( j==numTexComponents-1) comp.mEndIndex += extraVerticesAfter;
371
         mTexComponent.add(comp);
372
         }
373

    
374
       for(int j=0; j<numEffComponents; j++)
375
         {
376
         int index = mesh.mEffComponent.get(j);
377
         index += (extraVerticesBefore+mNumVertices);
378
         if( j==numEffComponents-1 ) index += extraVerticesAfter;
379
         mEffComponent.add(index);
380

    
381
         if( origEffComponents<MAX_EFFECT_COMPONENTS )
382
           {
383
           mUBA.copy(origEffComponents, mesh.mUBA, j);
384
           mUBC.copy(origEffComponents, mesh.mUBC, j);
385
           origEffComponents++;
386
           }
387
         }
388

    
389
       mNumVertices += (extraVerticesBefore+numVertices+extraVerticesAfter);
390
       }
391

    
392
     float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
393
     float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
394
     numVertices = origVertices;
395

    
396
     if( origVertices>0 )
397
       {
398
       System.arraycopy(mVertAttribs1,                              0, newAttribs1,                          0, VERT1_ATTRIBS*numVertices);
399
       System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS            );
400
       System.arraycopy(mVertAttribs2,                              0, newAttribs2,                          0, VERT2_ATTRIBS*numVertices);
401
       System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS            );
402
       origVertices++;
403

    
404
       if( numVertices%2==1 )
405
         {
406
         System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
407
         System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
408
         origVertices++;
409
         }
410
       }
411

    
412
     for(int i=0; i<numMeshes; i++)
413
       {
414
       mesh = meshes[i];
415
       numVertices = mesh.mNumVertices;
416

    
417
       if( origVertices>0 )
418
         {
419
         System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
420
         System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
421
         origVertices++;
422
         }
423
       System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
424
       System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices);
425
       origVertices+=numVertices;
426

    
427
       if( i<numMeshes-1 )
428
         {
429
         System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
430
         System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
431
         origVertices++;
432

    
433
         if( numVertices%2==1 )
434
           {
435
           System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
436
           System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
437
           origVertices++;
438
           }
439
         }
440
       }
441

    
442
     if( origVertices!=mNumVertices )
443
       {
444
       android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
445
       }
446

    
447
     int endIndex, index=0, numEffComp = mEffComponent.size();
448

    
449
     for(int component=0; component<numEffComp; component++)
450
       {
451
       endIndex = mEffComponent.get(component);
452

    
453
       for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component;
454
       }
455

    
456
     mVertAttribs1 = newAttribs1;
457
     mVertAttribs2 = newAttribs2;
458
     mVBO1.invalidate();
459
     mVBO2.invalidate();
460
     }
461

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463
// called from MeshJoined
464

    
465
   void join(MeshBase[] meshes)
466
     {
467
     boolean immediateJoin = true;
468

    
469
     for (MeshBase mesh : meshes)
470
       {
471
       if (mesh.mJobNode[0] != null)
472
         {
473
         immediateJoin = false;
474
         break;
475
         }
476
       }
477

    
478
     if( immediateJoin ) joinAttribs(meshes);
479
     else                mJobNode[0] = DeferredJobs.join(this,meshes);
480
     }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
   void textureMap(Static4D[] maps, int startComponent)
485
     {
486
     int num_comp = mTexComponent.size();
487
     int num_maps = maps.length;
488
     int min = Math.min(num_comp-startComponent, num_maps);
489
     int vertex = startComponent>0 ? mTexComponent.get(startComponent-1).mEndIndex+1 : 0;
490
     Static4D newMap, oldMap;
491
     TexComponent comp;
492
     float newW, newH, ratW, ratH, movX, movY;
493

    
494
     for(int i=0; i<min; i++)
495
       {
496
       newMap = maps[i];
497
       comp = mTexComponent.get(i+startComponent);
498

    
499
       if( newMap!=null )
500
         {
501
         newW = newMap.get2();
502
         newH = newMap.get3();
503

    
504
         if( newW!=0.0f && newH!=0.0f )
505
           {
506
           oldMap = comp.mTextureMap;
507
           ratW = newW/oldMap.get2();
508
           ratH = newH/oldMap.get3();
509
           movX = newMap.get0() - ratW*oldMap.get0();
510
           movY = newMap.get1() - ratH*oldMap.get1();
511

    
512
           for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
513
             {
514
             mVertAttribs2[index  ] = ratW*mVertAttribs2[index  ] + movX;
515
             mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
516
             }
517
           comp.setMap(newMap);
518
           }
519
         }
520

    
521
       vertex= comp.mEndIndex+1;
522
       }
523

    
524
     mVBO2.invalidate();
525
     }
526

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528

    
529
   public static int getMaxEffComponents()
530
     {
531
     return MAX_EFFECT_COMPONENTS;
532
     }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535
/**
536
 * Not part of public API, do not document (public only because has to be used from the main package)
537
 *
538
 * @y.exclude
539
 */
540
   public void copyTransformToVertex()
541
     {
542
     ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0,
543
                                                              TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT);
544
     if( buffer!=null )
545
       {
546
       FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
547
       feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices);
548
       mVBO1.updateFloat(mVertAttribs1);
549
       }
550
     else
551
       {
552
       int error = GLES30.glGetError();
553
       Log.e("mesh", "failed to map tf buffer, error="+error);
554
       }
555

    
556
     GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
557
     }
558

    
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560
/**
561
 * Not part of public API, do not document (public only because has to be used from the main package)
562
 *
563
 * @y.exclude
564
 */
565
   public void debug()
566
     {
567
     if( mJobNode[0]!=null )
568
       {
569
       mJobNode[0].print(0);
570
       }
571
     else
572
       {
573
       android.util.Log.e("mesh", "JobNode null");
574
       }
575
     }
576

    
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578
/**
579
 * Not part of public API, do not document (public only because has to be used from the main package)
580
 *
581
 * @y.exclude
582
 */
583
   public void printPos()
584
     {
585
     StringBuilder sb = new StringBuilder();
586

    
587
     for(int i=0; i<mNumVertices; i++)
588
       {
589
       sb.append('(');
590
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB  ]);
591
       sb.append(',');
592
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+1]);
593
       sb.append(',');
594
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+2]);
595
       sb.append(") ");
596
       }
597
     Log.d("mesh", sb.toString());
598
     }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601
/**
602
 * Not part of public API, do not document (public only because has to be used from the main package)
603
 *
604
 * @y.exclude
605
 */
606
   public void printCom()
607
     {
608
     StringBuilder sb = new StringBuilder();
609

    
610
     for(int i=0; i<mNumVertices; i++)
611
       {
612
       sb.append(mVertAttribs2[VERT2_ATTRIBS*i+COM_ATTRIB]);
613
       sb.append(' ');
614
       }
615

    
616
     Log.d("mesh", sb.toString());
617
     }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620
/**
621
 * Not part of public API, do not document (public only because has to be used from the main package)
622
 *
623
 * @y.exclude
624
 */
625
   public void printTex()
626
     {
627
     int vert=0;
628
     int num = numTexComponents();
629
     StringBuilder sb = new StringBuilder();
630
     sb.append("tex components: ").append(num);
631

    
632
     for(int i=0; i<num; i++)
633
       {
634
       int end = mTexComponent.get(i).mEndIndex;
635
       sb.append("\n");
636

    
637
       for( ; vert<=end; vert++)
638
         {
639
         sb.append(' ');
640
         sb.append('(');
641
         sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB]);
642
         sb.append(',');
643
         sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB+1]);
644
         sb.append(')');
645
         }
646
       }
647

    
648
     Log.d("mesh", sb.toString());
649
     }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652
/**
653
 * Not part of public API, do not document (public only because has to be used from the main package)
654
 *
655
 * @y.exclude
656
 */
657
   public int getTFO()
658
     {
659
     return mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
660
     }
661

    
662
///////////////////////////////////////////////////////////////////////////////////////////////////
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 int getNumVertices()
669
     {
670
     return mNumVertices;
671
     }
672

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674
/**
675
 * Not part of public API, do not document (public only because has to be used from the main package)
676
 *
677
 * @y.exclude
678
 */
679
   public void send(int programH)
680
     {
681
     int indexA = mUBA.getIndex();
682
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA);
683
     GLES30.glUniformBlockBinding(programH, ASSOC_UBO_BINDING, indexA);
684

    
685
     int indexC = mUBC.getIndex();
686
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
687
     GLES30.glUniformBlockBinding(programH, CENTER_UBO_BINDING, indexC);
688
     }
689

    
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
/**
692
 * Not part of public API, do not document (public only because has to be used from the main package)
693
 *
694
 * @y.exclude
695
 */
696
   public void bindVertexAttribs(DistortedProgram program)
697
     {
698
     if( mJobNode[0]!=null )
699
       {
700
       mJobNode[0].execute();  // this will set itself to null
701
/*
702
       try
703
         {
704
         String name = "/sdcard/"+mNumVertices+".dmesh";
705
         DataOutputStream dos = new DataOutputStream(new java.io.FileOutputStream(name));
706
         write(dos);
707
         android.util.Log.e("mesh", "file written: "+name);
708
         }
709
       catch(java.io.FileNotFoundException ex)
710
         {
711
         android.util.Log.e("mesh", "file not found exception: "+ex.toString());
712
         }
713
 */
714
       }
715

    
716
     int index1 = mVBO1.createImmediatelyFloat(mNumVertices*VERT1_SIZE, mVertAttribs1);
717
     int index2 = mVBO2.createImmediatelyFloat(mNumVertices*VERT2_SIZE, mVertAttribs2);
718

    
719
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 );
720
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS);
721
     GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR);
722
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 );
723
     GLES30.glVertexAttribPointer(program.mAttribute[2], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
724
     GLES30.glVertexAttribPointer(program.mAttribute[3], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
725
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
726
     }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729
/**
730
 * Not part of public API, do not document (public only because has to be used from the main package)
731
 *
732
 * @y.exclude
733
 */
734
   public void bindTransformAttribs(DistortedProgram program)
735
     {
736
     int index = mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
737

    
738
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index );
739
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
740
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
741
     }
742

    
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744
/**
745
 * Not part of public API, do not document (public only because has to be used from the main package)
746
 *
747
 * @y.exclude
748
 */
749
   public void setInflate(float inflate)
750
     {
751
     mInflate = inflate;
752
     }
753

    
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755
/**
756
 * Not part of public API, do not document (public only because has to be used from the main package)
757
 *
758
 * @y.exclude
759
 */
760
   public float getInflate()
761
     {
762
     return mInflate;
763
     }
764

    
765
///////////////////////////////////////////////////////////////////////////////////////////////////
766
// Return the number of bytes read.
767

    
768
   int read(DataInputStream stream)
769
     {
770
     byte[] buffer = new byte[BYTES_PER_FLOAT*4];
771
     int version, numEff, numTex;
772

    
773
     //////////////////////////////////////////////////////////////////////////////////////////
774
     // read version, number of vertices, number of tex components, number of effect components
775
     //////////////////////////////////////////////////////////////////////////////////////////
776

    
777
     try
778
       {
779
       stream.read(buffer);
780
       ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
781

    
782
       version = byteBuf.getInt(0);
783

    
784
       if( version==1 || version==2 )
785
         {
786
         mNumVertices= byteBuf.getInt(4);
787
         numTex      = byteBuf.getInt(8);
788
         numEff      = byteBuf.getInt(12);
789
         }
790
       else
791
         {
792
         android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
793
         return 0;
794
         }
795
       }
796
     catch(IOException e)
797
       {
798
       android.util.Log.e("mesh", "IOException1 trying to read file: "+e.toString());
799
       return 0;
800
       }
801

    
802
     //////////////////////////////////////////////////////////////////////////////////////////
803
     // read contents of all texture and effect components
804
     //////////////////////////////////////////////////////////////////////////////////////////
805

    
806
     if( mNumVertices>0 && numEff>0 && numTex>0 )
807
       {
808
       int size = numEff+TEX_COMP_SIZE*numTex;
809
       float[] tmp = new float[size];
810
       mVertAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
811
       mVertAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
812

    
813
       // version 1 had extra 3 floats (the 'inflate' vector) in its vert1 array
814
       int vert1InFile = version==2 ? VERT1_ATTRIBS : VERT1_ATTRIBS+3;
815
       // ... and there was no center.
816
       int centerSize  = version==2 ? 3*numEff : 0;
817

    
818
       buffer = new byte[BYTES_PER_FLOAT*(size + centerSize + mNumVertices*(vert1InFile+VERT2_ATTRIBS))];
819

    
820
       try
821
         {
822
         stream.read(buffer);
823
         }
824
       catch(IOException e)
825
         {
826
         android.util.Log.e("mesh", "IOException2 trying to read file: "+e.toString());
827
         return 0;
828
         }
829

    
830
       ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
831
       FloatBuffer floatBuf = byteBuf.asFloatBuffer();
832

    
833
       floatBuf.get(tmp,0,size);
834

    
835
       TexComponent tex;
836
       int index, texComp;
837
       float x, y, z, w;
838

    
839
       for(texComp=0; texComp<numTex; texComp++)
840
         {
841
         index = (int)tmp[TEX_COMP_SIZE*texComp];
842

    
843
         x= tmp[TEX_COMP_SIZE*texComp+1];
844
         y= tmp[TEX_COMP_SIZE*texComp+2];
845
         z= tmp[TEX_COMP_SIZE*texComp+3];
846
         w= tmp[TEX_COMP_SIZE*texComp+4];
847

    
848
         tex = new TexComponent(index);
849
         tex.setMap(new Static4D(x,y,z,w));
850

    
851
         mTexComponent.add(tex);
852
         }
853

    
854
       for(int effComp=0; effComp<numEff; effComp++)
855
         {
856
         index = (int)tmp[TEX_COMP_SIZE*texComp + effComp ];
857
         mEffComponent.add(index);
858
         }
859

    
860
       //////////////////////////////////////////////////////////////////////////////////////////
861
       // read vert1 array, vert2 array and (if version>1) the component centers.
862
       //////////////////////////////////////////////////////////////////////////////////////////
863

    
864
       switch(version)
865
         {
866
         case 1 : index = floatBuf.position();
867

    
868
                  for(int vert=0; vert<mNumVertices; vert++)
869
                    {
870
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB  ] = floatBuf.get(index+POS_ATTRIB  );
871
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+1] = floatBuf.get(index+POS_ATTRIB+1);
872
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+2] = floatBuf.get(index+POS_ATTRIB+2);
873
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB  ] = floatBuf.get(index+NOR_ATTRIB  );
874
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+1] = floatBuf.get(index+NOR_ATTRIB+1);
875
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+2] = floatBuf.get(index+NOR_ATTRIB+2);
876
                    index+=vert1InFile;
877
                    }
878
                  floatBuf.position(index);
879
                  break;
880
         case 2 : float[] centers = new float[3*numEff];
881
                  floatBuf.get(centers,0,3*numEff);
882

    
883
                  for(int eff=0; eff<numEff; eff++)
884
                    {
885
                    mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]);
886
                    }
887

    
888
                  floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices);
889
                  break;
890
         default: android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
891
                  return 0;
892
         }
893

    
894
       floatBuf.get(mVertAttribs2, 0, VERT2_ATTRIBS*mNumVertices);
895
       }
896

    
897
     return BYTES_PER_FLOAT*( 4 + numEff+TEX_COMP_SIZE*numTex + VERT1_ATTRIBS*mNumVertices + VERT2_ATTRIBS*mNumVertices );
898
     }
899

    
900
///////////////////////////////////////////////////////////////////////////////////////////////////
901
/**
902
 * @y.exclude
903
 */
904
   public int getLastVertexEff(int effComponent)
905
     {
906
     if( effComponent>=0 && effComponent<mTexComponent.size() )
907
       {
908
       return mEffComponent.get(effComponent);
909
       }
910

    
911
     return 0;
912
     }
913

    
914
///////////////////////////////////////////////////////////////////////////////////////////////////
915
/**
916
 * @y.exclude
917
 */
918
   public int getLastVertexTex(int texComponent)
919
     {
920
     if( texComponent>=0 && texComponent<mTexComponent.size() )
921
       {
922
       return mTexComponent.get(texComponent).mEndIndex;
923
       }
924

    
925
     return 0;
926
     }
927

    
928
///////////////////////////////////////////////////////////////////////////////////////////////////
929
// PUBLIC API
930
///////////////////////////////////////////////////////////////////////////////////////////////////
931
/**
932
 * Write the Mesh to a File.
933
 */
934
   public void write(DataOutputStream stream)
935
     {
936
     TexComponent tex;
937

    
938
     int numTex = mTexComponent.size();
939
     int numEff = mEffComponent.size();
940

    
941
     try
942
       {
943
       stream.writeInt(2);  // version
944
       stream.writeInt(mNumVertices);
945
       stream.writeInt(numTex);
946
       stream.writeInt(numEff);
947

    
948
       for(int i=0; i<numTex; i++)
949
         {
950
         tex = mTexComponent.get(i);
951

    
952
         stream.writeFloat((float)tex.mEndIndex);
953
         stream.writeFloat(tex.mTextureMap.get0());
954
         stream.writeFloat(tex.mTextureMap.get1());
955
         stream.writeFloat(tex.mTextureMap.get2());
956
         stream.writeFloat(tex.mTextureMap.get3());
957
         }
958

    
959
       for(int i=0; i<numEff; i++)
960
         {
961
         stream.writeFloat((float)mEffComponent.get(i));
962
         }
963

    
964
       float[] centers = mUBC.getBackingArray();
965

    
966
       for(int i=0; i<numEff; i++)
967
         {
968
         stream.writeFloat(centers[4*i  ]);
969
         stream.writeFloat(centers[4*i+1]);
970
         stream.writeFloat(centers[4*i+2]);
971
         }
972

    
973
       ByteBuffer vertBuf1 = ByteBuffer.allocate(VERT1_SIZE*mNumVertices);
974
       vertBuf1.asFloatBuffer().put(mVertAttribs1);
975
       ByteBuffer vertBuf2 = ByteBuffer.allocate(VERT2_SIZE*mNumVertices);
976
       vertBuf2.asFloatBuffer().put(mVertAttribs2);
977

    
978
       stream.write(vertBuf1.array());
979
       stream.write(vertBuf2.array());
980
       }
981
     catch(IOException ex)
982
       {
983
       android.util.Log.e("mesh", "IOException trying to write a mesh: "+ex.toString());
984
       }
985
     }
986

    
987
///////////////////////////////////////////////////////////////////////////////////////////////////
988
/**
989
 * When rendering this Mesh, do we want to render the Normal vectors as well?
990
 * <p>
991
 * Will work only on OpenGL ES >= 3.0 devices.
992
 *
993
 * @param show Controls if we render the Normal vectors or not.
994
 */
995
   public void setShowNormals(boolean show)
996
     {
997
     mShowNormals = show;
998
     }
999

    
1000
///////////////////////////////////////////////////////////////////////////////////////////////////
1001
/**
1002
 * When rendering this mesh, should we also draw the normal vectors?
1003
 *
1004
 * @return <i>true</i> if we do render normal vectors
1005
 */
1006
   public boolean getShowNormals()
1007
     {
1008
     return mShowNormals;
1009
     }
1010

    
1011
///////////////////////////////////////////////////////////////////////////////////////////////////
1012
/**
1013
 * Merge all texture components of this Mesh into a single one.
1014
 */
1015
   public void mergeTexComponents()
1016
     {
1017
     if( mJobNode[0]==null )
1018
       {
1019
       mergeTexComponentsNow();
1020
       }
1021
     else
1022
       {
1023
       mJobNode[0] = DeferredJobs.mergeTex(this);
1024
       }
1025
     }
1026

    
1027
///////////////////////////////////////////////////////////////////////////////////////////////////
1028
/**
1029
 * Merge all effect components of this Mesh into a single one.
1030
 */
1031
   public void mergeEffComponents()
1032
     {
1033
     if( mJobNode[0]==null )
1034
       {
1035
       mergeEffComponentsNow();
1036
       }
1037
     else
1038
       {
1039
       mJobNode[0] = DeferredJobs.mergeEff(this);
1040
       }
1041
     }
1042

    
1043
///////////////////////////////////////////////////////////////////////////////////////////////////
1044
/**
1045
 * Release all internal resources.
1046
 */
1047
   public void markForDeletion()
1048
     {
1049
     mVertAttribs1 = null;
1050
     mVertAttribs2 = null;
1051

    
1052
     mVBO1.markForDeletion();
1053
     mVBO2.markForDeletion();
1054
     mTFO.markForDeletion();
1055
     }
1056

    
1057
///////////////////////////////////////////////////////////////////////////////////////////////////
1058
/**
1059
 * Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
1060
 * <p>
1061
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effect
1062
 * contains any Dynamics, they will be evaluated at 0.
1063
 *
1064
 * @param effect List of Matrix Effects to apply to the Mesh.
1065
 * @param andAssoc 'Logical AND' association which defines which components will be affected.
1066
 * @param equAssoc 'equality' association which defines which components will be affected.
1067
 */
1068
   public void apply(MatrixEffect effect, int andAssoc, int equAssoc)
1069
     {
1070
     if( mJobNode[0]==null )
1071
       {
1072
       applyMatrix(effect,andAssoc,equAssoc);
1073
       }
1074
     else
1075
       {
1076
       mJobNode[0] = DeferredJobs.matrix(this,effect,andAssoc,equAssoc);
1077
       }
1078
     }
1079

    
1080
///////////////////////////////////////////////////////////////////////////////////////////////////
1081
/**
1082
 * Apply a Vertex Effect to the vertex mesh.
1083
 * <p>
1084
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effects
1085
 * contain any Dynamics, the Dynamics will be evaluated at 0.
1086
 *
1087
 * We would call this several times building up a list of Effects to do. This list of effects gets
1088
 * lazily executed only when the Mesh is used for rendering for the first time.
1089
 *
1090
 * @param effect Vertex Effect to apply to the Mesh.
1091
 */
1092
   public void apply(VertexEffect effect)
1093
     {
1094
     mJobNode[0] = DeferredJobs.vertex(this,effect);
1095
     }
1096

    
1097
///////////////////////////////////////////////////////////////////////////////////////////////////
1098
/**
1099
 * Sets texture maps for (some of) the components of this mesh.
1100
 * <p>
1101
 * Format: ( x of lower-left corner, y of lower-left corner, width, height ).
1102
 * For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
1103
 * upper-left quadrant of the texture.
1104
 * <p>
1105
 * Probably the most common user case would be sending as many maps as there are components in this
1106
 * Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
1107
 * to null (those will be ignored as well). So if there are 5 components, and we want to set the map
1108
 * of the 2nd and 4rd one, call this with
1109
 * maps = new Static4D[4]
1110
 * maps[0] = null
1111
 * maps[1] = the map for the 2nd component
1112
 * maps[2] = null
1113
 * maps[3] = the map for the 4th component
1114
 *
1115
 * A map's width and height have to be non-zero (but can be negative!)
1116
 *
1117
 * @param maps            List of texture maps to apply to the texture's components.
1118
 * @param startComponent  the component the first of the maps refers to.
1119
 */
1120
   public void setTextureMap(Static4D[] maps, int startComponent)
1121
     {
1122
     if( mJobNode[0]==null )
1123
       {
1124
       textureMap(maps,startComponent);
1125
       }
1126
     else
1127
       {
1128
       mJobNode[0] = DeferredJobs.textureMap(this,maps,startComponent);
1129
       }
1130
     }
1131

    
1132
///////////////////////////////////////////////////////////////////////////////////////////////////
1133
/**
1134
 * Return the texture map of one of the components.
1135
 *
1136
 * @param component The component number whose texture map we want to retrieve.
1137
 */
1138
   public Static4D getTextureMap(int component)
1139
     {
1140
     return (component>=0 && component<mTexComponent.size()) ? mTexComponent.get(component).mTextureMap : null;
1141
     }
1142

    
1143
///////////////////////////////////////////////////////////////////////////////////////////////////
1144
/**
1145
 * Set Effect association.
1146
 *
1147
 * This creates an association between a Component of this Mesh and a Vertex Effect.
1148
 * One can set two types of associations - an 'logical and' and a 'equal' associations and the Effect
1149
 * will only be active on vertices of Components such that
1150
 *
1151
 * (effect andAssoc) & (component andAssoc) != 0 || (effect equAssoc) == (mesh equAssoc)
1152
 *
1153
 * (see main_vertex_shader)
1154
 *
1155
 * The point: this way we can configure the system so that each Vertex Effect acts only on a certain
1156
 * subset of a Mesh, thus potentially significantly reducing the number of render calls.
1157
 */
1158
   public void setEffectAssociation(int component, int andAssociation, int equAssociation)
1159
     {
1160
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1161
       {
1162
       if( mJobNode[0]==null )
1163
         {
1164
         setEffectAssociationNow(component, andAssociation, equAssociation);
1165
         }
1166
       else
1167
         {
1168
         mJobNode[0] = DeferredJobs.effectAssoc(this,component,andAssociation,equAssociation);
1169
         }
1170
       }
1171
     }
1172

    
1173
///////////////////////////////////////////////////////////////////////////////////////////////////
1174
/**
1175
 * Set center of a Component.
1176
 *
1177
 * A 'center' of a (effect) component is a 3D point in space. The array of centers gets sent to
1178
 * the vertex shader as a Uniform Buffer Object; in the vertex shader we can then use it to compute
1179
 * the 'Inflation' of the whole Mesh per-component. 'Inflation' is needed by postprocess effects to
1180
 * add the 'halo' around an object.
1181
 *
1182
 * This is all 'per-component' so that a user has a chance to make the halo look right in case of
1183
 * non-convex meshes: then we need to ensure that each component of such a mesh is a convex
1184
 * sub-mesh with its center being more-or-less the center of gravity of the sub-mesh.
1185
 */
1186
   public void setComponentCenter(int component, float centerX, float centerY, float centerZ)
1187
     {
1188
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1189
       {
1190
       if( mJobNode[0]==null )
1191
         {
1192
         setComponentCenterNow(component, centerX, centerY, centerZ);
1193
         }
1194
       else
1195
         {
1196
         mJobNode[0] = DeferredJobs.componentCenter(this,component,centerX, centerY, centerZ);
1197
         }
1198
       }
1199
     }
1200

    
1201
///////////////////////////////////////////////////////////////////////////////////////////////////
1202
/**
1203
 * Return the number of texture components, i.e. individual subsets of the whole set of vertices
1204
 * which can be independently textured.
1205
 *
1206
 * @return The number of Texture Components of this Mesh.
1207
 */
1208
   public int numTexComponents()
1209
     {
1210
     return mTexComponent.size();
1211
     }
1212

    
1213
///////////////////////////////////////////////////////////////////////////////////////////////////
1214
/**
1215
 * Return the number of 'effect' components, i.e. individual subsets of the whole set of vertices
1216
 * to which a VertexEffect can be addressed, independently of other vertices.
1217
 *
1218
 * @return The number of Effect Components of this Mesh.
1219
 */
1220
   public int numEffComponents()
1221
     {
1222
     return mEffComponent.size();
1223
     }
1224

    
1225
///////////////////////////////////////////////////////////////////////////////////////////////////
1226
/**
1227
 * Copy the Mesh.
1228
 *
1229
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
1230
 *             and normals (the rest, in particular the mVertAttribs2 containing texture
1231
 *             coordinates and effect associations, is always deep copied)
1232
 */
1233
   public abstract MeshBase copy(boolean deep);
1234
   }
(2-2/11)