Hey guys,
I’ve spent the last few days trying to figure out how to get some of the tougher world forge models to play nice with the JME asetpack system.
After a few attempts I was able to get the previously unavailable assets working with the browser.
(Though it is far from completion)
I feel like I have the more important models in at this point except the human builder ones.
Unfortunately many of the models were not able to be imported with alpha discard threshold intact.
But there is a simple fix.
Once you add the models to the project you can simply edit the model in the scene composer and run this app state:
package mygame;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.material.RenderState;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.SceneGraphVisitor;
import com.jme3.scene.Spatial;
/**
*
* @author bob
*/
public class AlphaDiscarder extends AbstractAppState {
@Override
public void initialize(AppStateManager stateManager, Application app) {
discardAlpha(((SimpleApplication) app).getRootNode());
}
private Node discardAlpha(Node node) {
SceneGraphVisitor sgv = new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
if (spatial instanceof Geometry) {
((Geometry) spatial).getMaterial().setFloat("AlphaDiscardThreshold", 0.5f);
((Geometry) spatial).getMaterial().getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
}
}
};
node.depthFirstTraversal(sgv);
return node;
}
}
Then save the model.
Here is an example:
Before:
After:
These assets are very good and many contain normal and shadow maps. They are also extremely low vertice in many cases and can be used on Android.
This is under free software license and a copy is contained within.
The asset pack is available here.
If you have any questions or suggestions feel free to ask.
Thanks for reading,
BigBob