Project

General

Profile

« Previous | Next » 

Revision e8925fcd

Added by Leszek Koltunski almost 4 years ago

Big change to MeshBase:
1) split the list of Components into two: 'texture map' components and 'effect' components.
Reason: imagine the Rubik Cube with a Solver. When setting up a initial position in the Solver, we need to be able to set texture maps of each individual face of each cubit.
Thus previously (when there was only one Component which kept info both about Effect associations and Texture Maps) a 5x5x5 Rubik Cube would have to have 98*6 = almost 600 components.
This alone would mean 1200 uniforms in the Vertex Shader --> more than the guaranteed 1024.
Splitting the Component into two parts lets us merge the 6 'Effect' components of each Rubik Cubit into one (thus leaving only 98 Effect Components in the Verteex Shader --> 196 uniforms) while still allowing for change of the texture map of each individual face.
2) (re-) add the 'apply a matrix effect' (this time with associations)

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
126 126
    String mainVertHeader= version + ("#define NUM_VERTEX "   + ( numV>0 ? DistortedLibrary.getMax(EffectType.VERTEX  ) : 0 ) + "\n");
127 127
    String mainFragHeader= version + "\n";
128 128

  
129
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n";
129
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
130 130

  
131 131
    String enabledEffectV= VertexEffect.getGLSL();
132 132

  
src/main/java/org/distorted/library/main/DistortedLibrary.java
218 218
    String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX  ) : 0 ) + "\n");
219 219
    String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
220 220

  
221
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n";
221
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
222 222

  
223 223
    String enabledEffectV= VertexEffect.getGLSL();
224 224
    String enabledEffectF= FragmentEffect.getGLSL();
......
309 309
    String fullVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
310 310
    String fullFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " +                                         0   + "\n");
311 311

  
312
    fullVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n";
312
    fullVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
313 313

  
314 314
    String enabledEffectV= VertexEffect.getAllGLSL();
315 315
    String enabledEffectF= "{}";
......
348 348
    String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX  ) : 0 ) + "\n") + ("#define OIT\n");
349 349
    String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + ("#define OIT\n");
350 350

  
351
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n";
351
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
352 352

  
353 353
    String enabledEffectV= VertexEffect.getGLSL();
354 354
    String enabledEffectF= FragmentEffect.getGLSL();
src/main/java/org/distorted/library/mesh/DeferredJobs.java
19 19

  
20 20
package org.distorted.library.mesh;
21 21

  
22
import org.distorted.library.effect.MatrixEffect;
22 23
import org.distorted.library.effect.VertexEffect;
23 24
import org.distorted.library.effectqueue.EffectQueueVertex;
24 25
import org.distorted.library.main.DistortedLibrary;
......
36 37
 */
