Project

General

Profile

« Previous | Next » 

Revision f2b21ce0

Added by Leszek Koltunski 7 months ago

move the 'VariantFaceIsOuter' info into the ObjectShape class.

View differences:

src/main/java/org/distorted/objectlib/bandaged/FactoryBandaged.java
983 983

  
984 984
    FactoryCubit factory = FactoryCubit.getInstance();
985 985
    factory.clear();
986
    factory.createNewFaceTransform(shape,null);
986
    factory.createNewFaceTransform(shape);
987 987
    return factory.createRoundedSolid(shape,face,effects,numFaces);
988 988
    }
989 989
  }
src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java
1322 1322

  
1323 1323
///////////////////////////////////////////////////////////////////////////////////////////////////
1324 1324

  
1325
  public void createNewFaceTransform(final ObjectShape shape, int[] outer)
1325
  public void createNewFaceTransform(final ObjectShape shape)
1326 1326
    {
1327 1327
    float[][] vertices = shape.getVertices();
1328 1328
    int[][] indices = shape.getVertIndices();
......
1343 1343
    for (int face=0; face<numFaces; face++)
1344 1344
      {
1345 1345
      boolean collapsed = false;
1346
      boolean isOuter = (outer!=null && outer[face]>0);
1346
      boolean isOuter = shape.faceIsOuter(face)>0;
1347 1347
      FaceTransform newT;
1348 1348

  
1349 1349
      if( !isMultigon )
src/main/java/org/distorted/objectlib/helpers/FactoryCutSolid.java
9 9

  
10 10
package org.distorted.objectlib.helpers;
11 11

  
12
///////////////////////////////////////////////////////////////////////////////////////////////////
13

  
12
import org.distorted.library.type.Static3D;
14 13
import org.distorted.library.type.Static4D;
14
import org.distorted.objectlib.main.TwistyObjectControllable;
15

  
16
///////////////////////////////////////////////////////////////////////////////////////////////////
15 17

  
16 18
public class FactoryCutSolid
17 19
  {
20
  private static final float MAX_ERROR_DIST = 0.0001f;
21

  
18 22
  public static class CutSolidInfo
19 23
    {
20 24
    private final int[][] mVariantQuatMap;
......
24 28
    public int[][] getVariantQuatMap() { return mVariantQuatMap; }
25 29
    };
26 30

  
27
  private float[][] mPotentialVertices;
28
  private boolean[][] mFaceIsOutside;
29

  
30 31
///////////////////////////////////////////////////////////////////////////////////////////////////
31 32

  
32
  private static int getRotatingQuat(ObjectShape s1, ObjectShape s2, Static4D[] quats, float[] center)
33
  private static int getRotatingQuat(ObjectShape s1, ObjectShape s2, Static4D[] quats)
33 34
    {
34 35
    return -1;
35 36
    }
36 37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
// Return true iff 'vertex' lies on the external face
40

  
41
  private static boolean vertexOnPlane(float[] vertex, Static3D faceAxis, float dist)
42
    {
43
    float fx = faceAxis.get0();
44
    float fy = faceAxis.get0();
45
    float fz = faceAxis.get0();
46

  
47
    float d = vertex[0]*fx + vertex[1]*fy + vertex[2]*fz - dist;
48
    return (d>=-MAX_ERROR_DIST && d<=MAX_ERROR_DIST);
49
    }
50

  
37 51
///////////////////////////////////////////////////////////////////////////////////////////////////
38 52

  
39
  public static CutSolidInfo computeInfo(float[][] pos, float[][] cutPlanes, Static4D[] quats, float[] center)
53
  private static int[][] computeFaceMap(ObjectShape[] shapes, Static3D[] faceAxis, float[] dist3D)
40 54
    {
55
   //  mCubitFaceToPuzzleFaceMap= ObjectShape.computePuzzleFaceMap(mShapes,mCubitPos, mCubitOrigQuat, mCubitGhostQuat, this);
56

  
57
    int numShapes = shapes.length;
58
    int[][] map = new int[numShapes][];
59

  
60
    for(int s=0; s<numShapes; s++)
61
      {
62

  
63
      }
64

  
65
    return map;
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  public static CutSolidInfo computeInfo(TwistyObjectControllable object, float[][] cutPlanes)
71
    {
72
    float[][] pos = object.getCubitPositions();
73
    Static3D[] faceAxis = object.getFaceAxis();
74
    float[] dist = object.getDist3D();
41 75
    int numCubits = pos.length;
42 76

  
43 77
    float[][] potentialVertices = FactoryShape.computePotentialVertices(cutPlanes);
......
46 80
    for(int c=0; c<numCubits; c++)
47 81
      shapes[c] = FactoryShape.createShape(cutPlanes,potentialVertices,pos[c],pos[c]);
48 82

  
49
    int[][] map = new int[numCubits][];
50
    for(int c=0; c<numCubits; c++) map[c] = new int[] {-1,0};
83
    int[][] cubitFaceToPuzzleFaceMap = computeFaceMap(shapes,faceAxis,dist);
84
    Static4D[] quats = object.getQuats();
85

  
86
    int[][] map = new int[numCubits][2];
87
    for(int c=0; c<numCubits; c++) map[c][0] = -1;
51 88

  
52 89
    int variant = 0;
53 90
    for(int c=0; c<numCubits; c++)
......
59 96
        for(int d=c+1; d<numCubits; d++)
60 97
          {
61 98
          ObjectShape shape2 = shapes[d];
62
          int quat = getRotatingQuat(shape1,shape2,quats,center);
99
          int quat = getRotatingQuat(shape1,shape2,quats);
63 100

  
64 101
          if( quat>=0 )
65 102
            {
......
70 107
        }
71 108

  
72 109
    ObjectShape[] variantShapes = new ObjectShape[variant];
73
    for(int v=0; v<variant; v++)
110
    for(int c=0; c<numCubits; c++)
74 111
      {
75

  
112
      int v = map[c][0];
113
      if( variantShapes[v]==null ) variantShapes[v] = shapes[c];
76 114
      }
77 115

  
78

  
79
    return new CutSolidInfo(shapes,map);
116
    return new CutSolidInfo(variantShapes,map);
80 117
    }
81 118
  }
src/main/java/org/distorted/objectlib/helpers/ObjectShape.java
28 28
  private final int mNumFaces;
29 29
  private final int[][][] mMultigonIndices;
30 30

  
31
  private boolean[] mFaceIsOuter;
32

  
31 33
///////////////////////////////////////////////////////////////////////////////////////////////////
32 34

  
33 35
  public ObjectShape(float[][] vertices, int[][] vertIndices)
......
159 161
    output[2] /= len;
160 162
    }
161 163

  
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

  
166
  public void setFaceOuter(boolean[] outer)
167
    {
168
    mFaceIsOuter = outer;
169
    }
170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
  public int faceIsOuter(int face)
174
    {
175
    return mFaceIsOuter==null ? -1 : (mFaceIsOuter[face] ? 1 : 0);
176
    }
177

  
162 178
///////////////////////////////////////////////////////////////////////////////////////////////////
163 179
// Attention: ATM this can return either (nx,ny,nz) or the negative (-nx,-ny,-nz)
164 180
// (negative if the first three points of the first loop are 'concave' - as for example are the
src/main/java/org/distorted/objectlib/json/JsonReader.java
72 72
  private Static4D[] mCubitQuats;
73 73
  private int mNumCubitVariants;
74 74
  private int[] mCubitVariant;
75
  private int[][] mVariantStickerShape, mVariantFaceIsOuter, mCubitFaceColor;
75
  private int[][] mVariantStickerShape, mCubitFaceColor;
76 76
  private ObjectSticker[] mObjectSticker;
77 77
  private Static3D[] mAxis;
78 78
  private int[][] mBasicAngle;
......
263 263
    {
264 264
    mNumCubitVariants     = object.length();
265 265
    mVariantStickerShape  = new int[mNumCubitVariants][];
266
    mVariantFaceIsOuter   = new int[mNumCubitVariants][];
267 266
    mShapes               = new ObjectShape[mNumCubitVariants];
268 267
    mFaceShapes           = new ObjectFaceShape[mNumCubitVariants];
269 268
    mVertexEffects        = new ObjectVertexEffects[mNumCubitVariants];
270 269
    mNumCubitFaces = -1;
271 270

  
272
    for(int i=0; i<mNumCubitVariants; i++)
271
    for(int v=0; v<mNumCubitVariants; v++)
273 272
      {
274
      JSONObject jsonShape = object.getJSONObject(i);
273
      JSONObject jsonShape = object.getJSONObject(v);
275 274

  
276 275
      /////////////////////////////////////////////////////////////////////////
277 276
      ////// ObjectShape //////////////////////////////////////////////////////
......
279 278
      int numVertices = jsonVertices.length();
280 279
      float[][] verts = new float[numVertices][3];
281 280

  
282
      for(int v=0; v<numVertices; v++)
281
      for(int n=0; n<numVertices; n++)
283 282
        {
284
        JSONObject vert = jsonVertices.getJSONObject(v);
285
        verts[v][0] = (float)vert.getDouble("x");
286
        verts[v][1] = (float)vert.getDouble("y");
287
        verts[v][2] = (float)vert.getDouble("z");
283
        JSONObject vert = jsonVertices.getJSONObject(n);
284
        verts[n][0] = (float)vert.getDouble("x");
285
        verts[n][1] = (float)vert.getDouble("y");
286
        verts[n][2] = (float)vert.getDouble("z");
288 287
        }
289 288

  
290 289
      JSONArray jsonFaces= jsonShape.getJSONArray("faces");
......
305 304
          for(int k=0; k<numV; k++) vertIndices[f][k] = vertices.getInt(k);
306 305
          }
307 306

  
308
        mShapes[i] = new ObjectShape(verts,vertIndices);
307
        mShapes[v] = new ObjectShape(verts,vertIndices);
309 308
        }
310 309
      else
311 310
        {
......
327 326
            }
328 327
          }
329 328

  
330
        mShapes[i] = new ObjectShape(verts,vertIndices);
329
        mShapes[v] = new ObjectShape(verts,vertIndices);
331 330
        }
332 331

  
333 332
      /////////////////////////////////////////////////////////////////////////
334 333
      ////// StickerShape & Outer /////////////////////////////////////////////
335
      mVariantStickerShape[i]= new int[numFaces];
336
      mVariantFaceIsOuter[i] = new int[numFaces];
334
      mVariantStickerShape[v]= new int[numFaces];
335
      boolean[] variantFaceIsOuter = new boolean[numFaces];
337 336
      int[] bandIndices = new int[numFaces];
338 337

  
339 338
      for(int f=0; f<numFaces; f++)
340 339
        {
341 340
        JSONObject jsonFace = jsonFaces.getJSONObject(f);
342
        mVariantStickerShape[i][f]= jsonFace.getInt("sticker");
343
        mVariantFaceIsOuter[i][f] = jsonFace.optInt("isOuter",0);
341
        mVariantStickerShape[v][f]= jsonFace.getInt("sticker");
342
        variantFaceIsOuter[f] = (jsonFace.optInt("isOuter",0)==1);
344 343
        bandIndices[f] = jsonFace.getInt("bandIndex");
345 344
        }
345
      mShapes[v].setFaceOuter(variantFaceIsOuter);
346 346

  
347 347
      /////////////////////////////////////////////////////////////////////////
348 348
      ////// ObjectFaceShape //////////////////////////////////////////////////
......
375 375
        convexity[2] = (float)jsonConvexity.getDouble("z");
376 376
        }
