Skip to content

Commit f1bb7ed

Browse files
committed
engine refactoring. fixes #105 #88 #69
1 parent 8899c67 commit f1bb7ed

File tree

72 files changed

+2394
-2644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2394
-2644
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ The application does not use any third party library.
1313
* Collada format (DAE): https://en.wikipedia.org/wiki/COLLADA
1414

1515

16-
News (16/05/2019)
16+
News (19/05/2019)
1717
=================
1818

1919
* New: Stereoscopic rendering: anaglyph (red-green glasses) & VR glasses (cardboard)
20-
* Fix: some bugs fixed
20+
* New: Engine refactoring
21+
* Fix: Bugs fixed
2122

2223

2324

@@ -179,6 +180,13 @@ ChangeLog
179180

180181
(f) fixed, (i) improved, (n) new feature
181182

183+
- 2.5.0 (19/05/2019)
184+
- (n) new blending toggle
185+
- (n) new color toggle
186+
- (i) engine refactoring: externalized shaders
187+
- (i) engine improved: fixed bugs and removed classes
188+
- 2.4.0 (16/05/2019)
189+
- (n) stereoscopic rendering: anaglyph + cardboard
182190
- 2.3.0 (27/09/2018)
183191
- (n) Externalized 3d engine into android library module
184192
- (n) Wiki initial documentation
15.4 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="org.andresoviedo.dddmodel2"
5-
android:versionCode="19"
6-
android:versionName="2.3.0" >
5+
android:versionCode="20"
6+
android:versionName="2.5.0" >
77

88
<uses-sdk
99
android:minSdkVersion=""

app/src/main/java/org/andresoviedo/app/model3D/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import org.andresoviedo.app.model3D.view.MenuActivity;
99
import org.andresoviedo.app.model3D.view.ModelActivity;
10-
import org.andresoviedo.util.android.AndroidURLStreamHandlerFactory;
1110
import org.andresoviedo.dddmodel2.R;
11+
import org.andresoviedo.util.android.AndroidURLStreamHandlerFactory;
1212

1313
import java.net.URL;
1414

app/src/main/java/org/andresoviedo/app/model3D/demo/ExampleSceneLoader.java

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import android.util.Log;
88
import android.widget.Toast;
99

10-
import org.andresoviedo.android_3d_model_engine.services.Object3DBuilder;
1110
import org.andresoviedo.android_3d_model_engine.model.Object3DData;
11+
import org.andresoviedo.android_3d_model_engine.services.Object3DBuilder;
1212
import org.andresoviedo.app.model3D.view.ModelActivity;
1313
import org.andresoviedo.util.android.ContentUtils;
1414
import org.andresoviedo.util.io.IOUtils;
@@ -161,45 +161,6 @@ protected Void doInBackground(Void... params) {
161161
} catch (Exception ex) {
162162
errors.add(ex);
163163
}*/
164-
165-
/*// test loading collada object
166-
try {
167-
// this has heterogeneous faces
168-
new ColladaLoaderTask(parent, Uri.parse("assets://org.andresoviedo" +
169-
".dddmodel2/assets/models/cowboy.dae"), new LoaderTask.Callback() {
170-
@Override
171-
public void onStart() {
172-
// Set up ContentUtils so referenced materials and/or textures could be find
173-
ContentUtils.setThreadActivity(parent);
174-
ContentUtils.provideAssets(parent);
175-
}
176-
177-
@Override
178-
public void onLoadError(Exception ex) {
179-
ContentUtils.setThreadActivity(null);
180-
ContentUtils.clearDocumentsProvided();
181-
}
182-
183-
@Override
184-
public void onLoadComplete(List<Object3DData> data) {
185-
186-
}
187-
188-
@Override
189-
public void onLoadComplete(List<Object3DData> data) {
190-
for (Object3DData d : data) {
191-
d.centerAndScale(4, new float[]{0, 0, -2});
192-
addObject(d);
193-
}
194-
ContentUtils.setThreadActivity(null);
195-
ContentUtils.clearDocumentsProvided();
196-
}
197-
}).execute();
198-
199-
} catch (Exception ex) {
200-
Log.e("Example",ex.getMessage(),ex);
201-
errors.add(ex);
202-
}*/
203164
} catch (Exception ex) {
204165
errors.add(ex);
205166
} finally{
@@ -225,5 +186,18 @@ protected void onPostExecute(Void result) {
225186
}
226187
}
227188
}.execute();
189+
190+
// test loading collada object
191+
/*try {
192+
// this has heterogeneous faces
193+
new ColladaLoaderTask(parent, Uri.parse("assets://assets/models/cowboy.dae"), this).execute();
194+
195+
} catch (Exception ex) {
196+
Log.e("Example",ex.getMessage(),ex);
197+
//errors.add(ex);
198+
} finally {
199+
ContentUtils.setThreadActivity(null);
200+
ContentUtils.clearDocumentsProvided();
201+
}*/
228202
}
229203
}

