Skip to content

Commit

Permalink
Closes #17. Added support for STL files
Browse files Browse the repository at this point in the history
  • Loading branch information
andresoviedo committed Apr 17, 2017
1 parent 56ad5eb commit 9c27b82
Show file tree
Hide file tree
Showing 22 changed files with 2,891 additions and 356 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ Android 3D Model Viewer
![codeship badge](https://codeship.com/projects/52cf9560-deb2-0134-4203-2aaddef843aa/status?branch=master)

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


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


News (16/04/2017)
News (17/04/2017)
=================

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

Expand Down Expand Up @@ -62,7 +59,7 @@ Features
========

- OpenGL ES 2.0 API
- OBJ format supported (wavefront)
- Formats: OBJ (wavefront) & STL (STereoLithography)
- calculation of normals
- transformations: scaling, rotation, translation
- colors
Expand Down Expand Up @@ -128,6 +125,11 @@ ChangeLog

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

- 1.3.1 (17/04/2017)
- (n) #17: Added support for STL files
- (n) #17: Asynchronous building of model so the build rendering is previewed
- (f) #17: Added Toasts to buttons to show current state

- 1.2.10 (16/04/2017)
- (f) #16: Immersive mode is now configurable in the ModelActivity Intent: b.putString("immersiveMode", "false");
- (f) #16: Background color configurable in the ModelActivity Intent: b.putString("backgroundColor", "0 0 0 1");
Expand Down
Binary file modified app/build/outputs/apk/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.andresoviedo.dddmodel2"
android:versionCode="9"
android:versionName="1.2.10" >
android:versionCode="10"
android:versionName="1.3.0" >

<uses-sdk
android:minSdkVersion="8"
Expand Down
Binary file added app/src/main/assets/models/african_statue.stl
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package org.andresoviedo.app.model3D.controller;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.util.Log;

import org.andresoviedo.app.model3D.model.Object3DBuilder;
import org.andresoviedo.app.model3D.model.Object3DData;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
* This component allows loading the model without blocking the UI.
*
* @author andresoviedo
*/
public abstract class LoaderTask extends AsyncTask<Void, Integer, Object3DData> {

/**
* URL to the 3D model
*/
protected final URL url;
/**
* Callback to notify of events
*/
protected final Object3DBuilder.Callback callback;
/**
* The dialog that will show the progress of the loading
*/
protected final ProgressDialog dialog;
/**
* The parent activity
*/
private final Activity parent;
/**
* Directory where the model is located (null when its loaded from asset)
*/
private final File currentDir;
/**
* Asset directory where the model is loaded (null when its loaded from the filesystem)
*/
private final String assetsDir;
/**
* Id of the data being loaded
*/
private final String modelId;
/**
* Exception when loading data (if any)
*/
protected Exception error;

/**
* Build a new progress dialog for loading the data model asynchronously
*
* @param url the URL pointing to the 3d model
* @param currentDir the directory where the model is located (null when the model is an asset)
* @param modelId the id the data being loaded
*/
public LoaderTask(Activity parent, URL url, File currentDir, String assetsDir, String modelId, Object3DBuilder.Callback callback) {
this.parent = parent;
this.url = url;
this.currentDir = currentDir;
this.assetsDir = assetsDir;
this.modelId = modelId;
this.dialog = new ProgressDialog(parent);
this.callback = callback;
}


@Override
protected void onPreExecute() {
super.onPreExecute();
// this.dialog = ProgressDialog.show(this.parent, "Please wait ...", "Loading model data...", true);
// this.dialog.setTitle(modelId);
this.dialog.setMessage("Loading...");
this.dialog.setCancelable(false);
this.dialog.show();
}



@Override
protected Object3DData doInBackground(Void... params) {
try {
Object3DData data = build();
callback.onLoadComplete(data);
build(data);
return data;
} catch (Exception ex) {
error = ex;
return null;
}
}

protected abstract Object3DData build() throws Exception;

protected abstract void build(Object3DData data) throws Exception;

@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
switch (values[0]) {
case 0:
this.dialog.setMessage("Analyzing model...");
break;
case 1:
this.dialog.setMessage("Allocating memory...");
break;
case 2:
this.dialog.setMessage("Loading data...");
break;
case 3:
this.dialog.setMessage("Scaling object...");
break;
case 4:
this.dialog.setMessage("Building 3D model...");
break;
case 5:
// Toast.makeText(parent, modelId + " Build!", Toast.LENGTH_LONG).show();
break;
}
}

@Override
protected void onPostExecute(Object3DData data) {
super.onPostExecute(data);
if (dialog.isShowing()) {
dialog.dismiss();
}
if (error != null) {
callback.onLoadError(error);
} else {
callback.onBuildComplete(data);
}
}


}
Loading

0 comments on commit 9c27b82

Please sign in to comment.