377 377

  
378
      mFaceShapes[i] = new ObjectFaceShape(bands,bandIndices,convexity);
378
      mFaceShapes[v] = new ObjectFaceShape(bands,bandIndices,convexity);
379 379

  
380 380
      /////////////////////////////////////////////////////////////////////////
381 381
      ////// ObjectVertexEffects //////////////////////////////////////////////
......
415 415
          use[j] = jsonEffect.getBoolean("use");
416 416
          }
417 417

  
418
        mVertexEffects[i] = new ObjectVertexEffects(name,vars,center,region,use);
418
        mVertexEffects[v] = new ObjectVertexEffects(name,vars,center,region,use);
419 419
        }
420 420
      }
421 421
    }
......
1111 1111
  public float[][] returnRotationFactor()              { return mRotationFactor; }
1112 1112
  public int[] getCubitTypes()                         { return mCubitType; }
1113 1113
  public float[][] getCubitOffsets()                   { return mCubitRowOffset; }
1114
  public int[][] getVariantFaceIsOuter()               { return mVariantFaceIsOuter; }
1115 1114
  public int getCubitFaceFace(int cubit, int face)     { return mCubitFaceColor[cubit][face]; }
1116 1115
  public int getNumScrambles()                         { return mNumScrambles; }
1117 1116
  public int getPrice()                                { return mPrice; }
