Project

General

Profile

« Previous | Next » 

Revision e7f85322

Added by Leszek Koltunski over 4 years ago

Progress with of Pyraminx.
Bugfix for joining a single Mesh!

View differences:

src/main/java/org/distorted/library/mesh/MeshBase.java
186 186
     {
187 187
     MeshBase mesh;
188 188
     Component comp;
189
     int com, num, len = meshes.length;
189
     int numComponents, numVertices, numMeshes = meshes.length;
190 190
     int origVertices = mNumVertices;
191 191

  
192 192
     // compute new numVertices; take care of Components
193 193

  
194 194
     if( origVertices>0 )
195 195
       {
196
       com = mComponent.size();
196
       numComponents = mComponent.size();
197 197
       mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
198
       mComponent.get(com-1).mEndIndex = mNumVertices;
198
       mComponent.get(numComponents-1).mEndIndex = mNumVertices;
199 199
       }
200 200

  
201
     for(int i=0; i<len; i++)
201
     for(int i=0; i<numMeshes; i++)
202 202
       {
203 203
       mesh = meshes[i];
204
       com = mesh.mComponent.size();
204
       numComponents = mesh.mComponent.size();
205 205

  
206
       for(int j=0; j<com; j++)
206
       for(int j=0; j<numComponents; j++)
207 207
         {
208 208
         comp = new Component(mesh.mComponent.get(j));
209 209
         comp.mEndIndex += mNumVertices;
210 210
         mComponent.add(comp);
211 211
         }
212 212

  
213
       num = mesh.mNumVertices;
213
       numVertices = mesh.mNumVertices;
214 214

  
215
       if( mNumVertices==0 ) mNumVertices += (num%2==1 ? num+2 : num+1);
216
       else if( i==len-1 )   mNumVertices += (num+1);
217
       else                  mNumVertices += (num%2==1 ? num+3 : num+2);
215
       if( mNumVertices==0 )
216
         {
217
         if( numMeshes>1 )
218
            mNumVertices += (numVertices%2==1 ? numVertices+2 : numVertices+1);
219
         else
220
            mNumVertices +=  numVertices;
221
         }
222
       else if( i==numMeshes-1 ) mNumVertices += (numVertices+1);
223
       else                      mNumVertices += (numVertices%2==1 ? numVertices+3 : numVertices+2);
218 224
       }
219 225

  
220 226
     // allocate new attrib array
221 227
     float[] newAttribs = new float[VERT_ATTRIBS*mNumVertices];
222
     num = origVertices;
228
     numVertices = origVertices;
223 229

  
224 230
     if( origVertices>0 )
225 231
       {
226
       System.arraycopy(mVertAttribs,                             0, newAttribs,                         0, VERT_ATTRIBS*num);
232
       System.arraycopy(mVertAttribs,                             0, newAttribs,                         0, VERT_ATTRIBS*numVertices);
227 233
       System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS    );
228 234
       origVertices++;
229 235

  
230
       if( num%2==1 )
236
       if( numVertices%2==1 )
231 237
         {
232 238
         System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
233 239
         origVertices++;
234 240
         }
235 241
       }
236 242

  
237
     for(int i=0; i<len; i++)
243
     for(int i=0; i<numMeshes; i++)
238 244
       {
239 245
       mesh = meshes[i];
240
       num = mesh.mNumVertices;
246
       numVertices = mesh.mNumVertices;
241 247

  
242 248
       if( origVertices>0 )
243 249
         {
244 250
         System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS    );
245 251
         origVertices++;
246 252
         }
247
       System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS*num);
248
       origVertices+=num;
253
       System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS*numVertices);
254
       origVertices+=numVertices;
249 255

  
250
       if( i<len-1 )
256
       if( i<numMeshes-1 )
251 257
         {
252
         System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(num-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
258
         System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(numVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
253 259
         origVertices++;
254 260

  
255
         if( num%2==1 )
261
         if( numVertices%2==1 )
256 262
           {
257
           System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(num-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
263
           System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(numVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
258 264
           origVertices++;
259 265
           }
260 266
         }

Also available in: Unified diff