gpt4 book ai didi

libgdx - 渲染 3d .g3db 模型时出现空白屏幕 [libgdx]

转载 作者:行者123 更新时间:2023-12-05 01:35:09 26 4
gpt4 key购买 nike

我一直在尝试在我的屏幕上显示一个模型(一个来自 Blender 的简单 UVSphere)。我首先将其导出为 .fbx 格式,然后使用 gdx-conv-win32.exe 转换为 .g3db 格式。到目前为止,我有这段代码,但它向我显示的只是一个空白的黑屏......它仅适用于本教程中找到的模型(.obj 模型)https://xoppa.github.io/blog/loading-models-using-libgdx/

package com.mygdx.game.screens;

/.../ imports

public class GameScreen extends MenuScreens {

public Environment environment;
public PerspectiveCamera cam;
public CameraInputController camController;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;

AssetManager manager = new AssetManager();
public boolean loading;
public Array<ModelInstance> instances;

public GameScreen(ProjectSurvival game){
super();
this.game = game;

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.9f, 0.9f, 0.9f, 20f, 20f, 20f));
environment.add(new PointLight().set(1, 1, 1, 20, 20, 20, 500));
instances = new Array<ModelInstance>();

cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(1f, 1f, 1f);
cam.lookAt(0,0,0);
cam.near = 1f;
cam.far = 300f;
cam.update();

camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);

manager = new AssetManager();
manager.load("ship.g3db", Model.class);
loading = true;
}

private void doneLoading() {
Model test = manager.get("ship.g3db", Model.class);
ModelInstance shipInstance = new ModelInstance(test);
instances.add(shipInstance);
loading = false;
}

@Override
public void show() {
}

@Override
public void render(float delta) {
//super.render(delta);

if (loading && manager.update()) {
doneLoading();
System.out.println("loaded");
}
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(instances, environment);
modelBatch.end();
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
super.dispose();
modelBatch.dispose();
model.dispose();
instances.clear();
manager.dispose();
}

}

还有其他几个类似的主题,但没有一个能解决我的问题......请我需要帮助!

编辑:

这是我的 g3dj 文件(我剪掉了它的一些部分,因为它很长):
{
"version": [ 0, 1],
"id": "",
"meshes": [
{
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
"vertices": [
-0.724124, 0.035572, -0.598984, -0.742302, -0.159337, -0.650807, 0.028780, 0.420519,
-0.691568, 0.068115, -0.634070, -0.791498, -0.084201, -0.605335, 0.021021, 0.407816,
-0.694079, 0.034096, -0.634070, -0.878414, 0.254219, -0.404614, 0.026918, 0.405321,
// deleted (...)
-0.846887, -0.041603, -0.403719, -0.887509, -0.132389, -0.441267, 0.051316, 0.489956,
-0.826199, -0.040587, -0.445113, -0.867977, -0.072359, -0.491256, 0.049283, 0.474874,
-0.803523, -0.039472, -0.485435, -0.859127, -0.022919, -0.511185, 0.047232, 0.459797
],
"parts": [
{
"id": "Mesh_part1",
"type": "TRIANGLES",
"indices": [
0, 1, 2, 1, 0, 3, 4, 2, 5, 2, 4, 0,
2, 6, 7, 6, 2, 1, 5, 7, 8, 7, 5, 2,
0, 9, 3, 3, 9, 10, 9, 11, 10, 11, 9, 12,
9, 4, 13, 4, 9, 0, 12, 13, 14, 13, 12, 9,
// deleted (...)
3610, 3613, 3614, 137, 3614, 3613, 3614, 137, 133, 3606, 3612, 3596,
3612, 3606, 3613, 112, 3613, 3606, 3613, 112, 137, 3614, 3608, 3610,
3608, 3614, 3615, 3615, 3539, 3608, 3539, 3615, 3543, 133, 3615, 3614,
3615, 133, 134, 134, 3543, 3615, 3543, 134, 14
]
}
]
}
],
"materials": [
{
"id": "Material.001",
"ambient": [ 0.200000, 0.200000, 0.200000],
"diffuse": [ 0.800000, 0.800000, 0.800000],
"emissive": [ 0.000000, 0.000000, 0.000000],
"opacity": 0.000000,
"specular": [ 0.200000, 0.200000, 0.200000],
"shininess": 20.000000
}
],
"nodes": [
{
"id": "Sphere",
"rotation": [-0.707107, 0.000000, 0.000000, 0.707107],
"scale": [ 100.000000, 100.000000, 100.000000],
"translation": [ 0.000000, 101.334976, 0.000000],
"parts": [
{
"meshpartid": "Mesh_part1",
"materialid": "Material.001",
"uvMapping": [[]]
}
]
}
],
"animations": []

}

最佳答案

由于没有公认的答案:

如@Xoppa 所述,在您的文件中,不透明度设置为零,在 gd3j 文件中将其设置为 1.0000

"opacity":  0.000000

//TODO 1: 在 blender 中找到 Material 的属性是什么

//TODO 2:添加到故障排除指南

关于libgdx - 渲染 3d .g3db 模型时出现空白屏幕 [libgdx],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40245325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com