Merge pull request #16358 from JFonS/particlesgizmo_box_fix

ParticlesGizmo solid box now follows actual visibility_aabb position.
This commit is contained in:
Rémi Verschelde 2018-05-03 21:47:00 +02:00 committed by GitHub
commit e9c1957a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -299,13 +299,24 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
} }
} }
void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size) { void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position) {
ERR_FAIL_COND(!spatial_node); ERR_FAIL_COND(!spatial_node);
CubeMesh cubem; CubeMesh cubem;
cubem.set_size(p_size); cubem.set_size(p_size);
Array arrays = cubem.surface_get_arrays(0);
PoolVector3Array vertex = arrays[VS::ARRAY_VERTEX];
PoolVector3Array::Write w = vertex.write();
for (int i = 0; i < vertex.size(); ++i) {
w[i] += p_position;
}
arrays[VS::ARRAY_VERTEX] = vertex;
Ref<ArrayMesh> m = memnew(ArrayMesh); Ref<ArrayMesh> m = memnew(ArrayMesh);
m->add_surface_from_arrays(cubem.surface_get_primitive_type(0), cubem.surface_get_arrays(0)); m->add_surface_from_arrays(cubem.surface_get_primitive_type(0), arrays);
m->surface_set_material(0, p_material); m->surface_set_material(0, p_material);
add_mesh(m); add_mesh(m);
} }
@ -2411,7 +2422,7 @@ void ParticlesGizmo::redraw() {
gizmo_color.a = 0.1; gizmo_color.a = 0.1;
Ref<Material> solid_material = create_material("particles_solid_material", gizmo_color); Ref<Material> solid_material = create_material("particles_solid_material", gizmo_color);
add_solid_box(solid_material, aabb.get_size()); add_solid_box(solid_material, aabb.get_size(), aabb.get_position() + aabb.get_size() / 2.0);
} }
//add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05);

View File

@ -105,7 +105,7 @@ protected:
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const AABB &p_bounds = AABB()); void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const AABB &p_bounds = AABB());
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1); void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1);
void add_handles(const Vector<Vector3> &p_handles, bool p_billboard = false, bool p_secondary = false); void add_handles(const Vector<Vector3> &p_handles, bool p_billboard = false, bool p_secondary = false);
void add_solid_box(Ref<Material> &p_material, Vector3 p_size); void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3());
void set_spatial_node(Spatial *p_node); void set_spatial_node(Spatial *p_node);
const Spatial *get_spatial_node() const { return spatial_node; } const Spatial *get_spatial_node() const { return spatial_node; }