37 38
public class DeferredJobs
38 39
  {
39
  private static final int JOB_TYPE_VERTEX = 0;
40
  private static final int JOB_TYPE_MERGE  = 1;
41
  private static final int JOB_TYPE_JOIN   = 2;
42
  private static final int JOB_TYPE_COPY   = 3;
43
  private static final int JOB_TYPE_TEXTURE= 4;
40
  private static final int JOB_TYPE_VERTEX   = 0;
41
  private static final int JOB_TYPE_MATRIX   = 1;
42
  private static final int JOB_TYPE_MERGE_TEX= 2;
43
  private static final int JOB_TYPE_MERGE_EFF= 3;
44
  private static final int JOB_TYPE_JOIN     = 4;
45
  private static final int JOB_TYPE_COPY     = 5;
46
  private static final int JOB_TYPE_TEXTURE  = 6;
44 47

  
45 48
  private static ArrayList<JobNode> mJobs = new ArrayList<>();
46 49

  
......
51 54
    private int mType;
52 55
    private MeshBase mTarget;
53 56
    private MeshBase[] mSource;
54
    private EffectQueueVertex mEffects;
57
    private EffectQueueVertex mVertexEffects;
58
    private MatrixEffect mMatrixEffect;
55 59
    private Static4D[] mMaps;
60
    private int mAndAssoc, mEcuAssoc;
56 61

  
57
    Job(int type, MeshBase target, MeshBase[] source, VertexEffect effect, Static4D[] maps)
62
    Job(int type, MeshBase target, MeshBase[] source, VertexEffect vEff, MatrixEffect mEff, Static4D[] maps, int and, int ecu)
58 63
      {
59
      mType   = type;
60
      mTarget = target;
61
      mSource = source;
62
      mMaps   = maps;
63

  
64
      if( effect!=null )
64
      mType     = type;
65
      mTarget   = target;
66
      mSource   = source;
67
      mMaps     = maps;
68
      mAndAssoc = and;
69
      mEcuAssoc = ecu;
70

  
71
      if( vEff!=null )
65 72
        {
66
        mEffects= new EffectQueueVertex();
67
        mEffects.add(effect);
73
        mVertexEffects= new EffectQueueVertex();
74
        mVertexEffects.add(vEff);
68 75
        }
76

  
77
      mMatrixEffect = mEff;
69 78
      }
70 79

  
71 80
    void addEffect(VertexEffect effect)
72 81
      {
73
      mEffects.add(effect);
82
      mVertexEffects.add(effect);
74 83
      }
75 84

  
76 85
    void execute()
77 86
      {
78 87
      switch(mType)
79 88
        {
80
        case JOB_TYPE_VERTEX : DistortedLibrary.adjustVertices(mTarget, mEffects);
81
                               //Log.e("jobs", "executing vertex job");
82
                               //mTarget.print();
83
                               break;
84
        case JOB_TYPE_MERGE  : mTarget.merge();
85
                               //Log.e("jobs", "executing merge job");
86
                               //mTarget.print();
87
                               break;
88
        case JOB_TYPE_JOIN   : mTarget.joinAttribs(mSource);
89
                               //Log.e("jobs", "executing join job");
90
                               //mTarget.print();
91
                               break;
92
        case JOB_TYPE_COPY   : mTarget.copy(mSource[0]);
93
                               //Log.e("jobs", "executing copy job");
94
                               //mTarget.print();
95
                               break;
96
        case JOB_TYPE_TEXTURE: mTarget.textureMap(mMaps);
97
                               //Log.e("jobs", "executing textureMap job");
98
                               //mTarget.print();
99
                               break;
89
        case JOB_TYPE_VERTEX   : DistortedLibrary.adjustVertices(mTarget, mVertexEffects);
90
                                 break;
91
        case JOB_TYPE_MATRIX   : mTarget.applyMatrix(mMatrixEffect,mAndAssoc,mEcuAssoc);
92
                                 break;
93
        case JOB_TYPE_MERGE_TEX: mTarget.mergeTexComponentsNow();
94
                                 break;
95
        case JOB_TYPE_MERGE_EFF: mTarget.mergeEffComponentsNow();
96
                                 break;
97
        case JOB_TYPE_JOIN     : mTarget.joinAttribs(mSource);
98
                                 break;
99
        case JOB_TYPE_COPY     : mTarget.copy(mSource[0]);
100
                                 break;
101
        case JOB_TYPE_TEXTURE  : mTarget.textureMap(mMaps);
102
                                 break;
100 103
        }
104
/*
105
      Log.e("jobs", "executing "+print()+" job");
106
      mTarget.print();
107
*/
101 108
      }
102 109

  
103 110
    void clear()
104 111
      {
105
      if( mEffects!=null ) mEffects.removeAll(false);
112
      if( mVertexEffects!=null ) mVertexEffects.removeAll(false);
106 113
      }
107 114

  
108 115
    String print()
109 116
      {
110 117
      switch(mType)
111 118
        {
112
        case JOB_TYPE_VERTEX : return "VERTEX (eff: "+mEffects.getNumEffects()+" effToBe: "+mEffects.getNumEffectsToBe()+")";
113
        case JOB_TYPE_MERGE  : return "MERGE";
114
        case JOB_TYPE_JOIN   : return "JOIN: "+mSource.length;
115
        case JOB_TYPE_COPY   : return "COPY";
116
        case JOB_TYPE_TEXTURE: return "TEXTURE";
119
        case JOB_TYPE_VERTEX   : return "VERTEX";
120
        case JOB_TYPE_MATRIX   : return "MATRIX";
121
        case JOB_TYPE_MERGE_TEX: return "MERGE_TEX";
122
        case JOB_TYPE_MERGE_EFF: return "MERGE_EFF";
123
        case JOB_TYPE_JOIN     : return "JOIN";
124
        case JOB_TYPE_COPY     : return "COPY";
125
        case JOB_TYPE_TEXTURE  : return "TEXTURE";
117 126
        }
118 127

  
119 128
      return null;
......
217 226

  
218 227
    if( jn==null )
219 228
      {
220
      Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null);
229
      Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null,null,0,0);
221 230
      JobNode node = new JobNode(job);
222 231
      mJobs.add(node);
223 232
      return node;
......
231 240
        }
