Search in sources :

Example 11 with AmbientLight

use of com.jme3.light.AmbientLight in project jmonkeyengine by jMonkeyEngine.

the class HelloCollision method setUpLight.

private void setUpLight() {
    // We add light so we see the scene
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(1.3f));
    rootNode.addLight(al);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
    rootNode.addLight(dl);
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) AmbientLight(com.jme3.light.AmbientLight)

Example 12 with AmbientLight

use of com.jme3.light.AmbientLight in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("scene")) {
        if (elementStack.size() != 0) {
            throw new SAXException("dotScene parse error: 'scene' element must be the root XML element");
        }
        String version = attribs.getValue("formatVersion");
        if (version == null || (!version.equals("1.0.0") && !version.equals("1.0.1"))) {
            logger.log(Level.WARNING, "Unrecognized version number" + " in dotScene file: {0}", version);
        }
    } else if (qName.equals("nodes")) {
        if (root != null) {
            throw new SAXException("dotScene parse error: nodes element was specified twice");
        }
        if (sceneName == null) {
            root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
        } else {
            root = new com.jme3.scene.Node(sceneName + "-scene_node");
        }
        node = root;
    } else if (qName.equals("externals")) {
        checkTopNode("scene");
    } else if (qName.equals("item")) {
        checkTopNode("externals");
    } else if (qName.equals("file")) {
        checkTopNode("item");
    // NOTE: This part of the file is ignored, it is parsed
    // by SceneMaterialLoader in the first pass.
    } else if (qName.equals("node")) {
        String curElement = elementStack.peek();
        if (!curElement.equals("node") && !curElement.equals("nodes")) {
            throw new SAXException("dotScene parse error: " + "node element can only appear under 'node' or 'nodes'");
        }
        parseNode(attribs);
    } else if (qName.equals("property")) {
        if (node != null) {
            String type = attribs.getValue("type");
            String name = attribs.getValue("name");
            String data = attribs.getValue("data");
            if (type.equals("BOOL")) {
                node.setUserData(name, Boolean.parseBoolean(data) || data.equals("1"));
            } else if (type.equals("FLOAT")) {
                node.setUserData(name, Float.parseFloat(data));
            } else if (type.equals("STRING")) {
                node.setUserData(name, data);
            } else if (type.equals("INT")) {
                node.setUserData(name, Integer.parseInt(data));
            }
        }
    } else if (qName.equals("entity")) {
        checkTopNode("node");
        parseEntity(attribs);
    } else if (qName.equals("camera")) {
        checkTopNode("node");
        parseCamera(attribs);
    } else if (qName.equals("clipping")) {
        checkTopNode("camera");
        parseCameraClipping(attribs);
    } else if (qName.equals("position")) {
        if (elementStack.peek().equals("node")) {
            node.setLocalTranslation(SAXUtil.parseVector3(attribs));
        } else if (elementStack.peek().equals("camera")) {
            cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
        }
    } else if (qName.equals("quaternion") || qName.equals("rotation")) {
        node.setLocalRotation(parseQuat(attribs));
    } else if (qName.equals("scale")) {
        node.setLocalScale(SAXUtil.parseVector3(attribs));
    } else if (qName.equals("light")) {
        parseLight(attribs);
    } else if (qName.equals("colourDiffuse") || qName.equals("colorDiffuse")) {
        if (elementStack.peek().equals("light")) {
            if (light != null) {
                light.setColor(parseColor(attribs));
            }
        } else {
            checkTopNode("environment");
        }
    } else if (qName.equals("colourAmbient") || qName.equals("colorAmbient")) {
        if (elementStack.peek().equals("environment")) {
            ColorRGBA color = parseColor(attribs);
            if (!color.equals(ColorRGBA.Black) && !color.equals(ColorRGBA.BlackNoAlpha)) {
                // Lets add an ambient light to the scene.
                AmbientLight al = new AmbientLight();
                al.setColor(color);
                root.addLight(al);
            }
        }
    } else if (qName.equals("normal") || qName.equals("direction")) {
        checkTopNode("light");
        parseLightNormal(attribs);
    } else if (qName.equals("lightAttenuation")) {
        parseLightAttenuation(attribs);
    } else if (qName.equals("spotLightRange") || qName.equals("lightRange")) {
        parseLightSpotLightRange(attribs);
    }
    elementStack.push(qName);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) LightNode(com.jme3.scene.LightNode) CameraNode(com.jme3.scene.CameraNode) AmbientLight(com.jme3.light.AmbientLight) SAXException(org.xml.sax.SAXException)

