Java Code Examples for com.jme3.app.Application#getAssetManager()

The following examples show how to use com.jme3.app.Application#getAssetManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BulletDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialize the materials.
 *
 * @param app the application which owns this state (not null)
 */
private void setupMaterials(Application app) {
    AssetManager manager = app.getAssetManager();
    DEBUG_BLUE = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_BLUE.getAdditionalRenderState().setWireframe(true);
    DEBUG_BLUE.setColor("Color", ColorRGBA.Blue);
    DEBUG_GREEN = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_GREEN.getAdditionalRenderState().setWireframe(true);
    DEBUG_GREEN.setColor("Color", ColorRGBA.Green);
    DEBUG_RED = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_RED.getAdditionalRenderState().setWireframe(true);
    DEBUG_RED.setColor("Color", ColorRGBA.Red);
    DEBUG_YELLOW = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_YELLOW.getAdditionalRenderState().setWireframe(true);
    DEBUG_YELLOW.setColor("Color", ColorRGBA.Yellow);
    DEBUG_MAGENTA = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_MAGENTA.getAdditionalRenderState().setWireframe(true);
    DEBUG_MAGENTA.setColor("Color", ColorRGBA.Magenta);
    DEBUG_PINK = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_PINK.getAdditionalRenderState().setWireframe(true);
    DEBUG_PINK.setColor("Color", ColorRGBA.Pink);
}
 
Example 2
Source File: Cinematic.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void initialize(AppStateManager stateManager, Application app) {
    if (niftyXmlPath != null) {
        NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(),
                app.getInputManager(),
                app.getAudioRenderer(),
                app.getGuiViewPort());
        nifty = niftyDisplay.getNifty();
        nifty.fromXmlWithoutStartScreen(niftyXmlPath);
        app.getGuiViewPort().addProcessor(niftyDisplay);
    }
    initEvent(app, this);
    for (CinematicEvent cinematicEvent : cinematicEvents) {
        cinematicEvent.initEvent(app, this);
    }



    initialized = true;
}
 
Example 3
Source File: PhysicsTestHelper.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * creates the necessary inputlistener and action to shoot balls from the camera
 *
 * @param app the application that's running
 * @param rootNode where ball geometries should be added
 * @param space where collision objects should be added
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
Example 4
Source File: BulletDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize this state prior to its 1st update. Should be invoked only by
 * a subclass or by the AppStateManager.
 *
 * @param stateManager the manager for this state (not null)
 * @param app the application which owns this state (not null)
 */
@Override
public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.app = app;
    this.rm = app.getRenderManager();
    this.assetManager = app.getAssetManager();
    setupMaterials(app);
    physicsDebugRootNode.setCullHint(Spatial.CullHint.Never);
    viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera());
    viewPort.setClearFlags(false, true, false);
    viewPort.attachScene(physicsDebugRootNode);
}
 
Example 5
Source File: SoundEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void initEvent(Application app, Cinematic cinematic) {
    super.initEvent(app, cinematic);
    audioNode = new AudioNode(app.getAssetManager(), path, stream);
    audioNode.setPositional(false);
    setLoopMode(loopMode);
}
 
Example 6
Source File: LightsDebugState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initialize(Application app) {
    debugNode = new Node("Environment debug Node");
    Sphere s = new Sphere(16, 16, 0.15f);
    debugGeom = new Geometry("debugEnvProbe", s);
    debugMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/reflect.j3md");
    debugGeom.setMaterial(debugMaterial);
    debugBounds = BoundingSphereDebug.createDebugSphere(app.getAssetManager());
    if (scene == null) {
        scene = app.getViewPort().getScenes().get(0);
    }
}
 
Example 7
Source File: MaterialDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void initialize(AppStateManager stateManager, Application app) {
    renderManager = app.getRenderManager();
    assetManager = app.getAssetManager();
    inputManager = app.getInputManager();
    for (Binding binding : bindings) {
        bind(binding);
    }
    super.initialize(stateManager, app);
}
 
Example 8
Source File: PhysicsTestHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * creates the necessary inputlistener and action to shoot balls from teh camera
 * @param app
 * @param rootNode
 * @param space
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(1);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
Example 9
Source File: SoundTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void initEvent(Application app, Cinematic cinematic) {    
    super.initEvent(app, cinematic);
    audioNode = new AudioNode(app.getAssetManager(), path, stream);
    setLoopMode(loopMode);

}
 
Example 10
Source File: GuiGlobals.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected GuiGlobals( Application app ) {
    this.assets = app.getAssetManager();
    
    if( isHeadless(app) ) {
        // Do only minimal initialization... and nothing requiring
        // input, a screen, etc.
        styles = new Styles();
        setDefaultStyles();

        iconBase = getClass().getPackage().getName().replace( '.', '/' ) + "/icons";
        
        return;
    }
     
    this.keyInterceptor = new KeyInterceptState(app);
    
    // For now, pick either mouse or touch based on the
    // availability of touch.  It's an either/or at the 
    // moment but the rest of the code is setup to support
    // both at once should we ever want to support touch
    // devices that also may have a mouse connected.
    if (app.getContext().getTouchInput() == null) {
        this.mouseState = new MouseAppState(app);
    } else {
        this.touchState = new TouchAppState(app);
    }
    
    this.inputMapper = new InputMapper(app.getInputManager());
    this.focusState = new FocusManagerState();
    this.focusNavState = new FocusNavigationState(inputMapper, focusState);
    this.animationState = new AnimationState();
    this.popupState = new PopupState();

    // Write the app state dependencies directly so that:
    // a) they are there before initialization
    // b) so that the states don't have to rely on GuiGlobals to find
    //    them.
    // c) so that we might disable them properly even at runtime
    //    if the user kills or replaces the nav state
    focusState.setFocusNavigationState(focusNavState);
    
    app.getStateManager().attach(keyInterceptor);
    
    if( mouseState != null ) {
        app.getStateManager().attach(mouseState);
    }
    if( touchState != null ) {
        app.getStateManager().attach(touchState);
    }
    
    app.getStateManager().attach(focusState);
    app.getStateManager().attach(focusNavState);
    app.getStateManager().attach(animationState);
    app.getStateManager().attach(popupState);

    styles = new Styles();
    setDefaultStyles();

    iconBase = getClass().getPackage().getName().replace( '.', '/' ) + "/icons";

    ViewPort main = app.getViewPort();
    setupGuiComparators(main);
    
    // By default all of our app picking states are enabled so we should
    // make a 'formal' request.
    setCursorEventsEnabled(true);
    
    gammaEnabled = app.getContext().getSettings().isGammaCorrection();
}
 
Example 11
Source File: InstancedDirectionalShadowFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create a new instanced version of the {@link DirectionalLightShadowFilterVR directional light shadow filter}.
 * @param application the application that this filter is attached to.
 * @param camera 
 * @param shadowMapSize the size of the rendered shadowmaps (512, 1024, 2048, etc...)
 * @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps).
 * @param instancedRendering <code>true</code> if this filter has to use instance rendering and <code>false</code> otherwise.
 * @param rightCamera the camera used as right eye in stereo rendering mode.
 */
public InstancedDirectionalShadowFilter(Application application, Camera camera, int shadowMapSize, int nbSplits, boolean instancedRendering, Camera rightCamera) {
    super(application.getAssetManager(), shadowMapSize, nbSplits, "Common/MatDefs/VR/PostShadowFilter.j3md");
    this.instanceRendering = instancedRendering;
    this.rightCamera = rightCamera;
}