我用以下代码合并了几条甲壳类:
import java.util.ArrayList;
import java.util.Arrays;
import org.obsgolem.crystalia.gfx.Renderer;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import java.util.*;
public class MeshBatch
{
private final static VertexAttribute[] attributeConfig = new VertexAttribute[]{
new VertexAttribute(Usage.Position, 3, "a_position"),
new VertexAttribute(Usage.ColorPacked, 4, "a_color"),
new VertexAttribute(Usage.Normal, 3, "a_normal")};
private final static int VERTEX_SIZE = 3 + 1 + 3;
private Mesh m;
private List<Float> vertices = new ArrayList<Float>();
private List<Short> indices = new ArrayList<Short>();
public void addMesh(float[] vert, short[] ind)
{
int offset = (vertices.size() / VERTEX_SIZE);
//You have to throw an exception when you get over the limit of short indices
if (offset + vert.length / VERTEX_SIZE > Short.MAX_VALUE) {
throw new RuntimeException("blablabla");
}
for (short i : addOffset(ind, offset)) {
indices.add(i);
}
for (float v : vert) {
vertices.add(v);
}
}
public short[] addOffset(short[] ind, int offset)
{
short[] indarr = new short[ind.length];
for (int i = 0; i < ind.length; ++i) {
//Do you really need this check? You are the only one using this code
//so make sure that you never provide a null value. If you really want to have a chekc throw an exception instead
short value = ind[i];//ind[i] == null ? 0 : ind[i];
indarr[i] = (short) (value + offset);
}
return indarr;
}
public void end()
{
m = new Mesh(false, vertices.size(), indices.size(), attributeConfig);
m.setVertices(Renderer.makeFloatArray(vertices));
m.setIndices(Renderer.makeShortArray(indices));
}
public void render()
{
Renderer.getInstance().render(m);
}
}
然而,当我使用这个类来画时, 我得到与照明有关的奇怪效果。 有了这个网格, 所有其他物体的灯光都更亮了, 而用光线制作的灯光看起来是平的。 用正常的方式( 每件物体的光线) 我得到光滑的光滑。 我拍了两个截图 :
With merged mesh:
Without merged mesh:
是什么导致了这个问题, 以及它如何影响另一个网格的照明? 我的顶部是用正确的格式发送的( 3个顶部的浮点, 1个颜色的浮点, 3个正常的浮点 ) 。 我的指数也在起作用 。 问题只有在网格实际形成时才出现 。 没有光线,问题就会发生 完美。 我认为问题与正常有关, 但我无法找到问题所在 。
Edit: I think I have mixed the problem. 当我把瓷砖从使用隔膜换成用隔膜换成固定的照明时, 怎么会这样呢?