/** * The main method takes all the parameters and assumes they are input files for the ray tracer. * It tries to render each one and write it out to a PNG file named <input_file>.png. A '-p' * option may be passed in to change the path that is prepended to each file that is included. * * @param args */ public static final void main(String[] args) { ArrayList<ScenePath> pathArgs = new ArrayList<>(); ArrayList<ScenePath> scenesToRender = new ArrayList<>(); String currentRoot = directory; // Use All The Arguments for (int i = 0; i < args.length; i++) { switch (args[i].toLowerCase()) { case "-p": // Use A Different Root Path i++; if (i < args.length) currentRoot = args[i]; break; case "-pnull": // Use The CWD currentRoot = null; break; default: // This Must Be A File pathArgs.add(new ScenePath(currentRoot, args[i])); break; } } if (pathArgs.size() < 1) { // Attempt To Render All The Scenes pathArgs.add(new ScenePath(currentRoot, ".")); // Display What's Going To Go Down printUsage(); System.out.println("\nAttempting To Render All Scenes"); } // Expand All The Possible Scenes for (ScenePath p : pathArgs) { // Add All The Files In The File f = p.file.toFile(); if (f.isDirectory()) { for (File _f : f.listFiles()) { // We Only Want XML Files if (!_f.getPath().endsWith(".xml")) continue; scenesToRender.add(new ScenePath(p.getRoot(), _f.toPath().toAbsolutePath().toString())); } } else { // We Only Want XML Files if (!f.getPath().endsWith(".xml")) continue; // Just A Single Scene scenesToRender.add(p); } } System.out.println("Attempting To Render " + scenesToRender.size() + " Scene(s)"); RayTracer rayTracer = new RayTracer(); rayTracer.run(scenesToRender); }
/** * The run method takes all the parameters and assumes they are input files for the ray tracer. It * tries to render each one and write it out to a PNG file named <input_file>.png. * * @param args */ public void run(ArrayList<ScenePath> args) { Parser parser = new Parser(); for (ScenePath p : args) { // Set The Current Workspace For The Scene sceneWorkspace = p; // Parse the input file Scene scene = (Scene) parser.parse(sceneWorkspace.getFile(), Scene.class); // Create the acceleration structure. ArrayList<Surface> renderableSurfaces = new ArrayList<Surface>(); List<Surface> surfaces = scene.getSurfaces(); for (Iterator<Surface> iter = surfaces.iterator(); iter.hasNext(); ) { iter.next().appendRenderableSurfaces(renderableSurfaces); } scene.setSurfaces(renderableSurfaces); // Render the scene renderImage(scene); // Write the image out scene.getImage().write(sceneWorkspace.getFile() + ".png"); } }