src/main/java/org/distorted/objectlib/json/JsonWriter.java
121 121

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

  
124
  private JSONArray generateFaces(TwistyObject object, ObjectShape shape, int[] bandIndices, int[] faceOuter, int cubit) throws JSONException
124
  private JSONArray generateFaces(TwistyObject object, ObjectShape shape, int[] bandIndices, int cubit) throws JSONException
125 125
    {
126 126
    JSONArray array = new JSONArray();
127 127
    int numFaces = shape.getNumFaces();
......
130 130
    int[][] vertIndices1   = shape.getVertIndices();
131 131
    int[][][] vertIndices2 = shape.getMultigonIndices();
132 132

  
133
    for(int i=0; i<numFaces; i++)
133
    for(int f=0; f<numFaces; f++)
134 134
      {
135 135
      JSONObject face = new JSONObject();
136
      face.put("bandIndex", bandIndices[i]);
136
      face.put("bandIndex", bandIndices[f]);
137 137

  
138
      int stiShape = object.getVariantStickerShape(variant,i);
138
      int stiShape = object.getVariantStickerShape(variant,f);
139 139
      face.put("sticker", stiShape);
140
      face.put("isOuter", faceOuter[i]);
140
      face.put("isOuter", shape.faceIsOuter(f));
141 141

  
142 142
      JSONArray faceArr = new JSONArray();
143 143

  
144 144
      if( !multigon )
145 145
        {
146
        int num = vertIndices1[i].length;
147
        for(int j=0; j<num; j++) faceArr.put(vertIndices1[i][j]);
146
        for( int index : vertIndices1[f] ) faceArr.put(index);
148 147
        }
149 148
      else
150 149
        {
151
        int num = vertIndices2[i].length;
152
        for(int j=0; j<num; j++)
150
        for( int[] component : vertIndices2[f] )
153 151
          {
154 152
          JSONArray compArr = new JSONArray();
155
          int com = vertIndices2[i][j].length;
156
          for(int k=0; k<com; k++) compArr.put(vertIndices2[i][j][k]);
153
          for( int index : component ) compArr.put(index);
157 154
          faceArr.put(compArr);
158 155
          }
159 156
        }
......
264 261
    JSONArray shapes = new JSONArray();
265 262
    int numVariants = object.getNumCubitVariants();
266 263
    float[][] positions = object.getCubitPositions();
267
    int[][] faceOuter   = object.getVariantFaceIsOuter();
268 264
    int numCubits = positions.length;
269 265
    mNumCubitFaces = 0;
270 266

  
......
296 292

  
297 293
      JSONArray verticesArr = generateVertices(vertices);
298 294
      shapeObj.put("vertices", verticesArr);
299
      JSONArray facesArr = generateFaces(object,shape,bandIndices,faceOuter[i],cubit);
295
      JSONArray facesArr = generateFaces(object,shape,bandIndices,cubit);
300 296
      shapeObj.put("faces", facesArr);
301 297
      JSONArray bandsArr = generateBands(bands);
302 298
      shapeObj.put("bands", bandsArr);
src/main/java/org/distorted/objectlib/main/TwistyJson.java
41 41
  @Override public int[][] getMinimalCubiesInRow()                   { return mReader.getMinimalCubiesInRow(); }
42 42
  @Override public int getCubitRotationType(int cubit)               { return mReader.getCubitTypes()[cubit]; }
43 43
  @Override public float[] getCubitRowOffset(int cubit)              { return mReader.getCubitOffsets()[cubit]; }
44
  @Override public int[][] getVariantFaceIsOuter()                   { return mReader.getVariantFaceIsOuter(); }
45 44
  @Override public int[][] getSolvedQuats()                          { return mReader.getSolvedQuats(); }
46 45
  @Override public Static4D[] getQuats()                             { return mReader.getQuats(); }
47 46
  @Override public int getSolvedFunctionIndex()                      { return mReader.getSolvedFunctionIndex(); }
src/main/java/org/distorted/objectlib/main/TwistyObjectWithMesh.java
60 60
  private ObjectShape[] mShapes;
61 61
  private int mNumCubitVariants;
62 62
  private int[][] mCubitFaceToPuzzleFaceMap;
63
  private int[][] mVariantFaceIsOuter;
64 63
  private int mMaxNumLayers;
65 64
  private int mIconMode;
66 65
  private float mRadius;
......
259 258
///////////////////////////////////////////////////////////////////////////////////////////////////
260 259

  
261 260
  public float getPillowCoeff()                { return 1.0f; }
262
  public int[][] getVariantFaceIsOuter()       { return mVariantFaceIsOuter; }
263 261
  public int getMaxNumCubitFaces()             { return 0; }
264 262
  public int[] getNumLayers()                  { return mNumLayers; }
265 263
  public boolean isInIconMode()                { return mIconMode==MODE_ICON; }
......
329 327

  
330 328
  private void createOuterFaces()
331 329
    {
330
    boolean[][] variantFaceIsOuter = new boolean[mNumCubitVariants][];
331

  
332 332
    for(int v=0; v<mNumCubitVariants; v++)
333 333
      {
334 334
      int numFaces = mShapes[v].getNumFaces();
335
      mVariantFaceIsOuter[v] = new int[numFaces];
335
      variantFaceIsOuter[v] = new boolean[numFaces];
336 336
      }
337 337

  
338 338
    for( int cubit=0; cubit<mNumCubits; cubit++)
......
341 341
      int numFaces = mShapes[variant].getNumFaces();
342 342

  
343 343
      for(int face=0; face<numFaces; face++)
344
        if( getPuzzleFace(cubit,face)>=0 ) mVariantFaceIsOuter[variant][face] = 1;
344
        if( getPuzzleFace(cubit,face)>=0 ) variantFaceIsOuter[variant][face] = true;
345 345
      }
346

  
347
    for(int v=0; v<mNumCubitVariants; v++) mShapes[v].setFaceOuter(variantFaceIsOuter[v]);
346 348
    }
347 349

  
348 350
///////////////////////////////////////////////////////////////////////////////////////////////////
......
358 360

  
359 361
      mShapes = new ObjectShape[mNumCubitVariants];
360 362
      for(int v=0; v<mNumCubitVariants; v++) mShapes[v] = getObjectShape(v);
361
      mVariantFaceIsOuter = new int[mNumCubitVariants][];
362 363

  
363 364
      if( !fromJSON )
364 365
        {
365 366
        createGhostQuat();
366 367
        mCubitFaceToPuzzleFaceMap= ObjectShape.computePuzzleFaceMap(mShapes,mCubitPos, mCubitOrigQuat, mCubitGhostQuat, this);
367
        createOuterFaces();
368
        if( mShapes[0].faceIsOuter(0)==-1 ) createOuterFaces(); // -1, i.e. not created yet
368 369
        }
369 370

  
370 371
      if( fromDMESH )
371 372
        {
372
        for(int i=0; i<mNumCubitVariants; i++) factory.createNewFaceTransform(mShapes[i], mVariantFaceIsOuter[i]);
373
        for(int i=0; i<mNumCubitVariants; i++) factory.createNewFaceTransform(mShapes[i]);
373 374
        }
374 375
      }
