Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Concave, Skip and Clip Collision Build Bugs (#84)
* Fix Skip and Clip Collision Build Bug Most of Qodot's MapData is passed by Span, a data type that references another existing value. Modifying the Span value will modify the original value as well. Qodot generates Mesh and Collision Shape data running 2 passes of SurfaceGatherer.Run() on each Entity. During each Run(), SurfaceGatherer loops through each Brush and Face of an SolidEntity, checking if the current Brush or Face it's on should be skipped. It then loops through each Vertex of the current Face. If the current SolidEntity is an Entity or Group type, it subtracts the center position from the current Vertex. Then finally it adds the Vertex to the Surface Output. The problem is that it loops through the Vertices as a Span type, which is passed by reference. Therefore, every time the Entity's Center position is subtracted from the Vertex, it modifies the original value. For Skip textures, it only ends subtracting from this value once because they are filtered out during the Mesh Generation Run. Meanwhile, all other texture types are subtracted twice, causing the sets of vertices to be offset. The fix is to copy the Span's current FaceVertex (vertexSpan[v]) to a new local FaceVertex struct, then modify the copied value and insert that into the Output array, leaving the original MapData intact. With this change, there is no longer a need to add the entity.center to the vertex position in qodot_map.gd's build_entity_collision_shapes() function, nor is there any need to comment out GeoGenerator's entity.center += brush.center line. FilterBrush is also moved back to the start of the Brush loop as in the original Qodot for 3.5. This seems to solve the crashes related to Clip texture filtering. Tested both on the default qodot.fgd with worldspawn and on a custom FGD with special SolidEntity classes. * Fix Skip and Clip Collision Build Bug Most of Qodot's MapData is passed by Span, a data type that references another existing value. Modifying the Span value will modify the original value as well. Qodot generates Mesh and Collision Shape data running 2 passes of SurfaceGatherer.Run() on each Entity. During each Run(), SurfaceGatherer loops through each Brush and Face of an SolidEntity, checking if the current Brush or Face it's on should be skipped. It then loops through each Vertex of the current Face. If the current SolidEntity is an Entity or Group type, it subtracts the center position from the current Vertex. Then finally it adds the Vertex to the Surface Output. The problem is that it loops through the Vertices as a Span type, which is passed by reference. Therefore, every time the Entity's Center position is subtracted from the Vertex, it modifies the original value. For Skip textures, it only ends subtracting from this value once because they are filtered out during the Mesh Generation Run. Meanwhile, all other texture types are subtracted twice, causing the sets of vertices to be offset. The fix is to copy the Span's current FaceVertex (vertexSpan[v]) to a new local FaceVertex struct, then modify the copied value and insert that into the Output array, leaving the original MapData intact. With this change, there is no longer a need to add the entity.center to the vertex position in qodot_map.gd's build_entity_collision_shapes() function, nor is there any need to comment out GeoGenerator's entity.center += brush.center line. FilterBrush is also moved back to the start of the Brush loop as in the original Qodot for 3.5. This seems to solve the crashes related to Clip texture filtering. Tested both on the default qodot.fgd with worldspawn and on a custom FGD with special SolidEntity classes. * Fix Skip and Clip Collision Build Bug Most of Qodot's MapData is passed by Span, a data type that references another existing value. Modifying the Span value will modify the original value as well. Qodot generates Mesh and Collision Shape data running 2 passes of SurfaceGatherer.Run() on each Entity. During each Run(), SurfaceGatherer loops through each Brush and Face of an SolidEntity, checking if the current Brush or Face it's on should be skipped. It then loops through each Vertex of the current Face. If the current SolidEntity is an Entity or Group type, it subtracts the center position from the current Vertex. Then finally it adds the Vertex to the Surface Output. The problem is that it loops through the Vertices as a Span type, which is passed by reference. Therefore, every time the Entity's Center position is subtracted from the Vertex, it modifies the original value. For Skip textures, it only ends subtracting from this value once because they are filtered out during the Mesh Generation Run. Meanwhile, all other texture types are subtracted twice, causing the sets of vertices to be offset. The fix is to copy the Span's current FaceVertex (vertexSpan[v]) to a new local FaceVertex struct, then modify the copied value and insert that into the Output array, leaving the original MapData intact. With this change, there is no longer a need to add the entity.center to the vertex position in qodot_map.gd's build_entity_collision_shapes() function, nor is there any need to comment out GeoGenerator's entity.center += brush.center line. FilterBrush is also moved back to the start of the Brush loop as in the original Qodot for 3.5. This seems to solve the crashes related to Clip texture filtering. Tested both on the default qodot.fgd with worldspawn and on a custom FGD with special SolidEntity classes. * Fix Concave Collision Building Surface Index in SurfaceGatherer was reading the initial value as -1 if SurfaceSplitType was set to NONE. Setting it to the AddSurface() return allows it to gather the surfaces properly. * Fix Concave Collision Building Fixed SurfaceGatherer Run() bug by setting surfIdx to the return value of AddSurface() when SurfaceSplitType is NONE. With the fix of #84 the collision shape points no longer need to add the entity position value in qodot_map.gd. * Fix Concave Collision Building Added index_offset setting after SurfaceSplitType.NONE check, just in case it's needed.
- Loading branch information