H2xDev / GodotVMF

A VMF importer for Godot Engine
MIT License
129 stars 6 forks source link

Add UV2 generation #25

Closed URAKOLOUY5 closed 4 months ago

URAKOLOUY5 commented 4 months ago

Greetings, H2xDev.

Recently, I found this project while searching for a more convenient way to create geometry for levels, and I really liked it, since I used to Source/2. However, manual creation of UV2 maps each time is not good. As it turns out, by adding a few lines of code, the ability to automatically generate UV2 maps becomes available.

image

New properties in VMFNode

image

H2xDev commented 4 months ago

Hello @URAKOLOUY5! Thank you for contribution!

Would be good if you put these settings into the vmf.config.json in the import section. For example:

    "import": {
        "scale": 0.025,
+       "lightmapTexelSize": 0.03,
        "generateCollision": true,
+       "generateLightmapUV2": true,
        "instancesFolder": "res://examples/instances",
        "entitiesFolder": "res://examples/entities"
    },

To get access to the config use VMFConfig.config

Also for new features, adding docs here is required.

URAKOLOUY5 commented 4 months ago

Got it!

Moved config to vmf.config.json

There's now 3 new options

Import

Models

Note: it can be overridden by the lightmapTexelSize keyvalue in prop_static (can be manually added to prop_static or in the .fgd file for convenience).

Updated docs to cover those changes

MDLManager rebuilds models on texel change

Since we can't write metadata to the PackedScene (https://github.com/godotengine/godot/issues/76366), I decided to create a small JSON file to store the texel size. When the mapper updates the texel size in the prop properties, MDLManager recreates the cached version of that model.

However, there's a possibility for a race condition where several props define different texel sizes.

H2xDev commented 4 months ago

@URAKOLOUY5 Approved. Thank you for contribution :)