232 241
      else
233 242
        {
234
        Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null);
243
        Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null,null,0,0);
235 244
        JobNode node = new JobNode(job);
236 245
        node.mPrevJobs.add(jn);
237 246
        jn.mNextJobs.add(node);
......
243 252

  
244 253
///////////////////////////////////////////////////////////////////////////////////////////////////
245 254

  
246
  static JobNode merge(MeshBase target)
255
  static JobNode matrix(MeshBase target, MatrixEffect effect, int andAssoc, int ecuAssoc)
256
    {
257
    JobNode jn = target.mJobNode[0];
258
    Job job = new Job(JOB_TYPE_MATRIX,target,null,null,effect,null,andAssoc,ecuAssoc);
259
    JobNode node = new JobNode(job);
260
    node.mPrevJobs.add(jn);
261
    jn.mNextJobs.add(node);
262
    mJobs.add(node);
263
    return node;
264
    }
265

  
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

  
268
  static JobNode mergeTex(MeshBase target)
269
    {
270
    JobNode jn = target.mJobNode[0];
271
    Job job = new Job(JOB_TYPE_MERGE_TEX,target,null,null,null,null,0,0);
272
    JobNode node = new JobNode(job);
273
    node.mPrevJobs.add(jn);
274
    jn.mNextJobs.add(node);
275
    mJobs.add(node);
276
    return node;
277
    }
278

  
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

  
281
  static JobNode mergeEff(MeshBase target)
