因此,我将模型转换为.g3db
,并使其正常工作。但是,在对代码LibGDX
进行了非常基本的重构之后,人们抱怨其中存在no loader for type: Model
。
工作代码:
public GameScene(AssetManager assetManager) {
this.assetManager = assetManager;
modelBatch = new ModelBatch();
initEnvironment();
initCamera();
// Here I load the image with the passed assetmanager
loadAssets();
}
private void loadAssets() {
// Following line works
assetManager.load("data/cube.g3db", Model.class);
assetManager.finishLoading();
Model ship = assetManager.get("data/cube.g3db");
ModelInstance shipInstance = new ModelInstance(ship);
instances.add(shipInstance);
}
Afaik我在下面的代码中做的完全一样,我也不知道为什么它失败了。
public DynamicScene(AssetManager assetManager) {
this.assetManager = assetManager;
modelBatch = new ModelBatch();
initEnvironment();
initCamera();
ball = new Ball(assetManager);
}
// Ball constructor
public Ball(AssetManager assetManager) {
this.assetManager = assetManager;
loadModel();
}
private void loadModel() {
// Following line fails
assetManager.load("data/ball.g3dp", Model.class);
// Also fails when loading the same model as working example:
assetManager.load("data/cube.g3dp", Model.class);
assetManager.finishLoading();
Model ball = assetManager.get("data/ball.g3db");
ballModel = new ModelInstance(ball);
ballModel.transform.setToTranslation(0, 10, 0);
}
两个初始类都从主类传递new AssetManager()
到其构造函数。
@Override
public void create () {
//gameScene = new GameScene(new AssetManager());
dynamicScene = new DynamicScene(new AssetManager());
}
切换回工作版本总是成功运行,运行底部版本总是失败。