Skip to main content

Tutorial on min3d framework



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
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 "
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.

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!



additional ** avd setting to run project in android emulator.








Comments

  1. Thanks a lot,,, very helpful but my object don't have textures!

    ReplyDelete
    Replies
    1. hi Shima glad that this post help you. suppose you ll have ur texture if you really follow the steps.

      Delete
    2. kindly check on step 6 :)

      Delete
    3. yes 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!
      thanks :)

      Delete
  2. Do you know How can I set this object to my live wallpaper? is it possible?

    ReplyDelete
    Replies
    1. hi shima, it would be great if you can try to check out this svn code. and try it out first.

      http://min3d-live-wallpaper-fork.googlecode.com/svn/trunk/

      Delete
  3. hi, I have some issue with my code.
    I 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.

    ReplyDelete
    Replies
    1. http://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo

      Can you try this solution?

      Delete
    2. please re-check on step 7

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Thanks for the tutorial, helped me a lot.
    But 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 ?

    ReplyDelete
    Replies
    1. Thanks for the compliment. actually vaalac this tutorial quite old i ve no longer working on android development.

      other 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.

      Delete
    2. 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.
      I'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 :).

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. That 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...

    ReplyDelete
    Replies
    1. im not sure whether the rotation can be based on ear or eye, as the face is imported as whole object.

      Delete
  8. This is my Logcat, i have followed all steps as mentioned but cant still figure out why these errors are coming.

    07-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);

    ReplyDelete
    Replies
    1. im not sure what caused that error, have you checked on step 6?

      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..

      Delete
  9. I have to import it in android studio. Can you please help me out with that?

    ReplyDelete
    Replies
    1. Hi 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?

      Delete
  10. Yes. Whenever I import the project, gradle shows an error that gradle sync failed

    ReplyDelete
  11. it also shows cannot resolve "min3d" symbol

    ReplyDelete
    Replies
    1. The 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.

      Well 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.

      Delete
  12. Okay. Thank you. I'll try this and let you know if it will work.

    ReplyDelete
    Replies
    1. After 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.

      Delete
    2. Hey, still its not working.
      I 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

      Delete
    3. Can you please help me out with this?

      Delete
    4. This comment has been removed by the author.

      Delete
    5. This comment has been removed by the author.

      Delete
    6. i had the same error when i use bigger resolution emulator.

      i updated above post with my avd settings.

      Delete
    7. on you emulator setting on emulated performance section please uncheck the host gpu.

      Delete
  13. Oh okay. Thanks. I hope it will work.

    ReplyDelete
  14. Hey it works.
    What 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

    ReplyDelete
    Replies
    1. i guess you have tried it by now. currently im busy with working. get back to you on weekend.

      Delete
    2. Yes I have tried it but its not running.
      So please can you help me with this?

      Delete
  15. Thanks 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.

    ReplyDelete
    Replies
    1. i did a post on AS as well .. http://ubuntuanakramli.blogspot.my/2015/10/tutorial-on-min3d-framework-using.html
      is it similar with what you plan to do?

      Delete
  16. Hi I am getting resource not found exception , I followed this tutorial properly, is there anything I did wrong?
    below 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)

    ReplyDelete
    Replies
    1. Can screenshot your resource/res folder?

      Delete
    2. Please see the screen shot below in the link

      https://ibb.co/n6zxLa

      Delete
    3. can you check the package is defined properly in the class Object3DView class

      change com.example.min3dtest:raw
      to your package. with the right file name?

      Delete
  17. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

Tutorial on Min3D framework using Android Studio

Salam peeps, UPDATES***, the model on the old link is no longer working. so i have create a github repo, where i put the source code in a project, you guys can try to clone in and run on your android studio device emulator or directly on your phone, Ive replaced the model with a cube. https://github.com/aliaramli/Min3DTutorial Previously i ve posted tutorial on min3D using eclipse IDE, i believe most of us has moved to Android Studio IDE in developing android apps? As previous tutorial shows a lot of support from readers and among hot post in my blog, i ve decided to post the same tutorial but this time using Android Studio. For those who are familiar with Eclipse/Android Studio migration they might not have problem in running this tutorial . For more detail explanation on min3D please visit this website page Ok lets get started. Step One Create a new android project in android studio. you may name it as what you like, below are how i defined my project settings.

Get the last active time from users in woocommerce using sql query

To easily get the last active time from users (under Woocommerce extended plugin) we can easily query from database using the meta_key of "wc_last_active" example query: select user_id, meta_value from wp_usermeta where meta_key= "wc_last_active" and user_id in (11111,112222); results: +-------------+------------------+ | user_id    | meta_value | +-------------+-------------------+ |   11111   | 1556755200 | |   112222 | 1566518400 |