Example 13 with AmbientLight

use of com.jme3.light.AmbientLight in project jmonkeyengine by jMonkeyEngine.

the class BlenderLoader method load.

@Override
public Spatial load(AssetInfo assetInfo) throws IOException {
    try {
        BlenderContext blenderContext = this.setup(assetInfo);
        AnimationHelper animationHelper = blenderContext.getHelper(AnimationHelper.class);
        animationHelper.loadAnimations();
        BlenderKey blenderKey = blenderContext.getBlenderKey();
        LoadedFeatures loadedFeatures = new LoadedFeatures();
        for (FileBlockHeader block : blenderContext.getBlocks()) {
            switch(block.getCode()) {
                case BLOCK_OB00:
                    ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
                    Node object = (Node) objectHelper.toObject(block.getStructure(blenderContext), blenderContext);
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.log(Level.FINE, "{0}: {1}--> {2}", new Object[] { object.getName(), object.getLocalTranslation().toString(), object.getParent() == null ? "null" : object.getParent().getName() });
                    }
                    if (object.getParent() == null) {
                        loadedFeatures.objects.add(object);
                    }
                    if (object instanceof LightNode && ((LightNode) object).getLight() != null) {
                        loadedFeatures.lights.add(((LightNode) object).getLight());
                    } else if (object instanceof CameraNode && ((CameraNode) object).getCamera() != null) {
                        loadedFeatures.cameras.add(((CameraNode) object).getCamera());
                    }
                    break;
                case // Scene
                BLOCK_SC00:
                    loadedFeatures.sceneBlocks.add(block);
                    break;
                case // Material
                BLOCK_MA00:
                    MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
                    MaterialContext materialContext = materialHelper.toMaterialContext(block.getStructure(blenderContext), blenderContext);
                    loadedFeatures.materials.add(materialContext);
                    break;
                case // Mesh
                BLOCK_ME00:
                    MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
                    TemporalMesh temporalMesh = meshHelper.toTemporalMesh(block.getStructure(blenderContext), blenderContext);
                    loadedFeatures.meshes.add(temporalMesh);
                    break;
                case // Image
                BLOCK_IM00:
                    TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
                    Texture image = textureHelper.loadImageAsTexture(block.getStructure(blenderContext), 0, blenderContext);
                    if (image != null && image.getImage() != null) {
                        // render results are stored as images but are not being loaded
                        loadedFeatures.images.add(image);
                    }
                    break;
                case BLOCK_TE00:
                    Structure textureStructure = block.getStructure(blenderContext);
                    int type = ((Number) textureStructure.getFieldValue("type")).intValue();
                    if (type == TextureHelper.TEX_IMAGE) {
                        TextureHelper texHelper = blenderContext.getHelper(TextureHelper.class);
                        Texture texture = texHelper.getTexture(textureStructure, null, blenderContext);
                        if (texture != null) {
                            // null is returned when texture has no image
                            loadedFeatures.textures.add(texture);
                        }
                    } else {
                        LOGGER.fine("Only image textures can be loaded as unlinked assets. Generated textures will be applied to an existing object.");
                    }
                    break;
                case // World
                BLOCK_WO00:
                    LandscapeHelper landscapeHelper = blenderContext.getHelper(LandscapeHelper.class);
                    Structure worldStructure = block.getStructure(blenderContext);
                    String worldName = worldStructure.getName();
                    if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) {
                        Light ambientLight = landscapeHelper.toAmbientLight(worldStructure);
                        if (ambientLight != null) {
                            loadedFeatures.objects.add(new LightNode(null, ambientLight));
                            loadedFeatures.lights.add(ambientLight);
                        }
                        loadedFeatures.sky = landscapeHelper.toSky(worldStructure);
                        loadedFeatures.backgroundColor = landscapeHelper.toBackgroundColor(worldStructure);
                        Filter fogFilter = landscapeHelper.toFog(worldStructure);
                        if (fogFilter != null) {
                            loadedFeatures.filters.add(landscapeHelper.toFog(worldStructure));
                        }
                    }
                    break;
                case BLOCK_AC00:
                    LOGGER.fine("Loading unlinked animations is not yet supported!");
                    break;
                default:
                    LOGGER.log(Level.FINEST, "Ommiting the block: {0}.", block.getCode());
            }
        }
        LOGGER.fine("Baking constraints after every feature is loaded.");
        ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
        constraintHelper.bakeConstraints(blenderContext);
        LOGGER.fine("Loading scenes and attaching them to the root object.");
        for (FileBlockHeader sceneBlock : loadedFeatures.sceneBlocks) {
            loadedFeatures.scenes.add(this.toScene(sceneBlock.getStructure(blenderContext), blenderContext));
        }
        LOGGER.fine("Creating the root node of the model and applying loaded nodes of the scene and loaded features to it.");
        Node modelRoot = new Node(blenderKey.getName());
        for (Node scene : loadedFeatures.scenes) {
            modelRoot.attachChild(scene);
        }
        if (blenderKey.isLoadUnlinkedAssets()) {
            LOGGER.fine("Setting loaded content as user data in resulting sptaial.");
            Map<String, Map<String, Object>> linkedData = new HashMap<String, Map<String, Object>>();
            Map<String, Object> thisFileData = new HashMap<String, Object>();
            thisFileData.put("scenes", loadedFeatures.scenes == null ? new ArrayList<Object>() : loadedFeatures.scenes);
            thisFileData.put("objects", loadedFeatures.objects == null ? new ArrayList<Object>() : loadedFeatures.objects);
            thisFileData.put("meshes", loadedFeatures.meshes == null ? new ArrayList<Object>() : loadedFeatures.meshes);
            thisFileData.put("materials", loadedFeatures.materials == null ? new ArrayList<Object>() : loadedFeatures.materials);
            thisFileData.put("textures", loadedFeatures.textures == null ? new ArrayList<Object>() : loadedFeatures.textures);
            thisFileData.put("images", loadedFeatures.images == null ? new ArrayList<Object>() : loadedFeatures.images);
            thisFileData.put("animations", loadedFeatures.animations == null ? new ArrayList<Object>() : loadedFeatures.animations);
            thisFileData.put("cameras", loadedFeatures.cameras == null ? new ArrayList<Object>() : loadedFeatures.cameras);
            thisFileData.put("lights", loadedFeatures.lights == null ? new ArrayList<Object>() : loadedFeatures.lights);
            thisFileData.put("filters", loadedFeatures.filters == null ? new ArrayList<Object>() : loadedFeatures.filters);
            thisFileData.put("backgroundColor", loadedFeatures.backgroundColor);
            thisFileData.put("sky", loadedFeatures.sky);
            linkedData.put("this", thisFileData);
            linkedData.putAll(blenderContext.getLinkedFeatures());
            modelRoot.setUserData("linkedData", linkedData);
        }
        return modelRoot;
    } catch (BlenderFileException e) {
        throw new IOException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        throw new IOException("Unexpected importer exception occured: " + e.getLocalizedMessage(), e);
    } finally {
        this.clear(assetInfo);
    }
}
Also used : HashMap(java.util.HashMap) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) CameraNode(com.jme3.scene.CameraNode) ArrayList(java.util.ArrayList) Texture(com.jme3.texture.Texture) LandscapeHelper(com.jme3.scene.plugins.blender.landscape.LandscapeHelper) LightNode(com.jme3.scene.LightNode) Light(com.jme3.light.Light) TextureHelper(com.jme3.scene.plugins.blender.textures.TextureHelper) BlenderKey(com.jme3.asset.BlenderKey) Structure(com.jme3.scene.plugins.blender.file.Structure) ObjectHelper(com.jme3.scene.plugins.blender.objects.ObjectHelper) AnimationHelper(com.jme3.scene.plugins.blender.animations.AnimationHelper) FileBlockHeader(com.jme3.scene.plugins.blender.file.FileBlockHeader) BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException) IOException(java.io.IOException) ConstraintHelper(com.jme3.scene.plugins.blender.constraints.ConstraintHelper) BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TemporalMesh(com.jme3.scene.plugins.blender.meshes.TemporalMesh) Filter(com.jme3.post.Filter) MaterialHelper(com.jme3.scene.plugins.blender.materials.MaterialHelper) MaterialContext(com.jme3.scene.plugins.blender.materials.MaterialContext) HashMap(java.util.HashMap) Map(java.util.Map) MeshHelper(com.jme3.scene.plugins.blender.meshes.MeshHelper)

