Skip to content

Commit 9c27b82

Browse files
committed
Closes #17. Added support for STL files
1 parent 56ad5eb commit 9c27b82

22 files changed

+2891
-356
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ Android 3D Model Viewer
44
![codeship badge](https://codeship.com/projects/52cf9560-deb2-0134-4203-2aaddef843aa/status?branch=master)
55

66
This is a demo of OpenGL ES 2.0.
7-
It is basically an android application with a 3D renderer that can load Wavefront Obj files.
7+
It is basically an android application with a 3D renderer that can load Wavefront Obj & STL files.
88
The purpose of this application is to learn and share how to draw using OpenGL language.
99

1010

11-
https://en.wikipedia.org/wiki/Wavefront_.obj_file
11+
* Wafefront format (OBJ): https://en.wikipedia.org/wiki/Wavefront_.obj_file
12+
* STereoLithography format (STL): https://en.wikipedia.org/wiki/STL_(file_format)
1213

1314

14-
News (16/04/2017)
15+
News (17/04/2017)
1516
=================
1617

17-
* Fixed #16: Toogle point drawing + several improvements
18-
* Fixed #15: Toggle rotating light + fixed wireframe colors
19-
* Fixed #14: Camera movement improved
20-
* Fixed #13: Fixed parsing of vertices
21-
* Fixed #12: Wireframe performance
22-
* Fixed #11: Normals generation
23-
* Fixed #10: Fixed texture issue
18+
* Enhancement #17: Added support for TLS format
19+
* Fixed #16: Toogle point drawing
20+
* Fixed #15: Toggle rotating light
2421
* Fixed #1: Cpu Performance problems
2522
* Fixed #5: Memory Performance problems
2623

@@ -62,7 +59,7 @@ Features
6259
========
6360

6461
- OpenGL ES 2.0 API
65-
- OBJ format supported (wavefront)
62+
- Formats: OBJ (wavefront) & STL (STereoLithography)
6663
- calculation of normals
6764
- transformations: scaling, rotation, translation
6865
- colors
@@ -128,6 +125,11 @@ ChangeLog
128125

129126
(f) fixed, (i) improved, (n) new feature
130127

128+
- 1.3.1 (17/04/2017)
129+
- (n) #17: Added support for STL files
130+
- (n) #17: Asynchronous building of model so the build rendering is previewed
131+
- (f) #17: Added Toasts to buttons to show current state
132+
131133
- 1.2.10 (16/04/2017)
132134
- (f) #16: Immersive mode is now configurable in the ModelActivity Intent: b.putString("immersiveMode", "false");
133135
- (f) #16: Background color configurable in the ModelActivity Intent: b.putString("backgroundColor", "0 0 0 1");

app/build/outputs/apk/app-release.apk

4.13 MB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="org.andresoviedo.dddmodel2"
4-
android:versionCode="9"
5-
android:versionName="1.2.10" >
4+
android:versionCode="10"
5+
android:versionName="1.3.0" >
66

77
<uses-sdk
88
android:minSdkVersion="8"
9.13 MB
Binary file not shown.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package org.andresoviedo.app.model3D.controller;
2+
3+
import android.app.Activity;
4+
import android.app.ProgressDialog;
5+
import android.os.AsyncTask;
6+
import android.util.Log;
7+
8+
import org.andresoviedo.app.model3D.model.Object3DBuilder;
9+
import org.andresoviedo.app.model3D.model.Object3DData;
10+
11+
import java.io.File;
12+
import java.io.FileInputStream;
13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
import java.net.URL;
16+
17+
/**
18+
* This component allows loading the model without blocking the UI.
19+
*
20+
* @author andresoviedo
21+
*/
22+
public abstract class LoaderTask extends AsyncTask<Void, Integer, Object3DData> {
23+
24+
/**
25+
* URL to the 3D model
26+
*/
27+
protected final URL url;
28+
/**
29+
* Callback to notify of events
30+
*/
31+
protected final Object3DBuilder.Callback callback;
32+
/**
33+
* The dialog that will show the progress of the loading
34+
*/
35+
protected final ProgressDialog dialog;
36+
/**
37+
* The parent activity
38+
*/
39+
private final Activity parent;
40+
/**
41+
* Directory where the model is located (null when its loaded from asset)
42+
*/
43+
private final File currentDir;
44+
/**
45+
* Asset directory where the model is loaded (null when its loaded from the filesystem)
46+
*/
47+
private final String assetsDir;
48+
/**
49+
* Id of the data being loaded
50+
*/
51+
private final String modelId;
52+
/**
53+
* Exception when loading data (if any)
54+
*/
55+
protected Exception error;
56+
57+
/**
58+
* Build a new progress dialog for loading the data model asynchronously
59+
*
60+
* @param url the URL pointing to the 3d model
61+
* @param currentDir the directory where the model is located (null when the model is an asset)
62+
* @param modelId the id the data being loaded
63+
*/
64+
public LoaderTask(Activity parent, URL url, File currentDir, String assetsDir, String modelId, Object3DBuilder.Callback callback) {
65+
this.parent = parent;
66+
this.url = url;
67+
this.currentDir = currentDir;
68+
this.assetsDir = assetsDir;
69+
this.modelId = modelId;
70+
this.dialog = new ProgressDialog(parent);
71+
this.callback = callback;
72+
}
73+
74+
75+
@Override
76+
protected void onPreExecute() {
77+
super.onPreExecute();
78+
// this.dialog = ProgressDialog.show(this.parent, "Please wait ...", "Loading model data...", true);
79+
// this.dialog.setTitle(modelId);
80+
this.dialog.setMessage("Loading...");
81+
this.dialog.setCancelable(false);
82+
this.dialog.show();
83+
}
84+
85+
86+
87+
@Override
88+
protected Object3DData doInBackground(Void... params) {
89+
try {
90+
Object3DData data = build();
91+
callback.onLoadComplete(data);
92+
build(data);
93+
return data;
94+
} catch (Exception ex) {
95+
error = ex;
96+
return null;
97+
}
98+
}
99+
100+
protected abstract Object3DData build() throws Exception;
101+
102+
protected abstract void build(Object3DData data) throws Exception;
103+
104+
@Override
105+
protected void onProgressUpdate(Integer... values) {
106+
super.onProgressUpdate(values);
107+
switch (values[0]) {
108+
case 0:
109+
this.dialog.setMessage("Analyzing model...");
110+
break;
111+
case 1:
112+
this.dialog.setMessage("Allocating memory...");
113+
break;
114+
case 2:
115+
this.dialog.setMessage("Loading data...");
116+
break;
117+
case 3:
118+
this.dialog.setMessage("Scaling object...");
119+
break;
120+
case 4:
121+
this.dialog.setMessage("Building 3D model...");
122+
break;
123+
case 5:
124+
// Toast.makeText(parent, modelId + " Build!", Toast.LENGTH_LONG).show();
125+
break;
126+
}
127+
}
128+
129+
@Override
130+
protected void onPostExecute(Object3DData data) {
131+
super.onPostExecute(data);
132+
if (dialog.isShowing()) {
133+
dialog.dismiss();
134+
}
135+
if (error != null) {
136+
callback.onLoadError(error);
137+
} else {
138+
callback.onBuildComplete(data);
139+
}
140+
}
141+
142+
143+
}

0 commit comments

Comments
 (0)