[SOLVED] Need help with scaled mesh and set origin and rotations

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NullPointer

Hi i try to create a Multimesh like a wall with size of (1,1,0.2) as a single mesh and use them to draw walls in different directions.

	var multiMesh = MultiMesh.new()
	multiMesh.transform_format = MultiMesh.TRANSFORM_3D
	multiMesh.mesh = CubeMesh.new()
	multiMesh.mesh.size = Vector3(1,1,.2)
	multiMesh.color_format = MultiMesh.COLOR_FLOAT
	multiMesh.mesh.material = SpatialMaterial.new()
	multiMesh.mesh.material.vertex_color_use_as_albedo = true
	multiMesh.set_instance_color(0, Color.red)
	multiMesh.set_instance_color(1, Color.blue)
	multiMesh.set_instance_color(2, Color(.5,0,0,1))
	multiMesh.set_instance_color(3, Color(0,0,.5, 1))

	var mmi = MultiMeshInstance.new()
	mmi.multimesh = multiMesh;
	var t0 = Transform().rotated(Vector3(0,1,0), deg2rad(0))
	t0.origin = Vector3(0, 0, 0)
	var b = Basis().rotated(Vector3(0,1,0), deg2rad(90))
	var t1 = Transform(b,Vector3(0, 0, 0) )
	multiMesh.set_instance_transform(0, t0)
	multiMesh.set_instance_transform(1, t1)

The problem is original mesh position needs to fixed by mmi.translate(Vector3(.5,.5,.1)) to place the wall in the top line of the space (1,1)

When i try to reuse with the multimesh i apply the rotation related to the wall direction deg 0 for top horizontal
deg 90 for right vertical
deg 180 for bottom horizontal
deg 270 for left vertical

When i apply the transform to the mesh instance the mesh is wrong placed.
The picture shows the problem, on the left the blue wall is missplaced and should be placed like the example on the right side.
enter image description here
Looks like i need to set the center of the original mesh back to 0,5, 0.5 to get correct result.
The wall is just an example i have different mesh types.
What i doing wrong?

:bust_in_silhouette: Reply From: NullPointer

Hi all, after reading and understanding the Godot documentation i found my own solution

func set_instance_transform( meshIndex, origin:Vector3, degrees:int):
	var v:Vector3 =  assert_size/2 - translation
	var b = transform.basis.rotated(Vector3(0,1,0), deg2rad(degrees))
	var t = Transform(b, v).translated(v)
	t.origin += origin
	multimesh.set_instance_transform(meshIndex, t)