Project

General

Profile

« Previous | Next » 

Revision be56193c

Added by Leszek Koltunski about 3 years ago

Move all the special cubit-creating code out of FactoryCubit and to the Object classes, and thus hopefully finish implementing the new cubit creating engine.

View differences:

src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
26 26
import org.distorted.helpers.FactoryCubit;
27 27
import org.distorted.helpers.FactorySticker;
28 28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.effect.VertexEffect;
30
import org.distorted.library.effect.VertexEffectMove;
31
import org.distorted.library.effect.VertexEffectRotate;
32
import org.distorted.library.effect.VertexEffectScale;
29 33
import org.distorted.library.main.DistortedEffects;
30 34
import org.distorted.library.main.DistortedTexture;
31 35
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshJoined;
37
import org.distorted.library.mesh.MeshPolygon;
32 38
import org.distorted.library.mesh.MeshSquare;
39
import org.distorted.library.type.Static1D;
33 40
import org.distorted.library.type.Static3D;
34 41
import org.distorted.library.type.Static4D;
35 42

  
......
183 190
    return ( cubit>=0 && cubit< indices.length ) ? indices[cubit] : 0;
184 191
    }
185 192

  
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

  
195
  private float[] createVertices(int A, int B)
196
    {
197
    float E = 0.5f / Math.max(A,B);
198
    return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E };
199
    }
200

  
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

  
203
  private MeshBase createCuboid(int[] dimensions)
204
    {
205
    FactoryCubit factory = FactoryCubit.getInstance();
206

  
207
    int X = dimensions[0];
208
    int Y = dimensions[1];
209
    int Z = dimensions[2];
210

  
211
    float[] verticesXY = createVertices(X,Y);
212
    float[] verticesXZ = createVertices(X,Z);
213
    float[] verticesYZ = createVertices(Z,Y);
214

  
215
    float defHeight = 0.048f;
216

  
217
    float[] bandsX = factory.computeBands( defHeight/X,65,0.25f,0.5f,5);
218
    float[] bandsY = factory.computeBands( defHeight/Y,65,0.25f,0.5f,5);
219
    float[] bandsZ = factory.computeBands( defHeight/Z,65,0.25f,0.5f,5);
220

  
221
    MeshBase[] meshes = new MeshPolygon[6];
222

  
223
    meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2);
224
    meshes[0].setEffectAssociation(0,1,0);
225
    meshes[1] = meshes[0].copy(true);
226
    meshes[1].setEffectAssociation(0,2,0);
227
    meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2);
228
    meshes[2].setEffectAssociation(0,4,0);
229
    meshes[3] = meshes[2].copy(true);
230
    meshes[3].setEffectAssociation(0,8,0);
231
    meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2);
232
    meshes[4].setEffectAssociation(0,16,0);
233
    meshes[5] = meshes[4].copy(true);
234
    meshes[5].setEffectAssociation(0,32,0);
235

  
236
    return new MeshJoined(meshes);
237
    }
238

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

  
241
  private VertexEffect[] createCuboidEffects(int[] dimensions)
242
    {
243
    float X = dimensions[0];
244
    float Y = dimensions[1];
245
    float Z = dimensions[2];
246

  
247
    float MAX_XY = Math.max(X,Y);
248
    float MAX_XZ = Math.max(X,Z);
249
    float MAX_YZ = Math.max(Z,Y);
250

  
251
    Static1D angle = new Static1D(90);
252
    Static3D move  = new Static3D( 0.0f, 0.0f, 0.5f);
253
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
254
    Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f);
255
    Static3D center= new Static3D( 0.0f, 0.0f, 0.0f);
256

  
257
    Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z);
258
    Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z);
259
    Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ);
260
    Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ);
261
    Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ);
262
    Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ);
263

  
264
    VertexEffect[] effect = new VertexEffect[9];
265

  
266
    effect[0] = new VertexEffectMove(move);
267
    effect[1] = new VertexEffectRotate(angle, axisX, center);
268
    effect[2] = new VertexEffectRotate(angle, axisY, center);
269
    effect[3] = new VertexEffectScale(scale3);
270
    effect[4] = new VertexEffectScale(scale4);
271
    effect[5] = new VertexEffectScale(scale5);
272
    effect[6] = new VertexEffectScale(scale6);
273
    effect[7] = new VertexEffectScale(scale7);
274
    effect[8] = new VertexEffectScale(scale8);
275

  
276
    effect[1].setMeshAssociation(12,-1);  // meshes 2,3
277
    effect[2].setMeshAssociation( 3,-1);  // meshes 0,1
278
    effect[3].setMeshAssociation(16,-1);  // mesh 4
279
    effect[4].setMeshAssociation(32,-1);  // mesh 5
280
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
281
    effect[6].setMeshAssociation( 4,-1);  // mesh 2
282
    effect[7].setMeshAssociation( 1,-1);  // mesh 0
283
    effect[8].setMeshAssociation( 2,-1);  // mesh 1
284

  
285
    return effect;
286
    }
287

  
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

  
290
  private MeshBase createCuboidMesh(int[] dimensions)
291
    {
292
    MeshBase mesh = createCuboid(dimensions);
293
    VertexEffect[] effects = createCuboidEffects(dimensions);
294
    for( VertexEffect effect : effects ) mesh.apply(effect);
295

  
296
    int X = dimensions[0];
297
    int Y = dimensions[1];
298
    int Z = dimensions[2];
299

  
300
    float strength = 0.04f;
301
    float radius   = 0.15f;
302

  
303
    Static3D[] vertices = new Static3D[1];
304
    Static3D center;
305
    FactoryCubit factory = FactoryCubit.getInstance();
306

  
307
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,+0.5f*Z);
308
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
309
    factory.roundCorners(mesh, center, vertices, strength, radius);
310

  
311
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,-0.5f*Z);
312
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
313
    factory.roundCorners(mesh, center, vertices, strength, radius);
314

  
315
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,+0.5f*Z);
316
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
317
    factory.roundCorners(mesh, center, vertices, strength, radius);
318

  
319
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,-0.5f*Z);
320
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
321
    factory.roundCorners(mesh, center, vertices, strength, radius);
322

  
323
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,+0.5f*Z);
324
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
325
    factory.roundCorners(mesh, center, vertices, strength, radius);
326

  
327
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,-0.5f*Z);
328
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
329
    factory.roundCorners(mesh, center, vertices, strength, radius);
330

  
331
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,+0.5f*Z);
332
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
333
    factory.roundCorners(mesh, center, vertices, strength, radius);
334

  
335
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,-0.5f*Z);
336
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
337
    factory.roundCorners(mesh, center, vertices, strength, radius);
338

  
339
    mesh.mergeEffComponents();
340

  
341
    return mesh;
342
    }
343

  
186 344
///////////////////////////////////////////////////////////////////////////////////////////////////
187 345

  
188 346
  MeshBase createCubitMesh(int cubit, int numLayers)
......
194 352

  
195 353
      for(int i=0; i<LEN; i++)
196 354
        {
197
        mMeshes[i] = FactoryCubit.getInstance().createCuboidMesh(mDimensions[i]);
355
        mMeshes[i] = createCuboidMesh(mDimensions[i]);
198 356
        }
199 357
      }
200 358

  

Also available in: Unified diff