/src/org/mt4j/util/modelImporter/fileObj/ObjectFileMaterials.java

http://mt4j.googlecode.com/ · Java · 671 lines · 399 code · 115 blank · 157 comment · 141 complexity · f05d751946ea0ff07ae422c9f330d214 MD5 · raw file

  1. /*
  2. * $RCSfile: ObjectFile.java,v $
  3. *
  4. * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * - Redistribution of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * - Redistribution in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. *
  18. * Neither the name of Sun Microsystems, Inc. or the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * This software is provided "AS IS," without a warranty of any
  23. * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
  24. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
  26. * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
  27. * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
  28. * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
  29. * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
  30. * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
  31. * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
  32. * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
  33. * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGES.
  35. *
  36. * You acknowledge that this software is not designed, licensed or
  37. * intended for use in the design, construction, operation or
  38. * maintenance of any nuclear facility.
  39. *
  40. * $Revision: 1.6 $
  41. * $Date: 2009/12/21 13:55:05 $
  42. * $State: Exp $
  43. */
  44. package org.mt4j.util.modelImporter.fileObj;
  45. import java.awt.Image;
  46. import java.awt.image.ImageObserver;
  47. import java.io.BufferedInputStream;
  48. import java.io.BufferedReader;
  49. import java.io.File;
  50. import java.io.FileNotFoundException;
  51. import java.io.FileReader;
  52. import java.io.IOException;
  53. import java.io.InputStream;
  54. import java.io.InputStreamReader;
  55. import java.io.Reader;
  56. import java.net.URL;
  57. import java.util.HashMap;
  58. import java.util.Map;
  59. import java.util.WeakHashMap;
  60. import javax.media.opengl.GL;
  61. import org.mt4j.components.visibleComponents.shapes.AbstractShape;
  62. import org.mt4j.util.MT4jSettings;
  63. import org.mt4j.util.math.Tools3D;
  64. import org.mt4j.util.opengl.GLMaterial;
  65. import org.mt4j.util.opengl.GLTexture;
  66. import org.mt4j.util.opengl.GLTextureSettings;
  67. import org.mt4j.util.opengl.GLTexture.EXPANSION_FILTER;
  68. import org.mt4j.util.opengl.GLTexture.SHRINKAGE_FILTER;
  69. import org.mt4j.util.opengl.GLTexture.TEXTURE_TARGET;
  70. import org.mt4j.util.opengl.GLTexture.WRAP_MODE;
  71. import processing.core.PApplet;
  72. import processing.core.PImage;
  73. class ObjectFileMaterials implements ImageObserver {
  74. // DEBUG
  75. // 1 = Name of materials
  76. // 16 = Tokens
  77. private static final int DEBUG = 0;
  78. private String curName = null;
  79. private ObjectFileMaterial cur = null;
  80. private HashMap materials; // key=String name of material
  81. // value=ObjectFileMaterial
  82. private Map<String, PImage> textureCache = new WeakHashMap<String, PImage>();
  83. PApplet pa;
  84. private String basePath;
  85. private boolean fromUrl;
  86. private class ObjectFileMaterial {
  87. // public Color3f Ka;
  88. // public Color3f Kd;
  89. // public Color3f Ks;
  90. public float[] Ka;
  91. public float[] Kd;
  92. public float[] Ks;
  93. public int illum;
  94. public float Ns;
  95. // public Texture2D t;
  96. public PImage t;
  97. public boolean transparent;
  98. public float transparencyLevel;
  99. public PImage d;
  100. }
  101. void assignMaterial(GL gl, String matName, AbstractShape shape) {
  102. ObjectFileMaterial p = null;
  103. if ((DEBUG & 1) != 0)
  104. System.out.println("Color " + matName);
  105. GLMaterial m = new GLMaterial(gl);
  106. p = (ObjectFileMaterial)materials.get(matName);
  107. // Appearance a = new Appearance();
  108. if (p != null) {
  109. // Set ambient & diffuse color
  110. if (p.Ka != null)
  111. // m.setAmbient(p.Ka);
  112. m.setAmbient(new float[]{p.Ka[0],p.Ka[1],p.Ka[2], 1.0f}); //we have to add the last value, else material will not be opaque
  113. if (p.Kd != null)
  114. // m.setDiffuse(p.Kd);
  115. m.setDiffuse(new float[]{p.Kd[0],p.Kd[1],p.Kd[2], 1.0f});
  116. // Set specular color
  117. if ((p.Ks != null) && (p.illum != 1))
  118. // m.setSpecular(p.Ks);
  119. m.setSpecular(new float[]{p.Ks[0],p.Ks[1],p.Ks[2], 1.0f});
  120. else if (p.illum == 1)
  121. m.setSpecular(new float[]{0.0f, 0.0f, 0.0f, 1.0f});
  122. // if (p.illum >= 1) m.setLightingEnable(true);
  123. // else if (p.illum == 0) m.setLightingEnable(false);
  124. if (p.Ns != -1.0f)
  125. m.setShininess(p.Ns);
  126. if (p.t != null) {
  127. PImage tex = p.t;
  128. // /*
  129. //Apply alpha mask from transparancy map to the texture
  130. if (p.d != null){
  131. //System.out.println("Trying to add alpha mask for material: " + matName);
  132. PImage alphaMap = p.d;
  133. if (alphaMap.width == tex.width && alphaMap.height == tex.height){
  134. tex.mask(alphaMap);
  135. if (tex instanceof GLTexture) {
  136. GLTexture glTex = (GLTexture) tex;
  137. // glTex.putPixelsIntoTexture(tex);
  138. glTex.loadGLTexture(tex);
  139. }
  140. }else{
  141. //System.out.println("Alpha map isnt the same size as the texture for material: " + matName);
  142. }
  143. }
  144. // */
  145. shape.setTexture(tex);
  146. System.out.println("Texture assigned to object: " + shape.getName());
  147. }
  148. // if (p.transparent)
  149. // a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST,p.transparencyLevel));
  150. shape.setMaterial(m);
  151. }else{
  152. System.err.println("No material \"" + matName + "\" found for object " + shape.getName());
  153. }
  154. if ((DEBUG & 1) != 0)
  155. System.out.println(m);
  156. } // End of assignMaterial
  157. private void readName(ObjectFileParser st) throws ParsingErrorException {
  158. st.getToken();
  159. if (st.ttype == ObjectFileParser.TT_WORD) {
  160. if (curName != null) materials.put(curName, cur);
  161. curName = st.sval;
  162. cur = new ObjectFileMaterial();
  163. }
  164. st.skipToNextLine();
  165. } // End of readName
  166. private void readAmbient(ObjectFileParser st) throws ParsingErrorException {
  167. // Color3f p = new Color3f();
  168. float[] p = new float[3];
  169. st.getNumber();
  170. p[0] = (float)st.nval;
  171. st.getNumber();
  172. p[1] = (float)st.nval;
  173. st.getNumber();
  174. p[2] = (float)st.nval;
  175. cur.Ka = p;
  176. st.skipToNextLine();
  177. } // End of readAmbient
  178. private void readDiffuse(ObjectFileParser st) throws ParsingErrorException {
  179. // Color3f p = new Color3f();
  180. float[] p = new float[3];
  181. st.getNumber();
  182. p[0] = (float)st.nval;
  183. st.getNumber();
  184. p[1] = (float)st.nval;
  185. st.getNumber();
  186. p[2] = (float)st.nval;
  187. cur.Kd = p;
  188. st.skipToNextLine();
  189. } // End of readDiffuse
  190. private void readSpecular(ObjectFileParser st) throws ParsingErrorException {
  191. // Color3f p = new Color3f();
  192. float[] p = new float[3];
  193. st.getNumber();
  194. p[0] = (float)st.nval;
  195. st.getNumber();
  196. p[1] = (float)st.nval;
  197. st.getNumber();
  198. p[2] = (float)st.nval;
  199. cur.Ks = p;
  200. st.skipToNextLine();
  201. } // End of readSpecular
  202. private void readIllum(ObjectFileParser st) throws ParsingErrorException {
  203. st.getNumber();
  204. cur.illum = (int)st.nval;
  205. st.skipToNextLine();
  206. } // End of readSpecular
  207. private void readTransparency(ObjectFileParser st) throws ParsingErrorException {
  208. st.getNumber();
  209. cur.transparencyLevel = (float)st.nval;
  210. if ( cur.transparencyLevel < 1.0f ){
  211. cur.transparent = true;
  212. }
  213. st.skipToNextLine();
  214. } // End of readTransparency
  215. private void readShininess(ObjectFileParser st) throws ParsingErrorException {
  216. float f;
  217. st.getNumber();
  218. cur.Ns = (float)st.nval;
  219. if (cur.Ns < 1.0f) cur.Ns = 1.0f;
  220. else if (cur.Ns > 128.0f) cur.Ns = 128.0f;
  221. st.skipToNextLine();
  222. } // End of readSpecular
  223. public void readMapKd(ObjectFileParser st) {
  224. // Filenames are case sensitive
  225. st.lowerCaseMode(false);
  226. // Get name of texture file (skip path)
  227. String tFile = "";
  228. do {
  229. st.getToken();
  230. // if (st.ttype == ObjectFileParser.TT_WORD){
  231. // tFile += st.sval;
  232. //
  233. // }
  234. if (st.ttype != ObjectFileParser.TT_EOL ){
  235. tFile += st.sval;
  236. }
  237. } while (st.ttype != ObjectFileParser.TT_EOL);
  238. st.lowerCaseMode(true);
  239. if (!tFile.equals("")) {
  240. PImage texture = null;
  241. // Check for filename with no extension
  242. if (tFile.lastIndexOf('.') != -1) {
  243. try {
  244. // Convert filename to lower case for extension comparisons
  245. String suffix = tFile.substring(tFile.lastIndexOf('.') + 1).toLowerCase();
  246. // TextureLoader t = null;
  247. tFile = toLowerCase(tFile);
  248. if ((suffix.equals("int")) || (suffix.equals("inta")) ||
  249. (suffix.equals("rgb")) || (suffix.equals("rgba")) ||
  250. (suffix.equals("bw")) || (suffix.equals("sgi"))
  251. ) {
  252. PImage cachedImage = textureCache.get(tFile);
  253. if (cachedImage != null){
  254. texture = cachedImage;
  255. //System.out.println("->Loaded texture from CACHE : \"" + tFile + "\"");
  256. }else{
  257. File textureFile = new File(basePath + tFile);
  258. if (textureFile.exists()){
  259. boolean success = textureFile.renameTo(new File(basePath + tFile));
  260. if (!success) {
  261. // File was not successfully renamed
  262. System.out.println("failed to RENAME file: " + textureFile.getAbsolutePath());
  263. }
  264. if (MT4jSettings.getInstance().isOpenGlMode()){
  265. PImage img = pa.loadImage(basePath + tFile);
  266. if (Tools3D.isPowerOfTwoDimension(img)){
  267. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  268. }else{
  269. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  270. // ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
  271. }
  272. }else{
  273. texture = pa.loadImage(basePath + tFile);
  274. }
  275. textureCache.put(tFile, texture);
  276. }else{
  277. System.out.println("Trying to load obj texture from: " + basePath + tFile);
  278. if (MT4jSettings.getInstance().isOpenGlMode()){
  279. PImage img = pa.loadImage(basePath + tFile);
  280. if (Tools3D.isPowerOfTwoDimension(img)){
  281. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  282. }else{
  283. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  284. // ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
  285. }
  286. }else{
  287. texture = pa.loadImage(basePath + tFile);
  288. }
  289. textureCache.put(tFile, texture);
  290. }
  291. }
  292. // RgbFile f;
  293. // if (fromUrl) {
  294. // f = new RgbFile(new URL(basePath + tFile).openStream());
  295. // } else {
  296. // f = new RgbFile(new FileInputStream(basePath + tFile));
  297. // }
  298. // BufferedImage bi = f.getImage();
  299. boolean luminance = suffix.equals("int") || suffix.equals("inta");
  300. boolean alpha = suffix.equals("inta") || suffix.equals("rgba");
  301. cur.transparent = alpha;
  302. String s = null;
  303. if (luminance && alpha) s = "LUM8_ALPHA8";
  304. else if (luminance) s = "LUMINANCE";
  305. else if (alpha) s = "RGBA";
  306. else s = "RGB";
  307. // t = new TextureLoader(bi, s, TextureLoader.GENERATE_MIPMAP);
  308. } else {
  309. // tFile.toLowerCase();
  310. // tFile.toLowerCase(Locale.ENGLISH);
  311. // basePath.toLowerCase();
  312. PImage cachedImage = textureCache.get(tFile);
  313. if (cachedImage != null){
  314. texture = cachedImage;
  315. //System.out.println("->Loaded texture from CACHE : \"" + tFile + "\"");
  316. }else{
  317. File textureFile = new File(basePath + tFile);
  318. if (textureFile.exists()){
  319. boolean success = textureFile.renameTo(new File(basePath + tFile));
  320. if (!success) {
  321. // File was not successfully renamed
  322. System.out.println("failed to RENAME file: " + textureFile.getAbsolutePath());
  323. }
  324. if (MT4jSettings.getInstance().isOpenGlMode()){
  325. PImage img = pa.loadImage(basePath + tFile);
  326. if (Tools3D.isPowerOfTwoDimension(img)){
  327. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  328. }else{
  329. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  330. // ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
  331. }
  332. }else{
  333. texture = pa.loadImage(basePath + tFile);
  334. }
  335. textureCache.put(tFile, texture);
  336. }else{
  337. System.out.println("Trying to load obj texture from: " + basePath + tFile);
  338. if (MT4jSettings.getInstance().isOpenGlMode()){
  339. PImage img = pa.loadImage(basePath + tFile);
  340. if (Tools3D.isPowerOfTwoDimension(img)){
  341. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  342. }else{
  343. texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
  344. // ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
  345. }
  346. }else{
  347. texture = pa.loadImage(basePath + tFile);
  348. }
  349. textureCache.put(tFile, texture);
  350. }
  351. }
  352. // if (ConstantsAndSettings.getInstance().isOpenGlMode()){
  353. // GLTexture glTex = new GLTexture(pa, basePath + tFile);
  354. // texture = glTex;
  355. // }else{
  356. // texture = pa.loadImage(basePath + tFile);
  357. // }
  358. // // For all other file types, use the TextureLoader
  359. // if (fromUrl) {
  360. // t = new TextureLoader(new URL(basePath + tFile), "RGB",
  361. // TextureLoader.GENERATE_MIPMAP, null);
  362. // } else {
  363. // t = new TextureLoader(basePath + tFile, "RGB",
  364. // TextureLoader.GENERATE_MIPMAP, null);
  365. // }
  366. }
  367. // Texture2D texture = (Texture2D)t.getTexture();
  368. if (texture != null)
  369. cur.t = texture;
  370. }
  371. catch (Exception e) {
  372. // Texture won't get loaded if file can't be found
  373. e.printStackTrace();
  374. }
  375. // catch (MalformedURLException e) {
  376. // // Texture won't get loaded if file can't be found
  377. // }
  378. // catch (IOException e) {
  379. // // Texture won't get loaded if file can't be found
  380. // }
  381. }
  382. }
  383. st.skipToNextLine();
  384. } // End of readMapKd
  385. /**
  386. *
  387. * @param string
  388. * @return
  389. */
  390. public String toLowerCase(String string){
  391. char[] chars = new char[string.length()];
  392. for (int i = 0; i < chars.length; i++) {
  393. char c = string.charAt(i);
  394. c = Character.toLowerCase(c);
  395. chars[i] = c;
  396. }
  397. return new String(chars);
  398. }
  399. public void readMapD(ObjectFileParser st) {
  400. // Filenames are case sensitive
  401. st.lowerCaseMode(false);
  402. // Get name of texture file (skip path)
  403. String tFile = "";
  404. do {
  405. st.getToken();
  406. // if (st.ttype == ObjectFileParser.TT_WORD){
  407. // tFile += st.sval;
  408. // }
  409. if (st.ttype != ObjectFileParser.TT_EOL ){
  410. tFile += st.sval;
  411. }
  412. }while (st.ttype != ObjectFileParser.TT_EOL);
  413. st.lowerCaseMode(true);
  414. if (!tFile.equals("")) {
  415. PImage alphaMap;
  416. // Check for filename with no extension
  417. if (tFile.lastIndexOf('.') != -1) {
  418. try {
  419. // Convert filename to lower case for extension comparisons
  420. String suffix = tFile.substring(tFile.lastIndexOf('.') + 1).toLowerCase();
  421. if ((suffix.equals("int")) || (suffix.equals("inta")) ||
  422. (suffix.equals("rgb")) || (suffix.equals("rgba")) ||
  423. (suffix.equals("bw")) || (suffix.equals("sgi"))
  424. ) {
  425. tFile = toLowerCase(tFile);
  426. alphaMap = pa.loadImage(basePath + tFile);
  427. } else {
  428. tFile = toLowerCase(tFile);
  429. alphaMap = pa.loadImage(basePath + tFile);
  430. }
  431. if (alphaMap != null){
  432. cur.d = alphaMap;
  433. }
  434. }catch (Exception e) {
  435. // Texture won't get loaded if file can't be found
  436. e.printStackTrace();
  437. }
  438. }
  439. }
  440. st.skipToNextLine();
  441. } // End of readMapKd
  442. /**
  443. *
  444. * @param st
  445. * @throws ParsingErrorException
  446. */
  447. private void readFile(ObjectFileParser st) throws ParsingErrorException {
  448. int t;
  449. st.getToken();
  450. while (st.ttype != ObjectFileParser.TT_EOF) {
  451. // Print out one token for each line
  452. if ((DEBUG & 16) != 0) {
  453. System.out.print("Token ");
  454. if (st.ttype == ObjectFileParser.TT_EOL) System.out.println("EOL");
  455. else if (st.ttype == ObjectFileParser.TT_WORD)
  456. System.out.println(st.sval);
  457. else System.out.println((char)st.ttype);
  458. }
  459. if (st.ttype == ObjectFileParser.TT_WORD) {
  460. if (st.sval.equals("newmtl")) {
  461. readName(st);
  462. } else if (st.sval.equals("ka")) {
  463. readAmbient(st);
  464. } else if (st.sval.equals("kd")) {
  465. readDiffuse(st);
  466. } else if (st.sval.equals("ks")) {
  467. readSpecular(st);
  468. } else if (st.sval.equals("illum")) {
  469. readIllum(st);
  470. } else if (st.sval.equals("d")) {
  471. readTransparency(st);
  472. } else if (st.sval.equals("ns")) {
  473. readShininess(st);
  474. } else if (st.sval.equals("tf")) {
  475. st.skipToNextLine();
  476. } else if (st.sval.equals("sharpness")) {
  477. st.skipToNextLine();
  478. } else if (st.sval.equals("map_kd")) {
  479. readMapKd(st);
  480. } else if (st.sval.equals("map_ka")) {
  481. st.skipToNextLine();
  482. } else if (st.sval.equals("map_ks")) {
  483. st.skipToNextLine();
  484. } else if (st.sval.equals("map_ns")) {
  485. st.skipToNextLine();
  486. } else if (st.sval.equals("bump")) {
  487. st.skipToNextLine();
  488. }else if (st.sval.equals("map_d")) {
  489. readMapD(st);
  490. }
  491. }
  492. st.skipToNextLine();
  493. // Get next token
  494. st.getToken();
  495. }
  496. if (curName != null) materials.put(curName, cur);
  497. } // End of readFile
  498. /**
  499. *
  500. * @param basePath
  501. * @param fileName
  502. * @throws ParsingErrorException
  503. */
  504. void readMaterialFile(String basePath, String fileName) throws ParsingErrorException {
  505. Reader reader;
  506. this.basePath = basePath;
  507. // this.fromUrl = fromUrl;
  508. try {
  509. if (fromUrl) {
  510. reader = (Reader)
  511. (new InputStreamReader(
  512. new BufferedInputStream(
  513. (new URL(basePath + fileName).openStream()))));
  514. } else {
  515. File f = new File(basePath+fileName);
  516. if (f.exists()){
  517. reader = new BufferedReader(new FileReader(basePath + fileName));
  518. }else{
  519. InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(basePath + fileName);
  520. if (stream == null){
  521. stream = pa.getClass().getResourceAsStream(basePath + fileName);
  522. }
  523. if (stream == null){
  524. throw new FileNotFoundException("File not found: " + basePath + fileName);
  525. }
  526. reader = new BufferedReader(new InputStreamReader(stream));
  527. }
  528. }
  529. }
  530. catch (IOException e) {
  531. // couldn't find it - ignore mtllib
  532. e.printStackTrace();
  533. return;
  534. }
  535. if ((DEBUG & 1) != 0)
  536. System.out.println("Material file: " + basePath + fileName);
  537. ObjectFileParser st = new ObjectFileParser(reader);
  538. readFile(st);
  539. } // End of readMaterialFile
  540. ObjectFileMaterials() throws ParsingErrorException {
  541. // Reader reader = new StringReader(DefaultMaterials.materials);
  542. //
  543. // ObjectFileParser st = new ObjectFileParser(reader);
  544. materials = new HashMap(50);
  545. // readFile(st);
  546. } // End of ObjectFileMaterials
  547. /**
  548. * Implement the ImageObserver interface. Needed to load jpeg and gif
  549. * files using the Toolkit.
  550. */
  551. public boolean imageUpdate(Image img, int flags,
  552. int x, int y, int w, int h) {
  553. return (flags & (ALLBITS | ABORT)) == 0;
  554. } // End of imageUpdate
  555. } // End of class ObjectFileMaterials
  556. // End of file ObjectFileMaterials.java