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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations