Skip to content

Commit

Permalink
Split out fill_map function
Browse files Browse the repository at this point in the history
  • Loading branch information
lw64 committed May 10, 2024
1 parent cf717d8 commit 0efbc88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/editor_collision_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ EditorCollisionChunk::~EditorCollisionChunk() {
}

void EditorCollisionChunk::refill() {
Transform3D xform;
PackedFloat32Array map_data = fill_map(&xform);

Ref<HeightMapShape3D> hshape = _col_shape->get_shape();
hshape->set_map_data(map_data);
_col_shape->set_global_transform(xform);
}

inline PackedFloat32Array EditorCollisionChunk::fill_map(Transform3D *xform) {
Ref<Terrain3DStorage> storage = ((CollisionChunkManager *)_manager)->_terrain->get_storage();
float hole_const = NAN;
if (ProjectSettings::get_singleton()->get_setting("physics/3d/physics_engine") == "JoltPhysics3D") {
Expand All @@ -35,8 +44,8 @@ void EditorCollisionChunk::refill() {
int region = storage->get_region_index(Vector3(_position.x, 0, _position.y));
int region_size = storage->get_region_size();

Ref<HeightMapShape3D> hshape = _col_shape->get_shape();
PackedFloat32Array map_data = hshape->get_map_data();
PackedFloat32Array map_data = PackedFloat32Array();
map_data.resize(_size * _size);

Ref<Image> map, map_x, map_z, map_xz;
Ref<Image> cmap, cmap_x, cmap_z, cmap_xz;
Expand Down Expand Up @@ -109,13 +118,12 @@ void EditorCollisionChunk::refill() {
}
}

hshape->set_map_data(map_data);

// Non rotated shape for normal array index above
//Transform3D xform = Transform3D(Basis(), global_pos);
// Rotated shape Y=90 for -90 rotated array index
Transform3D xform = Transform3D(Basis(Vector3(0, 1.0, 0), Math_PI * .5), Vector3(_position.x, 0.0, _position.y));
_col_shape->set_global_transform(xform);
*xform = Transform3D(Basis(Vector3(0, 1.0, 0), Math_PI * .5), Vector3(_position.x, 0.0, _position.y));

return map_data;
}

void EditorCollisionChunk::set_position(Vector2i p_position) {
Expand Down
1 change: 1 addition & 0 deletions src/editor_collision_chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EditorCollisionChunk : public BaseChunk {
~EditorCollisionChunk();

void refill() override;
inline PackedFloat32Array fill_map(Transform3D *xform);
void set_enabled(bool enabled) override;
void set_position(Vector2i p_position) override;

Expand Down

0 comments on commit 0efbc88

Please sign in to comment.