I have a GDScript to generate UV2:
tool
extends Spatial
export var prepare_for_baking = false setget toggle_prepare
func toggle_prepare(condition):
if condition == true:
for node in get_children():
if node is MeshInstance:
if node.mesh is ArrayMesh:
node.mesh = node.mesh.duplicate()
node.mesh.lightmap_unwrap(node.global_transform, 0.05)
node.use_in_baked_light = true
I converted it to C#:
using Godot;
using System;
[Tool]
public class assets : Spatial
{
private bool _prepareForBaking;
[Export]
private bool PrepareForBaking
{
get { return _prepareForBaking; }
set
{
_prepareForBaking = value;
if(_prepareForBaking)
{
foreach(Node node in GetChildren())
{
if(node is MeshInstance)
{
MeshInstance meshInstance = (MeshInstance)node;
if(meshInstance.Mesh is ArrayMesh)
{
ArrayMesh arrayMesh = (ArrayMesh)meshInstance.Mesh;
// Make the mesh unique:
arrayMesh = (ArrayMesh)arrayMesh.Duplicate();
// Make UV2:
arrayMesh.LightmapUnwrap(meshInstance.GlobalTransform, 0.05f);
// Check the Use In Baked Light checkbox:
meshInstance.UseInBakedLight = true;
}
}
}
}
}
}
}
But the C# script cannot generate UV2. How to generate UV2 with C# script?