+2 votes

I'm wondering if there is a good way to view GDScript's SurfaceTool generated mesh in the editor for easier visual manipulation/placement of that procedurally generated mesh.

Adding 'tool' to the top of the GDScript file that generates the mesh for a MeshInstance node appears to somewhat work by causing the script to be executed in editor each time the scene file is opened. But this appears to cause the generated mesh to be stored in the .tscn file when the scene is saved, which makes the file unnecessarily big.

I can manually clear the MeshInstance's Mesh field every time I'm saving the scene but feels like there should be a better way that I'm missing...

in Engine by (20 points)

1 Answer

+1 vote
Best answer

I think it depends on how you structured your code, are you triggering the mesh generation at func _ready? Then it's normal.
If not, I'd say paste here some of your code, so that I can help more.
I can tell you that in my case I used properties (export, with onready), and used them to trigger the mesh generation function only when value is changed (using setget), so, for example:

extends Spatial

export(bool) onready var trigger_generation= false setget GenerateMesh

func GenerateMesh(_newval):
    if(_newval != trigger_generation):
by (106 points)
selected by

Thank you for your suggestion.
Yes, I'm generating the mesh in _ready() and it works for the game, but I was hoping to generate it at a point where I can also see the mesh inside the editor. Below is an example of how I'm trying to generate a simple triangle in code. It shows up in the game but inside the editor it just shows up as an empty node without the triangle mesh. Enabling procedurally generated mesh to show up in editor would make it easy to place it correctly relative to non-procedurally generated meshes so that's what I'm hoping to achieve.

extends MultiMeshInstance

func _ready():
    var st = SurfaceTool.new()

    var pts = [

    for i in range(pts.size()):

    multimesh.mesh = st.commit()
    multimesh.instance_count = 1
    for i in range(multimesh.instance_count):
        multimesh.set_instance_transform(i, Transform())
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.