(PApplet parent, String path,
BufferedReader reader,
ArrayList<OBJFace> faces,
ArrayList<OBJMaterial> materials,
ArrayList<PVector> coords,
ArrayList<PVector> normals,
ArrayList<PVector> texcoords)
| 151 | |
| 152 | |
| 153 | static protected void parseOBJ(PApplet parent, String path, |
| 154 | BufferedReader reader, |
| 155 | ArrayList<OBJFace> faces, |
| 156 | ArrayList<OBJMaterial> materials, |
| 157 | ArrayList<PVector> coords, |
| 158 | ArrayList<PVector> normals, |
| 159 | ArrayList<PVector> texcoords) { |
| 160 | Map<String, Integer> mtlTable = new HashMap<String, Integer>(); |
| 161 | int mtlIdxCur = -1; |
| 162 | boolean readv, readvn, readvt; |
| 163 | try { |
| 164 | |
| 165 | readv = readvn = readvt = false; |
| 166 | String line; |
| 167 | String gname = "object"; |
| 168 | while ((line = reader.readLine()) != null) { |
| 169 | // Parse the line. |
| 170 | line = line.trim(); |
| 171 | if (line.equals("") || line.indexOf('#') == 0) { |
| 172 | // Empty line of comment, ignore line |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | // The below patch/hack comes from Carlos Tomas Marti and is a |
| 177 | // fix for single backslashes in Rhino obj files |
| 178 | |
| 179 | // BEGINNING OF RHINO OBJ FILES HACK |
| 180 | // Statements can be broken in multiple lines using '\' at the |
| 181 | // end of a line. |
| 182 | // In regular expressions, the backslash is also an escape |
| 183 | // character. |
| 184 | // The regular expression \\ matches a single backslash. This |
| 185 | // regular expression as a Java string, becomes "\\\\". |
| 186 | // That's right: 4 backslashes to match a single one. |
| 187 | while (line.contains("\\")) { |
| 188 | line = line.split("\\\\")[0]; |
| 189 | final String s = reader.readLine(); |
| 190 | if (s != null) |
| 191 | line += s; |
| 192 | } |
| 193 | // END OF RHINO OBJ FILES HACK |
| 194 | |
| 195 | String[] parts = line.split("\\s+"); |
| 196 | // if not a blank line, process the line. |
| 197 | if (parts.length > 0) { |
| 198 | if (parts[0].equals("v")) { |
| 199 | // vertex |
| 200 | PVector tempv = new PVector(Float.valueOf(parts[1]).floatValue(), |
| 201 | Float.valueOf(parts[2]).floatValue(), |
| 202 | Float.valueOf(parts[3]).floatValue()); |
| 203 | coords.add(tempv); |
| 204 | readv = true; |
| 205 | } else if (parts[0].equals("vn")) { |
| 206 | // normal |
| 207 | PVector tempn = new PVector(Float.valueOf(parts[1]).floatValue(), |
| 208 | Float.valueOf(parts[2]).floatValue(), |
| 209 | Float.valueOf(parts[3]).floatValue()); |
| 210 | normals.add(tempn); |
no test coverage detected