在此例中实现对外部模型的加载: 用jme再现虎式坦克。下了几个模型发现不能用,打开jar包,plugins目录下,发现jme支持的有fbx,gltf,obj等3d格式,以后才可能会增加对dae等格式的支持的插件,作为一个开源项目,我们也可以为之贡献加载器插件代码。
public class model extends SimpleApplication {
public static void main(String[] args) {
//启动程序
model app=new model();
app.start();
}
@Override
public void simpleInitApp() {
// TODO Auto-generated method stub
cam.setLocation(new Vector3f(0.41600543f,3.2057908f,6.6927643f));
cam.setRotation(new Quaternion(-0.00414816f,0.9817784f,-0.18875499f,-0.021575727f));
flyCam.setMoveSpeed(10);
viewPort.setBackgroundColor(ColorRGBA.LightGray);
//#1 导入模型
Spatial model=assetManager.loadModel("Models/Tank/scene.gltf");
model.scale(0.3f);//按比例缩小
model.center();//将模型的中心移到原点
//#2创造光源
//定向光
DirectionalLight sun=new DirectionalLight();
sun.setDirection(new Vector3f(-1,-2,-3));
//环境光
AmbientLight ambientLight=new AmbientLight();
//调整光照亮度
ColorRGBA lightColor=new ColorRGBA();
sun.setColor(lightColor.mult(0.6f));
ambientLight.setColor(lightColor.mult(0.4f));
//#3 将模型和光源添加到场景图中
rootNode.attachChild(model);
rootNode.addLight(sun);
rootNode.addLight(ambientLight);
}
}
下一步的打算自然是让它跑起来啊,后序更新!!