Search in sources :

Example 1 with OgreMeshKey

use of com.jme3.scene.plugins.ogre.OgreMeshKey in project jmonkeyengine by jMonkeyEngine.

the class TestBumpModel method simpleInitApp.

@Override
public void simpleInitApp() {
    Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml"));
    signpost.setMaterial((Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"));
    TangentBinormalGenerator.generate(signpost);
    rootNode.attachChild(signpost);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial((Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);
    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    // sunset light
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
    rootNode.addLight(dl);
    // skylight
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.6f, -1, -0.6f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f));
    rootNode.addLight(dl);
    // white ambient light
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) OgreMeshKey(com.jme3.scene.plugins.ogre.OgreMeshKey) PointLight(com.jme3.light.PointLight)

Example 2 with OgreMeshKey

use of com.jme3.scene.plugins.ogre.OgreMeshKey in project jmonkeyengine by jMonkeyEngine.

the class TestQ3 method simpleInitApp.

public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    flyCam.setMoveSpeed(100);
    setupKeys();
    this.cam.setFrustumFar(2000);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.clone().multLocal(2));
    dl.setDirection(new Vector3f(-1, -1, -1).normalize());
    rootNode.addLight(dl);
    AmbientLight am = new AmbientLight();
    am.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(am);
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("quake3level.zip", ZipLocator.class);
    }
    // create the geometry and attach it
    MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
    OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
    gameLevel = (Node) assetManager.loadAsset(key);
    gameLevel.setLocalScale(0.1f);
    // add a physics control, it will generate a MeshCollisionShape based on the gameLevel
    gameLevel.addControl(new RigidBodyControl(0));
    player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);
    player.setPhysicsLocation(new Vector3f(60, 10, -60));
    rootNode.attachChild(gameLevel);
    getPhysicsSpace().addAll(gameLevel);
    getPhysicsSpace().add(player);
}
Also used : PhysicsCharacter(com.jme3.bullet.objects.PhysicsCharacter) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) BulletAppState(com.jme3.bullet.BulletAppState) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) MaterialList(com.jme3.material.MaterialList) OgreMeshKey(com.jme3.scene.plugins.ogre.OgreMeshKey) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) AmbientLight(com.jme3.light.AmbientLight)

Example 3 with OgreMeshKey

use of com.jme3.scene.plugins.ogre.OgreMeshKey in project jmonkeyengine by jMonkeyEngine.

the class MeshLoader method load.

public Object load(AssetInfo info) throws IOException {
    try {
        key = info.getKey();
        meshName = key.getName();
        folderName = key.getFolder();
        String ext = key.getExtension();
        meshName = meshName.substring(0, meshName.length() - ext.length() - 1);
        if (folderName != null && folderName.length() > 0) {
            meshName = meshName.substring(folderName.length());
        }
        assetManager = info.getManager();
        if (key instanceof OgreMeshKey) {
            // OgreMeshKey is being used, try getting the material list
            // from it
            OgreMeshKey meshKey = (OgreMeshKey) key;
            materialList = meshKey.getMaterialList();
            String materialName = meshKey.getMaterialName();
            // Material list not set but material name is available
            if (materialList == null && materialName != null) {
                OgreMaterialKey materialKey = new OgreMaterialKey(folderName + materialName + ".material");
                try {
                    materialList = (MaterialList) assetManager.loadAsset(materialKey);
                } catch (AssetNotFoundException e) {
                    logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { materialKey, key });
                }
            }
        } else {
            // Make sure to reset it to null so that previous state
            // doesn't leak onto this one
            materialList = null;
        }
        // default method.
        if (materialList == null) {
            OgreMaterialKey materialKey = new OgreMaterialKey(folderName + meshName + ".material");
            try {
                materialList = (MaterialList) assetManager.loadAsset(materialKey);
            } catch (AssetNotFoundException e) {
                logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { materialKey, key });
            }
        }
        // Added by larynx 25.06.2011
        // Android needs the namespace aware flag set to true                 
        // Kirill 30.06.2011
        // Now, hack is applied for both desktop and android to avoid
        // checking with JmeSystem.
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        InputStreamReader r = null;
        try {
            r = new InputStreamReader(info.openStream());
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return compileModel();
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");
        ioEx.initCause(ex);
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 4 with OgreMeshKey

use of com.jme3.scene.plugins.ogre.OgreMeshKey in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method parseEntity.

private void parseEntity(Attributes attribs) throws SAXException {
    String name = attribs.getValue("name");
    if (name == null) {
        name = "OgreEntity-" + (++nodeIdx);
    } else {
        name += "-entity";
    }
    String meshFile = attribs.getValue("meshFile");
    if (meshFile == null) {
        throw new SAXException("Required attribute 'meshFile' missing for 'entity' node");
    }
    // TODO: Not currently used
    String materialName = attribs.getValue("materialName");
    if (folderName != null) {
        meshFile = folderName + meshFile;
    }
    // NOTE: append "xml" since its assumed mesh files are binary in dotScene
    meshFile += ".xml";
    entityNode = new com.jme3.scene.Node(name);
    OgreMeshKey meshKey = new OgreMeshKey(meshFile, materialList);
    try {
        try {
            Spatial ogreMesh = (Spatial) meshLoader.load(assetManager.locateAsset(meshKey));
            entityNode.attachChild(ogreMesh);
        } catch (IOException e) {
            throw new AssetNotFoundException(meshKey.toString());
        }
    } catch (AssetNotFoundException ex) {
        if (ex.getMessage().equals(meshFile)) {
            logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { meshKey, key });
            // Attach placeholder asset.
            Spatial model = PlaceholderAssets.getPlaceholderModel(assetManager);
            model.setKey(key);
            entityNode.attachChild(model);
        } else {
            throw ex;
        }
    }
    node.attachChild(entityNode);
    node = null;
}
Also used : Spatial(com.jme3.scene.Spatial) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

DirectionalLight (com.jme3.light.DirectionalLight)2 Vector3f (com.jme3.math.Vector3f)2 Spatial (com.jme3.scene.Spatial)2 OgreMeshKey (com.jme3.scene.plugins.ogre.OgreMeshKey)2 IOException (java.io.IOException)2 SAXException (org.xml.sax.SAXException)2 BulletAppState (com.jme3.bullet.BulletAppState)1 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)1 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)1 PhysicsCharacter (com.jme3.bullet.objects.PhysicsCharacter)1 AmbientLight (com.jme3.light.AmbientLight)1 PointLight (com.jme3.light.PointLight)1 MaterialList (com.jme3.material.MaterialList)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Geometry (com.jme3.scene.Geometry)1 OgreMaterialKey (com.jme3.scene.plugins.ogre.matext.OgreMaterialKey)1 Sphere (com.jme3.scene.shape.Sphere)1 InputStreamReader (java.io.InputStreamReader)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1