1
votes

Blender >> .obj, .mtl >> Java using min3D, openGL ES >> Android device

What am I doing wrong or what is wrong with these .mtl or .obj files that would make get a parser error in min3d?

So far I have only replaced period in "mtllib face.mtl" with an underscore "mtllib face_mtl"

Nothing is tabulated or spaced. If it looks weird it is because of my mistake in the submission of this question.

So far all the examples from "MatD's tutorials" have worked fine. Only when I try to load my own files, I run into problems.

I have looked over both files line by line while checking the Wiki page for Wavefront obj files, and no luck there.

I have a feeling that this may be related to a texture problem in the .mtl or the whole export. I do not have any images or any other files that were exported with Blender.

Thank you very much, I hope this is all legible.

ERROR: Occurs where I commented in code below

05-11 16:06:01.371: E/AndroidRuntime(2280): FATAL EXCEPTION: GLThread 9

05-11 16:06:01.371: E/AndroidRuntime(2280): java.lang.NullPointerException

05-11 16:06:01.371: E/AndroidRuntime(2280): at min3d.parser.ObjParser.readMaterialLib(ObjParser.java:197)

05-11 16:06:01.371: E/AndroidRuntime(2280): at min3d.parser.ObjParser.parse(ObjParser.java:107)

05-11 16:06:01.371: E/AndroidRuntime(2280): at nbg.min3d.test.Obj3DView.initScene(Obj3DView.java:24)

05-11 16:06:01.371: E/AndroidRuntime(2280): at min3d.core.Scene.init(Scene.java:254)

05-11 16:06:01.371: E/AndroidRuntime(2280): at min3d.core.Renderer.onSurfaceCreated(Renderer.java:75)

05-11 16:06:01.371: E/AndroidRuntime(2280): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1317)

05-11 16:06:01.371: E/AndroidRuntime(2280): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

Here is where the errors occurred:

