blackears / cyclopsLevelBuilder

A Godot plugin to let you block in levels inside the Godot editor.
MIT License
1.09k stars 44 forks source link

calc_lightmap_uvs() errors out on empty tree bounds #116

Closed FabriceCastel closed 10 months ago

FabriceCastel commented 10 months ago

In particular, var xform_inv = xform.affine_inverse() was erroring out for me, which I was able to resolve by throwing in an if to stop trying to bake the lightmap UVs for an empty tree:

func calc_lightmap_uvs():
    var packer:FacePacker = FacePacker.new()
    var max_dim:float = max(bounds.size.x, bounds.size.y, bounds.size.z)
    var tree:FacePacker.FaceTree = packer.build_faces(self, max_dim * .1)

    if tree.bounds.size != Vector2.ZERO:
        var xform:Transform2D = Transform2D.IDENTITY
        xform = xform.scaled(tree.bounds.size)
        var xform_inv = xform.affine_inverse()

        for ft in tree.face_list:
            var face:FaceInfo = faces[ft.face_index]
            face.lightmap_uvs = xform_inv * ft.points

I'm not sure if that's a legitimate solution or a band-aid, I just don't have enough context on the inner workings of this project to totally grok what's going on.

blackears commented 10 months ago

I've added a fix to 1.0.2. Your fix should work for your code if you're still using 1.0.1. I am planning to release 1.0.2 shortly.