2

我试图通过创建彼此相邻的 4 个立方体来渲染墙壁,应用纹理时出现问题 - JME3 确实渲染了立方体并应用了纹理,但我看到了立方体的内部。这是我可以改变的某种形式的“视图”吗?如果是这样,怎么做?

下面是我的意思的代码和图像在此处输入图像描述

    Box ground = new Box(new Vector3f(1.0f, -1.0f, 1.0f), 5, 0,-5);
    Geometry groundPlane = new Geometry("GroundPlane", ground);
    Material groundMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    groundMat.setColor("Color", ColorRGBA.Brown);
    groundPlane.setMaterial(groundMat);

    for(int i = 1; i < 5; i++)
    {
        Box wall = new Box(new Vector3f(0.0f, -1.0f, 0.0f), new Vector3f((float)i, 0.0f, -1.0f));
        Geometry wallFace = new Geometry("WallMesh", wall);
        Material wallSkin = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        Texture tex_ml = assetManager.loadTexture("Interface/Wall.png");
        wallSkin.setTexture("ColorMap", tex_ml);
        wallFace.setMaterial(wallSkin);
        rootNode.attachChild(wallFace);            
    }

    rootNode.attachChild(groundPlane);      

亲切的问候

艾登·斯特莱多姆

完成 - 最终代码

    Vector3f oldVec = Vector3f.ZERO;
    Vector3f newVec = Vector3f.ZERO;

    for(int i = 0; i < 5; i++)
    {
        newVec = new Vector3f((float)i, 0.0f, 0.0f);
        Box wall = new Box(oldVec, newVec);
        Geometry wallFace = new Geometry("WallMesh", wall);
        Material wallSkin = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        wallSkin.setTexture("ColorMap", tex_ml);
        wallFace.setMaterial(wallSkin);
        //wallSkin.getAdditionalRenderState().setWireframe(true);
        oldVec = new Vector3f((float)i, -1.0f, -1.0f);
        rootNode.attachChild(wallFace);            
    }

    rootNode.attachChild(groundPlane);   

在此处输入图像描述

4

2 回答 2

3

看起来你的法线指向相反的方向。检查您的渲染引擎以查看您是否具有反向法线功能,或者您需要以相反的顺序提供顶点。

或者试试这个方法

Box wall = new Box(new Vector3f(i, 0.0f, 0.0f), 1.0f, 1.0f, 1.0f);
于 2012-05-26T08:21:32.743 回答
0

这个Box类是你自己的,还是 jmonkey 提供的?

如果它是你自己的,你的三角形缠绕顺序似乎会被翻转。

于 2012-05-25T14:06:49.437 回答