247 282
    {
248 283
    JobNode jn = target.mJobNode[0];
249
    Job job = new Job(JOB_TYPE_MERGE,target,null,null,null);
284
    Job job = new Job(JOB_TYPE_MERGE_EFF,target,null,null,null,null,0,0);
250 285
    JobNode node = new JobNode(job);
251 286
    node.mPrevJobs.add(jn);
252 287
    jn.mNextJobs.add(node);
......
260 295
    {
261 296
    JobNode jn;
262 297

  
263
    Job job = new Job(JOB_TYPE_JOIN,target,meshes,null,null);
298
    Job job = new Job(JOB_TYPE_JOIN,target,meshes,null,null,null,0,0);
264 299
    JobNode node = new JobNode(job);
265 300

  
266 301
    for (MeshBase mesh : meshes)
......
285 320
    JobNode jn = mesh.mJobNode[0];
286 321
    MeshBase[] meshes = new MeshBase[1];
287 322
    meshes[0] = mesh;
288
    Job job = new Job(JOB_TYPE_COPY,target,meshes,null,null);
323
    Job job = new Job(JOB_TYPE_COPY,target,meshes,null,null,null,0,0);
289 324
    JobNode node = new JobNode(job);
290 325
    node.mPrevJobs.add(jn);
291 326
    jn.mNextJobs.add(node);
......
298 333
  static JobNode textureMap(MeshBase target, Static4D[] maps)
299 334
    {
300 335
    JobNode jn = target.mJobNode[0];
301
    Job job = new Job(JOB_TYPE_TEXTURE,target,null,null,maps);
336
    Job job = new Job(JOB_TYPE_TEXTURE,target,null,null,null,maps,0,0);
302 337
    JobNode node = new JobNode(job);
303 338
    node.mPrevJobs.add(jn);
304 339
    jn.mNextJobs.add(node);
src/main/java/org/distorted/library/mesh/MeshBase.java
20 20
package org.distorted.library.mesh;
21 21

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

  
26
import org.distorted.library.effect.MatrixEffect;
25 27
import org.distorted.library.effect.VertexEffect;
26 28
import org.distorted.library.effectqueue.EffectQueue;
27 29
import org.distorted.library.main.InternalBuffer;
......
42 44
 */
43 45
public abstract class MeshBase
44 46
   {
45
   private static final int MAX_COMPONENTS= 100;
47
   private static final int MAX_EFFECT_COMPONENTS= 100;
46 48
   private static final int DEFAULT_ASSOCIATION = 0xffffffff;
47 49

  
48 50
   // sizes of attributes of an individual vertex.
......
88 90
   private static int[] mEquAssociationH = new int[EffectQueue.MAIN_VARIANTS];
89 91
   private static int[] mAndAssociationH = new int[EffectQueue.MAIN_VARIANTS];
90 92

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

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

  
......
115 117
       }
116 118
     }
117 119

  
118
   private ArrayList<Component> mComponent;
120
   private ArrayList<TexComponent> mTexComponent;
121
   private ArrayList<Integer> mEffComponent;
119 122

  
120 123
///////////////////////////////////////////////////////////////////////////////////////////////////
121 124

  
122 125
   MeshBase()
123 126
     {
124
     mShowNormals= false;
125
     mInflate    = 0.0f;
126
     mComponent  = new ArrayList<>();
127
     mEquAssociation= new int[MAX_COMPONENTS];
128
     mAndAssociation= new int[MAX_COMPONENTS];
127
     mShowNormals  = false;
128
     mInflate      = 0.0f;
129
     mTexComponent = new ArrayList<>();
130
     mEffComponent = new ArrayList<>();
131

  
132
     mEquAssociation= new int[MAX_EFFECT_COMPONENTS];
133
     mAndAssociation= new int[MAX_EFFECT_COMPONENTS];
129 134

  
130 135
     mJobNode = new DeferredJobs.JobNode[1];
131 136

  
132
     for(int i=0; i<MAX_COMPONENTS; i++)
137
     for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
133 138
       {
134 139
       mAndAssociation[i] = DEFAULT_ASSOCIATION;
135 140
       mEquAssociation[i] = i;
......
149 154
     mInflate    = original.mInflate;
150 155
     mNumVertices= original.mNumVertices;
151 156

  
152
     mAndAssociation= new int[MAX_COMPONENTS];
153
     System.arraycopy(original.mAndAssociation, 0, mAndAssociation, 0, MAX_COMPONENTS);
154
     mEquAssociation= new int[MAX_COMPONENTS];
155
     System.arraycopy(original.mEquAssociation, 0, mEquAssociation, 0, MAX_COMPONENTS);
157
     mAndAssociation= new int[MAX_EFFECT_COMPONENTS];
158
     System.arraycopy(original.mAndAssociation, 0, mAndAssociation, 0, MAX_EFFECT_COMPONENTS);
159
     mEquAssociation= new int[MAX_EFFECT_COMPONENTS];
160
     System.arraycopy(original.mEquAssociation, 0, mEquAssociation, 0, MAX_EFFECT_COMPONENTS);
156 161

  
157 162
     if( deep )
158 163
       {
......
188 193

  
189 194
   private void shallowCopy(MeshBase original)
190 195
     {
191
     int size = original.mComponent.size();
192
     mComponent = new ArrayList<>();
196
     int texComSize = original.mTexComponent.size();
197
     mTexComponent = new ArrayList<>();
193 198

  
194
     for(int i=0; i<size; i++)
199
     for(int i=0; i<texComSize; i++)
195 200
       {
196
       Component comp = new Component(original.mComponent.get(i));
197
       mComponent.add(comp);
201
       TexComponent comp = new TexComponent(original.mTexComponent.get(i));
202
       mTexComponent.add(comp);
198 203
       }
199 204

  
205
     mEffComponent = new ArrayList<>();
206
     mEffComponent.addAll(original.mEffComponent);
207

  
200 208
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
201 209
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
202 210
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
......
205 213

  
206 214
///////////////////////////////////////////////////////////////////////////////////////////////////
207 215

  
208
   void merge()
216
   void mergeTexComponentsNow()
209 217
     {
210
     int num = mComponent.size();
218
     int num = mTexComponent.size();
211 219

  
212 220
     if( num>1 )
213 221
       {
214
       mComponent.clear();
215
       mComponent.add(new Component(mNumVertices-1));
222
       mTexComponent.clear();
223
       mTexComponent.add(new TexComponent(mNumVertices-1));
224

  
225
       mVBO2.invalidate();
226
       }
227
     }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
   void mergeEffComponentsNow()
232
     {
233
     int num = mEffComponent.size();
234

  
235
     if( num>1 )
236
       {
237
       mEffComponent.clear();
238
       mEffComponent.add(mNumVertices-1);
216 239

  
217 240
       for(int index=0; index<mNumVertices; index++)
218 241
         {
......
225 248

  
226 249
///////////////////////////////////////////////////////////////////////////////////////////////////
227 250

  
228
   int numComponents()
251
   void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
252
     {
253
     float[] matrix   = new float[16];
254
     float[] uniforms = new float[7];
255
     int start, end=-1, numComp = mEffComponent.size();
256

  
257
     Matrix.setIdentityM(matrix,0);
258
     effect.compute(uniforms,0,0,0);
259
     effect.apply(matrix, uniforms, 0);
260

  
261
     for(int i=0; i<numComp; i++)
262
       {
263
       start = end;
264
       end   = mEffComponent.get(i);
265

  
266
       if( (andAssoc & mAndAssociation[i]) != 0 || (equAssoc == mEquAssociation[i]) )
267
         {
268
         applyMatrixToComponent(matrix,start+1,end+1);
269
         }
270
       }
271

  
272
     mVBO1.invalidate();
273
     }
274

  
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

  
277
   private void applyMatrixToComponent(float[] matrix, int start, int end)
278
     {
279
     float x,y,z;
280

  
281
     for(int index=start; index<end*VERT1_ATTRIBS; index+=VERT1_ATTRIBS )
282
       {
283
       x = mVertAttribs1[index+POS_ATTRIB  ];
284
       y = mVertAttribs1[index+POS_ATTRIB+1];
285
       z = mVertAttribs1[index+POS_ATTRIB+2];
286

  
287
       mVertAttribs1[index+POS_ATTRIB  ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z + matrix[12];
288
       mVertAttribs1[index+POS_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z + matrix[13];
289
       mVertAttribs1[index+POS_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z + matrix[14];
290

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

  
295
       mVertAttribs1[index+NOR_ATTRIB  ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z;
296
       mVertAttribs1[index+NOR_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z;
297
       mVertAttribs1[index+NOR_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z;
298

  
299
       x = mVertAttribs1[index+INF_ATTRIB  ];
300
       y = mVertAttribs1[index+INF_ATTRIB+1];
301
       z = mVertAttribs1[index+INF_ATTRIB+2];
302

  
303
       mVertAttribs1[index+INF_ATTRIB  ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z;
304
       mVertAttribs1[index+INF_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z;
305
       mVertAttribs1[index+INF_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z;
306
       }
307
     }
308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

  
311
   int numTexComponents()
312
     {
313
     return mTexComponent.size();
314
     }
315

  
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

  
318
   int numEffComponents()
229 319
     {
230
     return mComponent.size();
320
     return mEffComponent.size();
231 321
     }
232 322

  
233 323
///////////////////////////////////////////////////////////////////////////////////////////////////
......
239 329
     mVertAttribs1= vert1Attribs;
240 330
     mVertAttribs2= vert2Attribs;
241 331

  
242
     mComponent.add(new Component(mNumVertices-1));
332
     mTexComponent.add(new TexComponent(mNumVertices-1));
333
     mEffComponent.add(mNumVertices-1);
243 334

  
244 335
     mVBO1.invalidate();
245 336
     mVBO2.invalidate();
......
250 341
   void joinAttribs(MeshBase[] meshes)
251 342
     {
252 343
     MeshBase mesh;
253
     Component comp;
344
     TexComponent comp;
254 345
     int numMeshes = meshes.length;
255
     int origVertices = mNumVertices;
256
     int origComponents=0,numComponents,numVertices;
346
     int numVertices,origVertices = mNumVertices;
347
     int origTexComponents=0,numTexComponents;
348
     int origEffComponents=0,numEffComponents;
257 349

  
258 350
     if( origVertices>0 )
259 351
       {
260
       origComponents = mComponent.size();
352
       origTexComponents = mTexComponent.size();
261 353
       mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
262
       mComponent.get(origComponents-1).mEndIndex = mNumVertices-1;
354
       mTexComponent.get(origTexComponents-1).mEndIndex = mNumVertices-1;
355
       origEffComponents = mEffComponent.size();
356
       mEffComponent.set(origEffComponents-1,mNumVertices-1);
263 357
       }
264 358

  
265 359
     for(int i=0; i<numMeshes; i++)
266 360
       {
267 361
       mesh = meshes[i];
268
       numComponents = mesh.mComponent.size();
362
       numTexComponents = mesh.mTexComponent.size();
363
       numEffComponents = mesh.mEffComponent.size();
269 364
       numVertices = mesh.mNumVertices;
270 365

  
271 366
       int extraVerticesBefore = mNumVertices==0 ? 0:1;
272 367
       int extraVerticesAfter  = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1);
273 368

  
274
       for(int j=0; j<numComponents; j++)
369
       for(int j=0; j<numTexComponents; j++)
275 370
         {
276
         comp = new Component(mesh.mComponent.get(j));
371
         comp = new TexComponent(mesh.mTexComponent.get(j));
277 372
         comp.mEndIndex += (extraVerticesBefore+mNumVertices+extraVerticesAfter);
278
         mComponent.add(comp);
373
         mTexComponent.add(comp);
374
         }
279 375

  
280
         if( origComponents<MAX_COMPONENTS )
376
       for(int j=0; j<numEffComponents; j++)
377
         {
378
         int index = mesh.mEffComponent.get(j);
379
         index += (extraVerticesBefore+mNumVertices+extraVerticesAfter);
380
         mEffComponent.add(index);
381

  
382
         if( origEffComponents<MAX_EFFECT_COMPONENTS )
281 383
           {
282
           mAndAssociation[origComponents] = mesh.mAndAssociation[j];
283
           mEquAssociation[origComponents] = mesh.mEquAssociation[j];
284
           origComponents++;
384
           mAndAssociation[origEffComponents] = mesh.mAndAssociation[j];
385
           mEquAssociation[origEffComponents] = mesh.mEquAssociation[j];
386
           origEffComponents++;
285 387
           }
286 388
         }
287 389

  
......
294 396

  
295 397
     if( origVertices>0 )
296 398
       {
297
       System.arraycopy(mVertAttribs1,                              0, newAttribs1,                         0, VERT1_ATTRIBS*numVertices);
298
       System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS    );
299
       System.arraycopy(mVertAttribs2,                              0, newAttribs2,                         0, VERT2_ATTRIBS*numVertices);
300
       System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS    );
399
       System.arraycopy(mVertAttribs1,                              0, newAttribs1,                          0, VERT1_ATTRIBS*numVertices);
400
       System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS            );
401
       System.arraycopy(mVertAttribs2,                              0, newAttribs2,                          0, VERT2_ATTRIBS*numVertices);
402
       System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS            );
301 403
       origVertices++;
302 404

  
303 405
       if( numVertices%2==1 )
......
315 417

  
316 418
       if( origVertices>0 )
317 419
         {
318
         System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS    );
319
         System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS    );
420
         System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
421
         System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
320 422
         origVertices++;
321 423
         }
322 424
       System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
......
343 445
       android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
344 446
       }
345 447

  
346
     int endIndex, index=0, numComp = mComponent.size();
448
     int endIndex, index=0, numEffComp = mEffComponent.size();
347 449

  
348
     for(int component=0; component<numComp; component++)
450
     for(int component=0; component<numEffComp; component++)
349 451
       {
350
       endIndex = mComponent.get(component).mEndIndex;
452
       endIndex = mEffComponent.get(component);
351 453

  
352 454
       for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component;
353 455
       }
......
382 484

  
383 485
   void textureMap(Static4D[] maps)
384 486
     {
385
     int num_comp = mComponent.size();
487
     int num_comp = mTexComponent.size();
386 488
     int num_maps = maps.length;
387 489
     int min = Math.min(num_comp, num_maps);
388 490
     int vertex = 0;
389 491
     Static4D newMap, oldMap;
390
     Component comp;
492
     TexComponent comp;
391 493
     float newW, newH, ratW, ratH, movX, movY;
392 494

  
393 495
     for(int i=0; i<min; i++)
394 496
       {
395 497
       newMap = maps[i];
396
       comp = mComponent.get(i);
498
       comp = mTexComponent.get(i);
397 499

  
398 500
       if( newMap!=null )
399 501
         {
......
425 527

  
426 528
///////////////////////////////////////////////////////////////////////////////////////////////////
427 529

  
428
   public static int getMaxComponents()
530
   public static int getMaxEffComponents()
429 531
     {
430
     return MAX_COMPONENTS;
532
     return MAX_EFFECT_COMPONENTS;
431 533
     }
432 534

  
433 535
///////////////////////////////////////////////////////////////////////////////////////////////////
......
543 645
 */
544 646
   public void send(int variant)
545 647
     {
546
     GLES30.glUniform1iv( mEquAssociationH[variant], MAX_COMPONENTS, mEquAssociation, 0);
547
     GLES30.glUniform1iv( mAndAssociationH[variant], MAX_COMPONENTS, mAndAssociation, 0);
648
     GLES30.glUniform1iv( mEquAssociationH[variant], MAX_EFFECT_COMPONENTS, mEquAssociation, 0);
649
     GLES30.glUniform1iv( mAndAssociationH[variant], MAX_EFFECT_COMPONENTS, mAndAssociation, 0);
548 650
     }
549 651

  
550 652
///////////////////////////////////////////////////////////////////////////////////////////////////
......
638 740

  
639 741
///////////////////////////////////////////////////////////////////////////////////////////////////
640 742
/**
641
 * Merge all components of this Mesh into a single one.
743
 * Merge all texture components of this Mesh into a single one.
642 744
 */
643
   public void mergeComponents()
745
   public void mergeTexComponents()
644 746
     {
645 747
     if( mJobNode[0]==null )
646 748
       {
647
       merge();
749
       mergeTexComponentsNow();
648 750
       }
649 751
     else
650 752
       {
651
       mJobNode[0] = DeferredJobs.merge(this);
753
       mJobNode[0] = DeferredJobs.mergeTex(this);
754
       }
755
     }
756

  
757
///////////////////////////////////////////////////////////////////////////////////////////////////
758
/**
759
 * Merge all effect components of this Mesh into a single one.
760
 */
761
   public void mergeEffComponents()
762
     {
763
     if( mJobNode[0]==null )
764
       {
765
       mergeEffComponentsNow();
766
       }
767
     else
768
       {
769
       mJobNode[0] = DeferredJobs.mergeEff(this);
652 770
       }
653 771
     }
654 772

  
......
666 784
     mTFO.markForDeletion();
667 785
     }
668 786

  
787
///////////////////////////////////////////////////////////////////////////////////////////////////
788
/**
789
 * Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
790
 * <p>
791
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effect
792
 * contains any Dynamics, they will be evaluated at 0.
793
 *
794
 * @param effect List of Matrix Effects to apply to the Mesh.
795
 * @param andAssoc 'Logical AND' association which defines which components will be affected.
796
 * @param equAssoc 'equality' association which defines which components will be affected.
797
 */
798
   public void apply(MatrixEffect effect, int andAssoc, int equAssoc)
799
     {
800
     if( mJobNode[0]==null )
801
       {
802
       applyMatrix(effect,andAssoc,equAssoc);
803
       }
804
     else
805
       {
806
       mJobNode[0] = DeferredJobs.matrix(this,effect,andAssoc,equAssoc);
807
       }
808
     }
809

  
669 810
///////////////////////////////////////////////////////////////////////////////////////////////////
670 811
/**
671 812
 * Apply a Vertex Effect to the vertex mesh.
......
725 866
 */
726 867
   public Static4D getTextureMap(int component)
727 868
     {
728
     return (component>=0 && component<mComponent.size()) ? mComponent.get(component).mTextureMap : null;
869
     return (component>=0 && component<mTexComponent.size()) ? mTexComponent.get(component).mTextureMap : null;
729 870
     }
730 871

  
731 872
///////////////////////////////////////////////////////////////////////////////////////////////////
......
745 886
 */
746 887
  public void setEffectAssociation(int component, int andAssociation, int equAssociation)
747 888
    {
748
    if( component>=0 && component<MAX_COMPONENTS )
889
    if( component>=0 && component<MAX_EFFECT_COMPONENTS )
749 890
      {
750 891
      mAndAssociation[component] = andAssociation;
751 892
      mEquAssociation[component] = equAssociation;
src/main/java/org/distorted/library/mesh/MeshJoined.java
22 22
///////////////////////////////////////////////////////////////////////////////////////////////////
23 23

  
24 24
public class MeshJoined extends MeshBase
25
  {
25
{
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
28 28
 * Join a list of (probably already changed by Vertex Effects) Meshes into one.
......
56 56
   {
57 57
   return new MeshJoined(this,deep);
58 58
   }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
/**
62
 * Return how many basic Meshes is this Mesh joined from.
63
 */
64
  public int getNumComponents()
65
     {
66
     return numComponents();
67
     }
68
  }
59
}

Also available in: Unified diff