19 |
19 |
|
20 |
20 |
package org.distorted.examples.meshfile;
|
21 |
21 |
|
|
22 |
import android.content.Context;
|
|
23 |
import android.content.res.Resources;
|
22 |
24 |
import android.graphics.Bitmap;
|
23 |
25 |
import android.graphics.Canvas;
|
24 |
26 |
import android.graphics.Paint;
|
25 |
27 |
import android.opengl.GLSurfaceView;
|
26 |
28 |
|
27 |
|
import org.distorted.library.effect.EffectType;
|
28 |
|
import org.distorted.library.effect.MatrixEffectMove;
|
29 |
29 |
import org.distorted.library.effect.MatrixEffectQuaternion;
|
30 |
30 |
import org.distorted.library.effect.MatrixEffectScale;
|
31 |
|
import org.distorted.library.effect.VertexEffectDeform;
|
32 |
|
import org.distorted.library.effect.VertexEffectMove;
|
33 |
|
import org.distorted.library.effect.VertexEffectRotate;
|
34 |
|
import org.distorted.library.effect.VertexEffectSink;
|
35 |
31 |
import org.distorted.library.main.DistortedEffects;
|
36 |
32 |
import org.distorted.library.main.DistortedLibrary;
|
37 |
33 |
import org.distorted.library.main.DistortedScreen;
|
38 |
34 |
import org.distorted.library.main.DistortedTexture;
|
39 |
35 |
import org.distorted.library.mesh.MeshBase;
|
40 |
|
import org.distorted.library.mesh.MeshJoined;
|
41 |
|
import org.distorted.library.mesh.MeshRectangles;
|
42 |
|
import org.distorted.library.type.Dynamic1D;
|
|
36 |
import org.distorted.library.mesh.MeshFile;
|
43 |
37 |
import org.distorted.library.type.DynamicQuat;
|
44 |
|
import org.distorted.library.type.Static1D;
|
45 |
38 |
import org.distorted.library.type.Static3D;
|
46 |
39 |
import org.distorted.library.type.Static4D;
|
47 |
40 |
|
|
41 |
import java.io.DataInputStream;
|
|
42 |
import java.io.IOException;
|
|
43 |
import java.io.InputStream;
|
|
44 |
|
48 |
45 |
import javax.microedition.khronos.egl.EGLConfig;
|
49 |
46 |
import javax.microedition.khronos.opengles.GL10;
|
50 |
47 |
|
... | ... | |
111 |
108 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
112 |
109 |
{
|
113 |
110 |
if( mTexture==null ) mTexture = new DistortedTexture();
|
|
111 |
mTexture.setTexture( createTexture(0) );
|
114 |
112 |
|
115 |
113 |
try
|
116 |
114 |
{
|
... | ... | |
124 |
122 |
|
125 |
123 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126 |
124 |
|
127 |
|
void open(String name)
|
|
125 |
void open(int resourceID)
|
128 |
126 |
{
|
129 |
|
mTexture.setTexture( createTexture(name) );
|
130 |
|
mMesh = createMesh(name);
|
|
127 |
mMesh = createMesh(resourceID);
|
131 |
128 |
|
132 |
129 |
mScreen.detachAll();
|
133 |
130 |
mScreen.attach(mTexture,mEffects,mMesh);
|
... | ... | |
135 |
132 |
|
136 |
133 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137 |
134 |
|
138 |
|
private Bitmap createTexture(String name)
|
|
135 |
private Bitmap createTexture(int resourceID)
|
139 |
136 |
{
|
140 |
|
// TODO
|
|
137 |
final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
|
|
138 |
final int FACES=FACE_COLORS.length;
|
|
139 |
int SIZE = 200;
|
|
140 |
float STROKE = 0.05f*SIZE;
|
|
141 |
float OFF = STROKE/2 -1;
|
|
142 |
float OFF2 = 0.5f*SIZE + OFF;
|
|
143 |
float HEIGHT = SIZE - OFF;
|
|
144 |
float RADIUS = SIZE/12;
|
|
145 |
float ARC1_H = 0.2f*SIZE;
|
|
146 |
float ARC1_W = SIZE*0.5f;
|
|
147 |
float ARC2_W = 0.153f*SIZE;
|
|
148 |
float ARC2_H = 0.905f*SIZE;
|
|
149 |
float ARC3_W = SIZE-ARC2_W;
|
|
150 |
|
|
151 |
Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888);
|
|
152 |
Canvas canvas = new Canvas(result);
|
|
153 |
Paint paint = new Paint();
|
|
154 |
paint.setAntiAlias(true);
|
|
155 |
paint.setStrokeWidth(STROKE);
|
|
156 |
|
|
157 |
for(int i=0; i<FACES; i++)
|
|
158 |
{
|
|
159 |
paint.setColor(FACE_COLORS[i]);
|
|
160 |
paint.setStyle(Paint.Style.FILL);
|
|
161 |
|
|
162 |
canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint);
|
|
163 |
|
|
164 |
paint.setColor(0xff000000);
|
|
165 |
paint.setStyle(Paint.Style.STROKE);
|
|
166 |
|
|
167 |
canvas.drawLine( i*SIZE, HEIGHT, SIZE +i*SIZE, HEIGHT, paint);
|
|
168 |
canvas.drawLine( OFF +i*SIZE, SIZE, OFF2 +i*SIZE, 0, paint);
|
|
169 |
canvas.drawLine((SIZE-OFF)+i*SIZE, SIZE, (SIZE-OFF2) +i*SIZE, 0, paint);
|
|
170 |
|
|
171 |
canvas.drawArc( ARC1_W-RADIUS+i*SIZE, ARC1_H-RADIUS, ARC1_W+RADIUS+i*SIZE, ARC1_H+RADIUS, 225, 90, false, paint);
|
|
172 |
canvas.drawArc( ARC2_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC2_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 105, 90, false, paint);
|
|
173 |
canvas.drawArc( ARC3_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC3_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 345, 90, false, paint);
|
|
174 |
}
|
141 |
175 |
|
142 |
|
return null;
|
|
176 |
return result;
|
143 |
177 |
}
|
144 |
178 |
|
145 |
179 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
180 |
|
147 |
|
private MeshBase createMesh(String name)
|
|
181 |
private MeshBase createMesh(int resourceID)
|
148 |
182 |
{
|
149 |
|
// TODO
|
|
183 |
Context con = mView.getContext();
|
|
184 |
Resources res = con.getResources();
|
|
185 |
InputStream is = res.openRawResource(resourceID);
|
|
186 |
DataInputStream dos = new DataInputStream(is);
|
|
187 |
MeshBase mesh = new MeshFile(dos);
|
|
188 |
|
|
189 |
try
|
|
190 |
{
|
|
191 |
is.close();
|
|
192 |
}
|
|
193 |
catch(IOException e)
|
|
194 |
{
|
|
195 |
android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
|
|
196 |
}
|
150 |
197 |
|
151 |
|
return null;
|
|
198 |
return mesh;
|
152 |
199 |
}
|
153 |
200 |
}
|
Reading a mesh from the .dmesh file might work now. Checked on two small meshes.