Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Material.java, 1.16, 1.17 Camera.jav
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2009-11-27 13:35:45
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv9026/src/net/sourceforge/bprocessor/model Modified Files: Material.java Camera.java Project.java Log Message: Export to XML Index: Material.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Material.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Material.java 23 Jun 2009 12:08:45 -0000 1.16 --- Material.java 27 Nov 2009 13:35:26 -0000 1.17 *************** *** 311,313 **** --- 311,329 ---- printer.println("illum " + (int) illumination); } + + /** + * + * @param printer PrintStream + */ + public void exportXml(PrintStream printer) { + String value = "<Material" + + " id=\"" + getId() + "\"" + + " name=\"" + name + "\"" + + " red=\"" + diffuseColor[0] + "\"" + + " green=\"" + diffuseColor[1] + "\"" + + " blue=\"" + diffuseColor[2] + "\"" + + ">"; + printer.println(" " + value); + printer.println(" </Material>"); + } } Index: Camera.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** Camera.java 9 Sep 2009 10:31:00 -0000 1.60 --- Camera.java 27 Nov 2009 13:35:26 -0000 1.61 *************** *** 8,11 **** --- 8,12 ---- import java.awt.Toolkit; + import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; *************** *** 750,752 **** --- 751,792 ---- hiddenGeometrics.add(g); } + + /** + * + * @param printer PrintStream + */ + public void exportXml(PrintStream printer) { + String value = "<Camera" + + " id=\"" + getId() + "\"" + + " name=\"" + name + "\"" + + " focalwidth=\"" + focalwidth + "\"" + + ">"; + printer.println(" " + value); + { + String str = " <position" + + " x=\"" + camera[0] + "\"" + + " y=\"" + camera[1] + "\"" + + " z=\"" + camera[2] + "\"" + + "/>"; + printer.println(str); + } + { + String str = " <lookat" + + " x=\"" + center[0] + "\"" + + " y=\"" + center[1] + "\"" + + " z=\"" + center[2] + "\"" + + "/>"; + printer.println(str); + } + { + String str = " <roll" + + " x=\"" + roll[0] + "\"" + + " y=\"" + roll[1] + "\"" + + " z=\"" + roll[2] + "\"" + + "/>"; + printer.println(str); + } + printer.println(" </Camera>"); + } + } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.182 retrieving revision 1.183 diff -C2 -d -r1.182 -r1.183 *** Project.java 14 Sep 2009 16:22:55 -0000 1.182 --- Project.java 27 Nov 2009 13:35:26 -0000 1.183 *************** *** 11,15 **** import java.io.ByteArrayOutputStream; import java.io.File; - import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; --- 11,14 ---- *************** *** 802,807 **** * @return The cameras */ ! public Collection getCameras() { ! return new HashSet(cameras.values()); } --- 801,806 ---- * @return The cameras */ ! public Collection<Camera> getCameras() { ! return cameras.values(); } *************** *** 833,836 **** --- 832,836 ---- public void run() { export(); + isExporting = false; } } *************** *** 1867,1898 **** */ public void export() { - System.out.println("export to " + getExportPath() + ".obj"); - String objname = getExportPath() + ".obj"; - String mtlname = getExportPath() + ".mtl"; try { ! { ! OutputStream out = new FileOutputStream(new File(mtlname)); ! for (Material current : getMaterials()) { ! current.export(out); ! } ! out.close(); ! } ! { ! OutputStream out = new FileOutputStream(new File(objname)); ! PrintStream printer = new PrintStream(out); ! printer.println("mtllib " + mtlname); ! exportOBJ(out); ! out.close(); ! } ! } catch (FileNotFoundException e) { ! // TODO Auto-generated catch block ! System.out.println("cannot export to " + objname); } catch (IOException e) { // TODO Auto-generated catch block ! System.out.println("cannot export to " + objname); } - isExporting = false; } /** * --- 1867,1962 ---- */ public void export() { try { ! export(getExportPath()); } catch (IOException e) { // TODO Auto-generated catch block ! e.printStackTrace(); ! } ! } ! ! /** ! * Export to the given path ! * @param path String ! * @throws IOException Error ! */ ! public void export(String path) throws IOException { ! exportXml(path); ! } ! ! /** ! * ! * @param path String ! * @throws IOException Exception ! */ ! public void exportXml(String path) throws IOException { ! System.out.println("export to " + path + ".xml"); ! String xmlname = path + ".xml"; ! OutputStream out = new FileOutputStream(new File(xmlname)); ! PrintStream printer = new PrintStream(out); ! printer.println("<Scene>"); ! ! for (Material current : getMaterials()) { ! current.exportXml(printer); ! } ! ! for (Camera current : getCameras()) { ! current.exportXml(printer); ! } ! ! List<Space> spaces = world.collectSpaces(); ! ! List<Space> constructs = new LinkedList(); ! for (Space current : spaces) { ! if (!current.isVoid() && current.isConstructionSpace()) { ! constructs.add(current); ! } ! } ! List<Space> containers = new LinkedList(); ! for (Space current : constructs) { ! Space tesselation = current.tesselate(); ! List<Space> single = new LinkedList(); ! single.add(tesselation); ! Material material = current.getMaterial(); ! if (material == null) { ! material = Defaults.getConstructionMaterial(); ! } ! String header = "<Object" ! + " name=\"" + current.getName() + "\"" ! + " material=\"" + material.getName() + "\"" ! + ">"; ! printer.println(header); ! Space.export(single, printer); ! printer.println("</Object>"); ! } ! printer.println("</Scene"); ! out.close(); ! } ! ! /** ! * Export object file to given path ! * @param path String ! * @throws IOException Exception ! */ ! public void exportObj(String path) throws IOException { ! System.out.println("export to " + path + ".obj"); ! String objname = path + ".obj"; ! String mtlname = path + ".mtl"; ! { ! OutputStream out = new FileOutputStream(new File(mtlname)); ! for (Material current : getMaterials()) { ! current.export(out); ! } ! out.close(); ! } ! { ! OutputStream out = new FileOutputStream(new File(objname)); ! PrintStream printer = new PrintStream(out); ! printer.println("mtllib " + mtlname); ! exportOBJ(out); ! out.close(); } } + /** * |