I want to create a plane of squares color of which I could manipulate. I was told that it can be done using vertex colors. I looked up bunch of tutorials but still can't quite get it. Example is on the picture.
If you use surfacetool you can use add_color()
https://docs.godotengine.org/en/stable/classes/class_surfacetool.html#class-surfacetool-method-add-color
st.add_color("ffffff") > will turn white.
Is the image what you want to achieve or is it what you have now?
Languor image is what i want
Napalm hmmm no i dont. guess gotta try surface tool
So to achieve what is shown in the image you need each quad 'face' to be separate from it's neighbor. I.e. no shared vertices. Split them. Otherwise you end up with smooth gradient across the face via the vertex colors.
Languor Ok i struggled a bit and managed to use a multimesh with script. I want to make each square selectable to some level. Like each square can have an object on it or you should be able to mouse hover on a square and see info popup or something. Fps is not the greatest though. Did you mean some better approach?
using Godot;
using System;
public class squares : MultiMeshInstance
{
private Random rnd;
private const int width = 256;
private const int height = 256;
public override void _Ready()
{
rnd = new Random();
var plane = new PlaneMesh
{
Size = new Vector2(1, 1),
Material = new SpatialMaterial { VertexColorUseAsAlbedo = true }
};
Multimesh = new MultiMesh
{
TransformFormat = MultiMesh.TransformFormatEnum.Transform3d,
ColorFormat = MultiMesh.ColorFormatEnum.Color8bit,
CustomDataFormat = MultiMesh.CustomDataFormatEnum.None,
InstanceCount = width*height,
VisibleInstanceCount = -1,
Mesh = plane
};
int instancesCount = 0;
for (int x = 0; x < width; x++)
{
for (int z = 0; z < height; z++)
{
Multimesh.SetInstanceTransform(instancesCount, new Transform(Basis.Identity, new Vector3(x, 0, z)));
var color = new Color((float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble());
Multimesh.SetInstanceColor(instancesCount, color);
instancesCount++;
}
}
//later colors can be set like that
Multimesh.SetInstanceColor(0, Colors.Purple);
Multimesh.SetInstanceColor(1, Colors.Purple);
Multimesh.SetInstanceColor(2, Colors.Purple);
}
}
result:
Languor yeah im not sure what you are talking about. quad 'face' on what? plane mesh with many faces?
Omidyar plane mesh with many faces?
Any mesh with many faces, but specifying quad face
since gpus can only really render triangles so chances are you might have 2 tris per 1 quad face.
Languor ok but i do not find this information applicable
having all these 'faces' be separate objects can be costly, multimesh certainly helps, but batching them together into groups of many face meshes or 'chunks' can be better for performance.
© 2022 - 2024 — McMap. All rights reserved.