Search in sources :

Example 1 with MaterialList

use of com.jme3.material.MaterialList in project jmonkeyengine by jMonkeyEngine.

the class MTLLoader method load.

@SuppressWarnings("empty-statement")
public Object load(AssetInfo info) throws IOException {
    reset();
    this.key = info.getKey();
    this.assetManager = info.getManager();
    folderName = info.getKey().getFolder();
    matList = new MaterialList();
    InputStream in = null;
    try {
        in = info.openStream();
        scan = new Scanner(in);
        scan.useLocale(Locale.US);
        while (readLine()) ;
    } finally {
        if (in != null) {
            in.close();
        }
    }
    if (matName != null) {
        // still have a material in the vars
        createMaterial();
        resetMaterial();
    }
    MaterialList list = matList;
    return list;
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) MaterialList(com.jme3.material.MaterialList)

Example 2 with MaterialList

use of com.jme3.material.MaterialList 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 MaterialList

use of com.jme3.material.MaterialList in project jmonkeyengine by jMonkeyEngine.

the class MeshLoader method applyMaterial.

private void applyMaterial(Geometry geom, String matName) {
    Material mat = null;
    if (matName == null) {
        // no material specified. use placeholder.
        mat = null;
    } else if (matName.endsWith(".j3m")) {
        // load as native jme3 material instance
        try {
            mat = assetManager.loadMaterial(matName);
        } catch (AssetNotFoundException ex) {
            // Warning will be raised (see below)
            if (!ex.getMessage().equals(matName)) {
                throw ex;
            }
        }
    } else {
        if (materialList != null) {
            mat = materialList.get(matName);
        }
    }
    if (mat == null) {
        logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { matName, key });
        mat = PlaceholderAssets.getPlaceholderMaterial(assetManager);
    //mat.setKey(new MaterialKey(matName));
    }
    if (mat.isTransparent()) {
        geom.setQueueBucket(Bucket.Transparent);
    }
    geom.setMaterial(mat);
}
Also used : Material(com.jme3.material.Material)

Example 4 with MaterialList

use of com.jme3.material.MaterialList in project jmonkeyengine by jMonkeyEngine.

the class SceneMaterialLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("externals")) {
        checkTopNode("scene");
        // Has an externals block, create material list.
        materialList = new MaterialList();
    } else if (qName.equals("item")) {
        checkTopNode("externals");
        if (!attribs.getValue("type").equals("material")) {
            // This is not a material external. Ignore it.
            ignoreItem = true;
        }
    } else if (qName.equals("file")) {
        checkTopNode("item");
        if (!ignoreItem) {
            String materialPath = attribs.getValue("name");
            String materialName = new File(materialPath).getName();
            String matFile = folderName + materialName;
            try {
                MaterialList loadedMaterialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(matFile));
                materialList.putAll(loadedMaterialList);
            } catch (AssetNotFoundException ex) {
                logger.log(Level.WARNING, "Cannot locate material file: {0}", matFile);
            }
        }
    }
    elementStack.push(qName);
}
Also used : MaterialList(com.jme3.material.MaterialList) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) File(java.io.File)

Example 5 with MaterialList

use of com.jme3.material.MaterialList in project jmonkeyengine by jMonkeyEngine.

the class MaterialExtensionLoader method load.

public MaterialList load(AssetManager assetManager, AssetKey key, MaterialExtensionSet matExts, List<Statement> statements) throws IOException {
    this.assetManager = assetManager;
    this.matExts = matExts;
    this.key = key;
    list = new MaterialList();
    for (Statement statement : statements) {
        if (statement.getLine().startsWith("import")) {
            // ignore
            continue;
        } else if (statement.getLine().startsWith("material")) {
            Material material = readExtendingMaterial(statement);
            list.put(matName, material);
            List<String> matAliases = matExts.getNameMappings(matName);
            if (matAliases != null) {
                for (String string : matAliases) {
                    list.put(string, material);
                }
            }
        }
    }
    return list;
}
Also used : Statement(com.jme3.util.blockparser.Statement) MaterialList(com.jme3.material.MaterialList) Material(com.jme3.material.Material) List(java.util.List) MaterialList(com.jme3.material.MaterialList)

Aggregations

MaterialList (com.jme3.material.MaterialList)5 OgreMaterialKey (com.jme3.scene.plugins.ogre.matext.OgreMaterialKey)4 IOException (java.io.IOException)4 Material (com.jme3.material.Material)3 SAXException (org.xml.sax.SAXException)3 Statement (com.jme3.util.blockparser.Statement)2 InputStreamReader (java.io.InputStreamReader)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)1 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 DirectionalLight (com.jme3.light.DirectionalLight)1 Vector3f (com.jme3.math.Vector3f)1 Spatial (com.jme3.scene.Spatial)1