Squared plane
Asked Answered
O

10

0

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.

Omidyar answered 30/8, 2022 at 16:1 Comment(0)
N
0

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.

Napalm answered 30/8, 2022 at 16:40 Comment(0)
L
0

Is the image what you want to achieve or is it what you have now?

Languor answered 30/8, 2022 at 17:32 Comment(0)
O
0

Languor image is what i want

Omidyar answered 30/8, 2022 at 17:54 Comment(0)
O
0

Napalm hmmm no i dont. guess gotta try surface tool

Omidyar answered 30/8, 2022 at 17:54 Comment(0)
L
0

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 answered 30/8, 2022 at 18:10 Comment(0)
O
0

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:

Omidyar answered 31/8, 2022 at 11:12 Comment(0)
O
0

Languor yeah im not sure what you are talking about. quad 'face' on what? plane mesh with many faces?

Omidyar answered 31/8, 2022 at 11:53 Comment(0)
L
0

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 answered 31/8, 2022 at 14:35 Comment(0)
O
0

Languor ok but i do not find this information applicable

Omidyar answered 31/8, 2022 at 15:18 Comment(0)
L
0

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.

Languor answered 31/8, 2022 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.