【问题标题】:Why will my geometry not appear? (jMonkeyEngine)为什么我的几何图形不会出现? (jMonkeyEngine)
【发布时间】:2015-06-13 20:23:43
【问题描述】:

我刚刚开始使用 jMonkeyEngine,但遇到了一个我似乎无法解决的问题。

在主类的simpleInitApp方法中,我可以使用下面的代码成功渲染一个盒子:

    Box playerBase = new Box(Vector3f.ZERO,1f,1f,1f);
    Geometry playerBaseGeom = new Geometry("playerBase", playerBase);
    Transform fixBaseHeight = new Transform(
            new Vector3f(0f,(0.5f * 2f),0f));
    playerBaseGeom.setLocalTransform(fixBaseHeight);
    Material playerBaseMaterial = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    playerBaseMaterial.setColor("Color", ColorRGBA.Yellow);
    playerBaseGeom.setMaterial(playerBaseMaterial);
    rootNode.attachChild(playerBaseGeom);

我尝试使用一个名为Tower 的类来生成几个代表塔的盒子(用于简单的塔防游戏)。塔类如下所示:

public class Tower {

    private static final float HEIGHT = 0.5f;
    private static final float WIDTH = 0.2f;
    private static final float DEPTH = 0.2f;

    private Geometry towerGeom;
    private Material towerMaterial;
    private Box tower;

    public Tower(AssetManager assetManager, float x_coord, float z_coord) {

        tower = new Box();
        towerGeom = new Geometry("tower", tower);
        towerMaterial = new Material(assetManager,
                "Common/MatDefs/Misc/Unshaded.j3md");
        towerMaterial.setColor("Color", ColorRGBA.Green);
        towerGeom.setMaterial(towerMaterial);

        towerGeom.setLocalTranslation(x_coord, (0.5f * .5f),z_coord);
        towerGeom.setLocalScale(WIDTH, HEIGHT, DEPTH);
    }

    public Geometry getGeometry() {
        return towerGeom;
    }
}

在主类中,在simpleInitApp 方法中,我尝试像这样使用我的新Tower 类:

    List <Tower> towers = new ArrayList<Tower>();
    towers.add(new Tower(assetManager, 10f,8f));
    for(Tower t:towers) {
        rootNode.attachChild(t.getGeometry());
    }

但是,没有渲染立方体。为什么?我使用了与开头显示的完全相同的程序,它奏效了。

【问题讨论】:

  • 别忘了照明。

标签: java 3d jmonkeyengine


【解决方案1】:

Box() 构造函数仅用于序列化,不会初始化网格。上例中的构造函数已弃用。使用:

tower = new Box(0.5f, 0.5f, 0.5f);

这将创建一个大小为 1x1x1 的立方体,以 [0, 0, 0] 为中心。

另外,一定要看看塔。使用默认相机位置和 [10, 0, 8] 的塔,它将被放置在您身后。

getCamera().lookAt( new Vector3f(10f, 0, 8f), Vector3f.UNIT_Y );

我建议您查阅 jME 源代码来解决此类问题,这样您就可以确定发生了什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多