Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manbod/5027673fb8bab2d9bb7da8a3ff482494 to your computer and use it in GitHub Desktop.
Save manbod/5027673fb8bab2d9bb7da8a3ff482494 to your computer and use it in GitHub Desktop.
Load a 3D android model and add it to the given position
/**
* Load a 3D android model and add it to the given position
*/
private void createDroidAtPosition(Vector position){
// Create a droid on the surface
final Bitmap bot = ViroHelper.getBitmapFromAsset(this, "andy.png");
final Object3D object3D = new Object3D();
object3D.setPosition(position);
mScene.getRootNode().addChildNode(object3D);
// Load the Android model asynchronously.
object3D.loadModel(Uri.parse("file:///android_asset/andy.obj"), Object3D.Type.OBJ, new AsyncObject3DListener() {
@Override
public void onObject3DLoaded(final Object3D object, final Object3D.Type type) {
// When the model is loaded, set the texture associated with this OBJ.
Texture objectTexture = new Texture(bot, Texture.Format.RGBA8, false, false);
Material material = new Material();
material.setDiffuseTexture(objectTexture);
object3D.getGeometry().setMaterials(Arrays.asList(material));
}
@Override
public void onObject3DFailed(String s) {
}
});
// Make the object draggable.
object3D.setDragListener(new DragListener() {
@Override
public void onDrag(int i, Node node, Vector vector, Vector vector1) {
// No-op.
}
});
object3D.setDragType(Node.DragType.FIXED_DISTANCE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment