diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-12-14 15:07:17 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2011-12-14 15:07:17 -0800 |
commit | 1168868e766f0696c30f644292a5a833ee3983e4 (patch) | |
tree | 3ad79ddb09367535c880f289b0305a77a8bbf83e /tests/RenderScriptTests/SceneGraph/src | |
parent | 684267525b349eb12f4e31d88061c51115678dec (diff) | |
download | frameworks_base-1168868e766f0696c30f644292a5a833ee3983e4.zip frameworks_base-1168868e766f0696c30f644292a5a833ee3983e4.tar.gz frameworks_base-1168868e766f0696c30f644292a5a833ee3983e4.tar.bz2 |
make loading assets more robust
Change-Id: I9a2b7be8e8522264f8f2de04b43dbe5ec98bc24a
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
4 files changed, 35 insertions, 17 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java index 8a141fe..127d85e 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java @@ -50,6 +50,8 @@ public class ColladaParser { HashMap<String, Texture2D> mSamplerImageMap;
Scene mScene;
+ String mRootDir;
+
String toString(Float3 v) {
String valueStr = v.x + " " + v.y + " " + v.z;
return valueStr;
@@ -67,11 +69,13 @@ public class ColladaParser { mImages = new HashMap<String, Texture2D>();
}
- public void init(InputStream is) {
+ public void init(InputStream is, String rootDir) {
mLights.clear();
mCameras.clear();
mEffectsParams.clear();
+ mRootDir = rootDir;
+
long start = System.currentTimeMillis();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
@@ -444,6 +448,7 @@ public class ColladaParser { Texture2D tex = new Texture2D();
tex.setFileName(file);
+ tex.setFileDir(mRootDir);
mScene.appendTextures(tex);
mImages.put(id, tex);
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java index 3b4efa6..037741d 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java @@ -46,8 +46,7 @@ public class ColladaScene { private String modelName; private static String TAG = "ColladaScene"; private final int STATE_LAST_FOCUS = 1; - private final boolean mLoadFromSD = true; - private static String mSDCardPath = "sdcard/scenegraph/"; + boolean mLoadFromSD = false; TestAppRS mRenderer; SceneLoadedCallback mCallback; @@ -66,7 +65,11 @@ public class ColladaScene { mRS = rs; mRes = res; - new ColladaLoaderTask().execute(modelName + ".dae"); + if (modelName.indexOf("sdcard/") != -1) { + mLoadFromSD = true; + } + + new ColladaLoaderTask().execute(modelName); } private Resources mRes; @@ -76,6 +79,7 @@ public class ColladaScene { private class ColladaLoaderTask extends AsyncTask<String, Void, Boolean> { ColladaParser sceneSource; protected Boolean doInBackground(String... names) { + String rootDir = names[0].substring(0, names[0].lastIndexOf('/') + 1); long start = System.currentTimeMillis(); sceneSource = new ColladaParser(); InputStream is = null; @@ -83,7 +87,7 @@ public class ColladaScene { if (!mLoadFromSD) { is = mRes.getAssets().open(names[0]); } else { - File f = new File(mSDCardPath + names[0]); + File f = new File(names[0]); is = new BufferedInputStream(new FileInputStream(f)); } } catch (IOException e) { @@ -94,7 +98,7 @@ public class ColladaScene { Log.v("TIMER", "Stream load time: " + (end - start)); start = System.currentTimeMillis(); - sceneSource.init(is); + sceneSource.init(is, rootDir); end = System.currentTimeMillis(); Log.v("TIMER", "Collada parse time: " + (end - start)); return new Boolean(true); @@ -110,7 +114,8 @@ public class ColladaScene { mCallback.run(); } - new A3DLoaderTask().execute(modelName + ".a3d"); + String shortName = modelName.substring(0, modelName.lastIndexOf('.')); + new A3DLoaderTask().execute(shortName + ".a3d"); } } @@ -121,7 +126,7 @@ public class ColladaScene { if (!mLoadFromSD) { model = FileA3D.createFromAsset(mRS, mRes.getAssets(), names[0]); } else { - model = FileA3D.createFromFile(mRS, mSDCardPath + names[0]); + model = FileA3D.createFromFile(mRS, names[0]); } int numModels = model.getIndexEntryCount(); for (int i = 0; i < numModels; i ++) { diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java index 5bb821f..cebfcf4 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java @@ -44,7 +44,7 @@ import com.android.scenegraph.SceneManager.SceneLoadedCallback; // This is where the scenegraph and the rendered objects are initialized and used public class TestAppRS { - private static String modelName = "orientation_test"; + private static String modelName = "orientation_test.dae"; private static String TAG = "TestAppRS"; private final int STATE_LAST_FOCUS = 1; private final boolean mLoadFromSD = true; @@ -112,16 +112,16 @@ public class TestAppRS { initRS(); // Load a scene to render - mSceneManager.loadModel(modelName, mLoadedCallback); + mSceneManager.loadModel(mSDCardPath + modelName, mLoadedCallback); } // When a new model file is selected from the UI, this function gets called to init everything void loadModel(String path) { - String shortName = path.substring(path.lastIndexOf('/') + 1); - shortName = shortName.substring(0, shortName.lastIndexOf('.')); + //String shortName = path.substring(path.lastIndexOf('/') + 1); + //shortName = shortName.substring(0, shortName.lastIndexOf('.')); mScript.set_gInitialized(false); mActiveScene.destroyRS(mSceneManager); - mSceneManager.loadModel(shortName, mLoadedCallback); + mSceneManager.loadModel(path, mLoadedCallback); } private Resources mRes; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java index fdab999..e08622d 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java @@ -38,13 +38,21 @@ import android.util.Log; * @hide */ public class Texture2D extends SceneGraphBase { - private static String mSDCardPath = "sdcard/scenegraph/"; - private final boolean mLoadFromSD = true; + private boolean mLoadFromSD; String mFileName; + String mFileDir; Allocation mRsTexture; public Texture2D() { + mLoadFromSD = false; + } + + public void setFileDir(String dir) { + if (dir.indexOf("sdcard/") != -1) { + mLoadFromSD = true; + } + mFileDir = dir; } public void setFileName(String file) { @@ -64,9 +72,9 @@ public class Texture2D extends SceneGraphBase { InputStream is = null; try { if (!mLoadFromSD) { - is = res.getAssets().open(shortName); + is = res.getAssets().open(mFileDir + shortName); } else { - File f = new File(mSDCardPath + shortName); + File f = new File(mFileDir + shortName); is = new BufferedInputStream(new FileInputStream(f)); } } catch (IOException e) { |