我正在将一个简单的three.js场景转换为libgdx。一切都加载并运行良好,但似乎我的对象的UV纹理坐标未正确应用?我使用.obj / .mtl来表示模型和纹理。我知道在教程中声明在生产中应该使用.g3db格式与.obj格式,我打算这样做,但我仍然很好奇为什么纹理没有正确映射到我的.objs?有没有人见过这种事发生过?我只是错过了一些东西吗?
LIBGDX
THREEJS
package com.freedom.thirty;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.graphics.FPSLogger;
public class FreedomThirty implements ApplicationListener {
public PerspectiveCamera cam;
public CameraInputController camController;
public ModelBatch modelBatch;
public AssetManager assets;
public Array<ModelInstance> allModelInstances = new Array<ModelInstance>();
public Environment environment;
public boolean loading;
public Array<ModelInstance> players = new Array<ModelInstance>();
public ModelInstance player;
public ModelInstance board;
public ModelInstance skybox;
public FPSLogger theLogger = new FPSLogger();
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(-4f, 4f, 4f);
cam.lookAt(5f, 0f, -5f);
cam.near = 1f;
cam.far = 1000f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
assets = new AssetManager();
assets.load("test_character.obj", Model.class);
assets.load("meter_grid.obj", Model.class);
assets.load("skybox1.obj", Model.class);
loading = true;
}
private void doneLoading(){
skybox = new ModelInstance(assets.get("skybox1.obj", Model.class));
board = new ModelInstance(assets.get("meter_grid.obj", Model.class));
allModelInstances.add(board);
player = new ModelInstance(assets.get("test_character.obj", Model.class));
allModelInstances.add(player);
players.add(player);
loading = false;
}
@Override
public void render() {
if(loading && assets.update()){
doneLoading();
}
camController.update();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
modelBatch.render(allModelInstances, environment);
if(skybox != null){
modelBatch.render(skybox);
}
modelBatch.end();
theLogger.log();
}
@Override
public void dispose() {
modelBatch.dispose();
allModelInstances.clear();
assets.dispose();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}