summaryrefslogtreecommitdiff
path: root/scene/3d/mesh_instance_3d.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-05-14 23:09:03 +0200
committerGitHub <noreply@github.com>2020-05-14 23:09:03 +0200
commit00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch)
tree2b1c31f45add24085b64425ce440f577424c16a1 /scene/3d/mesh_instance_3d.cpp
parent5046f666a1181675b39f156c38346525dc1c444e (diff)
parent0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff)
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'scene/3d/mesh_instance_3d.cpp')
-rw-r--r--scene/3d/mesh_instance_3d.cpp88
1 files changed, 41 insertions, 47 deletions
diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp
index cdc8db8aea..13f40aed4f 100644
--- a/scene/3d/mesh_instance_3d.cpp
+++ b/scene/3d/mesh_instance_3d.cpp
@@ -37,12 +37,12 @@
#include "skeleton_3d.h"
bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) {
-
//this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else.
//add to it that it's probably found on first call to _set anyway.
- if (!get_instance().is_valid())
+ if (!get_instance().is_valid()) {
return false;
+ }
Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
if (E) {
@@ -53,8 +53,9 @@ bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) {
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/', 1).to_int();
- if (idx >= materials.size() || idx < 0)
+ if (idx >= materials.size() || idx < 0) {
return false;
+ }
set_surface_material(idx, p_value);
return true;
@@ -64,9 +65,9 @@ bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) {
}
bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
-
- if (!get_instance().is_valid())
+ if (!get_instance().is_valid()) {
return false;
+ }
const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
if (E) {
@@ -76,8 +77,9 @@ bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/', 1).to_int();
- if (idx >= materials.size() || idx < 0)
+ if (idx >= materials.size() || idx < 0) {
return false;
+ }
r_ret = materials[idx];
return true;
}
@@ -85,10 +87,8 @@ bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
}
void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
-
List<String> ls;
for (const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.front(); E; E = E->next()) {
-
ls.push_back(E->key());
}
@@ -106,9 +106,9 @@ void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
}
void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) {
-
- if (mesh == p_mesh)
+ if (mesh == p_mesh) {
return;
+ }
if (mesh.is_valid()) {
mesh->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance3D::_mesh_changed));
@@ -119,9 +119,7 @@ void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) {
blend_shape_tracks.clear();
if (mesh.is_valid()) {
-
for (int i = 0; i < mesh->get_blend_shape_count(); i++) {
-
BlendShapeTrack mt;
mt.idx = i;
mt.value = 0;
@@ -133,7 +131,6 @@ void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) {
set_base(mesh->get_rid());
} else {
-
set_base(RID());
}
@@ -141,13 +138,12 @@ void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) {
_change_notify();
}
-Ref<Mesh> MeshInstance3D::get_mesh() const {
+Ref<Mesh> MeshInstance3D::get_mesh() const {
return mesh;
}
void MeshInstance3D::_resolve_skeleton_path() {
-
Ref<SkinReference> new_skin_reference;
if (!skeleton_path.is_empty()) {
@@ -174,8 +170,9 @@ void MeshInstance3D::_resolve_skeleton_path() {
void MeshInstance3D::set_skin(const Ref<Skin> &p_skin) {
skin_internal = p_skin;
skin = p_skin;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_resolve_skeleton_path();
}
@@ -184,10 +181,10 @@ Ref<Skin> MeshInstance3D::get_skin() const {
}
void MeshInstance3D::set_skeleton_path(const NodePath &p_skeleton) {
-
skeleton_path = p_skeleton;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_resolve_skeleton_path();
}
@@ -196,32 +193,34 @@ NodePath MeshInstance3D::get_skeleton_path() {
}
AABB MeshInstance3D::get_aabb() const {
-
- if (!mesh.is_null())
+ if (!mesh.is_null()) {
return mesh->get_aabb();
+ }
return AABB();
}
Vector<Face3> MeshInstance3D::get_faces(uint32_t p_usage_flags) const {
-
- if (!(p_usage_flags & (FACES_SOLID | FACES_ENCLOSING)))
+ if (!(p_usage_flags & (FACES_SOLID | FACES_ENCLOSING))) {
return Vector<Face3>();
+ }
- if (mesh.is_null())
+ if (mesh.is_null()) {
return Vector<Face3>();
+ }
return mesh->get_faces();
}
Node *MeshInstance3D::create_trimesh_collision_node() {
-
- if (mesh.is_null())
+ if (mesh.is_null()) {
return nullptr;
+ }
Ref<Shape3D> shape = mesh->create_trimesh_shape();
- if (shape.is_null())
+ if (shape.is_null()) {
return nullptr;
+ }
StaticBody3D *static_body = memnew(StaticBody3D);
CollisionShape3D *cshape = memnew(CollisionShape3D);
@@ -231,7 +230,6 @@ Node *MeshInstance3D::create_trimesh_collision_node() {
}
void MeshInstance3D::create_trimesh_collision() {
-
StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_trimesh_collision_node());
ERR_FAIL_COND(!static_body);
static_body->set_name(String(get_name()) + "_col");
@@ -245,13 +243,14 @@ void MeshInstance3D::create_trimesh_collision() {
}
Node *MeshInstance3D::create_convex_collision_node() {
-
- if (mesh.is_null())
+ if (mesh.is_null()) {
return nullptr;
+ }
Ref<Shape3D> shape = mesh->create_convex_shape();
- if (shape.is_null())
+ if (shape.is_null()) {
return nullptr;
+ }
StaticBody3D *static_body = memnew(StaticBody3D);
CollisionShape3D *cshape = memnew(CollisionShape3D);
@@ -261,7 +260,6 @@ Node *MeshInstance3D::create_convex_collision_node() {
}
void MeshInstance3D::create_convex_collision() {
-
StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_convex_collision_node());
ERR_FAIL_COND(!static_body);
static_body->set_name(String(get_name()) + "_col");
@@ -275,38 +273,34 @@ void MeshInstance3D::create_convex_collision() {
}
void MeshInstance3D::_notification(int p_what) {
-
if (p_what == NOTIFICATION_ENTER_TREE) {
_resolve_skeleton_path();
}
}
int MeshInstance3D::get_surface_material_count() const {
-
return materials.size();
}
void MeshInstance3D::set_surface_material(int p_surface, const Ref<Material> &p_material) {
-
ERR_FAIL_INDEX(p_surface, materials.size());
materials.write[p_surface] = p_material;
- if (materials[p_surface].is_valid())
+ if (materials[p_surface].is_valid()) {
RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid());
- else
+ } else {
RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID());
+ }
}
Ref<Material> MeshInstance3D::get_surface_material(int p_surface) const {
-
ERR_FAIL_INDEX_V(p_surface, materials.size(), Ref<Material>());
return materials[p_surface];
}
Ref<Material> MeshInstance3D::get_active_material(int p_surface) const {
-
Ref<Material> material_override = get_material_override();
if (material_override.is_valid()) {
return material_override;
@@ -326,28 +320,29 @@ Ref<Material> MeshInstance3D::get_active_material(int p_surface) const {
}
void MeshInstance3D::_mesh_changed() {
-
materials.resize(mesh->get_surface_count());
}
void MeshInstance3D::create_debug_tangents() {
-
Vector<Vector3> lines;
Vector<Color> colors;
Ref<Mesh> mesh = get_mesh();
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
return;
+ }
for (int i = 0; i < mesh->get_surface_count(); i++) {
Array arrays = mesh->surface_get_arrays(i);
Vector<Vector3> verts = arrays[Mesh::ARRAY_VERTEX];
Vector<Vector3> norms = arrays[Mesh::ARRAY_NORMAL];
- if (norms.size() == 0)
+ if (norms.size() == 0) {
continue;
+ }
Vector<float> tangents = arrays[Mesh::ARRAY_TANGENT];
- if (tangents.size() == 0)
+ if (tangents.size() == 0) {
continue;
+ }
for (int j = 0; j < verts.size(); j++) {
Vector3 v = verts[j];
@@ -373,7 +368,6 @@ void MeshInstance3D::create_debug_tangents() {
}
if (lines.size()) {
-
Ref<StandardMaterial3D> sm;
sm.instance();
@@ -397,16 +391,16 @@ void MeshInstance3D::create_debug_tangents() {
add_child(mi);
#ifdef TOOLS_ENABLED
- if (this == get_tree()->get_edited_scene_root())
+ if (this == get_tree()->get_edited_scene_root()) {
mi->set_owner(this);
- else
+ } else {
mi->set_owner(get_owner());
+ }
#endif
}
}
void MeshInstance3D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance3D::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance3D::get_mesh);
ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &MeshInstance3D::set_skeleton_path);