375 376
    }
......
449 450
      ObjectFaceShape faceShape = getObjectFaceShape(variant);
450 451
      ObjectVertexEffects effects = getVertexEffects(variant);
451 452
      FactoryCubit factory = FactoryCubit.getInstance();
452
      factory.createNewFaceTransform(mShapes[variant],mVariantFaceIsOuter[variant]);
453
      factory.createNewFaceTransform(mShapes[variant]);
453 454
      mVariantMeshes[variant] = factory.createRoundedSolid(mShapes[variant],faceShape,effects,numComponents);
454 455
      }
455 456

  
src/main/java/org/distorted/objectlib/objects/TwistyCutSolid.java
102 102

  
103 103
  private void prepareShapes()
104 104
    {
105
    float[][] positions = getCubitPositions();
106 105
    if( mCutPlanes==null ) createCutPlanes();
107
    Static4D[] quats = getQuats();
108
    float[] center = getPlanesVector();
109
    FactoryCutSolid.CutSolidInfo info = FactoryCutSolid.computeInfo(positions,mCutPlanes,quats,center);
106
    FactoryCutSolid.CutSolidInfo info = FactoryCutSolid.computeInfo(this,mCutPlanes);
110 107
    mShapes = info.getShapes();
111 108
    mCubitToVariantQuatMap = info.getVariantQuatMap();
112 109
    }

Also available in: Unified diff