The title says it all. It would be very useful if we could do that
Is it possible to change a MeshInstance's point of origin?
You can change the MeshInstance's position, which would achieve effect you are looking for. You just need to change global_transform.origin
or transform.origin
if you want to move the MeshInstance around in 3D space through code.
But unfortunately, I do not think there is any interface to offset a mesh from the MeshInstance node it is attached to in Godot right now.
- Edited
@TwistedTwigleg said: You can change the MeshInstance's position, which would achieve effect you are looking for. You just need to change
global_transform.origin
ortransform.origin
if you want to move the MeshInstance around in 3D space through code.But unfortunately, I do not think there is any interface to offset a mesh from the MeshInstance node it is attached to in Godot right now.
So we can't actually change a mesh's transform origin. That's inconvenient because if a MeshInstance is used as a member of a mesh library to be used in a gridmap, the placement is not as intended most of the times, especially when it comes to the Y-axis.
parent the mesh instance to a spatial and move the mesh instance as you would like, to an extent the spatial can be handled and considered as the new/moved origin point.
@Megalomaniak said: parent the mesh instance to a spatial and move the mesh instance as you would like, to an extent the spatial can be handled and considered as the new/moved origin point.
I actually had to make the spatial the parent of the mesh node in order for it to work the way I wanted it. But there is one problem: It doesn't work when it's converted to a meshLibrary.
- Edited
Is it possible for a mesh with a spatial as parent to work in a gridLibrary and gridmaps?
I hean't used gridmaps nor mesh/gridLibrary so I'm honestly not sure. Maybe someone else can answer that.
@foumfo said: Is it possible for a mesh with a spatial as parent to work in a gridLibrary and gridmaps?
I did some testing using the default shapes included with MeshInstance nodes, and unfortunately it appears to ignore the parent Spatial node and any offsets. I also tried parenting a MeshInstance node to another MeshInstance node in a GridMap/MeshLibrary, but alas it also didn't work and instead just completely ignored both nodes.
It appears that for a GridMap/MeshLibrary, there is no way to offset the MeshInstance node. I was surprised, as I thought it would respect the offset from the parent Spatial node so long as it was not the root spatial node, but it appears that is not the case.
Maybe this should be a feature request on the GitHub repository?
- Edited
@TwistedTwigleg said:
@foumfo said: Is it possible for a mesh with a spatial as parent to work in a gridLibrary and gridmaps?
I did some testing using the default shapes included with MeshInstance nodes, and unfortunately it appears to ignore the parent Spatial node and any offsets. I also tried parenting a MeshInstance node to another MeshInstance node in a GridMap/MeshLibrary, but alas it also didn't work and instead just completely ignored both nodes.
It appears that for a GridMap/MeshLibrary, there is no way to offset the MeshInstance node. I was surprised, as I thought it would respect the offset from the parent Spatial node so long as it was not the root spatial node, but it appears that is not the case.
Maybe this should be a feature request on the GitHub repository?
I even tried it with a MultiMesh. Nothing. Has anyone ever done this request?
@foumfo said:
@TwistedTwigleg said:
@foumfo said: Is it possible for a mesh with a spatial as parent to work in a gridLibrary and gridmaps?
I did some testing using the default shapes included with MeshInstance nodes, and unfortunately it appears to ignore the parent Spatial node and any offsets. I also tried parenting a MeshInstance node to another MeshInstance node in a GridMap/MeshLibrary, but alas it also didn't work and instead just completely ignored both nodes.
It appears that for a GridMap/MeshLibrary, there is no way to offset the MeshInstance node. I was surprised, as I thought it would respect the offset from the parent Spatial node so long as it was not the root spatial node, but it appears that is not the case.
Maybe this should be a feature request on the GitHub repository?
I even tried it with a MultiMesh. Nothing. Has anyone ever done this request?
Good to know that both GridMap and MultiMesh nodes do not seem to take parent Spatial nodes into account when converted. My guess is that in the converting process, it does not process the offset(s) from Spatial nodes.
It seems there is one issue sort of relating to the problem, but with children of the MeshInstance node instead of the MeshInstance node itself.
I'm not sure if the conversion from scene to MeshLibrary should be a new issue, or is a duplicate of the issue above. The issue above is more about positioning children nodes rather than the MeshInstance node itself, but on the other hand, a fix for one may fix the other.
So, in essence, the only solution are imported objects?
@foumfo said: So, in essence, the only solution are imported objects?
Unfortunately, I think so.
Hopefully it will change in the future, but right now it seems any offsets have to be done in the 3D modeling program by changing the object’s origin prior to importing.
This issue persists in Godot 3.2.1, so I've submitted an enhancement request (https://github.com/godotengine/godot-proposals/issues/805). It is inconvenient to need to export primitives from Blender, just so that those primitives can be positioned/rotated correctly within a MeshLibrary.
Using a Grid map, you might want to uncheck the Center Y option.
Also ensure the meshes origin is at the floor if doing this. (You can do this in Blender)
Same goes for X and Z.
Thank you -- that's a helpful suggestion. I already have that checkbox checked, it is a very important checkbox but it addresses a different problem.
More specifically, the "Center Y" checkbox addresses an issue where small objects such as your house would end up floating in mid-air, aligned to the center of their grid cell. The "custom origin" issue is where your house sinks half-way into the ground because Godot would aligns the floor with the center of the house instead of the bottom of the house.
There is a way to change the origin inside Godot but I'm not sure if it works for what you want to do.
You can try to create a tool script and use the MeshDataTool class to offset the vertex position. After that save the ArrayMesh.
Here is an example with a plane mesh:
The mesh position is at (0,0,0) but the MeshInstance node is at (0, 1, 0) .
- Edited
the planemesh and quadmesh have got a variable "center offset" and it´s changes are applied to the meshlibrary of a gridmal as well.
Maybe the developers should move this option into the basic mesh-class, where all specific shaped meshes inherit from. It seems like it takes a list of all vertices of the mesh, adds the values from that variable to them and uses the results to render the mesh.
If meshinstance allows it, maybe you could try moving the vertices by some offset to change the center.