Example 14 with AmbientLight

use of com.jme3.light.AmbientLight in project jmonkeyengine by jMonkeyEngine.

the class LandscapeHelper method toAmbientLight.

/**
     * Loads scene ambient light.
     * @param worldStructure
     *            the world's blender structure
     * @return the scene's ambient light
     */
public Light toAmbientLight(Structure worldStructure) {
    LOGGER.fine("Loading ambient light.");
    AmbientLight ambientLight = null;
    float ambr = ((Number) worldStructure.getFieldValue("ambr")).floatValue();
    float ambg = ((Number) worldStructure.getFieldValue("ambg")).floatValue();
    float ambb = ((Number) worldStructure.getFieldValue("ambb")).floatValue();
    if (ambr > 0 || ambg > 0 || ambb > 0) {
        ambientLight = new AmbientLight();
        ColorRGBA ambientLightColor = new ColorRGBA(ambr, ambg, ambb, 0.0f);
        ambientLight.setColor(ambientLightColor);
        LOGGER.log(Level.FINE, "Loaded ambient light: {0}.", ambientLightColor);
    } else {
        LOGGER.finer("Ambient light is set to BLACK which means: no ambient light! The ambient light node will not be included in the result.");
    }
    return ambientLight;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) AmbientLight(com.jme3.light.AmbientLight)

