You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Fix GridMap OctantKey cell rasterization
Fixes GridMap OctantKey cell rasterization that had octants at different sizes due to faulty integer division.
This commit is contained in:
@@ -354,10 +354,7 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
|
|||||||
key.y = p_position.y;
|
key.y = p_position.y;
|
||||||
key.z = p_position.z;
|
key.z = p_position.z;
|
||||||
|
|
||||||
OctantKey ok;
|
const OctantKey ok = get_octant_key_from_cell_coords(p_position);
|
||||||
ok.x = p_position.x / octant_size;
|
|
||||||
ok.y = p_position.y / octant_size;
|
|
||||||
ok.z = p_position.z / octant_size;
|
|
||||||
|
|
||||||
if (p_item < 0) {
|
if (p_item < 0) {
|
||||||
//erase
|
//erase
|
||||||
@@ -521,6 +518,32 @@ int GridMap::get_orthogonal_index_from_basis(const Basis &p_basis) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GridMap::OctantKey GridMap::get_octant_key_from_index_key(const IndexKey &p_index_key) const {
|
||||||
|
const int x = p_index_key.x > 0 ? p_index_key.x / octant_size : (p_index_key.x - (octant_size - 1)) / octant_size;
|
||||||
|
const int y = p_index_key.y > 0 ? p_index_key.y / octant_size : (p_index_key.y - (octant_size - 1)) / octant_size;
|
||||||
|
const int z = p_index_key.z > 0 ? p_index_key.z / octant_size : (p_index_key.z - (octant_size - 1)) / octant_size;
|
||||||
|
|
||||||
|
OctantKey ok;
|
||||||
|
ok.key = 0;
|
||||||
|
ok.x = x;
|
||||||
|
ok.y = y;
|
||||||
|
ok.z = z;
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
GridMap::OctantKey GridMap::get_octant_key_from_cell_coords(const Vector3i &p_cell_coords) const {
|
||||||
|
const int x = p_cell_coords.x > 0 ? p_cell_coords.x / octant_size : (p_cell_coords.x - (octant_size - 1)) / octant_size;
|
||||||
|
const int y = p_cell_coords.y > 0 ? p_cell_coords.y / octant_size : (p_cell_coords.y - (octant_size - 1)) / octant_size;
|
||||||
|
const int z = p_cell_coords.z > 0 ? p_cell_coords.z / octant_size : (p_cell_coords.z - (octant_size - 1)) / octant_size;
|
||||||
|
|
||||||
|
OctantKey ok;
|
||||||
|
ok.key = 0;
|
||||||
|
ok.x = x;
|
||||||
|
ok.y = y;
|
||||||
|
ok.z = z;
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3i GridMap::local_to_map(const Vector3 &p_world_position) const {
|
Vector3i GridMap::local_to_map(const Vector3 &p_world_position) const {
|
||||||
Vector3 map_position = (p_world_position / cell_size).floor();
|
Vector3 map_position = (p_world_position / cell_size).floor();
|
||||||
return Vector3i(map_position);
|
return Vector3i(map_position);
|
||||||
@@ -1320,10 +1343,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
|
|||||||
xform.set_origin(cellpos * cell_size + ofs);
|
xform.set_origin(cellpos * cell_size + ofs);
|
||||||
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
|
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
|
||||||
|
|
||||||
OctantKey ok;
|
const OctantKey ok = get_octant_key_from_index_key(key);
|
||||||
ok.x = key.x / octant_size;
|
|
||||||
ok.y = key.y / octant_size;
|
|
||||||
ok.z = key.z / octant_size;
|
|
||||||
|
|
||||||
if (!surface_map.has(ok)) {
|
if (!surface_map.has(ok)) {
|
||||||
surface_map[ok] = HashMap<Ref<Material>, Ref<SurfaceTool>>();
|
surface_map[ok] = HashMap<Ref<Material>, Ref<SurfaceTool>>();
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ class GridMap : public Node3D {
|
|||||||
OctantKey() {}
|
OctantKey() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OctantKey get_octant_key_from_index_key(const IndexKey &p_index_key) const;
|
||||||
|
OctantKey get_octant_key_from_cell_coords(const Vector3i &p_cell_coords) const;
|
||||||
|
|
||||||
#ifndef PHYSICS_3D_DISABLED
|
#ifndef PHYSICS_3D_DISABLED
|
||||||
uint32_t collision_layer = 1;
|
uint32_t collision_layer = 1;
|
||||||
uint32_t collision_mask = 1;
|
uint32_t collision_mask = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user