godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add center_offset and rotation properties to BoxMesh. #10248

Open tx350z opened 3 months ago

tx350z commented 3 months ago

Describe the project you are working on

Generated large static geometry containing many PlaneMesh and BoxMesh instances.

Describe the problem or limitation you are having in your project

PlaneMesh has center_offset and orientation properties which allows creating up to 256 PlaneMeshes in an ArrayMesh which is rendered using a single MeshInstance3D.

The only way to position and rotate a BoxMesh seems to be with a separate MeshInstance3D.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add center_offset(offset:Vector3) and rotation(rot:Vector3) properties to BoxMesh so that multiple BoxMesh instances can be added to a single ArrayMesh.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

var mi:MeshInstance3D = MeshInstance3D.new();

var am:ArrayMesh = ArrayMesh.new();

var bm:BoxMesh = BoxMesh.new();
bm.center_offset = offset1;
bm.rotation = rotation1;
am.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, bm.get_mesh_arrays());

bm = BoxMesh.new();
bm.center_offset = offset2;
bm.rotation = rotation2;
am.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, bm.get_mesh_arrays());

mi.mesh = am;

add_child(mi);

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not that I can think of.

Is there a reason why this should be core and not an add-on in the asset library?

It requires a change to a built-in class.

AThousandShips commented 3 months ago

I don't think a rotation for a box mesh is really comparable with the orientation of a plane mesh, the plane mesh orientation dictates the direction is faces, not a detailed rotation, for a box mesh the orientation is irrelevant as it looks the same when rotated in 90 degree increments, unlike the plane mesh

None of the other primitives have any orientation either, and I'd say that if any should get it it wouldn't be box mesh, but torus and cylinders for example which do have more relevant orientation

Also if you just want to add based on transform you can just use SurfaceTool.append_from with a relevant transform with your specific primitive mesh

tx350z commented 3 months ago

I guess mentioning PlaneMesh.orientation as a form of rotation (which it is) confused you. I've removed the reference.

BoxMesh.rotation will be beneficial to my needs, not sure about yours.

Can't make a recommendation for other primitives since I'm not using them.

Perhaps adding center_offset and rotation to ImmediateMesh will be better? Dunno since I haven't found a need for the others.

AThousandShips commented 3 months ago

Adding this will make the code for generating the vertices much more complicated even if it isn't used, and I don't expect most users to use this feature, especially when the workaround is so simple:

var st := SurfaceTool.new()
var bm := BoxMesh.new()
# Setup the mesh.
var tr := Transform3D()
# Setup the rotation, most easily with just: Transform3D(Basis.from_euler(rotation), origin)
st.append_from(bm, 0, tr)
var ret := st.commit()
Calinou commented 3 months ago

See https://github.com/godotengine/godot-proposals/issues/5420, which requested making the Center Offset property available in all primitive meshes.

Out of curiosity, why not use MultiMeshInstance3D for your use case? Is there something preventing you from using it?

tx350z commented 3 months ago

See #5420, which requested making the Center Offset property available in all primitive meshes. This covers my needs.

Out of curiosity, why not use MultiMeshInstance3D for your use case? Is there something preventing you from using it? If I'm understanding the docs, MultiMeshInstance3D is used to randomly place Mesh copies. I need precise control over BoxMesh placement.

AThousandShips commented 3 months ago

If I'm understanding the docs, MultiMeshInstance3D is used to randomly place Mesh copies. I need precise control over BoxMesh placement.

You can place them specifically as well, see here, though only from code atm as far as I know