我正在使用libGDX用Java编写3D游戏。在我的游戏中,有一个房间的模型实例,他的墙壁只是矩形。我正在尝试添加“弹孔”效果,当玩家射击时,“弹孔”只是一种出现在墙上的纹理。我试图弄清楚实现它的最佳方法是什么?显而易见的方法是创建一个模型实例,该实例由具有每个弹孔的孔纹理的单个矩形构建-但是这种方式将对每个孔进行绘制调用,而不是性能方面的AFAIK。>
我创建墙的一段代码:
Texture wallTexture = new Texture(Gdx.files.internal("wall.png"));
wallTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
Material wallMaterial = new Material(TextureAttribute.createDiffuse(wallTexture));
MeshPartBuilder meshBuilder = modelBuilder.part("walls", GL20.GL_TRIANGLES,
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal |
VertexAttributes.Usage.TextureCoordinates, wallMaterial);
meshBuilder.setUVRange(0, 0, C.ROOM_SIZE, 3);
corner00.set(C.ROOM_SIZE, 0, 0);
corner10.set(0, 0, 0);
corner11.set(0, 0, 6);
corner01.set(C.ROOM_SIZE, 0, 6);
normal.set(0, 1, 0);
line1000.setNormalDirection(auxVector2.set(0, 1).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
corner00.set(C.ROOM_SIZE, C.ROOM_SIZE, 0);
corner10.set(C.ROOM_SIZE, 0, 0);
corner11.set(C.ROOM_SIZE, 0, 6);
corner01.set(C.ROOM_SIZE, C.ROOM_SIZE, 6);
normal.set(-1, 0, 0);
line1110.setNormalDirection(auxVector2.set(-1, 0).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
corner00.set(0, C.ROOM_SIZE, 0);
corner10.set(C.ROOM_SIZE, C.ROOM_SIZE, 0);
corner11.set(C.ROOM_SIZE, C.ROOM_SIZE, 6);
corner01.set(0, C.ROOM_SIZE, 6);
normal.set(0, -1, 0);
line0111.setNormalDirection(auxVector2.set(0, -1).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
corner00.set(0, 0, 0);
corner10.set(0, C.ROOM_SIZE, 0);
corner11.set(0, C.ROOM_SIZE, 6);
corner01.set(0, 0, 6);
normal.set(1, 0, 0);
line0001.setNormalDirection(auxVector2.set(1, 0).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
Model levelModel = modelBuilder.end();
levelModelInstance = new ModelInstance(levelModel);
此部分在加载关卡时仅出现一次。弹孔应该出现在游戏中。