Salam all. This time I want to share a bit, how I tried out the
mid3d framework for the first time. Acknowledge that I am new to android
development. I just follow the tutorial
on Mat-d website but there are certain things that I don’t understand how they actually
work. Thus I want to share what I did step by step to make this example work. For
explanations on coding/steps or errors please visit Mat-d website here J you ll understand more
….
Step one.
Download min3d into your eclipse.
Select File>Import>SVN>Checkout projects from SVN
Next.
Choose radio button : Create a new repository location
Next.
Enter the svn location
the thing that we want to check out from the svn is the min3d framework code.
Step two.
Download obj file
www.3dvia.com …you need
to register first..it has free acc version.. and download the following 3d
model of a face http://www.3dvia.com/models/66964B5C6E405264/face
Change the face.obj into face_obj
Change the face.mtl into face_mtl
Change the image name to use all lowercase, as android doesnot allow images with capital letter.
from face_eyeL_hi.jpg to face_eyel_hi.jpg
from face_eceR_hi.jpg to face_ecer_hi.jpg
Change the image name to use all lowercase, as android doesnot allow images with capital letter.
from face_eyeL_hi.jpg to face_eyel_hi.jpg
from face_eceR_hi.jpg to face_ecer_hi.jpg
Step three.
Create android project for min3d test
Add main java name
Min3dTest.java
Add second java class Obj3DView.java
Under source create new package by right click and choose
new package.
Name the package min3d.
Copy all these files as follows
Then paste inside the new package you created just now .. in
min3d package
After paste the package should look like this …
Step four
Code the java classes…
For the Min3dTest please use this code…to call the load object
3d activity
package com.example.min3dtest;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class Min3dTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.startActivity( new Intent(this,Obj3DView.class));
}
}
***the package should be according to your declaration while creating your project.
For the Obj3DView please use this code
package com.example.min3dtest;
import min3d.core.Object3dContainer;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import min3d.vos.Light;
public class Obj3DView extends RendererActivity {
private Object3dContainer faceObject3D;
/** Called when the activity is first created. */
@Override
public void initScene()
{
scene.lights().add(new Light());
scene.lights().add(new Light());
Light myLight = new Light();
myLight.position.setZ(150);
scene.lights().add(myLight);
IParser myParser = Parser.createParser(Parser.Type.OBJ, getResources(), "com.example.min3dtest:raw/face_obj",true);
myParser.parse();
faceObject3D = myParser.getParsedObject();
faceObject3D.position().x = faceObject3D.position().y = faceObject3D.position().z = 0;
faceObject3D.scale().x = faceObject3D.scale().y = faceObject3D.scale().z = 0.009f;
// Depending on the model you will need to change the scale faceObject3D.scale().x = faceObject3D.scale().y = faceObject3D.scale().z = 0.009f;
scene.addChild(faceObject3D);
}
@Override
public void updateScene() {
faceObject3D.rotation().x += 0.5;
faceObject3D.rotation().z += 1;
}
}
-------------------------------------------------------------------------------------------------------------------
***take note here the resource must be the same as you have declared mine one is "
--------------------------------------------------------------------------------------------------------------------***take note here the resource must be the same as you have declared mine one is "
com.example.min3dtest:raw/face_obj
IParser myParser = Parser.createParser(Parser.Type.OBJ, getResources(), "com.example.min3dtest:raw/face_obj",true);
Step five
Res folder
Under res folder create a folder name raw..
Insert the obj and mtl file inside that folder
It should be like this
Under res folder create a folder name drawable
Insert all the model texture into it like
picture below notice all names in lowercase
Step 6
Edit face_mtl and face_obj
Edit the face_mtl into this. Notice the differences before
this it has tabulation and spaces between lines.. this will not let our object
to have textures..
ensure that the map_Kd face_eyel_hi.jpg above the Kd 0.7 0.7 0.7 repeat the same thing for other .jpg. please refer below.
ensure that the map_Kd face_eyel_hi.jpg above the Kd 0.7 0.7 0.7 repeat the same thing for other .jpg. please refer below.
newmtl Texture0
Ns 20
d 1
illum 2
map_Kd face_eyel_hi.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
newmtl Texture1
Ns 20
d 1
illum 2
map_Kd face_eyer_hi.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
newmtl Texture2
Ns 20
d 1
illum 2
map_Kd face_skin_hi.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
newmtl Texture3
Ns 20
d 1
illum 2
map_Kd face_sock.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
IN face_obj
eyeL_hi to eyel_hi
and
ayeR_hi to eyer_hi
Step 7
Edit AndroidManifest.xml
Add this activity into your androidManifest.xml
<activity
android:name=".Obj3DView"
android:label="@string/app_name">
</activity>
Step 8
Run it!
Save all, build project and run apps. I tried on my real
device never try on emulator.. another this because rendering is a bit slow..
please unplug your usb cable after you have run the app.. you will see the 3d
object rotating…like this… well
Done!
Thanks a lot,,, very helpful but my object don't have textures!
ReplyDeletehi Shima glad that this post help you. suppose you ll have ur texture if you really follow the steps.
Deletekindly check on step 6 :)
Deleteyes it was because of step 6... I was replaced your lines in my mtl file and it didn't work but when I deleted spaces by my self from it solve!
Deletethanks :)
Do you know How can I set this object to my live wallpaper? is it possible?
ReplyDeletehi shima, it would be great if you can try to check out this svn code. and try it out first.
Deletehttp://min3d-live-wallpaper-fork.googlecode.com/svn/trunk/
hi, I have some issue with my code.
ReplyDeleteI tried to follow exactly what you taught but i have some errors.
my logcat says:
05-06 01:08:33.682: E/AndroidRuntime(24397): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.min3dtest/com.example.min3dtest.Obj3DView}: java.lang.ClassNotFoundException: com.example.min3dtest.Obj3DView in loader dalvik.system.PathClassLoader[/data/app/com.example.min3dtest-2.apk]
and other related errors.
My file structure is exactly same but i still get errors. my apk crashes. i follwed each and every instruction. Kindly help please.
http://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo
DeleteCan you try this solution?
please re-check on step 7
DeleteThis comment has been removed by the author.
ReplyDeleteThanks for the tutorial, helped me a lot.
ReplyDeleteBut I still have a problem, I've succeed to display the face you take as example, but I'm completly unable to make it work with my own .obj (convert from a .blend). I got a black screen. I've tried to modify the Scale and the position, but I can't find a way to make it work.
Do you have any idea of what could be the problem ?
Thanks for the compliment. actually vaalac this tutorial quite old i ve no longer working on android development.
Deleteother than this min3d api i also did try on http://www.hitlabnz.org/index.php/research/augmented-reality
hitlab api
and i did encountered problem when i try to use my own object. It seems like the conversion have some issues.
to solve my issue, i used a 3d object with .obj format and import to blender. and do conversion again to .obj with including the edges, normal, uvs, triangulate faces, write materials, objects as OBJ objects and material groups.
haha at that time i dont know the root cause of it. but i realized that the format .obj file is matter. else the rendering will not happen correctly.
i hope you can solve your problem as well, and kindly do share with us your solution.
Thanks for your quick answer ! I can't do the same trick than you, I'm not free to display the object I want, and they're all initialy .blend.
DeleteI'll keep testing and trying to see why it works with some object and not some others. I'll come back to share my solution if I find one :).
This comment has been removed by the author.
ReplyDeleteThat was a clean and clear tutorial dude. Is it possible to touch and rotate the 3d and selection of the ear/eye? If so, please guide me...
ReplyDeleteim not sure whether the rotation can be based on ear or eye, as the face is imported as whole object.
DeleteThis is my Logcat, i have followed all steps as mentioned but cant still figure out why these errors are coming.
ReplyDelete07-16 08:49:36.143: E/AndroidRuntime(9990): FATAL EXCEPTION: GLThread 9463
07-16 08:49:36.143: E/AndroidRuntime(9990): Process: com.example.min3dtest.java, PID: 9990
07-16 08:49:36.143: E/AndroidRuntime(9990): android.content.res.Resources$NotFoundException: Resource ID #0x0
07-16 08:49:36.143: E/AndroidRuntime(9990): at android.content.res.Resources.getValue(Resources.java:1310)
07-16 08:49:36.143: E/AndroidRuntime(9990): at android.content.res.Resources.getValue(Resources.java:1290)
07-16 08:49:36.143: E/AndroidRuntime(9990): at android.content.res.Resources.openRawResource(Resources.java:1209)
07-16 08:49:36.143: E/AndroidRuntime(9990): at android.content.res.Resources.openRawResource(Resources.java:1186)
07-16 08:49:36.143: E/AndroidRuntime(9990): at min3d.parser.ObjParser.parse(ObjParser.java:59)
07-16 08:49:36.143: E/AndroidRuntime(9990): at com.example.min3dtest.Obj3DView.initScene(Obj3DView.java:21)
07-16 08:49:36.143: E/AndroidRuntime(9990): at min3d.core.Scene.init(Scene.java:254)
07-16 08:49:36.143: E/AndroidRuntime(9990): at min3d.core.Renderer.onSurfaceCreated(Renderer.java:75)
07-16 08:49:36.143: E/AndroidRuntime(9990): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1500)
07-16 08:49:36.143: E/AndroidRuntime(9990): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
My project name is Min3dTest, package name is com.example.min3dtest
this is the parser line ....
IParser myParser = Parser.createParser(Parser.Type.OBJ, getResources(), "com.example.min3dtest:raw/face_obj",true);
im not sure what caused that error, have you checked on step 6?
DeleteStep 6
Edit face_mtl and face_obj
Edit the face_mtl into this. Notice the differences before this it has tabulation and spaces between lines.. this will not let our object to have textures..
I have to import it in android studio. Can you please help me out with that?
ReplyDeleteHi Arpita Tripathi, may i know first the error you encounter in importing the solution to Android Studio? if you checkout the code from SVN http://min3d.googlecode.com/svn/trunk into your new android studio project, is there any error?
DeleteYes. Whenever I import the project, gradle shows an error that gradle sync failed
ReplyDeleteit also shows cannot resolve "min3d" symbol
ReplyDeleteThe project solution from svn is an Eclipse project, if you want to run the sample project, you need to migrate your project solution to use Gradle based/ Android studio.
DeleteWell to run above tutorial .. you dont need to migrate.
What you need to do is .. create a new project in Android studio, and then create a new package name min3d, inside that package, you copy over all the files from (http://mind3d.googlecode.com>svn>trunk>src>min3d)min3d folder that you have checkout from svn. you can already make use of min3d framework.
Okay. Thank you. I'll try this and let you know if it will work.
ReplyDeleteAfter you have done with step 3 (copy paste file over new project) please continue to next steps. good luck and let me know if you encounter issue.
DeleteHey, still its not working.
DeleteI am getting these errors.
10-15 23:09:20.643 3814-3829/com.epulse.min3dmodel E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 160
Process: com.epulse.min3dmodel, PID: 3814
java.lang.IllegalArgumentException: No config chosen
at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:870)
at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
10-15 23:09:20.786 3814-3828/com.epulse.min3dmodel E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabea5a80
10-15 23:09:20.835 3814-3828/com.epulse.min3dmodel E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabea5b60
Can you please help me out with this?
Delete????????
DeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
Deletei had the same error when i use bigger resolution emulator.
Deletei updated above post with my avd settings.
on you emulator setting on emulated performance section please uncheck the host gpu.
DeleteOh okay. Thanks. I hope it will work.
ReplyDeleteHey it works.
ReplyDeleteWhat if I have to import some other obj file?
I have exported it from clara.io and it only contains obj file and mtl file.
https://clara.io/editor/ae8456df-de5b-428d-b91b-4c3e4776485d
This is the link to that file
i guess you have tried it by now. currently im busy with working. get back to you on weekend.
DeleteYes I have tried it but its not running.
DeleteSo please can you help me with this?
This comment has been removed by the author.
ReplyDeleteThanks for the tutorial. I could import the whole min3d-master into Android Studio but I wanted to make a new project in AS from scratch. So I tried your tutorial. I am not sure about Eclipse but in AS you have to add the second activity (here Obj3DView) into AndroidManifest.xml manually. Otherwise the app will crash right in the beginning. I am going to make a tutorial for creating a min3d project in Android Studio from scratch and post it later. For now this may save some time for somebody else who encountered similar problem.
ReplyDeletei did a post on AS as well .. http://ubuntuanakramli.blogspot.my/2015/10/tutorial-on-min3d-framework-using.html
Deleteis it similar with what you plan to do?
Hi I am getting resource not found exception , I followed this tutorial properly, is there anything I did wrong?
ReplyDeletebelow is the Log
04-04 02:03:08.331 8249-8638/com.example.abhi.min3dtutorial E/AndroidRuntime: FATAL EXCEPTION: GLThread 10396
Process: com.example.abhi.min3dtutorial, PID: 8249
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:2558)
at android.content.res.Resources.openRawResource(Resources.java:2472)
at android.content.res.Resources.openRawResource(Resources.java:2448)
Can screenshot your resource/res folder?
DeletePlease see the screen shot below in the link
Deletehttps://ibb.co/n6zxLa
can you check the package is defined properly in the class Object3DView class
Deletechange com.example.min3dtest:raw
to your package. with the right file name?
This comment has been removed by the author.
ReplyDelete