Project

General

Profile

« Previous | Next » 

Revision 4db4e39b

Added by Leszek Koltunski about 5 years ago

Improvements for texturing MeshCubes objects in two apps (in light of the recent change in default texture mapping)

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity2.java
32 32
import android.widget.CheckBox;
33 33

  
34 34
import org.distorted.examples.R;
35
import org.distorted.library.effect.EffectType;
36 35
import org.distorted.library.main.Distorted;
37 36
import org.distorted.library.main.DistortedEffects;
38 37
import org.distorted.library.main.DistortedTexture;
......
41 40
import org.distorted.library.mesh.MeshBase;
42 41
import org.distorted.library.mesh.MeshQuad;
43 42
import org.distorted.library.mesh.MeshSphere;
43
import org.distorted.library.type.Static4D;
44 44

  
45 45
import java.io.IOException;
46 46
import java.io.InputStream;
......
51 51
  {
52 52
  public static final int NUM_TABS = 4;
53 53

  
54
  private int mNumCols;
55
  private int mNumRows;
56
  private int mNumSlic;
57
  private int mObjectType;
58
  private int mBitmapID;
59
  private String mString;
60

  
61 54
  private DistortedTexture mTexture;
62 55
  private MeshBase mMesh;
63 56
  private Bitmap mBitmap;
......
66 59
  private float mRegionX, mRegionY, mRegionZ, mRegionR;
67 60
  private DistortedEffects mEffects;
68 61
  private ViewPager mViewPager;
69
  private Effects3DTabViewPager mPager;
70 62

  
71 63
  private boolean mShowCenter;
72 64
  private boolean mShowRegion;
......
88 80

  
89 81
    Bundle b = getIntent().getExtras();
90 82

  
91
    mObjectType = b.getInt("type");
92
    mNumCols    = b.getInt("cols");
93
    mNumRows    = b.getInt("rows");
94
    mNumSlic    = b.getInt("slices");
95
    mBitmapID   = b.getInt("bitmap");
96
    mString     = b.getString("string");
83
    int objectType = b.getInt("type");
84
    int numCols    = b.getInt("cols");
85
    int numRows    = b.getInt("rows");
86
    int numSlic    = b.getInt("slices");
87
    int bitmapID   = b.getInt("bitmap");
88
    String str     = b.getString("string");
97 89

  
98 90
    mShowCenter = false;
99 91
    mShowRegion = false;
100 92
    mShowNormal = false;
101 93
    mUseOIT     = false;
102 94

  
103
    switch(mObjectType)
95
    int maxsize = numCols > numRows ? (numCols>numSlic ? numCols:numSlic) : (numRows>numSlic ? numRows:numSlic) ;
96

  
97
    createBitmap(maxsize, bitmapID);
98

  
99
    switch(objectType)
104 100
      {
105
      case 0: mMesh = new MeshCubes(mNumCols, mString, mNumSlic);
101
      case 0: if( bitmapID!=-1 )
102
                {
103
                mMesh = new MeshCubes(numCols, str, numSlic);
104
                }
105
              else
106
                {
107
                Static4D mapFB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numRows/maxsize);
108
                Static4D mapLR = new Static4D(0.0f,0.0f, (float)numSlic/maxsize, (float)numRows/maxsize);
109
                Static4D mapTB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numSlic/maxsize);
110

  
111
                mMesh = new MeshCubes(numCols, str, numSlic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
112
                }
106 113
              break;
107
      case 1: mMesh = new MeshFlat(mNumCols,mNumRows);
114
      case 1: mMesh = new MeshFlat(numCols,numRows);
108 115
              break;
109
      case 2: mMesh = new MeshSphere(mNumRows);
116
      case 2: mMesh = new MeshSphere(numRows);
110 117
              break;
111 118
      case 3: mMesh = new MeshQuad();
112 119
              break;
113 120
      }
114 121

  
115 122
    mMesh.setShowNormals(mShowNormal);
116
    mTexture= new DistortedTexture(mNumCols,mNumRows);
123
    mTexture= new DistortedTexture(numCols,numRows);
117 124
    mEffects= new DistortedEffects();
118 125

  
119 126
    final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null);
......
122 129

  
123 130
    mViewPager = findViewById(R.id.effects3d_viewpager);
124 131
    mViewPager.setOffscreenPageLimit( NUM_TABS-1 );
125
    mPager = new Effects3DTabViewPager(this, getSupportFragmentManager() );
126
    mViewPager.setAdapter(mPager);
132
    Effects3DTabViewPager pager = new Effects3DTabViewPager(this, getSupportFragmentManager() );
133
    mViewPager.setAdapter(pager);
127 134
    TabLayout tabLayout = findViewById(R.id.effects3d_sliding_tabs);
128 135
    tabLayout.setupWithViewPager(mViewPager);
129 136

  
130 137
    resetData();
131 138
    }
132 139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

  
142
  private void createBitmap(int size, int bitmapID)
143
    {
144
    if( bitmapID!=-1)
145
      {
146
      InputStream is = getResources().openRawResource(bitmapID);
147

  
148
      try
149
        {
150
        mBitmap = BitmapFactory.decodeStream(is);
151
        }
152
      finally
153
        {
154
        try
155
          {
156
          is.close();
157
          }
158
        catch(IOException e) { }
159
        }
160
      }
161
    else
162
      {
163
      final int T = 64;
164
      final int S = T*size;
165

  
166
      Paint paint = new Paint();
167
      mBitmap = Bitmap.createBitmap(S,S, Bitmap.Config.ARGB_8888);
168
      Canvas canvas = new Canvas(mBitmap);
169

  
170
      paint.setAntiAlias(true);
171
      paint.setTextAlign(Paint.Align.CENTER);
172
      paint.setColor(0xff008800);
173
      paint.setStyle(Paint.Style.FILL);
174
      canvas.drawRect(0, 0, S, S, paint);
175
      paint.setColor(0xffffffff);
176

  
177
      for(int i=0; i<=size ; i++ )
178
        {
179
        canvas.drawRect( T*i-1, 0, T*i+1, S, paint);
180
        canvas.drawRect( 0, T*i-1, S, T*i+1, paint);
181
        }
182
      }
183
    }
184

  
133 185
///////////////////////////////////////////////////////////////////////////////////////////////////
134 186

  
135 187
  public DistortedTexture getTexture()
......
148 200

  
149 201
  public Bitmap getBitmap()
150 202
    {
151
    if( mBitmap==null )
152
      {
153
      if( mBitmapID!=-1)
154
        {
155
        InputStream is = getResources().openRawResource(mBitmapID);
156

  
157
        try
158
          {
159
          mBitmap = BitmapFactory.decodeStream(is);
160
          }
161
        finally
162
          {
163
          try
164
            {
165
            is.close();
166
            }
167
          catch(IOException e) { }
168
          }
169
        }
170
      else
171
        {
172
        final int W = 64*mNumCols;
173
        final int H = 64*mNumRows;
174

  
175
        Paint paint = new Paint();
176
        mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
177
        Canvas canvas = new Canvas(mBitmap);
178

  
179
        paint.setAntiAlias(true);
180
        paint.setTextAlign(Paint.Align.CENTER);
181
        paint.setColor(0xff008800);
182
        paint.setStyle(Paint.Style.FILL);
183
        canvas.drawRect(0, 0, W, H, paint);
184
        paint.setColor(0xffffffff);
185

  
186
        for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
187
        for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W,  H*i/mNumRows+1, paint);
188
        }
189
      }
190

  
191 203
    return mBitmap;
192 204
    }
193 205

  

Also available in: Unified diff