private void readMaterialLib(String libID) {
    StringBuffer resourceID = new StringBuffer(packageID);
    StringBuffer libIDSbuf = new StringBuffer(libID);
    int dotIndex = libIDSbuf.lastIndexOf(".");
    if (dotIndex > -1)
        libIDSbuf = libIDSbuf.replace(dotIndex, dotIndex + 1, "_");

    resourceID.append(":raw/");
    resourceID.append(libIDSbuf.toString());

    InputStream fileIn = resources.openRawResource(resources.getIdentifier(
            resourceID.toString(), null, null));
    BufferedReader buffer = new BufferedReader(
            new InputStreamReader(fileIn));
    String line;
    String currentMaterial = "";

    try {
        while ((line = buffer.readLine()) != null) {
            String[] parts = line.split(" ");
            if (parts.length == 0)
                continue;
            String type = parts[0];

            if (type.equals(NEW_MATERIAL)) {
                if (parts.length > 1) {
                    currentMaterial = parts[1];
                    materialMap.put(currentMaterial, new Material(
                            currentMaterial));
                }
            } else if(type.equals(DIFFUSE_COLOR) && !type.equals(DIFFUSE_TEX_MAP)) {
                Color4 diffuseColor = new Color4(Float.parseFloat(parts[1]) * 255.0f, Float.parseFloat(parts[2]) * 255.0f, Float.parseFloat(parts[3]) * 255.0f, 255.0f);


**//Below is where the error happens.. aka (ObjParser.java: 197)**


                materialMap.get(currentMaterial).diffuseColor = diffuseColor;
            } else if (type.equals(DIFFUSE_TEX_MAP)) {
                if (parts.length > 1) {
                    materialMap.get(currentMaterial).diffuseTextureMap = parts[1];
                    StringBuffer texture = new StringBuffer(packageID);
                    texture.append(":drawable/");

                    StringBuffer textureName = new StringBuffer(parts[1]);
                    dotIndex = textureName.lastIndexOf(".");
                    if (dotIndex > -1)
                        texture.append(textureName.substring(0, dotIndex));
                    else
                        texture.append(textureName);

                    int bmResourceID = resources.getIdentifier(texture
                            .toString(), null, null);
                    Bitmap b = Utils.makeBitmapFromResourceId(bmResourceID);
                    textureAtlas.addBitmapAsset(new BitmapAsset(currentMaterial, texture.toString()));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

.obj file:

# Blender v2.62 (sub 0) OBJ File: 'cylxyzaxis.blend'
# www.blender.org
mtllib face_mtl
o Cylinder.002
v 0.003384 0.016776 -1.001130
v 0.004515 0.016664 -1.001130
v 0.005603 0.016334 -1.001130
v 0.006606 0.015798 -1.001130
v 0.007485 0.015077 -1.001130
v 0.008206 0.014198 -1.001130
v 0.008742 0.013195 -1.001130
v 0.009072 0.012107 -1.001130
v 0.009184 0.010976 -1.001130
v 0.009072 0.009844 -1.001130
v 0.008742 0.008756 -1.001130
v 0.008206 0.007753 -1.001130
v 0.007485 0.006874 -1.001130
v 0.006606 0.006153 -1.001130
v 0.005603 0.005617 -1.001130
v 0.004515 0.005287 -1.001130
v 0.003384 0.005176 -1.001130
v 0.002252 0.005287 -1.001130
v 0.001164 0.005617 -1.001130
v 0.000161 0.006153 -1.001130
v -0.000717 0.006874 -1.001130
v -0.001439 0.007753 -1.001130
v -0.001975 0.008756 -1.001130
v -0.002305 0.009844 -1.001130
v -0.002416 0.010976 -1.001130
v -0.002305 0.012107 -1.001130
v -0.001975 0.013195 -1.001130
v -0.001439 0.014198 -1.001130
v -0.000717 0.015077 -1.001130
v 0.000161 0.015798 -1.001130
v 0.001164 0.016334 -1.001130
v 0.002252 0.016664 -1.001130
v 0.003384 0.016774 0.998870
v 0.004515 0.016663 0.998870
v 0.005603 0.016333 0.998870
v 0.006606 0.015797 0.998870
v 0.007485 0.015076 0.998870
v 0.008206 0.014197 0.998870
v 0.008742 0.013194 0.998870
v 0.009072 0.012106 0.998870
v 0.009184 0.010974 0.998870
v 0.009072 0.009843 0.998870
v 0.008742 0.008755 0.998870
v 0.008206 0.007752 0.998870
v 0.007485 0.006873 0.998870
v 0.006606 0.006152 0.998870
v 0.005603 0.005616 0.998870
v 0.004515 0.005286 0.998870
v 0.003384 0.005174 0.998870
v 0.002252 0.005286 0.998870
v 0.001164 0.005616 0.998870
v 0.000161 0.006152 0.998870
v -0.000717 0.006873 0.998870
v -0.001439 0.007752 0.998870
v -0.001975 0.008755 0.998870
v -0.002305 0.009843 0.998870
v -0.002416 0.010974 0.998870
v -0.002305 0.012106 0.998870
v -0.001975 0.013194 0.998870
v -0.001439 0.014197 0.998870
v -0.000718 0.015075 0.998870
v 0.000161 0.015797 0.998870
v 0.001164 0.016333 0.998870
v 0.002252 0.016663 0.998870
v 0.003384 0.010976 -1.001130
v 0.003384 0.010974 0.998870
usemtl 
s off
f 65 1 2
f 66 34 33
f 65 2 3
f 66 35 34
f 65 3 4
f 66 36 35
f 65 4 5
f 66 37 36
f 65 5 6
f 66 38 37
f 65 6 7
f 66 39 38
f 65 7 8
f 66 40 39
f 65 8 9
f 66 41 40
f 65 9 10
f 66 42 41
f 65 10 11
f 66 43 42
f 65 11 12
f 66 44 43
f 65 12 13
f 66 45 44
f 65 13 14
f 66 46 45
f 65 14 15
f 66 47 46
f 65 15 16
f 66 48 47
f 65 16 17
f 66 49 48
f 65 17 18
f 66 50 49
f 65 18 19
f 66 51 50
f 65 19 20
f 66 52 51
f 65 20 21
f 66 53 52
f 65 21 22
f 66 54 53
f 65 22 23
f 66 55 54
f 65 23 24
f 66 56 55
f 65 24 25
f 66 57 56
f 65 25 26
f 66 58 57
f 65 26 27
f 66 59 58
f 65 27 28
f 66 60 59
f 65 28 29
f 66 61 60
f 65 29 30
f 66 62 61
f 65 30 31
f 66 63 62
f 65 31 32
f 66 64 63
f 32 1 65
f 66 33 64
f 1 33 34 2
f 2 34 35 3
f 3 35 36 4
f 4 36 37 5
f 5 37 38 6
f 6 38 39 7
f 7 39 40 8
f 8 40 41 9
f 9 41 42 10
f 10 42 43 11
f 11 43 44 12
f 12 44 45 13
f 13 45 46 14
f 14 46 47 15
f 15 47 48 16
f 16 48 49 17
f 17 49 50 18
f 18 50 51 19
f 19 51 52 20
f 20 52 53 21
f 21 53 54 22
f 22 54 55 23
f 23 55 56 24
f 24 56 57 25
f 25 57 58 26
f 26 58 59 27
f 27 59 60 28
f 28 60 61 29
f 29 61 62 30
f 30 62 63 31
f 31 63 64 32
f 33 1 32 64
o Cylinder.001
v -0.996616 0.010976 -0.006930
v -0.996616 0.009844 -0.006819
v -0.996616 0.008756 -0.006489
v -0.996616 0.007753 -0.005953
v -0.996616 0.006874 -0.005231
v -0.996616 0.006153 -0.004353
v -0.996616 0.005617 -0.003350
v -0.996616 0.005287 -0.002262
v -0.996616 0.005176 -0.001130
v -0.996616 0.005287 0.000001
v -0.996616 0.005617 0.001089
v -0.996616 0.006153 0.002092
v -0.996616 0.006874 0.002971
v -0.996616 0.007753 0.003692
v -0.996616 0.008756 0.004228
v -0.996616 0.009844 0.004558
v -0.996616 0.010976 0.004670
v -0.996616 0.012107 0.004558
v -0.996616 0.013195 0.004228
v -0.996616 0.014198 0.003692
v -0.996616 0.015077 0.002971
v -0.996616 0.015798 0.002092
v -0.996616 0.016334 0.001089
v -0.996616 0.016664 0.000001
v -0.996616 0.016776 -0.001130
v -0.996616 0.016664 -0.002262
v -0.996616 0.016334 -0.003350
v -0.996616 0.015798 -0.004353
v -0.996616 0.015077 -0.005231
v -0.996616 0.014198 -0.005953
v -0.996616 0.013195 -0.006489
v -0.996616 0.012107 -0.006819
v 1.003384 0.010974 -0.006930
v 1.003384 0.009843 -0.006819
v 1.003384 0.008755 -0.006489
v 1.003384 0.007752 -0.005953
v 1.003384 0.006873 -0.005231
v 1.003384 0.006152 -0.004353
v 1.003384 0.005616 -0.003350
v 1.003384 0.005286 -0.002262
v 1.003384 0.005174 -0.001130
v 1.003384 0.005286 0.000001
v 1.003384 0.005616 0.001089
v 1.003384 0.006152 0.002092
v 1.003384 0.006873 0.002971
v 1.003384 0.007752 0.003692
v 1.003384 0.008755 0.004228
v 1.003384 0.009843 0.004558
v 1.003384 0.010974 0.004670
v 1.003384 0.012106 0.004558
v 1.003384 0.013194 0.004228
v 1.003384 0.014197 0.003692
v 1.003384 0.015076 0.002971
v 1.003384 0.015797 0.002092
v 1.003384 0.016333 0.001089
v 1.003384 0.016663 0.000001
v 1.003384 0.016774 -0.001130
v 1.003384 0.016663 -0.002262
v 1.003384 0.016333 -0.003350
v 1.003384 0.015797 -0.004352
v 1.003384 0.015076 -0.005231
v 1.003384 0.014197 -0.005953
v 1.003384 0.013194 -0.006489
v 1.003384 0.012106 -0.006819
v -0.996616 0.010976 -0.001130
v 1.003384 0.010974 -0.001130
usemtl 
s off
f 131 67 68
f 132 100 99
f 131 68 69
f 132 101 100
f 131 69 70
f 132 102 101
f 131 70 71
f 132 103 102
f 131 71 72
f 132 104 103
f 131 72 73
f 132 105 104
f 131 73 74
f 132 106 105
f 131 74 75
f 132 107 106
f 131 75 76
f 132 108 107
f 131 76 77
f 132 109 108
f 131 77 78
f 132 110 109
f 131 78 79
f 132 111 110
f 131 79 80
f 132 112 111
f 131 80 81
f 132 113 112
f 131 81 82
f 132 114 113
f 131 82 83
f 132 115 114
f 131 83 84
f 132 116 115
f 131 84 85
f 132 117 116
f 131 85 86
f 132 118 117
f 131 86 87
f 132 119 118
f 131 87 88
f 132 120 119
f 131 88 89
f 132 121 120
f 131 89 90
f 132 122 121
f 131 90 91
f 132 123 122
f 131 91 92
f 132 124 123
f 131 92 93
f 132 125 124
f 131 93 94
f 132 126 125
f 131 94 95
f 132 127 126
f 131 95 96
f 132 128 127
f 131 96 97
f 132 129 128
f 131 97 98
f 132 130 129
f 98 67 131
f 132 99 130
f 67 99 100 68
f 68 100 101 69
f 69 101 102 70
f 70 102 103 71
f 71 103 104 72
f 72 104 105 73
f 73 105 106 74
f 74 106 107 75
f 75 107 108 76
f 76 108 109 77
f 77 109 110 78
f 78 110 111 79
f 79 111 112 80
f 80 112 113 81
f 81 113 114 82
f 82 114 115 83
f 83 115 116 84
f 84 116 117 85
f 85 117 118 86
f 86 118 119 87
f 87 119 120 88
f 88 120 121 89
f 89 121 122 90
f 90 122 123 91
f 91 123 124 92
f 92 124 125 93
f 93 125 126 94
f 94 126 127 95
f 95 127 128 96
f 96 128 129 97
f 97 129 130 98
f 99 67 98 130
o Cylinder
v 0.000000 -1.000000 -0.005800
v 0.001132 -1.000000 -0.005689
v 0.002220 -1.000000 -0.005358
v 0.003222 -1.000000 -0.004822
v 0.004101 -1.000000 -0.004101
v 0.004822 -1.000000 -0.003222
v 0.005358 -1.000000 -0.002220
v 0.005689 -1.000000 -0.001132
v 0.005800 -1.000000 -0.000000
v 0.005689 -1.000000 0.001132
v 0.005358 -1.000000 0.002220
v 0.004822 -1.000000 0.003222
v 0.004101 -1.000000 0.004101
v 0.003222 -1.000000 0.004822
v 0.002220 -1.000000 0.005358
v 0.001132 -1.000000 0.005689
v -0.000000 -1.000000 0.005800
v -0.001132 -1.000000 0.005689
v -0.002220 -1.000000 0.005358
v -0.003222 -1.000000 0.004822
v -0.004101 -1.000000 0.004101
v -0.004822 -1.000000 0.003222
v -0.005358 -1.000000 0.002220
v -0.005689 -1.000000 0.001132
v -0.005800 -1.000000 -0.000000
v -0.005689 -1.000000 -0.001132
v -0.005358 -1.000000 -0.002220
v -0.004822 -1.000000 -0.003222
v -0.004101 -1.000000 -0.004101
v -0.003222 -1.000000 -0.004822
v -0.002220 -1.000000 -0.005358
v -0.001132 -1.000000 -0.005689
v 0.000000 1.000000 -0.005800
v 0.001132 1.000000 -0.005689
v 0.002220 1.000000 -0.005358
v 0.003222 1.000000 -0.004822
v 0.004101 1.000000 -0.004101
v 0.004822 1.000000 -0.003222
v 0.005358 1.000000 -0.002220
v 0.005689 1.000000 -0.001132
v 0.005800 1.000000 0.000000
v 0.005689 1.000000 0.001132
v 0.005358 1.000000 0.002220
v 0.004822 1.000000 0.003222
v 0.004101 1.000000 0.004101
v 0.003222 1.000000 0.004822
v 0.002220 1.000000 0.005358
v 0.001132 1.000000 0.005689
v 0.000000 1.000000 0.005800
v -0.001132 1.000000 0.005689
v -0.002220 1.000000 0.005358
v -0.003222 1.000000 0.004822
v -0.004101 1.000000 0.004101
v -0.004822 1.000000 0.003222
v -0.005358 1.000000 0.002220
v -0.005688 1.000000 0.001132
v -0.005800 1.000000 0.000000
v -0.005689 1.000000 -0.001131
v -0.005358 1.000000 -0.002220
v -0.004822 1.000000 -0.003222
v -0.004101 1.000000 -0.004101
v -0.003222 1.000000 -0.004822
v -0.002220 1.000000 -0.005358
v -0.001132 1.000000 -0.005688
v 0.000000 -1.000000 0.000000
v 0.000000 1.000000 0.000000
usemtl 
s off
f 197 133 134
f 198 166 165
f 197 134 135
f 198 167 166
f 197 135 136
f 198 168 167
f 197 136 137
f 198 169 168
f 197 137 138
f 198 170 169
f 197 138 139
f 198 171 170
f 197 139 140
f 198 172 171
f 197 140 141
f 198 173 172
f 197 141 142
f 198 174 173
f 197 142 143
f 198 175 174
f 197 143 144
f 198 176 175
f 197 144 145
f 198 177 176
f 197 145 146
f 198 178 177
f 197 146 147
f 198 179 178
f 197 147 148
f 198 180 179
f 197 148 149
f 198 181 180
f 197 149 150
f 198 182 181
f 197 150 151
f 198 183 182
f 197 151 152
f 198 184 183
f 197 152 153
f 198 185 184
f 197 153 154
f 198 186 185
f 197 154 155
f 198 187 186
f 197 155 156
f 198 188 187
f 197 156 157
f 198 189 188
f 197 157 158
f 198 190 189
f 197 158 159
f 198 191 190
f 197 159 160
f 198 192 191
f 197 160 161
f 198 193 192
f 197 161 162
f 198 194 193
f 197 162 163
f 198 195 194
f 197 163 164
f 198 196 195
f 164 133 197
f 198 165 196
f 133 165 166 134
f 134 166 167 135
f 135 167 168 136
f 136 168 169 137
f 137 169 170 138
f 138 170 171 139
f 139 171 172 140
f 140 172 173 141
f 141 173 174 142
f 142 174 175 143
f 143 175 176 144
f 144 176 177 145
f 145 177 178 146
f 146 178 179 147
f 147 179 180 148
f 148 180 181 149
f 149 181 182 150
f 150 182 183 151
f 151 183 184 152
f 152 184 185 153
f 153 185 186 154
f 154 186 187 155
f 155 187 188 156
f 156 188 189 157
f 157 189 190 158
f 158 190 191 159
f 159 191 192 160
f 160 192 193 161
f 161 193 194 162
f 162 194 195 163
f 163 195 196 164
f 165 133 164 196

.mtl file:

# Blender MTL File: 'cylxyzaxis.blend'
# Material Count: 1
newmtl
Ns 1.00000
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
1
Can you use your debugger to inspect that line? The error means that either materialMap is null, or materialMap.get() is returning null.Tim
The currentMaterial is returning "" and the currentMaterialKey is returning null. So when the key is hashed it causes a NullPointerException in a almost infinite iteration.I have no idea what this means though. Below is debug error...CommonKnowledge
this NullPointerException (id=830076966232) cause NullPointerException (id=830076966232) detailMessage null stackState (id=830076967384) stackTrace nullCommonKnowledge

1 Answers

2
votes

I'm not an expert with .obj, but I think that usemtl should maybe specify a material name? Something like usemtl some_material.

That would seem consistent with your 'current material is null' error.

Should probably give the material a name in the mtl file as well:

newmtl some_material