private static MouseCursor createMouseCursor( final AWTImageLoader awtImageLoader, final String resourceName) throws IOException { final com.ardor3d.image.Image image = awtImageLoader.load( ResourceLocatorTool.getClassPathResourceAsStream(LwjglSwtExample.class, resourceName), false); return new MouseCursor("cursor1", image, 0, image.getHeight() - 1); }
private static MouseCursor createMouseCursor(final String resourceName) throws IOException { final com.ardor3d.image.Image image = ImageLoaderUtil.loadImage( new URLResourceSource( ResourceLocatorTool.getClassPathResource(JoglSwtExample.class, resourceName)), false); return new MouseCursor("cursor1", image, 0, image.getHeight() - 1); }
public static ResourceSource locateResource(final String resourceType, String resourceName) { if (resourceName == null) { return null; } try { resourceName = URLDecoder.decode(resourceName, "UTF-8"); } catch (final UnsupportedEncodingException ex) { ex.printStackTrace(); } synchronized (_locatorMap) { final List<ResourceLocator> bases = _locatorMap.get(resourceType); if (bases != null) { for (int i = bases.size(); --i >= 0; ) { final ResourceLocator loc = bases.get(i); final ResourceSource rVal = loc.locateResource(resourceName); if (rVal != null) { return rVal; } } } // last resort... try { final URL u = ResourceLocatorTool.getClassPathResource(ResourceLocatorTool.class, resourceName); if (u != null) { return new URLResourceSource(u); } } catch (final Exception e) { logger.logp( Level.WARNING, ResourceLocatorTool.class.getName(), "locateResource(String, String)", e.getMessage(), e); } logger.warning("Unable to locate: " + resourceName); return null; } }
/** * Populate a manager with layer information. * * @param layersFile the script file to read from. * @param manager the manager to add layer information to. * @param input the input store object, holding things like AnimationClips that the layers might * need for construction. * @return an output store object * @throws IOException if there is a problem accessing the contents of the layersFile. * @throws ScriptException if the script given has syntax/parse errors. */ public static OutputStore addLayers( final ResourceSource layersFile, final AnimationManager manager, final InputStore input) throws IOException, ScriptException { final OutputStore output = new OutputStore(); final ScriptEngineManager mgr = new ScriptEngineManager(); final ScriptEngine jsEngine = mgr.getEngineByExtension("js"); jsEngine.put("MANAGER", manager); jsEngine.put("INPUTSTORE", input); jsEngine.put("OUTPUTSTORE", output); // load our helper functions first... jsEngine.eval( new InputStreamReader( ResourceLocatorTool.getClassPathResourceAsStream( JSLayerImporter.class, "com/ardor3d/extension/animation/skeletal/state/loader/functions.js"))); // Add our user data... jsEngine.eval(new InputStreamReader(layersFile.openStream())); // return our output store, which may have useful items such as attachment points, etc. return output; }
public static void main(final String[] args) { System.setProperty("ardor3d.useMultipleContexts", "true"); final Timer timer = new Timer(); final FrameHandler frameWork = new FrameHandler(timer); final LogicalLayer logicalLayer = new LogicalLayer(); final MyExit exit = new MyExit(); final ExampleScene scene = new ExampleScene(); final RotatingCubeGame game = new RotatingCubeGame(scene, exit, logicalLayer, Key.T); frameWork.addUpdater(game); // INIT SWT STUFF final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // This is our tab folder, it will be accepting our 3d canvases final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER); // Add a menu item that will create and add a new canvas. final Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); final MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("&Tasks"); final Menu submenu = new Menu(shell, SWT.DROP_DOWN); fileItem.setMenu(submenu); final MenuItem item = new MenuItem(submenu, SWT.PUSH); item.addListener( SWT.Selection, new Listener() { public void handleEvent(final Event e) { Display.getDefault() .asyncExec( new Runnable() { public void run() { addNewCanvas(tabFolder, scene, frameWork, logicalLayer); } }); } }); item.setText("Add &3d Canvas"); item.setAccelerator(SWT.MOD1 + '3'); AWTImageLoader.registerLoader(); try { final SimpleResourceLocator srl = new SimpleResourceLocator( ResourceLocatorTool.getClassPathResource( LwjglSwtExample.class, "com/ardor3d/example/media/")); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, srl); } catch (final URISyntaxException ex) { ex.printStackTrace(); } addNewCanvas(tabFolder, scene, frameWork, logicalLayer); shell.open(); game.init(); // frameWork.init(); while (!shell.isDisposed() && !exit.isExit()) { display.readAndDispatch(); frameWork.updateFrame(); Thread.yield(); // using the below way makes things really jerky. Not sure how to handle that. // if (display.readAndDispatch()) { // frameWork.updateFrame(); // } // else { // display.sleep(); // } } display.dispose(); System.exit(0); }
public void reloadShader() { if (useProjectedShader) { if (useRefraction) { currentShaderStr = projectedShaderRefractionStr; } else { currentShaderStr = projectedShaderStr; } } else { if (useRefraction) { currentShaderStr = simpleShaderRefractionStr; } else { currentShaderStr = simpleShaderStr; } } try { logger.info("loading " + currentShaderStr); waterShader.setVertexShader( ResourceLocatorTool.getClassPathResourceAsStream( WaterNode.class, currentShaderStr + ".vert")); waterShader.setFragmentShader( ResourceLocatorTool.getClassPathResourceAsStream( WaterNode.class, currentShaderStr + ".frag")); } catch (final IOException e) { logger.log(Level.WARNING, "Error loading shader", e); return; } waterShader.setUniform("normalMap", 0); waterShader.setUniform("reflection", 1); waterShader.setUniform("dudvMap", 2); if (useRefraction) { waterShader.setUniform("refraction", 3); waterShader.setUniform("depthMap", 4); } if (useProjectedShader) { if (useRefraction) { waterShader.setUniform("foamMap", 5); } else { waterShader.setUniform("foamMap", 3); } } waterShader._needSendShader = true; try { blurShaderVertical.setVertexShader( ResourceLocatorTool.getClassPathResourceAsStream( WaterNode.class, "com/ardor3d/extension/effect/bloom/bloom_blur.vert")); blurShaderVertical.setFragmentShader( ResourceLocatorTool.getClassPathResourceAsStream( WaterNode.class, "com/ardor3d/extension/effect/bloom/bloom_blur_vertical5_down.frag")); } catch (final IOException ex) { logger.logp( Level.SEVERE, getClass().getName(), "init(Renderer)", "Could not load shaders.", ex); } blurShaderVertical.setUniform("RT", 0); blurShaderVertical.setUniform("sampleDist", blurSampleDistance); blurShaderVertical._needSendShader = true; logger.info("Shader reloaded..."); }
/**