又名我可以有一个3d场景,是在前面的主要场景,而不是它被剪裁。
又名我的武器前面一直被我游戏中的场景所隐藏
情况
我有一个3d场景,由JMonkey渲染,另外还有由玩家持有的3d武器。此外,玩家可能站在离墙很近的地方,以至于(如果现实地对待)他们可能会把枪的末端穿过墙。这意味着,如果枪被放置在场景中“经过推算”,所以它看起来是正确的,那么枪的末端就会被剪掉,看起来很愚蠢。
因为这是一个3d对象(可以旋转或移动),所以我不能只使用2d图像并将其放入gui层。
发布于 2021-11-05 10:18:40
创建额外的摄像头和视口以支持这些额外的图形
在JMonkeyEngine中,可以有多个视口,并将它们叠加在一起以提供所描述的效果。每个视口在内部都是3d的,但视口本身相互叠加。
代码示例
用于设置内容的主类
public class Example extends SimpleApplication {
public static void main(String[] args){
Example app = new Example();
app.start(); // start the game
}
@Override
public void simpleInitApp() {
//this represents the "real world" in this example
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
this.stateManager.attach(new UnderGui());
}
}UnderGui层,在gui层和主3d场景之间具有3d场景。
/**
* The under gui is for things like the held tool. Things that are kind of 3d but also want to be "over" everything
* else
*/
public class UnderGui extends AbstractAppState {
private Node root;
public UnderGui() {
}
@Override
public void initialize(AppStateManager stateManager, Application app )
{
root = new Node( "Under gui viewport Root" );
Camera originalCam = app.getCamera();
Camera cam = new Camera(originalCam.getWidth(), originalCam.getHeight());
//the default camera is an orthoganal camera, use the main cam to copy sensible camera properties
cam.setParallelProjection(originalCam.isParallelProjection());
cam.setFrustum(originalCam.getFrustumNear(), originalCam.getFrustumFar(), originalCam.getFrustumLeft(), originalCam.getFrustumRight(),originalCam.getFrustumTop(), originalCam.getFrustumBottom() );
cam.setFov(originalCam.getFov());
//camera is looking in a +Z direction. -X is right, +X is left. +Y is up
ViewPort view = app.getRenderManager().createMainView("Under gui ViewPort", cam);
view.setEnabled(true);
view.setClearFlags(false, true, false);
view.attachScene( root );
root.attachChild(createWeapon(app.getAssetManager()));
}
/**
* This just creates a red box to be a "weapon" as an example
* @return
*/
private Geometry createWeapon(AssetManager assetManager){
Box b = new Box(1, 1, 1); // create cube shape
Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube's material
geom.setLocalTranslation(-2,0,2);
return geom;
}
@Override
public void render(RenderManager rm) {
root.updateGeometricState();
}
@Override
public void update( float tpf ) {
root.updateLogicalState(tpf);
}
}这也可以用于任何“透过墙壁的能力”覆盖
另一个糟糕的解决方案;setDepthTest
你也可以把武器放在主场景中,然后设置geometry.getMaterial().getAdditionalRenderState().setDepthTest(false);。然而,这是一个不太好的选择,因为它需要武器随着相机位置和方向的变化而不断移动,并且只能处理“简单的”3D覆盖,就好像武器的一个部分在另一个部分的前面(例如,库存在触发器之前),呈现的比特是随机的,因为您已经要求JME不做任何深度测试
https://stackoverflow.com/questions/69851702
复制相似问题