Hi there!
Recently I’ve been trying to add vertex colors and remove any UVs (simply because I don’t need them). So I thought about creating a custom mesh. I read all the tutorial but I get an error with the VertexColor material.
This is my error:
GRAVE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.asset.AssetLoadException: VertexColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.
at com.jme3.material.plugins.J3MLoader.loadFromScanner(J3MLoader.java:513)
at com.jme3.material.plugins.J3MLoader.load(J3MLoader.java:594)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:240)
at com.jme3.material.Material.(Material.java:124)
at mygame.TEST2.simpleInitApp(TEST2.java:101)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:124)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:200)
at java.lang.Thread.run(Thread.java:662)
and this is my code:
[java]HillHeightMap heightmap = null;
try {
heightmap = new HillHeightMap(513, 1000, 50, 100);
} catch (Exception ex) {
ex.printStackTrace();
}
mesh = new Mesh();
// Setup map avec vertexcolor
float[] buffer = heightmap.getHeightMap();
int sqrt = (int)Math.sqrt(buffer.length);
// Vertices
Vector3f[] vertices = new Vector3f[buffer.length];
for(int x = 0; x < sqrt; x++)
for(int z = 0; z < sqrt; z++)
{
vertices[(x * sqrt) + z] = new Vector3f(x, buffer[(x * sqrt) + z], z); // !!!!!!!
}
buffer = null;
// Indices
int[] indices = new int[(sqrt - 1) * (sqrt - 1) * 6];
int counter = 0;
for (int y = 0; y < sqrt - 1; y++)
{
for (int x = 0; x < sqrt - 1; x++)
{
int lowerLeft = x + y*sqrt;
int lowerRight = (x + 1) + y*sqrt;
int topLeft = x + (y + 1) * sqrt;
int topRight = (x + 1) + (y + 1) * sqrt;
indices[counter++] = topLeft;
indices[counter++] = lowerRight;
indices[counter++] = lowerLeft;
indices[counter++] = topLeft;
indices[counter++] = topRight;
indices[counter++] = lowerRight;
}
}
// Colors
float[] colors = new float[vertices.length * 4];
for(int i = 4; i < vertices.length * 4; i = i + 4)
{
if(vertices.y > 75)
{
colors = 1; // R
colors = 1; // G
colors = 1; // B
colors = 1; // A 1 = opaque, 0 = fully transparent
}
else
{
colors = 1; // R
colors = 0; // G
colors = 1; // B
colors = 1; // A 1 = opaque, 0 = fully transparent
}
}
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.Color, 2, BufferUtils.createFloatBuffer(colors));
mesh.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indices));
mesh.updateBound();
Geometry coloredMesh = new Geometry ("ColoredMesh", mesh);
Material matVC = new Material(assetManager, "Common/MatDefs/Misc/VertexColor.j3md");
coloredMesh.setMaterial(matVC);
rootNode.attachChild(coloredMesh);[/java]
Thank you for your help! :)