Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing .obj model from SD card Rajawali

I am Working with Rajawali 3D Framework and trying to Load .obj files from SDcard. I am able to upload and parse the obj file when I put these files (.obj, .mtl, texture.png (drawable folder)) on raw folder but when I try to parse it from sdcard it says:

 [org.rajawali3d.materials.Material] Could not compile fragmentshader:
 Shader log: Fragment shader compilation failed.

Here is my code for uploading .obj files from Sdcard:

private Object3D Object;
LoaderOBJ objParser = new LoaderOBJ(this,"Load/1c_obj");

            try {

                objParser.parse();
                Object = objParser.getParsedObject();
                getCurrentScene().addChild(Object);

            } catch (ParsingException e) {
                e.printStackTrace();
            }

Logcat:

 D/Rajawali﹕ Parsing: /storage/emulated/0/Load/1c_obj
 D/LoaderOBJ﹕ Found Material Lib: 1c_mtl
 D/LoaderOBJ$MaterialLib﹕ Parsing material: Texture0
 D/LoaderOBJ$MaterialLib﹕ Parsing material: Texture1
          
    9578-9612/com.example.loadobj D/LoadModelFragment$LoadModelRenderer﹕ startRendering()
    E/Rajawali﹕ [org.rajawali3d.materials.Material] Could not compile fragment shader:
    9578-9612/com.example.loadobj E/Rajawali﹕ Shader log: Fragment shader compilation failed.
    ERROR: 0:13: '.' : Syntax error:  syntax error
    ERROR: 1 compilation errors.  No code generated.
like image 402
Sanjh Avatar asked Jun 15 '15 06:06

Sanjh


1 Answers

If your are able to read obj files from your raw folder which is

LoaderOBJ objParser = new LoaderOBJ(mContext.getResources(),mTextureManager, R.raw.camero_obj);

and not from your sdcard you have to do following changes in your files: In your obj file that must be saved as _obj in your sdcard (so for _jpg and _mtl in same location)

in your case:

mtllib 1c_mtl

v -0.7526 14.5146 0.171602
v -0.7922 14.5792 0.075402
v -0.4998 14.7082 0.457802
v -0.5409 14.7486 0.393002
v -0.5358 14.5862 0.414902

Following by mtl file

newmtl Texture0
    illum 0
    Kd 0.7 0.7 0.7
    Ks 0 0 0
    Ka 0 0 0
newmtl Texture1
    illum 0
    Kd 0.7 0.7 0.7
    Ks 0 0 0
    Ka 0 0 0
    map_Kd parse_jpg

Remember to rename your texture jpg to _jpg Where you are getting Error:

ERROR: 0:13: '.' : Syntax error: syntax error

After this follow your code for parsing:

private Object3D Object;
LoaderOBJ objParser = new LoaderOBJ(this,"Load/1c_obj");

            try {

                objParser.parse();
                Object = objParser.getParsedObject();
                getCurrentScene().addChild(Object);

            } catch (ParsingException e) {
                e.printStackTrace();
            }

And The Error you are getting

E/Rajawali﹕ [org.rajawali3d.materials.Material] Could not compile fragment shader:

Its unable to read your texture file from your material file, For that you can do the above changes in your material file.

For more details on custom material or vertex shader follow the Rajawail Document and sample

like image 117
S J Avatar answered Nov 12 '22 12:11

S J