gongpha / gdQmapbsp

A simple plugin that loads Quake's MAP/BSP files into Godot 4 interactively
MIT License
42 stars 5 forks source link

Extract BSP/Clip nodes from BSP file for collision shapes (Potentially not needed a MAP file to play any Quake maps anymore !) #20

Closed gongpha closed 11 months ago

gongpha commented 12 months ago

Here, this PR will add the ability to extract BSP/Clip nodes from a BSP file for proper collision shapes instead of extracting them from a MAP file.

AFAIK, The BSP nodes are elements of the BSP tree, which is commonly used for rendering map geometries and detecting an exact collision e.g. hitscan from firing a gun. The clip nodes are used for detecting entity collision majority e.g. moving player. And they also have oversized collision shapes from simplifying a detail from map geometries for faster collision checking.

And more, this extraction could lead to PVS implementation like visleaves in the future.

Before a MAP file requirement, I've been trying to import BSP/Clip node data for performing collision shapes rather than baking trimesh (concave) shapes from the BSP triangles. Because they're slow and don't work at all on area nodes (used in trigger entities), even though the backface collision is enabled to fix this issue, that'll make the performance goes worse. Therefore, the MAP brush shapes were required for proper collision shapes. And, that's why it needed a MAP file every time we do importing process. (And that was also a reason why this plugin was named "Qmapbsp" ^^;)

Here are some more results :

BSP node shapes (exterior)

Godot_v4 0 3-stable_win64_hBZZb57ds4

Clip node shapes (exterior)

Godot_v4 0 3-stable_win64_xp5a0gag6y

BSP node shapes (interior)

I believe that they should be fitter on infinite planes. But these are easy to visualize their shapes though. Godot_v4 0 3-stable_win64_6hVBWIZKwT

Clip node shapes (interior)

Godot_v4 0 3-stable_win64_Q5vX4dJMXD

E4M4 (both were imported)

Godot_v4 0 3-stable_win64_dQ1S1ForCC Godot_v4 0 3-stable_win64_Q12bLwtCdH Godot_v4 0 3-stable_win64_fz4gze9iUf

Clearly differences between BSP and clip nodes

BSP Clip
image image
victorbstan commented 12 months ago

Is there a way to run these examples, or to test it out locally? I downloaded the branch, but don't see anything different...

gongpha commented 12 months ago

I will add them later. I'm not sure that should I replace it entire Quake1 Example. Because it might break your player update. Since the clip node collision shapes (must be used for player body) are somewhat extruded due to the simplifying process. The player body collision box must have a change.

I still recommended using collision shapes from a Map file rather than from the bsp one if you already had a map file when importing maps for your game. Because they're more optimal and clean. This extraction method is more likely used in case you only had a bsp file. for example, playing maps from PAK files.

victorbstan commented 12 months ago

Sounds good. I agree about the changes needed to collision for the player. I think the original collision code is very different than modern engines. Not sure how useful either. It would have been nice if it was possible to extract exact clip brushes from BSP only and not have to rely on map files.

victorbstan commented 12 months ago

Using -wrbrushes when compiling map files will embed brushes into the BSP, so for the purposes of being able to use only BSP and not have to ask users to provide MAP files, it would be a good option. Then this engine would still be able to extract clip brushes from the BSP...

gongpha commented 12 months ago

I tried compiling a map with -wrbrushes option added. But it gave me an empty BRUSHLIST lump . . . idk why (ericw 0.18.1)

-wrbrushes is a really interesting option though.

jitspoe commented 11 months ago

To respond to your question on https://github.com/godotengine/godot-proposals/issues/6695 - I didn't realize the clip brushes were stored exclusively in the clip nodes. Makes sense, though, as they don't impact point raycasts, so they don't need to be close to geometry -- only larger stuff collides with them. I believe the clip nodes are pre-extruded to match the player collision box (and I think there's another set or 2 for larger stuff). Planes are also added on edges that aren't on axis as well (so you can stand on the top of a pyramid, for example). Effectively, the planes are extruded such that the player movement can be done as a ray cast. You'll have to move them back on each axis (payer is 32 units wide and 56 units tall, so I think you'd move them back half that, so 16 units on the horizontal and 28 on the vertical. Not sure if vertical is centered). Then, if you're getting collision from the regular brush data as well, figure out what's redundant and remove it.

Also, you'd want to filter the clip stuff with appropriate layers/masks so only players and monsters collide with it and not bullets.

victorbstan commented 11 months ago

Small world. PS @gongpha you should join (UPDATED) https://discord.gg/qMRaS7f6kJ if you're interested in Quake stuff, it's were all the gibheads hang out.

gongpha commented 11 months ago

@victorbstan the link was expired.

victorbstan commented 11 months ago

Updated link if you're interested.

gongpha commented 11 months ago

I added the usage of clip nodes in Quake 1 EX. Also changed the collision and behavior of the player.

Surprised that the new collision player shape is neither a player bound box nor a smaller box. But only a single point . . . which resulted in me changing the stair shapecast to a raycast for checking stairs.

victorbstan commented 11 months ago

Surprised that the new collision player shape is neither a player bound box nor a smaller box. But only a single point . . . which resulted in me changing the stair shapecast to a raycast for checking stairs.

Looking forward to trying it out. I know there's maybe a larger size expanded hull shape for larger monsters, but I'm curious what this implies for making custom games... as the original quake game only supported two types of monster shapes (roughly)

gongpha commented 11 months ago

You can use any monster size you want. At least they mustn't be smaller than the player hull size (32x56x32 or 1x1.75x1 in godot unit).

More, If you're planning to import maps for custom games, I suggest you avoid using clip nodes for collisions if possible. Because not only they were extruded. But they can cause some hassle in the development process. Imagine if you worship clip nodes by causing you to have to adjust every entity collision box to fit the clip nodes. This can slow down the development process.

There're replacements here :

EDIT :

gongpha commented 11 months ago

Rebased

gongpha commented 11 months ago

Added ambient sounds when walking into bsp leaves.