app/src/main/java/org/andresoviedo/app/model3D/demo/SceneLoader.java

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import org.andresoviedo.android_3d_model_engine.animation.Animator;
99
import org.andresoviedo.android_3d_model_engine.collision.CollisionDetection;
1010
import org.andresoviedo.android_3d_model_engine.model.Camera;
11-
import org.andresoviedo.android_3d_model_engine.services.Object3DBuilder;
1211
import org.andresoviedo.android_3d_model_engine.model.Object3DData;
1312
import org.andresoviedo.android_3d_model_engine.services.LoaderTask;
13+
import org.andresoviedo.android_3d_model_engine.services.Object3DBuilder;
1414
import org.andresoviedo.android_3d_model_engine.services.collada.ColladaLoaderTask;
1515
import org.andresoviedo.android_3d_model_engine.services.stl.STLLoaderTask;
1616
import org.andresoviedo.android_3d_model_engine.services.wavefront.WavefrontLoaderTask;
@@ -52,6 +52,10 @@ public class SceneLoader implements LoaderTask.Callback {
5252
* Point of view camera
5353
*/
5454
private Camera camera;
55+
/**
56+
* Enable or disable blending (transparency)
57+
*/
58+
private boolean isBlendingEnabled = true;
5559
/**
5660
* Whether to draw objects as wireframes
5761
*/
@@ -72,6 +76,10 @@ public class SceneLoader implements LoaderTask.Callback {
7276
* Whether to draw using textures
7377
*/
7478
private boolean drawTextures = true;
79+
/**
80+
* Whether to draw using colors or use default white color
81+
*/
82+
private boolean drawColors = true;
7583
/**
7684
* Light toggle feature: we have 3 states: no light, light, light + rotation
7785
*/
@@ -83,7 +91,11 @@ public class SceneLoader implements LoaderTask.Callback {
8391
/**
8492
* Animate model (dae only) or not
8593
*/
86-
private boolean animateModel = true;
94+
private boolean doAnimation = true;
95+
/**
96+
* show bind pose only
97+
*/
98+
private boolean showBindPose = false;
8799
/**
88100
* Draw skeleton or not
89101
*/
@@ -137,6 +149,7 @@ public void init() {
137149

138150
// Camera to show a point of view
139151
camera = new Camera();
152+
camera.setChanged(true); // force first draw
140153

141154
if (parent.getParamUri() == null){
142155
return;
@@ -197,10 +210,10 @@ public void onDrawFrame() {
197210

198211
if (objects.isEmpty()) return;
199212

200-
if (animateModel) {
213+
if (doAnimation) {
201214
for (int i=0; i<objects.size(); i++) {
202215
Object3DData obj = objects.get(i);
203-
animator.update(obj);
216+
animator.update(obj, isShowBindPose());
204217
}
205218
}
206219
}
@@ -237,16 +250,20 @@ public synchronized List<Object3DData> getObjects() {
237250
}
238251

239252
public void toggleWireframe() {
240-
if (this.drawWireframe && !this.drawingPoints) {
253+
if (!this.drawWireframe && !this.drawingPoints && !this.drawSkeleton){
254+
this.drawWireframe = true;
255+
makeToastText("Wireframe", Toast.LENGTH_SHORT);
256+
} else if (!this.drawingPoints && !this.drawSkeleton){
241257
this.drawWireframe = false;
242258
this.drawingPoints = true;
243259
makeToastText("Points", Toast.LENGTH_SHORT);
244-
} else if (this.drawingPoints) {
260+
} else if (!this.drawSkeleton){
245261
this.drawingPoints = false;
246-
makeToastText("Faces", Toast.LENGTH_SHORT);
262+
this.drawSkeleton = true;
263+
makeToastText("Skeleton", Toast.LENGTH_SHORT);
247264
} else {
248-
makeToastText("Wireframe", Toast.LENGTH_SHORT);
249-
this.drawWireframe = true;
265+
this.drawSkeleton = false;
266+
makeToastText("Faces", Toast.LENGTH_SHORT);
250267
}
251268
requestRender();
252269
}
@@ -273,8 +290,19 @@ public boolean isDrawNormals() {
273290
}
274291

275292
public void toggleTextures() {
276-
this.drawTextures = !drawTextures;
277-
makeToastText("Textures "+this.drawTextures, Toast.LENGTH_SHORT);
293+
if (drawTextures && drawColors){
294+
this.drawTextures = false;
295+
this.drawColors = true;
296+
makeToastText("Texture off", Toast.LENGTH_SHORT);
297+
} else if (drawColors){
298+
this.drawTextures = false;
299+
this.drawColors = false;
300+
makeToastText("Colors off", Toast.LENGTH_SHORT);
301+
} else {
302+
this.drawTextures = true;
303+
this.drawColors = true;
304+
makeToastText("Textures on", Toast.LENGTH_SHORT);
305+
}
278306
}
279307

280308
public void toggleLighting() {
@@ -293,21 +321,27 @@ public void toggleLighting() {
293321
}
294322

295323
public void toggleAnimation() {
296-
if (animateModel && !drawSkeleton){
297-
this.drawSkeleton = true;
298-
makeToastText("Skeleton on", Toast.LENGTH_SHORT);
299-
} else if (animateModel){
300-
this.drawSkeleton = false;
301-
this.animateModel = false;
302-
makeToastText("Animation off", Toast.LENGTH_SHORT);
303-
} else {
304-
animateModel = true;
324+
if (!this.doAnimation && !this.showBindPose){
325+
this.doAnimation = true;
305326
makeToastText("Animation on", Toast.LENGTH_SHORT);
306327
}
328+
else if (!this.showBindPose) {
329+
this.doAnimation = true;
330+
this.showBindPose = true;
331+
makeToastText("Bind pose", Toast.LENGTH_SHORT);
332+
} else {
333+
this.doAnimation = false;
334+
this.showBindPose = false;
335+
makeToastText("Animation off", Toast.LENGTH_SHORT);
336+
}
307337
}
308338

309-
public boolean isDrawAnimation() {
310-
return animateModel;
339+
public boolean isDoAnimation() {
340+
return doAnimation;
341+
}
342+
343+
public boolean isShowBindPose() {
344+
return showBindPose;
311345
}
312346

313347
public void toggleCollision() {
@@ -345,6 +379,10 @@ public boolean isDrawTextures() {
345379
return drawTextures;
346380
}
347381

382+
public boolean isDrawColors() {
383+
return drawColors;
384+
}
385+
348386
public boolean isDrawLighting() {
349387
return drawLighting;
350388
}
@@ -365,6 +403,15 @@ public boolean isAnaglyph() {
365403
return isAnaglyph;
366404
}
367405

406+
public void toggleBlending() {
407+
this.isBlendingEnabled = !isBlendingEnabled;
408+
makeToastText("Blending "+isBlendingEnabled, Toast.LENGTH_SHORT);
409+
}
410+
411+
public boolean isBlendingEnabled() {
412+
return isBlendingEnabled;
413+
}
414+
368415
@Override
369416
public void onStart(){
370417
ContentUtils.setThreadActivity(parent);
@@ -385,6 +432,7 @@ public void onLoadComplete(List<Object3DData> datas) {
385432
}
386433
}
387434
}
435+
388436
// TODO: move error alert to LoaderTask
389437
List<String> allErrors = new ArrayList<>();
390438
for (Object3DData data : datas) {

app/src/main/java/org/andresoviedo/app/model3D/view/MenuActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
import android.widget.Toast;
1717

1818
import org.andresoviedo.android_3d_model_engine.services.wavefront.WavefrontLoader;
19+
import org.andresoviedo.dddmodel2.R;
1920
import org.andresoviedo.util.android.AndroidUtils;
2021
import org.andresoviedo.util.android.AssetUtils;
2122
import org.andresoviedo.util.android.ContentUtils;
2223
import org.andresoviedo.util.android.FileUtils;
2324
import org.andresoviedo.util.view.TextActivity;
24-
import org.andresoviedo.dddmodel2.R;
2525

2626
import java.io.File;
2727
import java.util.HashMap;

app/src/main/java/org/andresoviedo/app/model3D/view/ModelActivity.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import org.andresoviedo.app.model3D.demo.ExampleSceneLoader;
1818
import org.andresoviedo.app.model3D.demo.SceneLoader;
19-
import org.andresoviedo.util.android.ContentUtils;
2019
import org.andresoviedo.dddmodel2.R;
20+
import org.andresoviedo.util.android.ContentUtils;
2121

2222
import java.io.IOException;
2323

@@ -90,8 +90,12 @@ protected void onCreate(Bundle savedInstanceState) {
9090

9191
// Create a GLSurfaceView instance and set it
9292
// as the ContentView for this Activity.
93-
gLView = new ModelSurfaceView(this);
94-
setContentView(gLView);
93+
try {
94+
gLView = new ModelSurfaceView(this);
95+
setContentView(gLView);
96+
} catch (Exception e) {
97+
Toast.makeText(this, "Error loading OpenGL view:\n" +e.getMessage(), Toast.LENGTH_LONG).show();
98+
}
9599

96100
// Show the Up button in the action bar.
97101
setupActionBar();
@@ -166,6 +170,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
166170
case R.id.model_toggle_stereoscopic:
167171
scene.toggleStereoscopic();
168172
break;
173+
case R.id.model_toggle_blending:
174+
scene.toggleBlending();
175+
break;
169176
case R.id.model_toggle_immersive:
170177
toggleImmersive();
171178
break;

0 commit comments

Comments
 (0)