so its my first time in the world of 3D development in libgdx
so my first step is loading my initial 3D model, which is a car
this is what my car should like:
but instead it looks like this: (video showing better how glitched is)
so this is my code:
package io.github.rally3d;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Cubemap;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import net.mgsx.gltf.loaders.gltf.GLTFLoader;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
import net.mgsx.gltf.scene3d.lights.DirectionalLightEx;
import net.mgsx.gltf.scene3d.scene.Scene;
import net.mgsx.gltf.scene3d.scene.SceneAsset;
import net.mgsx.gltf.scene3d.scene.SceneManager;
import net.mgsx.gltf.scene3d.scene.SceneSkybox;
import net.mgsx.gltf.scene3d.utils.IBLBuilder;
public class Main extends ApplicationAdapter
{
private SceneManager sceneManager;
private SceneAsset sceneAsset;
private Scene scene;
private PerspectiveCamera camera;
private Cubemap diffuseCubemap;
private Cubemap environmentCubemap;
private Cubemap specularCubemap;
private Texture brdfLUT;
private float time;
private SceneSkybox skybox;
private DirectionalLightEx light;
private FirstPersonCameraController cameraController;
@Override
public void create() {
// create scene
sceneAsset = new GLTFLoader().load(Gdx.files.internal("untitled.gltf"));
scene = new Scene(sceneAsset.scene);
sceneManager = new SceneManager();
sceneManager.addScene(scene);
// setup camera (The BoomBox model is very small so you may need to adapt camera settings for your scene)
camera = new PerspectiveCamera(60f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
float d = .02f;
camera.near = d / 1000f;
camera.far = 2000;
sceneManager.setCamera(camera);
cameraController = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(cameraController);
// setup light
light = new DirectionalLightEx();
light.direction.set(1, -3, 1).nor();
light.color.set(Color.WHITE);
sceneManager.environment.add(light);
// setup quick IBL (image based lighting)
// IBLBuilder iblBuilder = IBLBuilder.createOutdoor(light);
// environmentCubemap = iblBuilder.buildEnvMap(1024);
// diffuseCubemap = iblBuilder.buildIrradianceMap(256);
// specularCubemap = iblBuilder.buildRadianceMap(10);
// iblBuilder.dispose();
// This texture is provided by the library, no need to have it in your assets.
brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png"));
sceneManager.setAmbientLight(0f);
// sceneManager.environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT));
// sceneManager.environment.set(PBRCubemapAttribute.createSpecularEnv(specularCubemap));
// sceneManager.environment.set(PBRCubemapAttribute.createDiffuseEnv(diffuseCubemap));
// setup skybox
// skybox = new SceneSkybox(environmentCubemap);
// sceneManager.setSkyBox(skybox);
}
@Override
public void resize(int width, int height) {
sceneManager.updateViewport(width, height);
}
@Override
public void render() {
float deltaTime = Gdx.graphics.getDeltaTime();
time += deltaTime;
cameraController.update();
scene.modelInstance.transform.rotate(Vector3.Y, 10 * deltaTime)
// render
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
sceneManager.update(deltaTime);
sceneManager.render();
}
@Override
public void dispose() {
sceneManager.dispose();
sceneAsset.dispose();
environmentCubemap.dispose();
diffuseCubemap.dispose();
specularCubemap.dispose();
brdfLUT.dispose();
skybox.dispose();
}
}
Any response will be received ! thanks!!
so its my first time in the world of 3D development in libgdx
so my first step is loading my initial 3D model, which is a car
this is what my car should like: https://sketchfab.com/3d-models/subaru-impreza-90ac9739c6b74a64bcddd10a6f5d029d
but instead it looks like this: https://go.screenpal.com/watch/cTVicInewRW (video showing better how glitched is)
so this is my code:
package io.github.rally3d;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Cubemap;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import net.mgsx.gltf.loaders.gltf.GLTFLoader;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
import net.mgsx.gltf.scene3d.lights.DirectionalLightEx;
import net.mgsx.gltf.scene3d.scene.Scene;
import net.mgsx.gltf.scene3d.scene.SceneAsset;
import net.mgsx.gltf.scene3d.scene.SceneManager;
import net.mgsx.gltf.scene3d.scene.SceneSkybox;
import net.mgsx.gltf.scene3d.utils.IBLBuilder;
public class Main extends ApplicationAdapter
{
private SceneManager sceneManager;
private SceneAsset sceneAsset;
private Scene scene;
private PerspectiveCamera camera;
private Cubemap diffuseCubemap;
private Cubemap environmentCubemap;
private Cubemap specularCubemap;
private Texture brdfLUT;
private float time;
private SceneSkybox skybox;
private DirectionalLightEx light;
private FirstPersonCameraController cameraController;
@Override
public void create() {
// create scene
sceneAsset = new GLTFLoader().load(Gdx.files.internal("untitled.gltf"));
scene = new Scene(sceneAsset.scene);
sceneManager = new SceneManager();
sceneManager.addScene(scene);
// setup camera (The BoomBox model is very small so you may need to adapt camera settings for your scene)
camera = new PerspectiveCamera(60f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
float d = .02f;
camera.near = d / 1000f;
camera.far = 2000;
sceneManager.setCamera(camera);
cameraController = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(cameraController);
// setup light
light = new DirectionalLightEx();
light.direction.set(1, -3, 1).nor();
light.color.set(Color.WHITE);
sceneManager.environment.add(light);
// setup quick IBL (image based lighting)
// IBLBuilder iblBuilder = IBLBuilder.createOutdoor(light);
// environmentCubemap = iblBuilder.buildEnvMap(1024);
// diffuseCubemap = iblBuilder.buildIrradianceMap(256);
// specularCubemap = iblBuilder.buildRadianceMap(10);
// iblBuilder.dispose();
// This texture is provided by the library, no need to have it in your assets.
brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png"));
sceneManager.setAmbientLight(0f);
// sceneManager.environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT));
// sceneManager.environment.set(PBRCubemapAttribute.createSpecularEnv(specularCubemap));
// sceneManager.environment.set(PBRCubemapAttribute.createDiffuseEnv(diffuseCubemap));
// setup skybox
// skybox = new SceneSkybox(environmentCubemap);
// sceneManager.setSkyBox(skybox);
}
@Override
public void resize(int width, int height) {
sceneManager.updateViewport(width, height);
}
@Override
public void render() {
float deltaTime = Gdx.graphics.getDeltaTime();
time += deltaTime;
cameraController.update();
scene.modelInstance.transform.rotate(Vector3.Y, 10 * deltaTime)
// render
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
sceneManager.update(deltaTime);
sceneManager.render();
}
@Override
public void dispose() {
sceneManager.dispose();
sceneAsset.dispose();
environmentCubemap.dispose();
diffuseCubemap.dispose();
specularCubemap.dispose();
brdfLUT.dispose();
skybox.dispose();
}
}
Any response will be received ! thanks!!
This might be an issue with the depth testing. It looks like opengl does not care which object should render in front or behind.
Unfortunately I don't know how the SceneManager renders the object - is this a class you defined that uses the ModelBatch?
My suggestions are:
make sure depth testing is enabled using glEnable(GL_DEPTH_TEST) when rendering
use fbx-conv to convert a 3d model to a libgdx friendly 3d format. You may output a json formatted 3d model and inspect it further, to see if you get what you expect (of course, this is not practical for models more complex than ~a cube).
provide your own shader to libgdx. The default ones can look horrible.
try rendering a simple object, like a cube. If you still see rendering errors, then it's more likely a rendering bug rather than a model import issue / something else.