Example 15 with AmbientLight

use of com.jme3.light.AmbientLight in project jmonkeyengine by jMonkeyEngine.

the class TestBoneRagdoll method setupLight.

private void setupLight() {
    // AmbientLight al = new AmbientLight();
    //  al.setColor(ColorRGBA.White.mult(1));
    //   rootNode.addLight(al);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Aggregations

AmbientLight (com.jme3.light.AmbientLight)35 DirectionalLight (com.jme3.light.DirectionalLight)24 Vector3f (com.jme3.math.Vector3f)24 Geometry (com.jme3.scene.Geometry)24 Material (com.jme3.material.Material)16 Box (com.jme3.scene.shape.Box)13 Node (com.jme3.scene.Node)12 Spatial (com.jme3.scene.Spatial)12 Sphere (com.jme3.scene.shape.Sphere)12 ColorRGBA (com.jme3.math.ColorRGBA)11 Quaternion (com.jme3.math.Quaternion)9 SpotLight (com.jme3.light.SpotLight)8 ActionListener (com.jme3.input.controls.ActionListener)7 KeyTrigger (com.jme3.input.controls.KeyTrigger)7 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 PointLight (com.jme3.light.PointLight)6 Texture (com.jme3.texture.Texture)6 Vector2f (com.jme3.math.Vector2f)5 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 SSAOFilter (com.jme3.post.ssao.SSAOFilter)3