summaryrefslogtreecommitdiffstats
path: root/scene/3d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/area.cpp488
-rw-r--r--scene/3d/area.h46
-rw-r--r--scene/3d/baked_light_instance.cpp1437
-rw-r--r--scene/3d/baked_light_instance.h70
-rw-r--r--scene/3d/body_shape.cpp166
-rw-r--r--scene/3d/body_shape.h10
-rw-r--r--scene/3d/bone_attachment.cpp65
-rw-r--r--scene/3d/bone_attachment.h13
-rw-r--r--scene/3d/camera.cpp448
-rw-r--r--scene/3d/camera.h46
-rw-r--r--scene/3d/character_camera.cpp1
-rw-r--r--scene/3d/character_camera.h1
-rw-r--r--scene/3d/collision_object.cpp232
-rw-r--r--scene/3d/collision_object.h36
-rw-r--r--scene/3d/collision_polygon.cpp134
-rw-r--r--scene/3d/collision_polygon.h18
-rw-r--r--scene/3d/gi_probe.cpp1317
-rw-r--r--scene/3d/gi_probe.h72
-rw-r--r--scene/3d/immediate_geometry.cpp120
-rw-r--r--scene/3d/immediate_geometry.h27
-rw-r--r--scene/3d/interpolated_camera.cpp66
-rw-r--r--scene/3d/interpolated_camera.h8
-rw-r--r--scene/3d/light.cpp366
-rw-r--r--scene/3d/light.h45
-rw-r--r--scene/3d/listener.cpp62
-rw-r--r--scene/3d/listener.h15
-rw-r--r--scene/3d/mesh_instance.cpp166
-rw-r--r--scene/3d/mesh_instance.h28
-rw-r--r--scene/3d/multimesh_instance.cpp22
-rw-r--r--scene/3d/multimesh_instance.h10
-rw-r--r--scene/3d/navigation.cpp577
-rw-r--r--scene/3d/navigation.h94
-rw-r--r--scene/3d/navigation_mesh.cpp240
-rw-r--r--scene/3d/navigation_mesh.h28
-rw-r--r--scene/3d/particles.cpp2
-rw-r--r--scene/3d/particles.h4
-rw-r--r--scene/3d/path.cpp242
-rw-r--r--scene/3d/path.h25
-rw-r--r--scene/3d/physics_body.cpp942
-rw-r--r--scene/3d/physics_body.h89
-rw-r--r--scene/3d/physics_joint.cpp1080
-rw-r--r--scene/3d/physics_joint.h210
-rw-r--r--scene/3d/portal.cpp158
-rw-r--r--scene/3d/portal.h17
-rw-r--r--scene/3d/position_3d.cpp4
-rw-r--r--scene/3d/position_3d.h6
-rw-r--r--scene/3d/proximity_group.cpp45
-rw-r--r--scene/3d/proximity_group.h8
-rw-r--r--scene/3d/quad.cpp153
-rw-r--r--scene/3d/quad.h13
-rw-r--r--scene/3d/ray_cast.cpp139
-rw-r--r--scene/3d/ray_cast.h16
-rw-r--r--scene/3d/reflection_probe.cpp226
-rw-r--r--scene/3d/reflection_probe.h20
-rw-r--r--scene/3d/remote_transform.cpp30
-rw-r--r--scene/3d/remote_transform.h19
-rw-r--r--scene/3d/room_instance.cpp92
-rw-r--r--scene/3d/room_instance.h25
-rw-r--r--scene/3d/scenario_fx.cpp46
-rw-r--r--scene/3d/scenario_fx.h9
-rw-r--r--scene/3d/skeleton.cpp393
-rw-r--r--scene/3d/skeleton.h50
-rw-r--r--scene/3d/spatial.cpp407
-rw-r--r--scene/3d/spatial.h81
-rw-r--r--scene/3d/spatial_indexer.cpp2
-rw-r--r--scene/3d/sprite_3d.cpp721
-rw-r--r--scene/3d/sprite_3d.h67
-rw-r--r--scene/3d/test_cube.cpp8
-rw-r--r--scene/3d/test_cube.h9
-rw-r--r--scene/3d/vehicle_body.cpp743
-rw-r--r--scene/3d/vehicle_body.h98
-rw-r--r--scene/3d/visibility_notifier.cpp176
-rw-r--r--scene/3d/visibility_notifier.h33
-rw-r--r--scene/3d/visual_instance.cpp232
-rw-r--r--scene/3d/visual_instance.h62
75 files changed, 5877 insertions, 7299 deletions
diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp
index 92ac091fc5..c42ca2f3f0 100644
--- a/scene/3d/area.cpp
+++ b/scene/3d/area.cpp
@@ -31,164 +31,152 @@
#include "servers/physics_server.h"
void Area::set_space_override_mode(SpaceOverride p_mode) {
- space_override=p_mode;
- PhysicsServer::get_singleton()->area_set_space_override_mode(get_rid(),PhysicsServer::AreaSpaceOverrideMode(p_mode));
-
-
+ space_override = p_mode;
+ PhysicsServer::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer::AreaSpaceOverrideMode(p_mode));
}
-Area::SpaceOverride Area::get_space_override_mode() const{
+Area::SpaceOverride Area::get_space_override_mode() const {
return space_override;
}
-void Area::set_gravity_is_point(bool p_enabled){
-
- gravity_is_point=p_enabled;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT,p_enabled);
+void Area::set_gravity_is_point(bool p_enabled) {
+ gravity_is_point = p_enabled;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT, p_enabled);
}
-bool Area::is_gravity_a_point() const{
+bool Area::is_gravity_a_point() const {
return gravity_is_point;
}
-void Area::set_gravity_distance_scale(real_t p_scale){
-
- gravity_distance_scale=p_scale;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale);
+void Area::set_gravity_distance_scale(real_t p_scale) {
+ gravity_distance_scale = p_scale;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
}
-real_t Area::get_gravity_distance_scale() const{
+real_t Area::get_gravity_distance_scale() const {
return gravity_distance_scale;
}
-void Area::set_gravity_vector(const Vector3& p_vec){
-
- gravity_vec=p_vec;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_VECTOR,p_vec);
+void Area::set_gravity_vector(const Vector3 &p_vec) {
+ gravity_vec = p_vec;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_VECTOR, p_vec);
}
-Vector3 Area::get_gravity_vector() const{
+Vector3 Area::get_gravity_vector() const {
return gravity_vec;
}
-void Area::set_gravity(real_t p_gravity){
+void Area::set_gravity(real_t p_gravity) {
- gravity=p_gravity;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY,p_gravity);
+ gravity = p_gravity;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY, p_gravity);
}
-real_t Area::get_gravity() const{
+real_t Area::get_gravity() const {
return gravity;
}
-void Area::set_linear_damp(real_t p_linear_damp){
+void Area::set_linear_damp(real_t p_linear_damp) {
- linear_damp=p_linear_damp;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_LINEAR_DAMP,p_linear_damp);
+ linear_damp = p_linear_damp;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
}
-real_t Area::get_linear_damp() const{
+real_t Area::get_linear_damp() const {
return linear_damp;
}
-void Area::set_angular_damp(real_t p_angular_damp){
+void Area::set_angular_damp(real_t p_angular_damp) {
- angular_damp=p_angular_damp;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_ANGULAR_DAMP,p_angular_damp);
+ angular_damp = p_angular_damp;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_ANGULAR_DAMP, p_angular_damp);
}
-real_t Area::get_angular_damp() const{
+real_t Area::get_angular_damp() const {
return angular_damp;
}
-void Area::set_priority(real_t p_priority){
+void Area::set_priority(real_t p_priority) {
- priority=p_priority;
- PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_PRIORITY,p_priority);
+ priority = p_priority;
+ PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_PRIORITY, p_priority);
}
-real_t Area::get_priority() const{
+real_t Area::get_priority() const {
return priority;
}
-
void Area::_body_enter_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(E->get().in_tree);
- E->get().in_tree=true;
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = true;
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
-
}
void Area::_body_exit_tree(ObjectID p_id) {
-
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(!E->get().in_tree);
- E->get().in_tree=false;
- emit_signal(SceneStringNames::get_singleton()->body_exited,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = false;
+ emit_signal(SceneStringNames::get_singleton()->body_exited, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
-
}
-void Area::_body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape) {
-
+void Area::_body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape) {
- bool body_in = p_status==PhysicsServer::AREA_BODY_ADDED;
- ObjectID objid=p_instance;
+ bool body_in = p_status == PhysicsServer::AREA_BODY_ADDED;
+ ObjectID objid = p_instance;
Object *obj = ObjectDB::get_instance(objid);
Node *node = obj ? obj->cast_to<Node>() : NULL;
- Map<ObjectID,BodyState>::Element *E=body_map.find(objid);
+ Map<ObjectID, BodyState>::Element *E = body_map.find(objid);
ERR_FAIL_COND(!body_in && !E);
- locked=true;
+ locked = true;
if (body_in) {
if (!E) {
- E = body_map.insert(objid,BodyState());
- E->get().rc=0;
- E->get().in_tree=node && node->is_inside_tree();
+ E = body_map.insert(objid, BodyState());
+ E->get().rc = 0;
+ E->get().in_tree = node && node->is_inside_tree();
if (node) {
- node->connect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree,make_binds(objid));
- node->connect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
}
}
-
}
E->get().rc++;
if (node)
- E->get().shapes.insert(ShapePair(p_body_shape,p_area_shape));
-
+ E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,objid,node,p_body_shape,p_area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_area_shape);
}
} else {
@@ -196,38 +184,32 @@ void Area::_body_inout(int p_status,const RID& p_body, int p_instance, int p_bod
E->get().rc--;
if (node)
- E->get().shapes.erase(ShapePair(p_body_shape,p_area_shape));
+ E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape));
- bool eraseit=false;
+ bool eraseit = false;
- if (E->get().rc==0) {
+ if (E->get().rc == 0) {
if (node) {
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree);
if (E->get().in_tree)
- emit_signal(SceneStringNames::get_singleton()->body_exited,obj);
-
+ emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
}
- eraseit=true;
-
+ eraseit = true;
}
if (node && E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,objid,obj,p_body_shape,p_area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_area_shape);
}
if (eraseit)
body_map.erase(E);
-
}
- locked=false;
-
-
+ locked = false;
}
-
void Area::_clear_monitoring() {
if (locked) {
@@ -236,11 +218,11 @@ void Area::_clear_monitoring() {
ERR_FAIL_COND(locked);
{
- Map<ObjectID,BodyState> bmcopy = body_map;
+ Map<ObjectID, BodyState> bmcopy = body_map;
body_map.clear();
//disconnect all monitored stuff
- for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) {
+ for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = obj ? obj->cast_to<Node>() : NULL;
@@ -248,26 +230,25 @@ void Area::_clear_monitoring() {
if (!E->get().in_tree)
continue;
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
- emit_signal(SceneStringNames::get_singleton()->body_exited,obj);
+ emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree);
}
-
}
{
- Map<ObjectID,AreaState> bmcopy = area_map;
+ Map<ObjectID, AreaState> bmcopy = area_map;
area_map.clear();
//disconnect all monitored stuff
- for (Map<ObjectID,AreaState>::Element *E=bmcopy.front();E;E=E->next()) {
+ for (Map<ObjectID, AreaState>::Element *E = bmcopy.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = obj ? obj->cast_to<Node>() : NULL;
@@ -275,22 +256,21 @@ void Area::_clear_monitoring() {
if (!E->get().in_tree)
continue;
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_exited,E->key(),node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
- emit_signal(SceneStringNames::get_singleton()->area_exited,obj);
+ emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree);
}
}
-
}
void Area::_notification(int p_what) {
- if (p_what==NOTIFICATION_EXIT_TREE) {
+ if (p_what == NOTIFICATION_EXIT_TREE) {
_clear_monitoring();
}
}
@@ -302,41 +282,38 @@ void Area::set_monitoring(bool p_enable) {
}
ERR_FAIL_COND(locked);
- if (p_enable==monitoring)
+ if (p_enable == monitoring)
return;
- monitoring=p_enable;
+ monitoring = p_enable;
if (monitoring) {
- PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_body_inout);
- PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_area_inout);
+ PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout);
+ PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout);
} else {
- PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName());
- PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName());
+ PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), NULL, StringName());
+ PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), NULL, StringName());
_clear_monitoring();
-
}
}
-
void Area::_area_enter_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,AreaState>::Element *E=area_map.find(p_id);
+ Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(E->get().in_tree);
- E->get().in_tree=true;
- emit_signal(SceneStringNames::get_singleton()->area_entered,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = true;
+ emit_signal(SceneStringNames::get_singleton()->area_entered, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_entered,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_entered, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
-
}
void Area::_area_exit_tree(ObjectID p_id) {
@@ -344,56 +321,51 @@ void Area::_area_exit_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,AreaState>::Element *E=area_map.find(p_id);
+ Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(!E->get().in_tree);
- E->get().in_tree=false;
- emit_signal(SceneStringNames::get_singleton()->area_exited,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = false;
+ emit_signal(SceneStringNames::get_singleton()->area_exited, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_exited,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_exited, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
-
}
-void Area::_area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape) {
-
+void Area::_area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape) {
- bool area_in = p_status==PhysicsServer::AREA_BODY_ADDED;
- ObjectID objid=p_instance;
+ bool area_in = p_status == PhysicsServer::AREA_BODY_ADDED;
+ ObjectID objid = p_instance;
Object *obj = ObjectDB::get_instance(objid);
Node *node = obj ? obj->cast_to<Node>() : NULL;
- Map<ObjectID,AreaState>::Element *E=area_map.find(objid);
+ Map<ObjectID, AreaState>::Element *E = area_map.find(objid);
ERR_FAIL_COND(!area_in && !E);
- locked=true;
+ locked = true;
if (area_in) {
if (!E) {
- E = area_map.insert(objid,AreaState());
- E->get().rc=0;
- E->get().in_tree=node && node->is_inside_tree();
+ E = area_map.insert(objid, AreaState());
+ E->get().rc = 0;
+ E->get().in_tree = node && node->is_inside_tree();
if (node) {
- node->connect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree,make_binds(objid));
- node->connect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree, make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_entered,node);
-
+ emit_signal(SceneStringNames::get_singleton()->area_entered, node);
}
}
-
}
E->get().rc++;
if (node)
- E->get().shapes.insert(AreaShapePair(p_area_shape,p_self_shape));
-
+ E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape));
if (!node || E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_entered,objid,node,p_area_shape,p_self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_entered, objid, node, p_area_shape, p_self_shape);
}
} else {
@@ -401,36 +373,31 @@ void Area::_area_inout(int p_status,const RID& p_area, int p_instance, int p_are
E->get().rc--;
if (node)
- E->get().shapes.erase(AreaShapePair(p_area_shape,p_self_shape));
+ E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape));
- bool eraseit=false;
+ bool eraseit = false;
- if (E->get().rc==0) {
+ if (E->get().rc == 0) {
if (node) {
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree);
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_exited,obj);
+ emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
}
-
}
- eraseit=true;
-
+ eraseit = true;
}
if (!node || E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_exited,objid,obj,p_area_shape,p_self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_exited, objid, obj, p_area_shape, p_self_shape);
}
if (eraseit)
area_map.erase(E);
-
}
- locked=false;
-
-
+ locked = false;
}
bool Area::is_monitoring() const {
@@ -438,21 +405,19 @@ bool Area::is_monitoring() const {
return monitoring;
}
-
Array Area::get_overlapping_bodies() const {
- ERR_FAIL_COND_V(!monitoring,Array());
+ ERR_FAIL_COND_V(!monitoring, Array());
Array ret;
ret.resize(body_map.size());
- int idx=0;
- for (const Map<ObjectID,BodyState>::Element *E=body_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<ObjectID, BodyState>::Element *E = body_map.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
if (!obj) {
- ret.resize( ret.size() -1 ); //ops
+ ret.resize(ret.size() - 1); //ops
} else {
- ret[idx++]=obj;
+ ret[idx++] = obj;
}
-
}
return ret;
@@ -465,12 +430,12 @@ void Area::set_monitorable(bool p_enable) {
}
ERR_FAIL_COND(locked);
- if (p_enable==monitorable)
+ if (p_enable == monitorable)
return;
- monitorable=p_enable;
+ monitorable = p_enable;
- PhysicsServer::get_singleton()->area_set_monitorable(get_rid(),monitorable);
+ PhysicsServer::get_singleton()->area_set_monitorable(get_rid(), monitorable);
}
bool Area::is_monitorable() const {
@@ -478,51 +443,45 @@ bool Area::is_monitorable() const {
return monitorable;
}
-
Array Area::get_overlapping_areas() const {
- ERR_FAIL_COND_V(!monitoring,Array());
+ ERR_FAIL_COND_V(!monitoring, Array());
Array ret;
ret.resize(area_map.size());
- int idx=0;
- for (const Map<ObjectID,AreaState>::Element *E=area_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<ObjectID, AreaState>::Element *E = area_map.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
if (!obj) {
- ret.resize( ret.size() -1 ); //ops
+ ret.resize(ret.size() - 1); //ops
} else {
- ret[idx++]=obj;
+ ret[idx++] = obj;
}
-
}
return ret;
}
-bool Area::overlaps_area(Node* p_area) const {
+bool Area::overlaps_area(Node *p_area) const {
- ERR_FAIL_NULL_V(p_area,false);
- const Map<ObjectID,AreaState>::Element *E=area_map.find(p_area->get_instance_ID());
+ ERR_FAIL_NULL_V(p_area, false);
+ const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_ID());
if (!E)
return false;
return E->get().in_tree;
-
-
-
}
-bool Area::overlaps_body(Node* p_body) const{
+bool Area::overlaps_body(Node *p_body) const {
- ERR_FAIL_NULL_V(p_body,false);
- const Map<ObjectID,BodyState>::Element *E=body_map.find(p_body->get_instance_ID());
+ ERR_FAIL_NULL_V(p_body, false);
+ const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_ID());
if (!E)
return false;
return E->get().in_tree;
-
}
void Area::set_collision_mask(uint32_t p_mask) {
- collision_mask=p_mask;
- PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(),p_mask);
+ collision_mask = p_mask;
+ PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask);
}
uint32_t Area::get_collision_mask() const {
@@ -531,8 +490,8 @@ uint32_t Area::get_collision_mask() const {
}
void Area::set_layer_mask(uint32_t p_mask) {
- layer_mask=p_mask;
- PhysicsServer::get_singleton()->area_set_layer_mask(get_rid(),p_mask);
+ layer_mask = p_mask;
+ PhysicsServer::get_singleton()->area_set_layer_mask(get_rid(), p_mask);
}
uint32_t Area::get_layer_mask() const {
@@ -544,144 +503,135 @@ void Area::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_collision_mask(mask);
-
}
-bool Area::get_collision_mask_bit(int p_bit) const{
+bool Area::get_collision_mask_bit(int p_bit) const {
- return get_collision_mask()&(1<<p_bit);
+ return get_collision_mask() & (1 << p_bit);
}
-
void Area::set_layer_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_layer_mask();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_layer_mask(mask);
-
}
-bool Area::get_layer_mask_bit(int p_bit) const{
+bool Area::get_layer_mask_bit(int p_bit) const {
- return get_layer_mask()&(1<<p_bit);
+ return get_layer_mask() & (1 << p_bit);
}
-
void Area::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_body_enter_tree","id"),&Area::_body_enter_tree);
- ClassDB::bind_method(D_METHOD("_body_exit_tree","id"),&Area::_body_exit_tree);
+ ClassDB::bind_method(D_METHOD("_body_enter_tree", "id"), &Area::_body_enter_tree);
+ ClassDB::bind_method(D_METHOD("_body_exit_tree", "id"), &Area::_body_exit_tree);
- ClassDB::bind_method(D_METHOD("_area_enter_tree","id"),&Area::_area_enter_tree);
- ClassDB::bind_method(D_METHOD("_area_exit_tree","id"),&Area::_area_exit_tree);
+ ClassDB::bind_method(D_METHOD("_area_enter_tree", "id"), &Area::_area_enter_tree);
+ ClassDB::bind_method(D_METHOD("_area_exit_tree", "id"), &Area::_area_exit_tree);
- ClassDB::bind_method(D_METHOD("set_space_override_mode","enable"),&Area::set_space_override_mode);
- ClassDB::bind_method(D_METHOD("get_space_override_mode"),&Area::get_space_override_mode);
+ ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area::set_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area::get_space_override_mode);
- ClassDB::bind_method(D_METHOD("set_gravity_is_point","enable"),&Area::set_gravity_is_point);
- ClassDB::bind_method(D_METHOD("is_gravity_a_point"),&Area::is_gravity_a_point);
+ ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area::set_gravity_is_point);
+ ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area::is_gravity_a_point);
- ClassDB::bind_method(D_METHOD("set_gravity_distance_scale","distance_scale"),&Area::set_gravity_distance_scale);
- ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"),&Area::get_gravity_distance_scale);
+ ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area::set_gravity_distance_scale);
+ ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area::get_gravity_distance_scale);
- ClassDB::bind_method(D_METHOD("set_gravity_vector","vector"),&Area::set_gravity_vector);
- ClassDB::bind_method(D_METHOD("get_gravity_vector"),&Area::get_gravity_vector);
+ ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area::set_gravity_vector);
+ ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area::get_gravity_vector);
- ClassDB::bind_method(D_METHOD("set_gravity","gravity"),&Area::set_gravity);
- ClassDB::bind_method(D_METHOD("get_gravity"),&Area::get_gravity);
+ ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area::set_gravity);
+ ClassDB::bind_method(D_METHOD("get_gravity"), &Area::get_gravity);
- ClassDB::bind_method(D_METHOD("set_angular_damp","angular_damp"),&Area::set_angular_damp);
- ClassDB::bind_method(D_METHOD("get_angular_damp"),&Area::get_angular_damp);
+ ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area::set_angular_damp);
+ ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area::get_angular_damp);
- ClassDB::bind_method(D_METHOD("set_linear_damp","linear_damp"),&Area::set_linear_damp);
- ClassDB::bind_method(D_METHOD("get_linear_damp"),&Area::get_linear_damp);
+ ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area::set_linear_damp);
+ ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area::get_linear_damp);
- ClassDB::bind_method(D_METHOD("set_priority","priority"),&Area::set_priority);
- ClassDB::bind_method(D_METHOD("get_priority"),&Area::get_priority);
+ ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area::set_priority);
+ ClassDB::bind_method(D_METHOD("get_priority"), &Area::get_priority);
- ClassDB::bind_method(D_METHOD("set_collision_mask","collision_mask"),&Area::set_collision_mask);
- ClassDB::bind_method(D_METHOD("get_collision_mask"),&Area::get_collision_mask);
+ ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area::set_collision_mask);
+ ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area::get_collision_mask);
- ClassDB::bind_method(D_METHOD("set_layer_mask","layer_mask"),&Area::set_layer_mask);
- ClassDB::bind_method(D_METHOD("get_layer_mask"),&Area::get_layer_mask);
+ ClassDB::bind_method(D_METHOD("set_layer_mask", "layer_mask"), &Area::set_layer_mask);
+ ClassDB::bind_method(D_METHOD("get_layer_mask"), &Area::get_layer_mask);
- ClassDB::bind_method(D_METHOD("set_collision_mask_bit","bit","value"),&Area::set_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("get_collision_mask_bit","bit"),&Area::get_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area::set_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area::get_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("set_layer_mask_bit","bit","value"),&Area::set_layer_mask_bit);
- ClassDB::bind_method(D_METHOD("get_layer_mask_bit","bit"),&Area::get_layer_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "bit", "value"), &Area::set_layer_mask_bit);
+ ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "bit"), &Area::get_layer_mask_bit);
- ClassDB::bind_method(D_METHOD("set_monitorable","enable"),&Area::set_monitorable);
- ClassDB::bind_method(D_METHOD("is_monitorable"),&Area::is_monitorable);
+ ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area::set_monitorable);
+ ClassDB::bind_method(D_METHOD("is_monitorable"), &Area::is_monitorable);
+ ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area::set_monitoring);
+ ClassDB::bind_method(D_METHOD("is_monitoring"), &Area::is_monitoring);
- ClassDB::bind_method(D_METHOD("set_monitoring","enable"),&Area::set_monitoring);
- ClassDB::bind_method(D_METHOD("is_monitoring"),&Area::is_monitoring);
+ ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area::get_overlapping_bodies);
+ ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area::get_overlapping_areas);
- ClassDB::bind_method(D_METHOD("get_overlapping_bodies"),&Area::get_overlapping_bodies);
- ClassDB::bind_method(D_METHOD("get_overlapping_areas"),&Area::get_overlapping_areas);
+ ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area::overlaps_body);
+ ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area::overlaps_area);
- ClassDB::bind_method(D_METHOD("overlaps_body","body"),&Area::overlaps_body);
- ClassDB::bind_method(D_METHOD("overlaps_area","area"),&Area::overlaps_area);
+ ClassDB::bind_method(D_METHOD("_body_inout"), &Area::_body_inout);
+ ClassDB::bind_method(D_METHOD("_area_inout"), &Area::_area_inout);
- ClassDB::bind_method(D_METHOD("_body_inout"),&Area::_body_inout);
- ClassDB::bind_method(D_METHOD("_area_inout"),&Area::_area_inout);
+ ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape")));
+ ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape")));
+ ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body")));
+ ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body")));
+ ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape")));
+ ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape")));
+ ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area")));
+ ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area")));
- ADD_SIGNAL( MethodInfo("body_shape_entered",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
- ADD_SIGNAL( MethodInfo("body_shape_exited",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
- ADD_SIGNAL( MethodInfo("body_entered",PropertyInfo(Variant::OBJECT,"body")));
- ADD_SIGNAL( MethodInfo("body_exited",PropertyInfo(Variant::OBJECT,"body")));
-
- ADD_SIGNAL( MethodInfo("area_shape_entered",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"self_shape")));
- ADD_SIGNAL( MethodInfo("area_shape_exited",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"self_shape")));
- ADD_SIGNAL( MethodInfo("area_entered",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area")));
- ADD_SIGNAL( MethodInfo("area_exited",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area")));
-
- ADD_PROPERTY( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Combine-Replace,Replace,Replace-Combine"),"set_space_override_mode","get_space_override_mode");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),"set_gravity_is_point","is_gravity_a_point");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),"set_gravity_distance_scale","get_gravity_distance_scale");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),"set_gravity_vector","get_gravity_vector");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),"set_gravity","get_gravity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),"set_linear_damp","get_linear_damp");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),"set_angular_damp","get_angular_damp");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),"set_priority","get_priority");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),"set_monitoring","is_monitoring");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),"set_monitorable","is_monitorable");
- ADD_GROUP("Collision","collision_");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision_layers",PROPERTY_HINT_LAYERS_3D_PHYSICS),"set_layer_mask","get_layer_mask");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_3D_PHYSICS),"set_collision_mask","get_collision_mask");
-
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001"), "set_gravity_distance_scale", "get_gravity_distance_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_vec"), "set_gravity_vector", "get_gravity_vector");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_gravity", "get_gravity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "0,1024,0.001"), "set_linear_damp", "get_linear_damp");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "0,1024,0.001"), "set_angular_damp", "get_angular_damp");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,128,1"), "set_priority", "get_priority");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitoring"), "set_monitoring", "is_monitoring");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitorable"), "set_monitorable", "is_monitorable");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layers", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_layer_mask", "get_layer_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
}
-Area::Area() : CollisionObject(PhysicsServer::get_singleton()->area_create(),true) {
+Area::Area()
+ : CollisionObject(PhysicsServer::get_singleton()->area_create(), true) {
- space_override=SPACE_OVERRIDE_DISABLED;
+ space_override = SPACE_OVERRIDE_DISABLED;
set_gravity(9.8);
- locked=false;
- set_gravity_vector(Vector3(0,-1,0));
- gravity_is_point=false;
- gravity_distance_scale=0;
- linear_damp=0.1;
- angular_damp=1;
- priority=0;
- monitoring=false;
- collision_mask=1;
- layer_mask=1;
+ locked = false;
+ set_gravity_vector(Vector3(0, -1, 0));
+ gravity_is_point = false;
+ gravity_distance_scale = 0;
+ linear_damp = 0.1;
+ angular_damp = 1;
+ priority = 0;
+ monitoring = false;
+ collision_mask = 1;
+ layer_mask = 1;
set_ray_pickable(false);
set_monitoring(true);
set_monitorable(true);
-
}
Area::~Area() {
-
-
}
diff --git a/scene/3d/area.h b/scene/3d/area.h
index 7956846505..a50f101ec1 100644
--- a/scene/3d/area.h
+++ b/scene/3d/area.h
@@ -34,9 +34,9 @@
class Area : public CollisionObject {
- GDCLASS( Area, CollisionObject );
-public:
+ GDCLASS(Area, CollisionObject);
+public:
enum SpaceOverride {
SPACE_OVERRIDE_DISABLED,
SPACE_OVERRIDE_COMBINE,
@@ -44,9 +44,8 @@ public:
SPACE_OVERRIDE_REPLACE,
SPACE_OVERRIDE_REPLACE_COMBINE
};
-private:
-
+private:
SpaceOverride space_override;
Vector3 gravity_vec;
real_t gravity;
@@ -61,8 +60,7 @@ private:
bool monitorable;
bool locked;
-
- void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape);
+ void _body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape);
void _body_enter_tree(ObjectID p_id);
void _body_exit_tree(ObjectID p_id);
@@ -71,15 +69,18 @@ private:
int body_shape;
int area_shape;
- bool operator<(const ShapePair& p_sp) const {
- if (body_shape==p_sp.body_shape)
+ bool operator<(const ShapePair &p_sp) const {
+ if (body_shape == p_sp.body_shape)
return area_shape < p_sp.area_shape;
else
return body_shape < p_sp.body_shape;
}
ShapePair() {}
- ShapePair(int p_bs, int p_as) { body_shape=p_bs; area_shape=p_as; }
+ ShapePair(int p_bs, int p_as) {
+ body_shape = p_bs;
+ area_shape = p_as;
+ }
};
struct BodyState {
@@ -89,10 +90,9 @@ private:
VSet<ShapePair> shapes;
};
- Map<ObjectID,BodyState> body_map;
+ Map<ObjectID, BodyState> body_map;
-
- void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape);
+ void _area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape);
void _area_enter_tree(ObjectID p_id);
void _area_exit_tree(ObjectID p_id);
@@ -101,15 +101,18 @@ private:
int area_shape;
int self_shape;
- bool operator<(const AreaShapePair& p_sp) const {
- if (area_shape==p_sp.area_shape)
+ bool operator<(const AreaShapePair &p_sp) const {
+ if (area_shape == p_sp.area_shape)
return self_shape < p_sp.self_shape;
else
return area_shape < p_sp.area_shape;
}
AreaShapePair() {}
- AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; }
+ AreaShapePair(int p_bs, int p_as) {
+ area_shape = p_bs;
+ self_shape = p_as;
+ }
};
struct AreaState {
@@ -119,16 +122,14 @@ private:
VSet<AreaShapePair> shapes;
};
- Map<ObjectID,AreaState> area_map;
+ Map<ObjectID, AreaState> area_map;
void _clear_monitoring();
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_space_override_mode(SpaceOverride p_mode);
SpaceOverride get_space_override_mode() const;
@@ -138,7 +139,7 @@ public:
void set_gravity_distance_scale(real_t p_scale);
real_t get_gravity_distance_scale() const;
- void set_gravity_vector(const Vector3& p_vec);
+ void set_gravity_vector(const Vector3 &p_vec);
Vector3 get_gravity_vector() const;
void set_gravity(real_t p_gravity);
@@ -174,9 +175,8 @@ public:
Array get_overlapping_bodies() const;
Array get_overlapping_areas() const; //function for script
- bool overlaps_area(Node* p_area) const;
- bool overlaps_body(Node* p_body) const;
-
+ bool overlaps_area(Node *p_area) const;
+ bool overlaps_body(Node *p_body) const;
Area();
~Area();
diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp
index e20d8faafd..ac424475ea 100644
--- a/scene/3d/baked_light_instance.cpp
+++ b/scene/3d/baked_light_instance.cpp
@@ -27,200 +27,226 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "baked_light_instance.h"
-#include "scene/scene_string_names.h"
-#include "mesh_instance.h"
#include "light.h"
#include "math.h"
+#include "mesh_instance.h"
+#include "scene/scene_string_names.h"
-#define FINDMINMAX(x0,x1,x2,min,max) \
- min = max = x0; \
- if(x1<min) min=x1;\
- if(x1>max) max=x1;\
- if(x2<min) min=x2;\
- if(x2>max) max=x2;
-
-static bool planeBoxOverlap(Vector3 normal,float d, Vector3 maxbox)
-{
- int q;
- Vector3 vmin,vmax;
- for(q=0;q<=2;q++)
- {
- if(normal[q]>0.0f)
- {
- vmin[q]=-maxbox[q];
- vmax[q]=maxbox[q];
- }
- else
- {
- vmin[q]=maxbox[q];
- vmax[q]=-maxbox[q];
- }
- }
- if(normal.dot(vmin)+d>0.0f) return false;
- if(normal.dot(vmax)+d>=0.0f) return true;
-
- return false;
-}
+#define FINDMINMAX(x0, x1, x2, min, max) \
+ min = max = x0; \
+ if (x1 < min) min = x1; \
+ if (x1 > max) max = x1; \
+ if (x2 < min) min = x2; \
+ if (x2 > max) max = x2;
+
+static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) {
+ int q;
+ Vector3 vmin, vmax;
+ for (q = 0; q <= 2; q++) {
+ if (normal[q] > 0.0f) {
+ vmin[q] = -maxbox[q];
+ vmax[q] = maxbox[q];
+ } else {
+ vmin[q] = maxbox[q];
+ vmax[q] = -maxbox[q];
+ }
+ }
+ if (normal.dot(vmin) + d > 0.0f) return false;
+ if (normal.dot(vmax) + d >= 0.0f) return true;
+ return false;
+}
/*======================== X-tests ========================*/
-#define AXISTEST_X01(a, b, fa, fb) \
- p0 = a*v0.y - b*v0.z; \
- p2 = a*v2.y - b*v2.z; \
- if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} \
- rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
-
-#define AXISTEST_X2(a, b, fa, fb) \
- p0 = a*v0.y - b*v0.z; \
- p1 = a*v1.y - b*v1.z; \
- if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} \
- rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
+#define AXISTEST_X01(a, b, fa, fb) \
+ p0 = a * v0.y - b * v0.z; \
+ p2 = a * v2.y - b * v2.z; \
+ if (p0 < p2) { \
+ min = p0; \
+ max = p2; \
+ } else { \
+ min = p2; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
+
+#define AXISTEST_X2(a, b, fa, fb) \
+ p0 = a * v0.y - b * v0.z; \
+ p1 = a * v1.y - b * v1.z; \
+ if (p0 < p1) { \
+ min = p0; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
/*======================== Y-tests ========================*/
-#define AXISTEST_Y02(a, b, fa, fb) \
- p0 = -a*v0.x + b*v0.z; \
- p2 = -a*v2.x + b*v2.z; \
- if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
-
-#define AXISTEST_Y1(a, b, fa, fb) \
- p0 = -a*v0.x + b*v0.z; \
- p1 = -a*v1.x + b*v1.z; \
- if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
+#define AXISTEST_Y02(a, b, fa, fb) \
+ p0 = -a * v0.x + b * v0.z; \
+ p2 = -a * v2.x + b * v2.z; \
+ if (p0 < p2) { \
+ min = p0; \
+ max = p2; \
+ } else { \
+ min = p2; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
+
+#define AXISTEST_Y1(a, b, fa, fb) \
+ p0 = -a * v0.x + b * v0.z; \
+ p1 = -a * v1.x + b * v1.z; \
+ if (p0 < p1) { \
+ min = p0; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
/*======================== Z-tests ========================*/
-#define AXISTEST_Z12(a, b, fa, fb) \
- p1 = a*v1.x - b*v1.y; \
- p2 = a*v2.x - b*v2.y; \
- if(p2<p1) {min=p2; max=p1;} else {min=p1; max=p2;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if(min>rad || max<-rad) return false;
-
-#define AXISTEST_Z0(a, b, fa, fb) \
- p0 = a*v0.x - b*v0.y; \
- p1 = a*v1.x - b*v1.y; \
- if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if(min>rad || max<-rad) return false;
-
-static bool fast_tri_box_overlap(const Vector3& boxcenter,const Vector3 boxhalfsize,const Vector3 *triverts) {
-
- /* use separating axis theorem to test overlap between triangle and box */
- /* need to test for overlap in these directions: */
- /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
- /* we do not even need to test these) */
- /* 2) normal of the triangle */
- /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
- /* this gives 3x3=9 more tests */
- Vector3 v0,v1,v2;
- float min,max,d,p0,p1,p2,rad,fex,fey,fez;
- Vector3 normal,e0,e1,e2;
-
- /* This is the fastest branch on Sun */
- /* move everything so that the boxcenter is in (0,0,0) */
-
- v0=triverts[0]-boxcenter;
- v1=triverts[1]-boxcenter;
- v2=triverts[2]-boxcenter;
-
- /* compute triangle edges */
- e0=v1-v0; /* tri edge 0 */
- e1=v2-v1; /* tri edge 1 */
- e2=v0-v2; /* tri edge 2 */
-
- /* Bullet 3: */
- /* test the 9 tests first (this was faster) */
- fex = Math::abs(e0.x);
- fey = Math::abs(e0.y);
- fez = Math::abs(e0.z);
- AXISTEST_X01(e0.z, e0.y, fez, fey);
- AXISTEST_Y02(e0.z, e0.x, fez, fex);
- AXISTEST_Z12(e0.y, e0.x, fey, fex);
-
- fex = Math::abs(e1.x);
- fey = Math::abs(e1.y);
- fez = Math::abs(e1.z);
- AXISTEST_X01(e1.z, e1.y, fez, fey);
- AXISTEST_Y02(e1.z, e1.x, fez, fex);
- AXISTEST_Z0(e1.y, e1.x, fey, fex);
-
- fex = Math::abs(e2.x);
- fey = Math::abs(e2.y);
- fez = Math::abs(e2.z);
- AXISTEST_X2(e2.z, e2.y, fez, fey);
- AXISTEST_Y1(e2.z, e2.x, fez, fex);
- AXISTEST_Z12(e2.y, e2.x, fey, fex);
-
- /* Bullet 1: */
- /* first test overlap in the {x,y,z}-directions */
- /* find min, max of the triangle each direction, and test for overlap in */
- /* that direction -- this is equivalent to testing a minimal AABB around */
- /* the triangle against the AABB */
-
- /* test in X-direction */
- FINDMINMAX(v0.x,v1.x,v2.x,min,max);
- if(min>boxhalfsize.x || max<-boxhalfsize.x) return false;
-
- /* test in Y-direction */
- FINDMINMAX(v0.y,v1.y,v2.y,min,max);
- if(min>boxhalfsize.y || max<-boxhalfsize.y) return false;
-
- /* test in Z-direction */
- FINDMINMAX(v0.z,v1.z,v2.z,min,max);
- if(min>boxhalfsize.z || max<-boxhalfsize.z) return false;
-
- /* Bullet 2: */
- /* test if the box intersects the plane of the triangle */
- /* compute plane equation of triangle: normal*x+d=0 */
- normal=e0.cross(e1);
- d=-normal.dot(v0); /* plane eq: normal.x+d=0 */
- if(!planeBoxOverlap(normal,d,boxhalfsize)) return false;
-
- return true; /* box and triangle overlaps */
+#define AXISTEST_Z12(a, b, fa, fb) \
+ p1 = a * v1.x - b * v1.y; \
+ p2 = a * v2.x - b * v2.y; \
+ if (p2 < p1) { \
+ min = p2; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p2; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
+ if (min > rad || max < -rad) return false;
+
+#define AXISTEST_Z0(a, b, fa, fb) \
+ p0 = a * v0.x - b * v0.y; \
+ p1 = a * v1.x - b * v1.y; \
+ if (p0 < p1) { \
+ min = p0; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
+ if (min > rad || max < -rad) return false;
+
+static bool fast_tri_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) {
+
+ /* use separating axis theorem to test overlap between triangle and box */
+ /* need to test for overlap in these directions: */
+ /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
+ /* we do not even need to test these) */
+ /* 2) normal of the triangle */
+ /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
+ /* this gives 3x3=9 more tests */
+ Vector3 v0, v1, v2;
+ float min, max, d, p0, p1, p2, rad, fex, fey, fez;
+ Vector3 normal, e0, e1, e2;
+
+ /* This is the fastest branch on Sun */
+ /* move everything so that the boxcenter is in (0,0,0) */
+
+ v0 = triverts[0] - boxcenter;
+ v1 = triverts[1] - boxcenter;
+ v2 = triverts[2] - boxcenter;
+
+ /* compute triangle edges */
+ e0 = v1 - v0; /* tri edge 0 */
+ e1 = v2 - v1; /* tri edge 1 */
+ e2 = v0 - v2; /* tri edge 2 */
+
+ /* Bullet 3: */
+ /* test the 9 tests first (this was faster) */
+ fex = Math::abs(e0.x);
+ fey = Math::abs(e0.y);
+ fez = Math::abs(e0.z);
+ AXISTEST_X01(e0.z, e0.y, fez, fey);
+ AXISTEST_Y02(e0.z, e0.x, fez, fex);
+ AXISTEST_Z12(e0.y, e0.x, fey, fex);
+
+ fex = Math::abs(e1.x);
+ fey = Math::abs(e1.y);
+ fez = Math::abs(e1.z);
+ AXISTEST_X01(e1.z, e1.y, fez, fey);
+ AXISTEST_Y02(e1.z, e1.x, fez, fex);
+ AXISTEST_Z0(e1.y, e1.x, fey, fex);
+
+ fex = Math::abs(e2.x);
+ fey = Math::abs(e2.y);
+ fez = Math::abs(e2.z);
+ AXISTEST_X2(e2.z, e2.y, fez, fey);
+ AXISTEST_Y1(e2.z, e2.x, fez, fex);
+ AXISTEST_Z12(e2.y, e2.x, fey, fex);
+
+ /* Bullet 1: */
+ /* first test overlap in the {x,y,z}-directions */
+ /* find min, max of the triangle each direction, and test for overlap in */
+ /* that direction -- this is equivalent to testing a minimal AABB around */
+ /* the triangle against the AABB */
+
+ /* test in X-direction */
+ FINDMINMAX(v0.x, v1.x, v2.x, min, max);
+ if (min > boxhalfsize.x || max < -boxhalfsize.x) return false;
+
+ /* test in Y-direction */
+ FINDMINMAX(v0.y, v1.y, v2.y, min, max);
+ if (min > boxhalfsize.y || max < -boxhalfsize.y) return false;
+
+ /* test in Z-direction */
+ FINDMINMAX(v0.z, v1.z, v2.z, min, max);
+ if (min > boxhalfsize.z || max < -boxhalfsize.z) return false;
+
+ /* Bullet 2: */
+ /* test if the box intersects the plane of the triangle */
+ /* compute plane equation of triangle: normal*x+d=0 */
+ normal = e0.cross(e1);
+ d = -normal.dot(v0); /* plane eq: normal.x+d=0 */
+ if (!planeBoxOverlap(normal, d, boxhalfsize)) return false;
+
+ return true; /* box and triangle overlaps */
}
-
-Vector<Color> BakedLight::_get_bake_texture(Image &p_image,const Color& p_color) {
+Vector<Color> BakedLight::_get_bake_texture(Image &p_image, const Color &p_color) {
Vector<Color> ret;
if (p_image.empty()) {
- ret.resize(bake_texture_size*bake_texture_size);
- for(int i=0;i<bake_texture_size*bake_texture_size;i++) {
- ret[i]=p_color;
+ ret.resize(bake_texture_size * bake_texture_size);
+ for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
+ ret[i] = p_color;
}
return ret;
}
p_image.convert(Image::FORMAT_RGBA8);
- p_image.resize(bake_texture_size,bake_texture_size,Image::INTERPOLATE_CUBIC);
-
+ p_image.resize(bake_texture_size, bake_texture_size, Image::INTERPOLATE_CUBIC);
PoolVector<uint8_t>::Read r = p_image.get_data().read();
- ret.resize(bake_texture_size*bake_texture_size);
+ ret.resize(bake_texture_size * bake_texture_size);
- for(int i=0;i<bake_texture_size*bake_texture_size;i++) {
+ for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
Color c;
- c.r = r[i*4+0]/255.0;
- c.g = r[i*4+1]/255.0;
- c.b = r[i*4+2]/255.0;
- c.a = r[i*4+3]/255.0;
- ret[i]=c;
-
+ c.r = r[i * 4 + 0] / 255.0;
+ c.g = r[i * 4 + 1] / 255.0;
+ c.b = r[i * 4 + 2] / 255.0;
+ c.a = r[i * 4 + 3] / 255.0;
+ ret[i] = c;
}
return ret;
}
-
BakedLight::MaterialCache BakedLight::_get_material_cache(Ref<Material> p_material) {
//this way of obtaining materials is inaccurate and also does not support some compressed formats very well
@@ -236,7 +262,6 @@ BakedLight::MaterialCache BakedLight::_get_material_cache(Ref<Material> p_materi
if (mat.is_valid()) {
-
Ref<ImageTexture> albedo_tex = mat->get_texture(FixedSpatialMaterial::TEXTURE_ALBEDO);
Image img_albedo;
@@ -245,14 +270,14 @@ BakedLight::MaterialCache BakedLight::_get_material_cache(Ref<Material> p_materi
img_albedo = albedo_tex->get_data();
}
- mc.albedo=_get_bake_texture(img_albedo,mat->get_albedo());
+ mc.albedo = _get_bake_texture(img_albedo, mat->get_albedo());
Ref<ImageTexture> emission_tex = mat->get_texture(FixedSpatialMaterial::TEXTURE_EMISSION);
Color emission_col = mat->get_emission();
- emission_col.r*=mat->get_emission_energy();
- emission_col.g*=mat->get_emission_energy();
- emission_col.b*=mat->get_emission_energy();
+ emission_col.r *= mat->get_emission_energy();
+ emission_col.g *= mat->get_emission_energy();
+ emission_col.b *= mat->get_emission_energy();
Image img_emission;
@@ -261,503 +286,465 @@ BakedLight::MaterialCache BakedLight::_get_material_cache(Ref<Material> p_materi
img_emission = emission_tex->get_data();
}
- mc.emission=_get_bake_texture(img_emission,emission_col);
+ mc.emission = _get_bake_texture(img_emission, emission_col);
} else {
Image empty;
- mc.albedo=_get_bake_texture(empty,Color(0.7,0.7,0.7));
- mc.emission=_get_bake_texture(empty,Color(0,0,0));
-
-
+ mc.albedo = _get_bake_texture(empty, Color(0.7, 0.7, 0.7));
+ mc.emission = _get_bake_texture(empty, Color(0, 0, 0));
}
- material_cache[p_material]=mc;
+ material_cache[p_material] = mc;
return mc;
-
-
}
+static _FORCE_INLINE_ Vector2 get_uv(const Vector3 &p_pos, const Vector3 *p_vtx, const Vector2 *p_uv) {
-
-static _FORCE_INLINE_ Vector2 get_uv(const Vector3& p_pos, const Vector3 *p_vtx, const Vector2* p_uv) {
-
- if (p_pos.distance_squared_to(p_vtx[0])<CMP_EPSILON2)
+ if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2)
return p_uv[0];
- if (p_pos.distance_squared_to(p_vtx[1])<CMP_EPSILON2)
+ if (p_pos.distance_squared_to(p_vtx[1]) < CMP_EPSILON2)
return p_uv[1];
- if (p_pos.distance_squared_to(p_vtx[2])<CMP_EPSILON2)
+ if (p_pos.distance_squared_to(p_vtx[2]) < CMP_EPSILON2)
return p_uv[2];
Vector3 v0 = p_vtx[1] - p_vtx[0];
Vector3 v1 = p_vtx[2] - p_vtx[0];
Vector3 v2 = p_pos - p_vtx[0];
- float d00 = v0.dot( v0);
- float d01 = v0.dot( v1);
- float d11 = v1.dot( v1);
- float d20 = v2.dot( v0);
- float d21 = v2.dot( v1);
+ float d00 = v0.dot(v0);
+ float d01 = v0.dot(v1);
+ float d11 = v1.dot(v1);
+ float d20 = v2.dot(v0);
+ float d21 = v2.dot(v1);
float denom = (d00 * d11 - d01 * d01);
- if (denom==0)
+ if (denom == 0)
return p_uv[0];
float v = (d11 * d20 - d01 * d21) / denom;
float w = (d00 * d21 - d01 * d20) / denom;
float u = 1.0f - v - w;
- return p_uv[0]*u + p_uv[1]*v + p_uv[2]*w;
+ return p_uv[0] * u + p_uv[1] * v + p_uv[2] * w;
}
-void BakedLight::_plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const Vector2* p_uv, const MaterialCache& p_material, const Rect3 &p_aabb) {
-
+void BakedLight::_plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const Vector2 *p_uv, const MaterialCache &p_material, const Rect3 &p_aabb) {
-
- if (p_level==cell_subdiv-1) {
+ if (p_level == cell_subdiv - 1) {
//plot the face by guessing it's albedo and emission value
//find best axis to map to, for scanning values
int closest_axis;
float closest_dot;
- Vector3 normal = Plane(p_vtx[0],p_vtx[1],p_vtx[2]).normal;
+ Vector3 normal = Plane(p_vtx[0], p_vtx[1], p_vtx[2]).normal;
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
Vector3 axis;
- axis[i]=1.0;
- float dot=ABS(normal.dot(axis));
- if (i==0 || dot>closest_dot) {
- closest_axis=i;
- closest_dot=dot;
+ axis[i] = 1.0;
+ float dot = ABS(normal.dot(axis));
+ if (i == 0 || dot > closest_dot) {
+ closest_axis = i;
+ closest_dot = dot;
}
}
Vector3 axis;
- axis[closest_axis]=1.0;
+ axis[closest_axis] = 1.0;
Vector3 t1;
- t1[(closest_axis+1)%3]=1.0;
+ t1[(closest_axis + 1) % 3] = 1.0;
Vector3 t2;
- t2[(closest_axis+2)%3]=1.0;
+ t2[(closest_axis + 2) % 3] = 1.0;
- t1*=p_aabb.size[(closest_axis+1)%3]/float(color_scan_cell_width);
- t2*=p_aabb.size[(closest_axis+2)%3]/float(color_scan_cell_width);
+ t1 *= p_aabb.size[(closest_axis + 1) % 3] / float(color_scan_cell_width);
+ t2 *= p_aabb.size[(closest_axis + 2) % 3] / float(color_scan_cell_width);
Color albedo_accum;
Color emission_accum;
- float alpha=0.0;
+ float alpha = 0.0;
//map to a grid average in the best axis for this face
- for(int i=0;i<color_scan_cell_width;i++) {
+ for (int i = 0; i < color_scan_cell_width; i++) {
- Vector3 ofs_i=float(i)*t1;
+ Vector3 ofs_i = float(i) * t1;
- for(int j=0;j<color_scan_cell_width;j++) {
+ for (int j = 0; j < color_scan_cell_width; j++) {
- Vector3 ofs_j=float(j)*t2;
+ Vector3 ofs_j = float(j) * t2;
- Vector3 from = p_aabb.pos+ofs_i+ofs_j;
+ Vector3 from = p_aabb.pos + ofs_i + ofs_j;
Vector3 to = from + t1 + t2 + axis * p_aabb.size[closest_axis];
- Vector3 half = (to-from)*0.5;
+ Vector3 half = (to - from) * 0.5;
//is in this cell?
- if (!fast_tri_box_overlap(from+half,half,p_vtx)) {
+ if (!fast_tri_box_overlap(from + half, half, p_vtx)) {
continue; //face does not span this cell
}
//go from -size to +size*2 to avoid skipping collisions
- Vector3 ray_from = from + (t1+t2)*0.5 - axis * p_aabb.size[closest_axis];
- Vector3 ray_to = ray_from + axis * p_aabb.size[closest_axis]*2;
+ Vector3 ray_from = from + (t1 + t2) * 0.5 - axis * p_aabb.size[closest_axis];
+ Vector3 ray_to = ray_from + axis * p_aabb.size[closest_axis] * 2;
Vector3 intersection;
- if (!Geometry::ray_intersects_triangle(ray_from,ray_to,p_vtx[0],p_vtx[1],p_vtx[2],&intersection)) {
+ if (!Geometry::ray_intersects_triangle(ray_from, ray_to, p_vtx[0], p_vtx[1], p_vtx[2], &intersection)) {
//no intersect? look in edges
- float closest_dist=1e20;
- for(int j=0;j<3;j++) {
+ float closest_dist = 1e20;
+ for (int j = 0; j < 3; j++) {
Vector3 c;
Vector3 inters;
- Geometry::get_closest_points_between_segments(p_vtx[j],p_vtx[(j+1)%3],ray_from,ray_to,inters,c);
- float d=c.distance_to(intersection);
- if (j==0 || d<closest_dist) {
- closest_dist=d;
- intersection=inters;
+ Geometry::get_closest_points_between_segments(p_vtx[j], p_vtx[(j + 1) % 3], ray_from, ray_to, inters, c);
+ float d = c.distance_to(intersection);
+ if (j == 0 || d < closest_dist) {
+ closest_dist = d;
+ intersection = inters;
}
}
}
- Vector2 uv = get_uv(intersection,p_vtx,p_uv);
-
+ Vector2 uv = get_uv(intersection, p_vtx, p_uv);
- int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
- int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
+ int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
+ int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
- int ofs = uv_y*bake_texture_size+uv_x;
- albedo_accum.r+=p_material.albedo[ofs].r;
- albedo_accum.g+=p_material.albedo[ofs].g;
- albedo_accum.b+=p_material.albedo[ofs].b;
- albedo_accum.a+=p_material.albedo[ofs].a;
-
- emission_accum.r+=p_material.emission[ofs].r;
- emission_accum.g+=p_material.emission[ofs].g;
- emission_accum.b+=p_material.emission[ofs].b;
- alpha+=1.0;
+ int ofs = uv_y * bake_texture_size + uv_x;
+ albedo_accum.r += p_material.albedo[ofs].r;
+ albedo_accum.g += p_material.albedo[ofs].g;
+ albedo_accum.b += p_material.albedo[ofs].b;
+ albedo_accum.a += p_material.albedo[ofs].a;
+ emission_accum.r += p_material.emission[ofs].r;
+ emission_accum.g += p_material.emission[ofs].g;
+ emission_accum.b += p_material.emission[ofs].b;
+ alpha += 1.0;
}
}
-
- if (alpha==0) {
+ if (alpha == 0) {
//could not in any way get texture information.. so use closest point to center
- Face3 f( p_vtx[0],p_vtx[1],p_vtx[2]);
- Vector3 inters = f.get_closest_point_to(p_aabb.pos+p_aabb.size*0.5);
+ Face3 f(p_vtx[0], p_vtx[1], p_vtx[2]);
+ Vector3 inters = f.get_closest_point_to(p_aabb.pos + p_aabb.size * 0.5);
- Vector2 uv = get_uv(inters,p_vtx,p_uv);
+ Vector2 uv = get_uv(inters, p_vtx, p_uv);
- int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
- int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
+ int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
+ int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
- int ofs = uv_y*bake_texture_size+uv_x;
+ int ofs = uv_y * bake_texture_size + uv_x;
- alpha = 1.0/(color_scan_cell_width*color_scan_cell_width);
+ alpha = 1.0 / (color_scan_cell_width * color_scan_cell_width);
- albedo_accum.r=p_material.albedo[ofs].r*alpha;
- albedo_accum.g=p_material.albedo[ofs].g*alpha;
- albedo_accum.b=p_material.albedo[ofs].b*alpha;
- albedo_accum.a=p_material.albedo[ofs].a*alpha;
-
- emission_accum.r=p_material.emission[ofs].r*alpha;
- emission_accum.g=p_material.emission[ofs].g*alpha;
- emission_accum.b=p_material.emission[ofs].b*alpha;
+ albedo_accum.r = p_material.albedo[ofs].r * alpha;
+ albedo_accum.g = p_material.albedo[ofs].g * alpha;
+ albedo_accum.b = p_material.albedo[ofs].b * alpha;
+ albedo_accum.a = p_material.albedo[ofs].a * alpha;
+ emission_accum.r = p_material.emission[ofs].r * alpha;
+ emission_accum.g = p_material.emission[ofs].g * alpha;
+ emission_accum.b = p_material.emission[ofs].b * alpha;
zero_alphas++;
} else {
- float accdiv = 1.0/(color_scan_cell_width*color_scan_cell_width);
- alpha*=accdiv;
+ float accdiv = 1.0 / (color_scan_cell_width * color_scan_cell_width);
+ alpha *= accdiv;
- albedo_accum.r*=accdiv;
- albedo_accum.g*=accdiv;
- albedo_accum.b*=accdiv;
- albedo_accum.a*=accdiv;
+ albedo_accum.r *= accdiv;
+ albedo_accum.g *= accdiv;
+ albedo_accum.b *= accdiv;
+ albedo_accum.a *= accdiv;
- emission_accum.r*=accdiv;
- emission_accum.g*=accdiv;
- emission_accum.b*=accdiv;
+ emission_accum.r *= accdiv;
+ emission_accum.g *= accdiv;
+ emission_accum.b *= accdiv;
}
//put this temporarily here, corrected in a later step
- bake_cells_write[p_idx].albedo[0]+=albedo_accum.r;
- bake_cells_write[p_idx].albedo[1]+=albedo_accum.g;
- bake_cells_write[p_idx].albedo[2]+=albedo_accum.b;
- bake_cells_write[p_idx].light[0]+=emission_accum.r;
- bake_cells_write[p_idx].light[1]+=emission_accum.g;
- bake_cells_write[p_idx].light[2]+=emission_accum.b;
- bake_cells_write[p_idx].alpha+=alpha;
-
- static const Vector3 side_normals[6]={
+ bake_cells_write[p_idx].albedo[0] += albedo_accum.r;
+ bake_cells_write[p_idx].albedo[1] += albedo_accum.g;
+ bake_cells_write[p_idx].albedo[2] += albedo_accum.b;
+ bake_cells_write[p_idx].light[0] += emission_accum.r;
+ bake_cells_write[p_idx].light[1] += emission_accum.g;
+ bake_cells_write[p_idx].light[2] += emission_accum.b;
+ bake_cells_write[p_idx].alpha += alpha;
+
+ static const Vector3 side_normals[6] = {
Vector3(-1, 0, 0),
- Vector3( 1, 0, 0),
- Vector3( 0,-1, 0),
- Vector3( 0, 1, 0),
- Vector3( 0, 0,-1),
- Vector3( 0, 0, 1),
+ Vector3(1, 0, 0),
+ Vector3(0, -1, 0),
+ Vector3(0, 1, 0),
+ Vector3(0, 0, -1),
+ Vector3(0, 0, 1),
};
- for(int i=0;i<6;i++) {
- if (normal.dot(side_normals[i])>CMP_EPSILON) {
- bake_cells_write[p_idx].used_sides|=(1<<i);
+ for (int i = 0; i < 6; i++) {
+ if (normal.dot(side_normals[i]) > CMP_EPSILON) {
+ bake_cells_write[p_idx].used_sides |= (1 << i);
}
}
-
} else {
//go down
- for(int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
- Rect3 aabb=p_aabb;
- aabb.size*=0.5;
+ Rect3 aabb = p_aabb;
+ aabb.size *= 0.5;
- if (i&1)
- aabb.pos.x+=aabb.size.x;
- if (i&2)
- aabb.pos.y+=aabb.size.y;
- if (i&4)
- aabb.pos.z+=aabb.size.z;
+ if (i & 1)
+ aabb.pos.x += aabb.size.x;
+ if (i & 2)
+ aabb.pos.y += aabb.size.y;
+ if (i & 4)
+ aabb.pos.z += aabb.size.z;
{
- Rect3 test_aabb=aabb;
+ Rect3 test_aabb = aabb;
//test_aabb.grow_by(test_aabb.get_longest_axis_size()*0.05); //grow a bit to avoid numerical error in real-time
- Vector3 qsize = test_aabb.size*0.5; //quarter size, for fast aabb test
+ Vector3 qsize = test_aabb.size * 0.5; //quarter size, for fast aabb test
- if (!fast_tri_box_overlap(test_aabb.pos+qsize,qsize,p_vtx)) {
- //if (!Face3(p_vtx[0],p_vtx[1],p_vtx[2]).intersects_aabb2(aabb)) {
+ if (!fast_tri_box_overlap(test_aabb.pos + qsize, qsize, p_vtx)) {
+ //if (!Face3(p_vtx[0],p_vtx[1],p_vtx[2]).intersects_aabb2(aabb)) {
//does not fit in child, go on
continue;
}
-
}
- if (bake_cells_write[p_idx].childs[i]==CHILD_EMPTY) {
+ if (bake_cells_write[p_idx].childs[i] == CHILD_EMPTY) {
//sub cell must be created
- if (bake_cells_used==(1<<bake_cells_alloc)) {
+ if (bake_cells_used == (1 << bake_cells_alloc)) {
//exhausted cells, creating more space
bake_cells_alloc++;
- bake_cells_write=PoolVector<BakeCell>::Write();
- bake_cells.resize(1<<bake_cells_alloc);
- bake_cells_write=bake_cells.write();
+ bake_cells_write = PoolVector<BakeCell>::Write();
+ bake_cells.resize(1 << bake_cells_alloc);
+ bake_cells_write = bake_cells.write();
}
- bake_cells_write[p_idx].childs[i]=bake_cells_used;
- bake_cells_level_used[p_level+1]++;
+ bake_cells_write[p_idx].childs[i] = bake_cells_used;
+ bake_cells_level_used[p_level + 1]++;
bake_cells_used++;
-
-
}
-
- _plot_face(bake_cells_write[p_idx].childs[i],p_level+1,p_vtx,p_uv,p_material,aabb);
+ _plot_face(bake_cells_write[p_idx].childs[i], p_level + 1, p_vtx, p_uv, p_material, aabb);
}
}
}
+void BakedLight::_fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z) {
-
-void BakedLight::_fixup_plot(int p_idx, int p_level,int p_x,int p_y, int p_z) {
-
-
-
- if (p_level==cell_subdiv-1) {
-
+ if (p_level == cell_subdiv - 1) {
float alpha = bake_cells_write[p_idx].alpha;
- bake_cells_write[p_idx].albedo[0]/=alpha;
- bake_cells_write[p_idx].albedo[1]/=alpha;
- bake_cells_write[p_idx].albedo[2]/=alpha;
+ bake_cells_write[p_idx].albedo[0] /= alpha;
+ bake_cells_write[p_idx].albedo[1] /= alpha;
+ bake_cells_write[p_idx].albedo[2] /= alpha;
//transfer emission to light
- bake_cells_write[p_idx].light[0]/=alpha;
- bake_cells_write[p_idx].light[1]/=alpha;
- bake_cells_write[p_idx].light[2]/=alpha;
+ bake_cells_write[p_idx].light[0] /= alpha;
+ bake_cells_write[p_idx].light[1] /= alpha;
+ bake_cells_write[p_idx].light[2] /= alpha;
- bake_cells_write[p_idx].alpha=1.0;
+ bake_cells_write[p_idx].alpha = 1.0;
//remove neighbours from used sides
- for(int n=0;n<6;n++) {
+ for (int n = 0; n < 6; n++) {
- int ofs[3]={0,0,0};
+ int ofs[3] = { 0, 0, 0 };
- ofs[n/2]=(n&1)?1:-1;
+ ofs[n / 2] = (n & 1) ? 1 : -1;
//convert to x,y,z on this level
- int x=p_x;
- int y=p_y;
- int z=p_z;
-
- x+=ofs[0];
- y+=ofs[1];
- z+=ofs[2];
+ int x = p_x;
+ int y = p_y;
+ int z = p_z;
- int ofs_x=0;
- int ofs_y=0;
- int ofs_z=0;
- int size = 1<<p_level;
- int half=size/2;
+ x += ofs[0];
+ y += ofs[1];
+ z += ofs[2];
+ int ofs_x = 0;
+ int ofs_y = 0;
+ int ofs_z = 0;
+ int size = 1 << p_level;
+ int half = size / 2;
- if (x<0 || x>=size || y<0 || y>=size || z<0 || z>=size) {
+ if (x < 0 || x >= size || y < 0 || y >= size || z < 0 || z >= size) {
//neighbour is out, can't use it
- bake_cells_write[p_idx].used_sides&=~(1<<uint32_t(n));
+ bake_cells_write[p_idx].used_sides &= ~(1 << uint32_t(n));
continue;
}
- uint32_t neighbour=0;
+ uint32_t neighbour = 0;
- for(int i=0;i<cell_subdiv-1;i++) {
+ for (int i = 0; i < cell_subdiv - 1; i++) {
BakeCell *bc = &bake_cells_write[neighbour];
int child = 0;
if (x >= ofs_x + half) {
- child|=1;
- ofs_x+=half;
+ child |= 1;
+ ofs_x += half;
}
if (y >= ofs_y + half) {
- child|=2;
- ofs_y+=half;
+ child |= 2;
+ ofs_y += half;
}
if (z >= ofs_z + half) {
- child|=4;
- ofs_z+=half;
+ child |= 4;
+ ofs_z += half;
}
neighbour = bc->childs[child];
- if (neighbour==CHILD_EMPTY) {
+ if (neighbour == CHILD_EMPTY) {
break;
}
- half>>=1;
+ half >>= 1;
}
- if (neighbour!=CHILD_EMPTY) {
- bake_cells_write[p_idx].used_sides&=~(1<<uint32_t(n));
+ if (neighbour != CHILD_EMPTY) {
+ bake_cells_write[p_idx].used_sides &= ~(1 << uint32_t(n));
}
}
} else {
-
//go down
- float alpha_average=0;
- int half = cells_per_axis >> (p_level+1);
- for(int i=0;i<8;i++) {
+ float alpha_average = 0;
+ int half = cells_per_axis >> (p_level + 1);
+ for (int i = 0; i < 8; i++) {
uint32_t child = bake_cells_write[p_idx].childs[i];
- if (child==CHILD_EMPTY)
+ if (child == CHILD_EMPTY)
continue;
+ int nx = p_x;
+ int ny = p_y;
+ int nz = p_z;
- int nx=p_x;
- int ny=p_y;
- int nz=p_z;
+ if (i & 1)
+ nx += half;
+ if (i & 2)
+ ny += half;
+ if (i & 4)
+ nz += half;
- if (i&1)
- nx+=half;
- if (i&2)
- ny+=half;
- if (i&4)
- nz+=half;
-
- _fixup_plot(child,p_level+1,nx,ny,nz);
- alpha_average+=bake_cells_write[child].alpha;
+ _fixup_plot(child, p_level + 1, nx, ny, nz);
+ alpha_average += bake_cells_write[child].alpha;
}
- bake_cells_write[p_idx].alpha=alpha_average/8.0;
- bake_cells_write[p_idx].light[0]=0;
- bake_cells_write[p_idx].light[1]=0;
- bake_cells_write[p_idx].light[2]=0;
- bake_cells_write[p_idx].albedo[0]=0;
- bake_cells_write[p_idx].albedo[1]=0;
- bake_cells_write[p_idx].albedo[2]=0;
-
+ bake_cells_write[p_idx].alpha = alpha_average / 8.0;
+ bake_cells_write[p_idx].light[0] = 0;
+ bake_cells_write[p_idx].light[1] = 0;
+ bake_cells_write[p_idx].light[2] = 0;
+ bake_cells_write[p_idx].albedo[0] = 0;
+ bake_cells_write[p_idx].albedo[1] = 0;
+ bake_cells_write[p_idx].albedo[2] = 0;
}
//clean up light
- bake_cells_write[p_idx].light_pass=0;
+ bake_cells_write[p_idx].light_pass = 0;
//find neighbours
-
-
-
}
+void BakedLight::_bake_add_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh) {
-void BakedLight::_bake_add_mesh(const Transform& p_xform,Ref<Mesh>& p_mesh) {
-
+ for (int i = 0; i < p_mesh->get_surface_count(); i++) {
- for(int i=0;i<p_mesh->get_surface_count();i++) {
-
- if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
continue; //only triangles
MaterialCache material = _get_material_cache(p_mesh->surface_get_material(i));
Array a = p_mesh->surface_get_arrays(i);
-
PoolVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
- PoolVector<Vector3>::Read vr=vertices.read();
+ PoolVector<Vector3>::Read vr = vertices.read();
PoolVector<Vector2> uv = a[Mesh::ARRAY_TEX_UV];
PoolVector<Vector2>::Read uvr;
PoolVector<int> index = a[Mesh::ARRAY_INDEX];
- bool read_uv=false;
+ bool read_uv = false;
if (uv.size()) {
- uvr=uv.read();
- read_uv=true;
+ uvr = uv.read();
+ read_uv = true;
}
if (index.size()) {
- int facecount = index.size()/3;
- PoolVector<int>::Read ir=index.read();
+ int facecount = index.size() / 3;
+ PoolVector<int>::Read ir = index.read();
- for(int j=0;j<facecount;j++) {
+ for (int j = 0; j < facecount; j++) {
Vector3 vtxs[3];
Vector2 uvs[3];
- for(int k=0;k<3;k++) {
- vtxs[k]=p_xform.xform(vr[ir[j*3+k]]);
+ for (int k = 0; k < 3; k++) {
+ vtxs[k] = p_xform.xform(vr[ir[j * 3 + k]]);
}
if (read_uv) {
- for(int k=0;k<3;k++) {
- uvs[k]=uvr[ir[j*3+k]];
+ for (int k = 0; k < 3; k++) {
+ uvs[k] = uvr[ir[j * 3 + k]];
}
}
//plot face
- _plot_face(0,0,vtxs,uvs,material,bounds);
+ _plot_face(0, 0, vtxs, uvs, material, bounds);
}
-
-
} else {
- int facecount = vertices.size()/3;
+ int facecount = vertices.size() / 3;
- for(int j=0;j<facecount;j++) {
+ for (int j = 0; j < facecount; j++) {
Vector3 vtxs[3];
Vector2 uvs[3];
- for(int k=0;k<3;k++) {
- vtxs[k]=p_xform.xform(vr[j*3+k]);
+ for (int k = 0; k < 3; k++) {
+ vtxs[k] = p_xform.xform(vr[j * 3 + k]);
}
if (read_uv) {
- for(int k=0;k<3;k++) {
- uvs[k]=uvr[j*3+k];
+ for (int k = 0; k < 3; k++) {
+ uvs[k] = uvr[j * 3 + k];
}
}
//plot face
- _plot_face(0,0,vtxs,uvs,material,bounds);
+ _plot_face(0, 0, vtxs, uvs, material, bounds);
}
-
}
}
}
+void BakedLight::_bake_add_to_aabb(const Transform &p_xform, Ref<Mesh> &p_mesh, bool &first) {
+ for (int i = 0; i < p_mesh->get_surface_count(); i++) {
-void BakedLight::_bake_add_to_aabb(const Transform& p_xform,Ref<Mesh>& p_mesh,bool &first) {
-
- for(int i=0;i<p_mesh->get_surface_count();i++) {
-
- if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
continue; //only triangles
Array a = p_mesh->surface_get_arrays(i);
PoolVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
int vc = vertices.size();
- PoolVector<Vector3>::Read vr=vertices.read();
+ PoolVector<Vector3>::Read vr = vertices.read();
if (first) {
- bounds.pos=p_xform.xform(vr[0]);
- first=false;
+ bounds.pos = p_xform.xform(vr[0]);
+ first = false;
}
-
- for(int j=0;j<vc;j++) {
+ for (int j = 0; j < vc; j++) {
bounds.expand_to(p_xform.xform(vr[j]));
}
}
@@ -765,25 +752,24 @@ void BakedLight::_bake_add_to_aabb(const Transform& p_xform,Ref<Mesh>& p_mesh,bo
void BakedLight::bake() {
+ bake_cells_alloc = 16;
+ bake_cells.resize(1 << bake_cells_alloc);
+ bake_cells_used = 1;
+ cells_per_axis = (1 << (cell_subdiv - 1));
+ zero_alphas = 0;
- bake_cells_alloc=16;
- bake_cells.resize(1<<bake_cells_alloc);
- bake_cells_used=1;
- cells_per_axis=(1<<(cell_subdiv-1));
- zero_alphas=0;
-
- bool aabb_first=true;
+ bool aabb_first = true;
print_line("Generating AABB");
bake_cells_level_used.resize(cell_subdiv);
- for(int i=0;i<cell_subdiv;i++) {
- bake_cells_level_used[i]=0;
+ for (int i = 0; i < cell_subdiv; i++) {
+ bake_cells_level_used[i] = 0;
}
- int count=0;
- for (Set<GeometryInstance*>::Element *E=geometries.front();E;E=E->next()) {
+ int count = 0;
+ for (Set<GeometryInstance *>::Element *E = geometries.front(); E; E = E->next()) {
- print_line("aabb geom "+itos(count)+"/"+itos(geometries.size()));
+ print_line("aabb geom " + itos(count) + "/" + itos(geometries.size()));
GeometryInstance *geom = E->get();
@@ -793,22 +779,22 @@ void BakedLight::bake() {
Ref<Mesh> mesh = mesh_instance->get_mesh();
if (mesh.is_valid()) {
- _bake_add_to_aabb(geom->get_relative_transform(this),mesh,aabb_first);
+ _bake_add_to_aabb(geom->get_relative_transform(this), mesh, aabb_first);
}
}
count++;
}
- print_line("AABB: "+bounds);
+ print_line("AABB: " + bounds);
ERR_FAIL_COND(aabb_first);
bake_cells_write = bake_cells.write();
- count=0;
+ count = 0;
- for (Set<GeometryInstance*>::Element *E=geometries.front();E;E=E->next()) {
+ for (Set<GeometryInstance *>::Element *E = geometries.front(); E; E = E->next()) {
GeometryInstance *geom = E->get();
- print_line("plot geom "+itos(count)+"/"+itos(geometries.size()));
+ print_line("plot geom " + itos(count) + "/" + itos(geometries.size()));
if (geom->cast_to<MeshInstance>()) {
@@ -816,127 +802,107 @@ void BakedLight::bake() {
Ref<Mesh> mesh = mesh_instance->get_mesh();
if (mesh.is_valid()) {
- _bake_add_mesh(geom->get_relative_transform(this),mesh);
+ _bake_add_mesh(geom->get_relative_transform(this), mesh);
}
}
count++;
}
+ _fixup_plot(0, 0, 0, 0, 0);
- _fixup_plot(0, 0,0,0,0);
-
-
- bake_cells_write=PoolVector<BakeCell>::Write();
+ bake_cells_write = PoolVector<BakeCell>::Write();
bake_cells.resize(bake_cells_used);
-
-
- print_line("total bake cells used: "+itos(bake_cells_used));
- for(int i=0;i<cell_subdiv;i++) {
- print_line("level "+itos(i)+": "+itos(bake_cells_level_used[i]));
+ print_line("total bake cells used: " + itos(bake_cells_used));
+ for (int i = 0; i < cell_subdiv; i++) {
+ print_line("level " + itos(i) + ": " + itos(bake_cells_level_used[i]));
}
- print_line("zero alphas: "+itos(zero_alphas));
-
-
-
+ print_line("zero alphas: " + itos(zero_alphas));
}
+void BakedLight::_bake_directional(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 &p_dir, const Color &p_color, int p_sign) {
-
-void BakedLight::_bake_directional(int p_idx, int p_level, int p_x,int p_y,int p_z,const Vector3& p_dir,const Color& p_color,int p_sign) {
-
-
-
-
- if (p_level==cell_subdiv-1) {
+ if (p_level == cell_subdiv - 1) {
Vector3 end;
- end.x = float(p_x+0.5) / cells_per_axis;
- end.y = float(p_y+0.5) / cells_per_axis;
- end.z = float(p_z+0.5) / cells_per_axis;
+ end.x = float(p_x + 0.5) / cells_per_axis;
+ end.y = float(p_y + 0.5) / cells_per_axis;
+ end.z = float(p_z + 0.5) / cells_per_axis;
- end = bounds.pos + bounds.size*end;
+ end = bounds.pos + bounds.size * end;
- float max_ray_len = (bounds.size).length()*1.2;
+ float max_ray_len = (bounds.size).length() * 1.2;
- Vector3 begin = end + max_ray_len*-p_dir;
+ Vector3 begin = end + max_ray_len * -p_dir;
//clip begin
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
- if (ABS(p_dir[i])<CMP_EPSILON) {
+ if (ABS(p_dir[i]) < CMP_EPSILON) {
continue; // parallel to axis, don't clip
}
Plane p;
- p.normal[i]=1.0;
- p.d=bounds.pos[i];
- if (p_dir[i]<0) {
- p.d+=bounds.size[i];
+ p.normal[i] = 1.0;
+ p.d = bounds.pos[i];
+ if (p_dir[i] < 0) {
+ p.d += bounds.size[i];
}
Vector3 inters;
- if (p.intersects_segment(end,begin,&inters)) {
- begin=inters;
+ if (p.intersects_segment(end, begin, &inters)) {
+ begin = inters;
}
-
}
+ int idx = _plot_ray(begin, end);
- int idx = _plot_ray(begin,end);
-
- if (idx>=0 && light_pass!=bake_cells_write[idx].light_pass) {
+ if (idx >= 0 && light_pass != bake_cells_write[idx].light_pass) {
//hit something, add or remove light to it
- Color albedo = Color(bake_cells_write[idx].albedo[0],bake_cells_write[idx].albedo[1],bake_cells_write[idx].albedo[2]);
- bake_cells_write[idx].light[0]+=albedo.r*p_color.r*p_sign;
- bake_cells_write[idx].light[1]+=albedo.g*p_color.g*p_sign;
- bake_cells_write[idx].light[2]+=albedo.b*p_color.b*p_sign;
- bake_cells_write[idx].light_pass=light_pass;
-
+ Color albedo = Color(bake_cells_write[idx].albedo[0], bake_cells_write[idx].albedo[1], bake_cells_write[idx].albedo[2]);
+ bake_cells_write[idx].light[0] += albedo.r * p_color.r * p_sign;
+ bake_cells_write[idx].light[1] += albedo.g * p_color.g * p_sign;
+ bake_cells_write[idx].light[2] += albedo.b * p_color.b * p_sign;
+ bake_cells_write[idx].light_pass = light_pass;
}
-
} else {
- int half = cells_per_axis >> (p_level+1);
+ int half = cells_per_axis >> (p_level + 1);
//go down
- for(int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
uint32_t child = bake_cells_write[p_idx].childs[i];
- if (child==CHILD_EMPTY)
+ if (child == CHILD_EMPTY)
continue;
- int nx=p_x;
- int ny=p_y;
- int nz=p_z;
-
- if (i&1)
- nx+=half;
- if (i&2)
- ny+=half;
- if (i&4)
- nz+=half;
+ int nx = p_x;
+ int ny = p_y;
+ int nz = p_z;
+ if (i & 1)
+ nx += half;
+ if (i & 2)
+ ny += half;
+ if (i & 4)
+ nz += half;
- _bake_directional(child,p_level+1,nx,ny,nz,p_dir,p_color,p_sign);
+ _bake_directional(child, p_level + 1, nx, ny, nz, p_dir, p_color, p_sign);
}
}
}
-
-
-
-void BakedLight::_bake_light(Light* p_light) {
+void BakedLight::_bake_light(Light *p_light) {
if (p_light->cast_to<DirectionalLight>()) {
- DirectionalLight * dl = p_light->cast_to<DirectionalLight>();
+ DirectionalLight *dl = p_light->cast_to<DirectionalLight>();
Transform rel_xf = dl->get_relative_transform(this);
@@ -944,91 +910,79 @@ void BakedLight::_bake_light(Light* p_light) {
Color color = dl->get_color();
float nrg = dl->get_param(Light::PARAM_ENERGY);
- color.r*=nrg;
- color.g*=nrg;
- color.b*=nrg;
+ color.r *= nrg;
+ color.g *= nrg;
+ color.b *= nrg;
light_pass++;
- _bake_directional(0,0,0,0,0,light_dir,color,1);
-
+ _bake_directional(0, 0, 0, 0, 0, light_dir, color, 1);
}
}
-
-void BakedLight::_upscale_light(int p_idx,int p_level) {
-
+void BakedLight::_upscale_light(int p_idx, int p_level) {
//go down
- float light_accum[3]={0,0,0};
- float alpha_accum=0;
+ float light_accum[3] = { 0, 0, 0 };
+ float alpha_accum = 0;
- bool check_children = p_level < (cell_subdiv -2);
+ bool check_children = p_level < (cell_subdiv - 2);
- for(int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
uint32_t child = bake_cells_write[p_idx].childs[i];
- if (child==CHILD_EMPTY)
+ if (child == CHILD_EMPTY)
continue;
if (check_children) {
- _upscale_light(child,p_level+1);
+ _upscale_light(child, p_level + 1);
}
- light_accum[0]+=bake_cells_write[child].light[0];
- light_accum[1]+=bake_cells_write[child].light[1];
- light_accum[2]+=bake_cells_write[child].light[2];
- alpha_accum+=bake_cells_write[child].alpha;
-
+ light_accum[0] += bake_cells_write[child].light[0];
+ light_accum[1] += bake_cells_write[child].light[1];
+ light_accum[2] += bake_cells_write[child].light[2];
+ alpha_accum += bake_cells_write[child].alpha;
}
- bake_cells_write[p_idx].light[0]=light_accum[0]/8.0;
- bake_cells_write[p_idx].light[1]=light_accum[1]/8.0;
- bake_cells_write[p_idx].light[2]=light_accum[2]/8.0;
- bake_cells_write[p_idx].alpha=alpha_accum/8.0;
-
+ bake_cells_write[p_idx].light[0] = light_accum[0] / 8.0;
+ bake_cells_write[p_idx].light[1] = light_accum[1] / 8.0;
+ bake_cells_write[p_idx].light[2] = light_accum[2] / 8.0;
+ bake_cells_write[p_idx].alpha = alpha_accum / 8.0;
}
-
void BakedLight::bake_lights() {
- ERR_FAIL_COND(bake_cells.size()==0);
+ ERR_FAIL_COND(bake_cells.size() == 0);
bake_cells_write = bake_cells.write();
- for(Set<Light*>::Element *E=lights.front();E;E=E->next()) {
+ for (Set<Light *>::Element *E = lights.front(); E; E = E->next()) {
_bake_light(E->get());
}
+ _upscale_light(0, 0);
- _upscale_light(0,0);
-
- bake_cells_write=PoolVector<BakeCell>::Write();
-
+ bake_cells_write = PoolVector<BakeCell>::Write();
}
+Color BakedLight::_cone_trace(const Vector3 &p_from, const Vector3 &p_dir, float p_half_angle) {
+ Color color(0, 0, 0, 0);
+ float tha = Math::tan(p_half_angle); //tan half angle
+ Vector3 from = (p_from - bounds.pos) / bounds.size; //convert to 0..1
+ from /= cells_per_axis; //convert to voxels of size 1
+ Vector3 dir = (p_dir / bounds.size).normalized();
-Color BakedLight::_cone_trace(const Vector3& p_from, const Vector3& p_dir, float p_half_angle) {
-
-
- Color color(0,0,0,0);
- float tha = Math::tan(p_half_angle);//tan half angle
- Vector3 from =(p_from-bounds.pos)/bounds.size; //convert to 0..1
- from/=cells_per_axis; //convert to voxels of size 1
- Vector3 dir = (p_dir/bounds.size).normalized();
-
- float max_dist = Vector3(cells_per_axis,cells_per_axis,cells_per_axis).length();
+ float max_dist = Vector3(cells_per_axis, cells_per_axis, cells_per_axis).length();
float dist = 1.0;
// self occlusion in flat surfaces
- float alpha=0;
+ float alpha = 0;
-
- while(dist < max_dist && alpha < 0.95) {
+ while (dist < max_dist && alpha < 0.95) {
#if 0
// smallest sample diameter possible is the voxel size
@@ -1149,56 +1103,55 @@ Color BakedLight::_cone_trace(const Vector3& p_from, const Vector3& p_dir, float
float diameter = 1.0;
Vector3 sample_pos = from + dist * dir;
- Color m(0,0,0,0);
+ Color m(0, 0, 0, 0);
{
int x = Math::floor(sample_pos.x);
int y = Math::floor(sample_pos.y);
int z = Math::floor(sample_pos.z);
- int ofs_x=0;
- int ofs_y=0;
- int ofs_z=0;
+ int ofs_x = 0;
+ int ofs_y = 0;
+ int ofs_z = 0;
int size = cells_per_axis;
- int half=size/2;
+ int half = size / 2;
- bool outside=x<0 || x>=size || y<0 || y>=size || z<0 || z>=size;
+ bool outside = x < 0 || x >= size || y < 0 || y >= size || z < 0 || z >= size;
if (!outside) {
+ uint32_t cell = 0;
- uint32_t cell=0;
-
- for(int i=0;i<cell_subdiv-1;i++) {
+ for (int i = 0; i < cell_subdiv - 1; i++) {
BakeCell *bc = &bake_cells_write[cell];
int child = 0;
if (x >= ofs_x + half) {
- child|=1;
- ofs_x+=half;
+ child |= 1;
+ ofs_x += half;
}
if (y >= ofs_y + half) {
- child|=2;
- ofs_y+=half;
+ child |= 2;
+ ofs_y += half;
}
if (z >= ofs_z + half) {
- child|=4;
- ofs_z+=half;
+ child |= 4;
+ ofs_z += half;
}
cell = bc->childs[child];
- if (cell==CHILD_EMPTY)
+ if (cell == CHILD_EMPTY)
break;
- half>>=1;
+ half >>= 1;
}
- if (cell!=CHILD_EMPTY) {
+ if (cell != CHILD_EMPTY) {
- m.r=bake_cells_write[cell].light[0];
- m.g=bake_cells_write[cell].light[1];
- m.b=bake_cells_write[cell].light[2];
- m.a=bake_cells_write[cell].alpha;
+ m.r = bake_cells_write[cell].light[0];
+ m.g = bake_cells_write[cell].light[1];
+ m.b = bake_cells_write[cell].light[2];
+ m.a = bake_cells_write[cell].alpha;
}
}
}
@@ -1219,72 +1172,64 @@ Color BakedLight::_cone_trace(const Vector3& p_from, const Vector3& p_dir, float
return color;
}
+void BakedLight::_bake_radiance(int p_idx, int p_level, int p_x, int p_y, int p_z) {
-
-void BakedLight::_bake_radiance(int p_idx, int p_level, int p_x,int p_y,int p_z) {
-
-
-
-
- if (p_level==cell_subdiv-1) {
+ if (p_level == cell_subdiv - 1) {
const int NUM_CONES = 6;
Vector3 cone_directions[6] = {
- Vector3(1, 0, 0),
- Vector3(0.5, 0.866025, 0),
- Vector3( 0.5, 0.267617, 0.823639),
- Vector3( 0.5, -0.700629, 0.509037),
- Vector3( 0.5, -0.700629, -0.509037),
- Vector3( 0.5, 0.267617, -0.823639)
- };
- float coneWeights[6] = {0.25, 0.15, 0.15, 0.15, 0.15, 0.15};
-
- Vector3 pos = (Vector3(p_x,p_y,p_z)/float(cells_per_axis))*bounds.size+bounds.pos;
- Vector3 voxel_size = bounds.size/float(cells_per_axis);
- pos+=voxel_size*0.5;
+ Vector3(1, 0, 0),
+ Vector3(0.5, 0.866025, 0),
+ Vector3(0.5, 0.267617, 0.823639),
+ Vector3(0.5, -0.700629, 0.509037),
+ Vector3(0.5, -0.700629, -0.509037),
+ Vector3(0.5, 0.267617, -0.823639)
+ };
+ float coneWeights[6] = { 0.25, 0.15, 0.15, 0.15, 0.15, 0.15 };
+
+ Vector3 pos = (Vector3(p_x, p_y, p_z) / float(cells_per_axis)) * bounds.size + bounds.pos;
+ Vector3 voxel_size = bounds.size / float(cells_per_axis);
+ pos += voxel_size * 0.5;
Color accum;
- bake_cells_write[p_idx].light[0]=0;
- bake_cells_write[p_idx].light[1]=0;
- bake_cells_write[p_idx].light[2]=0;
+ bake_cells_write[p_idx].light[0] = 0;
+ bake_cells_write[p_idx].light[1] = 0;
+ bake_cells_write[p_idx].light[2] = 0;
- int freepix=0;
- for(int i=0;i<6;i++) {
+ int freepix = 0;
+ for (int i = 0; i < 6; i++) {
- if (!(bake_cells_write[p_idx].used_sides&(1<<i)))
+ if (!(bake_cells_write[p_idx].used_sides & (1 << i)))
continue;
- if ((i&1)==0)
- bake_cells_write[p_idx].light[i/2]=1.0;
+ if ((i & 1) == 0)
+ bake_cells_write[p_idx].light[i / 2] = 1.0;
freepix++;
continue;
- int ofs = i/2;
+ int ofs = i / 2;
Vector3 dir;
- if ((i&1)==0)
- dir[ofs]=1.0;
+ if ((i & 1) == 0)
+ dir[ofs] = 1.0;
else
- dir[ofs]=-1.0;
-
- for(int j=0;j<1;j++) {
+ dir[ofs] = -1.0;
+ for (int j = 0; j < 1; j++) {
Vector3 cone_dir;
- cone_dir.x = cone_directions[j][(ofs+0)%3];
- cone_dir.y = cone_directions[j][(ofs+1)%3];
- cone_dir.z = cone_directions[j][(ofs+2)%3];
+ cone_dir.x = cone_directions[j][(ofs + 0) % 3];
+ cone_dir.y = cone_directions[j][(ofs + 1) % 3];
+ cone_dir.z = cone_directions[j][(ofs + 2) % 3];
- cone_dir[ofs]*=dir[ofs];
+ cone_dir[ofs] *= dir[ofs];
- Color res = _cone_trace(pos+dir*voxel_size,cone_dir,Math::deg2rad(29.9849));
- accum.r+=res.r;//*coneWeights[j];
- accum.g+=res.g;//*coneWeights[j];
- accum.b+=res.b;//*coneWeights[j];
+ Color res = _cone_trace(pos + dir * voxel_size, cone_dir, Math::deg2rad(29.9849));
+ accum.r += res.r; //*coneWeights[j];
+ accum.g += res.g; //*coneWeights[j];
+ accum.b += res.b; //*coneWeights[j];
}
-
-
}
#if 0
if (freepix==0) {
@@ -1333,108 +1278,101 @@ void BakedLight::_bake_radiance(int p_idx, int p_level, int p_x,int p_y,int p_z)
//bake_cells_write[p_idx].radiance[1]=accum.g;
//bake_cells_write[p_idx].radiance[2]=accum.b;
-
} else {
- int half = cells_per_axis >> (p_level+1);
+ int half = cells_per_axis >> (p_level + 1);
//go down
- for(int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
uint32_t child = bake_cells_write[p_idx].childs[i];
- if (child==CHILD_EMPTY)
+ if (child == CHILD_EMPTY)
continue;
- int nx=p_x;
- int ny=p_y;
- int nz=p_z;
-
- if (i&1)
- nx+=half;
- if (i&2)
- ny+=half;
- if (i&4)
- nz+=half;
+ int nx = p_x;
+ int ny = p_y;
+ int nz = p_z;
+ if (i & 1)
+ nx += half;
+ if (i & 2)
+ ny += half;
+ if (i & 4)
+ nz += half;
- _bake_radiance(child,p_level+1,nx,ny,nz);
+ _bake_radiance(child, p_level + 1, nx, ny, nz);
}
}
}
void BakedLight::bake_radiance() {
- ERR_FAIL_COND(bake_cells.size()==0);
+ ERR_FAIL_COND(bake_cells.size() == 0);
bake_cells_write = bake_cells.write();
- _bake_radiance(0,0,0,0,0);
-
- bake_cells_write=PoolVector<BakeCell>::Write();
+ _bake_radiance(0, 0, 0, 0, 0);
+ bake_cells_write = PoolVector<BakeCell>::Write();
}
-int BakedLight::_find_cell(int x,int y, int z) {
-
+int BakedLight::_find_cell(int x, int y, int z) {
- uint32_t cell=0;
+ uint32_t cell = 0;
- int ofs_x=0;
- int ofs_y=0;
- int ofs_z=0;
+ int ofs_x = 0;
+ int ofs_y = 0;
+ int ofs_z = 0;
int size = cells_per_axis;
- int half=size/2;
+ int half = size / 2;
- if (x<0 || x>=size)
+ if (x < 0 || x >= size)
return -1;
- if (y<0 || y>=size)
+ if (y < 0 || y >= size)
return -1;
- if (z<0 || z>=size)
+ if (z < 0 || z >= size)
return -1;
- for(int i=0;i<cell_subdiv-1;i++) {
+ for (int i = 0; i < cell_subdiv - 1; i++) {
BakeCell *bc = &bake_cells_write[cell];
int child = 0;
if (x >= ofs_x + half) {
- child|=1;
- ofs_x+=half;
+ child |= 1;
+ ofs_x += half;
}
if (y >= ofs_y + half) {
- child|=2;
- ofs_y+=half;
+ child |= 2;
+ ofs_y += half;
}
if (z >= ofs_z + half) {
- child|=4;
- ofs_z+=half;
+ child |= 4;
+ ofs_z += half;
}
cell = bc->childs[child];
- if (cell==CHILD_EMPTY)
+ if (cell == CHILD_EMPTY)
return -1;
- half>>=1;
+ half >>= 1;
}
return cell;
-
}
-
-int BakedLight::_plot_ray(const Vector3& p_from, const Vector3& p_to) {
+int BakedLight::_plot_ray(const Vector3 &p_from, const Vector3 &p_to) {
Vector3 from = (p_from - bounds.pos) / bounds.size;
Vector3 to = (p_to - bounds.pos) / bounds.size;
- int x1 = Math::floor(from.x*cells_per_axis);
- int y1 = Math::floor(from.y*cells_per_axis);
- int z1 = Math::floor(from.z*cells_per_axis);
-
- int x2 = Math::floor(to.x*cells_per_axis);
- int y2 = Math::floor(to.y*cells_per_axis);
- int z2 = Math::floor(to.z*cells_per_axis);
+ int x1 = Math::floor(from.x * cells_per_axis);
+ int y1 = Math::floor(from.y * cells_per_axis);
+ int z1 = Math::floor(from.z * cells_per_axis);
+ int x2 = Math::floor(to.x * cells_per_axis);
+ int y2 = Math::floor(to.y * cells_per_axis);
+ int z2 = Math::floor(to.z * cells_per_axis);
int i, dx, dy, dz, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2;
int point[3];
@@ -1459,8 +1397,8 @@ int BakedLight::_plot_ray(const Vector3& p_from, const Vector3& p_to) {
err_1 = dy2 - l;
err_2 = dz2 - l;
for (i = 0; i < l; i++) {
- int cell = _find_cell(point[0],point[1],point[2]);
- if (cell>=0)
+ int cell = _find_cell(point[0], point[1], point[2]);
+ if (cell >= 0)
return cell;
if (err_1 > 0) {
@@ -1479,8 +1417,8 @@ int BakedLight::_plot_ray(const Vector3& p_from, const Vector3& p_to) {
err_1 = dx2 - m;
err_2 = dz2 - m;
for (i = 0; i < m; i++) {
- int cell = _find_cell(point[0],point[1],point[2]);
- if (cell>=0)
+ int cell = _find_cell(point[0], point[1], point[2]);
+ if (cell >= 0)
return cell;
if (err_1 > 0) {
point[0] += x_inc;
@@ -1498,8 +1436,8 @@ int BakedLight::_plot_ray(const Vector3& p_from, const Vector3& p_to) {
err_1 = dy2 - n;
err_2 = dx2 - n;
for (i = 0; i < n; i++) {
- int cell = _find_cell(point[0],point[1],point[2]);
- if (cell>=0)
+ int cell = _find_cell(point[0], point[1], point[2]);
+ if (cell >= 0)
return cell;
if (err_1 > 0) {
@@ -1515,14 +1453,12 @@ int BakedLight::_plot_ray(const Vector3& p_from, const Vector3& p_to) {
point[2] += z_inc;
}
}
- return _find_cell(point[0],point[1],point[2]);
-
+ return _find_cell(point[0], point[1], point[2]);
}
-
void BakedLight::set_cell_subdiv(int p_subdiv) {
- cell_subdiv=p_subdiv;
+ cell_subdiv = p_subdiv;
//VS::get_singleton()->baked_light_set_subdivision(baked_light,p_subdiv);
}
@@ -1532,77 +1468,67 @@ int BakedLight::get_cell_subdiv() const {
return cell_subdiv;
}
-
-
Rect3 BakedLight::get_aabb() const {
- return Rect3(Vector3(0,0,0),Vector3(1,1,1));
+ return Rect3(Vector3(0, 0, 0), Vector3(1, 1, 1));
}
PoolVector<Face3> BakedLight::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
}
-
String BakedLight::get_configuration_warning() const {
return String();
}
+void BakedLight::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, DebugMode p_mode, Ref<MultiMesh> &p_multimesh, int &idx) {
-void BakedLight::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb,DebugMode p_mode,Ref<MultiMesh> &p_multimesh,int &idx) {
+ if (p_level == cell_subdiv - 1) {
-
- if (p_level==cell_subdiv-1) {
-
- Vector3 center = p_aabb.pos+p_aabb.size*0.5;
+ Vector3 center = p_aabb.pos + p_aabb.size * 0.5;
Transform xform;
- xform.origin=center;
- xform.basis.scale(p_aabb.size*0.5);
- p_multimesh->set_instance_transform(idx,xform);
+ xform.origin = center;
+ xform.basis.scale(p_aabb.size * 0.5);
+ p_multimesh->set_instance_transform(idx, xform);
Color col;
- switch(p_mode) {
+ switch (p_mode) {
case DEBUG_ALBEDO: {
- col=Color(bake_cells_write[p_idx].albedo[0],bake_cells_write[p_idx].albedo[1],bake_cells_write[p_idx].albedo[2]);
+ col = Color(bake_cells_write[p_idx].albedo[0], bake_cells_write[p_idx].albedo[1], bake_cells_write[p_idx].albedo[2]);
} break;
case DEBUG_LIGHT: {
- col=Color(bake_cells_write[p_idx].light[0],bake_cells_write[p_idx].light[1],bake_cells_write[p_idx].light[2]);
- Color colr=Color(bake_cells_write[p_idx].radiance[0],bake_cells_write[p_idx].radiance[1],bake_cells_write[p_idx].radiance[2]);
- col.r+=colr.r;
- col.g+=colr.g;
- col.b+=colr.b;
+ col = Color(bake_cells_write[p_idx].light[0], bake_cells_write[p_idx].light[1], bake_cells_write[p_idx].light[2]);
+ Color colr = Color(bake_cells_write[p_idx].radiance[0], bake_cells_write[p_idx].radiance[1], bake_cells_write[p_idx].radiance[2]);
+ col.r += colr.r;
+ col.g += colr.g;
+ col.b += colr.b;
} break;
-
}
- p_multimesh->set_instance_color(idx,col);
-
+ p_multimesh->set_instance_color(idx, col);
idx++;
} else {
- for(int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
- if (bake_cells_write[p_idx].childs[i]==CHILD_EMPTY)
+ if (bake_cells_write[p_idx].childs[i] == CHILD_EMPTY)
continue;
- Rect3 aabb=p_aabb;
- aabb.size*=0.5;
+ Rect3 aabb = p_aabb;
+ aabb.size *= 0.5;
- if (i&1)
- aabb.pos.x+=aabb.size.x;
- if (i&2)
- aabb.pos.y+=aabb.size.y;
- if (i&4)
- aabb.pos.z+=aabb.size.z;
+ if (i & 1)
+ aabb.pos.x += aabb.size.x;
+ if (i & 2)
+ aabb.pos.y += aabb.size.y;
+ if (i & 4)
+ aabb.pos.z += aabb.size.z;
- _debug_mesh(bake_cells_write[p_idx].childs[i],p_level+1,aabb,p_mode,p_multimesh,idx);
+ _debug_mesh(bake_cells_write[p_idx].childs[i], p_level + 1, aabb, p_mode, p_multimesh, idx);
}
-
}
-
}
-
void BakedLight::create_debug_mesh(DebugMode p_mode) {
Ref<MultiMesh> mm;
@@ -1610,13 +1536,11 @@ void BakedLight::create_debug_mesh(DebugMode p_mode) {
mm->set_transform_format(MultiMesh::TRANSFORM_3D);
mm->set_color_format(MultiMesh::COLOR_8BIT);
- mm->set_instance_count(bake_cells_level_used[cell_subdiv-1]);
+ mm->set_instance_count(bake_cells_level_used[cell_subdiv - 1]);
Ref<Mesh> mesh;
mesh.instance();
-
-
{
Array arr;
arr.resize(Mesh::ARRAY_MAX);
@@ -1624,83 +1548,76 @@ void BakedLight::create_debug_mesh(DebugMode p_mode) {
PoolVector<Vector3> vertices;
PoolVector<Color> colors;
- int vtx_idx=0;
- #define ADD_VTX(m_idx);\
- vertices.push_back( face_points[m_idx] );\
- colors.push_back( Color(1,1,1,1) );\
- vtx_idx++;\
-
- for (int i=0;i<6;i++) {
+ int vtx_idx = 0;
+#define ADD_VTX(m_idx) \
+ ; \
+ vertices.push_back(face_points[m_idx]); \
+ colors.push_back(Color(1, 1, 1, 1)); \
+ vtx_idx++;
+ for (int i = 0; i < 6; i++) {
Vector3 face_points[4];
- for (int j=0;j<4;j++) {
+ for (int j = 0; j < 4; j++) {
float v[3];
- v[0]=1.0;
- v[1]=1-2*((j>>1)&1);
- v[2]=v[1]*(1-2*(j&1));
+ v[0] = 1.0;
+ v[1] = 1 - 2 * ((j >> 1) & 1);
+ v[2] = v[1] * (1 - 2 * (j & 1));
- for (int k=0;k<3;k++) {
+ for (int k = 0; k < 3; k++) {
- if (i<3)
- face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
+ if (i < 3)
+ face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
else
- face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
+ face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
}
}
- //tri 1
+ //tri 1
ADD_VTX(0);
ADD_VTX(1);
ADD_VTX(2);
- //tri 2
+ //tri 2
ADD_VTX(2);
ADD_VTX(3);
ADD_VTX(0);
-
}
-
- arr[Mesh::ARRAY_VERTEX]=vertices;
- arr[Mesh::ARRAY_COLOR]=colors;
- mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES,arr);
+ arr[Mesh::ARRAY_VERTEX] = vertices;
+ arr[Mesh::ARRAY_COLOR] = colors;
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr);
}
{
Ref<FixedSpatialMaterial> fsm;
fsm.instance();
- fsm->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true);
- fsm->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true);
- fsm->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true);
- fsm->set_albedo(Color(1,1,1,1));
+ fsm->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ fsm->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ fsm->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true);
+ fsm->set_albedo(Color(1, 1, 1, 1));
- mesh->surface_set_material(0,fsm);
+ mesh->surface_set_material(0, fsm);
}
mm->set_mesh(mesh);
-
bake_cells_write = bake_cells.write();
+ int idx = 0;
+ _debug_mesh(0, 0, bounds, p_mode, mm, idx);
+ print_line("written: " + itos(idx) + " total: " + itos(bake_cells_level_used[cell_subdiv - 1]));
- int idx=0;
- _debug_mesh(0,0,bounds,p_mode,mm,idx);
-
- print_line("written: "+itos(idx)+" total: "+itos(bake_cells_level_used[cell_subdiv-1]));
-
-
- MultiMeshInstance *mmi = memnew( MultiMeshInstance );
+ MultiMeshInstance *mmi = memnew(MultiMeshInstance);
mmi->set_multimesh(mm);
add_child(mmi);
#ifdef TOOLS_ENABLED
- if (get_tree()->get_edited_scene_root()==this){
+ if (get_tree()->get_edited_scene_root() == this) {
mmi->set_owner(this);
} else {
mmi->set_owner(get_owner());
-
}
#else
mmi->set_owner(get_owner());
@@ -1715,45 +1632,41 @@ void BakedLight::_debug_mesh_light() {
create_debug_mesh(DEBUG_LIGHT);
}
-
void BakedLight::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_cell_subdiv","steps"),&BakedLight::set_cell_subdiv);
- ClassDB::bind_method(D_METHOD("get_cell_subdiv"),&BakedLight::get_cell_subdiv);
-
- ClassDB::bind_method(D_METHOD("bake"),&BakedLight::bake);
- ClassDB::set_method_flags(get_class_static(),_scs_create("bake"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("set_cell_subdiv", "steps"), &BakedLight::set_cell_subdiv);
+ ClassDB::bind_method(D_METHOD("get_cell_subdiv"), &BakedLight::get_cell_subdiv);
- ClassDB::bind_method(D_METHOD("bake_lights"),&BakedLight::bake_lights);
- ClassDB::set_method_flags(get_class_static(),_scs_create("bake_lights"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("bake"), &BakedLight::bake);
+ ClassDB::set_method_flags(get_class_static(), _scs_create("bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
- ClassDB::bind_method(D_METHOD("bake_radiance"),&BakedLight::bake_radiance);
- ClassDB::set_method_flags(get_class_static(),_scs_create("bake_radiance"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("bake_lights"), &BakedLight::bake_lights);
+ ClassDB::set_method_flags(get_class_static(), _scs_create("bake_lights"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
- ClassDB::bind_method(D_METHOD("debug_mesh_albedo"),&BakedLight::_debug_mesh_albedo);
- ClassDB::set_method_flags(get_class_static(),_scs_create("debug_mesh_albedo"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("bake_radiance"), &BakedLight::bake_radiance);
+ ClassDB::set_method_flags(get_class_static(), _scs_create("bake_radiance"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("debug_mesh_albedo"), &BakedLight::_debug_mesh_albedo);
+ ClassDB::set_method_flags(get_class_static(), _scs_create("debug_mesh_albedo"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
- ClassDB::bind_method(D_METHOD("debug_mesh_light"),&BakedLight::_debug_mesh_light);
- ClassDB::set_method_flags(get_class_static(),_scs_create("debug_mesh_light"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
-
- ADD_PROPERTY(PropertyInfo(Variant::INT,"cell_subdiv"),"set_cell_subdiv","get_cell_subdiv");
- ADD_SIGNAL( MethodInfo("baked_light_changed"));
+ ClassDB::bind_method(D_METHOD("debug_mesh_light"), &BakedLight::_debug_mesh_light);
+ ClassDB::set_method_flags(get_class_static(), _scs_create("debug_mesh_light"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_subdiv"), "set_cell_subdiv", "get_cell_subdiv");
+ ADD_SIGNAL(MethodInfo("baked_light_changed"));
}
BakedLight::BakedLight() {
//baked_light=VisualServer::get_singleton()->baked_light_create();
- VS::get_singleton()->instance_set_base(get_instance(),baked_light);
+ VS::get_singleton()->instance_set_base(get_instance(), baked_light);
- cell_subdiv=8;
- bake_texture_size=128;
- color_scan_cell_width=8;
- light_pass=0;
+ cell_subdiv = 8;
+ bake_texture_size = 128;
+ color_scan_cell_width = 8;
+ light_pass = 0;
}
-
BakedLight::~BakedLight() {
VS::get_singleton()->free(baked_light);
diff --git a/scene/3d/baked_light_instance.h b/scene/3d/baked_light_instance.h
index 2fda26ecea..2180f8b175 100644
--- a/scene/3d/baked_light_instance.h
+++ b/scene/3d/baked_light_instance.h
@@ -29,16 +29,15 @@
#ifndef BAKED_LIGHT_INSTANCE_H
#define BAKED_LIGHT_INSTANCE_H
+#include "scene/3d/multimesh_instance.h"
#include "scene/3d/visual_instance.h"
#include "scene/resources/baked_light.h"
-#include "scene/3d/multimesh_instance.h"
-
class BakedLightBaker;
class Light;
class BakedLight : public VisualInstance {
- GDCLASS(BakedLight,VisualInstance);
+ GDCLASS(BakedLight, VisualInstance);
public:
enum DebugMode {
@@ -53,10 +52,9 @@ private:
int cells_per_axis;
enum {
- CHILD_EMPTY=0xFFFFFFFF,
+ CHILD_EMPTY = 0xFFFFFFFF,
};
-
/* BAKE DATA */
struct BakeCell {
@@ -70,22 +68,21 @@ private:
uint32_t light_pass; //used for baking light
BakeCell() {
- for(int i=0;i<8;i++) {
- childs[i]=0xFFFFFFFF;
+ for (int i = 0; i < 8; i++) {
+ childs[i] = 0xFFFFFFFF;
}
- for(int i=0;i<3;i++) {
- light[i]=0;
- albedo[i]=0;
- radiance[i]=0;
+ for (int i = 0; i < 3; i++) {
+ light[i] = 0;
+ albedo[i] = 0;
+ radiance[i] = 0;
}
- alpha=0;
- light_pass=0;
- used_sides=0;
+ alpha = 0;
+ light_pass = 0;
+ used_sides = 0;
}
};
-
int bake_texture_size;
int color_scan_cell_width;
@@ -95,12 +92,9 @@ private:
Vector<Color> emission;
};
-
Vector<Color> _get_bake_texture(Image &p_image, const Color &p_color);
-
-
- Map<Ref<Material>,MaterialCache> material_cache;
+ Map<Ref<Material>, MaterialCache> material_cache;
MaterialCache _get_material_cache(Ref<Material> p_material);
int bake_cells_alloc;
@@ -110,42 +104,38 @@ private:
PoolVector<BakeCell> bake_cells;
PoolVector<BakeCell>::Write bake_cells_write;
-
-
- void _plot_face(int p_idx,int p_level,const Vector3 *p_vtx,const Vector2* p_uv, const MaterialCache& p_material,const Rect3& p_aabb);
+ void _plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const Vector2 *p_uv, const MaterialCache &p_material, const Rect3 &p_aabb);
void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z);
- void _bake_add_mesh(const Transform& p_xform,Ref<Mesh>& p_mesh);
- void _bake_add_to_aabb(const Transform& p_xform,Ref<Mesh>& p_mesh,bool &first);
+ void _bake_add_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh);
+ void _bake_add_to_aabb(const Transform &p_xform, Ref<Mesh> &p_mesh, bool &first);
- void _debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb,DebugMode p_mode,Ref<MultiMesh> &p_multimesh,int &idx);
+ void _debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, DebugMode p_mode, Ref<MultiMesh> &p_multimesh, int &idx);
void _debug_mesh_albedo();
void _debug_mesh_light();
-
- _FORCE_INLINE_ int _find_cell(int x,int y, int z);
- int _plot_ray(const Vector3& p_from, const Vector3& p_to);
+ _FORCE_INLINE_ int _find_cell(int x, int y, int z);
+ int _plot_ray(const Vector3 &p_from, const Vector3 &p_to);
uint32_t light_pass;
+ void _bake_directional(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 &p_dir, const Color &p_color, int p_sign);
+ void _upscale_light(int p_idx, int p_level);
+ void _bake_light(Light *p_light);
- void _bake_directional(int p_idx, int p_level, int p_x,int p_y,int p_z,const Vector3& p_dir,const Color& p_color,int p_sign);
- void _upscale_light(int p_idx,int p_level);
- void _bake_light(Light* p_light);
+ Color _cone_trace(const Vector3 &p_from, const Vector3 &p_dir, float p_half_angle);
+ void _bake_radiance(int p_idx, int p_level, int p_x, int p_y, int p_z);
- Color _cone_trace(const Vector3& p_from, const Vector3& p_dir, float p_half_angle);
- void _bake_radiance(int p_idx, int p_level, int p_x,int p_y,int p_z);
+ friend class GeometryInstance;
-friend class GeometryInstance;
+ Set<GeometryInstance *> geometries;
+ friend class Light;
- Set<GeometryInstance*> geometries;
-friend class Light;
+ Set<Light *> lights;
- Set<Light*> lights;
protected:
-
static void _bind_methods();
-public:
+public:
void set_cell_subdiv(int p_subdiv);
int get_cell_subdiv() const;
@@ -153,7 +143,6 @@ public:
void bake_lights();
void bake_radiance();
-
void create_debug_mesh(DebugMode p_mode);
virtual Rect3 get_aabb() const;
@@ -165,7 +154,6 @@ public:
~BakedLight();
};
-
#if 0
class BakedLightSampler : public VisualInstance {
GDCLASS(BakedLightSampler,VisualInstance);
diff --git a/scene/3d/body_shape.cpp b/scene/3d/body_shape.cpp
index af3fe3c0a4..8403806570 100644
--- a/scene/3d/body_shape.cpp
+++ b/scene/3d/body_shape.cpp
@@ -27,14 +27,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "body_shape.h"
-#include "servers/visual_server.h"
-#include "scene/resources/sphere_shape.h"
-#include "scene/resources/ray_shape.h"
#include "scene/resources/box_shape.h"
#include "scene/resources/capsule_shape.h"
-#include "scene/resources/convex_polygon_shape.h"
#include "scene/resources/concave_polygon_shape.h"
+#include "scene/resources/convex_polygon_shape.h"
#include "scene/resources/plane_shape.h"
+#include "scene/resources/ray_shape.h"
+#include "scene/resources/sphere_shape.h"
+#include "servers/visual_server.h"
//TODO: Implement CylinderShape and HeightMapShape?
#include "mesh_instance.h"
#include "physics_body.h"
@@ -48,7 +48,6 @@ void CollisionShape::_update_body() {
return;
if (get_parent() && get_parent()->cast_to<CollisionObject>())
get_parent()->cast_to<CollisionObject>()->_update_shapes_from_children();
-
}
void CollisionShape::make_convex_from_brothers() {
@@ -57,12 +56,12 @@ void CollisionShape::make_convex_from_brothers() {
if (!p)
return;
- for(int i=0;i<p->get_child_count();i++) {
+ for (int i = 0; i < p->get_child_count(); i++) {
Node *n = p->get_child(i);
if (n->cast_to<MeshInstance>()) {
- MeshInstance *mi=n->cast_to<MeshInstance>();
+ MeshInstance *mi = n->cast_to<MeshInstance>();
Ref<Mesh> m = mi->get_mesh();
if (m.is_valid()) {
@@ -71,7 +70,6 @@ void CollisionShape::make_convex_from_brothers() {
}
}
}
-
}
/*
@@ -302,32 +300,32 @@ void CollisionShape::_update_indicator() {
}
*/
-void CollisionShape::_add_to_collision_object(Object* p_cshape) {
+void CollisionShape::_add_to_collision_object(Object *p_cshape) {
if (unparenting)
return;
- CollisionObject *co=p_cshape->cast_to<CollisionObject>();
+ CollisionObject *co = p_cshape->cast_to<CollisionObject>();
ERR_FAIL_COND(!co);
if (shape.is_valid()) {
- update_shape_index=co->get_shape_count();
- co->add_shape(shape,get_transform());
+ update_shape_index = co->get_shape_count();
+ co->add_shape(shape, get_transform());
if (trigger)
- co->set_shape_as_trigger( co->get_shape_count() -1, true );
+ co->set_shape_as_trigger(co->get_shape_count() - 1, true);
} else {
- update_shape_index=-1;
+ update_shape_index = -1;
}
}
void CollisionShape::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- unparenting=false;
- can_update_body=get_tree()->is_editor_hint();
+ unparenting = false;
+ can_update_body = get_tree()->is_editor_hint();
set_notify_local_transform(!can_update_body);
if (get_tree()->is_debugging_collisions_hint()) {
@@ -343,19 +341,19 @@ void CollisionShape::_notification(int p_what) {
}
} break;
case NOTIFICATION_EXIT_TREE: {
- /* if (indicator_instance.is_valid()) {
+ /* if (indicator_instance.is_valid()) {
VisualServer::get_singleton()->free(indicator_instance);
indicator_instance=RID();
}*/
- can_update_body=false;
+ can_update_body = false;
set_notify_local_transform(false);
if (debug_shape) {
debug_shape->queue_delete();
- debug_shape=NULL;
+ debug_shape = NULL;
}
} break;
case NOTIFICATION_UNPARENTED: {
- unparenting=true;
+ unparenting = true;
if (can_update_body && updating_body)
_update_body();
} break;
@@ -365,34 +363,29 @@ void CollisionShape::_notification(int p_what) {
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
- if (!can_update_body && update_shape_index>=0) {
+ if (!can_update_body && update_shape_index >= 0) {
CollisionObject *co = get_parent()->cast_to<CollisionObject>();
if (co) {
- co->set_shape_transform(update_shape_index,get_transform());
+ co->set_shape_transform(update_shape_index, get_transform());
}
}
} break;
-
}
}
-
void CollisionShape::resource_changed(RES res) {
update_gizmo();
-
-
}
void CollisionShape::_set_update_shape_index(int p_index) {
-
- update_shape_index=p_index;
+ update_shape_index = p_index;
}
-int CollisionShape::_get_update_shape_index() const{
+int CollisionShape::_get_update_shape_index() const {
return update_shape_index;
}
@@ -410,45 +403,42 @@ String CollisionShape::get_configuration_warning() const {
return String();
}
-
void CollisionShape::_bind_methods() {
//not sure if this should do anything
- ClassDB::bind_method(D_METHOD("resource_changed","resource"),&CollisionShape::resource_changed);
- ClassDB::bind_method(D_METHOD("set_shape","shape"),&CollisionShape::set_shape);
- ClassDB::bind_method(D_METHOD("get_shape"),&CollisionShape::get_shape);
- ClassDB::bind_method(D_METHOD("_add_to_collision_object"),&CollisionShape::_add_to_collision_object);
- ClassDB::bind_method(D_METHOD("set_trigger","enable"),&CollisionShape::set_trigger);
- ClassDB::bind_method(D_METHOD("is_trigger"),&CollisionShape::is_trigger);
- ClassDB::bind_method(D_METHOD("make_convex_from_brothers"),&CollisionShape::make_convex_from_brothers);
- ClassDB::set_method_flags("CollisionShape","make_convex_from_brothers",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
- ClassDB::bind_method(D_METHOD("_set_update_shape_index","index"),&CollisionShape::_set_update_shape_index);
- ClassDB::bind_method(D_METHOD("_get_update_shape_index"),&CollisionShape::_get_update_shape_index);
+ ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &CollisionShape::resource_changed);
+ ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape::set_shape);
+ ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape::get_shape);
+ ClassDB::bind_method(D_METHOD("_add_to_collision_object"), &CollisionShape::_add_to_collision_object);
+ ClassDB::bind_method(D_METHOD("set_trigger", "enable"), &CollisionShape::set_trigger);
+ ClassDB::bind_method(D_METHOD("is_trigger"), &CollisionShape::is_trigger);
+ ClassDB::bind_method(D_METHOD("make_convex_from_brothers"), &CollisionShape::make_convex_from_brothers);
+ ClassDB::set_method_flags("CollisionShape", "make_convex_from_brothers", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("_set_update_shape_index", "index"), &CollisionShape::_set_update_shape_index);
+ ClassDB::bind_method(D_METHOD("_get_update_shape_index"), &CollisionShape::_get_update_shape_index);
- ClassDB::bind_method(D_METHOD("get_collision_object_shape_index"),&CollisionShape::get_collision_object_shape_index);
+ ClassDB::bind_method(D_METHOD("get_collision_object_shape_index"), &CollisionShape::get_collision_object_shape_index);
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"trigger"),"set_trigger","is_trigger");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "_update_shape_index", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_NOEDITOR), "_set_update_shape_index", "_get_update_shape_index");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "trigger"), "set_trigger", "is_trigger");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "_update_shape_index", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_update_shape_index", "_get_update_shape_index");
}
-
void CollisionShape::set_shape(const Ref<Shape> &p_shape) {
if (!shape.is_null())
shape->unregister_owner(this);
- shape=p_shape;
+ shape = p_shape;
if (!shape.is_null())
shape->register_owner(this);
update_gizmo();
if (updating_body) {
_update_body();
- } else if (can_update_body && update_shape_index>=0 && is_inside_tree()){
+ } else if (can_update_body && update_shape_index >= 0 && is_inside_tree()) {
CollisionObject *co = get_parent()->cast_to<CollisionObject>();
if (co) {
- co->set_shape(update_shape_index,p_shape);
+ co->set_shape(update_shape_index, p_shape);
}
-
}
}
@@ -457,9 +447,8 @@ Ref<Shape> CollisionShape::get_shape() const {
return shape;
}
-
void CollisionShape::set_updating_body(bool p_update) {
- updating_body=p_update;
+ updating_body = p_update;
}
bool CollisionShape::is_updating_body() const {
@@ -469,31 +458,31 @@ bool CollisionShape::is_updating_body() const {
void CollisionShape::set_trigger(bool p_trigger) {
- trigger=p_trigger;
- if (updating_body) {
- _update_body();
- } else if (can_update_body && update_shape_index>=0 && is_inside_tree()){
- CollisionObject *co = get_parent()->cast_to<CollisionObject>();
- if (co) {
- co->set_shape_as_trigger(update_shape_index,p_trigger);
- }
- }
+ trigger = p_trigger;
+ if (updating_body) {
+ _update_body();
+ } else if (can_update_body && update_shape_index >= 0 && is_inside_tree()) {
+ CollisionObject *co = get_parent()->cast_to<CollisionObject>();
+ if (co) {
+ co->set_shape_as_trigger(update_shape_index, p_trigger);
+ }
+ }
}
-bool CollisionShape::is_trigger() const{
+bool CollisionShape::is_trigger() const {
- return trigger;
+ return trigger;
}
CollisionShape::CollisionShape() {
//indicator = VisualServer::get_singleton()->mesh_create();
- updating_body=true;
- unparenting=false;
- update_shape_index=-1;
- trigger=false;
- can_update_body=false;
- debug_shape=NULL;
+ updating_body = true;
+ unparenting = false;
+ update_shape_index = -1;
+ trigger = false;
+ can_update_body = false;
+ debug_shape = NULL;
}
CollisionShape::~CollisionShape() {
@@ -504,10 +493,9 @@ CollisionShape::~CollisionShape() {
void CollisionShape::_create_debug_shape() {
-
if (debug_shape) {
debug_shape->queue_delete();
- debug_shape=NULL;
+ debug_shape = NULL;
}
Ref<Shape> s = get_shape();
@@ -515,37 +503,35 @@ void CollisionShape::_create_debug_shape() {
if (s.is_null())
return;
-
Ref<Mesh> mesh = s->get_debug_mesh();
- MeshInstance *mi = memnew( MeshInstance );
+ MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(mesh);
add_child(mi);
- debug_shape=mi;
-
+ debug_shape = mi;
}
#if 0
#include "body_volume.h"
-#include "scene/3d/physics_body.h"
#include "geometry.h"
+#include "scene/3d/physics_body.h"
-#define ADD_TRIANGLE( m_a, m_b, m_c, m_color)\
-{\
- Vector<Vector3> points;\
- points.resize(3);\
- points[0]=m_a;\
- points[1]=m_b;\
- points[2]=m_c;\
- Vector<Color> colors;\
- colors.resize(3);\
- colors[0]=m_color;\
- colors[1]=m_color;\
- colors[2]=m_color;\
- vs->poly_add_primitive(p_indicator,points,Vector<Vector3>(),colors,Vector<Vector3>());\
-}
+#define ADD_TRIANGLE(m_a, m_b, m_c, m_color) \
+ { \
+ Vector<Vector3> points; \
+ points.resize(3); \
+ points[0] = m_a; \
+ points[1] = m_b; \
+ points[2] = m_c; \
+ Vector<Color> colors; \
+ colors.resize(3); \
+ colors[0] = m_color; \
+ colors[1] = m_color; \
+ colors[2] = m_color; \
+ vs->poly_add_primitive(p_indicator, points, Vector<Vector3>(), colors, Vector<Vector3>()); \
+ }
void CollisionShape::_notification(int p_what) {
diff --git a/scene/3d/body_shape.h b/scene/3d/body_shape.h
index a7c3678251..137a6cd9fc 100644
--- a/scene/3d/body_shape.h
+++ b/scene/3d/body_shape.h
@@ -34,7 +34,7 @@
class CollisionShape : public Spatial {
- GDCLASS( CollisionShape, Spatial );
+ GDCLASS(CollisionShape, Spatial);
OBJ_CATEGORY("3D Physics Nodes");
Ref<Shape> shape;
@@ -50,7 +50,7 @@ class CollisionShape : public Spatial {
RID indicator_instance;
*/
- Node* debug_shape;
+ Node *debug_shape;
void resource_changed(RES res);
@@ -63,7 +63,7 @@ class CollisionShape : public Spatial {
int update_shape_index;
void _update_body();
- void _add_to_collision_object(Object* p_cshape);
+ void _add_to_collision_object(Object *p_cshape);
void _set_update_shape_index(int p_index);
int _get_update_shape_index() const;
@@ -71,12 +71,10 @@ class CollisionShape : public Spatial {
void _create_debug_shape();
protected:
-
void _notification(int p_what);
static void _bind_methods();
public:
-
void make_convex_from_brothers();
void set_shape(const Ref<Shape> &p_shape);
@@ -90,7 +88,6 @@ public:
int get_collision_object_shape_index() const { return _get_update_shape_index(); }
-
String get_configuration_warning() const;
CollisionShape();
@@ -98,4 +95,3 @@ public:
};
#endif // BODY_VOLUME_H
-
diff --git a/scene/3d/bone_attachment.cpp b/scene/3d/bone_attachment.cpp
index 1a2680e3b8..d8cb2dfdac 100644
--- a/scene/3d/bone_attachment.cpp
+++ b/scene/3d/bone_attachment.cpp
@@ -28,19 +28,19 @@
/*************************************************************************/
#include "bone_attachment.h"
-bool BoneAttachment::_get(const StringName& p_name,Variant &r_ret) const {
+bool BoneAttachment::_get(const StringName &p_name, Variant &r_ret) const {
- if (String(p_name)=="bone_name") {
+ if (String(p_name) == "bone_name") {
- r_ret=get_bone_name();
+ r_ret = get_bone_name();
return true;
}
return false;
}
-bool BoneAttachment::_set(const StringName& p_name, const Variant& p_value){
+bool BoneAttachment::_set(const StringName &p_name, const Variant &p_value) {
- if (String(p_name)=="bone_name") {
+ if (String(p_name) == "bone_name") {
set_bone_name(p_value);
return true;
@@ -48,40 +48,37 @@ bool BoneAttachment::_set(const StringName& p_name, const Variant& p_value){
return false;
}
-void BoneAttachment::_get_property_list( List<PropertyInfo>* p_list ) const{
+void BoneAttachment::_get_property_list(List<PropertyInfo> *p_list) const {
- Skeleton *parent=NULL;
- if(get_parent())
- parent=get_parent()->cast_to<Skeleton>();
+ Skeleton *parent = NULL;
+ if (get_parent())
+ parent = get_parent()->cast_to<Skeleton>();
if (parent) {
String names;
- for(int i=0;i<parent->get_bone_count();i++) {
- if(i>0)
- names+=",";
- names+=parent->get_bone_name(i);
+ for (int i = 0; i < parent->get_bone_count(); i++) {
+ if (i > 0)
+ names += ",";
+ names += parent->get_bone_name(i);
}
- p_list->push_back(PropertyInfo(Variant::STRING,"bone_name",PROPERTY_HINT_ENUM,names));
+ p_list->push_back(PropertyInfo(Variant::STRING, "bone_name", PROPERTY_HINT_ENUM, names));
} else {
- p_list->push_back(PropertyInfo(Variant::STRING,"bone_name"));
-
+ p_list->push_back(PropertyInfo(Variant::STRING, "bone_name"));
}
-
}
-
void BoneAttachment::_check_bind() {
if (get_parent() && get_parent()->cast_to<Skeleton>()) {
Skeleton *sk = get_parent()->cast_to<Skeleton>();
int idx = sk->find_bone(bone_name);
- if (idx!=-1) {
- sk->bind_child_node_to_bone(idx,this);
+ if (idx != -1) {
+ sk->bind_child_node_to_bone(idx, this);
set_transform(sk->get_bone_global_pose(idx));
- bound=true;
+ bound = true;
}
}
}
@@ -93,33 +90,33 @@ void BoneAttachment::_check_unbind() {
if (get_parent() && get_parent()->cast_to<Skeleton>()) {
Skeleton *sk = get_parent()->cast_to<Skeleton>();
int idx = sk->find_bone(bone_name);
- if (idx!=-1) {
- sk->unbind_child_node_from_bone(idx,this);
+ if (idx != -1) {
+ sk->unbind_child_node_from_bone(idx, this);
}
}
- bound=false;
+ bound = false;
}
}
-void BoneAttachment::set_bone_name(const String& p_name) {
+void BoneAttachment::set_bone_name(const String &p_name) {
if (is_inside_tree())
_check_unbind();
- bone_name=p_name;
+ bone_name = p_name;
if (is_inside_tree())
_check_bind();
}
-String BoneAttachment::get_bone_name() const{
+String BoneAttachment::get_bone_name() const {
return bone_name;
}
void BoneAttachment::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -132,13 +129,11 @@ void BoneAttachment::_notification(int p_what) {
}
}
-BoneAttachment::BoneAttachment()
-{
- bound=false;
-
+BoneAttachment::BoneAttachment() {
+ bound = false;
}
-void BoneAttachment::_bind_methods(){
- ClassDB::bind_method(D_METHOD("set_bone_name","bone_name"),&BoneAttachment::set_bone_name);
- ClassDB::bind_method(D_METHOD("get_bone_name"),&BoneAttachment::get_bone_name);
+void BoneAttachment::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment::set_bone_name);
+ ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment::get_bone_name);
}
diff --git a/scene/3d/bone_attachment.h b/scene/3d/bone_attachment.h
index 9bcbb82865..194d6b4f94 100644
--- a/scene/3d/bone_attachment.h
+++ b/scene/3d/bone_attachment.h
@@ -33,25 +33,24 @@
class BoneAttachment : public Spatial {
- GDCLASS(BoneAttachment,Spatial);
+ GDCLASS(BoneAttachment, Spatial);
bool bound;
String bone_name;
void _check_bind();
void _check_unbind();
-protected:
- bool _get(const StringName& p_name,Variant &r_ret) const;
- bool _set(const StringName& p_name, const Variant& p_value);
- void _get_property_list( List<PropertyInfo>* p_list ) const;
+protected:
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
-
- void set_bone_name(const String& p_name);
+ void set_bone_name(const String &p_name);
String get_bone_name() const;
BoneAttachment();
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index 2e04f2d8bc..540edd8a2a 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -32,10 +32,7 @@
#include "scene/resources/material.h"
#include "scene/resources/surface_tool.h"
-
void Camera::_update_audio_listener_state() {
-
-
}
void Camera::_request_camera_update() {
@@ -45,60 +42,56 @@ void Camera::_request_camera_update() {
void Camera::_update_camera_mode() {
-
- force_change=true;
- switch(mode) {
+ force_change = true;
+ switch (mode) {
case PROJECTION_PERSPECTIVE: {
-
- set_perspective(fov,near,far);
+ set_perspective(fov, near, far);
} break;
case PROJECTION_ORTHOGONAL: {
- set_orthogonal(size,near,far);
+ set_orthogonal(size, near, far);
} break;
-
}
-
}
-bool Camera::_set(const StringName& p_name, const Variant& p_value) {
+bool Camera::_set(const StringName &p_name, const Variant &p_value) {
- bool changed_all=false;
- if (p_name=="projection") {
+ bool changed_all = false;
+ if (p_name == "projection") {
int proj = p_value;
- if (proj==PROJECTION_PERSPECTIVE)
- mode=PROJECTION_PERSPECTIVE;
- if (proj==PROJECTION_ORTHOGONAL)
- mode=PROJECTION_ORTHOGONAL;
-
- changed_all=true;
- } else if (p_name=="fov" || p_name=="fovy" || p_name=="fovx")
- fov=p_value;
- else if (p_name=="size" || p_name=="sizex" || p_name=="sizey")
- size=p_value;
- else if (p_name=="near")
- near=p_value;
- else if (p_name=="far")
- far=p_value;
- else if (p_name=="keep_aspect")
+ if (proj == PROJECTION_PERSPECTIVE)
+ mode = PROJECTION_PERSPECTIVE;
+ if (proj == PROJECTION_ORTHOGONAL)
+ mode = PROJECTION_ORTHOGONAL;
+
+ changed_all = true;
+ } else if (p_name == "fov" || p_name == "fovy" || p_name == "fovx")
+ fov = p_value;
+ else if (p_name == "size" || p_name == "sizex" || p_name == "sizey")
+ size = p_value;
+ else if (p_name == "near")
+ near = p_value;
+ else if (p_name == "far")
+ far = p_value;
+ else if (p_name == "keep_aspect")
set_keep_aspect_mode(KeepAspect(int(p_value)));
- else if (p_name=="vaspect")
- set_keep_aspect_mode(p_value?KEEP_WIDTH:KEEP_HEIGHT);
- else if (p_name=="h_offset")
- h_offset=p_value;
- else if (p_name=="v_offset")
- v_offset=p_value;
- else if (p_name=="current") {
+ else if (p_name == "vaspect")
+ set_keep_aspect_mode(p_value ? KEEP_WIDTH : KEEP_HEIGHT);
+ else if (p_name == "h_offset")
+ h_offset = p_value;
+ else if (p_name == "v_offset")
+ v_offset = p_value;
+ else if (p_name == "current") {
if (p_value.operator bool()) {
make_current();
} else {
clear_current();
}
- } else if (p_name=="cull_mask") {
+ } else if (p_name == "cull_mask") {
set_cull_mask(p_value);
- } else if (p_name=="environment") {
+ } else if (p_name == "environment") {
set_environment(p_value);
} else
return false;
@@ -107,88 +100,84 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) {
if (changed_all)
_change_notify();
return true;
-
}
-bool Camera::_get(const StringName& p_name,Variant &r_ret) const {
-
- if (p_name=="projection") {
- r_ret= mode;
- } else if (p_name=="fov" || p_name=="fovy" || p_name=="fovx")
- r_ret= fov;
- else if (p_name=="size" || p_name=="sizex" || p_name=="sizey")
- r_ret= size;
- else if (p_name=="near")
- r_ret= near;
- else if (p_name=="far")
- r_ret= far;
- else if (p_name=="keep_aspect")
- r_ret= int(keep_aspect);
- else if (p_name=="current") {
+bool Camera::_get(const StringName &p_name, Variant &r_ret) const {
+
+ if (p_name == "projection") {
+ r_ret = mode;
+ } else if (p_name == "fov" || p_name == "fovy" || p_name == "fovx")
+ r_ret = fov;
+ else if (p_name == "size" || p_name == "sizex" || p_name == "sizey")
+ r_ret = size;
+ else if (p_name == "near")
+ r_ret = near;
+ else if (p_name == "far")
+ r_ret = far;
+ else if (p_name == "keep_aspect")
+ r_ret = int(keep_aspect);
+ else if (p_name == "current") {
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
- r_ret=current;
+ r_ret = current;
} else {
- r_ret=is_current();
+ r_ret = is_current();
}
- } else if (p_name=="cull_mask") {
- r_ret=get_cull_mask();
- } else if (p_name=="h_offset") {
- r_ret=get_h_offset();
- } else if (p_name=="v_offset") {
- r_ret=get_v_offset();
- } else if (p_name=="environment") {
- r_ret=get_environment();
+ } else if (p_name == "cull_mask") {
+ r_ret = get_cull_mask();
+ } else if (p_name == "h_offset") {
+ r_ret = get_h_offset();
+ } else if (p_name == "v_offset") {
+ r_ret = get_v_offset();
+ } else if (p_name == "environment") {
+ r_ret = get_environment();
} else
return false;
return true;
}
-void Camera::_get_property_list( List<PropertyInfo> *p_list) const {
+void Camera::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo( Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal") );
+ p_list->push_back(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal"));
- switch(mode) {
+ switch (mode) {
case PROJECTION_PERSPECTIVE: {
- p_list->push_back( PropertyInfo( Variant::REAL, "fov" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_NOEDITOR) );
- if (keep_aspect==KEEP_WIDTH)
- p_list->push_back( PropertyInfo( Variant::REAL, "fovx" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_EDITOR) );
+ p_list->push_back(PropertyInfo(Variant::REAL, "fov", PROPERTY_HINT_RANGE, "1,179,0.1", PROPERTY_USAGE_NOEDITOR));
+ if (keep_aspect == KEEP_WIDTH)
+ p_list->push_back(PropertyInfo(Variant::REAL, "fovx", PROPERTY_HINT_RANGE, "1,179,0.1", PROPERTY_USAGE_EDITOR));
else
- p_list->push_back( PropertyInfo( Variant::REAL, "fovy" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_EDITOR) );
-
+ p_list->push_back(PropertyInfo(Variant::REAL, "fovy", PROPERTY_HINT_RANGE, "1,179,0.1", PROPERTY_USAGE_EDITOR));
} break;
case PROJECTION_ORTHOGONAL: {
- p_list->push_back( PropertyInfo( Variant::REAL, "size" , PROPERTY_HINT_RANGE, "1,16384,0.01",PROPERTY_USAGE_NOEDITOR ) );
- if (keep_aspect==KEEP_WIDTH)
- p_list->push_back( PropertyInfo( Variant::REAL, "sizex" , PROPERTY_HINT_RANGE, "0.1,16384,0.01",PROPERTY_USAGE_EDITOR) );
+ p_list->push_back(PropertyInfo(Variant::REAL, "size", PROPERTY_HINT_RANGE, "1,16384,0.01", PROPERTY_USAGE_NOEDITOR));
+ if (keep_aspect == KEEP_WIDTH)
+ p_list->push_back(PropertyInfo(Variant::REAL, "sizex", PROPERTY_HINT_RANGE, "0.1,16384,0.01", PROPERTY_USAGE_EDITOR));
else
- p_list->push_back( PropertyInfo( Variant::REAL, "sizey" , PROPERTY_HINT_RANGE, "0.1,16384,0.01",PROPERTY_USAGE_EDITOR) );
+ p_list->push_back(PropertyInfo(Variant::REAL, "sizey", PROPERTY_HINT_RANGE, "0.1,16384,0.01", PROPERTY_USAGE_EDITOR));
} break;
-
}
- p_list->push_back( PropertyInfo( Variant::REAL, "near" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") );
- p_list->push_back( PropertyInfo( Variant::REAL, "far" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") );
- p_list->push_back( PropertyInfo( Variant::INT, "keep_aspect",PROPERTY_HINT_ENUM,"Keep Width,Keep Height") );
- p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) );
- p_list->push_back( PropertyInfo( Variant::INT, "cull_mask",PROPERTY_HINT_LAYERS_3D_RENDER ) );
- p_list->push_back( PropertyInfo( Variant::OBJECT, "environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment" ) );
- p_list->push_back( PropertyInfo( Variant::REAL, "h_offset" ) );
- p_list->push_back( PropertyInfo( Variant::REAL, "v_offset" ) );
-
+ p_list->push_back(PropertyInfo(Variant::REAL, "near", PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "far", PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01"));
+ p_list->push_back(PropertyInfo(Variant::INT, "keep_aspect", PROPERTY_HINT_ENUM, "Keep Width,Keep Height"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "current"));
+ p_list->push_back(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "h_offset"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "v_offset"));
}
void Camera::_update_camera() {
Transform tr = get_camera_transform();
- tr.origin+=tr.basis.get_axis(1)*v_offset;
- tr.origin+=tr.basis.get_axis(0)*h_offset;
- VisualServer::get_singleton()->camera_set_transform( camera, tr );
+ tr.origin += tr.basis.get_axis(1) * v_offset;
+ tr.origin += tr.basis.get_axis(0) * h_offset;
+ VisualServer::get_singleton()->camera_set_transform(camera, tr);
// here goes listener stuff
/*
@@ -198,28 +187,23 @@ void Camera::_update_camera() {
if (is_inside_tree() && is_current()) {
get_viewport()->_camera_transform_changed_notify();
-
}
if (is_current() && get_world().is_valid()) {
get_world()->_update_camera(this);
}
-
-
}
void Camera::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
-
bool first_camera = get_viewport()->_camera_add(this);
if (!get_tree()->is_node_being_edited(this) && (current || first_camera))
make_current();
-
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -230,16 +214,15 @@ void Camera::_notification(int p_what) {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
clear_current();
- current=true; //keep it true
+ current = true; //keep it true
} else {
- current=false;
+ current = false;
}
}
get_viewport()->_camera_remove(this);
-
} break;
case NOTIFICATION_BECAME_CURRENT: {
if (get_world().is_valid()) {
@@ -251,13 +234,9 @@ void Camera::_notification(int p_what) {
get_world()->_remove_camera(this);
}
} break;
-
-
}
-
}
-
Transform Camera::get_camera_transform() const {
return get_global_transform().orthonormalized();
@@ -265,31 +244,31 @@ Transform Camera::get_camera_transform() const {
void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) {
- if (!force_change && fov==p_fovy_degrees && p_z_near==near && p_z_far==far && mode==PROJECTION_PERSPECTIVE)
+ if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE)
return;
- fov=p_fovy_degrees;
- near=p_z_near;
- far=p_z_far;
- mode=PROJECTION_PERSPECTIVE;
+ fov = p_fovy_degrees;
+ near = p_z_near;
+ far = p_z_far;
+ mode = PROJECTION_PERSPECTIVE;
- VisualServer::get_singleton()->camera_set_perspective(camera,fov,near,far);
+ VisualServer::get_singleton()->camera_set_perspective(camera, fov, near, far);
update_gizmo();
- force_change=false;
+ force_change = false;
}
void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
- if (!force_change && size==p_size && p_z_near==near && p_z_far==far && mode==PROJECTION_ORTHOGONAL)
+ if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL)
return;
size = p_size;
- near=p_z_near;
- far=p_z_far;
- mode=PROJECTION_ORTHOGONAL;
- force_change=false;
+ near = p_z_near;
+ far = p_z_far;
+ mode = PROJECTION_ORTHOGONAL;
+ force_change = false;
- VisualServer::get_singleton()->camera_set_orthogonal(camera,size,near,far);
+ VisualServer::get_singleton()->camera_set_orthogonal(camera, size, near, far);
update_gizmo();
}
@@ -300,7 +279,7 @@ RID Camera::get_camera() const {
void Camera::make_current() {
- current=true;
+ current = true;
if (!is_inside_tree())
return;
@@ -310,55 +289,47 @@ void Camera::make_current() {
//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this);
}
-
-
-
void Camera::clear_current() {
- current=false;
+ current = false;
if (!is_inside_tree())
return;
- if (get_viewport()->get_camera()==this) {
+ if (get_viewport()->get_camera() == this) {
get_viewport()->_camera_set(NULL);
get_viewport()->_camera_make_next_current(this);
}
-
}
bool Camera::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
- return get_viewport()->get_camera()==this;
+ return get_viewport()->get_camera() == this;
} else
return current;
return false;
}
-
bool Camera::_can_gizmo_scale() const {
return false;
}
-
-
-Vector3 Camera::project_ray_normal(const Point2& p_pos) const {
+Vector3 Camera::project_ray_normal(const Point2 &p_pos) const {
Vector3 ray = project_local_ray_normal(p_pos);
return get_camera_transform().basis.xform(ray).normalized();
};
-Vector3 Camera::project_local_ray_normal(const Point2& p_pos) const {
+Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const {
if (!is_inside_tree()) {
ERR_EXPLAIN("Camera is not inside scene.");
- ERR_FAIL_COND_V(!is_inside_tree(),Vector3());
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
}
-
#if 0
Size2 viewport_size = get_viewport()->get_visible_rect().size;
Vector2 cpos = p_pos;
@@ -370,26 +341,25 @@ Vector3 Camera::project_local_ray_normal(const Point2& p_pos) const {
Vector3 ray;
- if (mode==PROJECTION_ORTHOGONAL) {
+ if (mode == PROJECTION_ORTHOGONAL) {
- ray=Vector3(0,0,-1);
+ ray = Vector3(0, 0, -1);
} else {
CameraMatrix cm;
- cm.set_perspective(fov,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
- float screen_w,screen_h;
- cm.get_viewport_size(screen_w,screen_h);
- ray=Vector3( ((cpos.x/viewport_size.width)*2.0-1.0)*screen_w, ((1.0-(cpos.y/viewport_size.height))*2.0-1.0)*screen_h,-near).normalized();
+ cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
+ float screen_w, screen_h;
+ cm.get_viewport_size(screen_w, screen_h);
+ ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_w, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_h, -near).normalized();
}
return ray;
};
-
-Vector3 Camera::project_ray_origin(const Point2& p_pos) const {
+Vector3 Camera::project_ray_origin(const Point2 &p_pos) const {
if (!is_inside_tree()) {
ERR_EXPLAIN("Camera is not inside scene.");
- ERR_FAIL_COND_V(!is_inside_tree(),Vector3());
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
}
#if 0
@@ -401,7 +371,7 @@ Vector3 Camera::project_ray_origin(const Point2& p_pos) const {
Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
#endif
- ERR_FAIL_COND_V( viewport_size.y == 0, Vector3() );
+ ERR_FAIL_COND_V(viewport_size.y == 0, Vector3());
//float aspect = viewport_size.x / viewport_size.y;
if (mode == PROJECTION_PERSPECTIVE) {
@@ -410,91 +380,84 @@ Vector3 Camera::project_ray_origin(const Point2& p_pos) const {
} else {
Vector2 pos = cpos / viewport_size;
- float vsize,hsize;
- if (keep_aspect==KEEP_WIDTH) {
- vsize = size/viewport_size.aspect();
+ float vsize, hsize;
+ if (keep_aspect == KEEP_WIDTH) {
+ vsize = size / viewport_size.aspect();
hsize = size;
} else {
- hsize = size*viewport_size.aspect();
+ hsize = size * viewport_size.aspect();
vsize = size;
-
}
-
-
Vector3 ray;
- ray.x = pos.x * (hsize) - hsize/2;
- ray.y = (1.0 - pos.y) * (vsize) - vsize/2;
+ ray.x = pos.x * (hsize)-hsize / 2;
+ ray.y = (1.0 - pos.y) * (vsize)-vsize / 2;
ray.z = -near;
ray = get_camera_transform().xform(ray);
return ray;
};
};
-bool Camera::is_position_behind(const Vector3& p_pos) const {
+bool Camera::is_position_behind(const Vector3 &p_pos) const {
Transform t = get_global_transform();
Vector3 eyedir = -get_global_transform().basis.get_axis(2).normalized();
- return eyedir.dot(p_pos) < (eyedir.dot(t.origin)+near);
+ return eyedir.dot(p_pos) < (eyedir.dot(t.origin) + near);
}
-Point2 Camera::unproject_position(const Vector3& p_pos) const {
+Point2 Camera::unproject_position(const Vector3 &p_pos) const {
if (!is_inside_tree()) {
ERR_EXPLAIN("Camera is not inside scene.");
- ERR_FAIL_COND_V(!is_inside_tree(),Vector2());
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector2());
}
Size2 viewport_size = get_viewport()->get_visible_rect().size;
CameraMatrix cm;
-
- if (mode==PROJECTION_ORTHOGONAL)
- cm.set_orthogonal(size,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
+ if (mode == PROJECTION_ORTHOGONAL)
+ cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
else
- cm.set_perspective(fov,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
-
- Plane p(get_camera_transform().xform_inv(p_pos),1.0);
+ cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
- p=cm.xform4(p);
- p.normal/=p.d;
+ Plane p(get_camera_transform().xform_inv(p_pos), 1.0);
+ p = cm.xform4(p);
+ p.normal /= p.d;
Point2 res;
- res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x;
- res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y;
+ res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x;
+ res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y;
return res;
-
}
-Vector3 Camera::project_position(const Point2& p_point) const {
+Vector3 Camera::project_position(const Point2 &p_point) const {
if (!is_inside_tree()) {
ERR_EXPLAIN("Camera is not inside scene.");
- ERR_FAIL_COND_V(!is_inside_tree(),Vector3());
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
}
Size2 viewport_size = get_viewport()->get_visible_rect().size;
CameraMatrix cm;
- if (mode==PROJECTION_ORTHOGONAL)
- cm.set_orthogonal(size,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
+ if (mode == PROJECTION_ORTHOGONAL)
+ cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
else
- cm.set_perspective(fov,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
+ cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
Size2 vp_size;
- cm.get_viewport_size(vp_size.x,vp_size.y);
+ cm.get_viewport_size(vp_size.x, vp_size.y);
Vector2 point;
- point.x = (p_point.x/viewport_size.x) * 2.0 - 1.0;
- point.y = (1.0-(p_point.y/viewport_size.y)) * 2.0 - 1.0;
- point*=vp_size;
-
- Vector3 p(point.x,point.y,-near);
+ point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0;
+ point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0;
+ point *= vp_size;
+ Vector3 p(point.x, point.y, -near);
return get_camera_transform().xform(p);
}
@@ -516,13 +479,13 @@ void Camera::_camera_make_current(Node *p_camera) {
}
*/
-void Camera::set_environment(const Ref<Environment>& p_environment) {
+void Camera::set_environment(const Ref<Environment> &p_environment) {
- environment=p_environment;
+ environment = p_environment;
if (environment.is_valid())
- VS::get_singleton()->camera_set_environment(camera,environment->get_rid());
+ VS::get_singleton()->camera_set_environment(camera, environment->get_rid());
else
- VS::get_singleton()->camera_set_environment(camera,RID());
+ VS::get_singleton()->camera_set_environment(camera, RID());
}
Ref<Environment> Camera::get_environment() const {
@@ -530,59 +493,55 @@ Ref<Environment> Camera::get_environment() const {
return environment;
}
-
void Camera::set_keep_aspect_mode(KeepAspect p_aspect) {
- keep_aspect=p_aspect;
- VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera,p_aspect==KEEP_WIDTH);
+ keep_aspect = p_aspect;
+ VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH);
_change_notify();
}
-Camera::KeepAspect Camera::get_keep_aspect_mode() const{
+Camera::KeepAspect Camera::get_keep_aspect_mode() const {
return keep_aspect;
}
-
-
void Camera::_bind_methods() {
- ClassDB::bind_method(D_METHOD("project_ray_normal","screen_point"), &Camera::project_ray_normal);
- ClassDB::bind_method(D_METHOD("project_local_ray_normal","screen_point"), &Camera::project_local_ray_normal);
- ClassDB::bind_method(D_METHOD("project_ray_origin","screen_point"), &Camera::project_ray_origin);
- ClassDB::bind_method(D_METHOD("unproject_position","world_point"), &Camera::unproject_position);
- ClassDB::bind_method(D_METHOD("is_position_behind","world_point"), &Camera::is_position_behind);
- ClassDB::bind_method(D_METHOD("project_position","screen_point"), &Camera::project_position);
- ClassDB::bind_method(D_METHOD("set_perspective","fov","z_near","z_far"),&Camera::set_perspective );
- ClassDB::bind_method(D_METHOD("set_orthogonal","size","z_near","z_far"),&Camera::set_orthogonal );
- ClassDB::bind_method(D_METHOD("make_current"),&Camera::make_current );
- ClassDB::bind_method(D_METHOD("clear_current"),&Camera::clear_current );
- ClassDB::bind_method(D_METHOD("is_current"),&Camera::is_current );
- ClassDB::bind_method(D_METHOD("get_camera_transform"),&Camera::get_camera_transform );
- ClassDB::bind_method(D_METHOD("get_fov"),&Camera::get_fov );
- ClassDB::bind_method(D_METHOD("get_size"),&Camera::get_size );
- ClassDB::bind_method(D_METHOD("get_zfar"),&Camera::get_zfar );
- ClassDB::bind_method(D_METHOD("get_znear"),&Camera::get_znear );
- ClassDB::bind_method(D_METHOD("get_projection"),&Camera::get_projection );
- ClassDB::bind_method(D_METHOD("set_h_offset","ofs"),&Camera::set_h_offset );
- ClassDB::bind_method(D_METHOD("get_h_offset"),&Camera::get_h_offset );
- ClassDB::bind_method(D_METHOD("set_v_offset","ofs"),&Camera::set_v_offset );
- ClassDB::bind_method(D_METHOD("get_v_offset"),&Camera::get_v_offset );
- ClassDB::bind_method(D_METHOD("set_cull_mask","mask"),&Camera::set_cull_mask );
- ClassDB::bind_method(D_METHOD("get_cull_mask"),&Camera::get_cull_mask );
- ClassDB::bind_method(D_METHOD("set_environment","env:Environment"),&Camera::set_environment );
- ClassDB::bind_method(D_METHOD("get_environment:Environment"),&Camera::get_environment );
- ClassDB::bind_method(D_METHOD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode );
- ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"),&Camera::get_keep_aspect_mode );
+ ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera::project_ray_normal);
+ ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera::project_local_ray_normal);
+ ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera::project_ray_origin);
+ ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera::unproject_position);
+ ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera::is_position_behind);
+ ClassDB::bind_method(D_METHOD("project_position", "screen_point"), &Camera::project_position);
+ ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera::set_perspective);
+ ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal);
+ ClassDB::bind_method(D_METHOD("make_current"), &Camera::make_current);
+ ClassDB::bind_method(D_METHOD("clear_current"), &Camera::clear_current);
+ ClassDB::bind_method(D_METHOD("is_current"), &Camera::is_current);
+ ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera::get_camera_transform);
+ ClassDB::bind_method(D_METHOD("get_fov"), &Camera::get_fov);
+ ClassDB::bind_method(D_METHOD("get_size"), &Camera::get_size);
+ ClassDB::bind_method(D_METHOD("get_zfar"), &Camera::get_zfar);
+ ClassDB::bind_method(D_METHOD("get_znear"), &Camera::get_znear);
+ ClassDB::bind_method(D_METHOD("get_projection"), &Camera::get_projection);
+ ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera::set_h_offset);
+ ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera::get_h_offset);
+ ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera::set_v_offset);
+ ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera::get_v_offset);
+ ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera::set_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera::get_cull_mask);
+ ClassDB::bind_method(D_METHOD("set_environment", "env:Environment"), &Camera::set_environment);
+ ClassDB::bind_method(D_METHOD("get_environment:Environment"), &Camera::get_environment);
+ ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera::set_keep_aspect_mode);
+ ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera::get_keep_aspect_mode);
//ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current );
- BIND_CONSTANT( PROJECTION_PERSPECTIVE );
- BIND_CONSTANT( PROJECTION_ORTHOGONAL );
-
- BIND_CONSTANT( KEEP_WIDTH );
- BIND_CONSTANT( KEEP_HEIGHT );
+ BIND_CONSTANT(PROJECTION_PERSPECTIVE);
+ BIND_CONSTANT(PROJECTION_ORTHOGONAL);
+ BIND_CONSTANT(KEEP_WIDTH);
+ BIND_CONSTANT(KEEP_HEIGHT);
}
float Camera::get_fov() const {
@@ -605,7 +564,6 @@ float Camera::get_zfar() const {
return far;
}
-
Camera::Projection Camera::get_projection() const {
return mode;
@@ -613,37 +571,32 @@ Camera::Projection Camera::get_projection() const {
void Camera::set_cull_mask(uint32_t p_layers) {
- layers=p_layers;
- VisualServer::get_singleton()->camera_set_cull_mask(camera,layers);
+ layers = p_layers;
+ VisualServer::get_singleton()->camera_set_cull_mask(camera, layers);
}
-uint32_t Camera::get_cull_mask() const{
+uint32_t Camera::get_cull_mask() const {
return layers;
}
-
Vector<Plane> Camera::get_frustum() const {
- ERR_FAIL_COND_V(!is_inside_world(),Vector<Plane>());
+ ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());
Size2 viewport_size = get_viewport()->get_visible_rect().size;
CameraMatrix cm;
- if (mode==PROJECTION_PERSPECTIVE)
- cm.set_perspective(fov,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
+ if (mode == PROJECTION_PERSPECTIVE)
+ cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
else
- cm.set_orthogonal(size,viewport_size.aspect(),near,far,keep_aspect==KEEP_WIDTH);
+ cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
return cm.get_projection_planes(get_camera_transform());
-
}
-
-
-
void Camera::set_v_offset(float p_offset) {
- v_offset=p_offset;
+ v_offset = p_offset;
_update_camera();
}
@@ -653,7 +606,7 @@ float Camera::get_v_offset() const {
}
void Camera::set_h_offset(float p_offset) {
- h_offset=p_offset;
+ h_offset = p_offset;
_update_camera();
}
@@ -662,32 +615,27 @@ float Camera::get_h_offset() const {
return h_offset;
}
-
Camera::Camera() {
camera = VisualServer::get_singleton()->camera_create();
- size=1;
- fov=0;
- near=0;
- far=0;
- current=false;
- force_change=false;
- mode=PROJECTION_PERSPECTIVE;
- set_perspective(60.0,0.1,100.0);
- keep_aspect=KEEP_HEIGHT;
- layers=0xfffff;
- v_offset=0;
- h_offset=0;
- VisualServer::get_singleton()->camera_set_cull_mask(camera,layers);
+ size = 1;
+ fov = 0;
+ near = 0;
+ far = 0;
+ current = false;
+ force_change = false;
+ mode = PROJECTION_PERSPECTIVE;
+ set_perspective(60.0, 0.1, 100.0);
+ keep_aspect = KEEP_HEIGHT;
+ layers = 0xfffff;
+ v_offset = 0;
+ h_offset = 0;
+ VisualServer::get_singleton()->camera_set_cull_mask(camera, layers);
//active=false;
set_notify_transform(true);
}
-
Camera::~Camera() {
VisualServer::get_singleton()->free(camera);
-
}
-
-
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index 5301c06ee5..3c31b6beeb 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -29,7 +29,6 @@
#ifndef CAMERA_H
#define CAMERA_H
-
#include "scene/3d/spatial.h"
#include "scene/main/viewport.h"
#include "scene/resources/environment.h"
@@ -38,7 +37,8 @@
*/
class Camera : public Spatial {
- GDCLASS( Camera, Spatial );
+ GDCLASS(Camera, Spatial);
+
public:
enum Projection {
@@ -52,7 +52,6 @@ public:
};
private:
-
bool force_change;
bool current;
@@ -60,7 +59,7 @@ private:
float fov;
float size;
- float near,far;
+ float near, far;
float v_offset;
float h_offset;
KeepAspect keep_aspect;
@@ -76,30 +75,27 @@ private:
virtual bool _can_gizmo_scale() const;
-
-
//void _camera_make_current(Node *p_camera);
-friend class Viewport;
+ friend class Viewport;
void _update_audio_listener_state();
-protected:
+protected:
void _update_camera();
virtual void _request_camera_update();
void _update_camera_mode();
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
-
enum {
- NOTIFICATION_BECAME_CURRENT=50,
- NOTIFICATION_LOST_CURRENT=51
+ NOTIFICATION_BECAME_CURRENT = 50,
+ NOTIFICATION_LOST_CURRENT = 51
};
void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far);
@@ -119,39 +115,35 @@ public:
virtual Transform get_camera_transform() const;
- Vector3 project_ray_normal(const Point2& p_point) const;
- Vector3 project_ray_origin(const Point2& p_point) const;
- Vector3 project_local_ray_normal(const Point2& p_point) const;
- Point2 unproject_position(const Vector3& p_pos) const;
- bool is_position_behind(const Vector3& p_pos) const;
- Vector3 project_position(const Point2& p_point) const;
+ Vector3 project_ray_normal(const Point2 &p_point) const;
+ Vector3 project_ray_origin(const Point2 &p_point) const;
+ Vector3 project_local_ray_normal(const Point2 &p_point) const;
+ Point2 unproject_position(const Vector3 &p_pos) const;
+ bool is_position_behind(const Vector3 &p_pos) const;
+ Vector3 project_position(const Point2 &p_point) const;
void set_cull_mask(uint32_t p_layers);
uint32_t get_cull_mask() const;
Vector<Plane> get_frustum() const;
- void set_environment(const Ref<Environment>& p_environment);
+ void set_environment(const Ref<Environment> &p_environment);
Ref<Environment> get_environment() const;
void set_keep_aspect_mode(KeepAspect p_aspect);
KeepAspect get_keep_aspect_mode() const;
-
void set_v_offset(float p_offset);
float get_v_offset() const;
void set_h_offset(float p_offset);
float get_h_offset() const;
-
Camera();
~Camera();
-
};
-
-VARIANT_ENUM_CAST( Camera::Projection );
-VARIANT_ENUM_CAST( Camera::KeepAspect );
+VARIANT_ENUM_CAST(Camera::Projection);
+VARIANT_ENUM_CAST(Camera::KeepAspect);
#endif
diff --git a/scene/3d/character_camera.cpp b/scene/3d/character_camera.cpp
index 424a7fc79c..edd97eaa6d 100644
--- a/scene/3d/character_camera.cpp
+++ b/scene/3d/character_camera.cpp
@@ -237,7 +237,6 @@ void CharacterCamera::_compute_camera() {
new_pos = character_pos + rel_n * l;
-
#endif
follow_pos=new_pos;
diff --git a/scene/3d/character_camera.h b/scene/3d/character_camera.h
index 5fde8c342e..464fa5c235 100644
--- a/scene/3d/character_camera.h
+++ b/scene/3d/character_camera.h
@@ -29,7 +29,6 @@
#ifndef CHARACTER_CAMERA_H
#define CHARACTER_CAMERA_H
-
#include "scene/3d/camera.h"
#if 0
class CharacterCamera : public Camera {
diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp
index 32e60f0d57..c3e19c4b81 100644
--- a/scene/3d/collision_object.cpp
+++ b/scene/3d/collision_object.cpp
@@ -27,15 +27,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "collision_object.h"
-#include "servers/physics_server.h"
#include "scene/scene_string_names.h"
+#include "servers/physics_server.h"
void CollisionObject::_update_shapes_from_children() {
shapes.clear();
- for(int i=0;i<get_child_count();i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- Node* n = get_child(i);
- n->call("_add_to_collision_object",this);
+ Node *n = get_child(i);
+ n->call("_add_to_collision_object", this);
}
_update_shapes();
@@ -43,31 +43,31 @@ void CollisionObject::_update_shapes_from_children() {
void CollisionObject::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
if (area)
- PhysicsServer::get_singleton()->area_set_transform(rid,get_global_transform());
+ PhysicsServer::get_singleton()->area_set_transform(rid, get_global_transform());
else
- PhysicsServer::get_singleton()->body_set_state(rid,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());
+ PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
RID space = get_world()->get_space();
if (area) {
- PhysicsServer::get_singleton()->area_set_space(rid,space);
+ PhysicsServer::get_singleton()->area_set_space(rid, space);
} else
- PhysicsServer::get_singleton()->body_set_space(rid,space);
+ PhysicsServer::get_singleton()->body_set_space(rid, space);
_update_pickable();
- //get space
+ //get space
};
case NOTIFICATION_TRANSFORM_CHANGED: {
if (area)
- PhysicsServer::get_singleton()->area_set_transform(rid,get_global_transform());
+ PhysicsServer::get_singleton()->area_set_transform(rid, get_global_transform());
else
- PhysicsServer::get_singleton()->body_set_state(rid,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());
+ PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -78,9 +78,9 @@ void CollisionObject::_notification(int p_what) {
case NOTIFICATION_EXIT_WORLD: {
if (area) {
- PhysicsServer::get_singleton()->area_set_space(rid,RID());
+ PhysicsServer::get_singleton()->area_set_space(rid, RID());
} else
- PhysicsServer::get_singleton()->body_set_space(rid,RID());
+ PhysicsServer::get_singleton()->body_set_space(rid, RID());
} break;
}
@@ -96,25 +96,24 @@ void CollisionObject::_update_shapes() {
else
PhysicsServer::get_singleton()->body_clear_shapes(rid);
- for(int i=0;i<shapes.size();i++) {
+ for (int i = 0; i < shapes.size(); i++) {
if (shapes[i].shape.is_null())
continue;
if (area)
- PhysicsServer::get_singleton()->area_add_shape(rid,shapes[i].shape->get_rid(),shapes[i].xform);
+ PhysicsServer::get_singleton()->area_add_shape(rid, shapes[i].shape->get_rid(), shapes[i].xform);
else {
- PhysicsServer::get_singleton()->body_add_shape(rid,shapes[i].shape->get_rid(),shapes[i].xform);
+ PhysicsServer::get_singleton()->body_add_shape(rid, shapes[i].shape->get_rid(), shapes[i].xform);
if (shapes[i].trigger)
- PhysicsServer::get_singleton()->body_set_shape_as_trigger(rid,i,shapes[i].trigger);
+ PhysicsServer::get_singleton()->body_set_shape_as_trigger(rid, i, shapes[i].trigger);
}
}
}
+bool CollisionObject::_set(const StringName &p_name, const Variant &p_value) {
+ String name = p_name;
-bool CollisionObject::_set(const StringName& p_name, const Variant& p_value) {
- String name=p_name;
-
- if (name=="shape_count") {
+ if (name == "shape_count") {
shapes.resize(p_value);
_update_shapes();
@@ -122,40 +121,37 @@ bool CollisionObject::_set(const StringName& p_name, const Variant& p_value) {
} else if (name.begins_with("shapes/")) {
- int idx=name.get_slicec('/',1).to_int();
- String what=name.get_slicec('/',2);
- if (what=="shape")
- set_shape(idx,RefPtr(p_value));
- else if (what=="transform")
- set_shape_transform(idx,p_value);
- else if (what=="trigger")
- set_shape_as_trigger(idx,p_value);
-
+ int idx = name.get_slicec('/', 1).to_int();
+ String what = name.get_slicec('/', 2);
+ if (what == "shape")
+ set_shape(idx, RefPtr(p_value));
+ else if (what == "transform")
+ set_shape_transform(idx, p_value);
+ else if (what == "trigger")
+ set_shape_as_trigger(idx, p_value);
} else
return false;
return true;
-
-
}
-bool CollisionObject::_get(const StringName& p_name,Variant &r_ret) const {
+bool CollisionObject::_get(const StringName &p_name, Variant &r_ret) const {
- String name=p_name;
+ String name = p_name;
- if (name=="shape_count") {
- r_ret= shapes.size();
+ if (name == "shape_count") {
+ r_ret = shapes.size();
} else if (name.begins_with("shapes/")) {
- int idx=name.get_slicec('/',1).to_int();
- String what=name.get_slicec('/',2);
- if (what=="shape")
- r_ret= get_shape(idx);
- else if (what=="transform")
- r_ret= get_shape_transform(idx);
- else if (what=="trigger")
- r_ret= is_shape_set_as_trigger(idx);
+ int idx = name.get_slicec('/', 1).to_int();
+ String what = name.get_slicec('/', 2);
+ if (what == "shape")
+ r_ret = get_shape(idx);
+ else if (what == "transform")
+ r_ret = get_shape_transform(idx);
+ else if (what == "trigger")
+ r_ret = is_shape_set_as_trigger(idx);
} else
return false;
@@ -163,26 +159,24 @@ bool CollisionObject::_get(const StringName& p_name,Variant &r_ret) const {
return true;
}
-void CollisionObject::_get_property_list( List<PropertyInfo> *p_list) const {
+void CollisionObject::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo(Variant::INT,"shape_count",PROPERTY_HINT_RANGE,"0,256,1",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
-
- for(int i=0;i<shapes.size();i++) {
- String path="shapes/"+itos(i)+"/";
- p_list->push_back( PropertyInfo(Variant::OBJECT,path+"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
- p_list->push_back( PropertyInfo(Variant::TRANSFORM,path+"transform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
- p_list->push_back( PropertyInfo(Variant::BOOL,path+"trigger",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
+ p_list->push_back(PropertyInfo(Variant::INT, "shape_count", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
+ for (int i = 0; i < shapes.size(); i++) {
+ String path = "shapes/" + itos(i) + "/";
+ p_list->push_back(PropertyInfo(Variant::OBJECT, path + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
+ p_list->push_back(PropertyInfo(Variant::TRANSFORM, path + "transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
+ p_list->push_back(PropertyInfo(Variant::BOOL, path + "trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
}
}
-
-void CollisionObject::_input_event(Node *p_camera, const InputEvent& p_input_event, const Vector3& p_pos, const Vector3& p_normal, int p_shape) {
+void CollisionObject::_input_event(Node *p_camera, const InputEvent &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) {
if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_input_event,p_camera,p_input_event,p_pos,p_normal,p_shape);
+ get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape);
}
- emit_signal(SceneStringNames::get_singleton()->input_event,p_camera,p_input_event,p_pos,p_normal,p_shape);
+ emit_signal(SceneStringNames::get_singleton()->input_event, p_camera, p_input_event, p_pos, p_normal, p_shape);
}
void CollisionObject::_mouse_enter() {
@@ -193,14 +187,12 @@ void CollisionObject::_mouse_enter() {
emit_signal(SceneStringNames::get_singleton()->mouse_entered);
}
-
void CollisionObject::_mouse_exit() {
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit);
}
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
-
}
void CollisionObject::_update_pickable() {
@@ -208,16 +200,15 @@ void CollisionObject::_update_pickable() {
return;
bool pickable = ray_pickable && is_inside_tree() && is_visible_in_tree();
if (area)
- PhysicsServer::get_singleton()->area_set_ray_pickable(rid,pickable);
+ PhysicsServer::get_singleton()->area_set_ray_pickable(rid, pickable);
else
- PhysicsServer::get_singleton()->body_set_ray_pickable(rid,pickable);
+ PhysicsServer::get_singleton()->body_set_ray_pickable(rid, pickable);
}
void CollisionObject::set_ray_pickable(bool p_ray_pickable) {
- ray_pickable=p_ray_pickable;
+ ray_pickable = p_ray_pickable;
_update_pickable();
-
}
bool CollisionObject::is_ray_pickable() const {
@@ -225,80 +216,74 @@ bool CollisionObject::is_ray_pickable() const {
return ray_pickable;
}
-
void CollisionObject::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_shape","shape:Shape","transform"),&CollisionObject::add_shape,DEFVAL(Transform()));
- ClassDB::bind_method(D_METHOD("get_shape_count"),&CollisionObject::get_shape_count);
- ClassDB::bind_method(D_METHOD("set_shape","shape_idx","shape:Shape"),&CollisionObject::set_shape);
- ClassDB::bind_method(D_METHOD("set_shape_transform","shape_idx","transform"),&CollisionObject::set_shape_transform);
-// ClassDB::bind_method(D_METHOD("set_shape_transform","shape_idx","transform"),&CollisionObject::set_shape_transform);
- ClassDB::bind_method(D_METHOD("set_shape_as_trigger","shape_idx","enable"),&CollisionObject::set_shape_as_trigger);
- ClassDB::bind_method(D_METHOD("is_shape_set_as_trigger","shape_idx"),&CollisionObject::is_shape_set_as_trigger);
- ClassDB::bind_method(D_METHOD("get_shape:Shape","shape_idx"),&CollisionObject::get_shape);
- ClassDB::bind_method(D_METHOD("get_shape_transform","shape_idx"),&CollisionObject::get_shape_transform);
- ClassDB::bind_method(D_METHOD("remove_shape","shape_idx"),&CollisionObject::remove_shape);
- ClassDB::bind_method(D_METHOD("clear_shapes"),&CollisionObject::clear_shapes);
- ClassDB::bind_method(D_METHOD("set_ray_pickable","ray_pickable"),&CollisionObject::set_ray_pickable);
- ClassDB::bind_method(D_METHOD("is_ray_pickable"),&CollisionObject::is_ray_pickable);
- ClassDB::bind_method(D_METHOD("set_capture_input_on_drag","enable"),&CollisionObject::set_capture_input_on_drag);
- ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"),&CollisionObject::get_capture_input_on_drag);
- ClassDB::bind_method(D_METHOD("get_rid"),&CollisionObject::get_rid);
- BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::OBJECT,"camera"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::VECTOR3,"click_pos"),PropertyInfo(Variant::VECTOR3,"click_normal"),PropertyInfo(Variant::INT,"shape_idx")));
-
- ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::OBJECT,"camera"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::VECTOR3,"click_pos"),PropertyInfo(Variant::VECTOR3,"click_normal"),PropertyInfo(Variant::INT,"shape_idx")));
- ADD_SIGNAL( MethodInfo("mouse_entered"));
- ADD_SIGNAL( MethodInfo("mouse_exited"));
-
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"input_ray_pickable"),"set_ray_pickable","is_ray_pickable");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"input_capture_on_drag"),"set_capture_input_on_drag","get_capture_input_on_drag");
+ ClassDB::bind_method(D_METHOD("add_shape", "shape:Shape", "transform"), &CollisionObject::add_shape, DEFVAL(Transform()));
+ ClassDB::bind_method(D_METHOD("get_shape_count"), &CollisionObject::get_shape_count);
+ ClassDB::bind_method(D_METHOD("set_shape", "shape_idx", "shape:Shape"), &CollisionObject::set_shape);
+ ClassDB::bind_method(D_METHOD("set_shape_transform", "shape_idx", "transform"), &CollisionObject::set_shape_transform);
+ // ClassDB::bind_method(D_METHOD("set_shape_transform","shape_idx","transform"),&CollisionObject::set_shape_transform);
+ ClassDB::bind_method(D_METHOD("set_shape_as_trigger", "shape_idx", "enable"), &CollisionObject::set_shape_as_trigger);
+ ClassDB::bind_method(D_METHOD("is_shape_set_as_trigger", "shape_idx"), &CollisionObject::is_shape_set_as_trigger);
+ ClassDB::bind_method(D_METHOD("get_shape:Shape", "shape_idx"), &CollisionObject::get_shape);
+ ClassDB::bind_method(D_METHOD("get_shape_transform", "shape_idx"), &CollisionObject::get_shape_transform);
+ ClassDB::bind_method(D_METHOD("remove_shape", "shape_idx"), &CollisionObject::remove_shape);
+ ClassDB::bind_method(D_METHOD("clear_shapes"), &CollisionObject::clear_shapes);
+ ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject::set_ray_pickable);
+ ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject::is_ray_pickable);
+ ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject::set_capture_input_on_drag);
+ ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"), &CollisionObject::get_capture_input_on_drag);
+ ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject::get_rid);
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::VECTOR3, "click_pos"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx")));
+
+ ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::VECTOR3, "click_pos"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx")));
+ ADD_SIGNAL(MethodInfo("mouse_entered"));
+ ADD_SIGNAL(MethodInfo("mouse_exited"));
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_ray_pickable"), "set_ray_pickable", "is_ray_pickable");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_capture_on_drag"), "set_capture_input_on_drag", "get_capture_input_on_drag");
}
-
-void CollisionObject::add_shape(const Ref<Shape>& p_shape, const Transform& p_transform) {
+void CollisionObject::add_shape(const Ref<Shape> &p_shape, const Transform &p_transform) {
ShapeData sdata;
- sdata.shape=p_shape;
- sdata.xform=p_transform;
+ sdata.shape = p_shape;
+ sdata.xform = p_transform;
shapes.push_back(sdata);
_update_shapes();
-
}
int CollisionObject::get_shape_count() const {
return shapes.size();
-
}
-void CollisionObject::set_shape(int p_shape_idx, const Ref<Shape>& p_shape) {
+void CollisionObject::set_shape(int p_shape_idx, const Ref<Shape> &p_shape) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
- shapes[p_shape_idx].shape=p_shape;
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
+ shapes[p_shape_idx].shape = p_shape;
_update_shapes();
}
-void CollisionObject::set_shape_transform(int p_shape_idx, const Transform& p_transform) {
+void CollisionObject::set_shape_transform(int p_shape_idx, const Transform &p_transform) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
- shapes[p_shape_idx].xform=p_transform;
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
+ shapes[p_shape_idx].xform = p_transform;
_update_shapes();
}
Ref<Shape> CollisionObject::get_shape(int p_shape_idx) const {
- ERR_FAIL_INDEX_V(p_shape_idx,shapes.size(),Ref<Shape>());
+ ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), Ref<Shape>());
return shapes[p_shape_idx].shape;
-
}
Transform CollisionObject::get_shape_transform(int p_shape_idx) const {
- ERR_FAIL_INDEX_V(p_shape_idx,shapes.size(),Transform());
+ ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), Transform());
return shapes[p_shape_idx].xform;
-
}
void CollisionObject::remove_shape(int p_shape_idx) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
shapes.remove(p_shape_idx);
_update_shapes();
@@ -313,41 +298,38 @@ void CollisionObject::clear_shapes() {
void CollisionObject::set_shape_as_trigger(int p_shape_idx, bool p_trigger) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
- shapes[p_shape_idx].trigger=p_trigger;
- if (!area && rid.is_valid()) {
-
- PhysicsServer::get_singleton()->body_set_shape_as_trigger(rid,p_shape_idx,p_trigger);
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
+ shapes[p_shape_idx].trigger = p_trigger;
+ if (!area && rid.is_valid()) {
- }
+ PhysicsServer::get_singleton()->body_set_shape_as_trigger(rid, p_shape_idx, p_trigger);
+ }
}
bool CollisionObject::is_shape_set_as_trigger(int p_shape_idx) const {
- ERR_FAIL_INDEX_V(p_shape_idx,shapes.size(),false);
- return shapes[p_shape_idx].trigger;
+ ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), false);
+ return shapes[p_shape_idx].trigger;
}
CollisionObject::CollisionObject(RID p_rid, bool p_area) {
- rid=p_rid;
- area=p_area;
- capture_input_on_drag=false;
- ray_pickable=true;
+ rid = p_rid;
+ area = p_area;
+ capture_input_on_drag = false;
+ ray_pickable = true;
set_notify_transform(true);
if (p_area) {
- PhysicsServer::get_singleton()->area_attach_object_instance_ID(rid,get_instance_ID());
+ PhysicsServer::get_singleton()->area_attach_object_instance_ID(rid, get_instance_ID());
} else {
- PhysicsServer::get_singleton()->body_attach_object_instance_ID(rid,get_instance_ID());
+ PhysicsServer::get_singleton()->body_attach_object_instance_ID(rid, get_instance_ID());
}
//set_transform_notify(true);
-
}
void CollisionObject::set_capture_input_on_drag(bool p_capture) {
- capture_input_on_drag=p_capture;
-
+ capture_input_on_drag = p_capture;
}
bool CollisionObject::get_capture_input_on_drag() const {
@@ -355,12 +337,10 @@ bool CollisionObject::get_capture_input_on_drag() const {
return capture_input_on_drag;
}
-
CollisionObject::CollisionObject() {
-
- capture_input_on_drag=false;
- ray_pickable=true;
+ capture_input_on_drag = false;
+ ray_pickable = true;
set_notify_transform(true);
//owner=
diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object.h
index b89b7e3361..9b124cf277 100644
--- a/scene/3d/collision_object.h
+++ b/scene/3d/collision_object.h
@@ -34,7 +34,7 @@
class CollisionObject : public Spatial {
- GDCLASS( CollisionObject, Spatial );
+ GDCLASS(CollisionObject, Spatial);
bool area;
RID rid;
@@ -42,12 +42,11 @@ class CollisionObject : public Spatial {
struct ShapeData {
Transform xform;
Ref<Shape> shape;
- bool trigger;
-
- ShapeData() {
- trigger=false;
- }
+ bool trigger;
+ ShapeData() {
+ trigger = false;
+ }
};
bool capture_input_on_drag;
@@ -57,30 +56,28 @@ class CollisionObject : public Spatial {
void _update_pickable();
void _update_shapes();
-friend class CollisionShape;
-friend class CollisionPolygon;
+ friend class CollisionShape;
+ friend class CollisionPolygon;
void _update_shapes_from_children();
-protected:
+protected:
CollisionObject(RID p_rid, bool p_area);
void _notification(int p_what);
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
-friend class Viewport;
- virtual void _input_event(Node* p_camera,const InputEvent& p_input_event,const Vector3& p_pos, const Vector3& p_normal, int p_shape);
+ friend class Viewport;
+ virtual void _input_event(Node *p_camera, const InputEvent &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
virtual void _mouse_enter();
virtual void _mouse_exit();
public:
-
-
- void add_shape(const Ref<Shape>& p_shape, const Transform& p_transform=Transform());
+ void add_shape(const Ref<Shape> &p_shape, const Transform &p_transform = Transform());
int get_shape_count() const;
- void set_shape(int p_shape_idx, const Ref<Shape>& p_shape);
- void set_shape_transform(int p_shape_idx, const Transform& p_transform);
+ void set_shape(int p_shape_idx, const Ref<Shape> &p_shape);
+ void set_shape_transform(int p_shape_idx, const Transform &p_transform);
Ref<Shape> get_shape(int p_shape_idx) const;
Transform get_shape_transform(int p_shape_idx) const;
void remove_shape(int p_shape_idx);
@@ -94,7 +91,6 @@ public:
void set_capture_input_on_drag(bool p_capture);
bool get_capture_input_on_drag() const;
-
_FORCE_INLINE_ RID get_rid() const { return rid; }
CollisionObject();
diff --git a/scene/3d/collision_polygon.cpp b/scene/3d/collision_polygon.cpp
index 82637c2488..12dab067d0 100644
--- a/scene/3d/collision_polygon.cpp
+++ b/scene/3d/collision_polygon.cpp
@@ -40,44 +40,43 @@ void CollisionPolygon::_add_to_collision_object(Object *p_obj) {
CollisionObject *co = p_obj->cast_to<CollisionObject>();
ERR_FAIL_COND(!co);
- if (polygon.size()==0)
+ if (polygon.size() == 0)
return;
- bool solids=build_mode==BUILD_SOLIDS;
+ bool solids = build_mode == BUILD_SOLIDS;
- Vector< Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon);
- if (decomp.size()==0)
+ Vector<Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon);
+ if (decomp.size() == 0)
return;
if (true || solids) {
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
- shape_from=co->get_shape_count();
- for(int i=0;i<decomp.size();i++) {
- Ref<ConvexPolygonShape> convex = memnew( ConvexPolygonShape );
+ shape_from = co->get_shape_count();
+ for (int i = 0; i < decomp.size(); i++) {
+ Ref<ConvexPolygonShape> convex = memnew(ConvexPolygonShape);
PoolVector<Vector3> cp;
int cs = decomp[i].size();
- cp.resize(cs*2);
+ cp.resize(cs * 2);
{
PoolVector<Vector3>::Write w = cp.write();
- int idx=0;
- for(int j=0;j<cs;j++) {
+ int idx = 0;
+ for (int j = 0; j < cs; j++) {
Vector2 d = decomp[i][j];
- w[idx++]=Vector3(d.x,d.y,depth*0.5);
- w[idx++]=Vector3(d.x,d.y,-depth*0.5);
+ w[idx++] = Vector3(d.x, d.y, depth * 0.5);
+ w[idx++] = Vector3(d.x, d.y, -depth * 0.5);
}
}
convex->set_points(cp);
- co->add_shape(convex,get_transform());
-
+ co->add_shape(convex, get_transform());
}
- shape_to=co->get_shape_count()-1;
- if (shape_to<shape_from) {
- shape_from=-1;
- shape_to=-1;
+ shape_to = co->get_shape_count() - 1;
+ if (shape_to < shape_from) {
+ shape_from = -1;
+ shape_to = -1;
}
} else {
@@ -100,9 +99,7 @@ void CollisionPolygon::_add_to_collision_object(Object *p_obj) {
#endif
}
-
//co->add_shape(shape,get_transform());
-
}
void CollisionPolygon::_update_parent() {
@@ -119,29 +116,28 @@ void CollisionPolygon::_update_parent() {
co->_update_shapes_from_children();
}
-void CollisionPolygon::_set_shape_range(const Vector2& p_range) {
+void CollisionPolygon::_set_shape_range(const Vector2 &p_range) {
- shape_from=p_range.x;
- shape_to=p_range.y;
+ shape_from = p_range.x;
+ shape_to = p_range.y;
}
Vector2 CollisionPolygon::_get_shape_range() const {
- return Vector2(shape_from,shape_to);
+ return Vector2(shape_from, shape_to);
}
void CollisionPolygon::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- can_update_body=get_tree()->is_editor_hint();
+ can_update_body = get_tree()->is_editor_hint();
set_notify_local_transform(!can_update_body);
//indicator_instance = VisualServer::get_singleton()->instance_create2(indicator,get_world()->get_scenario());
} break;
case NOTIFICATION_EXIT_TREE: {
- can_update_body=false;
+ can_update_body = false;
set_notify_local_transform(false);
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -154,12 +150,12 @@ void CollisionPolygon::_notification(int p_what) {
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
- if (!can_update_body && shape_from>=0 && shape_to>=0) {
+ if (!can_update_body && shape_from >= 0 && shape_to >= 0) {
CollisionObject *co = get_parent()->cast_to<CollisionObject>();
if (co) {
- for(int i=shape_from;i<=shape_to;i++) {
- co->set_shape_transform(i,get_transform());
+ for (int i = shape_from; i <= shape_to; i++) {
+ co->set_shape_transform(i, get_transform());
}
}
}
@@ -190,31 +186,29 @@ void CollisionPolygon::_notification(int p_what) {
}
}
-void CollisionPolygon::set_polygon(const Vector<Point2>& p_polygon) {
+void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) {
- polygon=p_polygon;
+ polygon = p_polygon;
if (can_update_body) {
- for(int i=0;i<polygon.size();i++) {
+ for (int i = 0; i < polygon.size(); i++) {
- Vector3 p1(polygon[i].x,polygon[i].y,depth*0.5);
+ Vector3 p1(polygon[i].x, polygon[i].y, depth * 0.5);
- if (i==0)
- aabb=Rect3(p1,Vector3());
+ if (i == 0)
+ aabb = Rect3(p1, Vector3());
else
aabb.expand_to(p1);
- Vector3 p2(polygon[i].x,polygon[i].y,-depth*0.5);
+ Vector3 p2(polygon[i].x, polygon[i].y, -depth * 0.5);
aabb.expand_to(p2);
-
-
}
- if (aabb==Rect3()) {
+ if (aabb == Rect3()) {
- aabb=Rect3(Vector3(-1,-1,-1),Vector3(2,2,2));
+ aabb = Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2));
} else {
- aabb.pos-=aabb.size*0.3;
- aabb.size+=aabb.size*0.6;
+ aabb.pos -= aabb.size * 0.3;
+ aabb.size += aabb.size * 0.6;
}
_update_parent();
}
@@ -228,14 +222,14 @@ Vector<Point2> CollisionPolygon::get_polygon() const {
void CollisionPolygon::set_build_mode(BuildMode p_mode) {
- ERR_FAIL_INDEX(p_mode,2);
- build_mode=p_mode;
+ ERR_FAIL_INDEX(p_mode, 2);
+ build_mode = p_mode;
if (!can_update_body)
return;
_update_parent();
}
-CollisionPolygon::BuildMode CollisionPolygon::get_build_mode() const{
+CollisionPolygon::BuildMode CollisionPolygon::get_build_mode() const {
return build_mode;
}
@@ -247,7 +241,7 @@ Rect3 CollisionPolygon::get_item_rect() const {
void CollisionPolygon::set_depth(float p_depth) {
- depth=p_depth;
+ depth = p_depth;
if (!can_update_body)
return;
_update_parent();
@@ -267,7 +261,6 @@ String CollisionPolygon::get_configuration_warning() const {
if (polygon.empty()) {
return TTR("An empty CollisionPolygon has no effect on collision.");
-
}
return String();
@@ -275,37 +268,36 @@ String CollisionPolygon::get_configuration_warning() const {
void CollisionPolygon::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_add_to_collision_object"),&CollisionPolygon::_add_to_collision_object);
+ ClassDB::bind_method(D_METHOD("_add_to_collision_object"), &CollisionPolygon::_add_to_collision_object);
- ClassDB::bind_method(D_METHOD("set_build_mode","build_mode"),&CollisionPolygon::set_build_mode);
- ClassDB::bind_method(D_METHOD("get_build_mode"),&CollisionPolygon::get_build_mode);
+ ClassDB::bind_method(D_METHOD("set_build_mode", "build_mode"), &CollisionPolygon::set_build_mode);
+ ClassDB::bind_method(D_METHOD("get_build_mode"), &CollisionPolygon::get_build_mode);
- ClassDB::bind_method(D_METHOD("set_depth","depth"),&CollisionPolygon::set_depth);
- ClassDB::bind_method(D_METHOD("get_depth"),&CollisionPolygon::get_depth);
+ ClassDB::bind_method(D_METHOD("set_depth", "depth"), &CollisionPolygon::set_depth);
+ ClassDB::bind_method(D_METHOD("get_depth"), &CollisionPolygon::get_depth);
- ClassDB::bind_method(D_METHOD("set_polygon","polygon"),&CollisionPolygon::set_polygon);
- ClassDB::bind_method(D_METHOD("get_polygon"),&CollisionPolygon::get_polygon);
+ ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon::set_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon::get_polygon);
- ClassDB::bind_method(D_METHOD("_set_shape_range","shape_range"),&CollisionPolygon::_set_shape_range);
- ClassDB::bind_method(D_METHOD("_get_shape_range"),&CollisionPolygon::_get_shape_range);
+ ClassDB::bind_method(D_METHOD("_set_shape_range", "shape_range"), &CollisionPolygon::_set_shape_range);
+ ClassDB::bind_method(D_METHOD("_get_shape_range"), &CollisionPolygon::_get_shape_range);
- ClassDB::bind_method(D_METHOD("get_collision_object_first_shape"),&CollisionPolygon::get_collision_object_first_shape);
- ClassDB::bind_method(D_METHOD("get_collision_object_last_shape"),&CollisionPolygon::get_collision_object_last_shape);
+ ClassDB::bind_method(D_METHOD("get_collision_object_first_shape"), &CollisionPolygon::get_collision_object_first_shape);
+ ClassDB::bind_method(D_METHOD("get_collision_object_last_shape"), &CollisionPolygon::get_collision_object_last_shape);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"build_mode",PROPERTY_HINT_ENUM,"Solids,Triangles"),"set_build_mode","get_build_mode");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"depth"),"set_depth","get_depth");
- ADD_PROPERTY( PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"polygon"),"set_polygon","get_polygon");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"shape_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_shape_range","_get_shape_range");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "build_mode", PROPERTY_HINT_ENUM, "Solids,Triangles"), "set_build_mode", "get_build_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth"), "set_depth", "get_depth");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "shape_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_shape_range", "_get_shape_range");
}
CollisionPolygon::CollisionPolygon() {
- shape_from=-1;
- shape_to=-1;
- can_update_body=false;
-
- aabb=Rect3(Vector3(-1,-1,-1),Vector3(2,2,2));
- build_mode=BUILD_SOLIDS;
- depth=1.0;
+ shape_from = -1;
+ shape_to = -1;
+ can_update_body = false;
+ aabb = Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2));
+ build_mode = BUILD_SOLIDS;
+ depth = 1.0;
}
diff --git a/scene/3d/collision_polygon.h b/scene/3d/collision_polygon.h
index 693cf0640a..fee146a87e 100644
--- a/scene/3d/collision_polygon.h
+++ b/scene/3d/collision_polygon.h
@@ -32,27 +32,22 @@
#include "scene/3d/spatial.h"
#include "scene/resources/shape.h"
-
-
class CollisionPolygon : public Spatial {
- GDCLASS(CollisionPolygon,Spatial);
-public:
+ GDCLASS(CollisionPolygon, Spatial);
+public:
enum BuildMode {
BUILD_SOLIDS,
BUILD_TRIANGLES,
};
protected:
-
-
float depth;
Rect3 aabb;
BuildMode build_mode;
Vector<Point2> polygon;
-
void _add_to_collision_object(Object *p_obj);
void _update_parent();
@@ -60,22 +55,21 @@ protected:
int shape_from;
int shape_to;
- void _set_shape_range(const Vector2& p_range);
+ void _set_shape_range(const Vector2 &p_range);
Vector2 _get_shape_range() const;
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_build_mode(BuildMode p_mode);
BuildMode get_build_mode() const;
void set_depth(float p_depth);
float get_depth() const;
- void set_polygon(const Vector<Point2>& p_polygon);
+ void set_polygon(const Vector<Point2> &p_polygon);
Vector<Point2> get_polygon() const;
virtual Rect3 get_item_rect() const;
@@ -88,5 +82,5 @@ public:
CollisionPolygon();
};
-VARIANT_ENUM_CAST( CollisionPolygon::BuildMode );
+VARIANT_ENUM_CAST(CollisionPolygon::BuildMode);
#endif // COLLISION_POLYGON_H
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index b22795e74d..cb1292a9d1 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -30,180 +30,158 @@
#include "mesh_instance.h"
+void GIProbeData::set_bounds(const Rect3 &p_bounds) {
-void GIProbeData::set_bounds(const Rect3& p_bounds) {
-
- VS::get_singleton()->gi_probe_set_bounds(probe,p_bounds);
+ VS::get_singleton()->gi_probe_set_bounds(probe, p_bounds);
}
-Rect3 GIProbeData::get_bounds() const{
+Rect3 GIProbeData::get_bounds() const {
return VS::get_singleton()->gi_probe_get_bounds(probe);
}
void GIProbeData::set_cell_size(float p_size) {
- VS::get_singleton()->gi_probe_set_cell_size(probe,p_size);
-
+ VS::get_singleton()->gi_probe_set_cell_size(probe, p_size);
}
float GIProbeData::get_cell_size() const {
return VS::get_singleton()->gi_probe_get_cell_size(probe);
-
}
-void GIProbeData::set_to_cell_xform(const Transform& p_xform) {
-
- VS::get_singleton()->gi_probe_set_to_cell_xform(probe,p_xform);
+void GIProbeData::set_to_cell_xform(const Transform &p_xform) {
+ VS::get_singleton()->gi_probe_set_to_cell_xform(probe, p_xform);
}
Transform GIProbeData::get_to_cell_xform() const {
return VS::get_singleton()->gi_probe_get_to_cell_xform(probe);
-
}
+void GIProbeData::set_dynamic_data(const PoolVector<int> &p_data) {
-void GIProbeData::set_dynamic_data(const PoolVector<int>& p_data){
-
- VS::get_singleton()->gi_probe_set_dynamic_data(probe,p_data);
-
+ VS::get_singleton()->gi_probe_set_dynamic_data(probe, p_data);
}
-PoolVector<int> GIProbeData::get_dynamic_data() const{
+PoolVector<int> GIProbeData::get_dynamic_data() const {
return VS::get_singleton()->gi_probe_get_dynamic_data(probe);
}
-void GIProbeData::set_dynamic_range(int p_range){
-
- VS::get_singleton()->gi_probe_set_dynamic_range(probe,p_range);
+void GIProbeData::set_dynamic_range(int p_range) {
+ VS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range);
}
void GIProbeData::set_energy(float p_range) {
- VS::get_singleton()->gi_probe_set_energy(probe,p_range);
+ VS::get_singleton()->gi_probe_set_energy(probe, p_range);
}
-float GIProbeData::get_energy() const{
+float GIProbeData::get_energy() const {
return VS::get_singleton()->gi_probe_get_energy(probe);
-
}
-
void GIProbeData::set_bias(float p_range) {
- VS::get_singleton()->gi_probe_set_bias(probe,p_range);
+ VS::get_singleton()->gi_probe_set_bias(probe, p_range);
}
-float GIProbeData::get_bias() const{
+float GIProbeData::get_bias() const {
return VS::get_singleton()->gi_probe_get_bias(probe);
-
}
-
void GIProbeData::set_propagation(float p_range) {
- VS::get_singleton()->gi_probe_set_propagation(probe,p_range);
+ VS::get_singleton()->gi_probe_set_propagation(probe, p_range);
}
-float GIProbeData::get_propagation() const{
+float GIProbeData::get_propagation() const {
return VS::get_singleton()->gi_probe_get_propagation(probe);
-
}
-
void GIProbeData::set_interior(bool p_enable) {
- VS::get_singleton()->gi_probe_set_interior(probe,p_enable);
-
+ VS::get_singleton()->gi_probe_set_interior(probe, p_enable);
}
-bool GIProbeData::is_interior() const{
+bool GIProbeData::is_interior() const {
return VS::get_singleton()->gi_probe_is_interior(probe);
}
-
-bool GIProbeData::is_compressed() const{
+bool GIProbeData::is_compressed() const {
return VS::get_singleton()->gi_probe_is_compressed(probe);
}
-
void GIProbeData::set_compress(bool p_enable) {
- VS::get_singleton()->gi_probe_set_compress(probe,p_enable);
-
+ VS::get_singleton()->gi_probe_set_compress(probe, p_enable);
}
-int GIProbeData::get_dynamic_range() const{
-
+int GIProbeData::get_dynamic_range() const {
return VS::get_singleton()->gi_probe_get_dynamic_range(probe);
}
-
RID GIProbeData::get_rid() const {
return probe;
}
-
void GIProbeData::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_bounds","bounds"),&GIProbeData::set_bounds);
- ClassDB::bind_method(D_METHOD("get_bounds"),&GIProbeData::get_bounds);
+ ClassDB::bind_method(D_METHOD("set_bounds", "bounds"), &GIProbeData::set_bounds);
+ ClassDB::bind_method(D_METHOD("get_bounds"), &GIProbeData::get_bounds);
- ClassDB::bind_method(D_METHOD("set_cell_size","cell_size"),&GIProbeData::set_cell_size);
- ClassDB::bind_method(D_METHOD("get_cell_size"),&GIProbeData::get_cell_size);
+ ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &GIProbeData::set_cell_size);
+ ClassDB::bind_method(D_METHOD("get_cell_size"), &GIProbeData::get_cell_size);
- ClassDB::bind_method(D_METHOD("set_to_cell_xform","to_cell_xform"),&GIProbeData::set_to_cell_xform);
- ClassDB::bind_method(D_METHOD("get_to_cell_xform"),&GIProbeData::get_to_cell_xform);
+ ClassDB::bind_method(D_METHOD("set_to_cell_xform", "to_cell_xform"), &GIProbeData::set_to_cell_xform);
+ ClassDB::bind_method(D_METHOD("get_to_cell_xform"), &GIProbeData::get_to_cell_xform);
- ClassDB::bind_method(D_METHOD("set_dynamic_data","dynamic_data"),&GIProbeData::set_dynamic_data);
- ClassDB::bind_method(D_METHOD("get_dynamic_data"),&GIProbeData::get_dynamic_data);
+ ClassDB::bind_method(D_METHOD("set_dynamic_data", "dynamic_data"), &GIProbeData::set_dynamic_data);
+ ClassDB::bind_method(D_METHOD("get_dynamic_data"), &GIProbeData::get_dynamic_data);
- ClassDB::bind_method(D_METHOD("set_dynamic_range","dynamic_range"),&GIProbeData::set_dynamic_range);
- ClassDB::bind_method(D_METHOD("get_dynamic_range"),&GIProbeData::get_dynamic_range);
+ ClassDB::bind_method(D_METHOD("set_dynamic_range", "dynamic_range"), &GIProbeData::set_dynamic_range);
+ ClassDB::bind_method(D_METHOD("get_dynamic_range"), &GIProbeData::get_dynamic_range);
- ClassDB::bind_method(D_METHOD("set_energy","energy"),&GIProbeData::set_energy);
- ClassDB::bind_method(D_METHOD("get_energy"),&GIProbeData::get_energy);
+ ClassDB::bind_method(D_METHOD("set_energy", "energy"), &GIProbeData::set_energy);
+ ClassDB::bind_method(D_METHOD("get_energy"), &GIProbeData::get_energy);
- ClassDB::bind_method(D_METHOD("set_bias","bias"),&GIProbeData::set_bias);
- ClassDB::bind_method(D_METHOD("get_bias"),&GIProbeData::get_bias);
+ ClassDB::bind_method(D_METHOD("set_bias", "bias"), &GIProbeData::set_bias);
+ ClassDB::bind_method(D_METHOD("get_bias"), &GIProbeData::get_bias);
- ClassDB::bind_method(D_METHOD("set_propagation","propagation"),&GIProbeData::set_propagation);
- ClassDB::bind_method(D_METHOD("get_propagation"),&GIProbeData::get_propagation);
+ ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &GIProbeData::set_propagation);
+ ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbeData::get_propagation);
- ClassDB::bind_method(D_METHOD("set_interior","interior"),&GIProbeData::set_interior);
- ClassDB::bind_method(D_METHOD("is_interior"),&GIProbeData::is_interior);
+ ClassDB::bind_method(D_METHOD("set_interior", "interior"), &GIProbeData::set_interior);
+ ClassDB::bind_method(D_METHOD("is_interior"), &GIProbeData::is_interior);
- ClassDB::bind_method(D_METHOD("set_compress","compress"),&GIProbeData::set_compress);
- ClassDB::bind_method(D_METHOD("is_compressed"),&GIProbeData::is_compressed);
+ ClassDB::bind_method(D_METHOD("set_compress", "compress"), &GIProbeData::set_compress);
+ ClassDB::bind_method(D_METHOD("is_compressed"), &GIProbeData::is_compressed);
- ADD_PROPERTY(PropertyInfo(Variant::RECT3,"bounds",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_bounds","get_bounds");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"cell_size",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_cell_size","get_cell_size");
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM,"to_cell_xform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_to_cell_xform","get_to_cell_xform");
-
- ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY,"dynamic_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_dynamic_data","get_dynamic_data");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_dynamic_range","get_dynamic_range");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_energy","get_energy");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"bias",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_bias","get_bias");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_propagation","get_propagation");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"interior",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_interior","is_interior");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"compress",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_compress","is_compressed");
+ ADD_PROPERTY(PropertyInfo(Variant::RECT3, "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bounds", "get_bounds");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_size", "get_cell_size");
+ ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "to_cell_xform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_to_cell_xform", "get_to_cell_xform");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "dynamic_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_dynamic_data", "get_dynamic_data");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_dynamic_range", "get_dynamic_range");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_energy", "get_energy");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bias", "get_bias");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_propagation", "get_propagation");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_interior", "is_interior");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_compress", "is_compressed");
}
GIProbeData::GIProbeData() {
- probe=VS::get_singleton()->gi_probe_create();
+ probe = VS::get_singleton()->gi_probe_create();
}
GIProbeData::~GIProbeData() {
@@ -211,20 +189,18 @@ GIProbeData::~GIProbeData() {
VS::get_singleton()->free(probe);
}
-
//////////////////////
//////////////////////
-
-void GIProbe::set_probe_data(const Ref<GIProbeData>& p_data) {
+void GIProbe::set_probe_data(const Ref<GIProbeData> &p_data) {
if (p_data.is_valid()) {
- VS::get_singleton()->instance_set_base(get_instance(),p_data->get_rid());
+ VS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid());
} else {
- VS::get_singleton()->instance_set_base(get_instance(),RID());
+ VS::get_singleton()->instance_set_base(get_instance(), RID());
}
- probe_data=p_data;
+ probe_data = p_data;
}
Ref<GIProbeData> GIProbe::get_probe_data() const {
@@ -234,8 +210,8 @@ Ref<GIProbeData> GIProbe::get_probe_data() const {
void GIProbe::set_subdiv(Subdiv p_subdiv) {
- ERR_FAIL_INDEX(p_subdiv,SUBDIV_MAX);
- subdiv=p_subdiv;
+ ERR_FAIL_INDEX(p_subdiv, SUBDIV_MAX);
+ subdiv = p_subdiv;
update_gizmo();
}
@@ -244,9 +220,9 @@ GIProbe::Subdiv GIProbe::get_subdiv() const {
return subdiv;
}
-void GIProbe::set_extents(const Vector3& p_extents) {
+void GIProbe::set_extents(const Vector3 &p_extents) {
- extents=p_extents;
+ extents = p_extents;
update_gizmo();
}
@@ -257,7 +233,7 @@ Vector3 GIProbe::get_extents() const {
void GIProbe::set_dynamic_range(int p_dynamic_range) {
- dynamic_range=p_dynamic_range;
+ dynamic_range = p_dynamic_range;
}
int GIProbe::get_dynamic_range() const {
@@ -266,7 +242,7 @@ int GIProbe::get_dynamic_range() const {
void GIProbe::set_energy(float p_energy) {
- energy=p_energy;
+ energy = p_energy;
if (probe_data.is_valid()) {
probe_data->set_energy(energy);
}
@@ -278,7 +254,7 @@ float GIProbe::get_energy() const {
void GIProbe::set_bias(float p_bias) {
- bias=p_bias;
+ bias = p_bias;
if (probe_data.is_valid()) {
probe_data->set_bias(bias);
}
@@ -290,7 +266,7 @@ float GIProbe::get_bias() const {
void GIProbe::set_propagation(float p_propagation) {
- propagation=p_propagation;
+ propagation = p_propagation;
if (probe_data.is_valid()) {
probe_data->set_propagation(propagation);
}
@@ -302,7 +278,7 @@ float GIProbe::get_propagation() const {
void GIProbe::set_interior(bool p_enable) {
- interior=p_enable;
+ interior = p_enable;
if (probe_data.is_valid()) {
probe_data->set_interior(p_enable);
}
@@ -313,10 +289,9 @@ bool GIProbe::is_interior() const {
return interior;
}
-
void GIProbe::set_compress(bool p_enable) {
- compress=p_enable;
+ compress = p_enable;
if (probe_data.is_valid()) {
probe_data->set_compress(p_enable);
}
@@ -327,263 +302,287 @@ bool GIProbe::is_compressed() const {
return compress;
}
-
#include "math.h"
-#define FINDMINMAX(x0,x1,x2,min,max) \
- min = max = x0; \
- if(x1<min) min=x1;\
- if(x1>max) max=x1;\
- if(x2<min) min=x2;\
- if(x2>max) max=x2;
-
-static bool planeBoxOverlap(Vector3 normal,float d, Vector3 maxbox)
-{
- int q;
- Vector3 vmin,vmax;
- for(q=0;q<=2;q++)
- {
- if(normal[q]>0.0f)
- {
- vmin[q]=-maxbox[q];
- vmax[q]=maxbox[q];
- }
- else
- {
- vmin[q]=maxbox[q];
- vmax[q]=-maxbox[q];
- }
- }
- if(normal.dot(vmin)+d>0.0f) return false;
- if(normal.dot(vmax)+d>=0.0f) return true;
-
- return false;
-}
+#define FINDMINMAX(x0, x1, x2, min, max) \
+ min = max = x0; \
+ if (x1 < min) min = x1; \
+ if (x1 > max) max = x1; \
+ if (x2 < min) min = x2; \
+ if (x2 > max) max = x2;
+
+static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) {
+ int q;
+ Vector3 vmin, vmax;
+ for (q = 0; q <= 2; q++) {
+ if (normal[q] > 0.0f) {
+ vmin[q] = -maxbox[q];
+ vmax[q] = maxbox[q];
+ } else {
+ vmin[q] = maxbox[q];
+ vmax[q] = -maxbox[q];
+ }
+ }
+ if (normal.dot(vmin) + d > 0.0f) return false;
+ if (normal.dot(vmax) + d >= 0.0f) return true;
+ return false;
+}
/*======================== X-tests ========================*/
-#define AXISTEST_X01(a, b, fa, fb) \
- p0 = a*v0.y - b*v0.z; \
- p2 = a*v2.y - b*v2.z; \
- if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} \
- rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
-
-#define AXISTEST_X2(a, b, fa, fb) \
- p0 = a*v0.y - b*v0.z; \
- p1 = a*v1.y - b*v1.z; \
- if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} \
- rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
+#define AXISTEST_X01(a, b, fa, fb) \
+ p0 = a * v0.y - b * v0.z; \
+ p2 = a * v2.y - b * v2.z; \
+ if (p0 < p2) { \
+ min = p0; \
+ max = p2; \
+ } else { \
+ min = p2; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
+
+#define AXISTEST_X2(a, b, fa, fb) \
+ p0 = a * v0.y - b * v0.z; \
+ p1 = a * v1.y - b * v1.z; \
+ if (p0 < p1) { \
+ min = p0; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
/*======================== Y-tests ========================*/
-#define AXISTEST_Y02(a, b, fa, fb) \
- p0 = -a*v0.x + b*v0.z; \
- p2 = -a*v2.x + b*v2.z; \
- if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
-
-#define AXISTEST_Y1(a, b, fa, fb) \
- p0 = -a*v0.x + b*v0.z; \
- p1 = -a*v1.x + b*v1.z; \
- if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if(min>rad || max<-rad) return false;
+#define AXISTEST_Y02(a, b, fa, fb) \
+ p0 = -a * v0.x + b * v0.z; \
+ p2 = -a * v2.x + b * v2.z; \
+ if (p0 < p2) { \
+ min = p0; \
+ max = p2; \
+ } else { \
+ min = p2; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
+
+#define AXISTEST_Y1(a, b, fa, fb) \
+ p0 = -a * v0.x + b * v0.z; \
+ p1 = -a * v1.x + b * v1.z; \
+ if (p0 < p1) { \
+ min = p0; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
+ if (min > rad || max < -rad) return false;
/*======================== Z-tests ========================*/
-#define AXISTEST_Z12(a, b, fa, fb) \
- p1 = a*v1.x - b*v1.y; \
- p2 = a*v2.x - b*v2.y; \
- if(p2<p1) {min=p2; max=p1;} else {min=p1; max=p2;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if(min>rad || max<-rad) return false;
-
-#define AXISTEST_Z0(a, b, fa, fb) \
- p0 = a*v0.x - b*v0.y; \
- p1 = a*v1.x - b*v1.y; \
- if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if(min>rad || max<-rad) return false;
-
-static bool fast_tri_box_overlap(const Vector3& boxcenter,const Vector3 boxhalfsize,const Vector3 *triverts) {
-
- /* use separating axis theorem to test overlap between triangle and box */
- /* need to test for overlap in these directions: */
- /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
- /* we do not even need to test these) */
- /* 2) normal of the triangle */
- /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
- /* this gives 3x3=9 more tests */
- Vector3 v0,v1,v2;
- float min,max,d,p0,p1,p2,rad,fex,fey,fez;
- Vector3 normal,e0,e1,e2;
-
- /* This is the fastest branch on Sun */
- /* move everything so that the boxcenter is in (0,0,0) */
-
- v0=triverts[0]-boxcenter;
- v1=triverts[1]-boxcenter;
- v2=triverts[2]-boxcenter;
-
- /* compute triangle edges */
- e0=v1-v0; /* tri edge 0 */
- e1=v2-v1; /* tri edge 1 */
- e2=v0-v2; /* tri edge 2 */
-
- /* Bullet 3: */
- /* test the 9 tests first (this was faster) */
- fex = Math::abs(e0.x);
- fey = Math::abs(e0.y);
- fez = Math::abs(e0.z);
- AXISTEST_X01(e0.z, e0.y, fez, fey);
- AXISTEST_Y02(e0.z, e0.x, fez, fex);
- AXISTEST_Z12(e0.y, e0.x, fey, fex);
-
- fex = Math::abs(e1.x);
- fey = Math::abs(e1.y);
- fez = Math::abs(e1.z);
- AXISTEST_X01(e1.z, e1.y, fez, fey);
- AXISTEST_Y02(e1.z, e1.x, fez, fex);
- AXISTEST_Z0(e1.y, e1.x, fey, fex);
-
- fex = Math::abs(e2.x);
- fey = Math::abs(e2.y);
- fez = Math::abs(e2.z);
- AXISTEST_X2(e2.z, e2.y, fez, fey);
- AXISTEST_Y1(e2.z, e2.x, fez, fex);
- AXISTEST_Z12(e2.y, e2.x, fey, fex);
-
- /* Bullet 1: */
- /* first test overlap in the {x,y,z}-directions */
- /* find min, max of the triangle each direction, and test for overlap in */
- /* that direction -- this is equivalent to testing a minimal AABB around */
- /* the triangle against the AABB */
-
- /* test in X-direction */
- FINDMINMAX(v0.x,v1.x,v2.x,min,max);
- if(min>boxhalfsize.x || max<-boxhalfsize.x) return false;
-
- /* test in Y-direction */
- FINDMINMAX(v0.y,v1.y,v2.y,min,max);
- if(min>boxhalfsize.y || max<-boxhalfsize.y) return false;
-
- /* test in Z-direction */
- FINDMINMAX(v0.z,v1.z,v2.z,min,max);
- if(min>boxhalfsize.z || max<-boxhalfsize.z) return false;
-
- /* Bullet 2: */
- /* test if the box intersects the plane of the triangle */
- /* compute plane equation of triangle: normal*x+d=0 */
- normal=e0.cross(e1);
- d=-normal.dot(v0); /* plane eq: normal.x+d=0 */
- if(!planeBoxOverlap(normal,d,boxhalfsize)) return false;
-
- return true; /* box and triangle overlaps */
+#define AXISTEST_Z12(a, b, fa, fb) \
+ p1 = a * v1.x - b * v1.y; \
+ p2 = a * v2.x - b * v2.y; \
+ if (p2 < p1) { \
+ min = p2; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p2; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
+ if (min > rad || max < -rad) return false;
+
+#define AXISTEST_Z0(a, b, fa, fb) \
+ p0 = a * v0.x - b * v0.y; \
+ p1 = a * v1.x - b * v1.y; \
+ if (p0 < p1) { \
+ min = p0; \
+ max = p1; \
+ } else { \
+ min = p1; \
+ max = p0; \
+ } \
+ rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
+ if (min > rad || max < -rad) return false;
+
+static bool fast_tri_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) {
+
+ /* use separating axis theorem to test overlap between triangle and box */
+ /* need to test for overlap in these directions: */
+ /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
+ /* we do not even need to test these) */
+ /* 2) normal of the triangle */
+ /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
+ /* this gives 3x3=9 more tests */
+ Vector3 v0, v1, v2;
+ float min, max, d, p0, p1, p2, rad, fex, fey, fez;
+ Vector3 normal, e0, e1, e2;
+
+ /* This is the fastest branch on Sun */
+ /* move everything so that the boxcenter is in (0,0,0) */
+
+ v0 = triverts[0] - boxcenter;
+ v1 = triverts[1] - boxcenter;
+ v2 = triverts[2] - boxcenter;
+
+ /* compute triangle edges */
+ e0 = v1 - v0; /* tri edge 0 */
+ e1 = v2 - v1; /* tri edge 1 */
+ e2 = v0 - v2; /* tri edge 2 */
+
+ /* Bullet 3: */
+ /* test the 9 tests first (this was faster) */
+ fex = Math::abs(e0.x);
+ fey = Math::abs(e0.y);
+ fez = Math::abs(e0.z);
+ AXISTEST_X01(e0.z, e0.y, fez, fey);
+ AXISTEST_Y02(e0.z, e0.x, fez, fex);
+ AXISTEST_Z12(e0.y, e0.x, fey, fex);
+
+ fex = Math::abs(e1.x);
+ fey = Math::abs(e1.y);
+ fez = Math::abs(e1.z);
+ AXISTEST_X01(e1.z, e1.y, fez, fey);
+ AXISTEST_Y02(e1.z, e1.x, fez, fex);
+ AXISTEST_Z0(e1.y, e1.x, fey, fex);
+
+ fex = Math::abs(e2.x);
+ fey = Math::abs(e2.y);
+ fez = Math::abs(e2.z);
+ AXISTEST_X2(e2.z, e2.y, fez, fey);
+ AXISTEST_Y1(e2.z, e2.x, fez, fex);
+ AXISTEST_Z12(e2.y, e2.x, fey, fex);
+
+ /* Bullet 1: */
+ /* first test overlap in the {x,y,z}-directions */
+ /* find min, max of the triangle each direction, and test for overlap in */
+ /* that direction -- this is equivalent to testing a minimal AABB around */
+ /* the triangle against the AABB */
+
+ /* test in X-direction */
+ FINDMINMAX(v0.x, v1.x, v2.x, min, max);
+ if (min > boxhalfsize.x || max < -boxhalfsize.x) return false;
+
+ /* test in Y-direction */
+ FINDMINMAX(v0.y, v1.y, v2.y, min, max);
+ if (min > boxhalfsize.y || max < -boxhalfsize.y) return false;
+
+ /* test in Z-direction */
+ FINDMINMAX(v0.z, v1.z, v2.z, min, max);
+ if (min > boxhalfsize.z || max < -boxhalfsize.z) return false;
+
+ /* Bullet 2: */
+ /* test if the box intersects the plane of the triangle */
+ /* compute plane equation of triangle: normal*x+d=0 */
+ normal = e0.cross(e1);
+ d = -normal.dot(v0); /* plane eq: normal.x+d=0 */
+ if (!planeBoxOverlap(normal, d, boxhalfsize)) return false;
+
+ return true; /* box and triangle overlaps */
}
+static _FORCE_INLINE_ Vector2 get_uv(const Vector3 &p_pos, const Vector3 *p_vtx, const Vector2 *p_uv) {
-
-static _FORCE_INLINE_ Vector2 get_uv(const Vector3& p_pos, const Vector3 *p_vtx, const Vector2* p_uv) {
-
- if (p_pos.distance_squared_to(p_vtx[0])<CMP_EPSILON2)
+ if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2)
return p_uv[0];
- if (p_pos.distance_squared_to(p_vtx[1])<CMP_EPSILON2)
+ if (p_pos.distance_squared_to(p_vtx[1]) < CMP_EPSILON2)
return p_uv[1];
- if (p_pos.distance_squared_to(p_vtx[2])<CMP_EPSILON2)
+ if (p_pos.distance_squared_to(p_vtx[2]) < CMP_EPSILON2)
return p_uv[2];
Vector3 v0 = p_vtx[1] - p_vtx[0];
Vector3 v1 = p_vtx[2] - p_vtx[0];
Vector3 v2 = p_pos - p_vtx[0];
- float d00 = v0.dot( v0);
- float d01 = v0.dot( v1);
- float d11 = v1.dot( v1);
- float d20 = v2.dot( v0);
- float d21 = v2.dot( v1);
+ float d00 = v0.dot(v0);
+ float d01 = v0.dot(v1);
+ float d11 = v1.dot(v1);
+ float d20 = v2.dot(v0);
+ float d21 = v2.dot(v1);
float denom = (d00 * d11 - d01 * d01);
- if (denom==0)
+ if (denom == 0)
return p_uv[0];
float v = (d11 * d20 - d01 * d21) / denom;
float w = (d00 * d21 - d01 * d20) / denom;
float u = 1.0f - v - w;
- return p_uv[0]*u + p_uv[1]*v + p_uv[2]*w;
+ return p_uv[0] * u + p_uv[1] * v + p_uv[2] * w;
}
-void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const Vector3 *p_vtx, const Vector2* p_uv, const Baker::MaterialCache& p_material, const Rect3 &p_aabb,Baker *p_baker) {
-
-
+void GIProbe::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const Baker::MaterialCache &p_material, const Rect3 &p_aabb, Baker *p_baker) {
- if (p_level==p_baker->cell_subdiv-1) {
+ if (p_level == p_baker->cell_subdiv - 1) {
//plot the face by guessing it's albedo and emission value
//find best axis to map to, for scanning values
int closest_axis;
float closest_dot;
- Plane plane = Plane(p_vtx[0],p_vtx[1],p_vtx[2]);
+ Plane plane = Plane(p_vtx[0], p_vtx[1], p_vtx[2]);
Vector3 normal = plane.normal;
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
Vector3 axis;
- axis[i]=1.0;
- float dot=ABS(normal.dot(axis));
- if (i==0 || dot>closest_dot) {
- closest_axis=i;
- closest_dot=dot;
+ axis[i] = 1.0;
+ float dot = ABS(normal.dot(axis));
+ if (i == 0 || dot > closest_dot) {
+ closest_axis = i;
+ closest_dot = dot;
}
}
-
Vector3 axis;
- axis[closest_axis]=1.0;
+ axis[closest_axis] = 1.0;
Vector3 t1;
- t1[(closest_axis+1)%3]=1.0;
+ t1[(closest_axis + 1) % 3] = 1.0;
Vector3 t2;
- t2[(closest_axis+2)%3]=1.0;
+ t2[(closest_axis + 2) % 3] = 1.0;
- t1*=p_aabb.size[(closest_axis+1)%3]/float(color_scan_cell_width);
- t2*=p_aabb.size[(closest_axis+2)%3]/float(color_scan_cell_width);
+ t1 *= p_aabb.size[(closest_axis + 1) % 3] / float(color_scan_cell_width);
+ t2 *= p_aabb.size[(closest_axis + 2) % 3] / float(color_scan_cell_width);
Color albedo_accum;
Color emission_accum;
Vector3 normal_accum;
- float alpha=0.0;
+ float alpha = 0.0;
//map to a grid average in the best axis for this face
- for(int i=0;i<color_scan_cell_width;i++) {
+ for (int i = 0; i < color_scan_cell_width; i++) {
- Vector3 ofs_i=float(i)*t1;
+ Vector3 ofs_i = float(i) * t1;
- for(int j=0;j<color_scan_cell_width;j++) {
+ for (int j = 0; j < color_scan_cell_width; j++) {
- Vector3 ofs_j=float(j)*t2;
+ Vector3 ofs_j = float(j) * t2;
- Vector3 from = p_aabb.pos+ofs_i+ofs_j;
+ Vector3 from = p_aabb.pos + ofs_i + ofs_j;
Vector3 to = from + t1 + t2 + axis * p_aabb.size[closest_axis];
- Vector3 half = (to-from)*0.5;
+ Vector3 half = (to - from) * 0.5;
//is in this cell?
- if (!fast_tri_box_overlap(from+half,half,p_vtx)) {
+ if (!fast_tri_box_overlap(from + half, half, p_vtx)) {
continue; //face does not span this cell
}
//go from -size to +size*2 to avoid skipping collisions
- Vector3 ray_from = from + (t1+t2)*0.5 - axis * p_aabb.size[closest_axis];
- Vector3 ray_to = ray_from + axis * p_aabb.size[closest_axis]*2;
+ Vector3 ray_from = from + (t1 + t2) * 0.5 - axis * p_aabb.size[closest_axis];
+ Vector3 ray_to = ray_from + axis * p_aabb.size[closest_axis] * 2;
- if (normal.dot(ray_from-ray_to)<0) {
- SWAP(ray_from,ray_to);
+ if (normal.dot(ray_from - ray_to) < 0) {
+ SWAP(ray_from, ray_to);
}
Vector3 intersection;
- if (!plane.intersects_segment(ray_from,ray_to,&intersection)) {
+ if (!plane.intersects_segment(ray_from, ray_to, &intersection)) {
if (ABS(plane.distance_to(ray_from)) < ABS(plane.distance_to(ray_to))) {
intersection = plane.project(ray_from);
} else {
@@ -592,96 +591,91 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V
}
}
- intersection=Face3(p_vtx[0],p_vtx[1],p_vtx[2]).get_closest_point_to(intersection);
-
- Vector2 uv = get_uv(intersection,p_vtx,p_uv);
+ intersection = Face3(p_vtx[0], p_vtx[1], p_vtx[2]).get_closest_point_to(intersection);
+ Vector2 uv = get_uv(intersection, p_vtx, p_uv);
- int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
- int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
+ int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
+ int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
- int ofs = uv_y*bake_texture_size+uv_x;
- albedo_accum.r+=p_material.albedo[ofs].r;
- albedo_accum.g+=p_material.albedo[ofs].g;
- albedo_accum.b+=p_material.albedo[ofs].b;
- albedo_accum.a+=p_material.albedo[ofs].a;
+ int ofs = uv_y * bake_texture_size + uv_x;
+ albedo_accum.r += p_material.albedo[ofs].r;
+ albedo_accum.g += p_material.albedo[ofs].g;
+ albedo_accum.b += p_material.albedo[ofs].b;
+ albedo_accum.a += p_material.albedo[ofs].a;
- emission_accum.r+=p_material.emission[ofs].r;
- emission_accum.g+=p_material.emission[ofs].g;
- emission_accum.b+=p_material.emission[ofs].b;
+ emission_accum.r += p_material.emission[ofs].r;
+ emission_accum.g += p_material.emission[ofs].g;
+ emission_accum.b += p_material.emission[ofs].b;
- normal_accum+=normal;
-
- alpha+=1.0;
+ normal_accum += normal;
+ alpha += 1.0;
}
}
-
- if (alpha==0) {
+ if (alpha == 0) {
//could not in any way get texture information.. so use closest point to center
- Face3 f( p_vtx[0],p_vtx[1],p_vtx[2]);
- Vector3 inters = f.get_closest_point_to(p_aabb.pos+p_aabb.size*0.5);
+ Face3 f(p_vtx[0], p_vtx[1], p_vtx[2]);
+ Vector3 inters = f.get_closest_point_to(p_aabb.pos + p_aabb.size * 0.5);
- Vector2 uv = get_uv(inters,p_vtx,p_uv);
+ Vector2 uv = get_uv(inters, p_vtx, p_uv);
- int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
- int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
+ int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
+ int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
- int ofs = uv_y*bake_texture_size+uv_x;
+ int ofs = uv_y * bake_texture_size + uv_x;
- alpha = 1.0/(color_scan_cell_width*color_scan_cell_width);
+ alpha = 1.0 / (color_scan_cell_width * color_scan_cell_width);
- albedo_accum.r=p_material.albedo[ofs].r*alpha;
- albedo_accum.g=p_material.albedo[ofs].g*alpha;
- albedo_accum.b=p_material.albedo[ofs].b*alpha;
- albedo_accum.a=p_material.albedo[ofs].a*alpha;
+ albedo_accum.r = p_material.albedo[ofs].r * alpha;
+ albedo_accum.g = p_material.albedo[ofs].g * alpha;
+ albedo_accum.b = p_material.albedo[ofs].b * alpha;
+ albedo_accum.a = p_material.albedo[ofs].a * alpha;
- emission_accum.r=p_material.emission[ofs].r*alpha;
- emission_accum.g=p_material.emission[ofs].g*alpha;
- emission_accum.b=p_material.emission[ofs].b*alpha;
-
- normal_accum*=alpha;
+ emission_accum.r = p_material.emission[ofs].r * alpha;
+ emission_accum.g = p_material.emission[ofs].g * alpha;
+ emission_accum.b = p_material.emission[ofs].b * alpha;
+ normal_accum *= alpha;
} else {
- float accdiv = 1.0/(color_scan_cell_width*color_scan_cell_width);
- alpha*=accdiv;
-
- albedo_accum.r*=accdiv;
- albedo_accum.g*=accdiv;
- albedo_accum.b*=accdiv;
- albedo_accum.a*=accdiv;
+ float accdiv = 1.0 / (color_scan_cell_width * color_scan_cell_width);
+ alpha *= accdiv;
- emission_accum.r*=accdiv;
- emission_accum.g*=accdiv;
- emission_accum.b*=accdiv;
+ albedo_accum.r *= accdiv;
+ albedo_accum.g *= accdiv;
+ albedo_accum.b *= accdiv;
+ albedo_accum.a *= accdiv;
- normal_accum*=accdiv;
+ emission_accum.r *= accdiv;
+ emission_accum.g *= accdiv;
+ emission_accum.b *= accdiv;
+ normal_accum *= accdiv;
}
//put this temporarily here, corrected in a later step
- p_baker->bake_cells[p_idx].albedo[0]+=albedo_accum.r;
- p_baker->bake_cells[p_idx].albedo[1]+=albedo_accum.g;
- p_baker->bake_cells[p_idx].albedo[2]+=albedo_accum.b;
- p_baker->bake_cells[p_idx].emission[0]+=emission_accum.r;
- p_baker->bake_cells[p_idx].emission[1]+=emission_accum.g;
- p_baker->bake_cells[p_idx].emission[2]+=emission_accum.b;
- p_baker->bake_cells[p_idx].normal[0]+=normal_accum.x;
- p_baker->bake_cells[p_idx].normal[1]+=normal_accum.y;
- p_baker->bake_cells[p_idx].normal[2]+=normal_accum.z;
- p_baker->bake_cells[p_idx].alpha+=alpha;
-
- static const Vector3 side_normals[6]={
+ p_baker->bake_cells[p_idx].albedo[0] += albedo_accum.r;
+ p_baker->bake_cells[p_idx].albedo[1] += albedo_accum.g;
+ p_baker->bake_cells[p_idx].albedo[2] += albedo_accum.b;
+ p_baker->bake_cells[p_idx].emission[0] += emission_accum.r;
+ p_baker->bake_cells[p_idx].emission[1] += emission_accum.g;
+ p_baker->bake_cells[p_idx].emission[2] += emission_accum.b;
+ p_baker->bake_cells[p_idx].normal[0] += normal_accum.x;
+ p_baker->bake_cells[p_idx].normal[1] += normal_accum.y;
+ p_baker->bake_cells[p_idx].normal[2] += normal_accum.z;
+ p_baker->bake_cells[p_idx].alpha += alpha;
+
+ static const Vector3 side_normals[6] = {
Vector3(-1, 0, 0),
- Vector3( 1, 0, 0),
- Vector3( 0,-1, 0),
- Vector3( 0, 1, 0),
- Vector3( 0, 0,-1),
- Vector3( 0, 0, 1),
+ Vector3(1, 0, 0),
+ Vector3(0, -1, 0),
+ Vector3(0, 1, 0),
+ Vector3(0, 0, -1),
+ Vector3(0, 0, 1),
};
/*
@@ -691,104 +685,95 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V
}
}*/
-
} else {
//go down
- int half = (1<<(p_baker->cell_subdiv-1)) >> (p_level+1);
- for(int i=0;i<8;i++) {
+ int half = (1 << (p_baker->cell_subdiv - 1)) >> (p_level + 1);
+ for (int i = 0; i < 8; i++) {
- Rect3 aabb=p_aabb;
- aabb.size*=0.5;
+ Rect3 aabb = p_aabb;
+ aabb.size *= 0.5;
- int nx=p_x;
- int ny=p_y;
- int nz=p_z;
+ int nx = p_x;
+ int ny = p_y;
+ int nz = p_z;
- if (i&1) {
- aabb.pos.x+=aabb.size.x;
- nx+=half;
+ if (i & 1) {
+ aabb.pos.x += aabb.size.x;
+ nx += half;
}
- if (i&2) {
- aabb.pos.y+=aabb.size.y;
- ny+=half;
+ if (i & 2) {
+ aabb.pos.y += aabb.size.y;
+ ny += half;
}
- if (i&4) {
- aabb.pos.z+=aabb.size.z;
- nz+=half;
+ if (i & 4) {
+ aabb.pos.z += aabb.size.z;
+ nz += half;
}
//make sure to not plot beyond limits
- if (nx<0 || nx>=p_baker->axis_cell_size[0] || ny<0 || ny>=p_baker->axis_cell_size[1] || nz<0 || nz>=p_baker->axis_cell_size[2])
+ if (nx < 0 || nx >= p_baker->axis_cell_size[0] || ny < 0 || ny >= p_baker->axis_cell_size[1] || nz < 0 || nz >= p_baker->axis_cell_size[2])
continue;
{
- Rect3 test_aabb=aabb;
+ Rect3 test_aabb = aabb;
//test_aabb.grow_by(test_aabb.get_longest_axis_size()*0.05); //grow a bit to avoid numerical error in real-time
- Vector3 qsize = test_aabb.size*0.5; //quarter size, for fast aabb test
+ Vector3 qsize = test_aabb.size * 0.5; //quarter size, for fast aabb test
- if (!fast_tri_box_overlap(test_aabb.pos+qsize,qsize,p_vtx)) {
- //if (!Face3(p_vtx[0],p_vtx[1],p_vtx[2]).intersects_aabb2(aabb)) {
+ if (!fast_tri_box_overlap(test_aabb.pos + qsize, qsize, p_vtx)) {
+ //if (!Face3(p_vtx[0],p_vtx[1],p_vtx[2]).intersects_aabb2(aabb)) {
//does not fit in child, go on
continue;
}
-
}
- if (p_baker->bake_cells[p_idx].childs[i]==Baker::CHILD_EMPTY) {
+ if (p_baker->bake_cells[p_idx].childs[i] == Baker::CHILD_EMPTY) {
//sub cell must be created
uint32_t child_idx = p_baker->bake_cells.size();
- p_baker->bake_cells[p_idx].childs[i]=child_idx;
- p_baker->bake_cells.resize( p_baker->bake_cells.size() + 1);
- p_baker->bake_cells[child_idx].level=p_level+1;
-
+ p_baker->bake_cells[p_idx].childs[i] = child_idx;
+ p_baker->bake_cells.resize(p_baker->bake_cells.size() + 1);
+ p_baker->bake_cells[child_idx].level = p_level + 1;
}
-
- _plot_face(p_baker->bake_cells[p_idx].childs[i],p_level+1,nx,ny,nz,p_vtx,p_uv,p_material,aabb,p_baker);
+ _plot_face(p_baker->bake_cells[p_idx].childs[i], p_level + 1, nx, ny, nz, p_vtx, p_uv, p_material, aabb, p_baker);
}
}
}
+void GIProbe::_fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker) {
-
-void GIProbe::_fixup_plot(int p_idx, int p_level,int p_x,int p_y, int p_z,Baker *p_baker) {
-
-
-
- if (p_level==p_baker->cell_subdiv-1) {
+ if (p_level == p_baker->cell_subdiv - 1) {
p_baker->leaf_voxel_count++;
float alpha = p_baker->bake_cells[p_idx].alpha;
- p_baker->bake_cells[p_idx].albedo[0]/=alpha;
- p_baker->bake_cells[p_idx].albedo[1]/=alpha;
- p_baker->bake_cells[p_idx].albedo[2]/=alpha;
+ p_baker->bake_cells[p_idx].albedo[0] /= alpha;
+ p_baker->bake_cells[p_idx].albedo[1] /= alpha;
+ p_baker->bake_cells[p_idx].albedo[2] /= alpha;
//transfer emission to light
- p_baker->bake_cells[p_idx].emission[0]/=alpha;
- p_baker->bake_cells[p_idx].emission[1]/=alpha;
- p_baker->bake_cells[p_idx].emission[2]/=alpha;
+ p_baker->bake_cells[p_idx].emission[0] /= alpha;
+ p_baker->bake_cells[p_idx].emission[1] /= alpha;
+ p_baker->bake_cells[p_idx].emission[2] /= alpha;
- p_baker->bake_cells[p_idx].normal[0]/=alpha;
- p_baker->bake_cells[p_idx].normal[1]/=alpha;
- p_baker->bake_cells[p_idx].normal[2]/=alpha;
+ p_baker->bake_cells[p_idx].normal[0] /= alpha;
+ p_baker->bake_cells[p_idx].normal[1] /= alpha;
+ p_baker->bake_cells[p_idx].normal[2] /= alpha;
- Vector3 n(p_baker->bake_cells[p_idx].normal[0],p_baker->bake_cells[p_idx].normal[1],p_baker->bake_cells[p_idx].normal[2]);
- if (n.length()<0.01) {
+ Vector3 n(p_baker->bake_cells[p_idx].normal[0], p_baker->bake_cells[p_idx].normal[1], p_baker->bake_cells[p_idx].normal[2]);
+ if (n.length() < 0.01) {
//too much fight over normal, zero it
- p_baker->bake_cells[p_idx].normal[0]=0;
- p_baker->bake_cells[p_idx].normal[1]=0;
- p_baker->bake_cells[p_idx].normal[2]=0;
+ p_baker->bake_cells[p_idx].normal[0] = 0;
+ p_baker->bake_cells[p_idx].normal[1] = 0;
+ p_baker->bake_cells[p_idx].normal[2] = 0;
} else {
n.normalize();
- p_baker->bake_cells[p_idx].normal[0]=n.x;
- p_baker->bake_cells[p_idx].normal[1]=n.y;
- p_baker->bake_cells[p_idx].normal[2]=n.z;
+ p_baker->bake_cells[p_idx].normal[0] = n.x;
+ p_baker->bake_cells[p_idx].normal[1] = n.y;
+ p_baker->bake_cells[p_idx].normal[2] = n.z;
}
-
- p_baker->bake_cells[p_idx].alpha=1.0;
+ p_baker->bake_cells[p_idx].alpha = 1.0;
/*
//remove neighbours from used sides
@@ -856,60 +841,54 @@ void GIProbe::_fixup_plot(int p_idx, int p_level,int p_x,int p_y, int p_z,Baker
*/
} else {
-
//go down
- float alpha_average=0;
- int half = (1<<(p_baker->cell_subdiv-1)) >> (p_level+1);
- for(int i=0;i<8;i++) {
+ float alpha_average = 0;
+ int half = (1 << (p_baker->cell_subdiv - 1)) >> (p_level + 1);
+ for (int i = 0; i < 8; i++) {
uint32_t child = p_baker->bake_cells[p_idx].childs[i];
- if (child==Baker::CHILD_EMPTY)
+ if (child == Baker::CHILD_EMPTY)
continue;
+ int nx = p_x;
+ int ny = p_y;
+ int nz = p_z;
- int nx=p_x;
- int ny=p_y;
- int nz=p_z;
-
- if (i&1)
- nx+=half;
- if (i&2)
- ny+=half;
- if (i&4)
- nz+=half;
+ if (i & 1)
+ nx += half;
+ if (i & 2)
+ ny += half;
+ if (i & 4)
+ nz += half;
- _fixup_plot(child,p_level+1,nx,ny,nz,p_baker);
- alpha_average+=p_baker->bake_cells[child].alpha;
+ _fixup_plot(child, p_level + 1, nx, ny, nz, p_baker);
+ alpha_average += p_baker->bake_cells[child].alpha;
}
- p_baker->bake_cells[p_idx].alpha=alpha_average/8.0;
- p_baker->bake_cells[p_idx].emission[0]=0;
- p_baker->bake_cells[p_idx].emission[1]=0;
- p_baker->bake_cells[p_idx].emission[2]=0;
- p_baker->bake_cells[p_idx].normal[0]=0;
- p_baker->bake_cells[p_idx].normal[1]=0;
- p_baker->bake_cells[p_idx].normal[2]=0;
- p_baker->bake_cells[p_idx].albedo[0]=0;
- p_baker->bake_cells[p_idx].albedo[1]=0;
- p_baker->bake_cells[p_idx].albedo[2]=0;
-
+ p_baker->bake_cells[p_idx].alpha = alpha_average / 8.0;
+ p_baker->bake_cells[p_idx].emission[0] = 0;
+ p_baker->bake_cells[p_idx].emission[1] = 0;
+ p_baker->bake_cells[p_idx].emission[2] = 0;
+ p_baker->bake_cells[p_idx].normal[0] = 0;
+ p_baker->bake_cells[p_idx].normal[1] = 0;
+ p_baker->bake_cells[p_idx].normal[2] = 0;
+ p_baker->bake_cells[p_idx].albedo[0] = 0;
+ p_baker->bake_cells[p_idx].albedo[1] = 0;
+ p_baker->bake_cells[p_idx].albedo[2] = 0;
}
-
}
-
-
-Vector<Color> GIProbe::_get_bake_texture(Image &p_image,const Color& p_color) {
+Vector<Color> GIProbe::_get_bake_texture(Image &p_image, const Color &p_color) {
Vector<Color> ret;
if (p_image.empty()) {
- ret.resize(bake_texture_size*bake_texture_size);
- for(int i=0;i<bake_texture_size*bake_texture_size;i++) {
- ret[i]=p_color;
+ ret.resize(bake_texture_size * bake_texture_size);
+ for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
+ ret[i] = p_color;
}
return ret;
@@ -920,27 +899,24 @@ Vector<Color> GIProbe::_get_bake_texture(Image &p_image,const Color& p_color) {
p_image.decompress();
}
p_image.convert(Image::FORMAT_RGBA8);
- p_image.resize(bake_texture_size,bake_texture_size,Image::INTERPOLATE_CUBIC);
-
+ p_image.resize(bake_texture_size, bake_texture_size, Image::INTERPOLATE_CUBIC);
PoolVector<uint8_t>::Read r = p_image.get_data().read();
- ret.resize(bake_texture_size*bake_texture_size);
+ ret.resize(bake_texture_size * bake_texture_size);
- for(int i=0;i<bake_texture_size*bake_texture_size;i++) {
+ for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
Color c;
- c.r = r[i*4+0]/255.0;
- c.g = r[i*4+1]/255.0;
- c.b = r[i*4+2]/255.0;
- c.a = r[i*4+3]/255.0;
- ret[i]=c;
-
+ c.r = r[i * 4 + 0] / 255.0;
+ c.g = r[i * 4 + 1] / 255.0;
+ c.b = r[i * 4 + 2] / 255.0;
+ c.a = r[i * 4 + 3] / 255.0;
+ ret[i] = c;
}
return ret;
}
-
-GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_material,Baker *p_baker) {
+GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_material, Baker *p_baker) {
//this way of obtaining materials is inaccurate and also does not support some compressed formats very well
Ref<FixedSpatialMaterial> mat = p_material;
@@ -962,17 +938,16 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
img_albedo = albedo_tex->get_data();
} else {
-
}
- mc.albedo=_get_bake_texture(img_albedo,mat->get_albedo());
+ mc.albedo = _get_bake_texture(img_albedo, mat->get_albedo());
Ref<ImageTexture> emission_tex = mat->get_texture(FixedSpatialMaterial::TEXTURE_EMISSION);
Color emission_col = mat->get_emission();
- emission_col.r*=mat->get_emission_energy();
- emission_col.g*=mat->get_emission_energy();
- emission_col.b*=mat->get_emission_energy();
+ emission_col.r *= mat->get_emission_energy();
+ emission_col.g *= mat->get_emission_energy();
+ emission_col.b *= mat->get_emission_energy();
Image img_emission;
@@ -981,122 +956,110 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
img_emission = emission_tex->get_data();
}
- mc.emission=_get_bake_texture(img_emission,emission_col);
+ mc.emission = _get_bake_texture(img_emission, emission_col);
} else {
Image empty;
- mc.albedo=_get_bake_texture(empty,Color(0.7,0.7,0.7));
- mc.emission=_get_bake_texture(empty,Color(0,0,0));
-
-
+ mc.albedo = _get_bake_texture(empty, Color(0.7, 0.7, 0.7));
+ mc.emission = _get_bake_texture(empty, Color(0, 0, 0));
}
- p_baker->material_cache[p_material]=mc;
+ p_baker->material_cache[p_material] = mc;
return mc;
-
-
}
-void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) {
+void GIProbe::_plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) {
+ for (int i = 0; i < p_mesh->get_surface_count(); i++) {
- for(int i=0;i<p_mesh->get_surface_count();i++) {
-
- if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
continue; //only triangles
Ref<Material> src_material;
if (p_override_material.is_valid()) {
- src_material=p_override_material;
- } else if (i<p_materials.size() && p_materials[i].is_valid()) {
- src_material=p_materials[i];
+ src_material = p_override_material;
+ } else if (i < p_materials.size() && p_materials[i].is_valid()) {
+ src_material = p_materials[i];
} else {
- src_material=p_mesh->surface_get_material(i);
-
+ src_material = p_mesh->surface_get_material(i);
}
- Baker::MaterialCache material = _get_material_cache(src_material,p_baker);
+ Baker::MaterialCache material = _get_material_cache(src_material, p_baker);
Array a = p_mesh->surface_get_arrays(i);
-
PoolVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
- PoolVector<Vector3>::Read vr=vertices.read();
+ PoolVector<Vector3>::Read vr = vertices.read();
PoolVector<Vector2> uv = a[Mesh::ARRAY_TEX_UV];
PoolVector<Vector2>::Read uvr;
PoolVector<int> index = a[Mesh::ARRAY_INDEX];
- bool read_uv=false;
+ bool read_uv = false;
if (uv.size()) {
- uvr=uv.read();
- read_uv=true;
+ uvr = uv.read();
+ read_uv = true;
}
if (index.size()) {
- int facecount = index.size()/3;
- PoolVector<int>::Read ir=index.read();
+ int facecount = index.size() / 3;
+ PoolVector<int>::Read ir = index.read();
- for(int j=0;j<facecount;j++) {
+ for (int j = 0; j < facecount; j++) {
Vector3 vtxs[3];
Vector2 uvs[3];
- for(int k=0;k<3;k++) {
- vtxs[k]=p_xform.xform(vr[ir[j*3+k]]);
+ for (int k = 0; k < 3; k++) {
+ vtxs[k] = p_xform.xform(vr[ir[j * 3 + k]]);
}
if (read_uv) {
- for(int k=0;k<3;k++) {
- uvs[k]=uvr[ir[j*3+k]];
+ for (int k = 0; k < 3; k++) {
+ uvs[k] = uvr[ir[j * 3 + k]];
}
}
//test against original bounds
- if (!fast_tri_box_overlap(-extents,extents*2,vtxs))
+ if (!fast_tri_box_overlap(-extents, extents * 2, vtxs))
continue;
//plot
- _plot_face(0,0,0,0,0,vtxs,uvs,material,p_baker->po2_bounds,p_baker);
+ _plot_face(0, 0, 0, 0, 0, vtxs, uvs, material, p_baker->po2_bounds, p_baker);
}
-
-
} else {
- int facecount = vertices.size()/3;
+ int facecount = vertices.size() / 3;
- for(int j=0;j<facecount;j++) {
+ for (int j = 0; j < facecount; j++) {
Vector3 vtxs[3];
Vector2 uvs[3];
- for(int k=0;k<3;k++) {
- vtxs[k]=p_xform.xform(vr[j*3+k]);
+ for (int k = 0; k < 3; k++) {
+ vtxs[k] = p_xform.xform(vr[j * 3 + k]);
}
if (read_uv) {
- for(int k=0;k<3;k++) {
- uvs[k]=uvr[j*3+k];
+ for (int k = 0; k < 3; k++) {
+ uvs[k] = uvr[j * 3 + k];
}
}
//test against original bounds
- if (!fast_tri_box_overlap(-extents,extents*2,vtxs))
+ if (!fast_tri_box_overlap(-extents, extents * 2, vtxs))
continue;
//plot face
- _plot_face(0,0,0,0,0,vtxs,uvs,material,p_baker->po2_bounds,p_baker);
+ _plot_face(0, 0, 0, 0, 0, vtxs, uvs, material, p_baker->po2_bounds, p_baker);
}
-
}
}
}
-
-
-void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){
+void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) {
MeshInstance *mi = p_at_node->cast_to<MeshInstance>();
if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT)) {
@@ -1107,16 +1070,15 @@ void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){
Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
- if (Rect3(-extents,extents*2).intersects(xf.xform(aabb))) {
+ if (Rect3(-extents, extents * 2).intersects(xf.xform(aabb))) {
Baker::PlotMesh pm;
- pm.local_xform=xf;
- pm.mesh=mesh;
- for(int i=0;i<mesh->get_surface_count();i++) {
+ pm.local_xform = xf;
+ pm.mesh = mesh;
+ for (int i = 0; i < mesh->get_surface_count(); i++) {
pm.instance_materials.push_back(mi->get_surface_material(i));
}
- pm.override_material=mi->get_material_override();
+ pm.override_material = mi->get_material_override();
p_baker->mesh_list.push_back(pm);
-
}
}
}
@@ -1125,10 +1087,10 @@ void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){
Spatial *s = p_at_node->cast_to<Spatial>();
Array meshes = p_at_node->call("get_meshes");
- for(int i=0;i<meshes.size();i+=2) {
+ for (int i = 0; i < meshes.size(); i += 2) {
Transform mxf = meshes[i];
- Ref<Mesh> mesh = meshes[i+1];
+ Ref<Mesh> mesh = meshes[i + 1];
if (!mesh.is_valid())
continue;
@@ -1136,166 +1098,151 @@ void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){
Transform xf = get_global_transform().affine_inverse() * (s->get_global_transform() * mxf);
- if (Rect3(-extents,extents*2).intersects(xf.xform(aabb))) {
+ if (Rect3(-extents, extents * 2).intersects(xf.xform(aabb))) {
Baker::PlotMesh pm;
- pm.local_xform=xf;
- pm.mesh=mesh;
+ pm.local_xform = xf;
+ pm.mesh = mesh;
p_baker->mesh_list.push_back(pm);
-
}
}
}
- for(int i=0;i<p_at_node->get_child_count();i++) {
+ for (int i = 0; i < p_at_node->get_child_count(); i++) {
Node *child = p_at_node->get_child(i);
if (!child->get_owner())
continue; //maybe a helper
- _find_meshes(child,p_baker);
-
+ _find_meshes(child, p_baker);
}
}
-
-
-
-void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){
+void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) {
Baker baker;
- static const int subdiv_value[SUBDIV_MAX]={7,8,9,10};
+ static const int subdiv_value[SUBDIV_MAX] = { 7, 8, 9, 10 };
- baker.cell_subdiv=subdiv_value[subdiv];
+ baker.cell_subdiv = subdiv_value[subdiv];
baker.bake_cells.resize(1);
//find out the actual real bounds, power of 2, which gets the highest subdivision
- baker.po2_bounds=Rect3(-extents,extents*2.0);
+ baker.po2_bounds = Rect3(-extents, extents * 2.0);
int longest_axis = baker.po2_bounds.get_longest_axis_index();
- baker.axis_cell_size[longest_axis]=(1<<(baker.cell_subdiv-1));
- baker.leaf_voxel_count=0;
+ baker.axis_cell_size[longest_axis] = (1 << (baker.cell_subdiv - 1));
+ baker.leaf_voxel_count = 0;
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
- if (i==longest_axis)
+ if (i == longest_axis)
continue;
- baker.axis_cell_size[i]=baker.axis_cell_size[longest_axis];
+ baker.axis_cell_size[i] = baker.axis_cell_size[longest_axis];
float axis_size = baker.po2_bounds.size[longest_axis];
//shrink until fit subdiv
- while (axis_size/2.0 >= baker.po2_bounds.size[i]) {
- axis_size/=2.0;
- baker.axis_cell_size[i]>>=1;
+ while (axis_size / 2.0 >= baker.po2_bounds.size[i]) {
+ axis_size /= 2.0;
+ baker.axis_cell_size[i] >>= 1;
}
- baker.po2_bounds.size[i]=baker.po2_bounds.size[longest_axis];
+ baker.po2_bounds.size[i] = baker.po2_bounds.size[longest_axis];
}
-
-
Transform to_bounds;
- to_bounds.basis.scale(Vector3(baker.po2_bounds.size[longest_axis],baker.po2_bounds.size[longest_axis],baker.po2_bounds.size[longest_axis]));
- to_bounds.origin=baker.po2_bounds.pos;
+ to_bounds.basis.scale(Vector3(baker.po2_bounds.size[longest_axis], baker.po2_bounds.size[longest_axis], baker.po2_bounds.size[longest_axis]));
+ to_bounds.origin = baker.po2_bounds.pos;
Transform to_grid;
- to_grid.basis.scale(Vector3(baker.axis_cell_size[longest_axis],baker.axis_cell_size[longest_axis],baker.axis_cell_size[longest_axis]));
+ to_grid.basis.scale(Vector3(baker.axis_cell_size[longest_axis], baker.axis_cell_size[longest_axis], baker.axis_cell_size[longest_axis]));
baker.to_cell_space = to_grid * to_bounds.affine_inverse();
+ _find_meshes(p_from_node ? p_from_node : get_parent(), &baker);
- _find_meshes(p_from_node?p_from_node:get_parent(),&baker);
-
-
+ int pmc = 0;
- int pmc=0;
+ for (List<Baker::PlotMesh>::Element *E = baker.mesh_list.front(); E; E = E->next()) {
- for(List<Baker::PlotMesh>::Element *E=baker.mesh_list.front();E;E=E->next()) {
+ print_line("plotting mesh " + itos(pmc++) + "/" + itos(baker.mesh_list.size()));
- print_line("plotting mesh "+itos(pmc++)+"/"+itos(baker.mesh_list.size()));
-
- _plot_mesh(E->get().local_xform,E->get().mesh,&baker,E->get().instance_materials,E->get().override_material);
+ _plot_mesh(E->get().local_xform, E->get().mesh, &baker, E->get().instance_materials, E->get().override_material);
}
- _fixup_plot(0,0,0,0,0,&baker);
+ _fixup_plot(0, 0, 0, 0, 0, &baker);
//create the data for visual server
PoolVector<int> data;
- data.resize( 16+(8+1+1+1+1)*baker.bake_cells.size() ); //4 for header, rest for rest.
+ data.resize(16 + (8 + 1 + 1 + 1 + 1) * baker.bake_cells.size()); //4 for header, rest for rest.
{
PoolVector<int>::Write w = data.write();
- uint32_t * w32 = (uint32_t*)w.ptr();
+ uint32_t *w32 = (uint32_t *)w.ptr();
- w32[0]=0;//version
- w32[1]=baker.cell_subdiv; //subdiv
- w32[2]=baker.axis_cell_size[0];
- w32[3]=baker.axis_cell_size[1];
- w32[4]=baker.axis_cell_size[2];
- w32[5]=baker.bake_cells.size();
- w32[6]=baker.leaf_voxel_count;
+ w32[0] = 0; //version
+ w32[1] = baker.cell_subdiv; //subdiv
+ w32[2] = baker.axis_cell_size[0];
+ w32[3] = baker.axis_cell_size[1];
+ w32[4] = baker.axis_cell_size[2];
+ w32[5] = baker.bake_cells.size();
+ w32[6] = baker.leaf_voxel_count;
- int ofs=16;
+ int ofs = 16;
- for(int i=0;i<baker.bake_cells.size();i++) {
+ for (int i = 0; i < baker.bake_cells.size(); i++) {
- for(int j=0;j<8;j++) {
- w32[ofs++]=baker.bake_cells[i].childs[j];
+ for (int j = 0; j < 8; j++) {
+ w32[ofs++] = baker.bake_cells[i].childs[j];
}
{ //albedo
- uint32_t rgba=uint32_t(CLAMP(baker.bake_cells[i].albedo[0]*255.0,0,255))<<16;
- rgba|=uint32_t(CLAMP(baker.bake_cells[i].albedo[1]*255.0,0,255))<<8;
- rgba|=uint32_t(CLAMP(baker.bake_cells[i].albedo[2]*255.0,0,255))<<0;
-
- w32[ofs++]=rgba;
-
+ uint32_t rgba = uint32_t(CLAMP(baker.bake_cells[i].albedo[0] * 255.0, 0, 255)) << 16;
+ rgba |= uint32_t(CLAMP(baker.bake_cells[i].albedo[1] * 255.0, 0, 255)) << 8;
+ rgba |= uint32_t(CLAMP(baker.bake_cells[i].albedo[2] * 255.0, 0, 255)) << 0;
+ w32[ofs++] = rgba;
}
{ //emission
- Vector3 e(baker.bake_cells[i].emission[0],baker.bake_cells[i].emission[1],baker.bake_cells[i].emission[2]);
+ Vector3 e(baker.bake_cells[i].emission[0], baker.bake_cells[i].emission[1], baker.bake_cells[i].emission[2]);
float l = e.length();
- if (l>0) {
+ if (l > 0) {
e.normalize();
- l=CLAMP(l/8.0,0,1.0);
+ l = CLAMP(l / 8.0, 0, 1.0);
}
- uint32_t em=uint32_t(CLAMP(e[0]*255,0,255))<<24;
- em|=uint32_t(CLAMP(e[1]*255,0,255))<<16;
- em|=uint32_t(CLAMP(e[2]*255,0,255))<<8;
- em|=uint32_t(CLAMP(l*255,0,255));
+ uint32_t em = uint32_t(CLAMP(e[0] * 255, 0, 255)) << 24;
+ em |= uint32_t(CLAMP(e[1] * 255, 0, 255)) << 16;
+ em |= uint32_t(CLAMP(e[2] * 255, 0, 255)) << 8;
+ em |= uint32_t(CLAMP(l * 255, 0, 255));
- w32[ofs++]=em;
+ w32[ofs++] = em;
}
//w32[ofs++]=baker.bake_cells[i].used_sides;
{ //normal
- Vector3 n(baker.bake_cells[i].normal[0],baker.bake_cells[i].normal[1],baker.bake_cells[i].normal[2]);
- n=n*Vector3(0.5,0.5,0.5)+Vector3(0.5,0.5,0.5);
- uint32_t norm=0;
-
+ Vector3 n(baker.bake_cells[i].normal[0], baker.bake_cells[i].normal[1], baker.bake_cells[i].normal[2]);
+ n = n * Vector3(0.5, 0.5, 0.5) + Vector3(0.5, 0.5, 0.5);
+ uint32_t norm = 0;
- norm|=uint32_t(CLAMP( n.x*255.0, 0, 255))<<16;
- norm|=uint32_t(CLAMP( n.y*255.0, 0, 255))<<8;
- norm|=uint32_t(CLAMP( n.z*255.0, 0, 255))<<0;
+ norm |= uint32_t(CLAMP(n.x * 255.0, 0, 255)) << 16;
+ norm |= uint32_t(CLAMP(n.y * 255.0, 0, 255)) << 8;
+ norm |= uint32_t(CLAMP(n.z * 255.0, 0, 255)) << 0;
- w32[ofs++]=norm;
+ w32[ofs++] = norm;
}
{
- uint16_t alpha = CLAMP(uint32_t(baker.bake_cells[i].alpha*65535.0),0,65535);
+ uint16_t alpha = CLAMP(uint32_t(baker.bake_cells[i].alpha * 65535.0), 0, 65535);
uint16_t level = baker.bake_cells[i].level;
- w32[ofs++] = (uint32_t(level)<<16)|uint32_t(alpha);
+ w32[ofs++] = (uint32_t(level) << 16) | uint32_t(alpha);
}
-
}
-
}
if (p_create_visual_debug) {
@@ -1304,8 +1251,8 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){
Ref<GIProbeData> probe_data;
probe_data.instance();
- probe_data->set_bounds(Rect3(-extents,extents*2.0));
- probe_data->set_cell_size(baker.po2_bounds.size[longest_axis]/baker.axis_cell_size[longest_axis]);
+ probe_data->set_bounds(Rect3(-extents, extents * 2.0));
+ probe_data->set_cell_size(baker.po2_bounds.size[longest_axis] / baker.axis_cell_size[longest_axis]);
probe_data->set_dynamic_data(data);
probe_data->set_dynamic_range(dynamic_range);
probe_data->set_energy(energy);
@@ -1317,54 +1264,44 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){
set_probe_data(probe_data);
}
-
-
-
-
-
}
+void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx, Baker *p_baker) {
-void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb,Ref<MultiMesh> &p_multimesh,int &idx,Baker *p_baker) {
+ if (p_level == p_baker->cell_subdiv - 1) {
-
- if (p_level==p_baker->cell_subdiv-1) {
-
- Vector3 center = p_aabb.pos+p_aabb.size*0.5;
+ Vector3 center = p_aabb.pos + p_aabb.size * 0.5;
Transform xform;
- xform.origin=center;
- xform.basis.scale(p_aabb.size*0.5);
- p_multimesh->set_instance_transform(idx,xform);
- Color col=Color(p_baker->bake_cells[p_idx].albedo[0],p_baker->bake_cells[p_idx].albedo[1],p_baker->bake_cells[p_idx].albedo[2]);
- p_multimesh->set_instance_color(idx,col);
+ xform.origin = center;
+ xform.basis.scale(p_aabb.size * 0.5);
+ p_multimesh->set_instance_transform(idx, xform);
+ Color col = Color(p_baker->bake_cells[p_idx].albedo[0], p_baker->bake_cells[p_idx].albedo[1], p_baker->bake_cells[p_idx].albedo[2]);
+ p_multimesh->set_instance_color(idx, col);
idx++;
} else {
- for(int i=0;i<8;i++) {
+ for (int i = 0; i < 8; i++) {
- if (p_baker->bake_cells[p_idx].childs[i]==Baker::CHILD_EMPTY)
+ if (p_baker->bake_cells[p_idx].childs[i] == Baker::CHILD_EMPTY)
continue;
- Rect3 aabb=p_aabb;
- aabb.size*=0.5;
+ Rect3 aabb = p_aabb;
+ aabb.size *= 0.5;
- if (i&1)
- aabb.pos.x+=aabb.size.x;
- if (i&2)
- aabb.pos.y+=aabb.size.y;
- if (i&4)
- aabb.pos.z+=aabb.size.z;
+ if (i & 1)
+ aabb.pos.x += aabb.size.x;
+ if (i & 2)
+ aabb.pos.y += aabb.size.y;
+ if (i & 4)
+ aabb.pos.z += aabb.size.z;
- _debug_mesh(p_baker->bake_cells[p_idx].childs[i],p_level+1,aabb,p_multimesh,idx,p_baker);
+ _debug_mesh(p_baker->bake_cells[p_idx].childs[i], p_level + 1, aabb, p_multimesh, idx, p_baker);
}
-
}
-
}
-
void GIProbe::_create_debug_mesh(Baker *p_baker) {
Ref<MultiMesh> mm;
@@ -1372,7 +1309,7 @@ void GIProbe::_create_debug_mesh(Baker *p_baker) {
mm->set_transform_format(MultiMesh::TRANSFORM_3D);
mm->set_color_format(MultiMesh::COLOR_8BIT);
- print_line("leaf voxels: "+itos(p_baker->leaf_voxel_count));
+ print_line("leaf voxels: " + itos(p_baker->leaf_voxel_count));
mm->set_instance_count(p_baker->leaf_voxel_count);
Ref<Mesh> mesh;
@@ -1385,76 +1322,72 @@ void GIProbe::_create_debug_mesh(Baker *p_baker) {
PoolVector<Vector3> vertices;
PoolVector<Color> colors;
- int vtx_idx=0;
- #define ADD_VTX(m_idx);\
- vertices.push_back( face_points[m_idx] );\
- colors.push_back( Color(1,1,1,1) );\
- vtx_idx++;\
-
- for (int i=0;i<6;i++) {
+ int vtx_idx = 0;
+#define ADD_VTX(m_idx) \
+ ; \
+ vertices.push_back(face_points[m_idx]); \
+ colors.push_back(Color(1, 1, 1, 1)); \
+ vtx_idx++;
+ for (int i = 0; i < 6; i++) {
Vector3 face_points[4];
- for (int j=0;j<4;j++) {
+ for (int j = 0; j < 4; j++) {
float v[3];
- v[0]=1.0;
- v[1]=1-2*((j>>1)&1);
- v[2]=v[1]*(1-2*(j&1));
+ v[0] = 1.0;
+ v[1] = 1 - 2 * ((j >> 1) & 1);
+ v[2] = v[1] * (1 - 2 * (j & 1));
- for (int k=0;k<3;k++) {
+ for (int k = 0; k < 3; k++) {
- if (i<3)
- face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
+ if (i < 3)
+ face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
else
- face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
+ face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
}
}
- //tri 1
+ //tri 1
ADD_VTX(0);
ADD_VTX(1);
ADD_VTX(2);
- //tri 2
+ //tri 2
ADD_VTX(2);
ADD_VTX(3);
ADD_VTX(0);
-
}
-
- arr[Mesh::ARRAY_VERTEX]=vertices;
- arr[Mesh::ARRAY_COLOR]=colors;
- mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES,arr);
+ arr[Mesh::ARRAY_VERTEX] = vertices;
+ arr[Mesh::ARRAY_COLOR] = colors;
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr);
}
{
Ref<FixedSpatialMaterial> fsm;
fsm.instance();
- fsm->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true);
- fsm->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true);
- fsm->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true);
- fsm->set_albedo(Color(1,1,1,1));
+ fsm->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ fsm->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ fsm->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true);
+ fsm->set_albedo(Color(1, 1, 1, 1));
- mesh->surface_set_material(0,fsm);
+ mesh->surface_set_material(0, fsm);
}
mm->set_mesh(mesh);
+ int idx = 0;
+ _debug_mesh(0, 0, p_baker->po2_bounds, mm, idx, p_baker);
- int idx=0;
- _debug_mesh(0,0,p_baker->po2_bounds,mm,idx,p_baker);
-
- MultiMeshInstance *mmi = memnew( MultiMeshInstance );
+ MultiMeshInstance *mmi = memnew(MultiMeshInstance);
mmi->set_multimesh(mm);
add_child(mmi);
#ifdef TOOLS_ENABLED
- if (get_tree()->get_edited_scene_root()==this){
+ if (get_tree()->get_edited_scene_root() == this) {
mmi->set_owner(this);
} else {
mmi->set_owner(get_owner());
-
}
#else
mmi->set_owner(get_owner());
@@ -1463,12 +1396,12 @@ void GIProbe::_create_debug_mesh(Baker *p_baker) {
void GIProbe::_debug_bake() {
- bake(NULL,true);
+ bake(NULL, true);
}
Rect3 GIProbe::get_aabb() const {
- return Rect3(-extents,extents*2);
+ return Rect3(-extents, extents * 2);
}
PoolVector<Face3> GIProbe::get_faces(uint32_t p_usage_flags) const {
@@ -1478,74 +1411,68 @@ PoolVector<Face3> GIProbe::get_faces(uint32_t p_usage_flags) const {
void GIProbe::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_probe_data","data"),&GIProbe::set_probe_data);
- ClassDB::bind_method(D_METHOD("get_probe_data"),&GIProbe::get_probe_data);
+ ClassDB::bind_method(D_METHOD("set_probe_data", "data"), &GIProbe::set_probe_data);
+ ClassDB::bind_method(D_METHOD("get_probe_data"), &GIProbe::get_probe_data);
- ClassDB::bind_method(D_METHOD("set_subdiv","subdiv"),&GIProbe::set_subdiv);
- ClassDB::bind_method(D_METHOD("get_subdiv"),&GIProbe::get_subdiv);
+ ClassDB::bind_method(D_METHOD("set_subdiv", "subdiv"), &GIProbe::set_subdiv);
+ ClassDB::bind_method(D_METHOD("get_subdiv"), &GIProbe::get_subdiv);
- ClassDB::bind_method(D_METHOD("set_extents","extents"),&GIProbe::set_extents);
- ClassDB::bind_method(D_METHOD("get_extents"),&GIProbe::get_extents);
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GIProbe::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &GIProbe::get_extents);
- ClassDB::bind_method(D_METHOD("set_dynamic_range","max"),&GIProbe::set_dynamic_range);
- ClassDB::bind_method(D_METHOD("get_dynamic_range"),&GIProbe::get_dynamic_range);
+ ClassDB::bind_method(D_METHOD("set_dynamic_range", "max"), &GIProbe::set_dynamic_range);
+ ClassDB::bind_method(D_METHOD("get_dynamic_range"), &GIProbe::get_dynamic_range);
- ClassDB::bind_method(D_METHOD("set_energy","max"),&GIProbe::set_energy);
- ClassDB::bind_method(D_METHOD("get_energy"),&GIProbe::get_energy);
+ ClassDB::bind_method(D_METHOD("set_energy", "max"), &GIProbe::set_energy);
+ ClassDB::bind_method(D_METHOD("get_energy"), &GIProbe::get_energy);
- ClassDB::bind_method(D_METHOD("set_bias","max"),&GIProbe::set_bias);
- ClassDB::bind_method(D_METHOD("get_bias"),&GIProbe::get_bias);
+ ClassDB::bind_method(D_METHOD("set_bias", "max"), &GIProbe::set_bias);
+ ClassDB::bind_method(D_METHOD("get_bias"), &GIProbe::get_bias);
- ClassDB::bind_method(D_METHOD("set_propagation","max"),&GIProbe::set_propagation);
- ClassDB::bind_method(D_METHOD("get_propagation"),&GIProbe::get_propagation);
+ ClassDB::bind_method(D_METHOD("set_propagation", "max"), &GIProbe::set_propagation);
+ ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbe::get_propagation);
- ClassDB::bind_method(D_METHOD("set_interior","enable"),&GIProbe::set_interior);
- ClassDB::bind_method(D_METHOD("is_interior"),&GIProbe::is_interior);
+ ClassDB::bind_method(D_METHOD("set_interior", "enable"), &GIProbe::set_interior);
+ ClassDB::bind_method(D_METHOD("is_interior"), &GIProbe::is_interior);
- ClassDB::bind_method(D_METHOD("set_compress","enable"),&GIProbe::set_compress);
- ClassDB::bind_method(D_METHOD("is_compressed"),&GIProbe::is_compressed);
+ ClassDB::bind_method(D_METHOD("set_compress", "enable"), &GIProbe::set_compress);
+ ClassDB::bind_method(D_METHOD("is_compressed"), &GIProbe::is_compressed);
- ClassDB::bind_method(D_METHOD("bake","from_node","create_visual_debug"),&GIProbe::bake,DEFVAL(Variant()),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("debug_bake"),&GIProbe::_debug_bake);
- ClassDB::set_method_flags(get_class_static(),_scs_create("debug_bake"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("bake", "from_node", "create_visual_debug"), &GIProbe::bake, DEFVAL(Variant()), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("debug_bake"), &GIProbe::_debug_bake);
+ ClassDB::set_method_flags(get_class_static(), _scs_create("debug_bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"subdiv",PROPERTY_HINT_ENUM,"64,128,256,512"),"set_subdiv","get_subdiv");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"extents"),"set_extents","get_extents");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_RANGE,"1,16,1"),"set_dynamic_range","get_dynamic_range");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_RANGE,"0,16,0.01"),"set_energy","get_energy");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_propagation","get_propagation");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"bias",PROPERTY_HINT_RANGE,"0,4,0.001"),"set_bias","get_bias");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"interior"),"set_interior","is_interior");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"compress"),"set_compress","is_compressed");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"data",PROPERTY_HINT_RESOURCE_TYPE,"GIProbeData"),"set_probe_data","get_probe_data");
-
-
- BIND_CONSTANT( SUBDIV_64 );
- BIND_CONSTANT( SUBDIV_128 );
- BIND_CONSTANT( SUBDIV_256 );
- BIND_CONSTANT( SUBDIV_MAX );
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "subdiv", PROPERTY_HINT_ENUM, "64,128,256,512"), "set_subdiv", "get_subdiv");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_RANGE, "1,16,1"), "set_dynamic_range", "get_dynamic_range");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_energy", "get_energy");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_RANGE, "0,4,0.001"), "set_bias", "get_bias");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compress"), "set_compress", "is_compressed");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "GIProbeData"), "set_probe_data", "get_probe_data");
+ BIND_CONSTANT(SUBDIV_64);
+ BIND_CONSTANT(SUBDIV_128);
+ BIND_CONSTANT(SUBDIV_256);
+ BIND_CONSTANT(SUBDIV_MAX);
}
GIProbe::GIProbe() {
- subdiv=SUBDIV_128;
- dynamic_range=4;
- energy=1.0;
- bias=0.4;
- propagation=1.0;
- extents=Vector3(10,10,10);
- color_scan_cell_width=4;
- bake_texture_size=128;
- interior=false;
- compress=false;
+ subdiv = SUBDIV_128;
+ dynamic_range = 4;
+ energy = 1.0;
+ bias = 0.4;
+ propagation = 1.0;
+ extents = Vector3(10, 10, 10);
+ color_scan_cell_width = 4;
+ bake_texture_size = 128;
+ interior = false;
+ compress = false;
gi_probe = VS::get_singleton()->gi_probe_create();
-
-
}
GIProbe::~GIProbe() {
-
-
}
diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h
index a45e80806a..675b41cef9 100644
--- a/scene/3d/gi_probe.h
+++ b/scene/3d/gi_probe.h
@@ -29,32 +29,29 @@
#ifndef GIPROBE_H
#define GIPROBE_H
-#include "scene/3d/visual_instance.h"
#include "multimesh_instance.h"
+#include "scene/3d/visual_instance.h"
class GIProbeData : public Resource {
- GDCLASS(GIProbeData,Resource);
+ GDCLASS(GIProbeData, Resource);
RID probe;
protected:
-
static void _bind_methods();
-public:
-
-
- void set_bounds(const Rect3& p_bounds);
+public:
+ void set_bounds(const Rect3 &p_bounds);
Rect3 get_bounds() const;
void set_cell_size(float p_size);
float get_cell_size() const;
- void set_to_cell_xform(const Transform& p_xform);
+ void set_to_cell_xform(const Transform &p_xform);
Transform get_to_cell_xform() const;
- void set_dynamic_data(const PoolVector<int>& p_data);
+ void set_dynamic_data(const PoolVector<int> &p_data);
PoolVector<int> get_dynamic_data() const;
void set_dynamic_range(int p_range);
@@ -81,12 +78,11 @@ public:
~GIProbeData();
};
+class GIProbe : public VisualInstance {
+ GDCLASS(GIProbe, VisualInstance);
-
-class GIProbe : public VisualInstance {
- GDCLASS(GIProbe,VisualInstance);
public:
- enum Subdiv{
+ enum Subdiv {
SUBDIV_64,
SUBDIV_128,
SUBDIV_256,
@@ -94,13 +90,13 @@ public:
SUBDIV_MAX
};
-private:
+private:
//stuff used for bake
struct Baker {
enum {
- CHILD_EMPTY=0xFFFFFFFF
+ CHILD_EMPTY = 0xFFFFFFFF
};
struct Cell {
@@ -113,18 +109,18 @@ private:
int level;
Cell() {
- for(int i=0;i<8;i++) {
- childs[i]=CHILD_EMPTY;
+ for (int i = 0; i < 8; i++) {
+ childs[i] = CHILD_EMPTY;
}
- for(int i=0;i<3;i++) {
- emission[i]=0;
- albedo[i]=0;
- normal[i]=0;
+ for (int i = 0; i < 3; i++) {
+ emission[i] = 0;
+ albedo[i] = 0;
+ normal[i] = 0;
}
- alpha=0;
- used_sides=0;
- level=0;
+ alpha = 0;
+ used_sides = 0;
+ level = 0;
}
};
@@ -137,13 +133,11 @@ private:
Vector<Color> emission;
};
-
Vector<Color> _get_bake_texture(Image &p_image, const Color &p_color);
- Map<Ref<Material>,MaterialCache> material_cache;
+ Map<Ref<Material>, MaterialCache> material_cache;
MaterialCache _get_material_cache(Ref<Material> p_material);
int leaf_voxel_count;
-
Rect3 po2_bounds;
int axis_cell_size[3];
@@ -159,7 +153,6 @@ private:
List<PlotMesh> mesh_list;
};
-
Ref<GIProbeData> probe_data;
RID gi_probe;
@@ -176,30 +169,29 @@ private:
int color_scan_cell_width;
int bake_texture_size;
- Vector<Color> _get_bake_texture(Image &p_image,const Color& p_color);
- Baker::MaterialCache _get_material_cache(Ref<Material> p_material,Baker *p_baker);
- void _plot_face(int p_idx, int p_level, int p_x,int p_y,int p_z,const Vector3 *p_vtx, const Vector2* p_uv, const Baker::MaterialCache& p_material, const Rect3 &p_aabb,Baker *p_baker);
- void _plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker,const Vector<Ref<Material> >& p_materials,const Ref<Material>& p_override_material);
- void _find_meshes(Node *p_at_node,Baker *p_baker);
- void _fixup_plot(int p_idx, int p_level,int p_x,int p_y, int p_z,Baker *p_baker);
+ Vector<Color> _get_bake_texture(Image &p_image, const Color &p_color);
+ Baker::MaterialCache _get_material_cache(Ref<Material> p_material, Baker *p_baker);
+ void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const Baker::MaterialCache &p_material, const Rect3 &p_aabb, Baker *p_baker);
+ void _plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material);
+ void _find_meshes(Node *p_at_node, Baker *p_baker);
+ void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker);
- void _debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb,Ref<MultiMesh> &p_multimesh,int &idx,Baker *p_baker);
+ void _debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx, Baker *p_baker);
void _create_debug_mesh(Baker *p_baker);
void _debug_bake();
protected:
-
static void _bind_methods();
-public:
- void set_probe_data(const Ref<GIProbeData>& p_data);
+public:
+ void set_probe_data(const Ref<GIProbeData> &p_data);
Ref<GIProbeData> get_probe_data() const;
void set_subdiv(Subdiv p_subdiv);
Subdiv get_subdiv() const;
- void set_extents(const Vector3& p_extents);
+ void set_extents(const Vector3 &p_extents);
Vector3 get_extents() const;
void set_dynamic_range(int p_dynamic_range);
@@ -220,7 +212,7 @@ public:
void set_compress(bool p_enable);
bool is_compressed() const;
- void bake(Node *p_from_node=NULL,bool p_create_visual_debug=false);
+ void bake(Node *p_from_node = NULL, bool p_create_visual_debug = false);
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry.cpp
index 6adbbe9ccf..adcc167223 100644
--- a/scene/3d/immediate_geometry.cpp
+++ b/scene/3d/immediate_geometry.cpp
@@ -28,68 +28,60 @@
/*************************************************************************/
#include "immediate_geometry.h"
+void ImmediateGeometry::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture> &p_texture) {
-void ImmediateGeometry::begin(Mesh::PrimitiveType p_primitive,const Ref<Texture>& p_texture) {
-
- VS::get_singleton()->immediate_begin(im,(VS::PrimitiveType)p_primitive,p_texture.is_valid()?p_texture->get_rid():RID());
+ VS::get_singleton()->immediate_begin(im, (VS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID());
if (p_texture.is_valid())
cached_textures.push_back(p_texture);
-
}
-void ImmediateGeometry::set_normal(const Vector3& p_normal){
+void ImmediateGeometry::set_normal(const Vector3 &p_normal) {
- VS::get_singleton()->immediate_normal(im,p_normal);
+ VS::get_singleton()->immediate_normal(im, p_normal);
}
-void ImmediateGeometry::set_tangent(const Plane& p_tangent){
-
- VS::get_singleton()->immediate_tangent(im,p_tangent);
+void ImmediateGeometry::set_tangent(const Plane &p_tangent) {
+ VS::get_singleton()->immediate_tangent(im, p_tangent);
}
-void ImmediateGeometry::set_color(const Color& p_color){
-
- VS::get_singleton()->immediate_color(im,p_color);
+void ImmediateGeometry::set_color(const Color &p_color) {
+ VS::get_singleton()->immediate_color(im, p_color);
}
-void ImmediateGeometry::set_uv(const Vector2& p_uv){
-
- VS::get_singleton()->immediate_uv(im,p_uv);
+void ImmediateGeometry::set_uv(const Vector2 &p_uv) {
+ VS::get_singleton()->immediate_uv(im, p_uv);
}
-void ImmediateGeometry::set_uv2(const Vector2& p_uv2){
-
- VS::get_singleton()->immediate_uv2(im,p_uv2);
+void ImmediateGeometry::set_uv2(const Vector2 &p_uv2) {
+ VS::get_singleton()->immediate_uv2(im, p_uv2);
}
-void ImmediateGeometry::add_vertex(const Vector3& p_vertex){
+void ImmediateGeometry::add_vertex(const Vector3 &p_vertex) {
- VS::get_singleton()->immediate_vertex(im,p_vertex);
+ VS::get_singleton()->immediate_vertex(im, p_vertex);
if (empty) {
- aabb.pos=p_vertex;
- aabb.size=Vector3();
- empty=false;
+ aabb.pos = p_vertex;
+ aabb.size = Vector3();
+ empty = false;
} else {
aabb.expand_to(p_vertex);
}
}
-void ImmediateGeometry::end(){
+void ImmediateGeometry::end() {
VS::get_singleton()->immediate_end(im);
-
}
-void ImmediateGeometry::clear(){
+void ImmediateGeometry::clear() {
VS::get_singleton()->immediate_clear(im);
- empty=true;
+ empty = true;
cached_textures.clear();
-
}
Rect3 ImmediateGeometry::get_aabb() const {
@@ -101,44 +93,41 @@ PoolVector<Face3> ImmediateGeometry::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
}
-
-
void ImmediateGeometry::add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv) {
- for(int i = 1; i <= p_lats; i++) {
- double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats);
- double z0 = Math::sin(lat0);
- double zr0 = Math::cos(lat0);
+ for (int i = 1; i <= p_lats; i++) {
+ double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats);
+ double z0 = Math::sin(lat0);
+ double zr0 = Math::cos(lat0);
- double lat1 = Math_PI * (-0.5 + (double) i / p_lats);
+ double lat1 = Math_PI * (-0.5 + (double)i / p_lats);
double z1 = Math::sin(lat1);
double zr1 = Math::cos(lat1);
- for(int j = p_lons; j >= 1; j--) {
+ for (int j = p_lons; j >= 1; j--) {
- double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons;
+ double lng0 = 2 * Math_PI * (double)(j - 1) / p_lons;
double x0 = Math::cos(lng0);
double y0 = Math::sin(lng0);
- double lng1 = 2 * Math_PI * (double) (j) / p_lons;
+ double lng1 = 2 * Math_PI * (double)(j) / p_lons;
double x1 = Math::cos(lng1);
double y1 = Math::sin(lng1);
-
- Vector3 v[4]={
- Vector3(x1 * zr0, z0, y1 *zr0),
- Vector3(x1 * zr1, z1, y1 *zr1),
- Vector3(x0 * zr1, z1, y0 *zr1),
- Vector3(x0 * zr0, z0, y0 *zr0)
+ Vector3 v[4] = {
+ Vector3(x1 * zr0, z0, y1 * zr0),
+ Vector3(x1 * zr1, z1, y1 * zr1),
+ Vector3(x0 * zr1, z1, y0 * zr1),
+ Vector3(x0 * zr0, z0, y0 * zr0)
};
-#define ADD_POINT(m_idx)\
- if (p_add_uv) {\
- set_uv(Vector2(Math::atan2(v[m_idx].x,v[m_idx].z)/Math_PI * 0.5+0.5,v[m_idx].y*0.5+0.5));\
- set_tangent(Plane(Vector3(-v[m_idx].z,v[m_idx].y,v[m_idx].x),1)); \
- }\
- set_normal(v[m_idx]);\
- add_vertex(v[m_idx]*p_radius);
+#define ADD_POINT(m_idx) \
+ if (p_add_uv) { \
+ set_uv(Vector2(Math::atan2(v[m_idx].x, v[m_idx].z) / Math_PI * 0.5 + 0.5, v[m_idx].y * 0.5 + 0.5)); \
+ set_tangent(Plane(Vector3(-v[m_idx].z, v[m_idx].y, v[m_idx].x), 1)); \
+ } \
+ set_normal(v[m_idx]); \
+ add_vertex(v[m_idx] * p_radius);
ADD_POINT(0);
ADD_POINT(1);
@@ -149,37 +138,30 @@ void ImmediateGeometry::add_sphere(int p_lats, int p_lons, float p_radius, bool
ADD_POINT(0);
}
}
-
}
void ImmediateGeometry::_bind_methods() {
- ClassDB::bind_method(D_METHOD("begin","primitive","texture:Texture"),&ImmediateGeometry::begin,DEFVAL(Ref<Texture>()));
- ClassDB::bind_method(D_METHOD("set_normal","normal"),&ImmediateGeometry::set_normal);
- ClassDB::bind_method(D_METHOD("set_tangent","tangent"),&ImmediateGeometry::set_tangent);
- ClassDB::bind_method(D_METHOD("set_color","color"),&ImmediateGeometry::set_color);
- ClassDB::bind_method(D_METHOD("set_uv","uv"),&ImmediateGeometry::set_uv);
- ClassDB::bind_method(D_METHOD("set_uv2","uv"),&ImmediateGeometry::set_uv2);
- ClassDB::bind_method(D_METHOD("add_vertex","pos"),&ImmediateGeometry::add_vertex);
- ClassDB::bind_method(D_METHOD("add_sphere","lats","lons","radius","add_uv"),&ImmediateGeometry::add_sphere,DEFVAL(true));
- ClassDB::bind_method(D_METHOD("end"),&ImmediateGeometry::end);
- ClassDB::bind_method(D_METHOD("clear"),&ImmediateGeometry::clear);
-
+ ClassDB::bind_method(D_METHOD("begin", "primitive", "texture:Texture"), &ImmediateGeometry::begin, DEFVAL(Ref<Texture>()));
+ ClassDB::bind_method(D_METHOD("set_normal", "normal"), &ImmediateGeometry::set_normal);
+ ClassDB::bind_method(D_METHOD("set_tangent", "tangent"), &ImmediateGeometry::set_tangent);
+ ClassDB::bind_method(D_METHOD("set_color", "color"), &ImmediateGeometry::set_color);
+ ClassDB::bind_method(D_METHOD("set_uv", "uv"), &ImmediateGeometry::set_uv);
+ ClassDB::bind_method(D_METHOD("set_uv2", "uv"), &ImmediateGeometry::set_uv2);
+ ClassDB::bind_method(D_METHOD("add_vertex", "pos"), &ImmediateGeometry::add_vertex);
+ ClassDB::bind_method(D_METHOD("add_sphere", "lats", "lons", "radius", "add_uv"), &ImmediateGeometry::add_sphere, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("end"), &ImmediateGeometry::end);
+ ClassDB::bind_method(D_METHOD("clear"), &ImmediateGeometry::clear);
}
-
-
ImmediateGeometry::ImmediateGeometry() {
im = VisualServer::get_singleton()->immediate_create();
set_base(im);
- empty=true;
-
+ empty = true;
}
-
ImmediateGeometry::~ImmediateGeometry() {
VisualServer::get_singleton()->free(im);
-
}
diff --git a/scene/3d/immediate_geometry.h b/scene/3d/immediate_geometry.h
index e385a34da1..6e0123992c 100644
--- a/scene/3d/immediate_geometry.h
+++ b/scene/3d/immediate_geometry.h
@@ -34,8 +34,7 @@
class ImmediateGeometry : public GeometryInstance {
- GDCLASS(ImmediateGeometry,GeometryInstance);
-
+ GDCLASS(ImmediateGeometry, GeometryInstance);
RID im;
//a list of texures drawn need to be kept, to avoid references
@@ -43,28 +42,24 @@ class ImmediateGeometry : public GeometryInstance {
List<Ref<Texture> > cached_textures;
bool empty;
Rect3 aabb;
-protected:
+protected:
static void _bind_methods();
-public:
-
- void begin(Mesh::PrimitiveType p_primitive,const Ref<Texture>& p_texture=Ref<Texture>());
- void set_normal(const Vector3& p_normal);
- void set_tangent(const Plane& p_tangent);
- void set_color(const Color& p_color);
- void set_uv(const Vector2& tex_uv);
- void set_uv2(const Vector2& tex_uv);
+public:
+ void begin(Mesh::PrimitiveType p_primitive, const Ref<Texture> &p_texture = Ref<Texture>());
+ void set_normal(const Vector3 &p_normal);
+ void set_tangent(const Plane &p_tangent);
+ void set_color(const Color &p_color);
+ void set_uv(const Vector2 &tex_uv);
+ void set_uv2(const Vector2 &tex_uv);
- void add_vertex(const Vector3& p_vertex);
+ void add_vertex(const Vector3 &p_vertex);
void end();
void clear();
-
- void add_sphere(int p_lats,int p_lons,float p_radius,bool p_add_uv=true);
-
-
+ void add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv = true);
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
diff --git a/scene/3d/interpolated_camera.cpp b/scene/3d/interpolated_camera.cpp
index 15ee971b7e..9723a686c5 100644
--- a/scene/3d/interpolated_camera.cpp
+++ b/scene/3d/interpolated_camera.cpp
@@ -28,10 +28,9 @@
/*************************************************************************/
#include "interpolated_camera.h"
-
void InterpolatedCamera::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (get_tree()->is_editor_hint() && enabled)
@@ -48,32 +47,30 @@ void InterpolatedCamera::_notification(int p_what) {
if (!node)
break;
- float delta = speed*get_process_delta_time();
+ float delta = speed * get_process_delta_time();
Transform target_xform = node->get_global_transform();
Transform local_transform = get_global_transform();
- local_transform = local_transform.interpolate_with(target_xform,delta);
+ local_transform = local_transform.interpolate_with(target_xform, delta);
set_global_transform(local_transform);
if (node->cast_to<Camera>()) {
Camera *cam = node->cast_to<Camera>();
- if (cam->get_projection()==get_projection()) {
+ if (cam->get_projection() == get_projection()) {
- float new_near = Math::lerp(get_znear(),cam->get_znear(),delta);
- float new_far = Math::lerp(get_zfar(),cam->get_zfar(),delta);
+ float new_near = Math::lerp(get_znear(), cam->get_znear(), delta);
+ float new_far = Math::lerp(get_zfar(), cam->get_zfar(), delta);
- if (cam->get_projection()==PROJECTION_ORTHOGONAL) {
+ if (cam->get_projection() == PROJECTION_ORTHOGONAL) {
- float size = Math::lerp(get_size(),cam->get_size(),delta);
- set_orthogonal(size,new_near,new_far);
+ float size = Math::lerp(get_size(), cam->get_size(), delta);
+ set_orthogonal(size, new_near, new_far);
} else {
- float fov = Math::lerp(get_fov(),cam->get_fov(),delta);
- set_perspective(fov,new_near,new_far);
+ float fov = Math::lerp(get_fov(), cam->get_fov(), delta);
+ set_perspective(fov, new_near, new_far);
}
}
}
-
-
}
} break;
@@ -89,25 +86,24 @@ void InterpolatedCamera::_set_target(const Object *p_target) {
void InterpolatedCamera::set_target(const Spatial *p_target) {
ERR_FAIL_NULL(p_target);
- target=get_path_to(p_target);
+ target = get_path_to(p_target);
}
+void InterpolatedCamera::set_target_path(const NodePath &p_path) {
-void InterpolatedCamera::set_target_path(const NodePath& p_path){
-
- target=p_path;
+ target = p_path;
}
-NodePath InterpolatedCamera::get_target_path() const{
+NodePath InterpolatedCamera::get_target_path() const {
return target;
}
void InterpolatedCamera::set_interpolation_enabled(bool p_enable) {
- if (enabled==p_enable)
+ if (enabled == p_enable)
return;
- enabled=p_enable;
+ enabled = p_enable;
if (p_enable) {
if (is_inside_tree() && get_tree()->is_editor_hint())
return;
@@ -123,7 +119,7 @@ bool InterpolatedCamera::is_interpolation_enabled() const {
void InterpolatedCamera::set_speed(real_t p_speed) {
- speed=p_speed;
+ speed = p_speed;
}
real_t InterpolatedCamera::get_speed() const {
@@ -131,27 +127,25 @@ real_t InterpolatedCamera::get_speed() const {
return speed;
}
-
void InterpolatedCamera::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_target_path","target_path"),&InterpolatedCamera::set_target_path);
- ClassDB::bind_method(D_METHOD("get_target_path"),&InterpolatedCamera::get_target_path);
- ClassDB::bind_method(D_METHOD("set_target","target:Camera"),&InterpolatedCamera::_set_target);
+ ClassDB::bind_method(D_METHOD("set_target_path", "target_path"), &InterpolatedCamera::set_target_path);
+ ClassDB::bind_method(D_METHOD("get_target_path"), &InterpolatedCamera::get_target_path);
+ ClassDB::bind_method(D_METHOD("set_target", "target:Camera"), &InterpolatedCamera::_set_target);
- ClassDB::bind_method(D_METHOD("set_speed","speed"),&InterpolatedCamera::set_speed);
- ClassDB::bind_method(D_METHOD("get_speed"),&InterpolatedCamera::get_speed);
+ ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InterpolatedCamera::set_speed);
+ ClassDB::bind_method(D_METHOD("get_speed"), &InterpolatedCamera::get_speed);
- ClassDB::bind_method(D_METHOD("set_interpolation_enabled","target_path"),&InterpolatedCamera::set_interpolation_enabled);
- ClassDB::bind_method(D_METHOD("is_interpolation_enabled"),&InterpolatedCamera::is_interpolation_enabled);
+ ClassDB::bind_method(D_METHOD("set_interpolation_enabled", "target_path"), &InterpolatedCamera::set_interpolation_enabled);
+ ClassDB::bind_method(D_METHOD("is_interpolation_enabled"), &InterpolatedCamera::is_interpolation_enabled);
- ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"target"), "set_target_path", "get_target_path") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"speed"), "set_speed", "get_speed") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"), "set_interpolation_enabled", "is_interpolation_enabled") ;
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target"), "set_target_path", "get_target_path");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed"), "set_speed", "get_speed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_interpolation_enabled", "is_interpolation_enabled");
}
InterpolatedCamera::InterpolatedCamera() {
- enabled=false;
- speed=1;
-
+ enabled = false;
+ speed = 1;
}
diff --git a/scene/3d/interpolated_camera.h b/scene/3d/interpolated_camera.h
index c78e6935da..ebadf39946 100644
--- a/scene/3d/interpolated_camera.h
+++ b/scene/3d/interpolated_camera.h
@@ -33,21 +33,20 @@
class InterpolatedCamera : public Camera {
- GDCLASS(InterpolatedCamera,Camera);
+ GDCLASS(InterpolatedCamera, Camera);
bool enabled;
real_t speed;
NodePath target;
-protected:
+protected:
void _notification(int p_what);
static void _bind_methods();
void _set_target(const Object *p_target);
public:
-
void set_target(const Spatial *p_target);
- void set_target_path(const NodePath& p_path);
+ void set_target_path(const NodePath &p_path);
NodePath get_target_path() const;
void set_speed(real_t p_speed);
@@ -56,7 +55,6 @@ public:
void set_interpolation_enabled(bool p_enable);
bool is_interpolation_enabled() const;
-
InterpolatedCamera();
};
diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp
index 473bca8d3b..7d01230517 100644
--- a/scene/3d/light.cpp
+++ b/scene/3d/light.cpp
@@ -28,108 +28,99 @@
/*************************************************************************/
#include "light.h"
+#include "baked_light_instance.h"
#include "global_config.h"
#include "scene/resources/surface_tool.h"
-#include "baked_light_instance.h"
-
bool Light::_can_gizmo_scale() const {
return false;
}
-
void Light::set_param(Param p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- param[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ param[p_param] = p_value;
- VS::get_singleton()->light_set_param(light,VS::LightParam(p_param),p_value);
+ VS::get_singleton()->light_set_param(light, VS::LightParam(p_param), p_value);
- if (p_param==PARAM_SPOT_ANGLE || p_param==PARAM_RANGE) {
+ if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) {
update_gizmo();
}
-
-
}
-float Light::get_param(Param p_param) const{
+float Light::get_param(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return param[p_param];
-
}
-void Light::set_shadow(bool p_enable){
-
- shadow=p_enable;
- VS::get_singleton()->light_set_shadow(light,p_enable);
+void Light::set_shadow(bool p_enable) {
+ shadow = p_enable;
+ VS::get_singleton()->light_set_shadow(light, p_enable);
}
-bool Light::has_shadow() const{
+bool Light::has_shadow() const {
return shadow;
}
-void Light::set_negative(bool p_enable){
+void Light::set_negative(bool p_enable) {
- negative=p_enable;
- VS::get_singleton()->light_set_negative(light,p_enable);
+ negative = p_enable;
+ VS::get_singleton()->light_set_negative(light, p_enable);
}
-bool Light::is_negative() const{
+bool Light::is_negative() const {
return negative;
}
-void Light::set_cull_mask(uint32_t p_cull_mask){
-
- cull_mask=p_cull_mask;
- VS::get_singleton()->light_set_cull_mask(light,p_cull_mask);
+void Light::set_cull_mask(uint32_t p_cull_mask) {
+ cull_mask = p_cull_mask;
+ VS::get_singleton()->light_set_cull_mask(light, p_cull_mask);
}
-uint32_t Light::get_cull_mask() const{
+uint32_t Light::get_cull_mask() const {
return cull_mask;
}
-void Light::set_color(const Color& p_color){
+void Light::set_color(const Color &p_color) {
- color=p_color;
- VS::get_singleton()->light_set_color(light,p_color);
+ color = p_color;
+ VS::get_singleton()->light_set_color(light, p_color);
}
-Color Light::get_color() const{
+Color Light::get_color() const {
return color;
}
-void Light::set_shadow_color(const Color& p_shadow_color){
+void Light::set_shadow_color(const Color &p_shadow_color) {
- shadow_color=p_shadow_color;
- VS::get_singleton()->light_set_shadow_color(light,p_shadow_color);
+ shadow_color = p_shadow_color;
+ VS::get_singleton()->light_set_shadow_color(light, p_shadow_color);
}
-Color Light::get_shadow_color() const{
+Color Light::get_shadow_color() const {
return shadow_color;
}
-
Rect3 Light::get_aabb() const {
+ if (type == VisualServer::LIGHT_DIRECTIONAL) {
- if (type==VisualServer::LIGHT_DIRECTIONAL) {
-
- return Rect3( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) );
+ return Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2));
- } else if (type==VisualServer::LIGHT_OMNI) {
+ } else if (type == VisualServer::LIGHT_OMNI) {
- return Rect3( Vector3(-1,-1,-1) * param[PARAM_RANGE], Vector3(2, 2, 2 ) * param[PARAM_RANGE]);
+ return Rect3(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]);
- } else if (type==VisualServer::LIGHT_SPOT) {
+ } else if (type == VisualServer::LIGHT_SPOT) {
- float len=param[PARAM_RANGE];
- float size=Math::tan(Math::deg2rad(param[PARAM_SPOT_ANGLE]))*len;
- return Rect3( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) );
+ float len = param[PARAM_RANGE];
+ float size = Math::tan(Math::deg2rad(param[PARAM_SPOT_ANGLE])) * len;
+ return Rect3(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
}
return Rect3();
@@ -140,187 +131,169 @@ PoolVector<Face3> Light::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
}
-
-
void Light::_update_visibility() {
if (!is_inside_tree())
return;
-
- bool editor_ok=true;
+ bool editor_ok = true;
#ifdef TOOLS_ENABLED
if (editor_only) {
if (!get_tree()->is_editor_hint()) {
- editor_ok=false;
+ editor_ok = false;
} else {
- editor_ok = (get_tree()->get_edited_scene_root() && (this==get_tree()->get_edited_scene_root() || get_owner()==get_tree()->get_edited_scene_root()));
+ editor_ok = (get_tree()->get_edited_scene_root() && (this == get_tree()->get_edited_scene_root() || get_owner() == get_tree()->get_edited_scene_root()));
}
}
#else
if (editor_only) {
- editor_ok=false;
+ editor_ok = false;
}
#endif
//VS::get_singleton()->instance_light_set_enabled(get_instance(),is_visible_in_tree() && editor_ok);
_change_notify("geometry/visible");
-
}
-
void Light::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
+ if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
_update_visibility();
-
}
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
_update_visibility();
Node *node = this;
- while(node) {
+ while (node) {
- baked_light=node->cast_to<BakedLight>();
+ baked_light = node->cast_to<BakedLight>();
if (baked_light) {
baked_light->lights.insert(this);
break;
}
- node=node->get_parent();
+ node = node->get_parent();
}
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
+ if (p_what == NOTIFICATION_EXIT_TREE) {
if (baked_light) {
baked_light->lights.erase(this);
}
}
-
}
-
void Light::set_editor_only(bool p_editor_only) {
- editor_only=p_editor_only;
+ editor_only = p_editor_only;
_update_visibility();
}
-bool Light::is_editor_only() const{
+bool Light::is_editor_only() const {
return editor_only;
}
-
void Light::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("set_editor_only","editor_only"), &Light::set_editor_only );
- ClassDB::bind_method(D_METHOD("is_editor_only"), &Light::is_editor_only );
-
-
- ClassDB::bind_method(D_METHOD("set_param","param","value"), &Light::set_param );
- ClassDB::bind_method(D_METHOD("get_param","param"), &Light::get_param );
-
- ClassDB::bind_method(D_METHOD("set_shadow","enabled"), &Light::set_shadow );
- ClassDB::bind_method(D_METHOD("has_shadow"), &Light::has_shadow );
-
- ClassDB::bind_method(D_METHOD("set_negative","enabled"), &Light::set_negative );
- ClassDB::bind_method(D_METHOD("is_negative"), &Light::is_negative );
-
- ClassDB::bind_method(D_METHOD("set_cull_mask","cull_mask"), &Light::set_cull_mask );
- ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light::get_cull_mask );
-
- ClassDB::bind_method(D_METHOD("set_color","color"), &Light::set_color );
- ClassDB::bind_method(D_METHOD("get_color"), &Light::get_color );
-
- ClassDB::bind_method(D_METHOD("set_shadow_color","shadow_color"), &Light::set_shadow_color );
- ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light::get_shadow_color );
-
- ADD_GROUP("Light","light_");
- ADD_PROPERTY( PropertyInfo( Variant::COLOR, "light_color",PROPERTY_HINT_COLOR_NO_ALPHA), "set_color", "get_color");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light_energy",PROPERTY_HINT_RANGE,"0,16,0.01"), "set_param", "get_param", PARAM_ENERGY);
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "light_negative"), "set_negative", "is_negative");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light_specular",PROPERTY_HINT_RANGE,"0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR);
- ADD_PROPERTY( PropertyInfo( Variant::INT, "light_cull_mask",PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
- ADD_GROUP("Shadow","shadow_");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow");
- ADD_PROPERTY( PropertyInfo( Variant::COLOR, "shadow_color",PROPERTY_HINT_COLOR_NO_ALPHA), "set_shadow_color", "get_shadow_color");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow_bias",PROPERTY_HINT_RANGE,"-16,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow_contact",PROPERTY_HINT_RANGE,"0,16,0.01"), "set_param", "get_param", PARAM_CONTACT_SHADOW_SIZE);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow_max_distance",PROPERTY_HINT_RANGE,"0,65536,0.1"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE);
- ADD_GROUP("Editor","");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
- ADD_GROUP("","");
-
- BIND_CONSTANT( PARAM_ENERGY );
- BIND_CONSTANT( PARAM_SPECULAR );
- BIND_CONSTANT( PARAM_RANGE );
- BIND_CONSTANT( PARAM_ATTENUATION );
- BIND_CONSTANT( PARAM_SPOT_ANGLE );
- BIND_CONSTANT( PARAM_SPOT_ATTENUATION );
- BIND_CONSTANT( PARAM_CONTACT_SHADOW_SIZE );
- BIND_CONSTANT( PARAM_SHADOW_MAX_DISTANCE );
- BIND_CONSTANT( PARAM_SHADOW_SPLIT_1_OFFSET );
- BIND_CONSTANT( PARAM_SHADOW_SPLIT_2_OFFSET );
- BIND_CONSTANT( PARAM_SHADOW_SPLIT_3_OFFSET );
- BIND_CONSTANT( PARAM_SHADOW_NORMAL_BIAS );
- BIND_CONSTANT( PARAM_SHADOW_BIAS );
- BIND_CONSTANT( PARAM_SHADOW_BIAS_SPLIT_SCALE );
- BIND_CONSTANT( PARAM_MAX );
-
-
+ ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light::set_editor_only);
+ ClassDB::bind_method(D_METHOD("is_editor_only"), &Light::is_editor_only);
+
+ ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light::set_param);
+ ClassDB::bind_method(D_METHOD("get_param", "param"), &Light::get_param);
+
+ ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light::set_shadow);
+ ClassDB::bind_method(D_METHOD("has_shadow"), &Light::has_shadow);
+
+ ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light::set_negative);
+ ClassDB::bind_method(D_METHOD("is_negative"), &Light::is_negative);
+
+ ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light::set_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light::get_cull_mask);
+
+ ClassDB::bind_method(D_METHOD("set_color", "color"), &Light::set_color);
+ ClassDB::bind_method(D_METHOD("get_color"), &Light::get_color);
+
+ ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light::set_shadow_color);
+ ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light::get_shadow_color);
+
+ ADD_GROUP("Light", "light_");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_color", "get_color");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_ENERGY);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "light_cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
+ ADD_GROUP("Shadow", "shadow_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_shadow_color", "get_shadow_color");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_contact", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_CONTACT_SHADOW_SIZE);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_max_distance", PROPERTY_HINT_RANGE, "0,65536,0.1"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE);
+ ADD_GROUP("Editor", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
+ ADD_GROUP("", "");
+
+ BIND_CONSTANT(PARAM_ENERGY);
+ BIND_CONSTANT(PARAM_SPECULAR);
+ BIND_CONSTANT(PARAM_RANGE);
+ BIND_CONSTANT(PARAM_ATTENUATION);
+ BIND_CONSTANT(PARAM_SPOT_ANGLE);
+ BIND_CONSTANT(PARAM_SPOT_ATTENUATION);
+ BIND_CONSTANT(PARAM_CONTACT_SHADOW_SIZE);
+ BIND_CONSTANT(PARAM_SHADOW_MAX_DISTANCE);
+ BIND_CONSTANT(PARAM_SHADOW_SPLIT_1_OFFSET);
+ BIND_CONSTANT(PARAM_SHADOW_SPLIT_2_OFFSET);
+ BIND_CONSTANT(PARAM_SHADOW_SPLIT_3_OFFSET);
+ BIND_CONSTANT(PARAM_SHADOW_NORMAL_BIAS);
+ BIND_CONSTANT(PARAM_SHADOW_BIAS);
+ BIND_CONSTANT(PARAM_SHADOW_BIAS_SPLIT_SCALE);
+ BIND_CONSTANT(PARAM_MAX);
}
-
Light::Light(VisualServer::LightType p_type) {
- type=p_type;
- light=VisualServer::get_singleton()->light_create(p_type);
- VS::get_singleton()->instance_set_base(get_instance(),light);
+ type = p_type;
+ light = VisualServer::get_singleton()->light_create(p_type);
+ VS::get_singleton()->instance_set_base(get_instance(), light);
- baked_light=NULL;
+ baked_light = NULL;
- editor_only=false;
- set_color(Color(1,1,1,1));
+ editor_only = false;
+ set_color(Color(1, 1, 1, 1));
set_shadow(false);
set_negative(false);
set_cull_mask(0xFFFFFFFF);
- set_param(PARAM_ENERGY,1);
- set_param(PARAM_SPECULAR,0.5);
- set_param(PARAM_RANGE,5);
- set_param(PARAM_ATTENUATION,1);
- set_param(PARAM_SPOT_ANGLE,45);
- set_param(PARAM_SPOT_ATTENUATION,1);
- set_param(PARAM_CONTACT_SHADOW_SIZE,0);
- set_param(PARAM_SHADOW_MAX_DISTANCE,0);
- set_param(PARAM_SHADOW_SPLIT_1_OFFSET,0.1);
- set_param(PARAM_SHADOW_SPLIT_2_OFFSET,0.2);
- set_param(PARAM_SHADOW_SPLIT_3_OFFSET,0.5);
- set_param(PARAM_SHADOW_NORMAL_BIAS,0.1);
- set_param(PARAM_SHADOW_BIAS,0.1);
- set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE,0.1);
-
+ set_param(PARAM_ENERGY, 1);
+ set_param(PARAM_SPECULAR, 0.5);
+ set_param(PARAM_RANGE, 5);
+ set_param(PARAM_ATTENUATION, 1);
+ set_param(PARAM_SPOT_ANGLE, 45);
+ set_param(PARAM_SPOT_ATTENUATION, 1);
+ set_param(PARAM_CONTACT_SHADOW_SIZE, 0);
+ set_param(PARAM_SHADOW_MAX_DISTANCE, 0);
+ set_param(PARAM_SHADOW_SPLIT_1_OFFSET, 0.1);
+ set_param(PARAM_SHADOW_SPLIT_2_OFFSET, 0.2);
+ set_param(PARAM_SHADOW_SPLIT_3_OFFSET, 0.5);
+ set_param(PARAM_SHADOW_NORMAL_BIAS, 0.1);
+ set_param(PARAM_SHADOW_BIAS, 0.1);
+ set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE, 0.1);
}
-
Light::Light() {
- type=VisualServer::LIGHT_DIRECTIONAL;
+ type = VisualServer::LIGHT_DIRECTIONAL;
ERR_PRINT("Light shouldn't be instanced dircetly, use the subtypes.");
}
-
Light::~Light() {
- VS::get_singleton()->instance_set_base(get_instance(),RID());
+ VS::get_singleton()->instance_set_base(get_instance(), RID());
if (light.is_valid())
VisualServer::get_singleton()->free(light);
@@ -329,8 +302,8 @@ Light::~Light() {
void DirectionalLight::set_shadow_mode(ShadowMode p_mode) {
- shadow_mode=p_mode;
- VS::get_singleton()->light_directional_set_shadow_mode(light,VS::LightDirectionalShadowMode(p_mode));
+ shadow_mode = p_mode;
+ VS::get_singleton()->light_directional_set_shadow_mode(light, VS::LightDirectionalShadowMode(p_mode));
}
DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const {
@@ -340,8 +313,8 @@ DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const {
void DirectionalLight::set_blend_splits(bool p_enable) {
- blend_splits=p_enable;
- VS::get_singleton()->light_directional_set_blend_splits(light,p_enable);
+ blend_splits = p_enable;
+ VS::get_singleton()->light_directional_set_blend_splits(light, p_enable);
}
bool DirectionalLight::is_blend_splits_enabled() const {
@@ -349,90 +322,83 @@ bool DirectionalLight::is_blend_splits_enabled() const {
return blend_splits;
}
-
void DirectionalLight::_bind_methods() {
- ClassDB::bind_method( D_METHOD("set_shadow_mode","mode"),&DirectionalLight::set_shadow_mode);
- ClassDB::bind_method( D_METHOD("get_shadow_mode"),&DirectionalLight::get_shadow_mode);
+ ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight::set_shadow_mode);
+ ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight::get_shadow_mode);
- ClassDB::bind_method( D_METHOD("set_blend_splits","enabled"),&DirectionalLight::set_blend_splits);
- ClassDB::bind_method( D_METHOD("is_blend_splits_enabled"),&DirectionalLight::is_blend_splits_enabled);
+ ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight::set_blend_splits);
+ ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight::is_blend_splits_enabled);
- ADD_GROUP("Directional Shadow","directional_shadow_");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "directional_shadow_mode",PROPERTY_HINT_ENUM,"Orthogonal,PSSM 2 Splits,PSSM 4 Splits"), "set_shadow_mode", "get_shadow_mode");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional_shadow_split_1",PROPERTY_HINT_RANGE,"0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_1_OFFSET);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional_shadow_split_2",PROPERTY_HINT_RANGE,"0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_2_OFFSET);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional_shadow_split_3",PROPERTY_HINT_RANGE,"0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET);
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional_shadow_normal_bias",PROPERTY_HINT_RANGE,"0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional_shadow_bias_split_scale",PROPERTY_HINT_RANGE,"0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS_SPLIT_SCALE);
-
- BIND_CONSTANT( SHADOW_ORTHOGONAL );
- BIND_CONSTANT( SHADOW_PARALLEL_2_SPLITS );
- BIND_CONSTANT( SHADOW_PARALLEL_4_SPLITS );
+ ADD_GROUP("Directional Shadow", "directional_shadow_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_mode", PROPERTY_HINT_ENUM, "Orthogonal,PSSM 2 Splits,PSSM 4 Splits"), "set_shadow_mode", "get_shadow_mode");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_split_1", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_1_OFFSET);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_split_2", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_2_OFFSET);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_split_3", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_normal_bias", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_bias_split_scale", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS_SPLIT_SCALE);
+ BIND_CONSTANT(SHADOW_ORTHOGONAL);
+ BIND_CONSTANT(SHADOW_PARALLEL_2_SPLITS);
+ BIND_CONSTANT(SHADOW_PARALLEL_4_SPLITS);
}
-
-DirectionalLight::DirectionalLight() : Light( VisualServer::LIGHT_DIRECTIONAL ) {
+DirectionalLight::DirectionalLight()
+ : Light(VisualServer::LIGHT_DIRECTIONAL) {
set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
- blend_splits=false;
+ blend_splits = false;
}
void OmniLight::set_shadow_mode(ShadowMode p_mode) {
- shadow_mode=p_mode;
- VS::get_singleton()->light_omni_set_shadow_mode(light,VS::LightOmniShadowMode(p_mode));
+ shadow_mode = p_mode;
+ VS::get_singleton()->light_omni_set_shadow_mode(light, VS::LightOmniShadowMode(p_mode));
}
-OmniLight::ShadowMode OmniLight::get_shadow_mode() const{
+OmniLight::ShadowMode OmniLight::get_shadow_mode() const {
return shadow_mode;
}
-void OmniLight::set_shadow_detail(ShadowDetail p_detail){
+void OmniLight::set_shadow_detail(ShadowDetail p_detail) {
- shadow_detail=p_detail;
- VS::get_singleton()->light_omni_set_shadow_detail(light,VS::LightOmniShadowDetail(p_detail));
+ shadow_detail = p_detail;
+ VS::get_singleton()->light_omni_set_shadow_detail(light, VS::LightOmniShadowDetail(p_detail));
}
-OmniLight::ShadowDetail OmniLight::get_shadow_detail() const{
+OmniLight::ShadowDetail OmniLight::get_shadow_detail() const {
return shadow_detail;
}
-
-
-
void OmniLight::_bind_methods() {
- ClassDB::bind_method( D_METHOD("set_shadow_mode","mode"),&OmniLight::set_shadow_mode);
- ClassDB::bind_method( D_METHOD("get_shadow_mode"),&OmniLight::get_shadow_mode);
-
- ClassDB::bind_method( D_METHOD("set_shadow_detail","detail"),&OmniLight::set_shadow_detail);
- ClassDB::bind_method( D_METHOD("get_shadow_detail"),&OmniLight::get_shadow_detail);
+ ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight::set_shadow_mode);
+ ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight::get_shadow_mode);
- ADD_GROUP("Omni","omni_");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "omni_range",PROPERTY_HINT_RANGE,"0,65536,0.1"), "set_param", "get_param", PARAM_RANGE);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "omni_attenuation",PROPERTY_HINT_EXP_EASING), "set_param", "get_param", PARAM_ATTENUATION);
- ADD_PROPERTY( PropertyInfo( Variant::INT, "omni_shadow_mode",PROPERTY_HINT_ENUM,"Dual Paraboloid,Cube"), "set_shadow_mode", "get_shadow_mode");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "omni_shadow_detail",PROPERTY_HINT_ENUM,"Vertical,Horizontal"), "set_shadow_detail", "get_shadow_detail");
+ ClassDB::bind_method(D_METHOD("set_shadow_detail", "detail"), &OmniLight::set_shadow_detail);
+ ClassDB::bind_method(D_METHOD("get_shadow_detail"), &OmniLight::get_shadow_detail);
+ ADD_GROUP("Omni", "omni_");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "omni_range", PROPERTY_HINT_RANGE, "0,65536,0.1"), "set_param", "get_param", PARAM_RANGE);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "omni_attenuation", PROPERTY_HINT_EXP_EASING), "set_param", "get_param", PARAM_ATTENUATION);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "omni_shadow_mode", PROPERTY_HINT_ENUM, "Dual Paraboloid,Cube"), "set_shadow_mode", "get_shadow_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "omni_shadow_detail", PROPERTY_HINT_ENUM, "Vertical,Horizontal"), "set_shadow_detail", "get_shadow_detail");
}
-OmniLight::OmniLight() : Light( VisualServer::LIGHT_OMNI ) {
+OmniLight::OmniLight()
+ : Light(VisualServer::LIGHT_OMNI) {
set_shadow_mode(SHADOW_DUAL_PARABOLOID);
set_shadow_detail(SHADOW_DETAIL_HORIZONTAL);
-
}
void SpotLight::_bind_methods() {
- ADD_GROUP("Spot","spot_");
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot_range",PROPERTY_HINT_RANGE,"0,65536,0.1"), "set_param", "get_param", PARAM_RANGE);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot_attenuation",PROPERTY_HINT_EXP_EASING), "set_param", "get_param", PARAM_ATTENUATION);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot_angle",PROPERTY_HINT_RANGE,"0,180,0.1"), "set_param", "get_param", PARAM_SPOT_ANGLE);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot_angle_attenuation",PROPERTY_HINT_EXP_EASING), "set_param", "get_param", PARAM_SPOT_ATTENUATION);
-
+ ADD_GROUP("Spot", "spot_");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_range", PROPERTY_HINT_RANGE, "0,65536,0.1"), "set_param", "get_param", PARAM_RANGE);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_attenuation", PROPERTY_HINT_EXP_EASING), "set_param", "get_param", PARAM_ATTENUATION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_angle", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_param", "get_param", PARAM_SPOT_ANGLE);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_angle_attenuation", PROPERTY_HINT_EXP_EASING), "set_param", "get_param", PARAM_SPOT_ATTENUATION);
}
diff --git a/scene/3d/light.h b/scene/3d/light.h
index 4cf0156d5c..fd50f0fcc4 100644
--- a/scene/3d/light.h
+++ b/scene/3d/light.h
@@ -29,7 +29,6 @@
#ifndef LIGHT_H
#define LIGHT_H
-
#include "scene/3d/visual_instance.h"
#include "scene/resources/texture.h"
#include "servers/visual_server.h"
@@ -38,16 +37,14 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
class BakedLight;
class Light : public VisualInstance {
- GDCLASS( Light, VisualInstance );
+ GDCLASS(Light, VisualInstance);
OBJ_CATEGORY("3D Light Nodes");
public:
-
enum Param {
PARAM_ENERGY = VS::LIGHT_PARAM_ENERGY,
PARAM_SPECULAR = VS::LIGHT_PARAM_SPECULAR,
@@ -55,7 +52,7 @@ public:
PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION,
PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE,
PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION,
- PARAM_CONTACT_SHADOW_SIZE= VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE,
+ PARAM_CONTACT_SHADOW_SIZE = VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE,
PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE,
PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET,
PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET,
@@ -67,7 +64,6 @@ public:
};
private:
-
Color color;
float param[PARAM_MAX];
Color shadow_color;
@@ -79,21 +75,19 @@ private:
void _update_visibility();
BakedLight *baked_light;
-// bind helpers
+ // bind helpers
protected:
-
RID light;
virtual bool _can_gizmo_scale() const;
-
+
static void _bind_methods();
void _notification(int p_what);
-
Light(VisualServer::LightType p_type);
-public:
+public:
VS::LightType get_light_type() const { return type; }
void set_editor_only(bool p_editor_only);
@@ -111,30 +105,26 @@ public:
void set_cull_mask(uint32_t p_cull_mask);
uint32_t get_cull_mask() const;
- void set_color(const Color& p_color);
+ void set_color(const Color &p_color);
Color get_color() const;
- void set_shadow_color(const Color& p_shadow_color);
+ void set_shadow_color(const Color &p_shadow_color);
Color get_shadow_color() const;
-
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
Light();
~Light();
-
};
VARIANT_ENUM_CAST(Light::Param);
-
class DirectionalLight : public Light {
- GDCLASS( DirectionalLight, Light );
+ GDCLASS(DirectionalLight, Light);
public:
-
enum ShadowMode {
SHADOW_ORTHOGONAL,
SHADOW_PARALLEL_2_SPLITS,
@@ -142,14 +132,13 @@ public:
};
private:
-
bool blend_splits;
ShadowMode shadow_mode;
protected:
static void _bind_methods();
-public:
+public:
void set_shadow_mode(ShadowMode p_mode);
ShadowMode get_shadow_mode() const;
@@ -163,7 +152,8 @@ VARIANT_ENUM_CAST(DirectionalLight::ShadowMode)
class OmniLight : public Light {
- GDCLASS( OmniLight, Light );
+ GDCLASS(OmniLight, Light);
+
public:
// omni light
enum ShadowMode {
@@ -178,14 +168,13 @@ public:
};
private:
-
ShadowMode shadow_mode;
ShadowDetail shadow_detail;
+
protected:
static void _bind_methods();
public:
-
void set_shadow_mode(ShadowMode p_mode);
ShadowMode get_shadow_mode() const;
@@ -200,14 +189,14 @@ VARIANT_ENUM_CAST(OmniLight::ShadowDetail)
class SpotLight : public Light {
- GDCLASS( SpotLight, Light );
+ GDCLASS(SpotLight, Light);
+
protected:
static void _bind_methods();
-public:
-
- SpotLight() : Light( VisualServer::LIGHT_SPOT ) {}
+public:
+ SpotLight()
+ : Light(VisualServer::LIGHT_SPOT) {}
};
-
#endif
diff --git a/scene/3d/listener.cpp b/scene/3d/listener.cpp
index 578044ad09..fc9326b571 100644
--- a/scene/3d/listener.cpp
+++ b/scene/3d/listener.cpp
@@ -31,8 +31,6 @@
#include "scene/resources/mesh.h"
void Listener::_update_audio_listener_state() {
-
-
}
void Listener::_request_listener_update() {
@@ -40,53 +38,48 @@ void Listener::_request_listener_update() {
_update_listener();
}
-bool Listener::_set(const StringName& p_name, const Variant& p_value) {
+bool Listener::_set(const StringName &p_name, const Variant &p_value) {
if (p_name == "current") {
if (p_value.operator bool()) {
make_current();
- }
- else {
+ } else {
clear_current();
}
- }
- else
+ } else
return false;
return true;
}
-bool Listener::_get(const StringName& p_name,Variant &r_ret) const {
+bool Listener::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name == "current") {
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
r_ret = current;
- }
- else {
+ } else {
r_ret = is_current();
}
- }
- else
+ } else
return false;
return true;
}
-void Listener::_get_property_list( List<PropertyInfo> *p_list) const {
+void Listener::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) );
+ p_list->push_back(PropertyInfo(Variant::BOOL, "current"));
}
void Listener::_update_listener() {
if (is_inside_tree() && is_current()) {
get_viewport()->_listener_transform_changed_notify();
-
}
}
void Listener::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
bool first_listener = get_viewport()->_listener_add(this);
@@ -101,24 +94,19 @@ void Listener::_notification(int p_what) {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
clear_current();
- current=true; //keep it true
+ current = true; //keep it true
} else {
- current=false;
+ current = false;
}
}
get_viewport()->_listener_remove(this);
-
} break;
-
-
}
-
}
-
Transform Listener::get_listener_transform() const {
return get_global_transform().orthonormalized();
@@ -126,7 +114,7 @@ Transform Listener::get_listener_transform() const {
void Listener::make_current() {
- current=true;
+ current = true;
if (!is_inside_tree())
return;
@@ -134,27 +122,23 @@ void Listener::make_current() {
get_viewport()->_listener_set(this);
}
-
-
-
void Listener::clear_current() {
- current=false;
+ current = false;
if (!is_inside_tree())
return;
- if (get_viewport()->get_listener()==this) {
+ if (get_viewport()->get_listener() == this) {
get_viewport()->_listener_set(NULL);
get_viewport()->_listener_make_next_current(this);
}
-
}
bool Listener::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
- return get_viewport()->get_listener()==this;
+ return get_viewport()->get_listener() == this;
} else
return current;
@@ -174,23 +158,19 @@ RES Listener::_get_gizmo_geometry() const {
void Listener::_bind_methods() {
- ClassDB::bind_method( D_METHOD("make_current"),&Listener::make_current );
- ClassDB::bind_method( D_METHOD("clear_current"),&Listener::clear_current );
- ClassDB::bind_method( D_METHOD("is_current"),&Listener::is_current );
- ClassDB::bind_method( D_METHOD("get_listener_transform"),&Listener::get_listener_transform );
+ ClassDB::bind_method(D_METHOD("make_current"), &Listener::make_current);
+ ClassDB::bind_method(D_METHOD("clear_current"), &Listener::clear_current);
+ ClassDB::bind_method(D_METHOD("is_current"), &Listener::is_current);
+ ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener::get_listener_transform);
}
Listener::Listener() {
- current=false;
- force_change=false;
+ current = false;
+ force_change = false;
set_notify_transform(true);
//active=false;
}
-
Listener::~Listener() {
-
}
-
-
diff --git a/scene/3d/listener.h b/scene/3d/listener.h
index 3b6e39bec5..4fb2aea072 100644
--- a/scene/3d/listener.h
+++ b/scene/3d/listener.h
@@ -29,15 +29,14 @@
#ifndef LISTENER_H
#define LISTENER_H
-
#include "scene/3d/spatial.h"
#include "scene/main/viewport.h"
class Listener : public Spatial {
GDCLASS(Listener, Spatial);
-private:
+private:
bool force_change;
bool current;
@@ -46,22 +45,21 @@ private:
virtual bool _can_gizmo_scale() const;
virtual RES _get_gizmo_geometry() const;
-friend class Viewport;
+ friend class Viewport;
void _update_audio_listener_state();
-protected:
+protected:
void _update_listener();
virtual void _request_listener_update();
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
-
void make_current();
void clear_current();
bool is_current() const;
@@ -75,7 +73,6 @@ public:
Listener();
~Listener();
-
};
#endif
diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp
index e6bd69aed2..b61232dbfd 100644
--- a/scene/3d/mesh_instance.cpp
+++ b/scene/3d/mesh_instance.cpp
@@ -28,12 +28,12 @@
/*************************************************************************/
#include "mesh_instance.h"
-#include "skeleton.h"
-#include "physics_body.h"
#include "body_shape.h"
-#include "scene/scene_string_names.h"
#include "core_string_names.h"
-bool MeshInstance::_set(const StringName& p_name, const Variant& p_value) {
+#include "physics_body.h"
+#include "scene/scene_string_names.h"
+#include "skeleton.h"
+bool MeshInstance::_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.
@@ -41,97 +41,91 @@ bool MeshInstance::_set(const StringName& p_name, const Variant& p_value) {
if (!get_instance().is_valid())
return false;
-
- Map<StringName,BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
+ Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
if (E) {
- E->get().value=p_value;
- VisualServer::get_singleton()->instance_set_blend_shape_weight(get_instance(),E->get().idx,E->get().value);
+ E->get().value = p_value;
+ VisualServer::get_singleton()->instance_set_blend_shape_weight(get_instance(), E->get().idx, E->get().value);
return true;
}
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)
+ int idx = p_name.operator String().get_slicec('/', 1).to_int();
+ if (idx >= materials.size() || idx < 0)
return false;
- set_surface_material(idx,p_value);
+ set_surface_material(idx, p_value);
return true;
}
return false;
}
-bool MeshInstance::_get(const StringName& p_name,Variant &r_ret) const {
-
+bool MeshInstance::_get(const StringName &p_name, Variant &r_ret) const {
if (!get_instance().is_valid())
return false;
- const Map<StringName,BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
+ const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
if (E) {
r_ret = E->get().value;
return true;
}
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)
+ int idx = p_name.operator String().get_slicec('/', 1).to_int();
+ if (idx >= materials.size() || idx < 0)
return false;
- r_ret=materials[idx];
+ r_ret = materials[idx];
return true;
}
return false;
}
-void MeshInstance::_get_property_list( List<PropertyInfo> *p_list) const {
+void MeshInstance::_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()) {
+ for (const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.front(); E; E = E->next()) {
ls.push_back(E->key());
}
ls.sort();
- for(List<String>::Element *E=ls.front();E;E=E->next()) {
- p_list->push_back( PropertyInfo(Variant::REAL,E->get(),PROPERTY_HINT_RANGE,"0,1,0.01"));
+ for (List<String>::Element *E = ls.front(); E; E = E->next()) {
+ p_list->push_back(PropertyInfo(Variant::REAL, E->get(), PROPERTY_HINT_RANGE, "0,1,0.01"));
}
if (mesh.is_valid()) {
- for(int i=0;i<mesh->get_surface_count();i++) {
- p_list->push_back( PropertyInfo(Variant::OBJECT, "material/"+itos(i), PROPERTY_HINT_RESOURCE_TYPE, "Material"));
+ for (int i = 0; i < mesh->get_surface_count(); i++) {
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "material/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "Material"));
}
}
}
+void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) {
-
-
-void MeshInstance::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,this,SceneStringNames::get_singleton()->_mesh_changed);
+ mesh->disconnect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->_mesh_changed);
materials.clear();
}
- mesh=p_mesh;
+ mesh = p_mesh;
blend_shape_tracks.clear();
if (mesh.is_valid()) {
-
- for(int i=0;i<mesh->get_blend_shape_count();i++) {
+ for (int i = 0; i < mesh->get_blend_shape_count(); i++) {
BlendShapeTrack mt;
- mt.idx=i;
- mt.value=0;
- blend_shape_tracks["blend_shapes/"+String(mesh->get_blend_shape_name(i))]=mt;
+ mt.idx = i;
+ mt.value = 0;
+ blend_shape_tracks["blend_shapes/" + String(mesh->get_blend_shape_name(i))] = mt;
}
- mesh->connect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_mesh_changed);
+ mesh->connect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->_mesh_changed);
materials.resize(mesh->get_surface_count());
set_base(mesh->get_rid());
@@ -147,14 +141,14 @@ Ref<Mesh> MeshInstance::get_mesh() const {
return mesh;
}
-void MeshInstance::_resolve_skeleton_path(){
+void MeshInstance::_resolve_skeleton_path() {
if (skeleton_path.is_empty())
return;
- Skeleton *skeleton=get_node(skeleton_path)?get_node(skeleton_path)->cast_to<Skeleton>():NULL;
+ Skeleton *skeleton = get_node(skeleton_path) ? get_node(skeleton_path)->cast_to<Skeleton>() : NULL;
if (skeleton)
- VisualServer::get_singleton()->instance_attach_skeleton( get_instance(), skeleton->get_skeleton() );
+ VisualServer::get_singleton()->instance_attach_skeleton(get_instance(), skeleton->get_skeleton());
}
void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) {
@@ -179,7 +173,7 @@ Rect3 MeshInstance::get_aabb() const {
PoolVector<Face3> MeshInstance::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 PoolVector<Face3>();
if (mesh.is_null())
@@ -188,8 +182,7 @@ PoolVector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const {
return mesh->get_faces();
}
-
-Node* MeshInstance::create_trimesh_collision_node() {
+Node *MeshInstance::create_trimesh_collision_node() {
if (mesh.is_null())
return NULL;
@@ -198,32 +191,28 @@ Node* MeshInstance::create_trimesh_collision_node() {
if (shape.is_null())
return NULL;
- StaticBody * static_body = memnew( StaticBody );
- static_body->add_shape( shape );
+ StaticBody *static_body = memnew(StaticBody);
+ static_body->add_shape(shape);
return static_body;
-
-
}
void MeshInstance::create_trimesh_collision() {
-
- StaticBody* static_body = create_trimesh_collision_node()->cast_to<StaticBody>();
+ StaticBody *static_body = create_trimesh_collision_node()->cast_to<StaticBody>();
ERR_FAIL_COND(!static_body);
- static_body->set_name( String(get_name()) + "_col" );
+ static_body->set_name(String(get_name()) + "_col");
add_child(static_body);
if (get_owner())
- static_body->set_owner( get_owner() );
- CollisionShape *cshape = memnew( CollisionShape );
+ static_body->set_owner(get_owner());
+ CollisionShape *cshape = memnew(CollisionShape);
cshape->set_shape(static_body->get_shape(0));
static_body->add_child(cshape);
if (get_owner())
- cshape->set_owner( get_owner() );
-
+ cshape->set_owner(get_owner());
}
-Node* MeshInstance::create_convex_collision_node() {
+Node *MeshInstance::create_convex_collision_node() {
if (mesh.is_null())
return NULL;
@@ -232,91 +221,78 @@ Node* MeshInstance::create_convex_collision_node() {
if (shape.is_null())
return NULL;
- StaticBody * static_body = memnew( StaticBody );
- static_body->add_shape( shape );
+ StaticBody *static_body = memnew(StaticBody);
+ static_body->add_shape(shape);
return static_body;
-
-
}
void MeshInstance::create_convex_collision() {
-
- StaticBody* static_body = create_convex_collision_node()->cast_to<StaticBody>();
+ StaticBody *static_body = create_convex_collision_node()->cast_to<StaticBody>();
ERR_FAIL_COND(!static_body);
- static_body->set_name( String(get_name()) + "_col" );
+ static_body->set_name(String(get_name()) + "_col");
add_child(static_body);
if (get_owner())
- static_body->set_owner( get_owner() );
- CollisionShape *cshape = memnew( CollisionShape );
+ static_body->set_owner(get_owner());
+ CollisionShape *cshape = memnew(CollisionShape);
cshape->set_shape(static_body->get_shape(0));
static_body->add_child(cshape);
if (get_owner())
- cshape->set_owner( get_owner() );
-
-
+ cshape->set_owner(get_owner());
}
void MeshInstance::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
_resolve_skeleton_path();
}
}
+void MeshInstance::set_surface_material(int p_surface, const Ref<Material> &p_material) {
-void MeshInstance::set_surface_material(int p_surface,const Ref<Material>& p_material) {
+ ERR_FAIL_INDEX(p_surface, materials.size());
- ERR_FAIL_INDEX(p_surface,materials.size());
-
- materials[p_surface]=p_material;
+ materials[p_surface] = p_material;
if (materials[p_surface].is_valid())
- VS::get_singleton()->instance_set_surface_material(get_instance(),p_surface,materials[p_surface]->get_rid());
+ VS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid());
else
- VS::get_singleton()->instance_set_surface_material(get_instance(),p_surface,RID());
-
+ VS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID());
}
Ref<Material> MeshInstance::get_surface_material(int p_surface) const {
- ERR_FAIL_INDEX_V(p_surface,materials.size(),Ref<Material>());
+ ERR_FAIL_INDEX_V(p_surface, materials.size(), Ref<Material>());
return materials[p_surface];
}
-
void MeshInstance::_mesh_changed() {
- materials.resize( mesh->get_surface_count() );
+ materials.resize(mesh->get_surface_count());
}
void MeshInstance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_mesh","mesh:Mesh"),&MeshInstance::set_mesh);
- ClassDB::bind_method(D_METHOD("get_mesh:Mesh"),&MeshInstance::get_mesh);
- ClassDB::bind_method(D_METHOD("set_skeleton_path","skeleton_path:NodePath"),&MeshInstance::set_skeleton_path);
- ClassDB::bind_method(D_METHOD("get_skeleton_path:NodePath"),&MeshInstance::get_skeleton_path);
+ ClassDB::bind_method(D_METHOD("set_mesh", "mesh:Mesh"), &MeshInstance::set_mesh);
+ ClassDB::bind_method(D_METHOD("get_mesh:Mesh"), &MeshInstance::get_mesh);
+ ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path:NodePath"), &MeshInstance::set_skeleton_path);
+ ClassDB::bind_method(D_METHOD("get_skeleton_path:NodePath"), &MeshInstance::get_skeleton_path);
- ClassDB::bind_method(D_METHOD("create_trimesh_collision"),&MeshInstance::create_trimesh_collision);
- ClassDB::set_method_flags("MeshInstance","create_trimesh_collision",METHOD_FLAGS_DEFAULT);
- ClassDB::bind_method(D_METHOD("create_convex_collision"),&MeshInstance::create_convex_collision);
- ClassDB::set_method_flags("MeshInstance","create_convex_collision",METHOD_FLAGS_DEFAULT);
- ClassDB::bind_method(D_METHOD("_mesh_changed"),&MeshInstance::_mesh_changed);
+ ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance::create_trimesh_collision);
+ ClassDB::set_method_flags("MeshInstance", "create_trimesh_collision", METHOD_FLAGS_DEFAULT);
+ ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance::create_convex_collision);
+ ClassDB::set_method_flags("MeshInstance", "create_convex_collision", METHOD_FLAGS_DEFAULT);
+ ClassDB::bind_method(D_METHOD("_mesh_changed"), &MeshInstance::_mesh_changed);
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh" ), "set_mesh", "get_mesh");
- ADD_PROPERTY( PropertyInfo (Variant::NODE_PATH, "skeleton"), "set_skeleton_path", "get_skeleton_path");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton"), "set_skeleton_path", "get_skeleton_path");
}
-MeshInstance::MeshInstance()
-{
- skeleton_path=NodePath("..");
+MeshInstance::MeshInstance() {
+ skeleton_path = NodePath("..");
}
-
MeshInstance::~MeshInstance() {
-
}
-
-
diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance.h
index 2d1af46980..543f407ca1 100644
--- a/scene/3d/mesh_instance.h
+++ b/scene/3d/mesh_instance.h
@@ -37,7 +37,7 @@
*/
class MeshInstance : public GeometryInstance {
- GDCLASS( MeshInstance, GeometryInstance );
+ GDCLASS(MeshInstance, GeometryInstance);
Ref<Mesh> mesh;
NodePath skeleton_path;
@@ -46,38 +46,40 @@ class MeshInstance : public GeometryInstance {
int idx;
float value;
- BlendShapeTrack() { idx=0; value=0; }
+ BlendShapeTrack() {
+ idx = 0;
+ value = 0;
+ }
};
- Map<StringName,BlendShapeTrack> blend_shape_tracks;
+ Map<StringName, BlendShapeTrack> blend_shape_tracks;
Vector<Ref<Material> > materials;
void _mesh_changed();
void _resolve_skeleton_path();
protected:
-
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_mesh(const Ref<Mesh>& p_mesh);
+public:
+ void set_mesh(const Ref<Mesh> &p_mesh);
Ref<Mesh> get_mesh() const;
- void set_skeleton_path(const NodePath& p_skeleton);
+ void set_skeleton_path(const NodePath &p_skeleton);
NodePath get_skeleton_path();
- void set_surface_material(int p_surface,const Ref<Material>& p_material);
+ void set_surface_material(int p_surface, const Ref<Material> &p_material);
Ref<Material> get_surface_material(int p_surface) const;
- Node* create_trimesh_collision_node();
+ Node *create_trimesh_collision_node();
void create_trimesh_collision();
- Node* create_convex_collision_node();
+ Node *create_convex_collision_node();
void create_convex_collision();
virtual Rect3 get_aabb() const;
diff --git a/scene/3d/multimesh_instance.cpp b/scene/3d/multimesh_instance.cpp
index e1acdfca53..18a747a5b9 100644
--- a/scene/3d/multimesh_instance.cpp
+++ b/scene/3d/multimesh_instance.cpp
@@ -28,27 +28,20 @@
/*************************************************************************/
#include "multimesh_instance.h"
-
-
-
-
void MultiMeshInstance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_multimesh","multimesh"),&MultiMeshInstance::set_multimesh);
- ClassDB::bind_method(D_METHOD("get_multimesh"),&MultiMeshInstance::get_multimesh);
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"multimesh",PROPERTY_HINT_RESOURCE_TYPE,"MultiMesh"), "set_multimesh", "get_multimesh");
-
-
+ ClassDB::bind_method(D_METHOD("set_multimesh", "multimesh"), &MultiMeshInstance::set_multimesh);
+ ClassDB::bind_method(D_METHOD("get_multimesh"), &MultiMeshInstance::get_multimesh);
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multimesh", PROPERTY_HINT_RESOURCE_TYPE, "MultiMesh"), "set_multimesh", "get_multimesh");
}
-void MultiMeshInstance::set_multimesh(const Ref<MultiMesh>& p_multimesh) {
+void MultiMeshInstance::set_multimesh(const Ref<MultiMesh> &p_multimesh) {
- multimesh=p_multimesh;
+ multimesh = p_multimesh;
if (multimesh.is_valid())
set_base(multimesh->get_rid());
else
set_base(RID());
-
}
Ref<MultiMesh> MultiMeshInstance::get_multimesh() const {
@@ -56,8 +49,6 @@ Ref<MultiMesh> MultiMeshInstance::get_multimesh() const {
return multimesh;
}
-
-
PoolVector<Face3> MultiMeshInstance::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
@@ -72,10 +63,7 @@ Rect3 MultiMeshInstance::get_aabb() const {
}
MultiMeshInstance::MultiMeshInstance() {
-
}
MultiMeshInstance::~MultiMeshInstance() {
-
-
}
diff --git a/scene/3d/multimesh_instance.h b/scene/3d/multimesh_instance.h
index 535e4275a3..4a0edb563c 100644
--- a/scene/3d/multimesh_instance.h
+++ b/scene/3d/multimesh_instance.h
@@ -37,21 +37,18 @@
*/
class MultiMeshInstance : public GeometryInstance {
- GDCLASS( MultiMeshInstance, GeometryInstance );
-
+ GDCLASS(MultiMeshInstance, GeometryInstance);
Ref<MultiMesh> multimesh;
-protected:
-
+protected:
static void _bind_methods();
// bind helpers
public:
-
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
- void set_multimesh(const Ref<MultiMesh>& p_multimesh);
+ void set_multimesh(const Ref<MultiMesh> &p_multimesh);
Ref<MultiMesh> get_multimesh() const;
virtual Rect3 get_aabb() const;
@@ -61,4 +58,3 @@ public:
};
#endif // MULTIMESH_INSTANCE_H
-
diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp
index 5c8fe6bb67..093d217cb0 100644
--- a/scene/3d/navigation.cpp
+++ b/scene/3d/navigation.cpp
@@ -31,60 +31,58 @@
void Navigation::_navmesh_link(int p_id) {
ERR_FAIL_COND(!navmesh_map.has(p_id));
- NavMesh &nm=navmesh_map[p_id];
+ NavMesh &nm = navmesh_map[p_id];
ERR_FAIL_COND(nm.linked);
print_line("LINK");
- PoolVector<Vector3> vertices=nm.navmesh->get_vertices();
+ PoolVector<Vector3> vertices = nm.navmesh->get_vertices();
int len = vertices.size();
- if (len==0)
+ if (len == 0)
return;
- PoolVector<Vector3>::Read r=vertices.read();
+ PoolVector<Vector3>::Read r = vertices.read();
- for(int i=0;i<nm.navmesh->get_polygon_count();i++) {
+ for (int i = 0; i < nm.navmesh->get_polygon_count(); i++) {
//build
- List<Polygon>::Element *P=nm.polygons.push_back(Polygon());
- Polygon &p=P->get();
- p.owner=&nm;
+ List<Polygon>::Element *P = nm.polygons.push_back(Polygon());
+ Polygon &p = P->get();
+ p.owner = &nm;
Vector<int> poly = nm.navmesh->get_polygon(i);
- int plen=poly.size();
- const int *indices=poly.ptr();
- bool valid=true;
+ int plen = poly.size();
+ const int *indices = poly.ptr();
+ bool valid = true;
p.edges.resize(plen);
Vector3 center;
- float sum=0;
+ float sum = 0;
- for(int j=0;j<plen;j++) {
+ for (int j = 0; j < plen; j++) {
int idx = indices[j];
- if (idx<0 || idx>=len) {
- valid=false;
+ if (idx < 0 || idx >= len) {
+ valid = false;
break;
}
Polygon::Edge e;
- Vector3 ep=nm.xform.xform(r[idx]);
- center+=ep;
- e.point=_get_point(ep);
- p.edges[j]=e;
+ Vector3 ep = nm.xform.xform(r[idx]);
+ center += ep;
+ e.point = _get_point(ep);
+ p.edges[j] = e;
- if (j>=2) {
- Vector3 epa = nm.xform.xform(r[indices[j-2]]);
- Vector3 epb = nm.xform.xform(r[indices[j-1]]);
-
- sum+=up.dot((epb-epa).cross(ep-epa));
+ if (j >= 2) {
+ Vector3 epa = nm.xform.xform(r[indices[j - 2]]);
+ Vector3 epb = nm.xform.xform(r[indices[j - 1]]);
+ sum += up.dot((epb - epa).cross(ep - epa));
}
-
}
- p.clockwise=sum>0;
+ p.clockwise = sum > 0;
if (!valid) {
nm.polygons.pop_back();
@@ -93,110 +91,106 @@ void Navigation::_navmesh_link(int p_id) {
}
p.center = center;
- if( plen != 0 ) {
+ if (plen != 0) {
p.center /= plen;
}
-
//connect
- for(int j=0;j<plen;j++) {
+ for (int j = 0; j < plen; j++) {
- int next = (j+1)%plen;
- EdgeKey ek(p.edges[j].point,p.edges[next].point);
+ int next = (j + 1) % plen;
+ EdgeKey ek(p.edges[j].point, p.edges[next].point);
- Map<EdgeKey,Connection>::Element *C=connections.find(ek);
+ Map<EdgeKey, Connection>::Element *C = connections.find(ek);
if (!C) {
Connection c;
- c.A=&p;
- c.A_edge=j;
- c.B=NULL;
- c.B_edge=-1;
- connections[ek]=c;
+ c.A = &p;
+ c.A_edge = j;
+ c.B = NULL;
+ c.B_edge = -1;
+ connections[ek] = c;
} else {
- if (C->get().B!=NULL) {
+ if (C->get().B != NULL) {
ConnectionPending pending;
- pending.polygon=&p;
- pending.edge=j;
- p.edges[j].P=C->get().pending.push_back(pending);
+ pending.polygon = &p;
+ pending.edge = j;
+ p.edges[j].P = C->get().pending.push_back(pending);
continue;
//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
//ERR_CONTINUE(C->get().B!=NULL); //wut
- C->get().B=&p;
- C->get().B_edge=j;
- C->get().A->edges[C->get().A_edge].C=&p;
- C->get().A->edges[C->get().A_edge].C_edge=j;
- p.edges[j].C=C->get().A;
- p.edges[j].C_edge=C->get().A_edge;
+ C->get().B = &p;
+ C->get().B_edge = j;
+ C->get().A->edges[C->get().A_edge].C = &p;
+ C->get().A->edges[C->get().A_edge].C_edge = j;
+ p.edges[j].C = C->get().A;
+ p.edges[j].C_edge = C->get().A_edge;
//connection successful.
}
}
}
- nm.linked=true;
-
+ nm.linked = true;
}
-
void Navigation::_navmesh_unlink(int p_id) {
ERR_FAIL_COND(!navmesh_map.has(p_id));
- NavMesh &nm=navmesh_map[p_id];
+ NavMesh &nm = navmesh_map[p_id];
ERR_FAIL_COND(!nm.linked);
print_line("UNLINK");
- for (List<Polygon>::Element *E=nm.polygons.front();E;E=E->next()) {
-
+ for (List<Polygon>::Element *E = nm.polygons.front(); E; E = E->next()) {
- Polygon &p=E->get();
+ Polygon &p = E->get();
int ec = p.edges.size();
- Polygon::Edge *edges=p.edges.ptr();
+ Polygon::Edge *edges = p.edges.ptr();
- for(int i=0;i<ec;i++) {
- int next = (i+1)%ec;
+ for (int i = 0; i < ec; i++) {
+ int next = (i + 1) % ec;
- EdgeKey ek(edges[i].point,edges[next].point);
- Map<EdgeKey,Connection>::Element *C=connections.find(ek);
+ EdgeKey ek(edges[i].point, edges[next].point);
+ Map<EdgeKey, Connection>::Element *C = connections.find(ek);
ERR_CONTINUE(!C);
if (edges[i].P) {
C->get().pending.erase(edges[i].P);
- edges[i].P=NULL;
+ edges[i].P = NULL;
} else if (C->get().B) {
//disconnect
- C->get().B->edges[C->get().B_edge].C=NULL;
- C->get().B->edges[C->get().B_edge].C_edge=-1;
- C->get().A->edges[C->get().A_edge].C=NULL;
- C->get().A->edges[C->get().A_edge].C_edge=-1;
+ C->get().B->edges[C->get().B_edge].C = NULL;
+ C->get().B->edges[C->get().B_edge].C_edge = -1;
+ C->get().A->edges[C->get().A_edge].C = NULL;
+ C->get().A->edges[C->get().A_edge].C_edge = -1;
- if (C->get().A==&E->get()) {
+ if (C->get().A == &E->get()) {
- C->get().A=C->get().B;
- C->get().A_edge=C->get().B_edge;
+ C->get().A = C->get().B;
+ C->get().A_edge = C->get().B_edge;
}
- C->get().B=NULL;
- C->get().B_edge=-1;
+ C->get().B = NULL;
+ C->get().B_edge = -1;
if (C->get().pending.size()) {
//reconnect if something is pending
ConnectionPending cp = C->get().pending.front()->get();
C->get().pending.pop_front();
- C->get().B=cp.polygon;
- C->get().B_edge=cp.edge;
- C->get().A->edges[C->get().A_edge].C=cp.polygon;
- C->get().A->edges[C->get().A_edge].C_edge=cp.edge;
- cp.polygon->edges[cp.edge].C=C->get().A;
- cp.polygon->edges[cp.edge].C_edge=C->get().A_edge;
- cp.polygon->edges[cp.edge].P=NULL;
+ C->get().B = cp.polygon;
+ C->get().B_edge = cp.edge;
+ C->get().A->edges[C->get().A_edge].C = cp.polygon;
+ C->get().A->edges[C->get().A_edge].C_edge = cp.edge;
+ cp.polygon->edges[cp.edge].C = C->get().A;
+ cp.polygon->edges[cp.edge].C_edge = C->get().A_edge;
+ cp.polygon->edges[cp.edge].P = NULL;
}
} else {
@@ -208,76 +202,68 @@ void Navigation::_navmesh_unlink(int p_id) {
nm.polygons.clear();
- nm.linked=false;
-
-
+ nm.linked = false;
}
-
-int Navigation::navmesh_create(const Ref<NavigationMesh>& p_mesh, const Transform& p_xform, Object *p_owner) {
+int Navigation::navmesh_create(const Ref<NavigationMesh> &p_mesh, const Transform &p_xform, Object *p_owner) {
int id = last_id++;
NavMesh nm;
- nm.linked=false;
- nm.navmesh=p_mesh;
- nm.xform=p_xform;
- nm.owner=p_owner;
- navmesh_map[id]=nm;
+ nm.linked = false;
+ nm.navmesh = p_mesh;
+ nm.xform = p_xform;
+ nm.owner = p_owner;
+ navmesh_map[id] = nm;
_navmesh_link(id);
return id;
}
-void Navigation::navmesh_set_transform(int p_id, const Transform& p_xform){
+void Navigation::navmesh_set_transform(int p_id, const Transform &p_xform) {
ERR_FAIL_COND(!navmesh_map.has(p_id));
- NavMesh &nm=navmesh_map[p_id];
- if (nm.xform==p_xform)
+ NavMesh &nm = navmesh_map[p_id];
+ if (nm.xform == p_xform)
return; //bleh
_navmesh_unlink(p_id);
- nm.xform=p_xform;
+ nm.xform = p_xform;
_navmesh_link(p_id);
-
-
-
}
-void Navigation::navmesh_remove(int p_id){
+void Navigation::navmesh_remove(int p_id) {
ERR_FAIL_COND(!navmesh_map.has(p_id));
_navmesh_unlink(p_id);
navmesh_map.erase(p_id);
-
}
-void Navigation::_clip_path(Vector<Vector3>& path, Polygon *from_poly, const Vector3& p_to_point, Polygon* p_to_poly) {
+void Navigation::_clip_path(Vector<Vector3> &path, Polygon *from_poly, const Vector3 &p_to_point, Polygon *p_to_poly) {
- Vector3 from = path[path.size()-1];
+ Vector3 from = path[path.size() - 1];
- if (from.distance_to(p_to_point)<CMP_EPSILON)
+ if (from.distance_to(p_to_point) < CMP_EPSILON)
return;
Plane cut_plane;
- cut_plane.normal = (from-p_to_point).cross(up);
- if (cut_plane.normal==Vector3())
+ cut_plane.normal = (from - p_to_point).cross(up);
+ if (cut_plane.normal == Vector3())
return;
cut_plane.normal.normalize();
cut_plane.d = cut_plane.normal.dot(from);
-
- while(from_poly!=p_to_poly) {
+ while (from_poly != p_to_poly) {
int pe = from_poly->prev_edge;
Vector3 a = _get_vertex(from_poly->edges[pe].point);
- Vector3 b = _get_vertex(from_poly->edges[(pe+1)%from_poly->edges.size()].point);
+ Vector3 b = _get_vertex(from_poly->edges[(pe + 1) % from_poly->edges.size()].point);
- from_poly=from_poly->edges[pe].C;
+ from_poly = from_poly->edges[pe].C;
ERR_FAIL_COND(!from_poly);
- if (a.distance_to(b)>CMP_EPSILON) {
+ if (a.distance_to(b) > CMP_EPSILON) {
Vector3 inters;
- if (cut_plane.intersects_segment(a,b,&inters)) {
- if (inters.distance_to(p_to_point)>CMP_EPSILON && inters.distance_to(path[path.size()-1])>CMP_EPSILON) {
+ if (cut_plane.intersects_segment(a, b, &inters)) {
+ if (inters.distance_to(p_to_point) > CMP_EPSILON && inters.distance_to(path[path.size() - 1]) > CMP_EPSILON) {
path.push_back(inters);
}
}
@@ -285,149 +271,138 @@ void Navigation::_clip_path(Vector<Vector3>& path, Polygon *from_poly, const Vec
}
}
-Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector3& p_end, bool p_optimize) {
+Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) {
-
- Polygon *begin_poly=NULL;
- Polygon *end_poly=NULL;
+ Polygon *begin_poly = NULL;
+ Polygon *end_poly = NULL;
Vector3 begin_point;
Vector3 end_point;
- float begin_d=1e20;
- float end_d=1e20;
-
+ float begin_d = 1e20;
+ float end_d = 1e20;
- for (Map<int,NavMesh>::Element*E=navmesh_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navmesh_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- Face3 f(_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point));
+ Face3 f(_get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point));
Vector3 spoint = f.get_closest_point_to(p_start);
float dpoint = spoint.distance_to(p_start);
- if (dpoint<begin_d) {
- begin_d=dpoint;
- begin_poly=&p;
- begin_point=spoint;
+ if (dpoint < begin_d) {
+ begin_d = dpoint;
+ begin_poly = &p;
+ begin_point = spoint;
}
spoint = f.get_closest_point_to(p_end);
dpoint = spoint.distance_to(p_end);
- if (dpoint<end_d) {
- end_d=dpoint;
- end_poly=&p;
- end_point=spoint;
+ if (dpoint < end_d) {
+ end_d = dpoint;
+ end_poly = &p;
+ end_point = spoint;
}
}
- p.prev_edge=-1;
+ p.prev_edge = -1;
}
}
-
if (!begin_poly || !end_poly) {
//print_line("No Path Path");
return Vector<Vector3>(); //no path
}
-
- if (begin_poly==end_poly) {
+ if (begin_poly == end_poly) {
Vector<Vector3> path;
path.resize(2);
- path[0]=begin_point;
- path[1]=end_point;
+ path[0] = begin_point;
+ path[1] = end_point;
//print_line("Direct Path");
return path;
}
+ bool found_route = false;
- bool found_route=false;
-
- List<Polygon*> open_list;
+ List<Polygon *> open_list;
- for(int i=0;i<begin_poly->edges.size();i++) {
+ for (int i = 0; i < begin_poly->edges.size(); i++) {
if (begin_poly->edges[i].C) {
- begin_poly->edges[i].C->prev_edge=begin_poly->edges[i].C_edge;
- begin_poly->edges[i].C->distance=begin_poly->center.distance_to(begin_poly->edges[i].C->center);
+ begin_poly->edges[i].C->prev_edge = begin_poly->edges[i].C_edge;
+ begin_poly->edges[i].C->distance = begin_poly->center.distance_to(begin_poly->edges[i].C->center);
open_list.push_back(begin_poly->edges[i].C);
- if (begin_poly->edges[i].C==end_poly) {
- found_route=true;
+ if (begin_poly->edges[i].C == end_poly) {
+ found_route = true;
}
}
}
+ while (!found_route) {
- while(!found_route) {
-
- if (open_list.size()==0) {
+ if (open_list.size() == 0) {
//print_line("NOU OPEN LIST");
break;
}
//check open list
- List<Polygon*>::Element *least_cost_poly=NULL;
- float least_cost=1e30;
+ List<Polygon *>::Element *least_cost_poly = NULL;
+ float least_cost = 1e30;
//this could be faster (cache previous results)
- for (List<Polygon*>::Element *E=open_list.front();E;E=E->next()) {
-
- Polygon *p=E->get();
+ for (List<Polygon *>::Element *E = open_list.front(); E; E = E->next()) {
+ Polygon *p = E->get();
- float cost=p->distance;
- cost+=p->center.distance_to(end_point);
+ float cost = p->distance;
+ cost += p->center.distance_to(end_point);
- if (cost<least_cost) {
+ if (cost < least_cost) {
- least_cost_poly=E;
- least_cost=cost;
+ least_cost_poly = E;
+ least_cost = cost;
}
}
-
- Polygon *p=least_cost_poly->get();
+ Polygon *p = least_cost_poly->get();
//open the neighbours for search
- for(int i=0;i<p->edges.size();i++) {
-
+ for (int i = 0; i < p->edges.size(); i++) {
- Polygon::Edge &e=p->edges[i];
+ Polygon::Edge &e = p->edges[i];
if (!e.C)
continue;
float distance = p->center.distance_to(e.C->center) + p->distance;
- if (e.C->prev_edge!=-1) {
+ if (e.C->prev_edge != -1) {
//oh this was visited already, can we win the cost?
- if (e.C->distance>distance) {
+ if (e.C->distance > distance) {
- e.C->prev_edge=e.C_edge;
- e.C->distance=distance;
+ e.C->prev_edge = e.C_edge;
+ e.C->distance = distance;
}
} else {
//add to open neighbours
- e.C->prev_edge=e.C_edge;
- e.C->distance=distance;
+ e.C->prev_edge = e.C_edge;
+ e.C->distance = distance;
open_list.push_back(e.C);
- if (e.C==end_poly) {
+ if (e.C == end_poly) {
//oh my reached end! stop algorithm
- found_route=true;
+ found_route = true;
break;
-
}
-
}
}
@@ -444,174 +419,164 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector
if (p_optimize) {
//string pulling
- Polygon *apex_poly=end_poly;
- Vector3 apex_point=end_point;
- Vector3 portal_left=apex_point;
- Vector3 portal_right=apex_point;
- Polygon *left_poly=end_poly;
- Polygon *right_poly=end_poly;
- Polygon *p=end_poly;
+ Polygon *apex_poly = end_poly;
+ Vector3 apex_point = end_point;
+ Vector3 portal_left = apex_point;
+ Vector3 portal_right = apex_point;
+ Polygon *left_poly = end_poly;
+ Polygon *right_poly = end_poly;
+ Polygon *p = end_poly;
path.push_back(end_point);
- while(p) {
+ while (p) {
Vector3 left;
Vector3 right;
-#define CLOCK_TANGENT(m_a,m_b,m_c) ( ((m_a)-(m_c)).cross((m_a)-(m_b)) )
+#define CLOCK_TANGENT(m_a, m_b, m_c) (((m_a) - (m_c)).cross((m_a) - (m_b)))
- if (p==begin_poly) {
- left=begin_point;
- right=begin_point;
+ if (p == begin_poly) {
+ left = begin_point;
+ right = begin_point;
} else {
int prev = p->prev_edge;
- int prev_n = (p->prev_edge+1)%p->edges.size();
+ int prev_n = (p->prev_edge + 1) % p->edges.size();
left = _get_vertex(p->edges[prev].point);
right = _get_vertex(p->edges[prev_n].point);
//if (CLOCK_TANGENT(apex_point,left,(left+right)*0.5).dot(up) < 0){
if (p->clockwise) {
- SWAP(left,right);
+ SWAP(left, right);
}
}
- bool skip=false;
-
+ bool skip = false;
- if (CLOCK_TANGENT(apex_point,portal_left,left).dot(up) >= 0){
+ if (CLOCK_TANGENT(apex_point, portal_left, left).dot(up) >= 0) {
//process
- if (portal_left==apex_point || CLOCK_TANGENT(apex_point,left,portal_right).dot(up) > 0) {
- left_poly=p;
- portal_left=left;
+ if (portal_left == apex_point || CLOCK_TANGENT(apex_point, left, portal_right).dot(up) > 0) {
+ left_poly = p;
+ portal_left = left;
} else {
- _clip_path(path,apex_poly,portal_right,right_poly);
+ _clip_path(path, apex_poly, portal_right, right_poly);
- apex_point=portal_right;
- p=right_poly;
- left_poly=p;
- apex_poly=p;
- portal_left=apex_point;
- portal_right=apex_point;
+ apex_point = portal_right;
+ p = right_poly;
+ left_poly = p;
+ apex_poly = p;
+ portal_left = apex_point;
+ portal_right = apex_point;
path.push_back(apex_point);
- skip=true;
+ skip = true;
}
}
- if (!skip && CLOCK_TANGENT(apex_point,portal_right,right).dot(up) <= 0){
+ if (!skip && CLOCK_TANGENT(apex_point, portal_right, right).dot(up) <= 0) {
//process
- if (portal_right==apex_point || CLOCK_TANGENT(apex_point,right,portal_left).dot(up) < 0) {
- right_poly=p;
- portal_right=right;
+ if (portal_right == apex_point || CLOCK_TANGENT(apex_point, right, portal_left).dot(up) < 0) {
+ right_poly = p;
+ portal_right = right;
} else {
- _clip_path(path,apex_poly,portal_left,left_poly);
+ _clip_path(path, apex_poly, portal_left, left_poly);
- apex_point=portal_left;
- p=left_poly;
- right_poly=p;
- apex_poly=p;
- portal_right=apex_point;
- portal_left=apex_point;
+ apex_point = portal_left;
+ p = left_poly;
+ right_poly = p;
+ apex_poly = p;
+ portal_right = apex_point;
+ portal_left = apex_point;
path.push_back(apex_point);
}
}
- if (p!=begin_poly)
- p=p->edges[p->prev_edge].C;
+ if (p != begin_poly)
+ p = p->edges[p->prev_edge].C;
else
- p=NULL;
-
+ p = NULL;
}
- if (path[path.size()-1]!=begin_point)
+ if (path[path.size() - 1] != begin_point)
path.push_back(begin_point);
path.invert();
-
-
-
} else {
//midpoints
- Polygon *p=end_poly;
+ Polygon *p = end_poly;
path.push_back(end_point);
- while(true) {
+ while (true) {
int prev = p->prev_edge;
- int prev_n = (p->prev_edge+1)%p->edges.size();
- Vector3 point = (_get_vertex(p->edges[prev].point) + _get_vertex(p->edges[prev_n].point))*0.5;
+ int prev_n = (p->prev_edge + 1) % p->edges.size();
+ Vector3 point = (_get_vertex(p->edges[prev].point) + _get_vertex(p->edges[prev_n].point)) * 0.5;
path.push_back(point);
p = p->edges[prev].C;
- if (p==begin_poly)
+ if (p == begin_poly)
break;
}
path.push_back(begin_point);
-
path.invert();
}
return path;
}
-
return Vector<Vector3>();
-
}
-Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision) {
-
+Vector3 Navigation::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool &p_use_collision) {
- bool use_collision=p_use_collision;
+ bool use_collision = p_use_collision;
Vector3 closest_point;
- float closest_point_d=1e20;
- NavMesh *closest_navmesh=NULL;
+ float closest_point_d = 1e20;
+ NavMesh *closest_navmesh = NULL;
- for (Map<int,NavMesh>::Element*E=navmesh_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navmesh_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- Face3 f(_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point));
+ Face3 f(_get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point));
Vector3 inters;
- if (f.intersects_segment(p_from,p_to,&inters)) {
+ if (f.intersects_segment(p_from, p_to, &inters)) {
if (!use_collision) {
- closest_point=inters;
- use_collision=true;
- closest_point_d=p_from.distance_to(inters);
- closest_navmesh=p.owner;
- } else if (closest_point_d > inters.distance_to(p_from)){
-
- closest_point=inters;
- closest_point_d=p_from.distance_to(inters);
- closest_navmesh=p.owner;
+ closest_point = inters;
+ use_collision = true;
+ closest_point_d = p_from.distance_to(inters);
+ closest_navmesh = p.owner;
+ } else if (closest_point_d > inters.distance_to(p_from)) {
+
+ closest_point = inters;
+ closest_point_d = p_from.distance_to(inters);
+ closest_navmesh = p.owner;
}
}
}
if (!use_collision) {
- for(int i=0;i<p.edges.size();i++) {
+ for (int i = 0; i < p.edges.size(); i++) {
- Vector3 a,b;
+ Vector3 a, b;
- Geometry::get_closest_points_between_segments(p_from,p_to,_get_vertex(p.edges[i].point),_get_vertex(p.edges[(i+1)%p.edges.size()].point),a,b);
+ Geometry::get_closest_points_between_segments(p_from, p_to, _get_vertex(p.edges[i].point), _get_vertex(p.edges[(i + 1) % p.edges.size()].point), a, b);
float d = a.distance_to(b);
- if (d<closest_point_d) {
+ if (d < closest_point_d) {
- closest_point_d=d;
- closest_point=b;
- closest_navmesh=p.owner;
+ closest_point_d = d;
+ closest_point = b;
+ closest_navmesh = p.owner;
}
-
}
}
}
@@ -624,132 +589,126 @@ Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vec
return closest_point;
}
-Vector3 Navigation::get_closest_point(const Vector3& p_point) {
+Vector3 Navigation::get_closest_point(const Vector3 &p_point) {
Vector3 closest_point;
- float closest_point_d=1e20;
+ float closest_point_d = 1e20;
- for (Map<int,NavMesh>::Element*E=navmesh_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navmesh_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- Face3 f(_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point));
+ Face3 f(_get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point));
Vector3 inters = f.get_closest_point_to(p_point);
float d = inters.distance_to(p_point);
- if (d<closest_point_d) {
- closest_point=inters;
- closest_point_d=d;
+ if (d < closest_point_d) {
+ closest_point = inters;
+ closest_point_d = d;
}
}
}
}
return closest_point;
-
}
-Vector3 Navigation::get_closest_point_normal(const Vector3& p_point){
+Vector3 Navigation::get_closest_point_normal(const Vector3 &p_point) {
Vector3 closest_point;
Vector3 closest_normal;
- float closest_point_d=1e20;
+ float closest_point_d = 1e20;
- for (Map<int,NavMesh>::Element*E=navmesh_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navmesh_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- Face3 f(_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point));
+ Face3 f(_get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point));
Vector3 inters = f.get_closest_point_to(p_point);
float d = inters.distance_to(p_point);
- if (d<closest_point_d) {
- closest_point=inters;
- closest_point_d=d;
- closest_normal=f.get_plane().normal;
+ if (d < closest_point_d) {
+ closest_point = inters;
+ closest_point_d = d;
+ closest_normal = f.get_plane().normal;
}
}
}
}
return closest_normal;
-
}
-
-Object* Navigation::get_closest_point_owner(const Vector3& p_point){
+Object *Navigation::get_closest_point_owner(const Vector3 &p_point) {
Vector3 closest_point;
- Object *owner=NULL;
- float closest_point_d=1e20;
+ Object *owner = NULL;
+ float closest_point_d = 1e20;
- for (Map<int,NavMesh>::Element*E=navmesh_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navmesh_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- Face3 f(_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point));
+ Face3 f(_get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point));
Vector3 inters = f.get_closest_point_to(p_point);
float d = inters.distance_to(p_point);
- if (d<closest_point_d) {
- closest_point=inters;
- closest_point_d=d;
- owner=E->get().owner;
+ if (d < closest_point_d) {
+ closest_point = inters;
+ closest_point_d = d;
+ owner = E->get().owner;
}
}
}
}
return owner;
-
}
-void Navigation::set_up_vector(const Vector3& p_up) {
+void Navigation::set_up_vector(const Vector3 &p_up) {
-
- up=p_up;
+ up = p_up;
}
-Vector3 Navigation::get_up_vector() const{
+Vector3 Navigation::get_up_vector() const {
return up;
}
-
void Navigation::_bind_methods() {
- ClassDB::bind_method(D_METHOD("navmesh_create","mesh:NavigationMesh","xform","owner"),&Navigation::navmesh_create,DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("navmesh_set_transform","id","xform"),&Navigation::navmesh_set_transform);
- ClassDB::bind_method(D_METHOD("navmesh_remove","id"),&Navigation::navmesh_remove);
+ ClassDB::bind_method(D_METHOD("navmesh_create", "mesh:NavigationMesh", "xform", "owner"), &Navigation::navmesh_create, DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("navmesh_set_transform", "id", "xform"), &Navigation::navmesh_set_transform);
+ ClassDB::bind_method(D_METHOD("navmesh_remove", "id"), &Navigation::navmesh_remove);
- ClassDB::bind_method(D_METHOD("get_simple_path","start","end","optimize"),&Navigation::get_simple_path,DEFVAL(true));
- ClassDB::bind_method(D_METHOD("get_closest_point_to_segment","start","end","use_collision"),&Navigation::get_closest_point_to_segment,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("get_closest_point","to_point"),&Navigation::get_closest_point);
- ClassDB::bind_method(D_METHOD("get_closest_point_normal","to_point"),&Navigation::get_closest_point_normal);
- ClassDB::bind_method(D_METHOD("get_closest_point_owner","to_point"),&Navigation::get_closest_point_owner);
+ ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation::get_simple_path, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "start", "end", "use_collision"), &Navigation::get_closest_point_to_segment, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation::get_closest_point);
+ ClassDB::bind_method(D_METHOD("get_closest_point_normal", "to_point"), &Navigation::get_closest_point_normal);
+ ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation::get_closest_point_owner);
- ClassDB::bind_method(D_METHOD("set_up_vector","up"),&Navigation::set_up_vector);
- ClassDB::bind_method(D_METHOD("get_up_vector"),&Navigation::get_up_vector);
+ ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation::set_up_vector);
+ ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation::get_up_vector);
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"up_vector"),"set_up_vector","get_up_vector");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "up_vector"), "set_up_vector", "get_up_vector");
}
Navigation::Navigation() {
- ERR_FAIL_COND( sizeof(Point)!=8 );
- cell_size=0.01; //one centimeter
- last_id=1;
- up=Vector3(0,1,0);
+ ERR_FAIL_COND(sizeof(Point) != 8);
+ cell_size = 0.01; //one centimeter
+ last_id = 1;
+ up = Vector3(0, 1, 0);
}
diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h
index 771e12466a..6222d2bad3 100644
--- a/scene/3d/navigation.h
+++ b/scene/3d/navigation.h
@@ -29,46 +29,43 @@
#ifndef NAVIGATION_H
#define NAVIGATION_H
-#include "scene/3d/spatial.h"
#include "scene/3d/navigation_mesh.h"
+#include "scene/3d/spatial.h"
class Navigation : public Spatial {
- GDCLASS( Navigation, Spatial);
-
+ GDCLASS(Navigation, Spatial);
union Point {
struct {
- int64_t x:21;
- int64_t y:22;
- int64_t z:21;
+ int64_t x : 21;
+ int64_t y : 22;
+ int64_t z : 21;
};
uint64_t key;
- bool operator<(const Point& p_key) const { return key < p_key.key; }
+ bool operator<(const Point &p_key) const { return key < p_key.key; }
};
-
struct EdgeKey {
Point a;
Point b;
- bool operator<(const EdgeKey& p_key) const {
- return (a.key==p_key.a.key)?(b.key<p_key.b.key):(a.key<p_key.a.key);
+ bool operator<(const EdgeKey &p_key) const {
+ return (a.key == p_key.a.key) ? (b.key < p_key.b.key) : (a.key < p_key.a.key);
};
- EdgeKey(const Point& p_a=Point(),const Point& p_b=Point()) {
- a=p_a;
- b=p_b;
+ EdgeKey(const Point &p_a = Point(), const Point &p_b = Point()) {
+ a = p_a;
+ b = p_b;
if (a.key > b.key) {
- SWAP(a,b);
+ SWAP(a, b);
}
}
};
-
struct NavMesh;
struct Polygon;
@@ -78,7 +75,6 @@ class Navigation : public Spatial {
int edge;
};
-
struct Polygon {
struct Edge {
@@ -86,7 +82,11 @@ class Navigation : public Spatial {
Polygon *C; //connection
int C_edge;
List<ConnectionPending>::Element *P;
- Edge() { C=NULL; C_edge=-1; P=NULL; }
+ Edge() {
+ C = NULL;
+ C_edge = -1;
+ P = NULL;
+ }
};
Vector<Edge> edges;
@@ -97,11 +97,9 @@ class Navigation : public Spatial {
int prev_edge;
bool clockwise;
-
NavMesh *owner;
};
-
struct Connection {
Polygon *A;
@@ -111,11 +109,15 @@ class Navigation : public Spatial {
List<ConnectionPending> pending;
- Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;}
+ Connection() {
+ A = NULL;
+ B = NULL;
+ A_edge = -1;
+ B_edge = -1;
+ }
};
- Map<EdgeKey,Connection> connections;
-
+ Map<EdgeKey, Connection> connections;
struct NavMesh {
@@ -124,62 +126,54 @@ class Navigation : public Spatial {
bool linked;
Ref<NavigationMesh> navmesh;
List<Polygon> polygons;
-
};
+ _FORCE_INLINE_ Point _get_point(const Vector3 &p_pos) const {
-
- _FORCE_INLINE_ Point _get_point(const Vector3& p_pos) const {
-
- int x = int(Math::floor(p_pos.x/cell_size));
- int y = int(Math::floor(p_pos.y/cell_size));
- int z = int(Math::floor(p_pos.z/cell_size));
+ int x = int(Math::floor(p_pos.x / cell_size));
+ int y = int(Math::floor(p_pos.y / cell_size));
+ int z = int(Math::floor(p_pos.z / cell_size));
Point p;
- p.key=0;
- p.x=x;
- p.y=y;
- p.z=z;
+ p.key = 0;
+ p.x = x;
+ p.y = y;
+ p.z = z;
return p;
-
}
- _FORCE_INLINE_ Vector3 _get_vertex(const Point& p_point) const {
+ _FORCE_INLINE_ Vector3 _get_vertex(const Point &p_point) const {
- return Vector3(p_point.x,p_point.y,p_point.z)*cell_size;
+ return Vector3(p_point.x, p_point.y, p_point.z) * cell_size;
}
-
-
void _navmesh_link(int p_id);
void _navmesh_unlink(int p_id);
float cell_size;
- Map<int,NavMesh> navmesh_map;
+ Map<int, NavMesh> navmesh_map;
int last_id;
Vector3 up;
- void _clip_path(Vector<Vector3>& path,Polygon *from_poly, const Vector3& p_to_point, Polygon* p_to_poly);
+ void _clip_path(Vector<Vector3> &path, Polygon *from_poly, const Vector3 &p_to_point, Polygon *p_to_poly);
protected:
-
static void _bind_methods();
public:
-
- void set_up_vector(const Vector3& p_up);
+ void set_up_vector(const Vector3 &p_up);
Vector3 get_up_vector() const;
//API should be as dynamic as possible
- int navmesh_create(const Ref<NavigationMesh>& p_mesh,const Transform& p_xform,Object* p_owner=NULL);
- void navmesh_set_transform(int p_id, const Transform& p_xform);
+ int navmesh_create(const Ref<NavigationMesh> &p_mesh, const Transform &p_xform, Object *p_owner = NULL);
+ void navmesh_set_transform(int p_id, const Transform &p_xform);
void navmesh_remove(int p_id);
- Vector<Vector3> get_simple_path(const Vector3& p_start, const Vector3& p_end,bool p_optimize=true);
- Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision=false);
- Vector3 get_closest_point(const Vector3& p_point);
- Vector3 get_closest_point_normal(const Vector3& p_point);
- Object* get_closest_point_owner(const Vector3& p_point);
+ Vector<Vector3> get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize = true);
+ Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool &p_use_collision = false);
+ Vector3 get_closest_point(const Vector3 &p_point);
+ Vector3 get_closest_point_normal(const Vector3 &p_point);
+ Object *get_closest_point_owner(const Vector3 &p_point);
Navigation();
};
diff --git a/scene/3d/navigation_mesh.cpp b/scene/3d/navigation_mesh.cpp
index 8efb9bb333..1059a9b979 100644
--- a/scene/3d/navigation_mesh.cpp
+++ b/scene/3d/navigation_mesh.cpp
@@ -27,23 +27,22 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "navigation_mesh.h"
-#include "navigation.h"
#include "mesh_instance.h"
+#include "navigation.h"
-void NavigationMesh::create_from_mesh(const Ref<Mesh>& p_mesh) {
-
+void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
- vertices=PoolVector<Vector3>();
+ vertices = PoolVector<Vector3>();
clear_polygons();
- for(int i=0;i<p_mesh->get_surface_count();i++) {
+ for (int i = 0; i < p_mesh->get_surface_count(); i++) {
- if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
continue;
Array arr = p_mesh->surface_get_arrays(i);
PoolVector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
PoolVector<int> iarr = arr[Mesh::ARRAY_INDEX];
- if (varr.size()==0 || iarr.size()==0)
+ if (varr.size() == 0 || iarr.size() == 0)
continue;
int from = vertices.size();
@@ -51,34 +50,33 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh>& p_mesh) {
int rlen = iarr.size();
PoolVector<int>::Read r = iarr.read();
- for(int j=0;j<rlen;j+=3) {
+ for (int j = 0; j < rlen; j += 3) {
Vector<int> vi;
vi.resize(3);
- vi[0]=r[j+0]+from;
- vi[1]=r[j+1]+from;
- vi[2]=r[j+2]+from;
+ vi[0] = r[j + 0] + from;
+ vi[1] = r[j + 1] + from;
+ vi[2] = r[j + 2] + from;
add_polygon(vi);
}
}
}
-void NavigationMesh::set_vertices(const PoolVector<Vector3>& p_vertices) {
+void NavigationMesh::set_vertices(const PoolVector<Vector3> &p_vertices) {
- vertices=p_vertices;
+ vertices = p_vertices;
}
-PoolVector<Vector3> NavigationMesh::get_vertices() const{
+PoolVector<Vector3> NavigationMesh::get_vertices() const {
return vertices;
}
-
-void NavigationMesh::_set_polygons(const Array& p_array) {
+void NavigationMesh::_set_polygons(const Array &p_array) {
polygons.resize(p_array.size());
- for(int i=0;i<p_array.size();i++) {
- polygons[i].indices=p_array[i];
+ for (int i = 0; i < p_array.size(); i++) {
+ polygons[i].indices = p_array[i];
}
}
@@ -86,31 +84,29 @@ Array NavigationMesh::_get_polygons() const {
Array ret;
ret.resize(polygons.size());
- for(int i=0;i<ret.size();i++) {
- ret[i]=polygons[i].indices;
+ for (int i = 0; i < ret.size(); i++) {
+ ret[i] = polygons[i].indices;
}
return ret;
}
-
-void NavigationMesh::add_polygon(const Vector<int>& p_polygon){
+void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
Polygon polygon;
- polygon.indices=p_polygon;
+ polygon.indices = p_polygon;
polygons.push_back(polygon);
-
}
-int NavigationMesh::get_polygon_count() const{
+int NavigationMesh::get_polygon_count() const {
return polygons.size();
}
-Vector<int> NavigationMesh::get_polygon(int p_idx){
+Vector<int> NavigationMesh::get_polygon(int p_idx) {
- ERR_FAIL_INDEX_V(p_idx,polygons.size(),Vector<int>());
+ ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>());
return polygons[p_idx].indices;
}
-void NavigationMesh::clear_polygons(){
+void NavigationMesh::clear_polygons() {
polygons.clear();
}
@@ -120,64 +116,59 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() {
if (debug_mesh.is_valid())
return debug_mesh;
-
-
PoolVector<Vector3> vertices = get_vertices();
- PoolVector<Vector3>::Read vr=vertices.read();
+ PoolVector<Vector3>::Read vr = vertices.read();
List<Face3> faces;
- for(int i=0;i<get_polygon_count();i++) {
+ for (int i = 0; i < get_polygon_count(); i++) {
Vector<int> p = get_polygon(i);
- for(int j=2;j<p.size();j++) {
+ for (int j = 2; j < p.size(); j++) {
Face3 f;
- f.vertex[0]=vr[p[0]];
- f.vertex[1]=vr[p[j-1]];
- f.vertex[2]=vr[p[j]];
+ f.vertex[0] = vr[p[0]];
+ f.vertex[1] = vr[p[j - 1]];
+ f.vertex[2] = vr[p[j]];
faces.push_back(f);
}
}
-
- Map<_EdgeKey,bool> edge_map;
+ Map<_EdgeKey, bool> edge_map;
PoolVector<Vector3> tmeshfaces;
- tmeshfaces.resize(faces.size()*3);
+ tmeshfaces.resize(faces.size() * 3);
{
- PoolVector<Vector3>::Write tw=tmeshfaces.write();
- int tidx=0;
-
+ PoolVector<Vector3>::Write tw = tmeshfaces.write();
+ int tidx = 0;
- for(List<Face3>::Element *E=faces.front();E;E=E->next()) {
+ for (List<Face3>::Element *E = faces.front(); E; E = E->next()) {
const Face3 &f = E->get();
- for(int j=0;j<3;j++) {
+ for (int j = 0; j < 3; j++) {
- tw[tidx++]=f.vertex[j];
+ tw[tidx++] = f.vertex[j];
_EdgeKey ek;
- ek.from=f.vertex[j].snapped(CMP_EPSILON);
- ek.to=f.vertex[(j+1)%3].snapped(CMP_EPSILON);
- if (ek.from<ek.to)
- SWAP(ek.from,ek.to);
+ ek.from = f.vertex[j].snapped(CMP_EPSILON);
+ ek.to = f.vertex[(j + 1) % 3].snapped(CMP_EPSILON);
+ if (ek.from < ek.to)
+ SWAP(ek.from, ek.to);
- Map<_EdgeKey,bool>::Element *E=edge_map.find(ek);
+ Map<_EdgeKey, bool>::Element *E = edge_map.find(ek);
if (E) {
- E->get()=false;
+ E->get() = false;
} else {
- edge_map[ek]=true;
+ edge_map[ek] = true;
}
-
}
}
}
List<Vector3> lines;
- for(Map<_EdgeKey,bool>::Element *E=edge_map.front();E;E=E->next()) {
+ for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) {
if (E->get()) {
lines.push_back(E->key().from);
@@ -189,58 +180,57 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() {
varr.resize(lines.size());
{
PoolVector<Vector3>::Write w = varr.write();
- int idx=0;
- for(List<Vector3>::Element *E=lines.front();E;E=E->next()) {
- w[idx++]=E->get();
+ int idx = 0;
+ for (List<Vector3>::Element *E = lines.front(); E; E = E->next()) {
+ w[idx++] = E->get();
}
}
- debug_mesh = Ref<Mesh>( memnew( Mesh ) );
+ debug_mesh = Ref<Mesh>(memnew(Mesh));
Array arr;
arr.resize(Mesh::ARRAY_MAX);
- arr[Mesh::ARRAY_VERTEX]=varr;
+ arr[Mesh::ARRAY_VERTEX] = varr;
- debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES,arr);
+ debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, arr);
return debug_mesh;
}
void NavigationMesh::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_vertices","vertices"),&NavigationMesh::set_vertices);
- ClassDB::bind_method(D_METHOD("get_vertices"),&NavigationMesh::get_vertices);
+ ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationMesh::set_vertices);
+ ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationMesh::get_vertices);
- ClassDB::bind_method(D_METHOD("add_polygon","polygon"),&NavigationMesh::add_polygon);
- ClassDB::bind_method(D_METHOD("get_polygon_count"),&NavigationMesh::get_polygon_count);
- ClassDB::bind_method(D_METHOD("get_polygon","idx"),&NavigationMesh::get_polygon);
- ClassDB::bind_method(D_METHOD("clear_polygons"),&NavigationMesh::clear_polygons);
+ ClassDB::bind_method(D_METHOD("add_polygon", "polygon"), &NavigationMesh::add_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon_count"), &NavigationMesh::get_polygon_count);
+ ClassDB::bind_method(D_METHOD("get_polygon", "idx"), &NavigationMesh::get_polygon);
+ ClassDB::bind_method(D_METHOD("clear_polygons"), &NavigationMesh::clear_polygons);
- ClassDB::bind_method(D_METHOD("_set_polygons","polygons"),&NavigationMesh::_set_polygons);
- ClassDB::bind_method(D_METHOD("_get_polygons"),&NavigationMesh::_get_polygons);
+ ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons);
+ ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons);
- ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY,"vertices",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_vertices","get_vertices");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY,"polygons",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_polygons","_get_polygons");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_vertices", "get_vertices");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_polygons", "_get_polygons");
}
NavigationMesh::NavigationMesh() {
-
}
void NavigationMeshInstance::set_enabled(bool p_enabled) {
- if (enabled==p_enabled)
+ if (enabled == p_enabled)
return;
- enabled=p_enabled;
+ enabled = p_enabled;
if (!is_inside_tree())
return;
if (!enabled) {
- if (nav_id!=-1) {
+ if (nav_id != -1) {
navigation->navmesh_remove(nav_id);
- nav_id=-1;
+ nav_id = -1;
}
} else {
@@ -248,20 +238,18 @@ void NavigationMeshInstance::set_enabled(bool p_enabled) {
if (navmesh.is_valid()) {
- nav_id = navigation->navmesh_create(navmesh,get_relative_transform(navigation),this);
+ nav_id = navigation->navmesh_create(navmesh, get_relative_transform(navigation), this);
}
}
-
}
if (debug_view) {
- MeshInstance *dm=debug_view->cast_to<MeshInstance>();
+ MeshInstance *dm = debug_view->cast_to<MeshInstance>();
if (is_enabled()) {
- dm->set_material_override( get_tree()->get_debug_navigation_material() );
+ dm->set_material_override(get_tree()->get_debug_navigation_material());
} else {
- dm->set_material_override( get_tree()->get_debug_navigation_disabled_material() );
+ dm->set_material_override(get_tree()->get_debug_navigation_disabled_material());
}
-
}
update_gizmo();
@@ -269,104 +257,96 @@ void NavigationMeshInstance::set_enabled(bool p_enabled) {
bool NavigationMeshInstance::is_enabled() const {
-
return enabled;
}
-
/////////////////////////////
-
void NavigationMeshInstance::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- Spatial *c=this;
- while(c) {
+ Spatial *c = this;
+ while (c) {
- navigation=c->cast_to<Navigation>();
+ navigation = c->cast_to<Navigation>();
if (navigation) {
if (enabled && navmesh.is_valid()) {
- nav_id = navigation->navmesh_create(navmesh,get_relative_transform(navigation),this);
+ nav_id = navigation->navmesh_create(navmesh, get_relative_transform(navigation), this);
}
break;
}
- c=c->get_parent_spatial();
+ c = c->get_parent_spatial();
}
if (navmesh.is_valid() && get_tree()->is_debugging_navigation_hint()) {
- MeshInstance *dm = memnew( MeshInstance );
- dm->set_mesh( navmesh->get_debug_mesh() );
+ MeshInstance *dm = memnew(MeshInstance);
+ dm->set_mesh(navmesh->get_debug_mesh());
if (is_enabled()) {
- dm->set_material_override( get_tree()->get_debug_navigation_material() );
+ dm->set_material_override(get_tree()->get_debug_navigation_material());
} else {
- dm->set_material_override( get_tree()->get_debug_navigation_disabled_material() );
+ dm->set_material_override(get_tree()->get_debug_navigation_disabled_material());
}
add_child(dm);
- debug_view=dm;
+ debug_view = dm;
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- if (navigation && nav_id!=-1) {
- navigation->navmesh_set_transform(nav_id,get_relative_transform(navigation));
+ if (navigation && nav_id != -1) {
+ navigation->navmesh_set_transform(nav_id, get_relative_transform(navigation));
}
-
-
} break;
case NOTIFICATION_EXIT_TREE: {
if (navigation) {
- if (nav_id!=-1) {
+ if (nav_id != -1) {
navigation->navmesh_remove(nav_id);
- nav_id=-1;
+ nav_id = -1;
}
}
if (debug_view) {
debug_view->queue_delete();
- debug_view=NULL;
+ debug_view = NULL;
}
- navigation=NULL;
+ navigation = NULL;
} break;
}
}
+void NavigationMeshInstance::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) {
-void NavigationMeshInstance::set_navigation_mesh(const Ref<NavigationMesh>& p_navmesh) {
-
- if (p_navmesh==navmesh)
+ if (p_navmesh == navmesh)
return;
- if (navigation && nav_id!=-1) {
+ if (navigation && nav_id != -1) {
navigation->navmesh_remove(nav_id);
- nav_id=-1;
+ nav_id = -1;
}
- navmesh=p_navmesh;
+ navmesh = p_navmesh;
if (navigation && navmesh.is_valid() && enabled) {
- nav_id = navigation->navmesh_create(navmesh,get_relative_transform(navigation),this);
+ nav_id = navigation->navmesh_create(navmesh, get_relative_transform(navigation), this);
}
-
+
if (debug_view && navmesh.is_valid()) {
- debug_view->cast_to<MeshInstance>()->set_mesh( navmesh->get_debug_mesh() );
+ debug_view->cast_to<MeshInstance>()->set_mesh(navmesh->get_debug_mesh());
}
-
+
update_gizmo();
update_configuration_warning();
-
}
-Ref<NavigationMesh> NavigationMeshInstance::get_navigation_mesh() const{
+Ref<NavigationMesh> NavigationMeshInstance::get_navigation_mesh() const {
return navmesh;
}
@@ -379,37 +359,35 @@ String NavigationMeshInstance::get_configuration_warning() const {
if (!navmesh.is_valid()) {
return TTR("A NavigationMesh resource must be set or created for this node to work.");
}
- const Spatial *c=this;
- while(c) {
+ const Spatial *c = this;
+ while (c) {
if (c->cast_to<Navigation>())
return String();
- c=c->get_parent()->cast_to<Spatial>();
+ c = c->get_parent()->cast_to<Spatial>();
}
return TTR("NavigationMeshInstance must be a child or grandchild to a Navigation node. It only provides navigation data.");
}
-
void NavigationMeshInstance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_navigation_mesh","navmesh"),&NavigationMeshInstance::set_navigation_mesh);
- ClassDB::bind_method(D_METHOD("get_navigation_mesh"),&NavigationMeshInstance::get_navigation_mesh);
+ ClassDB::bind_method(D_METHOD("set_navigation_mesh", "navmesh"), &NavigationMeshInstance::set_navigation_mesh);
+ ClassDB::bind_method(D_METHOD("get_navigation_mesh"), &NavigationMeshInstance::get_navigation_mesh);
- ClassDB::bind_method(D_METHOD("set_enabled","enabled"),&NavigationMeshInstance::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&NavigationMeshInstance::is_enabled);
+ ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationMeshInstance::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationMeshInstance::is_enabled);
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"navmesh",PROPERTY_HINT_RESOURCE_TYPE,"NavigationMesh"),"set_navigation_mesh","get_navigation_mesh");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),"set_enabled","is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navmesh", PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"), "set_navigation_mesh", "get_navigation_mesh");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
}
NavigationMeshInstance::NavigationMeshInstance() {
- debug_view=NULL;
- navigation=NULL;
- nav_id=-1;
- enabled=true;
+ debug_view = NULL;
+ navigation = NULL;
+ nav_id = -1;
+ enabled = true;
set_notify_transform(true);
-
}
diff --git a/scene/3d/navigation_mesh.h b/scene/3d/navigation_mesh.h
index e025b7ce8b..fda8923788 100644
--- a/scene/3d/navigation_mesh.h
+++ b/scene/3d/navigation_mesh.h
@@ -34,9 +34,9 @@
class Mesh;
-class NavigationMesh : public Resource {
+class NavigationMesh : public Resource {
- GDCLASS( NavigationMesh, Resource );
+ GDCLASS(NavigationMesh, Resource);
PoolVector<Vector3> vertices;
struct Polygon {
@@ -50,25 +50,22 @@ class NavigationMesh : public Resource {
Vector3 from;
Vector3 to;
- bool operator<(const _EdgeKey& p_with) const { return from==p_with.from ? to < p_with.to : from < p_with.from; }
+ bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
};
-
protected:
-
static void _bind_methods();
- void _set_polygons(const Array& p_array);
+ void _set_polygons(const Array &p_array);
Array _get_polygons() const;
public:
+ void create_from_mesh(const Ref<Mesh> &p_mesh);
- void create_from_mesh(const Ref<Mesh>& p_mesh);
-
- void set_vertices(const PoolVector<Vector3>& p_vertices);
+ void set_vertices(const PoolVector<Vector3> &p_vertices);
PoolVector<Vector3> get_vertices() const;
- void add_polygon(const Vector<int>& p_polygon);
+ void add_polygon(const Vector<int> &p_polygon);
int get_polygon_count() const;
Vector<int> get_polygon(int p_idx);
void clear_polygons();
@@ -78,12 +75,11 @@ public:
NavigationMesh();
};
-
class Navigation;
class NavigationMeshInstance : public Spatial {
- GDCLASS(NavigationMeshInstance,Spatial);
+ GDCLASS(NavigationMeshInstance, Spatial);
bool enabled;
int nav_id;
@@ -93,17 +89,14 @@ class NavigationMeshInstance : public Spatial {
Node *debug_view;
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
-
-
+public:
void set_enabled(bool p_enabled);
bool is_enabled() const;
- void set_navigation_mesh(const Ref<NavigationMesh>& p_navmesh);
+ void set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh);
Ref<NavigationMesh> get_navigation_mesh() const;
String get_configuration_warning() const;
@@ -111,5 +104,4 @@ public:
NavigationMeshInstance();
};
-
#endif // NAVIGATION_MESH_H
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp
index 0e0c1e9dc6..ea61253ac7 100644
--- a/scene/3d/particles.cpp
+++ b/scene/3d/particles.cpp
@@ -27,8 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "particles.h"
-#include "servers/visual_server.h"
#include "scene/resources/surface_tool.h"
+#include "servers/visual_server.h"
#if 0
/*
diff --git a/scene/3d/particles.h b/scene/3d/particles.h
index b96bd4e69e..6cb1caad3a 100644
--- a/scene/3d/particles.h
+++ b/scene/3d/particles.h
@@ -29,10 +29,10 @@
#ifndef VISUALINSTANCEPARTICLES_H
#define VISUALINSTANCEPARTICLES_H
+#include "rid.h"
#include "scene/3d/visual_instance.h"
-#include "scene/resources/material.h"
#include "scene/main/timer.h"
-#include "rid.h"
+#include "scene/resources/material.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/scene/3d/path.cpp b/scene/3d/path.cpp
index ead150e40b..457e9e5552 100644
--- a/scene/3d/path.cpp
+++ b/scene/3d/path.cpp
@@ -52,119 +52,108 @@ void Path::_notification(int p_what) {
void Path::_curve_changed() {
-
if (is_inside_tree() && get_tree()->is_editor_hint())
update_gizmo();
}
-
-void Path::set_curve(const Ref<Curve3D>& p_curve) {
+void Path::set_curve(const Ref<Curve3D> &p_curve) {
if (curve.is_valid()) {
- curve->disconnect("changed",this,"_curve_changed");
+ curve->disconnect("changed", this, "_curve_changed");
}
- curve=p_curve;
+ curve = p_curve;
if (curve.is_valid()) {
- curve->connect("changed",this,"_curve_changed");
+ curve->connect("changed", this, "_curve_changed");
}
_curve_changed();
-
}
-Ref<Curve3D> Path::get_curve() const{
+Ref<Curve3D> Path::get_curve() const {
return curve;
}
void Path::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_curve","curve:Curve3D"),&Path::set_curve);
- ClassDB::bind_method(D_METHOD("get_curve:Curve3D","curve"),&Path::get_curve);
- ClassDB::bind_method(D_METHOD("_curve_changed"),&Path::_curve_changed);
+ ClassDB::bind_method(D_METHOD("set_curve", "curve:Curve3D"), &Path::set_curve);
+ ClassDB::bind_method(D_METHOD("get_curve:Curve3D", "curve"), &Path::get_curve);
+ ClassDB::bind_method(D_METHOD("_curve_changed"), &Path::_curve_changed);
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve3D"), "set_curve","get_curve");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve3D"), "set_curve", "get_curve");
}
Path::Path() {
- set_curve(Ref<Curve3D>( memnew( Curve3D ))); //create one by default
+ set_curve(Ref<Curve3D>(memnew(Curve3D))); //create one by default
}
-
//////////////
-
void PathFollow::_update_transform() {
-
if (!path)
return;
- Ref<Curve3D> c =path->get_curve();
+ Ref<Curve3D> c = path->get_curve();
if (!c.is_valid())
return;
-
float o = offset;
if (loop)
- o=Math::fposmod(o,c->get_baked_length());
-
- Vector3 pos = c->interpolate_baked(o,cubic);
- Transform t=get_transform();
+ o = Math::fposmod(o, c->get_baked_length());
+ Vector3 pos = c->interpolate_baked(o, cubic);
+ Transform t = get_transform();
- if (rotation_mode!=ROTATION_NONE) {
+ if (rotation_mode != ROTATION_NONE) {
- Vector3 n = (c->interpolate_baked(o+lookahead,cubic)-pos).normalized();
+ Vector3 n = (c->interpolate_baked(o + lookahead, cubic) - pos).normalized();
- if (rotation_mode==ROTATION_Y) {
+ if (rotation_mode == ROTATION_Y) {
- n.y=0;
+ n.y = 0;
n.normalize();
}
- if (n.length()<CMP_EPSILON) {//nothing, use previous
- n=-t.get_basis().get_axis(2).normalized();
+ if (n.length() < CMP_EPSILON) { //nothing, use previous
+ n = -t.get_basis().get_axis(2).normalized();
}
+ Vector3 up = Vector3(0, 1, 0);
- Vector3 up = Vector3(0,1,0);
-
- if (rotation_mode==ROTATION_XYZ) {
+ if (rotation_mode == ROTATION_XYZ) {
float tilt = c->interpolate_baked_tilt(o);
- if (tilt!=0) {
+ if (tilt != 0) {
- Basis rot(-n,tilt); //remember.. lookat will be znegative.. znegative!! we abide by opengl clan.
- up=rot.xform(up);
+ Basis rot(-n, tilt); //remember.. lookat will be znegative.. znegative!! we abide by opengl clan.
+ up = rot.xform(up);
}
}
- t.set_look_at(pos,pos+n,up);
+ t.set_look_at(pos, pos + n, up);
} else {
- t.origin=pos;
+ t.origin = pos;
}
- t.origin+=t.basis.get_axis(0)*h_offset + t.basis.get_axis(1)*v_offset;
+ t.origin += t.basis.get_axis(0) * h_offset + t.basis.get_axis(1) * v_offset;
set_transform(t);
-
}
void PathFollow::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- Node *parent=get_parent();
+ Node *parent = get_parent();
if (parent) {
- path=parent->cast_to<Path>();
+ path = parent->cast_to<Path>();
if (path) {
_update_transform();
}
@@ -173,16 +162,14 @@ void PathFollow::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
-
- path=NULL;
+ path = NULL;
} break;
}
-
}
void PathFollow::set_cubic_interpolation(bool p_enable) {
- cubic=p_enable;
+ cubic = p_enable;
}
bool PathFollow::get_cubic_interpolation() const {
@@ -190,24 +177,23 @@ bool PathFollow::get_cubic_interpolation() const {
return cubic;
}
+bool PathFollow::_set(const StringName &p_name, const Variant &p_value) {
-bool PathFollow::_set(const StringName& p_name, const Variant& p_value) {
-
- if (p_name==SceneStringNames::get_singleton()->offset) {
+ if (p_name == SceneStringNames::get_singleton()->offset) {
set_offset(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->unit_offset) {
+ } else if (p_name == SceneStringNames::get_singleton()->unit_offset) {
set_unit_offset(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->rotation_mode) {
+ } else if (p_name == SceneStringNames::get_singleton()->rotation_mode) {
set_rotation_mode(RotationMode(p_value.operator int()));
- } else if (p_name==SceneStringNames::get_singleton()->v_offset) {
+ } else if (p_name == SceneStringNames::get_singleton()->v_offset) {
set_v_offset(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->h_offset) {
+ } else if (p_name == SceneStringNames::get_singleton()->h_offset) {
set_h_offset(p_value);
- } else if (String(p_name)=="cubic_interp") {
+ } else if (String(p_name) == "cubic_interp") {
set_cubic_interpolation(p_value);
- } else if (String(p_name)=="loop") {
+ } else if (String(p_name) == "loop") {
set_loop(p_value);
- } else if (String(p_name)=="lookahead") {
+ } else if (String(p_name) == "lookahead") {
set_lookahead(p_value);
} else
return false;
@@ -215,92 +201,87 @@ bool PathFollow::_set(const StringName& p_name, const Variant& p_value) {
return true;
}
-bool PathFollow::_get(const StringName& p_name,Variant &r_ret) const{
-
- if (p_name==SceneStringNames::get_singleton()->offset) {
- r_ret=get_offset();
- } else if (p_name==SceneStringNames::get_singleton()->unit_offset) {
- r_ret=get_unit_offset();
- } else if (p_name==SceneStringNames::get_singleton()->rotation_mode) {
- r_ret=get_rotation_mode();
- } else if (p_name==SceneStringNames::get_singleton()->v_offset) {
- r_ret=get_v_offset();
- } else if (p_name==SceneStringNames::get_singleton()->h_offset) {
- r_ret=get_h_offset();
- } else if (String(p_name)=="cubic_interp") {
- r_ret=cubic;
- } else if (String(p_name)=="loop") {
- r_ret=loop;
- } else if (String(p_name)=="lookahead") {
- r_ret=lookahead;
+bool PathFollow::_get(const StringName &p_name, Variant &r_ret) const {
+
+ if (p_name == SceneStringNames::get_singleton()->offset) {
+ r_ret = get_offset();
+ } else if (p_name == SceneStringNames::get_singleton()->unit_offset) {
+ r_ret = get_unit_offset();
+ } else if (p_name == SceneStringNames::get_singleton()->rotation_mode) {
+ r_ret = get_rotation_mode();
+ } else if (p_name == SceneStringNames::get_singleton()->v_offset) {
+ r_ret = get_v_offset();
+ } else if (p_name == SceneStringNames::get_singleton()->h_offset) {
+ r_ret = get_h_offset();
+ } else if (String(p_name) == "cubic_interp") {
+ r_ret = cubic;
+ } else if (String(p_name) == "loop") {
+ r_ret = loop;
+ } else if (String(p_name) == "lookahead") {
+ r_ret = lookahead;
} else
return false;
return true;
-
}
-void PathFollow::_get_property_list( List<PropertyInfo> *p_list) const{
+void PathFollow::_get_property_list(List<PropertyInfo> *p_list) const {
- float max=10000;
+ float max = 10000;
if (path && path->get_curve().is_valid())
- max=path->get_curve()->get_baked_length();
- p_list->push_back( PropertyInfo( Variant::REAL, "offset", PROPERTY_HINT_RANGE,"0,"+rtos(max)+",0.01"));
- p_list->push_back( PropertyInfo( Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE,"0,1,0.0001",PROPERTY_USAGE_EDITOR));
- p_list->push_back( PropertyInfo( Variant::REAL, "h_offset") );
- p_list->push_back( PropertyInfo( Variant::REAL, "v_offset") );
- p_list->push_back( PropertyInfo( Variant::INT, "rotation_mode", PROPERTY_HINT_ENUM,"None,Y,XY,XYZ"));
- p_list->push_back( PropertyInfo( Variant::BOOL, "cubic_interp"));
- p_list->push_back( PropertyInfo( Variant::BOOL, "loop"));
- p_list->push_back( PropertyInfo( Variant::REAL, "lookahead",PROPERTY_HINT_RANGE,"0.001,1024.0,0.001"));
+ max = path->get_curve()->get_baked_length();
+ p_list->push_back(PropertyInfo(Variant::REAL, "offset", PROPERTY_HINT_RANGE, "0," + rtos(max) + ",0.01"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE, "0,1,0.0001", PROPERTY_USAGE_EDITOR));
+ p_list->push_back(PropertyInfo(Variant::REAL, "h_offset"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "v_offset"));
+ p_list->push_back(PropertyInfo(Variant::INT, "rotation_mode", PROPERTY_HINT_ENUM, "None,Y,XY,XYZ"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "cubic_interp"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "loop"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "lookahead", PROPERTY_HINT_RANGE, "0.001,1024.0,0.001"));
}
-
void PathFollow::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&PathFollow::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&PathFollow::get_offset);
-
- ClassDB::bind_method(D_METHOD("set_h_offset","h_offset"),&PathFollow::set_h_offset);
- ClassDB::bind_method(D_METHOD("get_h_offset"),&PathFollow::get_h_offset);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow::get_offset);
- ClassDB::bind_method(D_METHOD("set_v_offset","v_offset"),&PathFollow::set_v_offset);
- ClassDB::bind_method(D_METHOD("get_v_offset"),&PathFollow::get_v_offset);
+ ClassDB::bind_method(D_METHOD("set_h_offset", "h_offset"), &PathFollow::set_h_offset);
+ ClassDB::bind_method(D_METHOD("get_h_offset"), &PathFollow::get_h_offset);
- ClassDB::bind_method(D_METHOD("set_unit_offset","unit_offset"),&PathFollow::set_unit_offset);
- ClassDB::bind_method(D_METHOD("get_unit_offset"),&PathFollow::get_unit_offset);
+ ClassDB::bind_method(D_METHOD("set_v_offset", "v_offset"), &PathFollow::set_v_offset);
+ ClassDB::bind_method(D_METHOD("get_v_offset"), &PathFollow::get_v_offset);
- ClassDB::bind_method(D_METHOD("set_rotation_mode","rotation_mode"),&PathFollow::set_rotation_mode);
- ClassDB::bind_method(D_METHOD("get_rotation_mode"),&PathFollow::get_rotation_mode);
+ ClassDB::bind_method(D_METHOD("set_unit_offset", "unit_offset"), &PathFollow::set_unit_offset);
+ ClassDB::bind_method(D_METHOD("get_unit_offset"), &PathFollow::get_unit_offset);
- ClassDB::bind_method(D_METHOD("set_cubic_interpolation","enable"),&PathFollow::set_cubic_interpolation);
- ClassDB::bind_method(D_METHOD("get_cubic_interpolation"),&PathFollow::get_cubic_interpolation);
+ ClassDB::bind_method(D_METHOD("set_rotation_mode", "rotation_mode"), &PathFollow::set_rotation_mode);
+ ClassDB::bind_method(D_METHOD("get_rotation_mode"), &PathFollow::get_rotation_mode);
- ClassDB::bind_method(D_METHOD("set_loop","loop"),&PathFollow::set_loop);
- ClassDB::bind_method(D_METHOD("has_loop"),&PathFollow::has_loop);
+ ClassDB::bind_method(D_METHOD("set_cubic_interpolation", "enable"), &PathFollow::set_cubic_interpolation);
+ ClassDB::bind_method(D_METHOD("get_cubic_interpolation"), &PathFollow::get_cubic_interpolation);
- BIND_CONSTANT( ROTATION_NONE );
- BIND_CONSTANT( ROTATION_Y );
- BIND_CONSTANT( ROTATION_XY );
- BIND_CONSTANT( ROTATION_XYZ );
+ ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow::set_loop);
+ ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow::has_loop);
+ BIND_CONSTANT(ROTATION_NONE);
+ BIND_CONSTANT(ROTATION_Y);
+ BIND_CONSTANT(ROTATION_XY);
+ BIND_CONSTANT(ROTATION_XYZ);
}
void PathFollow::set_offset(float p_offset) {
- offset=p_offset;
+ offset = p_offset;
if (path)
_update_transform();
_change_notify("offset");
_change_notify("unit_offset");
-
}
void PathFollow::set_h_offset(float p_h_offset) {
- h_offset=p_h_offset;
+ h_offset = p_h_offset;
if (path)
_update_transform();
-
}
float PathFollow::get_h_offset() const {
@@ -310,10 +291,9 @@ float PathFollow::get_h_offset() const {
void PathFollow::set_v_offset(float p_v_offset) {
- v_offset=p_v_offset;
+ v_offset = p_v_offset;
if (path)
_update_transform();
-
}
float PathFollow::get_v_offset() const {
@@ -321,8 +301,7 @@ float PathFollow::get_v_offset() const {
return v_offset;
}
-
-float PathFollow::get_offset() const{
+float PathFollow::get_offset() const {
return offset;
}
@@ -330,32 +309,30 @@ float PathFollow::get_offset() const{
void PathFollow::set_unit_offset(float p_unit_offset) {
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
- set_offset(p_unit_offset*path->get_curve()->get_baked_length());
-
+ set_offset(p_unit_offset * path->get_curve()->get_baked_length());
}
-float PathFollow::get_unit_offset() const{
+float PathFollow::get_unit_offset() const {
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
- return get_offset()/path->get_curve()->get_baked_length();
+ return get_offset() / path->get_curve()->get_baked_length();
else
return 0;
}
void PathFollow::set_lookahead(float p_lookahead) {
- lookahead=p_lookahead;
-
+ lookahead = p_lookahead;
}
-float PathFollow::get_lookahead() const{
+float PathFollow::get_lookahead() const {
return lookahead;
}
void PathFollow::set_rotation_mode(RotationMode p_rotation_mode) {
- rotation_mode=p_rotation_mode;
+ rotation_mode = p_rotation_mode;
_update_transform();
}
@@ -366,23 +343,22 @@ PathFollow::RotationMode PathFollow::get_rotation_mode() const {
void PathFollow::set_loop(bool p_loop) {
- loop=p_loop;
+ loop = p_loop;
}
-bool PathFollow::has_loop() const{
+bool PathFollow::has_loop() const {
return loop;
}
-
PathFollow::PathFollow() {
- offset=0;
- h_offset=0;
- v_offset=0;
- path=NULL;
- rotation_mode=ROTATION_XYZ;
- cubic=true;
- loop=true;
- lookahead=0.1;
+ offset = 0;
+ h_offset = 0;
+ v_offset = 0;
+ path = NULL;
+ rotation_mode = ROTATION_XYZ;
+ cubic = true;
+ loop = true;
+ lookahead = 0.1;
}
diff --git a/scene/3d/path.h b/scene/3d/path.h
index ab6f459ba9..94227799ed 100644
--- a/scene/3d/path.h
+++ b/scene/3d/path.h
@@ -29,36 +29,33 @@
#ifndef PATH_H
#define PATH_H
-#include "scene/resources/curve.h"
#include "scene/3d/spatial.h"
+#include "scene/resources/curve.h"
class Path : public Spatial {
- GDCLASS( Path, Spatial );
+ GDCLASS(Path, Spatial);
Ref<Curve3D> curve;
void _curve_changed();
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_curve(const Ref<Curve3D>& p_curve);
+public:
+ void set_curve(const Ref<Curve3D> &p_curve);
Ref<Curve3D> get_curve() const;
-
Path();
};
class PathFollow : public Spatial {
- GDCLASS(PathFollow,Spatial);
-public:
+ GDCLASS(PathFollow, Spatial);
+public:
enum RotationMode {
ROTATION_NONE,
@@ -79,17 +76,15 @@ private:
void _update_transform();
-
protected:
-
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_offset(float p_offset);
float get_offset() const;
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index af514a171f..78a00e4a7f 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -31,7 +31,7 @@
void PhysicsBody::_notification(int p_what) {
-/*
+ /*
switch(p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -57,11 +57,10 @@ float PhysicsBody::get_inverse_mass() const {
return 0;
}
-
void PhysicsBody::set_collision_layer(uint32_t p_mask) {
- layer_mask=p_mask;
- PhysicsServer::get_singleton()->body_set_layer_mask(get_rid(),p_mask);
+ layer_mask = p_mask;
+ PhysicsServer::get_singleton()->body_set_layer_mask(get_rid(), p_mask);
}
uint32_t PhysicsBody::get_collision_layer() const {
@@ -71,8 +70,8 @@ uint32_t PhysicsBody::get_collision_layer() const {
void PhysicsBody::set_collision_mask(uint32_t p_mask) {
- collision_mask=p_mask;
- PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(),p_mask);
+ collision_mask = p_mask;
+ PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask);
}
uint32_t PhysicsBody::get_collision_mask() const {
@@ -84,36 +83,33 @@ void PhysicsBody::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_collision_mask(mask);
-
}
-bool PhysicsBody::get_collision_mask_bit(int p_bit) const{
+bool PhysicsBody::get_collision_mask_bit(int p_bit) const {
- return get_collision_mask()&(1<<p_bit);
+ return get_collision_mask() & (1 << p_bit);
}
-
void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_layer();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_collision_layer(mask);
-
}
-bool PhysicsBody::get_collision_layer_bit(int p_bit) const{
+bool PhysicsBody::get_collision_layer_bit(int p_bit) const {
- return get_collision_layer()&(1<<p_bit);
+ return get_collision_layer() & (1 << p_bit);
}
-void PhysicsBody::add_collision_exception_with(Node* p_node) {
+void PhysicsBody::add_collision_exception_with(Node *p_node) {
ERR_FAIL_NULL(p_node);
PhysicsBody *physics_body = p_node->cast_to<PhysicsBody>();
@@ -121,11 +117,10 @@ void PhysicsBody::add_collision_exception_with(Node* p_node) {
ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
}
ERR_FAIL_COND(!physics_body);
- PhysicsServer::get_singleton()->body_add_collision_exception(get_rid(),physics_body->get_rid());
-
+ PhysicsServer::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid());
}
-void PhysicsBody::remove_collision_exception_with(Node* p_node) {
+void PhysicsBody::remove_collision_exception_with(Node *p_node) {
ERR_FAIL_NULL(p_node);
PhysicsBody *physics_body = p_node->cast_to<PhysicsBody>();
@@ -133,7 +128,7 @@ void PhysicsBody::remove_collision_exception_with(Node* p_node) {
ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
}
ERR_FAIL_COND(!physics_body);
- PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(),physics_body->get_rid());
+ PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid());
}
void PhysicsBody::_set_layers(uint32_t p_mask) {
@@ -141,80 +136,73 @@ void PhysicsBody::_set_layers(uint32_t p_mask) {
set_collision_mask(p_mask);
}
-uint32_t PhysicsBody::_get_layers() const{
+uint32_t PhysicsBody::_get_layers() const {
return get_collision_layer();
}
void PhysicsBody::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_collision_layer","layer"),&PhysicsBody::set_collision_layer);
- ClassDB::bind_method(D_METHOD("get_collision_layer"),&PhysicsBody::get_collision_layer);
+ ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody::set_collision_layer);
+ ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody::get_collision_layer);
- ClassDB::bind_method(D_METHOD("set_collision_mask","mask"),&PhysicsBody::set_collision_mask);
- ClassDB::bind_method(D_METHOD("get_collision_mask"),&PhysicsBody::get_collision_mask);
+ ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody::set_collision_mask);
+ ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody::get_collision_mask);
- ClassDB::bind_method(D_METHOD("set_collision_mask_bit","bit","value"),&PhysicsBody::set_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("get_collision_mask_bit","bit"),&PhysicsBody::get_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody::set_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody::get_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("set_collision_layer_bit","bit","value"),&PhysicsBody::set_collision_layer_bit);
- ClassDB::bind_method(D_METHOD("get_collision_layer_bit","bit"),&PhysicsBody::get_collision_layer_bit);
+ ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody::set_collision_layer_bit);
+ ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody::get_collision_layer_bit);
- ClassDB::bind_method(D_METHOD("_set_layers","mask"),&PhysicsBody::_set_layers);
- ClassDB::bind_method(D_METHOD("_get_layers"),&PhysicsBody::_get_layers);
+ ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody::_set_layers);
+ ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody::_get_layers);
- ADD_GROUP("Collision","collision_");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_layer",PROPERTY_HINT_LAYERS_3D_PHYSICS),"set_collision_layer","get_collision_layer");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_3D_PHYSICS),"set_collision_mask","get_collision_mask");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
}
+PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode)
+ : CollisionObject(PhysicsServer::get_singleton()->body_create(p_mode), false) {
-PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode) : CollisionObject( PhysicsServer::get_singleton()->body_create(p_mode), false) {
-
- layer_mask=1;
- collision_mask=1;
-
+ layer_mask = 1;
+ collision_mask = 1;
}
+void StaticBody::set_friction(real_t p_friction) {
-void StaticBody::set_friction(real_t p_friction){
-
- ERR_FAIL_COND(p_friction<0 || p_friction>1);
-
- friction=p_friction;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_FRICTION,friction);
+ ERR_FAIL_COND(p_friction < 0 || p_friction > 1);
+ friction = p_friction;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, friction);
}
-real_t StaticBody::get_friction() const{
+real_t StaticBody::get_friction() const {
return friction;
}
-void StaticBody::set_bounce(real_t p_bounce){
-
- ERR_FAIL_COND(p_bounce<0 || p_bounce>1);
+void StaticBody::set_bounce(real_t p_bounce) {
- bounce=p_bounce;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_BOUNCE,bounce);
+ ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1);
+ bounce = p_bounce;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, bounce);
}
-real_t StaticBody::get_bounce() const{
+real_t StaticBody::get_bounce() const {
return bounce;
}
+void StaticBody::set_constant_linear_velocity(const Vector3 &p_vel) {
-
-void StaticBody::set_constant_linear_velocity(const Vector3& p_vel) {
-
- constant_linear_velocity=p_vel;
- PhysicsServer::get_singleton()->body_set_state(get_rid(),PhysicsServer::BODY_STATE_LINEAR_VELOCITY,constant_linear_velocity);
-
+ constant_linear_velocity = p_vel;
+ PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity);
}
-void StaticBody::set_constant_angular_velocity(const Vector3& p_vel) {
+void StaticBody::set_constant_angular_velocity(const Vector3 &p_vel) {
- constant_angular_velocity=p_vel;
- PhysicsServer::get_singleton()->body_set_state(get_rid(),PhysicsServer::BODY_STATE_ANGULAR_VELOCITY,constant_angular_velocity);
+ constant_angular_velocity = p_vel;
+ PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity);
}
Vector3 StaticBody::get_constant_linear_velocity() const {
@@ -226,69 +214,61 @@ Vector3 StaticBody::get_constant_angular_velocity() const {
return constant_angular_velocity;
}
-
-
void StaticBody::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant_linear_velocity","vel"),&StaticBody::set_constant_linear_velocity);
- ClassDB::bind_method(D_METHOD("set_constant_angular_velocity","vel"),&StaticBody::set_constant_angular_velocity);
- ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"),&StaticBody::get_constant_linear_velocity);
- ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"),&StaticBody::get_constant_angular_velocity);
+ ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody::set_constant_linear_velocity);
+ ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody::set_constant_angular_velocity);
+ ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody::get_constant_linear_velocity);
+ ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"), &StaticBody::get_constant_angular_velocity);
- ClassDB::bind_method(D_METHOD("set_friction","friction"),&StaticBody::set_friction);
- ClassDB::bind_method(D_METHOD("get_friction"),&StaticBody::get_friction);
+ ClassDB::bind_method(D_METHOD("set_friction", "friction"), &StaticBody::set_friction);
+ ClassDB::bind_method(D_METHOD("get_friction"), &StaticBody::get_friction);
- ClassDB::bind_method(D_METHOD("set_bounce","bounce"),&StaticBody::set_bounce);
- ClassDB::bind_method(D_METHOD("get_bounce"),&StaticBody::get_bounce);
+ ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &StaticBody::set_bounce);
+ ClassDB::bind_method(D_METHOD("get_bounce"), &StaticBody::get_bounce);
- ClassDB::bind_method(D_METHOD("add_collision_exception_with","body:PhysicsBody"),&PhysicsBody::add_collision_exception_with);
- ClassDB::bind_method(D_METHOD("remove_collision_exception_with","body:PhysicsBody"),&PhysicsBody::remove_collision_exception_with);
+ ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body:PhysicsBody"), &PhysicsBody::add_collision_exception_with);
+ ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body:PhysicsBody"), &PhysicsBody::remove_collision_exception_with);
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_friction","get_friction");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_bounce","get_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3,"constant_linear_velocity"),"set_constant_linear_velocity","get_constant_linear_velocity");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3,"constant_angular_velocity"),"set_constant_angular_velocity","get_constant_angular_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_linear_velocity"), "set_constant_linear_velocity", "get_constant_linear_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity");
}
-StaticBody::StaticBody() : PhysicsBody(PhysicsServer::BODY_MODE_STATIC) {
+StaticBody::StaticBody()
+ : PhysicsBody(PhysicsServer::BODY_MODE_STATIC) {
- bounce=0;
- friction=1;
+ bounce = 0;
+ friction = 1;
}
StaticBody::~StaticBody() {
-
-
}
-
-
-
void RigidBody::_body_enter_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(E->get().in_tree);
- E->get().in_tree=true;
+ E->get().in_tree = true;
- contact_monitor->locked=true;
+ contact_monitor->locked = true;
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].local_shape);
}
- contact_monitor->locked=false;
-
-
+ contact_monitor->locked = false;
}
void RigidBody::_body_exit_tree(ObjectID p_id) {
@@ -296,58 +276,55 @@ void RigidBody::_body_exit_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(!E->get().in_tree);
- E->get().in_tree=false;
+ E->get().in_tree = false;
- contact_monitor->locked=true;
+ contact_monitor->locked = true;
- emit_signal(SceneStringNames::get_singleton()->body_exited,node);
+ emit_signal(SceneStringNames::get_singleton()->body_exited, node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].local_shape);
}
- contact_monitor->locked=false;
-
+ contact_monitor->locked = false;
}
-void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape) {
+void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) {
- bool body_in = p_status==1;
- ObjectID objid=p_instance;
+ bool body_in = p_status == 1;
+ ObjectID objid = p_instance;
Object *obj = ObjectDB::get_instance(objid);
Node *node = obj ? obj->cast_to<Node>() : NULL;
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(objid);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(objid);
ERR_FAIL_COND(!body_in && !E);
if (body_in) {
if (!E) {
- E = contact_monitor->body_map.insert(objid,BodyState());
+ E = contact_monitor->body_map.insert(objid, BodyState());
//E->get().rc=0;
- E->get().in_tree=node && node->is_inside_tree();
+ E->get().in_tree = node && node->is_inside_tree();
if (node) {
- node->connect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree,make_binds(objid));
- node->connect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
}
}
-
}
//E->get().rc++;
if (node)
- E->get().shapes.insert(ShapePair(p_body_shape,p_local_shape));
-
+ E->get().shapes.insert(ShapePair(p_body_shape, p_local_shape));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,objid,node,p_body_shape,p_local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_local_shape);
}
} else {
@@ -355,31 +332,27 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape,
//E->get().rc--;
if (node)
- E->get().shapes.erase(ShapePair(p_body_shape,p_local_shape));
+ E->get().shapes.erase(ShapePair(p_body_shape, p_local_shape));
bool in_tree = E->get().in_tree;
if (E->get().shapes.empty()) {
if (node) {
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree);
if (in_tree)
- emit_signal(SceneStringNames::get_singleton()->body_exited,obj);
-
+ emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
}
contact_monitor->body_map.erase(E);
}
if (node && in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,objid,obj,p_body_shape,p_local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_local_shape);
}
-
}
-
}
-
struct _RigidBodyInOut {
ObjectID id;
@@ -389,49 +362,49 @@ struct _RigidBodyInOut {
void RigidBody::_direct_state_changed(Object *p_state) {
- //eh.. fuck
+//eh.. fuck
#ifdef DEBUG_ENABLED
- state=p_state->cast_to<PhysicsDirectBodyState>();
+ state = p_state->cast_to<PhysicsDirectBodyState>();
#else
- state=(PhysicsDirectBodyState*)p_state; //trust it
+ state = (PhysicsDirectBodyState *)p_state; //trust it
#endif
set_ignore_transform_notification(true);
set_global_transform(state->get_transform());
- linear_velocity=state->get_linear_velocity();
- angular_velocity=state->get_angular_velocity();
- if(sleeping!=state->is_sleeping()) {
- sleeping=state->is_sleeping();
+ linear_velocity = state->get_linear_velocity();
+ angular_velocity = state->get_angular_velocity();
+ if (sleeping != state->is_sleeping()) {
+ sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
}
if (get_script_instance())
- get_script_instance()->call("_integrate_forces",state);
+ get_script_instance()->call("_integrate_forces", state);
set_ignore_transform_notification(false);
if (contact_monitor) {
- contact_monitor->locked=true;
+ contact_monitor->locked = true;
//untag all
- int rc=0;
- for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ int rc = 0;
+ for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- E->get().shapes[i].tagged=false;
+ E->get().shapes[i].tagged = false;
rc++;
}
}
- _RigidBodyInOut *toadd=(_RigidBodyInOut*)alloca(state->get_contact_count()*sizeof(_RigidBodyInOut));
- int toadd_count=0;//state->get_contact_count();
- RigidBody_RemoveAction *toremove=(RigidBody_RemoveAction*)alloca(rc*sizeof(RigidBody_RemoveAction));
- int toremove_count=0;
+ _RigidBodyInOut *toadd = (_RigidBodyInOut *)alloca(state->get_contact_count() * sizeof(_RigidBodyInOut));
+ int toadd_count = 0; //state->get_contact_count();
+ RigidBody_RemoveAction *toremove = (RigidBody_RemoveAction *)alloca(rc * sizeof(RigidBody_RemoveAction));
+ int toremove_count = 0;
//put the ones to add
- for(int i=0;i<state->get_contact_count();i++) {
+ for (int i = 0; i < state->get_contact_count(); i++) {
ObjectID obj = state->get_contact_collider_id(i);
int local_shape = state->get_contact_local_shape(i);
@@ -439,258 +412,239 @@ void RigidBody::_direct_state_changed(Object *p_state) {
//bool found=false;
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(obj);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(obj);
if (!E) {
- toadd[toadd_count].local_shape=local_shape;
- toadd[toadd_count].id=obj;
- toadd[toadd_count].shape=shape;
+ toadd[toadd_count].local_shape = local_shape;
+ toadd[toadd_count].id = obj;
+ toadd[toadd_count].shape = shape;
toadd_count++;
continue;
}
- ShapePair sp( shape,local_shape );
+ ShapePair sp(shape, local_shape);
int idx = E->get().shapes.find(sp);
- if (idx==-1) {
+ if (idx == -1) {
- toadd[toadd_count].local_shape=local_shape;
- toadd[toadd_count].id=obj;
- toadd[toadd_count].shape=shape;
+ toadd[toadd_count].local_shape = local_shape;
+ toadd[toadd_count].id = obj;
+ toadd[toadd_count].shape = shape;
toadd_count++;
continue;
}
- E->get().shapes[idx].tagged=true;
+ E->get().shapes[idx].tagged = true;
}
//put the ones to remove
- for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
if (!E->get().shapes[i].tagged) {
- toremove[toremove_count].body_id=E->key();
- toremove[toremove_count].pair=E->get().shapes[i];
+ toremove[toremove_count].body_id = E->key();
+ toremove[toremove_count].pair = E->get().shapes[i];
toremove_count++;
}
}
}
-
//process remotions
- for(int i=0;i<toremove_count;i++) {
+ for (int i = 0; i < toremove_count; i++) {
- _body_inout(0,toremove[i].body_id,toremove[i].pair.body_shape,toremove[i].pair.local_shape);
+ _body_inout(0, toremove[i].body_id, toremove[i].pair.body_shape, toremove[i].pair.local_shape);
}
//process aditions
- for(int i=0;i<toadd_count;i++) {
+ for (int i = 0; i < toadd_count; i++) {
- _body_inout(1,toadd[i].id,toadd[i].shape,toadd[i].local_shape);
+ _body_inout(1, toadd[i].id, toadd[i].shape, toadd[i].local_shape);
}
- contact_monitor->locked=false;
-
+ contact_monitor->locked = false;
}
-
-
- state=NULL;
+ state = NULL;
}
void RigidBody::_notification(int p_what) {
-
-
}
void RigidBody::set_mode(Mode p_mode) {
- mode=p_mode;
- switch(p_mode) {
+ mode = p_mode;
+ switch (p_mode) {
case MODE_RIGID: {
- PhysicsServer::get_singleton()->body_set_mode(get_rid(),PhysicsServer::BODY_MODE_RIGID);
+ PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_RIGID);
} break;
case MODE_STATIC: {
- PhysicsServer::get_singleton()->body_set_mode(get_rid(),PhysicsServer::BODY_MODE_STATIC);
+ PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_STATIC);
} break;
case MODE_CHARACTER: {
- PhysicsServer::get_singleton()->body_set_mode(get_rid(),PhysicsServer::BODY_MODE_CHARACTER);
+ PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_CHARACTER);
} break;
case MODE_KINEMATIC: {
- PhysicsServer::get_singleton()->body_set_mode(get_rid(),PhysicsServer::BODY_MODE_KINEMATIC);
+ PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_KINEMATIC);
} break;
-
}
}
-RigidBody::Mode RigidBody::get_mode() const{
+RigidBody::Mode RigidBody::get_mode() const {
return mode;
}
-void RigidBody::set_mass(real_t p_mass){
+void RigidBody::set_mass(real_t p_mass) {
- ERR_FAIL_COND(p_mass<=0);
- mass=p_mass;
+ ERR_FAIL_COND(p_mass <= 0);
+ mass = p_mass;
_change_notify("mass");
_change_notify("weight");
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_MASS,mass);
-
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_MASS, mass);
}
-real_t RigidBody::get_mass() const{
+real_t RigidBody::get_mass() const {
return mass;
}
-void RigidBody::set_weight(real_t p_weight){
+void RigidBody::set_weight(real_t p_weight) {
- set_mass(p_weight/9.8);
+ set_mass(p_weight / 9.8);
}
-real_t RigidBody::get_weight() const{
+real_t RigidBody::get_weight() const {
- return mass*9.8;
+ return mass * 9.8;
}
+void RigidBody::set_friction(real_t p_friction) {
-void RigidBody::set_friction(real_t p_friction){
-
- ERR_FAIL_COND(p_friction<0 || p_friction>1);
-
- friction=p_friction;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_FRICTION,friction);
+ ERR_FAIL_COND(p_friction < 0 || p_friction > 1);
+ friction = p_friction;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, friction);
}
-real_t RigidBody::get_friction() const{
+real_t RigidBody::get_friction() const {
return friction;
}
-void RigidBody::set_bounce(real_t p_bounce){
+void RigidBody::set_bounce(real_t p_bounce) {
- ERR_FAIL_COND(p_bounce<0 || p_bounce>1);
-
- bounce=p_bounce;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_BOUNCE,bounce);
+ ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1);
+ bounce = p_bounce;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, bounce);
}
-real_t RigidBody::get_bounce() const{
+real_t RigidBody::get_bounce() const {
return bounce;
}
+void RigidBody::set_gravity_scale(real_t p_gravity_scale) {
-void RigidBody::set_gravity_scale(real_t p_gravity_scale){
-
- gravity_scale=p_gravity_scale;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_GRAVITY_SCALE,gravity_scale);
-
+ gravity_scale = p_gravity_scale;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale);
}
-real_t RigidBody::get_gravity_scale() const{
+real_t RigidBody::get_gravity_scale() const {
return gravity_scale;
}
-void RigidBody::set_linear_damp(real_t p_linear_damp){
-
- ERR_FAIL_COND(p_linear_damp<-1);
- linear_damp=p_linear_damp;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_LINEAR_DAMP,linear_damp);
+void RigidBody::set_linear_damp(real_t p_linear_damp) {
+ ERR_FAIL_COND(p_linear_damp < -1);
+ linear_damp = p_linear_damp;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_LINEAR_DAMP, linear_damp);
}
-real_t RigidBody::get_linear_damp() const{
+real_t RigidBody::get_linear_damp() const {
return linear_damp;
}
-void RigidBody::set_angular_damp(real_t p_angular_damp){
-
- ERR_FAIL_COND(p_angular_damp<-1);
- angular_damp=p_angular_damp;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_ANGULAR_DAMP,angular_damp);
+void RigidBody::set_angular_damp(real_t p_angular_damp) {
+ ERR_FAIL_COND(p_angular_damp < -1);
+ angular_damp = p_angular_damp;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_ANGULAR_DAMP, angular_damp);
}
-real_t RigidBody::get_angular_damp() const{
+real_t RigidBody::get_angular_damp() const {
return angular_damp;
}
-void RigidBody::set_axis_velocity(const Vector3& p_axis) {
+void RigidBody::set_axis_velocity(const Vector3 &p_axis) {
- Vector3 v = state? state->get_linear_velocity() : linear_velocity;
+ Vector3 v = state ? state->get_linear_velocity() : linear_velocity;
Vector3 axis = p_axis.normalized();
- v-=axis*axis.dot(v);
- v+=p_axis;
+ v -= axis * axis.dot(v);
+ v += p_axis;
if (state) {
set_linear_velocity(v);
} else {
- PhysicsServer::get_singleton()->body_set_axis_velocity(get_rid(),p_axis);
- linear_velocity=v;
+ PhysicsServer::get_singleton()->body_set_axis_velocity(get_rid(), p_axis);
+ linear_velocity = v;
}
}
-void RigidBody::set_linear_velocity(const Vector3& p_velocity){
+void RigidBody::set_linear_velocity(const Vector3 &p_velocity) {
- linear_velocity=p_velocity;
+ linear_velocity = p_velocity;
if (state)
state->set_linear_velocity(linear_velocity);
else
- PhysicsServer::get_singleton()->body_set_state(get_rid(),PhysicsServer::BODY_STATE_LINEAR_VELOCITY,linear_velocity);
-
+ PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_LINEAR_VELOCITY, linear_velocity);
}
-Vector3 RigidBody::get_linear_velocity() const{
+Vector3 RigidBody::get_linear_velocity() const {
return linear_velocity;
}
-void RigidBody::set_angular_velocity(const Vector3& p_velocity){
+void RigidBody::set_angular_velocity(const Vector3 &p_velocity) {
- angular_velocity=p_velocity;
+ angular_velocity = p_velocity;
if (state)
state->set_angular_velocity(angular_velocity);
else
- PhysicsServer::get_singleton()->body_set_state(get_rid(),PhysicsServer::BODY_STATE_ANGULAR_VELOCITY,angular_velocity);
+ PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_ANGULAR_VELOCITY, angular_velocity);
}
-Vector3 RigidBody::get_angular_velocity() const{
+Vector3 RigidBody::get_angular_velocity() const {
return angular_velocity;
}
-void RigidBody::set_use_custom_integrator(bool p_enable){
+void RigidBody::set_use_custom_integrator(bool p_enable) {
- if (custom_integrator==p_enable)
+ if (custom_integrator == p_enable)
return;
- custom_integrator=p_enable;
- PhysicsServer::get_singleton()->body_set_omit_force_integration(get_rid(),p_enable);
-
-
+ custom_integrator = p_enable;
+ PhysicsServer::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable);
}
-bool RigidBody::is_using_custom_integrator(){
+bool RigidBody::is_using_custom_integrator() {
return custom_integrator;
}
void RigidBody::set_sleeping(bool p_sleeping) {
- sleeping=p_sleeping;
- PhysicsServer::get_singleton()->body_set_state(get_rid(),PhysicsServer::BODY_STATE_SLEEPING,sleeping);
-
+ sleeping = p_sleeping;
+ PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_SLEEPING, sleeping);
}
void RigidBody::set_can_sleep(bool p_active) {
- can_sleep=p_active;
- PhysicsServer::get_singleton()->body_set_state(get_rid(),PhysicsServer::BODY_STATE_CAN_SLEEP,p_active);
+ can_sleep = p_active;
+ PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_CAN_SLEEP, p_active);
}
bool RigidBody::is_able_to_sleep() const {
@@ -705,36 +659,34 @@ bool RigidBody::is_sleeping() const {
void RigidBody::set_max_contacts_reported(int p_amount) {
- max_contacts_reported=p_amount;
- PhysicsServer::get_singleton()->body_set_max_contacts_reported(get_rid(),p_amount);
+ max_contacts_reported = p_amount;
+ PhysicsServer::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount);
}
-int RigidBody::get_max_contacts_reported() const{
+int RigidBody::get_max_contacts_reported() const {
return max_contacts_reported;
}
-void RigidBody::apply_impulse(const Vector3& p_pos, const Vector3& p_impulse) {
+void RigidBody::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
- PhysicsServer::get_singleton()->body_apply_impulse(get_rid(),p_pos,p_impulse);
+ PhysicsServer::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse);
}
void RigidBody::set_use_continuous_collision_detection(bool p_enable) {
- ccd=p_enable;
- PhysicsServer::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(),p_enable);
+ ccd = p_enable;
+ PhysicsServer::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(), p_enable);
}
bool RigidBody::is_using_continuous_collision_detection() const {
-
return ccd;
}
-
void RigidBody::set_contact_monitor(bool p_enabled) {
- if (p_enabled==is_contact_monitor_enabled())
+ if (p_enabled == is_contact_monitor_enabled())
return;
if (!p_enabled) {
@@ -744,31 +696,29 @@ void RigidBody::set_contact_monitor(bool p_enabled) {
}
ERR_FAIL_COND(contact_monitor->locked);
- for(Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
//clean up mess
}
- memdelete( contact_monitor );
- contact_monitor=NULL;
+ memdelete(contact_monitor);
+ contact_monitor = NULL;
} else {
- contact_monitor = memnew( ContactMonitor );
- contact_monitor->locked=false;
-
+ contact_monitor = memnew(ContactMonitor);
+ contact_monitor->locked = false;
}
-
}
bool RigidBody::is_contact_monitor_enabled() const {
- return contact_monitor!=NULL;
+ return contact_monitor != NULL;
}
void RigidBody::set_axis_lock(AxisLock p_lock) {
- axis_lock=p_lock;
- PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(),PhysicsServer::BodyAxisLock(axis_lock));
+ axis_lock = p_lock;
+ PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), PhysicsServer::BodyAxisLock(axis_lock));
}
RigidBody::AxisLock RigidBody::get_axis_lock() const {
@@ -776,168 +726,161 @@ RigidBody::AxisLock RigidBody::get_axis_lock() const {
return axis_lock;
}
-
Array RigidBody::get_colliding_bodies() const {
- ERR_FAIL_COND_V(!contact_monitor,Array());
+ ERR_FAIL_COND_V(!contact_monitor, Array());
Array ret;
ret.resize(contact_monitor->body_map.size());
- int idx=0;
- for (const Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
if (!obj) {
- ret.resize( ret.size() -1 ); //ops
+ ret.resize(ret.size() - 1); //ops
} else {
- ret[idx++]=obj;
+ ret[idx++] = obj;
}
-
}
return ret;
}
-
void RigidBody::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_mode","mode"),&RigidBody::set_mode);
- ClassDB::bind_method(D_METHOD("get_mode"),&RigidBody::get_mode);
+ ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody::set_mode);
+ ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody::get_mode);
- ClassDB::bind_method(D_METHOD("set_mass","mass"),&RigidBody::set_mass);
- ClassDB::bind_method(D_METHOD("get_mass"),&RigidBody::get_mass);
+ ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody::set_mass);
+ ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody::get_mass);
- ClassDB::bind_method(D_METHOD("set_weight","weight"),&RigidBody::set_weight);
- ClassDB::bind_method(D_METHOD("get_weight"),&RigidBody::get_weight);
+ ClassDB::bind_method(D_METHOD("set_weight", "weight"), &RigidBody::set_weight);
+ ClassDB::bind_method(D_METHOD("get_weight"), &RigidBody::get_weight);
- ClassDB::bind_method(D_METHOD("set_friction","friction"),&RigidBody::set_friction);
- ClassDB::bind_method(D_METHOD("get_friction"),&RigidBody::get_friction);
+ ClassDB::bind_method(D_METHOD("set_friction", "friction"), &RigidBody::set_friction);
+ ClassDB::bind_method(D_METHOD("get_friction"), &RigidBody::get_friction);
- ClassDB::bind_method(D_METHOD("set_bounce","bounce"),&RigidBody::set_bounce);
- ClassDB::bind_method(D_METHOD("get_bounce"),&RigidBody::get_bounce);
+ ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &RigidBody::set_bounce);
+ ClassDB::bind_method(D_METHOD("get_bounce"), &RigidBody::get_bounce);
- ClassDB::bind_method(D_METHOD("set_linear_velocity","linear_velocity"),&RigidBody::set_linear_velocity);
- ClassDB::bind_method(D_METHOD("get_linear_velocity"),&RigidBody::get_linear_velocity);
+ ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidBody::set_linear_velocity);
+ ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody::get_linear_velocity);
- ClassDB::bind_method(D_METHOD("set_angular_velocity","angular_velocity"),&RigidBody::set_angular_velocity);
- ClassDB::bind_method(D_METHOD("get_angular_velocity"),&RigidBody::get_angular_velocity);
+ ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody::set_angular_velocity);
+ ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody::get_angular_velocity);
- ClassDB::bind_method(D_METHOD("set_gravity_scale","gravity_scale"),&RigidBody::set_gravity_scale);
- ClassDB::bind_method(D_METHOD("get_gravity_scale"),&RigidBody::get_gravity_scale);
+ ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody::set_gravity_scale);
+ ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody::get_gravity_scale);
- ClassDB::bind_method(D_METHOD("set_linear_damp","linear_damp"),&RigidBody::set_linear_damp);
- ClassDB::bind_method(D_METHOD("get_linear_damp"),&RigidBody::get_linear_damp);
+ ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidBody::set_linear_damp);
+ ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody::get_linear_damp);
- ClassDB::bind_method(D_METHOD("set_angular_damp","angular_damp"),&RigidBody::set_angular_damp);
- ClassDB::bind_method(D_METHOD("get_angular_damp"),&RigidBody::get_angular_damp);
+ ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidBody::set_angular_damp);
+ ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody::get_angular_damp);
+ ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidBody::set_max_contacts_reported);
+ ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody::get_max_contacts_reported);
- ClassDB::bind_method(D_METHOD("set_max_contacts_reported","amount"),&RigidBody::set_max_contacts_reported);
- ClassDB::bind_method(D_METHOD("get_max_contacts_reported"),&RigidBody::get_max_contacts_reported);
+ ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidBody::set_use_custom_integrator);
+ ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody::is_using_custom_integrator);
- ClassDB::bind_method(D_METHOD("set_use_custom_integrator","enable"),&RigidBody::set_use_custom_integrator);
- ClassDB::bind_method(D_METHOD("is_using_custom_integrator"),&RigidBody::is_using_custom_integrator);
+ ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidBody::set_contact_monitor);
+ ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody::is_contact_monitor_enabled);
- ClassDB::bind_method(D_METHOD("set_contact_monitor","enabled"),&RigidBody::set_contact_monitor);
- ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"),&RigidBody::is_contact_monitor_enabled);
+ ClassDB::bind_method(D_METHOD("set_use_continuous_collision_detection", "enable"), &RigidBody::set_use_continuous_collision_detection);
+ ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"), &RigidBody::is_using_continuous_collision_detection);
- ClassDB::bind_method(D_METHOD("set_use_continuous_collision_detection","enable"),&RigidBody::set_use_continuous_collision_detection);
- ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"),&RigidBody::is_using_continuous_collision_detection);
+ ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody::set_axis_velocity);
+ ClassDB::bind_method(D_METHOD("apply_impulse", "pos", "impulse"), &RigidBody::apply_impulse);
- ClassDB::bind_method(D_METHOD("set_axis_velocity","axis_velocity"),&RigidBody::set_axis_velocity);
- ClassDB::bind_method(D_METHOD("apply_impulse","pos","impulse"),&RigidBody::apply_impulse);
+ ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody::set_sleeping);
+ ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody::is_sleeping);
- ClassDB::bind_method(D_METHOD("set_sleeping","sleeping"),&RigidBody::set_sleeping);
- ClassDB::bind_method(D_METHOD("is_sleeping"),&RigidBody::is_sleeping);
+ ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidBody::set_can_sleep);
+ ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody::is_able_to_sleep);
- ClassDB::bind_method(D_METHOD("set_can_sleep","able_to_sleep"),&RigidBody::set_can_sleep);
- ClassDB::bind_method(D_METHOD("is_able_to_sleep"),&RigidBody::is_able_to_sleep);
+ ClassDB::bind_method(D_METHOD("_direct_state_changed"), &RigidBody::_direct_state_changed);
+ ClassDB::bind_method(D_METHOD("_body_enter_tree"), &RigidBody::_body_enter_tree);
+ ClassDB::bind_method(D_METHOD("_body_exit_tree"), &RigidBody::_body_exit_tree);
- ClassDB::bind_method(D_METHOD("_direct_state_changed"),&RigidBody::_direct_state_changed);
- ClassDB::bind_method(D_METHOD("_body_enter_tree"),&RigidBody::_body_enter_tree);
- ClassDB::bind_method(D_METHOD("_body_exit_tree"),&RigidBody::_body_exit_tree);
+ ClassDB::bind_method(D_METHOD("set_axis_lock", "axis_lock"), &RigidBody::set_axis_lock);
+ ClassDB::bind_method(D_METHOD("get_axis_lock"), &RigidBody::get_axis_lock);
- ClassDB::bind_method(D_METHOD("set_axis_lock","axis_lock"),&RigidBody::set_axis_lock);
- ClassDB::bind_method(D_METHOD("get_axis_lock"),&RigidBody::get_axis_lock);
+ ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody::get_colliding_bodies);
- ClassDB::bind_method(D_METHOD("get_colliding_bodies"),&RigidBody::get_colliding_bodies);
+ BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state:PhysicsDirectBodyState")));
- BIND_VMETHOD(MethodInfo("_integrate_forces",PropertyInfo(Variant::OBJECT,"state:PhysicsDirectBodyState")));
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Rigid,Static,Character,Kinematic"), "set_mode", "get_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "weight", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01", PROPERTY_USAGE_EDITOR), "set_weight", "get_weight");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity_scale", PROPERTY_HINT_RANGE, "-128,128,0.01"), "set_gravity_scale", "get_gravity_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "custom_integrator"), "set_use_custom_integrator", "is_using_custom_integrator");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "continuous_cd"), "set_use_continuous_collision_detection", "is_using_continuous_collision_detection");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "contacts_reported"), "set_max_contacts_reported", "get_max_contacts_reported");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "contact_monitor"), "set_contact_monitor", "is_contact_monitor_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleeping", "is_sleeping");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_lock", PROPERTY_HINT_ENUM, "Disabled,Lock X,Lock Y,Lock Z"), "set_axis_lock", "get_axis_lock");
+ ADD_GROUP("Linear", "linear_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "-1,128,0.01"), "set_linear_damp", "get_linear_damp");
+ ADD_GROUP("Angular", "angular_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "-1,128,0.01"), "set_angular_damp", "get_angular_damp");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Rigid,Static,Character,Kinematic"),"set_mode","get_mode");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"mass",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01"),"set_mass","get_mass");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"weight",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01",PROPERTY_USAGE_EDITOR),"set_weight","get_weight");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_friction","get_friction");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_bounce","get_bounce");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_scale",PROPERTY_HINT_RANGE,"-128,128,0.01"),"set_gravity_scale","get_gravity_scale");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"custom_integrator"),"set_use_custom_integrator","is_using_custom_integrator");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"continuous_cd"),"set_use_continuous_collision_detection","is_using_continuous_collision_detection");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"contacts_reported"),"set_max_contacts_reported","get_max_contacts_reported");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"contact_monitor"),"set_contact_monitor","is_contact_monitor_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"sleeping"),"set_sleeping","is_sleeping");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"can_sleep"),"set_can_sleep","is_able_to_sleep");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"axis_lock",PROPERTY_HINT_ENUM,"Disabled,Lock X,Lock Y,Lock Z"),"set_axis_lock","get_axis_lock");
- ADD_GROUP("Linear","linear_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"linear_velocity"),"set_linear_velocity","get_linear_velocity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"-1,128,0.01"),"set_linear_damp","get_linear_damp");
- ADD_GROUP("Angular","angular_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"angular_velocity"),"set_angular_velocity","get_angular_velocity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"-1,128,0.01"),"set_angular_damp","get_angular_damp");
+ ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape")));
+ ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape")));
+ ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body")));
+ ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body")));
+ ADD_SIGNAL(MethodInfo("sleeping_state_changed"));
- ADD_SIGNAL( MethodInfo("body_shape_entered",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
- ADD_SIGNAL( MethodInfo("body_shape_exited",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
- ADD_SIGNAL( MethodInfo("body_entered",PropertyInfo(Variant::OBJECT,"body")));
- ADD_SIGNAL( MethodInfo("body_exited",PropertyInfo(Variant::OBJECT,"body")));
- ADD_SIGNAL( MethodInfo("sleeping_state_changed"));
-
- BIND_CONSTANT( MODE_STATIC );
- BIND_CONSTANT( MODE_KINEMATIC );
- BIND_CONSTANT( MODE_RIGID );
- BIND_CONSTANT( MODE_CHARACTER );
+ BIND_CONSTANT(MODE_STATIC);
+ BIND_CONSTANT(MODE_KINEMATIC);
+ BIND_CONSTANT(MODE_RIGID);
+ BIND_CONSTANT(MODE_CHARACTER);
}
-RigidBody::RigidBody() : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) {
+RigidBody::RigidBody()
+ : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) {
- mode=MODE_RIGID;
+ mode = MODE_RIGID;
- bounce=0;
- mass=1;
- friction=1;
- max_contacts_reported=0;
- state=NULL;
+ bounce = 0;
+ mass = 1;
+ friction = 1;
+ max_contacts_reported = 0;
+ state = NULL;
- gravity_scale=1;
- linear_damp=-1;
- angular_damp=-1;
+ gravity_scale = 1;
+ linear_damp = -1;
+ angular_damp = -1;
//angular_velocity=0;
- sleeping=false;
- ccd=false;
+ sleeping = false;
+ ccd = false;
- custom_integrator=false;
- contact_monitor=NULL;
- can_sleep=true;
+ custom_integrator = false;
+ contact_monitor = NULL;
+ can_sleep = true;
axis_lock = AXIS_LOCK_DISABLED;
- PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(),this,"_direct_state_changed");
+ PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed");
}
RigidBody::~RigidBody() {
if (contact_monitor)
- memdelete( contact_monitor );
-
-
-
+ memdelete(contact_monitor);
}
//////////////////////////////////////////////////////
//////////////////////////
-
Variant KinematicBody::_get_collider() const {
- ObjectID oid=get_collider();
- if (oid==0)
+ ObjectID oid = get_collider();
+ if (oid == 0)
return Variant();
Object *obj = ObjectDB::get_instance(oid);
if (!obj)
@@ -951,10 +894,9 @@ Variant KinematicBody::_get_collider() const {
return obj;
}
-
bool KinematicBody::_ignores_mode(PhysicsServer::BodyMode p_mode) const {
- switch(p_mode) {
+ switch (p_mode) {
case PhysicsServer::BODY_MODE_STATIC: return !collide_static;
case PhysicsServer::BODY_MODE_KINEMATIC: return !collide_kinematic;
case PhysicsServer::BODY_MODE_RIGID: return !collide_rigid;
@@ -964,7 +906,7 @@ bool KinematicBody::_ignores_mode(PhysicsServer::BodyMode p_mode) const {
return true;
}
-Vector3 KinematicBody::move(const Vector3& p_motion) {
+Vector3 KinematicBody::move(const Vector3 &p_motion) {
//give me back regular physics engine logic
//this is madness
@@ -973,32 +915,30 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
//this took about a week to get right..
//but is it right? who knows at this point..
-
- colliding=false;
- ERR_FAIL_COND_V(!is_inside_tree(),Vector3());
+ colliding = false;
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(get_world()->get_space());
- ERR_FAIL_COND_V(!dss,Vector3());
- const int max_shapes=32;
- Vector3 sr[max_shapes*2];
+ ERR_FAIL_COND_V(!dss, Vector3());
+ const int max_shapes = 32;
+ Vector3 sr[max_shapes * 2];
int res_shapes;
Set<RID> exclude;
exclude.insert(get_rid());
-
//recover first
- int recover_attempts=4;
+ int recover_attempts = 4;
- bool collided=false;
- uint32_t mask=0;
+ bool collided = false;
+ uint32_t mask = 0;
if (collide_static)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_STATIC_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_STATIC_BODY;
if (collide_kinematic)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
if (collide_rigid)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_RIGID_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_RIGID_BODY;
if (collide_character)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY;
//print_line("motion: "+p_motion+" margin: "+rtos(margin));
@@ -1010,31 +950,28 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
do {
//motion recover
- for(int i=0;i<get_shape_count();i++) {
+ for (int i = 0; i < get_shape_count(); i++) {
if (is_shape_set_as_trigger(i))
continue;
- if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i),m,sr,max_shapes,res_shapes,exclude,get_collision_layer(),mask)) {
- collided=true;
+ if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), m, sr, max_shapes, res_shapes, exclude, get_collision_layer(), mask)) {
+ collided = true;
}
-
}
-
-
if (!collided)
break;
//print_line("have to recover");
Vector3 recover_motion;
- bool all_outside=true;
- for(int j=0;j<8;j++) {
- for(int i=0;i<res_shapes;i++) {
+ bool all_outside = true;
+ for (int j = 0; j < 8; j++) {
+ for (int i = 0; i < res_shapes; i++) {
- Vector3 a = sr[i*2+0];
- Vector3 b = sr[i*2+1];
- //print_line(String()+a+" -> "+b);
+ Vector3 a = sr[i * 2 + 0];
+ Vector3 b = sr[i * 2 + 1];
+//print_line(String()+a+" -> "+b);
#if 0
float d = a.distance_to(b);
@@ -1045,29 +982,27 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
recover_motion+=(b-a)*0.2;
#else
float dist = a.distance_to(b);
- if (dist>CMP_EPSILON) {
- Vector3 norm = (b-a).normalized();
- if (dist>margin*0.5)
- all_outside=false;
+ if (dist > CMP_EPSILON) {
+ Vector3 norm = (b - a).normalized();
+ if (dist > margin * 0.5)
+ all_outside = false;
float adv = norm.dot(recover_motion);
//print_line(itos(i)+" dist: "+rtos(dist)+" adv: "+rtos(adv));
- recover_motion+=norm*MAX(dist-adv,0)*0.4;
+ recover_motion += norm * MAX(dist - adv, 0) * 0.4;
}
#endif
-
}
}
-
- if (recover_motion==Vector3()) {
- collided=false;
+ if (recover_motion == Vector3()) {
+ collided = false;
break;
}
//print_line("**** RECOVER: "+recover_motion);
Transform gt = get_global_transform();
- gt.origin+=recover_motion;
+ gt.origin += recover_motion;
set_global_transform(gt);
recover_attempts--;
@@ -1077,133 +1012,127 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
} while (recover_attempts);
-
//move second
float safe = 1.0;
float unsafe = 1.0;
- int best_shape=-1;
+ int best_shape = -1;
PhysicsDirectSpaceState::ShapeRestInfo rest;
//print_line("pos: "+get_global_transform().origin);
//print_line("motion: "+p_motion);
-
- for(int i=0;i<get_shape_count();i++) {
-
+ for (int i = 0; i < get_shape_count(); i++) {
if (is_shape_set_as_trigger(i))
continue;
- float lsafe,lunsafe;
+ float lsafe, lunsafe;
PhysicsDirectSpaceState::ShapeRestInfo lrest;
- bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion,0, lsafe,lunsafe,exclude,get_collision_layer(),mask,&lrest);
+ bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0, lsafe, lunsafe, exclude, get_collision_layer(), mask, &lrest);
//print_line("shape: "+itos(i)+" travel:"+rtos(ltravel));
if (!valid) {
- safe=0;
- unsafe=0;
- best_shape=i; //sadly it's the best
+ safe = 0;
+ unsafe = 0;
+ best_shape = i; //sadly it's the best
//print_line("initial stuck");
break;
}
- if (lsafe==1.0) {
+ if (lsafe == 1.0) {
//print_line("initial free");
continue;
}
if (lsafe < safe) {
//print_line("initial at "+rtos(lsafe));
- safe=lsafe;
- safe=MAX(0,lsafe-0.01);
- unsafe=lunsafe;
- best_shape=i;
- rest=lrest;
+ safe = lsafe;
+ safe = MAX(0, lsafe - 0.01);
+ unsafe = lunsafe;
+ best_shape = i;
+ rest = lrest;
}
}
-
//print_line("best shape: "+itos(best_shape)+" motion "+p_motion);
- if (safe>=1) {
+ if (safe >= 1) {
//not collided
- colliding=false;
+ colliding = false;
} else {
- colliding=true;
+ colliding = true;
- if (true || (safe==0 && unsafe==0)) { //use it always because it's more precise than GJK
+ if (true || (safe == 0 && unsafe == 0)) { //use it always because it's more precise than GJK
//no advance, use rest info from collision
Transform ugt = get_global_transform();
- ugt.origin+=p_motion*unsafe;
+ ugt.origin += p_motion * unsafe;
PhysicsDirectSpaceState::ShapeRestInfo rest_info;
- bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), m,&rest,exclude,get_collision_layer(),mask);
+ bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt * get_shape_transform(best_shape), m, &rest, exclude, get_collision_layer(), mask);
if (!c2) {
//should not happen, but floating point precision is so weird..
- colliding=false;
+ colliding = false;
}
//print_line("Rest Travel: "+rest.normal);
-
}
if (colliding) {
- collision=rest.point;
- normal=rest.normal;
- collider=rest.collider_id;
- collider_vel=rest.linear_velocity;
- collider_shape=rest.shape;
+ collision = rest.point;
+ normal = rest.normal;
+ collider = rest.collider_id;
+ collider_vel = rest.linear_velocity;
+ collider_shape = rest.shape;
}
}
- Vector3 motion=p_motion*safe;
+ Vector3 motion = p_motion * safe;
/*
if (colliding)
motion+=normal*0.001;
*/
Transform gt = get_global_transform();
- gt.origin+=motion;
+ gt.origin += motion;
set_global_transform(gt);
- return p_motion-motion;
-
+ return p_motion - motion;
}
-Vector3 KinematicBody::move_to(const Vector3& p_position) {
+Vector3 KinematicBody::move_to(const Vector3 &p_position) {
- return move(p_position-get_global_transform().origin);
+ return move(p_position - get_global_transform().origin);
}
-bool KinematicBody::can_teleport_to(const Vector3& p_position) {
+bool KinematicBody::can_teleport_to(const Vector3 &p_position) {
- ERR_FAIL_COND_V(!is_inside_tree(),false);
+ ERR_FAIL_COND_V(!is_inside_tree(), false);
PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(get_world()->get_space());
- ERR_FAIL_COND_V(!dss,false);
+ ERR_FAIL_COND_V(!dss, false);
- uint32_t mask=0;
+ uint32_t mask = 0;
if (collide_static)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_STATIC_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_STATIC_BODY;
if (collide_kinematic)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
if (collide_rigid)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_RIGID_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_RIGID_BODY;
if (collide_character)
- mask|=PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY;
+ mask |= PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY;
- Transform xform=get_global_transform();
- xform.origin=p_position;
+ Transform xform = get_global_transform();
+ xform.origin = p_position;
Set<RID> exclude;
exclude.insert(get_rid());
- for(int i=0;i<get_shape_count();i++) {
+ for (int i = 0; i < get_shape_count(); i++) {
if (is_shape_set_as_trigger(i))
continue;
- bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,1,exclude,get_collision_layer(),mask);
+ bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i), 0, NULL, 1, exclude, get_collision_layer(), mask);
if (col)
return false;
}
@@ -1213,21 +1142,19 @@ bool KinematicBody::can_teleport_to(const Vector3& p_position) {
bool KinematicBody::is_colliding() const {
- ERR_FAIL_COND_V(!is_inside_tree(),false);
+ ERR_FAIL_COND_V(!is_inside_tree(), false);
return colliding;
}
Vector3 KinematicBody::get_collision_pos() const {
- ERR_FAIL_COND_V(!colliding,Vector3());
+ ERR_FAIL_COND_V(!colliding, Vector3());
return collision;
-
}
Vector3 KinematicBody::get_collision_normal() const {
- ERR_FAIL_COND_V(!colliding,Vector3());
+ ERR_FAIL_COND_V(!colliding, Vector3());
return normal;
-
}
Vector3 KinematicBody::get_collider_velocity() const {
@@ -1237,18 +1164,17 @@ Vector3 KinematicBody::get_collider_velocity() const {
ObjectID KinematicBody::get_collider() const {
- ERR_FAIL_COND_V(!colliding,0);
+ ERR_FAIL_COND_V(!colliding, 0);
return collider;
}
int KinematicBody::get_collider_shape() const {
- ERR_FAIL_COND_V(!colliding,-1);
+ ERR_FAIL_COND_V(!colliding, -1);
return collider_shape;
-
}
void KinematicBody::set_collide_with_static_bodies(bool p_enable) {
- collide_static=p_enable;
+ collide_static = p_enable;
}
bool KinematicBody::can_collide_with_static_bodies() const {
@@ -1257,19 +1183,16 @@ bool KinematicBody::can_collide_with_static_bodies() const {
void KinematicBody::set_collide_with_rigid_bodies(bool p_enable) {
- collide_rigid=p_enable;
-
+ collide_rigid = p_enable;
}
bool KinematicBody::can_collide_with_rigid_bodies() const {
-
return collide_rigid;
}
void KinematicBody::set_collide_with_kinematic_bodies(bool p_enable) {
- collide_kinematic=p_enable;
-
+ collide_kinematic = p_enable;
}
bool KinematicBody::can_collide_with_kinematic_bodies() const {
@@ -1278,7 +1201,7 @@ bool KinematicBody::can_collide_with_kinematic_bodies() const {
void KinematicBody::set_collide_with_character_bodies(bool p_enable) {
- collide_character=p_enable;
+ collide_character = p_enable;
}
bool KinematicBody::can_collide_with_character_bodies() const {
@@ -1287,70 +1210,63 @@ bool KinematicBody::can_collide_with_character_bodies() const {
void KinematicBody::set_collision_margin(float p_margin) {
- margin=p_margin;
+ margin = p_margin;
}
-float KinematicBody::get_collision_margin() const{
+float KinematicBody::get_collision_margin() const {
return margin;
}
void KinematicBody::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("move", "rel_vec"), &KinematicBody::move);
+ ClassDB::bind_method(D_METHOD("move_to", "position"), &KinematicBody::move_to);
- ClassDB::bind_method(D_METHOD("move","rel_vec"),&KinematicBody::move);
- ClassDB::bind_method(D_METHOD("move_to","position"),&KinematicBody::move_to);
-
- ClassDB::bind_method(D_METHOD("can_teleport_to","position"),&KinematicBody::can_teleport_to);
-
- ClassDB::bind_method(D_METHOD("is_colliding"),&KinematicBody::is_colliding);
-
- ClassDB::bind_method(D_METHOD("get_collision_pos"),&KinematicBody::get_collision_pos);
- ClassDB::bind_method(D_METHOD("get_collision_normal"),&KinematicBody::get_collision_normal);
- ClassDB::bind_method(D_METHOD("get_collider_velocity"),&KinematicBody::get_collider_velocity);
- ClassDB::bind_method(D_METHOD("get_collider:Variant"),&KinematicBody::_get_collider);
- ClassDB::bind_method(D_METHOD("get_collider_shape"),&KinematicBody::get_collider_shape);
+ ClassDB::bind_method(D_METHOD("can_teleport_to", "position"), &KinematicBody::can_teleport_to);
+ ClassDB::bind_method(D_METHOD("is_colliding"), &KinematicBody::is_colliding);
- ClassDB::bind_method(D_METHOD("set_collide_with_static_bodies","enable"),&KinematicBody::set_collide_with_static_bodies);
- ClassDB::bind_method(D_METHOD("can_collide_with_static_bodies"),&KinematicBody::can_collide_with_static_bodies);
+ ClassDB::bind_method(D_METHOD("get_collision_pos"), &KinematicBody::get_collision_pos);
+ ClassDB::bind_method(D_METHOD("get_collision_normal"), &KinematicBody::get_collision_normal);
+ ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicBody::get_collider_velocity);
+ ClassDB::bind_method(D_METHOD("get_collider:Variant"), &KinematicBody::_get_collider);
+ ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicBody::get_collider_shape);
- ClassDB::bind_method(D_METHOD("set_collide_with_kinematic_bodies","enable"),&KinematicBody::set_collide_with_kinematic_bodies);
- ClassDB::bind_method(D_METHOD("can_collide_with_kinematic_bodies"),&KinematicBody::can_collide_with_kinematic_bodies);
+ ClassDB::bind_method(D_METHOD("set_collide_with_static_bodies", "enable"), &KinematicBody::set_collide_with_static_bodies);
+ ClassDB::bind_method(D_METHOD("can_collide_with_static_bodies"), &KinematicBody::can_collide_with_static_bodies);
- ClassDB::bind_method(D_METHOD("set_collide_with_rigid_bodies","enable"),&KinematicBody::set_collide_with_rigid_bodies);
- ClassDB::bind_method(D_METHOD("can_collide_with_rigid_bodies"),&KinematicBody::can_collide_with_rigid_bodies);
+ ClassDB::bind_method(D_METHOD("set_collide_with_kinematic_bodies", "enable"), &KinematicBody::set_collide_with_kinematic_bodies);
+ ClassDB::bind_method(D_METHOD("can_collide_with_kinematic_bodies"), &KinematicBody::can_collide_with_kinematic_bodies);
- ClassDB::bind_method(D_METHOD("set_collide_with_character_bodies","enable"),&KinematicBody::set_collide_with_character_bodies);
- ClassDB::bind_method(D_METHOD("can_collide_with_character_bodies"),&KinematicBody::can_collide_with_character_bodies);
+ ClassDB::bind_method(D_METHOD("set_collide_with_rigid_bodies", "enable"), &KinematicBody::set_collide_with_rigid_bodies);
+ ClassDB::bind_method(D_METHOD("can_collide_with_rigid_bodies"), &KinematicBody::can_collide_with_rigid_bodies);
- ClassDB::bind_method(D_METHOD("set_collision_margin","pixels"),&KinematicBody::set_collision_margin);
- ClassDB::bind_method(D_METHOD("get_collision_margin","pixels"),&KinematicBody::get_collision_margin);
-
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collide_with/static"),"set_collide_with_static_bodies","can_collide_with_static_bodies");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collide_with/kinematic"),"set_collide_with_kinematic_bodies","can_collide_with_kinematic_bodies");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collide_with/rigid"),"set_collide_with_rigid_bodies","can_collide_with_rigid_bodies");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collide_with/character"),"set_collide_with_character_bodies","can_collide_with_character_bodies");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/margin",PROPERTY_HINT_RANGE,"0.001,256,0.001"),"set_collision_margin","get_collision_margin");
+ ClassDB::bind_method(D_METHOD("set_collide_with_character_bodies", "enable"), &KinematicBody::set_collide_with_character_bodies);
+ ClassDB::bind_method(D_METHOD("can_collide_with_character_bodies"), &KinematicBody::can_collide_with_character_bodies);
+ ClassDB::bind_method(D_METHOD("set_collision_margin", "pixels"), &KinematicBody::set_collision_margin);
+ ClassDB::bind_method(D_METHOD("get_collision_margin", "pixels"), &KinematicBody::get_collision_margin);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/static"), "set_collide_with_static_bodies", "can_collide_with_static_bodies");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/kinematic"), "set_collide_with_kinematic_bodies", "can_collide_with_kinematic_bodies");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/rigid"), "set_collide_with_rigid_bodies", "can_collide_with_rigid_bodies");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/character"), "set_collide_with_character_bodies", "can_collide_with_character_bodies");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision/margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_collision_margin", "get_collision_margin");
}
-KinematicBody::KinematicBody() : PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC){
+KinematicBody::KinematicBody()
+ : PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC) {
- collide_static=true;
- collide_rigid=true;
- collide_kinematic=true;
- collide_character=true;
+ collide_static = true;
+ collide_rigid = true;
+ collide_kinematic = true;
+ collide_character = true;
- colliding=false;
- collider=0;
- margin=0.001;
- collider_shape=0;
+ colliding = false;
+ collider = 0;
+ margin = 0.001;
+ collider_shape = 0;
}
-KinematicBody::~KinematicBody() {
-
-
+KinematicBody::~KinematicBody() {
}
-
-
diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h
index 86be98f81e..1cef946836 100644
--- a/scene/3d/physics_body.h
+++ b/scene/3d/physics_body.h
@@ -33,10 +33,9 @@
#include "servers/physics_server.h"
#include "vset.h"
-
class PhysicsBody : public CollisionObject {
- GDCLASS(PhysicsBody,CollisionObject);
+ GDCLASS(PhysicsBody, CollisionObject);
uint32_t layer_mask;
uint32_t collision_mask;
@@ -45,12 +44,11 @@ class PhysicsBody : public CollisionObject {
uint32_t _get_layers() const;
protected:
-
static void _bind_methods();
void _notification(int p_what);
PhysicsBody(PhysicsServer::BodyMode p_mode);
-public:
+public:
virtual Vector3 get_linear_velocity() const;
virtual Vector3 get_angular_velocity() const;
virtual float get_inverse_mass() const;
@@ -67,18 +65,15 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
- void add_collision_exception_with(Node* p_node); //must be physicsbody
- void remove_collision_exception_with(Node* p_node);
-
-
+ void add_collision_exception_with(Node *p_node); //must be physicsbody
+ void remove_collision_exception_with(Node *p_node);
PhysicsBody();
-
};
class StaticBody : public PhysicsBody {
- GDCLASS(StaticBody,PhysicsBody);
+ GDCLASS(StaticBody, PhysicsBody);
Vector3 constant_linear_velocity;
Vector3 constant_angular_velocity;
@@ -86,37 +81,31 @@ class StaticBody : public PhysicsBody {
real_t bounce;
real_t friction;
-
protected:
-
static void _bind_methods();
public:
-
-
void set_friction(real_t p_friction);
real_t get_friction() const;
void set_bounce(real_t p_bounce);
real_t get_bounce() const;
-
- void set_constant_linear_velocity(const Vector3& p_vel);
- void set_constant_angular_velocity(const Vector3& p_vel);
+ void set_constant_linear_velocity(const Vector3 &p_vel);
+ void set_constant_angular_velocity(const Vector3 &p_vel);
Vector3 get_constant_linear_velocity() const;
Vector3 get_constant_angular_velocity() const;
StaticBody();
~StaticBody();
-
};
class RigidBody : public PhysicsBody {
- GDCLASS(RigidBody,PhysicsBody);
-public:
+ GDCLASS(RigidBody, PhysicsBody);
+public:
enum Mode {
MODE_RIGID,
MODE_STATIC,
@@ -132,7 +121,6 @@ public:
};
private:
-
bool can_sleep;
PhysicsDirectBodyState *state;
Mode mode;
@@ -142,7 +130,7 @@ private:
real_t friction;
Vector3 linear_velocity;
- Vector3 angular_velocity;
+ Vector3 angular_velocity;
real_t gravity_scale;
real_t linear_damp;
real_t angular_damp;
@@ -152,33 +140,32 @@ private:
AxisLock axis_lock;
-
int max_contacts_reported;
bool custom_integrator;
-
struct ShapePair {
int body_shape;
int local_shape;
bool tagged;
- bool operator<(const ShapePair& p_sp) const {
- if (body_shape==p_sp.body_shape)
+ bool operator<(const ShapePair &p_sp) const {
+ if (body_shape == p_sp.body_shape)
return local_shape < p_sp.local_shape;
else
return body_shape < p_sp.body_shape;
}
ShapePair() {}
- ShapePair(int p_bs, int p_ls) { body_shape=p_bs; local_shape=p_ls; }
+ ShapePair(int p_bs, int p_ls) {
+ body_shape = p_bs;
+ local_shape = p_ls;
+ }
};
struct RigidBody_RemoveAction {
-
ObjectID body_id;
ShapePair pair;
-
};
struct BodyState {
@@ -190,33 +177,28 @@ private:
struct ContactMonitor {
bool locked;
- Map<ObjectID,BodyState> body_map;
-
+ Map<ObjectID, BodyState> body_map;
};
-
ContactMonitor *contact_monitor;
void _body_enter_tree(ObjectID p_id);
void _body_exit_tree(ObjectID p_id);
-
- void _body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape);
+ void _body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape);
void _direct_state_changed(Object *p_state);
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_mode(Mode p_mode);
Mode get_mode() const;
void set_mass(real_t p_mass);
real_t get_mass() const;
- virtual float get_inverse_mass() const { return 1.0/mass; }
+ virtual float get_inverse_mass() const { return 1.0 / mass; }
void set_weight(real_t p_weight);
real_t get_weight() const;
@@ -227,13 +209,13 @@ public:
void set_bounce(real_t p_bounce);
real_t get_bounce() const;
- void set_linear_velocity(const Vector3& p_velocity);
+ void set_linear_velocity(const Vector3 &p_velocity);
Vector3 get_linear_velocity() const;
- void set_axis_velocity(const Vector3& p_axis);
+ void set_axis_velocity(const Vector3 &p_axis);
- void set_angular_velocity(const Vector3&p_velocity);
- Vector3 get_angular_velocity() const;
+ void set_angular_velocity(const Vector3 &p_velocity);
+ Vector3 get_angular_velocity() const;
void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const;
@@ -244,7 +226,6 @@ public:
void set_angular_damp(real_t p_angular_damp);
real_t get_angular_damp() const;
-
void set_use_custom_integrator(bool p_enable);
bool is_using_custom_integrator();
@@ -268,23 +249,18 @@ public:
Array get_colliding_bodies() const;
- void apply_impulse(const Vector3& p_pos, const Vector3& p_impulse);
+ void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
RigidBody();
~RigidBody();
-
};
VARIANT_ENUM_CAST(RigidBody::Mode);
VARIANT_ENUM_CAST(RigidBody::AxisLock);
-
-
-
-
class KinematicBody : public PhysicsBody {
- GDCLASS(KinematicBody,PhysicsBody);
+ GDCLASS(KinematicBody, PhysicsBody);
float margin;
bool collide_static;
@@ -299,26 +275,24 @@ class KinematicBody : public PhysicsBody {
ObjectID collider;
int collider_shape;
-
-
Variant _get_collider() const;
_FORCE_INLINE_ bool _ignores_mode(PhysicsServer::BodyMode) const;
-protected:
+protected:
static void _bind_methods();
-public:
+public:
enum {
SLIDE_FLAG_FLOOR,
SLIDE_FLAG_WALL,
SLIDE_FLAG_ROOF
};
- Vector3 move(const Vector3& p_motion);
- Vector3 move_to(const Vector3& p_position);
+ Vector3 move(const Vector3 &p_motion);
+ Vector3 move_to(const Vector3 &p_position);
- bool can_teleport_to(const Vector3& p_position);
+ bool can_teleport_to(const Vector3 &p_position);
bool is_colliding() const;
Vector3 get_collision_pos() const;
Vector3 get_collision_normal() const;
@@ -343,7 +317,6 @@ public:
KinematicBody();
~KinematicBody();
-
};
#endif // PHYSICS_BODY__H
diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp
index d48d75f464..8c20b003f8 100644
--- a/scene/3d/physics_joint.cpp
+++ b/scene/3d/physics_joint.cpp
@@ -28,101 +28,89 @@
/*************************************************************************/
#include "physics_joint.h"
-
-
void Joint::_update_joint(bool p_only_free) {
-
if (joint.is_valid()) {
if (ba.is_valid() && bb.is_valid()) {
if (exclude_from_collision)
- PhysicsServer::get_singleton()->body_add_collision_exception(ba,bb);
+ PhysicsServer::get_singleton()->body_add_collision_exception(ba, bb);
else
- PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb);
-
+ PhysicsServer::get_singleton()->body_remove_collision_exception(ba, bb);
}
PhysicsServer::get_singleton()->free(joint);
- joint=RID();
- ba=RID();
- bb=RID();
+ joint = RID();
+ ba = RID();
+ bb = RID();
}
if (p_only_free || !is_inside_tree())
return;
- Node *node_a = has_node( get_node_a() ) ? get_node( get_node_a() ) : (Node*)NULL;
- Node *node_b = has_node( get_node_b() ) ? get_node( get_node_b() ) : (Node*)NULL;
+ Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
+ Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
if (!node_a && !node_b)
return;
- PhysicsBody *body_a=node_a ? node_a->cast_to<PhysicsBody>() : (PhysicsBody*)NULL;
- PhysicsBody *body_b=node_b ? node_b->cast_to<PhysicsBody>() : (PhysicsBody*)NULL;
+ PhysicsBody *body_a = node_a ? node_a->cast_to<PhysicsBody>() : (PhysicsBody *)NULL;
+ PhysicsBody *body_b = node_b ? node_b->cast_to<PhysicsBody>() : (PhysicsBody *)NULL;
if (!body_a && !body_b)
return;
if (!body_a) {
- SWAP(body_a,body_b);
+ SWAP(body_a, body_b);
} else if (body_b) {
//add a collision exception between both
- PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid());
+ PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
}
- joint = _configure_joint(body_a,body_b);
+ joint = _configure_joint(body_a, body_b);
if (joint.is_valid())
- PhysicsServer::get_singleton()->joint_set_solver_priority(joint,solver_priority);
+ PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority);
if (body_b && joint.is_valid()) {
- ba=body_a->get_rid();
- bb=body_b->get_rid();
- PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid());
-
+ ba = body_a->get_rid();
+ bb = body_b->get_rid();
+ PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
}
-
}
+void Joint::set_node_a(const NodePath &p_node_a) {
-void Joint::set_node_a(const NodePath& p_node_a) {
-
-
- if (a==p_node_a)
+ if (a == p_node_a)
return;
- a=p_node_a;
+ a = p_node_a;
_update_joint();
}
-NodePath Joint::get_node_a() const{
+NodePath Joint::get_node_a() const {
return a;
}
-void Joint::set_node_b(const NodePath& p_node_b){
+void Joint::set_node_b(const NodePath &p_node_b) {
- if (b==p_node_b)
+ if (b == p_node_b)
return;
- b=p_node_b;
+ b = p_node_b;
_update_joint();
-
}
-NodePath Joint::get_node_b() const{
-
+NodePath Joint::get_node_b() const {
return b;
}
-
void Joint::set_solver_priority(int p_priority) {
- solver_priority=p_priority;
+ solver_priority = p_priority;
if (joint.is_valid())
- PhysicsServer::get_singleton()->joint_set_solver_priority(joint,solver_priority);
-
+ PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority);
}
int Joint::get_solver_priority() const {
@@ -130,10 +118,9 @@ int Joint::get_solver_priority() const {
return solver_priority;
}
-
void Joint::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_READY: {
_update_joint();
@@ -142,95 +129,83 @@ void Joint::_notification(int p_what) {
if (joint.is_valid()) {
_update_joint(true);
//PhysicsServer::get_singleton()->free(joint);
- joint=RID();
+ joint = RID();
}
} break;
-
}
-
}
-
void Joint::set_exclude_nodes_from_collision(bool p_enable) {
- if (exclude_from_collision==p_enable)
+ if (exclude_from_collision == p_enable)
return;
- exclude_from_collision=p_enable;
+ exclude_from_collision = p_enable;
_update_joint();
}
-bool Joint::get_exclude_nodes_from_collision() const{
+bool Joint::get_exclude_nodes_from_collision() const {
return exclude_from_collision;
}
void Joint::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint::set_node_a);
+ ClassDB::bind_method(D_METHOD("get_node_a"), &Joint::get_node_a);
- ClassDB::bind_method( D_METHOD("set_node_a","node"), &Joint::set_node_a );
- ClassDB::bind_method( D_METHOD("get_node_a"), &Joint::get_node_a );
-
- ClassDB::bind_method( D_METHOD("set_node_b","node"), &Joint::set_node_b );
- ClassDB::bind_method( D_METHOD("get_node_b"), &Joint::get_node_b );
-
- ClassDB::bind_method( D_METHOD("set_solver_priority","priority"), &Joint::set_solver_priority );
- ClassDB::bind_method( D_METHOD("get_solver_priority"), &Joint::get_solver_priority );
+ ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint::set_node_b);
+ ClassDB::bind_method(D_METHOD("get_node_b"), &Joint::get_node_b);
- ClassDB::bind_method( D_METHOD("set_exclude_nodes_from_collision","enable"), &Joint::set_exclude_nodes_from_collision );
- ClassDB::bind_method( D_METHOD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision );
-
- ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_a"), "set_node_a","get_node_a") ;
- ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_b"), "set_node_b","get_node_b") ;
- ADD_PROPERTY( PropertyInfo( Variant::INT, "solver/priority",PROPERTY_HINT_RANGE,"1,8,1"), "set_solver_priority","get_solver_priority") ;
-
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "collision/exclude_nodes"), "set_exclude_nodes_from_collision","get_exclude_nodes_from_collision") ;
+ ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint::set_solver_priority);
+ ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint::get_solver_priority);
+ ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint::set_exclude_nodes_from_collision);
+ ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision);
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a"), "set_node_a", "get_node_a");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b"), "set_node_b", "get_node_b");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "solver/priority", PROPERTY_HINT_RANGE, "1,8,1"), "set_solver_priority", "get_solver_priority");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision/exclude_nodes"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision");
}
-
-
Joint::Joint() {
- exclude_from_collision=true;
- solver_priority=1;
+ exclude_from_collision = true;
+ solver_priority = 1;
set_notify_transform(true);
}
-
///////////////////////////////////
void PinJoint::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_param","param","value"),&PinJoint::set_param);
- ClassDB::bind_method(D_METHOD("get_param","param"),&PinJoint::get_param);
+ ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint::set_param);
+ ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint::get_param);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/bias",PROPERTY_HINT_RANGE,"0.01,0.99,0.01"),"set_param","get_param", PARAM_BIAS );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/damping",PROPERTY_HINT_RANGE,"0.01,8.0,0.01"),"set_param","get_param", PARAM_DAMPING );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/impulse_clamp",PROPERTY_HINT_RANGE,"0.0,64.0,0.01"),"set_param","get_param", PARAM_IMPULSE_CLAMP );
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_BIAS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/damping", PROPERTY_HINT_RANGE, "0.01,8.0,0.01"), "set_param", "get_param", PARAM_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/impulse_clamp", PROPERTY_HINT_RANGE, "0.0,64.0,0.01"), "set_param", "get_param", PARAM_IMPULSE_CLAMP);
- BIND_CONSTANT( PARAM_BIAS );
- BIND_CONSTANT( PARAM_DAMPING );
- BIND_CONSTANT( PARAM_IMPULSE_CLAMP );
+ BIND_CONSTANT(PARAM_BIAS);
+ BIND_CONSTANT(PARAM_DAMPING);
+ BIND_CONSTANT(PARAM_IMPULSE_CLAMP);
}
-void PinJoint::set_param(Param p_param,float p_value){
+void PinJoint::set_param(Param p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,3);
- params[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, 3);
+ params[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->pin_joint_set_param(get_joint(),PhysicsServer::PinJointParam(p_param),p_value);
+ PhysicsServer::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer::PinJointParam(p_param), p_value);
}
-float PinJoint::get_param(Param p_param) const{
+float PinJoint::get_param(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,3,0);
+ ERR_FAIL_INDEX_V(p_param, 3, 0);
return params[p_param];
}
-
-RID PinJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
-
+RID PinJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
Vector3 pinpos = get_global_transform().origin;
Vector3 local_a = body_a->get_global_transform().affine_inverse().xform(pinpos);
@@ -239,37 +214,29 @@ RID PinJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
if (body_b)
local_b = body_b->get_global_transform().affine_inverse().xform(pinpos);
else
- local_b=pinpos;
+ local_b = pinpos;
- RID j = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(),local_a,body_b?body_b->get_rid():RID(),local_b);
- for(int i=0;i<3;i++) {
- PhysicsServer::get_singleton()->pin_joint_set_param(j,PhysicsServer::PinJointParam(i),params[i]);
+ RID j = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
+ for (int i = 0; i < 3; i++) {
+ PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PinJointParam(i), params[i]);
}
return j;
}
-
PinJoint::PinJoint() {
- params[PARAM_BIAS]=0.3;
- params[PARAM_DAMPING]=1;
- params[PARAM_IMPULSE_CLAMP]=0;
-
+ params[PARAM_BIAS] = 0.3;
+ params[PARAM_DAMPING] = 1;
+ params[PARAM_IMPULSE_CLAMP] = 0;
}
-
-
-
/////////////////////////////////////////////////
-
-
///////////////////////////////////
-
void HingeJoint::_set_upper_limit(float p_limit) {
- set_param(PARAM_LIMIT_UPPER,Math::deg2rad(p_limit));
+ set_param(PARAM_LIMIT_UPPER, Math::deg2rad(p_limit));
}
float HingeJoint::_get_upper_limit() const {
@@ -279,95 +246,87 @@ float HingeJoint::_get_upper_limit() const {
void HingeJoint::_set_lower_limit(float p_limit) {
- set_param(PARAM_LIMIT_LOWER,Math::deg2rad(p_limit));
-
+ set_param(PARAM_LIMIT_LOWER, Math::deg2rad(p_limit));
}
float HingeJoint::_get_lower_limit() const {
return Math::rad2deg(get_param(PARAM_LIMIT_LOWER));
-
}
-
void HingeJoint::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_param","param","value"),&HingeJoint::set_param);
- ClassDB::bind_method(D_METHOD("get_param","param"),&HingeJoint::get_param);
-
- ClassDB::bind_method(D_METHOD("set_flag","flag","enabled"),&HingeJoint::set_flag);
- ClassDB::bind_method(D_METHOD("get_flag","flag"),&HingeJoint::get_flag);
+ ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint::set_param);
+ ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint::get_param);
- ClassDB::bind_method(D_METHOD("_set_upper_limit","upper_limit"),&HingeJoint::_set_upper_limit);
- ClassDB::bind_method(D_METHOD("_get_upper_limit"),&HingeJoint::_get_upper_limit);
+ ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint::set_flag);
+ ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint::get_flag);
- ClassDB::bind_method(D_METHOD("_set_lower_limit","lower_limit"),&HingeJoint::_set_lower_limit);
- ClassDB::bind_method(D_METHOD("_get_lower_limit"),&HingeJoint::_get_lower_limit);
+ ClassDB::bind_method(D_METHOD("_set_upper_limit", "upper_limit"), &HingeJoint::_set_upper_limit);
+ ClassDB::bind_method(D_METHOD("_get_upper_limit"), &HingeJoint::_get_upper_limit);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/bias",PROPERTY_HINT_RANGE,"0.01,0.99,0.01"),"set_param","get_param", PARAM_BIAS );
+ ClassDB::bind_method(D_METHOD("_set_lower_limit", "lower_limit"), &HingeJoint::_set_lower_limit);
+ ClassDB::bind_method(D_METHOD("_get_lower_limit"), &HingeJoint::_get_lower_limit);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"angular_limit/enable"),"set_flag","get_flag", FLAG_USE_LIMIT );
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_limit/upper",PROPERTY_HINT_RANGE,"-180,180,0.1"),"_set_upper_limit","_get_upper_limit") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_limit/lower",PROPERTY_HINT_RANGE,"-180,180,0.1"),"_set_lower_limit","_get_lower_limit") ;
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_limit/bias",PROPERTY_HINT_RANGE,"0.01,0.99,0.01"),"set_param","get_param", PARAM_LIMIT_BIAS );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_limit/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param","get_param", PARAM_LIMIT_SOFTNESS );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_limit/relaxation",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param","get_param", PARAM_LIMIT_RELAXATION );
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_BIAS);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"motor/enable"),"set_flag","get_flag", FLAG_ENABLE_MOTOR );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"motor/target_velocity",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),"set_param","get_param", PARAM_MOTOR_TARGET_VELOCITY );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"motor/max_impulse",PROPERTY_HINT_RANGE,"0.01,1024,0.01"),"set_param","get_param", PARAM_MOTOR_MAX_IMPULSE);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit/enable"), "set_flag", "get_flag", FLAG_USE_LIMIT);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/upper", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_upper_limit", "_get_upper_limit");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/lower", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_lower_limit", "_get_lower_limit");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_LIMIT_BIAS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param", "get_param", PARAM_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/relaxation", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param", "get_param", PARAM_LIMIT_RELAXATION);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "motor/enable"), "set_flag", "get_flag", FLAG_ENABLE_MOTOR);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "motor/target_velocity", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_param", "get_param", PARAM_MOTOR_TARGET_VELOCITY);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "motor/max_impulse", PROPERTY_HINT_RANGE, "0.01,1024,0.01"), "set_param", "get_param", PARAM_MOTOR_MAX_IMPULSE);
- BIND_CONSTANT( PARAM_BIAS );
- BIND_CONSTANT( PARAM_LIMIT_UPPER );
- BIND_CONSTANT( PARAM_LIMIT_LOWER );
- BIND_CONSTANT( PARAM_LIMIT_BIAS );
- BIND_CONSTANT( PARAM_LIMIT_SOFTNESS );
- BIND_CONSTANT( PARAM_LIMIT_RELAXATION );
- BIND_CONSTANT( PARAM_MOTOR_TARGET_VELOCITY );
- BIND_CONSTANT( PARAM_MOTOR_MAX_IMPULSE );
- BIND_CONSTANT( PARAM_MAX );
-
- BIND_CONSTANT( FLAG_USE_LIMIT );
- BIND_CONSTANT( FLAG_ENABLE_MOTOR );
- BIND_CONSTANT( FLAG_MAX );
+ BIND_CONSTANT(PARAM_BIAS);
+ BIND_CONSTANT(PARAM_LIMIT_UPPER);
+ BIND_CONSTANT(PARAM_LIMIT_LOWER);
+ BIND_CONSTANT(PARAM_LIMIT_BIAS);
+ BIND_CONSTANT(PARAM_LIMIT_SOFTNESS);
+ BIND_CONSTANT(PARAM_LIMIT_RELAXATION);
+ BIND_CONSTANT(PARAM_MOTOR_TARGET_VELOCITY);
+ BIND_CONSTANT(PARAM_MOTOR_MAX_IMPULSE);
+ BIND_CONSTANT(PARAM_MAX);
+ BIND_CONSTANT(FLAG_USE_LIMIT);
+ BIND_CONSTANT(FLAG_ENABLE_MOTOR);
+ BIND_CONSTANT(FLAG_MAX);
}
-void HingeJoint::set_param(Param p_param,float p_value){
+void HingeJoint::set_param(Param p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- params[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ params[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->hinge_joint_set_param(get_joint(),PhysicsServer::HingeJointParam(p_param),p_value);
+ PhysicsServer::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer::HingeJointParam(p_param), p_value);
update_gizmo();
-
}
-float HingeJoint::get_param(Param p_param) const{
+float HingeJoint::get_param(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return params[p_param];
}
+void HingeJoint::set_flag(Flag p_flag, bool p_value) {
-void HingeJoint::set_flag(Flag p_flag,bool p_value){
-
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- flags[p_flag]=p_value;
+ ERR_FAIL_INDEX(p_flag, FLAG_MAX);
+ flags[p_flag] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->hinge_joint_set_flag(get_joint(),PhysicsServer::HingeJointFlag(p_flag),p_value);
+ PhysicsServer::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer::HingeJointFlag(p_flag), p_value);
update_gizmo();
}
-bool HingeJoint::get_flag(Flag p_flag) const{
+bool HingeJoint::get_flag(Flag p_flag) const {
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
+ ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
return flags[p_flag];
}
-RID HingeJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
-
+RID HingeJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
Transform gt = get_global_transform();
Transform ainv = body_a->get_global_transform().affine_inverse();
@@ -383,48 +342,39 @@ RID HingeJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
local_b.orthonormalize();
- RID j = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(),local_a,body_b?body_b->get_rid():RID(),local_b);
- for(int i=0;i<PARAM_MAX;i++) {
- PhysicsServer::get_singleton()->hinge_joint_set_param(j,PhysicsServer::HingeJointParam(i),params[i]);
+ RID j = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
+ for (int i = 0; i < PARAM_MAX; i++) {
+ PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HingeJointParam(i), params[i]);
}
- for(int i=0;i<FLAG_MAX;i++) {
- set_flag(Flag(i),flags[i]);
- PhysicsServer::get_singleton()->hinge_joint_set_flag(j,PhysicsServer::HingeJointFlag(i),flags[i]);
+ for (int i = 0; i < FLAG_MAX; i++) {
+ set_flag(Flag(i), flags[i]);
+ PhysicsServer::get_singleton()->hinge_joint_set_flag(j, PhysicsServer::HingeJointFlag(i), flags[i]);
}
return j;
}
-
HingeJoint::HingeJoint() {
- params[PARAM_BIAS]=0.3;
- params[PARAM_LIMIT_UPPER]=Math_PI*0.5;
- params[PARAM_LIMIT_LOWER]=-Math_PI*0.5;
- params[PARAM_LIMIT_BIAS]=0.3;
- params[PARAM_LIMIT_SOFTNESS]=0.9;
- params[PARAM_LIMIT_RELAXATION]=1.0;
- params[PARAM_MOTOR_TARGET_VELOCITY]=1;
- params[PARAM_MOTOR_MAX_IMPULSE]=1;
-
-
- flags[FLAG_USE_LIMIT]=false;
- flags[FLAG_ENABLE_MOTOR]=false;
+ params[PARAM_BIAS] = 0.3;
+ params[PARAM_LIMIT_UPPER] = Math_PI * 0.5;
+ params[PARAM_LIMIT_LOWER] = -Math_PI * 0.5;
+ params[PARAM_LIMIT_BIAS] = 0.3;
+ params[PARAM_LIMIT_SOFTNESS] = 0.9;
+ params[PARAM_LIMIT_RELAXATION] = 1.0;
+ params[PARAM_MOTOR_TARGET_VELOCITY] = 1;
+ params[PARAM_MOTOR_MAX_IMPULSE] = 1;
+ flags[FLAG_USE_LIMIT] = false;
+ flags[FLAG_ENABLE_MOTOR] = false;
}
-
-
-
/////////////////////////////////////////////////
-
//////////////////////////////////
-
-
void SliderJoint::_set_upper_limit_angular(float p_limit_angular) {
- set_param(PARAM_ANGULAR_LIMIT_UPPER,Math::deg2rad(p_limit_angular));
+ set_param(PARAM_ANGULAR_LIMIT_UPPER, Math::deg2rad(p_limit_angular));
}
float SliderJoint::_get_upper_limit_angular() const {
@@ -434,100 +384,91 @@ float SliderJoint::_get_upper_limit_angular() const {
void SliderJoint::_set_lower_limit_angular(float p_limit_angular) {
- set_param(PARAM_ANGULAR_LIMIT_LOWER,Math::deg2rad(p_limit_angular));
-
+ set_param(PARAM_ANGULAR_LIMIT_LOWER, Math::deg2rad(p_limit_angular));
}
float SliderJoint::_get_lower_limit_angular() const {
return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_LOWER));
-
}
-
void SliderJoint::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_param","param","value"),&SliderJoint::set_param);
- ClassDB::bind_method(D_METHOD("get_param","param"),&SliderJoint::get_param);
-
-
- ClassDB::bind_method(D_METHOD("_set_upper_limit_angular","upper_limit_angular"),&SliderJoint::_set_upper_limit_angular);
- ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"),&SliderJoint::_get_upper_limit_angular);
-
- ClassDB::bind_method(D_METHOD("_set_lower_limit_angular","lower_limit_angular"),&SliderJoint::_set_lower_limit_angular);
- ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"),&SliderJoint::_get_lower_limit_angular);
-
-
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_limit/upper_distance",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),"set_param","get_param", PARAM_LINEAR_LIMIT_UPPER);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_limit/lower_distance",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),"set_param","get_param", PARAM_LINEAR_LIMIT_LOWER);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_limit/softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_limit/restitution",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_LIMIT_RESTITUTION);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_limit/damping",PROPERTY_HINT_RANGE,"0,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_LIMIT_DAMPING);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_motion/softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_MOTION_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_motion/restitution",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_MOTION_RESTITUTION);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_motion/damping",PROPERTY_HINT_RANGE,"0,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_MOTION_DAMPING);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_ortho/softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_ortho/restitution",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"linear_ortho/damping",PROPERTY_HINT_RANGE,"0,16.0,0.01") ,"set_param","get_param", PARAM_LINEAR_ORTHOGONAL_DAMPING);
-
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_limit/upper_angle",PROPERTY_HINT_RANGE,"-180,180,0.1"),"_set_upper_limit_angular","_get_upper_limit_angular") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_limit/lower_angle",PROPERTY_HINT_RANGE,"-180,180,0.1"),"_set_lower_limit_angular","_get_lower_limit_angular") ;
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_limit/softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_limit/restitution",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_LIMIT_RESTITUTION);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_limit/damping",PROPERTY_HINT_RANGE,"0,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_LIMIT_DAMPING);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_motion/softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_MOTION_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_motion/restitution",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_MOTION_RESTITUTION);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_motion/damping",PROPERTY_HINT_RANGE,"0,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_MOTION_DAMPING);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_ortho/softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_ortho/restitution",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"angular_ortho/damping",PROPERTY_HINT_RANGE,"0,16.0,0.01") ,"set_param","get_param", PARAM_ANGULAR_ORTHOGONAL_DAMPING);
-
-
- BIND_CONSTANT( PARAM_LINEAR_LIMIT_UPPER);
- BIND_CONSTANT( PARAM_LINEAR_LIMIT_LOWER);
- BIND_CONSTANT( PARAM_LINEAR_LIMIT_SOFTNESS);
- BIND_CONSTANT( PARAM_LINEAR_LIMIT_RESTITUTION);
- BIND_CONSTANT( PARAM_LINEAR_LIMIT_DAMPING);
- BIND_CONSTANT( PARAM_LINEAR_MOTION_SOFTNESS);
- BIND_CONSTANT( PARAM_LINEAR_MOTION_RESTITUTION);
- BIND_CONSTANT( PARAM_LINEAR_MOTION_DAMPING);
- BIND_CONSTANT( PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
- BIND_CONSTANT( PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
- BIND_CONSTANT( PARAM_LINEAR_ORTHOGONAL_DAMPING);
-
- BIND_CONSTANT( PARAM_ANGULAR_LIMIT_UPPER);
- BIND_CONSTANT( PARAM_ANGULAR_LIMIT_LOWER);
- BIND_CONSTANT( PARAM_ANGULAR_LIMIT_SOFTNESS);
- BIND_CONSTANT( PARAM_ANGULAR_LIMIT_RESTITUTION);
- BIND_CONSTANT( PARAM_ANGULAR_LIMIT_DAMPING);
- BIND_CONSTANT( PARAM_ANGULAR_MOTION_SOFTNESS);
- BIND_CONSTANT( PARAM_ANGULAR_MOTION_RESTITUTION);
- BIND_CONSTANT( PARAM_ANGULAR_MOTION_DAMPING);
- BIND_CONSTANT( PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
- BIND_CONSTANT( PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
- BIND_CONSTANT( PARAM_ANGULAR_ORTHOGONAL_DAMPING);
-
- BIND_CONSTANT( PARAM_MAX);
-}
-
-void SliderJoint::set_param(Param p_param,float p_value){
-
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- params[p_param]=p_value;
+ ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint::set_param);
+ ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint::get_param);
+
+ ClassDB::bind_method(D_METHOD("_set_upper_limit_angular", "upper_limit_angular"), &SliderJoint::_set_upper_limit_angular);
+ ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"), &SliderJoint::_get_upper_limit_angular);
+
+ ClassDB::bind_method(D_METHOD("_set_lower_limit_angular", "lower_limit_angular"), &SliderJoint::_set_lower_limit_angular);
+ ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"), &SliderJoint::_get_lower_limit_angular);
+
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/upper_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_UPPER);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/lower_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_LOWER);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motion/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motion/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motion/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_MOTION_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_ortho/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_ortho/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_ortho/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_LINEAR_ORTHOGONAL_DAMPING);
+
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_upper_limit_angular", "_get_upper_limit_angular");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_lower_limit_angular", "_get_lower_limit_angular");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_LIMIT_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motion/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motion/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motion/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_MOTION_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_ortho/softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_ortho/restitution", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_ortho/damping", PROPERTY_HINT_RANGE, "0,16.0,0.01"), "set_param", "get_param", PARAM_ANGULAR_ORTHOGONAL_DAMPING);
+
+ BIND_CONSTANT(PARAM_LINEAR_LIMIT_UPPER);
+ BIND_CONSTANT(PARAM_LINEAR_LIMIT_LOWER);
+ BIND_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
+ BIND_CONSTANT(PARAM_LINEAR_LIMIT_RESTITUTION);
+ BIND_CONSTANT(PARAM_LINEAR_LIMIT_DAMPING);
+ BIND_CONSTANT(PARAM_LINEAR_MOTION_SOFTNESS);
+ BIND_CONSTANT(PARAM_LINEAR_MOTION_RESTITUTION);
+ BIND_CONSTANT(PARAM_LINEAR_MOTION_DAMPING);
+ BIND_CONSTANT(PARAM_LINEAR_ORTHOGONAL_SOFTNESS);
+ BIND_CONSTANT(PARAM_LINEAR_ORTHOGONAL_RESTITUTION);
+ BIND_CONSTANT(PARAM_LINEAR_ORTHOGONAL_DAMPING);
+
+ BIND_CONSTANT(PARAM_ANGULAR_LIMIT_UPPER);
+ BIND_CONSTANT(PARAM_ANGULAR_LIMIT_LOWER);
+ BIND_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS);
+ BIND_CONSTANT(PARAM_ANGULAR_LIMIT_RESTITUTION);
+ BIND_CONSTANT(PARAM_ANGULAR_LIMIT_DAMPING);
+ BIND_CONSTANT(PARAM_ANGULAR_MOTION_SOFTNESS);
+ BIND_CONSTANT(PARAM_ANGULAR_MOTION_RESTITUTION);
+ BIND_CONSTANT(PARAM_ANGULAR_MOTION_DAMPING);
+ BIND_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_SOFTNESS);
+ BIND_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_RESTITUTION);
+ BIND_CONSTANT(PARAM_ANGULAR_ORTHOGONAL_DAMPING);
+
+ BIND_CONSTANT(PARAM_MAX);
+}
+
+void SliderJoint::set_param(Param p_param, float p_value) {
+
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ params[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->slider_joint_set_param(get_joint(),PhysicsServer::SliderJointParam(p_param),p_value);
+ PhysicsServer::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer::SliderJointParam(p_param), p_value);
update_gizmo();
-
}
-float SliderJoint::get_param(Param p_param) const{
+float SliderJoint::get_param(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return params[p_param];
}
-
-RID SliderJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
-
+RID SliderJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
Transform gt = get_global_transform();
Transform ainv = body_a->get_global_transform().affine_inverse();
@@ -543,53 +484,46 @@ RID SliderJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
local_b.orthonormalize();
- RID j = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(),local_a,body_b?body_b->get_rid():RID(),local_b);
- for(int i=0;i<PARAM_MAX;i++) {
- PhysicsServer::get_singleton()->slider_joint_set_param(j,PhysicsServer::SliderJointParam(i),params[i]);
+ RID j = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
+ for (int i = 0; i < PARAM_MAX; i++) {
+ PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SliderJointParam(i), params[i]);
}
return j;
}
-
SliderJoint::SliderJoint() {
-
-
- params[ PARAM_LINEAR_LIMIT_UPPER ]=1.0;
- params[ PARAM_LINEAR_LIMIT_LOWER ]=-1.0;
- params[ PARAM_LINEAR_LIMIT_SOFTNESS ]=1.0;
- params[ PARAM_LINEAR_LIMIT_RESTITUTION]=0.7;
- params[ PARAM_LINEAR_LIMIT_DAMPING]=1.0;
- params[ PARAM_LINEAR_MOTION_SOFTNESS ]=1.0;
- params[ PARAM_LINEAR_MOTION_RESTITUTION]=0.7;
- params[ PARAM_LINEAR_MOTION_DAMPING]=0;//1.0;
- params[ PARAM_LINEAR_ORTHOGONAL_SOFTNESS ]=1.0;
- params[ PARAM_LINEAR_ORTHOGONAL_RESTITUTION]=0.7;
- params[ PARAM_LINEAR_ORTHOGONAL_DAMPING]=1.0;
-
- params[ PARAM_ANGULAR_LIMIT_UPPER ]=0 ;
- params[ PARAM_ANGULAR_LIMIT_LOWER ]=0 ;
- params[ PARAM_ANGULAR_LIMIT_SOFTNESS ]=1.0;
- params[ PARAM_ANGULAR_LIMIT_RESTITUTION]=0.7;
- params[ PARAM_ANGULAR_LIMIT_DAMPING]=0;//1.0;
- params[ PARAM_ANGULAR_MOTION_SOFTNESS ]=1.0;
- params[ PARAM_ANGULAR_MOTION_RESTITUTION]=0.7;
- params[ PARAM_ANGULAR_MOTION_DAMPING]=1.0;
- params[ PARAM_ANGULAR_ORTHOGONAL_SOFTNESS ]=1.0;
- params[ PARAM_ANGULAR_ORTHOGONAL_RESTITUTION]=0.7;
- params[ PARAM_ANGULAR_ORTHOGONAL_DAMPING]=1.0;
+ params[PARAM_LINEAR_LIMIT_UPPER] = 1.0;
+ params[PARAM_LINEAR_LIMIT_LOWER] = -1.0;
+ params[PARAM_LINEAR_LIMIT_SOFTNESS] = 1.0;
+ params[PARAM_LINEAR_LIMIT_RESTITUTION] = 0.7;
+ params[PARAM_LINEAR_LIMIT_DAMPING] = 1.0;
+ params[PARAM_LINEAR_MOTION_SOFTNESS] = 1.0;
+ params[PARAM_LINEAR_MOTION_RESTITUTION] = 0.7;
+ params[PARAM_LINEAR_MOTION_DAMPING] = 0; //1.0;
+ params[PARAM_LINEAR_ORTHOGONAL_SOFTNESS] = 1.0;
+ params[PARAM_LINEAR_ORTHOGONAL_RESTITUTION] = 0.7;
+ params[PARAM_LINEAR_ORTHOGONAL_DAMPING] = 1.0;
+
+ params[PARAM_ANGULAR_LIMIT_UPPER] = 0;
+ params[PARAM_ANGULAR_LIMIT_LOWER] = 0;
+ params[PARAM_ANGULAR_LIMIT_SOFTNESS] = 1.0;
+ params[PARAM_ANGULAR_LIMIT_RESTITUTION] = 0.7;
+ params[PARAM_ANGULAR_LIMIT_DAMPING] = 0; //1.0;
+ params[PARAM_ANGULAR_MOTION_SOFTNESS] = 1.0;
+ params[PARAM_ANGULAR_MOTION_RESTITUTION] = 0.7;
+ params[PARAM_ANGULAR_MOTION_DAMPING] = 1.0;
+ params[PARAM_ANGULAR_ORTHOGONAL_SOFTNESS] = 1.0;
+ params[PARAM_ANGULAR_ORTHOGONAL_RESTITUTION] = 0.7;
+ params[PARAM_ANGULAR_ORTHOGONAL_DAMPING] = 1.0;
}
-
-
//////////////////////////////////
-
-
void ConeTwistJoint::_set_swing_span(float p_limit_angular) {
- set_param(PARAM_SWING_SPAN,Math::deg2rad(p_limit_angular));
+ set_param(PARAM_SWING_SPAN, Math::deg2rad(p_limit_angular));
}
float ConeTwistJoint::_get_swing_span() const {
@@ -599,64 +533,56 @@ float ConeTwistJoint::_get_swing_span() const {
void ConeTwistJoint::_set_twist_span(float p_limit_angular) {
- set_param(PARAM_TWIST_SPAN,Math::deg2rad(p_limit_angular));
-
+ set_param(PARAM_TWIST_SPAN, Math::deg2rad(p_limit_angular));
}
float ConeTwistJoint::_get_twist_span() const {
return Math::rad2deg(get_param(PARAM_TWIST_SPAN));
-
}
-
void ConeTwistJoint::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_param","param","value"),&ConeTwistJoint::set_param);
- ClassDB::bind_method(D_METHOD("get_param","param"),&ConeTwistJoint::get_param);
-
+ ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint::set_param);
+ ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint::get_param);
- ClassDB::bind_method(D_METHOD("_set_swing_span","swing_span"),&ConeTwistJoint::_set_swing_span);
- ClassDB::bind_method(D_METHOD("_get_swing_span"),&ConeTwistJoint::_get_swing_span);
+ ClassDB::bind_method(D_METHOD("_set_swing_span", "swing_span"), &ConeTwistJoint::_set_swing_span);
+ ClassDB::bind_method(D_METHOD("_get_swing_span"), &ConeTwistJoint::_get_swing_span);
- ClassDB::bind_method(D_METHOD("_set_twist_span","twist_span"),&ConeTwistJoint::_set_twist_span);
- ClassDB::bind_method(D_METHOD("_get_twist_span"),&ConeTwistJoint::_get_twist_span);
+ ClassDB::bind_method(D_METHOD("_set_twist_span", "twist_span"), &ConeTwistJoint::_set_twist_span);
+ ClassDB::bind_method(D_METHOD("_get_twist_span"), &ConeTwistJoint::_get_twist_span);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "swing_span", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_swing_span", "_get_swing_span");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "twist_span", PROPERTY_HINT_RANGE, "-40000,40000,0.1"), "_set_twist_span", "_get_twist_span");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"swing_span",PROPERTY_HINT_RANGE,"-180,180,0.1"),"_set_swing_span","_get_swing_span") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"twist_span",PROPERTY_HINT_RANGE,"-40000,40000,0.1"),"_set_twist_span","_get_twist_span") ;
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_BIAS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "relaxation", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_RELAXATION);
-
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"bias",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_BIAS );
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"softness",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_SOFTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"relaxation",PROPERTY_HINT_RANGE,"0.01,16.0,0.01") ,"set_param","get_param", PARAM_RELAXATION);
-
- BIND_CONSTANT( PARAM_SWING_SPAN );
- BIND_CONSTANT( PARAM_TWIST_SPAN );
- BIND_CONSTANT( PARAM_BIAS );
- BIND_CONSTANT( PARAM_SOFTNESS );
- BIND_CONSTANT( PARAM_RELAXATION );
- BIND_CONSTANT( PARAM_MAX );
+ BIND_CONSTANT(PARAM_SWING_SPAN);
+ BIND_CONSTANT(PARAM_TWIST_SPAN);
+ BIND_CONSTANT(PARAM_BIAS);
+ BIND_CONSTANT(PARAM_SOFTNESS);
+ BIND_CONSTANT(PARAM_RELAXATION);
+ BIND_CONSTANT(PARAM_MAX);
}
-void ConeTwistJoint::set_param(Param p_param,float p_value){
+void ConeTwistJoint::set_param(Param p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- params[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ params[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->cone_twist_joint_set_param(get_joint(),PhysicsServer::ConeTwistJointParam(p_param),p_value);
+ PhysicsServer::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer::ConeTwistJointParam(p_param), p_value);
update_gizmo();
}
-float ConeTwistJoint::get_param(Param p_param) const{
+float ConeTwistJoint::get_param(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return params[p_param];
}
-
-RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
-
+RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
Transform gt = get_global_transform();
//Vector3 cone_twistpos = gt.origin;
@@ -675,311 +601,285 @@ RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
local_b.orthonormalize();
- RID j = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(),local_a,body_b?body_b->get_rid():RID(),local_b);
- for(int i=0;i<PARAM_MAX;i++) {
- PhysicsServer::get_singleton()->cone_twist_joint_set_param(j,PhysicsServer::ConeTwistJointParam(i),params[i]);
+ RID j = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
+ for (int i = 0; i < PARAM_MAX; i++) {
+ PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::ConeTwistJointParam(i), params[i]);
}
return j;
}
-
ConeTwistJoint::ConeTwistJoint() {
-
- params[ PARAM_SWING_SPAN ]=Math_PI*0.25;
- params[ PARAM_TWIST_SPAN ]=Math_PI;
- params[ PARAM_BIAS ]=0.3;
- params[ PARAM_SOFTNESS ]=0.8;
- params[ PARAM_RELAXATION ]=1.0;
-
+ params[PARAM_SWING_SPAN] = Math_PI * 0.25;
+ params[PARAM_TWIST_SPAN] = Math_PI;
+ params[PARAM_BIAS] = 0.3;
+ params[PARAM_SOFTNESS] = 0.8;
+ params[PARAM_RELAXATION] = 1.0;
}
/////////////////////////////////////////////////////////////////////
-
void Generic6DOFJoint::_set_angular_hi_limit_x(float p_limit_angular) {
- set_param_x(PARAM_ANGULAR_UPPER_LIMIT,Math::deg2rad(p_limit_angular));
+ set_param_x(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular));
}
-float Generic6DOFJoint::_get_angular_hi_limit_x() const{
+float Generic6DOFJoint::_get_angular_hi_limit_x() const {
return Math::rad2deg(get_param_x(PARAM_ANGULAR_UPPER_LIMIT));
-
}
void Generic6DOFJoint::_set_angular_lo_limit_x(float p_limit_angular) {
- set_param_x(PARAM_ANGULAR_LOWER_LIMIT,Math::deg2rad(p_limit_angular));
+ set_param_x(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular));
}
-float Generic6DOFJoint::_get_angular_lo_limit_x() const{
+float Generic6DOFJoint::_get_angular_lo_limit_x() const {
return Math::rad2deg(get_param_x(PARAM_ANGULAR_LOWER_LIMIT));
-
}
-
void Generic6DOFJoint::_set_angular_hi_limit_y(float p_limit_angular) {
- set_param_y(PARAM_ANGULAR_UPPER_LIMIT,Math::deg2rad(p_limit_angular));
+ set_param_y(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular));
}
-float Generic6DOFJoint::_get_angular_hi_limit_y() const{
+float Generic6DOFJoint::_get_angular_hi_limit_y() const {
return Math::rad2deg(get_param_y(PARAM_ANGULAR_UPPER_LIMIT));
-
}
void Generic6DOFJoint::_set_angular_lo_limit_y(float p_limit_angular) {
- set_param_y(PARAM_ANGULAR_LOWER_LIMIT,Math::deg2rad(p_limit_angular));
+ set_param_y(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular));
}
-float Generic6DOFJoint::_get_angular_lo_limit_y() const{
+float Generic6DOFJoint::_get_angular_lo_limit_y() const {
return Math::rad2deg(get_param_y(PARAM_ANGULAR_LOWER_LIMIT));
-
}
-
void Generic6DOFJoint::_set_angular_hi_limit_z(float p_limit_angular) {
- set_param_z(PARAM_ANGULAR_UPPER_LIMIT,Math::deg2rad(p_limit_angular));
+ set_param_z(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular));
}
-float Generic6DOFJoint::_get_angular_hi_limit_z() const{
+float Generic6DOFJoint::_get_angular_hi_limit_z() const {
return Math::rad2deg(get_param_z(PARAM_ANGULAR_UPPER_LIMIT));
-
}
void Generic6DOFJoint::_set_angular_lo_limit_z(float p_limit_angular) {
- set_param_z(PARAM_ANGULAR_LOWER_LIMIT,Math::deg2rad(p_limit_angular));
+ set_param_z(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular));
}
-float Generic6DOFJoint::_get_angular_lo_limit_z() const{
+float Generic6DOFJoint::_get_angular_lo_limit_z() const {
return Math::rad2deg(get_param_z(PARAM_ANGULAR_LOWER_LIMIT));
-
}
-
-
-void Generic6DOFJoint::_bind_methods(){
-
-
- ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x","angle"),&Generic6DOFJoint::_set_angular_hi_limit_x);
- ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"),&Generic6DOFJoint::_get_angular_hi_limit_x);
-
- ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x","angle"),&Generic6DOFJoint::_set_angular_lo_limit_x);
- ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"),&Generic6DOFJoint::_get_angular_lo_limit_x);
-
- ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y","angle"),&Generic6DOFJoint::_set_angular_hi_limit_y);
- ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"),&Generic6DOFJoint::_get_angular_hi_limit_y);
-
- ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y","angle"),&Generic6DOFJoint::_set_angular_lo_limit_y);
- ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"),&Generic6DOFJoint::_get_angular_lo_limit_y);
-
- ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z","angle"),&Generic6DOFJoint::_set_angular_hi_limit_z);
- ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"),&Generic6DOFJoint::_get_angular_hi_limit_z);
-
- ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z","angle"),&Generic6DOFJoint::_set_angular_lo_limit_z);
- ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"),&Generic6DOFJoint::_get_angular_lo_limit_z);
-
- ClassDB::bind_method(D_METHOD("set_param_x","param","value"),&Generic6DOFJoint::set_param_x);
- ClassDB::bind_method(D_METHOD("get_param_x","param"),&Generic6DOFJoint::get_param_x);
-
- ClassDB::bind_method(D_METHOD("set_param_y","param","value"),&Generic6DOFJoint::set_param_y);
- ClassDB::bind_method(D_METHOD("get_param_y","param"),&Generic6DOFJoint::get_param_y);
-
- ClassDB::bind_method(D_METHOD("set_param_z","param","value"),&Generic6DOFJoint::set_param_z);
- ClassDB::bind_method(D_METHOD("get_param_z","param"),&Generic6DOFJoint::get_param_z);
-
- ClassDB::bind_method(D_METHOD("set_flag_x","flag","value"),&Generic6DOFJoint::set_flag_x);
- ClassDB::bind_method(D_METHOD("get_flag_x","flag"),&Generic6DOFJoint::get_flag_x);
-
- ClassDB::bind_method(D_METHOD("set_flag_y","flag","value"),&Generic6DOFJoint::set_flag_y);
- ClassDB::bind_method(D_METHOD("get_flag_y","flag"),&Generic6DOFJoint::get_flag_y);
-
- ClassDB::bind_method(D_METHOD("set_flag_z","flag","value"),&Generic6DOFJoint::set_flag_z);
- ClassDB::bind_method(D_METHOD("get_flag_z","flag"),&Generic6DOFJoint::get_flag_z);
-
-
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"linear_limit_x/enabled"),"set_flag_x","get_flag_x",FLAG_ENABLE_LINEAR_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_x/upper_distance"),"set_param_x","get_param_x",PARAM_LINEAR_UPPER_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_x/lower_distance"),"set_param_x","get_param_x",PARAM_LINEAR_LOWER_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_x/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_x","get_param_x",PARAM_LINEAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_x/restitution",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_x","get_param_x",PARAM_LINEAR_RESTITUTION);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_x/damping",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_x","get_param_x",PARAM_LINEAR_DAMPING);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"angular_limit_x/enabled"),"set_flag_x","get_flag_x",FLAG_ENABLE_ANGULAR_LIMIT);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"angular_limit_x/upper_angle",PROPERTY_HINT_RANGE,"-180,180,0.01"),"_set_angular_hi_limit_x","_get_angular_hi_limit_x");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"angular_limit_x/lower_angle",PROPERTY_HINT_RANGE,"-180,180,0.01"),"_set_angular_lo_limit_x","_get_angular_lo_limit_x");
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_x/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_x","get_param_x",PARAM_ANGULAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_x/restitution",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_x","get_param_x",PARAM_ANGULAR_RESTITUTION);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_x/damping",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_x","get_param_x",PARAM_ANGULAR_DAMPING);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_x/force_limit"),"set_param_x","get_param_x",PARAM_ANGULAR_FORCE_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_x/erp"),"set_param_x","get_param_x",PARAM_ANGULAR_ERP);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"angular_motor_x/enabled"),"set_flag_x","get_flag_x",FLAG_ENABLE_MOTOR);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_motor_x/target_velocity"),"set_param_x","get_param_x",PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_motor_x/force_limit"),"set_param_x","get_param_x",PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
-
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"linear_limit_y/enabled"),"set_flag_y","get_flag_y",FLAG_ENABLE_LINEAR_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_y/upper_distance"),"set_param_y","get_param_y",PARAM_LINEAR_UPPER_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_y/lower_distance"),"set_param_y","get_param_y",PARAM_LINEAR_LOWER_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_y/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_y","get_param_y",PARAM_LINEAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_y/restitution",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_y","get_param_y",PARAM_LINEAR_RESTITUTION);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_y/damping",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_y","get_param_y",PARAM_LINEAR_DAMPING);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"angular_limit_y/enabled"),"set_flag_y","get_flag_y",FLAG_ENABLE_ANGULAR_LIMIT);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"angular_limit_y/upper_angle",PROPERTY_HINT_RANGE,"-180,180,0.01"),"_set_angular_hi_limit_y","_get_angular_hi_limit_y");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"angular_limit_y/lower_angle",PROPERTY_HINT_RANGE,"-180,180,0.01"),"_set_angular_lo_limit_y","_get_angular_lo_limit_y");
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_y/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_y","get_param_y",PARAM_ANGULAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_y/restitution",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_y","get_param_y",PARAM_ANGULAR_RESTITUTION);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_y/damping",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_y","get_param_y",PARAM_ANGULAR_DAMPING);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_y/force_limit"),"set_param_y","get_param_y",PARAM_ANGULAR_FORCE_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_y/erp"),"set_param_y","get_param_y",PARAM_ANGULAR_ERP);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"angular_motor_y/enabled"),"set_flag_y","get_flag_y",FLAG_ENABLE_MOTOR);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_motor_y/target_velocity"),"set_param_y","get_param_y",PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_motor_y/force_limit"),"set_param_y","get_param_y",PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
-
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"linear_limit_z/enabled"),"set_flag_z","get_flag_z",FLAG_ENABLE_LINEAR_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_z/upper_distance"),"set_param_z","get_param_z",PARAM_LINEAR_UPPER_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_z/lower_distance"),"set_param_z","get_param_z",PARAM_LINEAR_LOWER_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_z/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_z","get_param_z",PARAM_LINEAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_z/restitution",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_z","get_param_z",PARAM_LINEAR_RESTITUTION);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"linear_limit_z/damping",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_z","get_param_z",PARAM_LINEAR_DAMPING);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"angular_limit_z/enabled"),"set_flag_z","get_flag_z",FLAG_ENABLE_ANGULAR_LIMIT);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"angular_limit_z/upper_angle",PROPERTY_HINT_RANGE,"-180,180,0.01"),"_set_angular_hi_limit_z","_get_angular_hi_limit_z");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"angular_limit_z/lower_angle",PROPERTY_HINT_RANGE,"-180,180,0.01"),"_set_angular_lo_limit_z","_get_angular_lo_limit_z");
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_z/softness",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_z","get_param_z",PARAM_ANGULAR_LIMIT_SOFTNESS);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_z/restitution",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_z","get_param_z",PARAM_ANGULAR_RESTITUTION);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_z/damping",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_param_z","get_param_z",PARAM_ANGULAR_DAMPING);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_z/force_limit"),"set_param_z","get_param_z",PARAM_ANGULAR_FORCE_LIMIT);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_limit_z/erp"),"set_param_z","get_param_z",PARAM_ANGULAR_ERP);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"angular_motor_z/enabled"),"set_flag_z","get_flag_z",FLAG_ENABLE_MOTOR);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_motor_z/target_velocity"),"set_param_z","get_param_z",PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"angular_motor_z/force_limit"),"set_param_z","get_param_z",PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
-
-
- BIND_CONSTANT( PARAM_LINEAR_LOWER_LIMIT);
- BIND_CONSTANT( PARAM_LINEAR_UPPER_LIMIT);
- BIND_CONSTANT( PARAM_LINEAR_LIMIT_SOFTNESS);
- BIND_CONSTANT( PARAM_LINEAR_RESTITUTION);
- BIND_CONSTANT( PARAM_LINEAR_DAMPING);
- BIND_CONSTANT( PARAM_ANGULAR_LOWER_LIMIT);
- BIND_CONSTANT( PARAM_ANGULAR_UPPER_LIMIT);
- BIND_CONSTANT( PARAM_ANGULAR_LIMIT_SOFTNESS);
- BIND_CONSTANT( PARAM_ANGULAR_DAMPING);
- BIND_CONSTANT( PARAM_ANGULAR_RESTITUTION);
- BIND_CONSTANT( PARAM_ANGULAR_FORCE_LIMIT);
- BIND_CONSTANT( PARAM_ANGULAR_ERP);
- BIND_CONSTANT( PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
- BIND_CONSTANT( PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
- BIND_CONSTANT( PARAM_MAX);
-
- BIND_CONSTANT( FLAG_ENABLE_LINEAR_LIMIT);
- BIND_CONSTANT( FLAG_ENABLE_ANGULAR_LIMIT);
- BIND_CONSTANT( FLAG_ENABLE_MOTOR);
- BIND_CONSTANT( FLAG_MAX );
-}
-
-
-void Generic6DOFJoint::set_param_x(Param p_param,float p_value){
-
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- params_x[p_param]=p_value;
+void Generic6DOFJoint::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_x);
+ ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"), &Generic6DOFJoint::_get_angular_hi_limit_x);
+
+ ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_x);
+ ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"), &Generic6DOFJoint::_get_angular_lo_limit_x);
+
+ ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_y);
+ ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"), &Generic6DOFJoint::_get_angular_hi_limit_y);
+
+ ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_y);
+ ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"), &Generic6DOFJoint::_get_angular_lo_limit_y);
+
+ ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_z);
+ ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"), &Generic6DOFJoint::_get_angular_hi_limit_z);
+
+ ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_z);
+ ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"), &Generic6DOFJoint::_get_angular_lo_limit_z);
+
+ ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint::set_param_x);
+ ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint::get_param_x);
+
+ ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint::set_param_y);
+ ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint::get_param_y);
+
+ ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint::set_param_z);
+ ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint::get_param_z);
+
+ ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint::set_flag_x);
+ ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint::get_flag_x);
+
+ ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint::set_flag_y);
+ ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint::get_flag_y);
+
+ ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint::set_flag_z);
+ ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint::get_flag_z);
+
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/upper_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/lower_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_LOWER_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_ANGULAR_LIMIT);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_x/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_x", "_get_angular_hi_limit_x");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_x/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_x", "_get_angular_lo_limit_x");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_ANGULAR_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/force_limit"), "set_param_x", "get_param_x", PARAM_ANGULAR_FORCE_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_x/erp"), "set_param_x", "get_param_x", PARAM_ANGULAR_ERP);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_MOTOR);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_x/target_velocity"), "set_param_x", "get_param_x", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_x/force_limit"), "set_param_x", "get_param_x", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
+
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/upper_distance"), "set_param_y", "get_param_y", PARAM_LINEAR_UPPER_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/lower_distance"), "set_param_y", "get_param_y", PARAM_LINEAR_LOWER_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_ANGULAR_LIMIT);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_y/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_y", "_get_angular_hi_limit_y");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_y/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_y", "_get_angular_lo_limit_y");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_ANGULAR_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/force_limit"), "set_param_y", "get_param_y", PARAM_ANGULAR_FORCE_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_y/erp"), "set_param_y", "get_param_y", PARAM_ANGULAR_ERP);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_MOTOR);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_y/target_velocity"), "set_param_y", "get_param_y", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_y/force_limit"), "set_param_y", "get_param_y", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
+
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/upper_distance"), "set_param_z", "get_param_z", PARAM_LINEAR_UPPER_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/lower_distance"), "set_param_z", "get_param_z", PARAM_LINEAR_LOWER_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_ANGULAR_LIMIT);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_z/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_z", "_get_angular_hi_limit_z");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_z/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_z", "_get_angular_lo_limit_z");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_LIMIT_SOFTNESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_RESTITUTION);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_ANGULAR_DAMPING);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/force_limit"), "set_param_z", "get_param_z", PARAM_ANGULAR_FORCE_LIMIT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_limit_z/erp"), "set_param_z", "get_param_z", PARAM_ANGULAR_ERP);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_motor_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_MOTOR);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_z/target_velocity"), "set_param_z", "get_param_z", PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_motor_z/force_limit"), "set_param_z", "get_param_z", PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
+
+ BIND_CONSTANT(PARAM_LINEAR_LOWER_LIMIT);
+ BIND_CONSTANT(PARAM_LINEAR_UPPER_LIMIT);
+ BIND_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
+ BIND_CONSTANT(PARAM_LINEAR_RESTITUTION);
+ BIND_CONSTANT(PARAM_LINEAR_DAMPING);
+ BIND_CONSTANT(PARAM_ANGULAR_LOWER_LIMIT);
+ BIND_CONSTANT(PARAM_ANGULAR_UPPER_LIMIT);
+ BIND_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS);
+ BIND_CONSTANT(PARAM_ANGULAR_DAMPING);
+ BIND_CONSTANT(PARAM_ANGULAR_RESTITUTION);
+ BIND_CONSTANT(PARAM_ANGULAR_FORCE_LIMIT);
+ BIND_CONSTANT(PARAM_ANGULAR_ERP);
+ BIND_CONSTANT(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY);
+ BIND_CONSTANT(PARAM_ANGULAR_MOTOR_FORCE_LIMIT);
+ BIND_CONSTANT(PARAM_MAX);
+
+ BIND_CONSTANT(FLAG_ENABLE_LINEAR_LIMIT);
+ BIND_CONSTANT(FLAG_ENABLE_ANGULAR_LIMIT);
+ BIND_CONSTANT(FLAG_ENABLE_MOTOR);
+ BIND_CONSTANT(FLAG_MAX);
+}
+
+void Generic6DOFJoint::set_param_x(Param p_param, float p_value) {
+
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ params_x[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(),Vector3::AXIS_X,PhysicsServer::G6DOFJointAxisParam(p_param),p_value);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
update_gizmo();
}
-float Generic6DOFJoint::get_param_x(Param p_param) const{
+float Generic6DOFJoint::get_param_x(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return params_x[p_param];
}
-void Generic6DOFJoint::set_param_y(Param p_param,float p_value){
+void Generic6DOFJoint::set_param_y(Param p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- params_y[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ params_y[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(),Vector3::AXIS_Y,PhysicsServer::G6DOFJointAxisParam(p_param),p_value);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
update_gizmo();
-
}
-float Generic6DOFJoint::get_param_y(Param p_param) const{
+float Generic6DOFJoint::get_param_y(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return params_y[p_param];
}
+void Generic6DOFJoint::set_param_z(Param p_param, float p_value) {
-void Generic6DOFJoint::set_param_z(Param p_param,float p_value){
-
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- params_z[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ params_z[p_param] = p_value;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(),Vector3::AXIS_Z,PhysicsServer::G6DOFJointAxisParam(p_param),p_value);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
update_gizmo();
}
-float Generic6DOFJoint::get_param_z(Param p_param) const{
+float Generic6DOFJoint::get_param_z(Param p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return params_z[p_param];
}
+void Generic6DOFJoint::set_flag_x(Flag p_flag, bool p_enabled) {
-void Generic6DOFJoint::set_flag_x(Flag p_flag,bool p_enabled){
-
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- flags_x[p_flag]=p_enabled;
+ ERR_FAIL_INDEX(p_flag, FLAG_MAX);
+ flags_x[p_flag] = p_enabled;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(),Vector3::AXIS_X,PhysicsServer::G6DOFJointAxisFlag(p_flag),p_enabled);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
update_gizmo();
-
}
-bool Generic6DOFJoint::get_flag_x(Flag p_flag) const{
+bool Generic6DOFJoint::get_flag_x(Flag p_flag) const {
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
+ ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
return flags_x[p_flag];
-
}
-void Generic6DOFJoint::set_flag_y(Flag p_flag,bool p_enabled){
+void Generic6DOFJoint::set_flag_y(Flag p_flag, bool p_enabled) {
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- flags_y[p_flag]=p_enabled;
+ ERR_FAIL_INDEX(p_flag, FLAG_MAX);
+ flags_y[p_flag] = p_enabled;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(),Vector3::AXIS_Y,PhysicsServer::G6DOFJointAxisFlag(p_flag),p_enabled);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
update_gizmo();
}
-bool Generic6DOFJoint::get_flag_y(Flag p_flag) const{
+bool Generic6DOFJoint::get_flag_y(Flag p_flag) const {
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
+ ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
return flags_y[p_flag];
-
}
-void Generic6DOFJoint::set_flag_z(Flag p_flag,bool p_enabled){
+void Generic6DOFJoint::set_flag_z(Flag p_flag, bool p_enabled) {
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- flags_z[p_flag]=p_enabled;
+ ERR_FAIL_INDEX(p_flag, FLAG_MAX);
+ flags_z[p_flag] = p_enabled;
if (get_joint().is_valid())
- PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(),Vector3::AXIS_Z,PhysicsServer::G6DOFJointAxisFlag(p_flag),p_enabled);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
update_gizmo();
}
-bool Generic6DOFJoint::get_flag_z(Flag p_flag) const{
+bool Generic6DOFJoint::get_flag_z(Flag p_flag) const {
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
+ ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
return flags_z[p_flag];
-
}
-RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b) {
-
+RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) {
Transform gt = get_global_transform();
//Vector3 cone_twistpos = gt.origin;
@@ -998,87 +898,81 @@ RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a,PhysicsBody *body_b)
local_b.orthonormalize();
- RID j = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(),local_a,body_b?body_b->get_rid():RID(),local_b);
- for(int i=0;i<PARAM_MAX;i++) {
- PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j,Vector3::AXIS_X,PhysicsServer::G6DOFJointAxisParam(i),params_x[i]);
- PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j,Vector3::AXIS_Y,PhysicsServer::G6DOFJointAxisParam(i),params_y[i]);
- PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j,Vector3::AXIS_Z,PhysicsServer::G6DOFJointAxisParam(i),params_z[i]);
+ RID j = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
+ for (int i = 0; i < PARAM_MAX; i++) {
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(i), params_x[i]);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(i), params_y[i]);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(i), params_z[i]);
}
- for(int i=0;i<FLAG_MAX;i++) {
- PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j,Vector3::AXIS_X,PhysicsServer::G6DOFJointAxisFlag(i),flags_x[i]);
- PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j,Vector3::AXIS_Y,PhysicsServer::G6DOFJointAxisFlag(i),flags_y[i]);
- PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j,Vector3::AXIS_Z,PhysicsServer::G6DOFJointAxisFlag(i),flags_z[i]);
+ for (int i = 0; i < FLAG_MAX; i++) {
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(i), flags_x[i]);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(i), flags_y[i]);
+ PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(i), flags_z[i]);
}
return j;
}
-
Generic6DOFJoint::Generic6DOFJoint() {
- set_param_x( PARAM_LINEAR_LOWER_LIMIT,0);
- set_param_x( PARAM_LINEAR_UPPER_LIMIT,0);
- set_param_x( PARAM_LINEAR_LIMIT_SOFTNESS,0.7);
- set_param_x( PARAM_LINEAR_RESTITUTION,0.5);
- set_param_x( PARAM_LINEAR_DAMPING,1.0);
- set_param_x( PARAM_ANGULAR_LOWER_LIMIT,0);
- set_param_x( PARAM_ANGULAR_UPPER_LIMIT,0);
- set_param_x( PARAM_ANGULAR_LIMIT_SOFTNESS,0.5f);
- set_param_x( PARAM_ANGULAR_DAMPING,1.0f);
- set_param_x( PARAM_ANGULAR_RESTITUTION,0);
- set_param_x( PARAM_ANGULAR_FORCE_LIMIT,0);
- set_param_x( PARAM_ANGULAR_ERP,0.5);
- set_param_x( PARAM_ANGULAR_MOTOR_TARGET_VELOCITY,0);
- set_param_x( PARAM_ANGULAR_MOTOR_FORCE_LIMIT,300);
-
- set_flag_x( FLAG_ENABLE_ANGULAR_LIMIT,true);
- set_flag_x( FLAG_ENABLE_LINEAR_LIMIT,true);
- set_flag_x( FLAG_ENABLE_MOTOR,false);
-
- set_param_y( PARAM_LINEAR_LOWER_LIMIT,0);
- set_param_y( PARAM_LINEAR_UPPER_LIMIT,0);
- set_param_y( PARAM_LINEAR_LIMIT_SOFTNESS,0.7);
- set_param_y( PARAM_LINEAR_RESTITUTION,0.5);
- set_param_y( PARAM_LINEAR_DAMPING,1.0);
- set_param_y( PARAM_ANGULAR_LOWER_LIMIT,0);
- set_param_y( PARAM_ANGULAR_UPPER_LIMIT,0);
- set_param_y( PARAM_ANGULAR_LIMIT_SOFTNESS,0.5f);
- set_param_y( PARAM_ANGULAR_DAMPING,1.0f);
- set_param_y( PARAM_ANGULAR_RESTITUTION,0);
- set_param_y( PARAM_ANGULAR_FORCE_LIMIT,0);
- set_param_y( PARAM_ANGULAR_ERP,0.5);
- set_param_y( PARAM_ANGULAR_MOTOR_TARGET_VELOCITY,0);
- set_param_y( PARAM_ANGULAR_MOTOR_FORCE_LIMIT,300);
-
- set_flag_y( FLAG_ENABLE_ANGULAR_LIMIT,true);
- set_flag_y( FLAG_ENABLE_LINEAR_LIMIT,true);
- set_flag_y( FLAG_ENABLE_MOTOR,false);
-
-
- set_param_z( PARAM_LINEAR_LOWER_LIMIT,0);
- set_param_z( PARAM_LINEAR_UPPER_LIMIT,0);
- set_param_z( PARAM_LINEAR_LIMIT_SOFTNESS,0.7);
- set_param_z( PARAM_LINEAR_RESTITUTION,0.5);
- set_param_z( PARAM_LINEAR_DAMPING,1.0);
- set_param_z( PARAM_ANGULAR_LOWER_LIMIT,0);
- set_param_z( PARAM_ANGULAR_UPPER_LIMIT,0);
- set_param_z( PARAM_ANGULAR_LIMIT_SOFTNESS,0.5f);
- set_param_z( PARAM_ANGULAR_DAMPING,1.0f);
- set_param_z( PARAM_ANGULAR_RESTITUTION,0);
- set_param_z( PARAM_ANGULAR_FORCE_LIMIT,0);
- set_param_z( PARAM_ANGULAR_ERP,0.5);
- set_param_z( PARAM_ANGULAR_MOTOR_TARGET_VELOCITY,0);
- set_param_z( PARAM_ANGULAR_MOTOR_FORCE_LIMIT,300);
-
- set_flag_z( FLAG_ENABLE_ANGULAR_LIMIT,true);
- set_flag_z( FLAG_ENABLE_LINEAR_LIMIT,true);
- set_flag_z( FLAG_ENABLE_MOTOR,false);
-
+ set_param_x(PARAM_LINEAR_LOWER_LIMIT, 0);
+ set_param_x(PARAM_LINEAR_UPPER_LIMIT, 0);
+ set_param_x(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
+ set_param_x(PARAM_LINEAR_RESTITUTION, 0.5);
+ set_param_x(PARAM_LINEAR_DAMPING, 1.0);
+ set_param_x(PARAM_ANGULAR_LOWER_LIMIT, 0);
+ set_param_x(PARAM_ANGULAR_UPPER_LIMIT, 0);
+ set_param_x(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
+ set_param_x(PARAM_ANGULAR_DAMPING, 1.0f);
+ set_param_x(PARAM_ANGULAR_RESTITUTION, 0);
+ set_param_x(PARAM_ANGULAR_FORCE_LIMIT, 0);
+ set_param_x(PARAM_ANGULAR_ERP, 0.5);
+ set_param_x(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
+ set_param_x(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
+
+ set_flag_x(FLAG_ENABLE_ANGULAR_LIMIT, true);
+ set_flag_x(FLAG_ENABLE_LINEAR_LIMIT, true);
+ set_flag_x(FLAG_ENABLE_MOTOR, false);
+
+ set_param_y(PARAM_LINEAR_LOWER_LIMIT, 0);
+ set_param_y(PARAM_LINEAR_UPPER_LIMIT, 0);
+ set_param_y(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
+ set_param_y(PARAM_LINEAR_RESTITUTION, 0.5);
+ set_param_y(PARAM_LINEAR_DAMPING, 1.0);
+ set_param_y(PARAM_ANGULAR_LOWER_LIMIT, 0);
+ set_param_y(PARAM_ANGULAR_UPPER_LIMIT, 0);
+ set_param_y(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
+ set_param_y(PARAM_ANGULAR_DAMPING, 1.0f);
+ set_param_y(PARAM_ANGULAR_RESTITUTION, 0);
+ set_param_y(PARAM_ANGULAR_FORCE_LIMIT, 0);
+ set_param_y(PARAM_ANGULAR_ERP, 0.5);
+ set_param_y(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
+ set_param_y(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
+
+ set_flag_y(FLAG_ENABLE_ANGULAR_LIMIT, true);
+ set_flag_y(FLAG_ENABLE_LINEAR_LIMIT, true);
+ set_flag_y(FLAG_ENABLE_MOTOR, false);
+
+ set_param_z(PARAM_LINEAR_LOWER_LIMIT, 0);
+ set_param_z(PARAM_LINEAR_UPPER_LIMIT, 0);
+ set_param_z(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7);
+ set_param_z(PARAM_LINEAR_RESTITUTION, 0.5);
+ set_param_z(PARAM_LINEAR_DAMPING, 1.0);
+ set_param_z(PARAM_ANGULAR_LOWER_LIMIT, 0);
+ set_param_z(PARAM_ANGULAR_UPPER_LIMIT, 0);
+ set_param_z(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f);
+ set_param_z(PARAM_ANGULAR_DAMPING, 1.0f);
+ set_param_z(PARAM_ANGULAR_RESTITUTION, 0);
+ set_param_z(PARAM_ANGULAR_FORCE_LIMIT, 0);
+ set_param_z(PARAM_ANGULAR_ERP, 0.5);
+ set_param_z(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY, 0);
+ set_param_z(PARAM_ANGULAR_MOTOR_FORCE_LIMIT, 300);
+
+ set_flag_z(FLAG_ENABLE_ANGULAR_LIMIT, true);
+ set_flag_z(FLAG_ENABLE_LINEAR_LIMIT, true);
+ set_flag_z(FLAG_ENABLE_MOTOR, false);
}
-
-
-
#if 0
void PhysicsJoint::_set(const String& p_name, const Variant& p_value) {
diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h
index 5debe87d38..90d86d652d 100644
--- a/scene/3d/physics_joint.h
+++ b/scene/3d/physics_joint.h
@@ -29,15 +29,14 @@
#ifndef PHYSICS_JOINT_H
#define PHYSICS_JOINT_H
-#include "scene/3d/spatial.h"
#include "scene/3d/physics_body.h"
-
+#include "scene/3d/spatial.h"
class Joint : public Spatial {
- GDCLASS(Joint,Spatial);
+ GDCLASS(Joint, Spatial);
- RID ba,bb;
+ RID ba, bb;
RID joint;
@@ -47,22 +46,20 @@ class Joint : public Spatial {
int solver_priority;
bool exclude_from_collision;
-
protected:
-
- void _update_joint(bool p_only_free=false);
+ void _update_joint(bool p_only_free = false);
void _notification(int p_what);
- virtual RID _configure_joint(PhysicsBody *body_a,PhysicsBody *body_b)=0;
+ virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) = 0;
static void _bind_methods();
-public:
- void set_node_a(const NodePath& p_node_a);
+public:
+ void set_node_a(const NodePath &p_node_a);
NodePath get_node_a() const;
- void set_node_b(const NodePath& p_node_b);
+ void set_node_b(const NodePath &p_node_b);
NodePath get_node_b() const;
void set_solver_priority(int p_priority);
@@ -73,31 +70,28 @@ public:
RID get_joint() const { return joint; }
Joint();
-
};
///////////////////////////////////////////
-
class PinJoint : public Joint {
- GDCLASS(PinJoint,Joint);
-public:
+ GDCLASS(PinJoint, Joint);
+public:
enum Param {
- PARAM_BIAS=PhysicsServer::PIN_JOINT_BIAS,
- PARAM_DAMPING=PhysicsServer::PIN_JOINT_DAMPING,
- PARAM_IMPULSE_CLAMP=PhysicsServer::PIN_JOINT_IMPULSE_CLAMP
+ PARAM_BIAS = PhysicsServer::PIN_JOINT_BIAS,
+ PARAM_DAMPING = PhysicsServer::PIN_JOINT_DAMPING,
+ PARAM_IMPULSE_CLAMP = PhysicsServer::PIN_JOINT_IMPULSE_CLAMP
};
protected:
-
float params[3];
virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
static void _bind_methods();
-public:
- void set_param(Param p_param,float p_value);
+public:
+ void set_param(Param p_param, float p_value);
float get_param(Param p_param) const;
PinJoint();
@@ -105,34 +99,30 @@ public:
VARIANT_ENUM_CAST(PinJoint::Param);
-
class HingeJoint : public Joint {
- GDCLASS(HingeJoint,Joint);
-public:
+ GDCLASS(HingeJoint, Joint);
+public:
enum Param {
- PARAM_BIAS=PhysicsServer::HINGE_JOINT_BIAS,
- PARAM_LIMIT_UPPER=PhysicsServer::HINGE_JOINT_LIMIT_UPPER,
- PARAM_LIMIT_LOWER=PhysicsServer::HINGE_JOINT_LIMIT_LOWER,
- PARAM_LIMIT_BIAS=PhysicsServer::HINGE_JOINT_LIMIT_BIAS,
- PARAM_LIMIT_SOFTNESS=PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS,
- PARAM_LIMIT_RELAXATION=PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION,
- PARAM_MOTOR_TARGET_VELOCITY=PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY,
- PARAM_MOTOR_MAX_IMPULSE=PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE,
- PARAM_MAX=PhysicsServer::HINGE_JOINT_MAX
+ PARAM_BIAS = PhysicsServer::HINGE_JOINT_BIAS,
+ PARAM_LIMIT_UPPER = PhysicsServer::HINGE_JOINT_LIMIT_UPPER,
+ PARAM_LIMIT_LOWER = PhysicsServer::HINGE_JOINT_LIMIT_LOWER,
+ PARAM_LIMIT_BIAS = PhysicsServer::HINGE_JOINT_LIMIT_BIAS,
+ PARAM_LIMIT_SOFTNESS = PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS,
+ PARAM_LIMIT_RELAXATION = PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION,
+ PARAM_MOTOR_TARGET_VELOCITY = PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY,
+ PARAM_MOTOR_MAX_IMPULSE = PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE,
+ PARAM_MAX = PhysicsServer::HINGE_JOINT_MAX
};
enum Flag {
- FLAG_USE_LIMIT=PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT,
- FLAG_ENABLE_MOTOR=PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR,
- FLAG_MAX=PhysicsServer::HINGE_JOINT_FLAG_MAX
+ FLAG_USE_LIMIT = PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT,
+ FLAG_ENABLE_MOTOR = PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR,
+ FLAG_MAX = PhysicsServer::HINGE_JOINT_FLAG_MAX
};
-
-
protected:
-
float params[PARAM_MAX];
bool flags[FLAG_MAX];
virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
@@ -145,11 +135,10 @@ protected:
float _get_lower_limit() const;
public:
-
- void set_param(Param p_param,float p_value);
+ void set_param(Param p_param, float p_value);
float get_param(Param p_param) const;
- void set_flag(Flag p_flag,bool p_value);
+ void set_flag(Flag p_flag, bool p_value);
bool get_flag(Flag p_flag) const;
HingeJoint();
@@ -158,44 +147,40 @@ public:
VARIANT_ENUM_CAST(HingeJoint::Param);
VARIANT_ENUM_CAST(HingeJoint::Flag);
-
class SliderJoint : public Joint {
- GDCLASS(SliderJoint,Joint);
-public:
+ GDCLASS(SliderJoint, Joint);
+public:
enum Param {
- PARAM_LINEAR_LIMIT_UPPER=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER,
- PARAM_LINEAR_LIMIT_LOWER=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER,
- PARAM_LINEAR_LIMIT_SOFTNESS=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
- PARAM_LINEAR_LIMIT_RESTITUTION=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
- PARAM_LINEAR_LIMIT_DAMPING=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
- PARAM_LINEAR_MOTION_SOFTNESS=PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
- PARAM_LINEAR_MOTION_RESTITUTION=PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
- PARAM_LINEAR_MOTION_DAMPING=PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING,
- PARAM_LINEAR_ORTHOGONAL_SOFTNESS=PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
- PARAM_LINEAR_ORTHOGONAL_RESTITUTION=PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
- PARAM_LINEAR_ORTHOGONAL_DAMPING=PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
-
- PARAM_ANGULAR_LIMIT_UPPER=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
- PARAM_ANGULAR_LIMIT_LOWER=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
- PARAM_ANGULAR_LIMIT_SOFTNESS=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
- PARAM_ANGULAR_LIMIT_RESTITUTION=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
- PARAM_ANGULAR_LIMIT_DAMPING=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
- PARAM_ANGULAR_MOTION_SOFTNESS=PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
- PARAM_ANGULAR_MOTION_RESTITUTION=PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
- PARAM_ANGULAR_MOTION_DAMPING=PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
- PARAM_ANGULAR_ORTHOGONAL_SOFTNESS=PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
- PARAM_ANGULAR_ORTHOGONAL_RESTITUTION=PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
- PARAM_ANGULAR_ORTHOGONAL_DAMPING=PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
- PARAM_MAX=PhysicsServer::SLIDER_JOINT_MAX
+ PARAM_LINEAR_LIMIT_UPPER = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER,
+ PARAM_LINEAR_LIMIT_LOWER = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER,
+ PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
+ PARAM_LINEAR_LIMIT_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
+ PARAM_LINEAR_LIMIT_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
+ PARAM_LINEAR_MOTION_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
+ PARAM_LINEAR_MOTION_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
+ PARAM_LINEAR_MOTION_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING,
+ PARAM_LINEAR_ORTHOGONAL_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
+ PARAM_LINEAR_ORTHOGONAL_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
+ PARAM_LINEAR_ORTHOGONAL_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
+
+ PARAM_ANGULAR_LIMIT_UPPER = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
+ PARAM_ANGULAR_LIMIT_LOWER = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
+ PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
+ PARAM_ANGULAR_LIMIT_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
+ PARAM_ANGULAR_LIMIT_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
+ PARAM_ANGULAR_MOTION_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
+ PARAM_ANGULAR_MOTION_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
+ PARAM_ANGULAR_MOTION_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
+ PARAM_ANGULAR_ORTHOGONAL_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
+ PARAM_ANGULAR_ORTHOGONAL_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
+ PARAM_ANGULAR_ORTHOGONAL_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
+ PARAM_MAX = PhysicsServer::SLIDER_JOINT_MAX
};
protected:
-
-
-
void _set_upper_limit_angular(float p_limit_angular);
float _get_upper_limit_angular() const;
@@ -205,25 +190,21 @@ protected:
float params[PARAM_MAX];
virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
static void _bind_methods();
-public:
- void set_param(Param p_param,float p_value);
+public:
+ void set_param(Param p_param, float p_value);
float get_param(Param p_param) const;
SliderJoint();
};
-
VARIANT_ENUM_CAST(SliderJoint::Param);
-
-
-
class ConeTwistJoint : public Joint {
- GDCLASS(ConeTwistJoint,Joint);
-public:
+ GDCLASS(ConeTwistJoint, Joint);
+public:
enum Param {
PARAM_SWING_SPAN,
@@ -235,8 +216,6 @@ public:
};
protected:
-
-
void _set_swing_span(float p_limit_angular);
float _get_swing_span() const;
@@ -246,53 +225,48 @@ protected:
float params[PARAM_MAX];
virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
static void _bind_methods();
-public:
- void set_param(Param p_param,float p_value);
+public:
+ void set_param(Param p_param, float p_value);
float get_param(Param p_param) const;
ConeTwistJoint();
};
-
VARIANT_ENUM_CAST(ConeTwistJoint::Param);
-
class Generic6DOFJoint : public Joint {
- GDCLASS(Generic6DOFJoint,Joint);
-public:
+ GDCLASS(Generic6DOFJoint, Joint);
+public:
enum Param {
- PARAM_LINEAR_LOWER_LIMIT=PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT,
- PARAM_LINEAR_UPPER_LIMIT=PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT,
- PARAM_LINEAR_LIMIT_SOFTNESS=PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
- PARAM_LINEAR_RESTITUTION=PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION,
- PARAM_LINEAR_DAMPING=PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING,
- PARAM_ANGULAR_LOWER_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
- PARAM_ANGULAR_UPPER_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
- PARAM_ANGULAR_LIMIT_SOFTNESS=PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
- PARAM_ANGULAR_DAMPING=PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING,
- PARAM_ANGULAR_RESTITUTION=PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION,
- PARAM_ANGULAR_FORCE_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
- PARAM_ANGULAR_ERP=PhysicsServer::G6DOF_JOINT_ANGULAR_ERP,
- PARAM_ANGULAR_MOTOR_TARGET_VELOCITY=PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
- PARAM_ANGULAR_MOTOR_FORCE_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
- PARAM_MAX=PhysicsServer::G6DOF_JOINT_MAX,
+ PARAM_LINEAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT,
+ PARAM_LINEAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT,
+ PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
+ PARAM_LINEAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION,
+ PARAM_LINEAR_DAMPING = PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING,
+ PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
+ PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
+ PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
+ PARAM_ANGULAR_DAMPING = PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING,
+ PARAM_ANGULAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION,
+ PARAM_ANGULAR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
+ PARAM_ANGULAR_ERP = PhysicsServer::G6DOF_JOINT_ANGULAR_ERP,
+ PARAM_ANGULAR_MOTOR_TARGET_VELOCITY = PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
+ PARAM_ANGULAR_MOTOR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
+ PARAM_MAX = PhysicsServer::G6DOF_JOINT_MAX,
};
enum Flag {
- FLAG_ENABLE_LINEAR_LIMIT=PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
- FLAG_ENABLE_ANGULAR_LIMIT=PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
- FLAG_ENABLE_MOTOR=PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR,
- FLAG_MAX=PhysicsServer::G6DOF_JOINT_FLAG_MAX
+ FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
+ FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
+ FLAG_ENABLE_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR,
+ FLAG_MAX = PhysicsServer::G6DOF_JOINT_FLAG_MAX
};
-
protected:
-
-
void _set_angular_hi_limit_x(float p_limit_angular);
float _get_angular_hi_limit_x() const;
@@ -320,34 +294,32 @@ protected:
virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
static void _bind_methods();
-public:
- void set_param_x(Param p_param,float p_value);
+public:
+ void set_param_x(Param p_param, float p_value);
float get_param_x(Param p_param) const;
- void set_param_y(Param p_param,float p_value);
+ void set_param_y(Param p_param, float p_value);
float get_param_y(Param p_param) const;
- void set_param_z(Param p_param,float p_value);
+ void set_param_z(Param p_param, float p_value);
float get_param_z(Param p_param) const;
- void set_flag_x(Flag p_flag,bool p_enabled);
+ void set_flag_x(Flag p_flag, bool p_enabled);
bool get_flag_x(Flag p_flag) const;
- void set_flag_y(Flag p_flag,bool p_enabled);
+ void set_flag_y(Flag p_flag, bool p_enabled);
bool get_flag_y(Flag p_flag) const;
- void set_flag_z(Flag p_flag,bool p_enabled);
+ void set_flag_z(Flag p_flag, bool p_enabled);
bool get_flag_z(Flag p_flag) const;
Generic6DOFJoint();
};
-
VARIANT_ENUM_CAST(Generic6DOFJoint::Param);
VARIANT_ENUM_CAST(Generic6DOFJoint::Flag);
-
#if 0
class PhysicsJoint : public Spatial {
diff --git a/scene/3d/portal.cpp b/scene/3d/portal.cpp
index 19f1261238..391a74ec45 100644
--- a/scene/3d/portal.cpp
+++ b/scene/3d/portal.cpp
@@ -27,31 +27,31 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "portal.h"
-#include "servers/visual_server.h"
-#include "scene/resources/surface_tool.h"
#include "global_config.h"
+#include "scene/resources/surface_tool.h"
+#include "servers/visual_server.h"
-bool Portal::_set(const StringName& p_name, const Variant& p_value) {
+bool Portal::_set(const StringName &p_name, const Variant &p_value) {
- if (p_name=="shape") {
- PoolVector<float> src_coords=p_value;
+ if (p_name == "shape") {
+ PoolVector<float> src_coords = p_value;
Vector<Point2> points;
int src_coords_size = src_coords.size();
- ERR_FAIL_COND_V(src_coords_size%2,false);
- points.resize(src_coords_size/2);
- for (int i=0;i<points.size();i++) {
+ ERR_FAIL_COND_V(src_coords_size % 2, false);
+ points.resize(src_coords_size / 2);
+ for (int i = 0; i < points.size(); i++) {
- points[i].x=src_coords[i*2+0];
- points[i].y=src_coords[i*2+1];
+ points[i].x = src_coords[i * 2 + 0];
+ points[i].y = src_coords[i * 2 + 1];
set_shape(points);
}
- } else if (p_name=="enabled") {
+ } else if (p_name == "enabled") {
set_enabled(p_value);
- } else if (p_name=="disable_distance") {
+ } else if (p_name == "disable_distance") {
set_disable_distance(p_value);
- } else if (p_name=="disabled_color") {
+ } else if (p_name == "disabled_color") {
set_disabled_color(p_value);
- } else if (p_name=="connect_range") {
+ } else if (p_name == "connect_range") {
set_connect_range(p_value);
} else
return false;
@@ -59,87 +59,82 @@ bool Portal::_set(const StringName& p_name, const Variant& p_value) {
return true;
}
-bool Portal::_get(const StringName& p_name,Variant &r_ret) const {
+bool Portal::_get(const StringName &p_name, Variant &r_ret) const {
- if (p_name=="shape") {
- Vector<Point2> points=get_shape();
+ if (p_name == "shape") {
+ Vector<Point2> points = get_shape();
PoolVector<float> dst_coords;
- dst_coords.resize(points.size()*2);
+ dst_coords.resize(points.size() * 2);
- for (int i=0;i<points.size();i++) {
+ for (int i = 0; i < points.size(); i++) {
- dst_coords.set(i*2+0,points[i].x);
- dst_coords.set(i*2+1,points[i].y);
+ dst_coords.set(i * 2 + 0, points[i].x);
+ dst_coords.set(i * 2 + 1, points[i].y);
}
- r_ret= dst_coords;
- } else if (p_name=="enabled") {
- r_ret= is_enabled();
- } else if (p_name=="disable_distance") {
- r_ret= get_disable_distance();
- } else if (p_name=="disabled_color") {
- r_ret= get_disabled_color();
- } else if (p_name=="connect_range") {
- r_ret= get_connect_range();
+ r_ret = dst_coords;
+ } else if (p_name == "enabled") {
+ r_ret = is_enabled();
+ } else if (p_name == "disable_distance") {
+ r_ret = get_disable_distance();
+ } else if (p_name == "disabled_color") {
+ r_ret = get_disabled_color();
+ } else if (p_name == "connect_range") {
+ r_ret = get_connect_range();
} else
return false;
return true;
}
-void Portal::_get_property_list( List<PropertyInfo> *p_list) const {
+void Portal::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo( Variant::POOL_REAL_ARRAY, "shape" ) );
- p_list->push_back( PropertyInfo( Variant::BOOL, "enabled" ) );
- p_list->push_back( PropertyInfo( Variant::REAL, "disable_distance",PROPERTY_HINT_RANGE,"0,4096,0.01" ) );
- p_list->push_back( PropertyInfo( Variant::COLOR, "disabled_color") );
- p_list->push_back( PropertyInfo( Variant::REAL, "connect_range",PROPERTY_HINT_RANGE,"0.1,4096,0.01" ) );
+ p_list->push_back(PropertyInfo(Variant::POOL_REAL_ARRAY, "shape"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "enabled"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "disable_distance", PROPERTY_HINT_RANGE, "0,4096,0.01"));
+ p_list->push_back(PropertyInfo(Variant::COLOR, "disabled_color"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "connect_range", PROPERTY_HINT_RANGE, "0.1,4096,0.01"));
}
-
-
-
Rect3 Portal::get_aabb() const {
return aabb;
}
PoolVector<Face3> Portal::get_faces(uint32_t p_usage_flags) const {
- if (!(p_usage_flags&FACES_ENCLOSING))
+ if (!(p_usage_flags & FACES_ENCLOSING))
return PoolVector<Face3>();
Vector<Point2> shape = get_shape();
- if (shape.size()==0)
+ if (shape.size() == 0)
return PoolVector<Face3>();
Vector2 center;
- for (int i=0;i<shape.size();i++) {
-
- center+=shape[i];
+ for (int i = 0; i < shape.size(); i++) {
+ center += shape[i];
}
PoolVector<Face3> ret;
- center/=shape.size();
+ center /= shape.size();
- for (int i=0;i<shape.size();i++) {
+ for (int i = 0; i < shape.size(); i++) {
- int n=(i+1)%shape.size();
+ int n = (i + 1) % shape.size();
Face3 f;
- f.vertex[0]=Vector3( center.x, center.y, 0 );
- f.vertex[1]=Vector3( shape[i].x, shape[i].y, 0 );
- f.vertex[2]=Vector3( shape[n].x, shape[n].y, 0 );
+ f.vertex[0] = Vector3(center.x, center.y, 0);
+ f.vertex[1] = Vector3(shape[i].x, shape[i].y, 0);
+ f.vertex[2] = Vector3(shape[n].x, shape[n].y, 0);
ret.push_back(f);
}
return ret;
}
-void Portal::set_shape(const Vector<Point2>& p_shape) {
-
+void Portal::set_shape(const Vector<Point2> &p_shape) {
VisualServer::get_singleton()->portal_set_shape(portal, p_shape);
- shape=p_shape;
+ shape = p_shape;
update_gizmo();
}
@@ -150,7 +145,7 @@ Vector<Point2> Portal::get_shape() const {
void Portal::set_connect_range(float p_range) {
- connect_range=p_range;
+ connect_range = p_range;
//VisualServer::get_singleton()->portal_set_connect_range(portal,p_range);
}
@@ -159,35 +154,31 @@ float Portal::get_connect_range() const {
return connect_range;
}
-
void Portal::set_enabled(bool p_enabled) {
- enabled=p_enabled;
- VisualServer::get_singleton()->portal_set_enabled(portal,enabled);
+ enabled = p_enabled;
+ VisualServer::get_singleton()->portal_set_enabled(portal, enabled);
}
bool Portal::is_enabled() const {
-
return enabled;
}
void Portal::set_disable_distance(float p_distance) {
- disable_distance=p_distance;
- VisualServer::get_singleton()->portal_set_disable_distance(portal,disable_distance);
-
+ disable_distance = p_distance;
+ VisualServer::get_singleton()->portal_set_disable_distance(portal, disable_distance);
}
float Portal::get_disable_distance() const {
-
return disable_distance;
}
-void Portal::set_disabled_color(const Color& p_disabled_color) {
+void Portal::set_disabled_color(const Color &p_disabled_color) {
- disabled_color=p_disabled_color;
- VisualServer::get_singleton()->portal_set_disabled_color(portal,disabled_color);
+ disabled_color = p_disabled_color;
+ VisualServer::get_singleton()->portal_set_disabled_color(portal, disabled_color);
}
Color Portal::get_disabled_color() const {
@@ -197,47 +188,40 @@ Color Portal::get_disabled_color() const {
void Portal::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_shape","points"),&Portal::set_shape);
- ClassDB::bind_method(D_METHOD("get_shape"),&Portal::get_shape);
+ ClassDB::bind_method(D_METHOD("set_shape", "points"), &Portal::set_shape);
+ ClassDB::bind_method(D_METHOD("get_shape"), &Portal::get_shape);
- ClassDB::bind_method(D_METHOD("set_enabled","enable"),&Portal::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&Portal::is_enabled);
+ ClassDB::bind_method(D_METHOD("set_enabled", "enable"), &Portal::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &Portal::is_enabled);
- ClassDB::bind_method(D_METHOD("set_disable_distance","distance"),&Portal::set_disable_distance);
- ClassDB::bind_method(D_METHOD("get_disable_distance"),&Portal::get_disable_distance);
+ ClassDB::bind_method(D_METHOD("set_disable_distance", "distance"), &Portal::set_disable_distance);
+ ClassDB::bind_method(D_METHOD("get_disable_distance"), &Portal::get_disable_distance);
- ClassDB::bind_method(D_METHOD("set_disabled_color","color"),&Portal::set_disabled_color);
- ClassDB::bind_method(D_METHOD("get_disabled_color"),&Portal::get_disabled_color);
-
- ClassDB::bind_method(D_METHOD("set_connect_range","range"),&Portal::set_connect_range);
- ClassDB::bind_method(D_METHOD("get_connect_range"),&Portal::get_connect_range);
+ ClassDB::bind_method(D_METHOD("set_disabled_color", "color"), &Portal::set_disabled_color);
+ ClassDB::bind_method(D_METHOD("get_disabled_color"), &Portal::get_disabled_color);
+ ClassDB::bind_method(D_METHOD("set_connect_range", "range"), &Portal::set_connect_range);
+ ClassDB::bind_method(D_METHOD("get_connect_range"), &Portal::get_connect_range);
}
Portal::Portal() {
portal = VisualServer::get_singleton()->portal_create();
- Vector< Point2 > points;
- points.push_back( Point2( -1, 1 ) );
- points.push_back( Point2( 1, 1 ) );
- points.push_back( Point2( 1, -1 ) );
- points.push_back( Point2( -1, -1 ) );
+ Vector<Point2> points;
+ points.push_back(Point2(-1, 1));
+ points.push_back(Point2(1, 1));
+ points.push_back(Point2(1, -1));
+ points.push_back(Point2(-1, -1));
set_shape(points); // default shape
-
set_connect_range(0.8);
set_disable_distance(50);
set_enabled(true);
set_base(portal);
-
-
}
-
Portal::~Portal() {
VisualServer::get_singleton()->free(portal);
}
-
-
diff --git a/scene/3d/portal.h b/scene/3d/portal.h
index 077924c7e8..018708308f 100644
--- a/scene/3d/portal.h
+++ b/scene/3d/portal.h
@@ -34,14 +34,11 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
/* Portal Logic:
If a portal is placed next (very close to) a similar, opposing portal, they automatically connect,
otherwise, a portal connects to the parent room
*/
-
-
class Portal : public VisualInstance {
GDCLASS(Portal, VisualInstance);
@@ -56,17 +53,14 @@ class Portal : public VisualInstance {
Rect3 aabb;
-
protected:
-
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
public:
-
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
@@ -76,10 +70,10 @@ public:
void set_disable_distance(float p_distance);
float get_disable_distance() const;
- void set_disabled_color(const Color& p_disabled_color);
+ void set_disabled_color(const Color &p_disabled_color);
Color get_disabled_color() const;
- void set_shape(const Vector<Point2>& p_shape);
+ void set_shape(const Vector<Point2> &p_shape);
Vector<Point2> get_shape() const;
void set_connect_range(float p_range);
@@ -87,7 +81,6 @@ public:
Portal();
~Portal();
-
};
#endif
diff --git a/scene/3d/position_3d.cpp b/scene/3d/position_3d.cpp
index e7403053b2..ee09ed93a7 100644
--- a/scene/3d/position_3d.cpp
+++ b/scene/3d/position_3d.cpp
@@ -29,7 +29,5 @@
#include "position_3d.h"
#include "scene/resources/mesh.h"
-
-Position3D::Position3D()
-{
+Position3D::Position3D() {
}
diff --git a/scene/3d/position_3d.h b/scene/3d/position_3d.h
index e732c5321e..dae94dfbaf 100644
--- a/scene/3d/position_3d.h
+++ b/scene/3d/position_3d.h
@@ -31,13 +31,11 @@
#include "scene/3d/spatial.h"
-class Position3D : public Spatial {
-
- GDCLASS(Position3D,Spatial);
+class Position3D : public Spatial {
+ GDCLASS(Position3D, Spatial);
public:
-
Position3D();
};
diff --git a/scene/3d/proximity_group.cpp b/scene/3d/proximity_group.cpp
index f0dc8cb2ed..f1225b6901 100644
--- a/scene/3d/proximity_group.cpp
+++ b/scene/3d/proximity_group.cpp
@@ -47,7 +47,7 @@ void ProximityGroup::clear_groups() {
E = E->next();
};
- for (int i=0; i<num; i++) {
+ for (int i = 0; i < num; i++) {
groups.erase(remove_list[i]);
};
@@ -74,7 +74,7 @@ void ProximityGroup::update_groups() {
clear_groups();
};
-void ProximityGroup::add_groups(int* p_cell, String p_base, int p_depth) {
+void ProximityGroup::add_groups(int *p_cell, String p_base, int p_depth) {
p_base = p_base + "|";
if (grid_radius[p_depth] == 0) {
@@ -89,7 +89,7 @@ void ProximityGroup::add_groups(int* p_cell, String p_base, int p_depth) {
int start = p_cell[p_depth] - grid_radius[p_depth];
int end = p_cell[p_depth] + grid_radius[p_depth];
- for (int i=start; i<=end; i++) {
+ for (int i = start; i <= end; i++) {
String gname = p_base + itos(i);
if (p_depth == 2) {
@@ -102,7 +102,7 @@ void ProximityGroup::add_groups(int* p_cell, String p_base, int p_depth) {
void ProximityGroup::_new_group(StringName p_name) {
- const Map<StringName, uint32_t>::Element* E = groups.find(p_name);
+ const Map<StringName, uint32_t>::Element *E = groups.find(p_name);
if (!E) {
add_to_group(p_name);
};
@@ -119,13 +119,13 @@ void ProximityGroup::_notification(int what) {
switch (what) {
- case NOTIFICATION_EXIT_TREE:
- ++group_version;
- clear_groups();
- break;
- case NOTIFICATION_TRANSFORM_CHANGED:
- update_groups();
- break;
+ case NOTIFICATION_EXIT_TREE:
+ ++group_version;
+ clear_groups();
+ break;
+ case NOTIFICATION_TRANSFORM_CHANGED:
+ update_groups();
+ break;
};
};
@@ -138,7 +138,6 @@ void ProximityGroup::broadcast(String p_name, Variant p_params) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFAULT, E->key(), "_proximity_group_broadcast", p_name, p_params);
E = E->next();
};
-
};
void ProximityGroup::_proximity_group_broadcast(String p_name, Variant p_params) {
@@ -152,13 +151,12 @@ void ProximityGroup::_proximity_group_broadcast(String p_name, Variant p_params)
};
};
-
void ProximityGroup::set_dispatch_mode(int p_mode) {
dispatch_mode = (DispatchMode)p_mode;
};
-void ProximityGroup::set_grid_radius(const Vector3& p_radius) {
+void ProximityGroup::set_grid_radius(const Vector3 &p_radius) {
grid_radius = p_radius;
};
@@ -168,22 +166,20 @@ Vector3 ProximityGroup::get_grid_radius() const {
return grid_radius;
};
-
void ProximityGroup::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_group_name","name"), &ProximityGroup::set_group_name);
- ClassDB::bind_method(D_METHOD("broadcast","name", "parameters"), &ProximityGroup::broadcast);
- ClassDB::bind_method(D_METHOD("set_dispatch_mode","mode"), &ProximityGroup::set_dispatch_mode);
- ClassDB::bind_method(D_METHOD("_proximity_group_broadcast","name","params"), &ProximityGroup::_proximity_group_broadcast);
- ClassDB::bind_method(D_METHOD("set_grid_radius","radius"), &ProximityGroup::set_grid_radius);
+ ClassDB::bind_method(D_METHOD("set_group_name", "name"), &ProximityGroup::set_group_name);
+ ClassDB::bind_method(D_METHOD("broadcast", "name", "parameters"), &ProximityGroup::broadcast);
+ ClassDB::bind_method(D_METHOD("set_dispatch_mode", "mode"), &ProximityGroup::set_dispatch_mode);
+ ClassDB::bind_method(D_METHOD("_proximity_group_broadcast", "name", "params"), &ProximityGroup::_proximity_group_broadcast);
+ ClassDB::bind_method(D_METHOD("set_grid_radius", "radius"), &ProximityGroup::set_grid_radius);
ClassDB::bind_method(D_METHOD("get_grid_radius"), &ProximityGroup::get_grid_radius);
- ADD_PROPERTY( PropertyInfo( Variant::VECTOR3, "grid_radius"), "set_grid_radius", "get_grid_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "grid_radius"), "set_grid_radius", "get_grid_radius");
- ADD_SIGNAL( MethodInfo("broadcast", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::ARRAY, "parameters")) );
+ ADD_SIGNAL(MethodInfo("broadcast", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::ARRAY, "parameters")));
};
-
ProximityGroup::ProximityGroup() {
group_version = 0;
@@ -191,9 +187,8 @@ ProximityGroup::ProximityGroup() {
grid_radius = Vector3(1, 1, 1);
set_notify_transform(true);
-
};
-ProximityGroup::~ProximityGroup() {
+ProximityGroup::~ProximityGroup(){
};
diff --git a/scene/3d/proximity_group.h b/scene/3d/proximity_group.h
index 58d2436975..f40ffe2ffe 100644
--- a/scene/3d/proximity_group.h
+++ b/scene/3d/proximity_group.h
@@ -33,7 +33,7 @@
class ProximityGroup : public Spatial {
- GDCLASS( ProximityGroup, Spatial );
+ GDCLASS(ProximityGroup, Spatial);
OBJ_CATEGORY("3D");
public:
@@ -57,7 +57,7 @@ public:
Vector3 grid_radius;
uint32_t group_version;
- void add_groups(int* p_cell, String p_base, int p_depth);
+ void add_groups(int *p_cell, String p_base, int p_depth);
void _new_group(StringName p_name);
void _proximity_group_broadcast(String p_name, Variant p_params);
@@ -65,12 +65,11 @@ public:
static void _bind_methods();
public:
-
void set_group_name(String p_group_name);
void broadcast(String p_name, Variant p_params);
void set_dispatch_mode(int p_mode);
- void set_grid_radius(const Vector3& p_radius);
+ void set_grid_radius(const Vector3 &p_radius);
Vector3 get_grid_radius() const;
ProximityGroup();
@@ -78,4 +77,3 @@ public:
};
#endif
-
diff --git a/scene/3d/quad.cpp b/scene/3d/quad.cpp
index e740769bd4..e32320681c 100644
--- a/scene/3d/quad.cpp
+++ b/scene/3d/quad.cpp
@@ -35,39 +35,36 @@ void Quad::_update() {
return;
Vector3 normal;
- normal[axis]=1.0;
-
- const int axis_order_1[3]={1,2,0};
- const int axis_order_2[3]={2,0,1};
- const int a1=axis_order_1[axis];
- const int a2=axis_order_2[axis];
-
+ normal[axis] = 1.0;
+ const int axis_order_1[3] = { 1, 2, 0 };
+ const int axis_order_2[3] = { 2, 0, 1 };
+ const int a1 = axis_order_1[axis];
+ const int a2 = axis_order_2[axis];
PoolVector<Vector3> points;
points.resize(4);
PoolVector<Vector3>::Write pointsw = points.write();
- Vector2 s2 = size*0.5;
+ Vector2 s2 = size * 0.5;
Vector2 o = offset;
if (!centered)
- o+=s2;
-
- pointsw[0][a1]=-s2.x+offset.x;
- pointsw[0][a2]=s2.y+offset.y;
+ o += s2;
- pointsw[1][a1]=s2.x+offset.x;
- pointsw[1][a2]=s2.y+offset.y;
+ pointsw[0][a1] = -s2.x + offset.x;
+ pointsw[0][a2] = s2.y + offset.y;
- pointsw[2][a1]=s2.x+offset.x;
- pointsw[2][a2]=-s2.y+offset.y;
+ pointsw[1][a1] = s2.x + offset.x;
+ pointsw[1][a2] = s2.y + offset.y;
- pointsw[3][a1]=-s2.x+offset.x;
- pointsw[3][a2]=-s2.y+offset.y;
+ pointsw[2][a1] = s2.x + offset.x;
+ pointsw[2][a2] = -s2.y + offset.y;
+ pointsw[3][a1] = -s2.x + offset.x;
+ pointsw[3][a2] = -s2.y + offset.y;
- aabb=Rect3(pointsw[0],Vector3());
- for(int i=1;i<4;i++)
+ aabb = Rect3(pointsw[0], Vector3());
+ for (int i = 1; i < 4; i++)
aabb.expand_to(pointsw[i]);
pointsw = PoolVector<Vector3>::Write();
@@ -76,21 +73,19 @@ void Quad::_update() {
normals.resize(4);
PoolVector<Vector3>::Write normalsw = normals.write();
- for(int i=0;i<4;i++)
- normalsw[i]=normal;
-
- normalsw=PoolVector<Vector3>::Write();
-
+ for (int i = 0; i < 4; i++)
+ normalsw[i] = normal;
+ normalsw = PoolVector<Vector3>::Write();
PoolVector<Vector2> uvs;
uvs.resize(4);
PoolVector<Vector2>::Write uvsw = uvs.write();
- uvsw[0]=Vector2(0,0);
- uvsw[1]=Vector2(1,0);
- uvsw[2]=Vector2(1,1);
- uvsw[3]=Vector2(0,1);
+ uvsw[0] = Vector2(0, 0);
+ uvsw[1] = Vector2(1, 0);
+ uvsw[2] = Vector2(1, 1);
+ uvsw[3] = Vector2(0, 1);
uvsw = PoolVector<Vector2>::Write();
@@ -98,90 +93,86 @@ void Quad::_update() {
indices.resize(6);
PoolVector<int>::Write indicesw = indices.write();
- indicesw[0]=0;
- indicesw[1]=1;
- indicesw[2]=2;
- indicesw[3]=2;
- indicesw[4]=3;
- indicesw[5]=0;
+ indicesw[0] = 0;
+ indicesw[1] = 1;
+ indicesw[2] = 2;
+ indicesw[3] = 2;
+ indicesw[4] = 3;
+ indicesw[5] = 0;
- indicesw=PoolVector<int>::Write();
+ indicesw = PoolVector<int>::Write();
Array arr;
arr.resize(VS::ARRAY_MAX);
- arr[VS::ARRAY_VERTEX]=points;
- arr[VS::ARRAY_NORMAL]=normals;
- arr[VS::ARRAY_TEX_UV]=uvs;
- arr[VS::ARRAY_INDEX]=indices;
-
+ arr[VS::ARRAY_VERTEX] = points;
+ arr[VS::ARRAY_NORMAL] = normals;
+ arr[VS::ARRAY_TEX_UV] = uvs;
+ arr[VS::ARRAY_INDEX] = indices;
if (configured) {
- VS::get_singleton()->mesh_remove_surface(mesh,0);
+ VS::get_singleton()->mesh_remove_surface(mesh, 0);
} else {
- configured=true;
+ configured = true;
}
- VS::get_singleton()->mesh_add_surface_from_arrays(mesh,VS::PRIMITIVE_TRIANGLES,arr);
+ VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VS::PRIMITIVE_TRIANGLES, arr);
- pending_update=false;
+ pending_update = false;
}
-
void Quad::set_axis(Vector3::Axis p_axis) {
- axis=p_axis;
+ axis = p_axis;
_update();
}
-Vector3::Axis Quad::get_axis() const{
+Vector3::Axis Quad::get_axis() const {
return axis;
}
-void Quad::set_size(const Vector2& p_size){
+void Quad::set_size(const Vector2 &p_size) {
- size=p_size;
+ size = p_size;
_update();
}
-Vector2 Quad::get_size() const{
+Vector2 Quad::get_size() const {
return size;
}
-void Quad::set_offset(const Vector2& p_offset){
+void Quad::set_offset(const Vector2 &p_offset) {
- offset=p_offset;
+ offset = p_offset;
_update();
}
-Vector2 Quad::get_offset() const{
+Vector2 Quad::get_offset() const {
return offset;
}
-void Quad::set_centered(bool p_enabled){
+void Quad::set_centered(bool p_enabled) {
- centered=p_enabled;
+ centered = p_enabled;
_update();
}
-bool Quad::is_centered() const{
+bool Quad::is_centered() const {
return centered;
}
void Quad::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (pending_update)
_update();
-
} break;
case NOTIFICATION_EXIT_TREE: {
- pending_update=true;
-
+ pending_update = true;
} break;
}
@@ -197,38 +188,36 @@ Rect3 Quad::get_aabb() const {
return aabb;
}
-void Quad::_bind_methods(){
+void Quad::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_axis","axis"),&Quad::set_axis);
- ClassDB::bind_method(D_METHOD("get_axis"),&Quad::get_axis);
+ ClassDB::bind_method(D_METHOD("set_axis", "axis"), &Quad::set_axis);
+ ClassDB::bind_method(D_METHOD("get_axis"), &Quad::get_axis);
- ClassDB::bind_method(D_METHOD("set_size","size"),&Quad::set_size);
- ClassDB::bind_method(D_METHOD("get_size"),&Quad::get_size);
+ ClassDB::bind_method(D_METHOD("set_size", "size"), &Quad::set_size);
+ ClassDB::bind_method(D_METHOD("get_size"), &Quad::get_size);
- ClassDB::bind_method(D_METHOD("set_centered","centered"),&Quad::set_centered);
- ClassDB::bind_method(D_METHOD("is_centered"),&Quad::is_centered);
+ ClassDB::bind_method(D_METHOD("set_centered", "centered"), &Quad::set_centered);
+ ClassDB::bind_method(D_METHOD("is_centered"), &Quad::is_centered);
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&Quad::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&Quad::get_offset);
-
- ADD_PROPERTY( PropertyInfo( Variant::INT, "axis", PROPERTY_HINT_ENUM,"X,Y,Z" ), "set_axis", "get_axis");
- ADD_PROPERTY( PropertyInfo( Variant::VECTOR2, "size" ), "set_size", "get_size");
- ADD_PROPERTY( PropertyInfo( Variant::VECTOR2, "offset" ), "set_offset", "get_offset");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered" ), "set_centered", "is_centered");
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Quad::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &Quad::get_offset);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "axis", PROPERTY_HINT_ENUM, "X,Y,Z"), "set_axis", "get_axis");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
}
Quad::Quad() {
- pending_update=true;
- centered=true;
+ pending_update = true;
+ centered = true;
//offset=0;
- size=Vector2(1,1);
- axis=Vector3::AXIS_Z;
- mesh=VisualServer::get_singleton()->mesh_create();
+ size = Vector2(1, 1);
+ axis = Vector3::AXIS_Z;
+ mesh = VisualServer::get_singleton()->mesh_create();
set_base(mesh);
- configured=false;
-
+ configured = false;
}
Quad::~Quad() {
diff --git a/scene/3d/quad.h b/scene/3d/quad.h
index af91d7a1f5..607d7238ed 100644
--- a/scene/3d/quad.h
+++ b/scene/3d/quad.h
@@ -29,13 +29,12 @@
#ifndef QUAD_H
#define QUAD_H
-
-#include "scene/3d/visual_instance.h"
#include "rid.h"
+#include "scene/3d/visual_instance.h"
class Quad : public GeometryInstance {
- GDCLASS(Quad,GeometryInstance);
+ GDCLASS(Quad, GeometryInstance);
Vector3::Axis axis;
bool centered;
@@ -50,18 +49,17 @@ class Quad : public GeometryInstance {
void _update();
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_axis(Vector3::Axis p_axis);
Vector3::Axis get_axis() const;
- void set_size(const Vector2& p_sizze);
+ void set_size(const Vector2 &p_sizze);
Vector2 get_size() const;
- void set_offset(const Vector2& p_offset);
+ void set_offset(const Vector2 &p_offset);
Vector2 get_offset() const;
void set_centered(bool p_enabled);
@@ -74,5 +72,4 @@ public:
~Quad();
};
-
#endif // QUAD_H
diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp
index 6be8b89441..a73114a7c7 100644
--- a/scene/3d/ray_cast.cpp
+++ b/scene/3d/ray_cast.cpp
@@ -28,24 +28,23 @@
/*************************************************************************/
#include "ray_cast.h"
-#include "servers/physics_server.h"
#include "collision_object.h"
-void RayCast::set_cast_to(const Vector3& p_point) {
+#include "servers/physics_server.h"
+void RayCast::set_cast_to(const Vector3 &p_point) {
- cast_to=p_point;
+ cast_to = p_point;
if (is_inside_tree() && (get_tree()->is_editor_hint() || get_tree()->is_debugging_collisions_hint()))
update_gizmo();
-
}
-Vector3 RayCast::get_cast_to() const{
+Vector3 RayCast::get_cast_to() const {
return cast_to;
}
void RayCast::set_layer_mask(uint32_t p_mask) {
- layer_mask=p_mask;
+ layer_mask = p_mask;
}
uint32_t RayCast::get_layer_mask() const {
@@ -55,7 +54,7 @@ uint32_t RayCast::get_layer_mask() const {
void RayCast::set_type_mask(uint32_t p_mask) {
- type_mask=p_mask;
+ type_mask = p_mask;
}
uint32_t RayCast::get_type_mask() const {
@@ -63,13 +62,13 @@ uint32_t RayCast::get_type_mask() const {
return type_mask;
}
-bool RayCast::is_colliding() const{
+bool RayCast::is_colliding() const {
return collided;
}
-Object *RayCast::get_collider() const{
+Object *RayCast::get_collider() const {
- if (against==0)
+ if (against == 0)
return NULL;
return ObjectDB::get_instance(against);
@@ -79,37 +78,32 @@ int RayCast::get_collider_shape() const {
return against_shape;
}
-Vector3 RayCast::get_collision_point() const{
+Vector3 RayCast::get_collision_point() const {
return collision_point;
}
-Vector3 RayCast::get_collision_normal() const{
+Vector3 RayCast::get_collision_normal() const {
return collision_normal;
}
-
void RayCast::set_enabled(bool p_enabled) {
- enabled=p_enabled;
+ enabled = p_enabled;
if (is_inside_tree() && !get_tree()->is_editor_hint())
set_fixed_process(p_enabled);
if (!p_enabled)
- collided=false;
-
+ collided = false;
}
-
bool RayCast::is_enabled() const {
-
return enabled;
}
-
void RayCast::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -118,8 +112,6 @@ void RayCast::_notification(int p_what) {
} else
set_fixed_process(false);
-
-
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -127,7 +119,6 @@ void RayCast::_notification(int p_what) {
set_fixed_process(false);
}
-
} break;
case NOTIFICATION_FIXED_PROCESS: {
@@ -136,35 +127,34 @@ void RayCast::_notification(int p_what) {
_update_raycast_state();
-
} break;
}
}
-void RayCast::_update_raycast_state(){
+void RayCast::_update_raycast_state() {
Ref<World> w3d = get_world();
- ERR_FAIL_COND( w3d.is_null() );
+ ERR_FAIL_COND(w3d.is_null());
PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(w3d->get_space());
- ERR_FAIL_COND( !dss );
+ ERR_FAIL_COND(!dss);
Transform gt = get_global_transform();
Vector3 to = cast_to;
- if (to==Vector3())
- to=Vector3(0,0.01,0);
+ if (to == Vector3())
+ to = Vector3(0, 0.01, 0);
PhysicsDirectSpaceState::RayResult rr;
- if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude, layer_mask, type_mask)) {
+ if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, layer_mask, type_mask)) {
- collided=true;
- against=rr.collider_id;
- collision_point=rr.position;
- collision_normal=rr.normal;
- against_shape=rr.shape;
+ collided = true;
+ against = rr.collider_id;
+ collision_point = rr.position;
+ collision_normal = rr.normal;
+ against_shape = rr.shape;
} else {
- collided=false;
+ collided = false;
}
}
@@ -172,85 +162,82 @@ void RayCast::force_raycast_update() {
_update_raycast_state();
}
-void RayCast::add_exception_rid(const RID& p_rid) {
+void RayCast::add_exception_rid(const RID &p_rid) {
exclude.insert(p_rid);
}
-void RayCast::add_exception(const Object* p_object){
+void RayCast::add_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
- CollisionObject *co=((Object*)p_object)->cast_to<CollisionObject>();
+ CollisionObject *co = ((Object *)p_object)->cast_to<CollisionObject>();
if (!co)
return;
add_exception_rid(co->get_rid());
}
-void RayCast::remove_exception_rid(const RID& p_rid) {
+void RayCast::remove_exception_rid(const RID &p_rid) {
exclude.erase(p_rid);
}
-void RayCast::remove_exception(const Object* p_object){
+void RayCast::remove_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
- CollisionObject *co=((Object*)p_object)->cast_to<CollisionObject>();
+ CollisionObject *co = ((Object *)p_object)->cast_to<CollisionObject>();
if (!co)
return;
remove_exception_rid(co->get_rid());
}
-
-void RayCast::clear_exceptions(){
+void RayCast::clear_exceptions() {
exclude.clear();
}
-
void RayCast::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast::is_enabled);
- ClassDB::bind_method(D_METHOD("set_enabled","enabled"),&RayCast::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&RayCast::is_enabled);
-
- ClassDB::bind_method(D_METHOD("set_cast_to","local_point"),&RayCast::set_cast_to);
- ClassDB::bind_method(D_METHOD("get_cast_to"),&RayCast::get_cast_to);
+ ClassDB::bind_method(D_METHOD("set_cast_to", "local_point"), &RayCast::set_cast_to);
+ ClassDB::bind_method(D_METHOD("get_cast_to"), &RayCast::get_cast_to);
- ClassDB::bind_method(D_METHOD("is_colliding"),&RayCast::is_colliding);
- ClassDB::bind_method(D_METHOD("force_raycast_update"),&RayCast::force_raycast_update);
+ ClassDB::bind_method(D_METHOD("is_colliding"), &RayCast::is_colliding);
+ ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast::force_raycast_update);
- ClassDB::bind_method(D_METHOD("get_collider"),&RayCast::get_collider);
- ClassDB::bind_method(D_METHOD("get_collider_shape"),&RayCast::get_collider_shape);
- ClassDB::bind_method(D_METHOD("get_collision_point"),&RayCast::get_collision_point);
- ClassDB::bind_method(D_METHOD("get_collision_normal"),&RayCast::get_collision_normal);
+ ClassDB::bind_method(D_METHOD("get_collider"), &RayCast::get_collider);
+ ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast::get_collider_shape);
+ ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast::get_collision_point);
+ ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast::get_collision_normal);
- ClassDB::bind_method(D_METHOD("add_exception_rid","rid"),&RayCast::add_exception_rid);
- ClassDB::bind_method(D_METHOD("add_exception","node"),&RayCast::add_exception);
+ ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &RayCast::add_exception_rid);
+ ClassDB::bind_method(D_METHOD("add_exception", "node"), &RayCast::add_exception);
- ClassDB::bind_method(D_METHOD("remove_exception_rid","rid"),&RayCast::remove_exception_rid);
- ClassDB::bind_method(D_METHOD("remove_exception","node"),&RayCast::remove_exception);
+ ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &RayCast::remove_exception_rid);
+ ClassDB::bind_method(D_METHOD("remove_exception", "node"), &RayCast::remove_exception);
- ClassDB::bind_method(D_METHOD("clear_exceptions"),&RayCast::clear_exceptions);
+ ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast::clear_exceptions);
- ClassDB::bind_method(D_METHOD("set_layer_mask","mask"),&RayCast::set_layer_mask);
- ClassDB::bind_method(D_METHOD("get_layer_mask"),&RayCast::get_layer_mask);
+ ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &RayCast::set_layer_mask);
+ ClassDB::bind_method(D_METHOD("get_layer_mask"), &RayCast::get_layer_mask);
- ClassDB::bind_method(D_METHOD("set_type_mask","mask"),&RayCast::set_type_mask);
- ClassDB::bind_method(D_METHOD("get_type_mask"),&RayCast::get_type_mask);
+ ClassDB::bind_method(D_METHOD("set_type_mask", "mask"), &RayCast::set_type_mask);
+ ClassDB::bind_method(D_METHOD("get_type_mask"), &RayCast::get_type_mask);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),"set_enabled","is_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3,"cast_to"),"set_cast_to","get_cast_to");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"layer_mask",PROPERTY_HINT_LAYERS_3D_PHYSICS),"set_layer_mask","get_layer_mask");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"type_mask",PROPERTY_HINT_FLAGS,"Static,Kinematic,Rigid,Character,Area"),"set_type_mask","get_type_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cast_to"), "set_cast_to", "get_cast_to");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layer_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_layer_mask", "get_layer_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type_mask", PROPERTY_HINT_FLAGS, "Static,Kinematic,Rigid,Character,Area"), "set_type_mask", "get_type_mask");
}
RayCast::RayCast() {
- enabled=false;
- against=0;
- collided=false;
- against_shape=0;
- layer_mask=1;
- type_mask=PhysicsDirectSpaceState::TYPE_MASK_COLLISION;
- cast_to=Vector3(0,-1,0);
+ enabled = false;
+ against = 0;
+ collided = false;
+ against_shape = 0;
+ layer_mask = 1;
+ type_mask = PhysicsDirectSpaceState::TYPE_MASK_COLLISION;
+ cast_to = Vector3(0, -1, 0);
}
diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h
index 32d24cc962..00a10446a5 100644
--- a/scene/3d/ray_cast.h
+++ b/scene/3d/ray_cast.h
@@ -33,8 +33,7 @@
class RayCast : public Spatial {
- GDCLASS(RayCast,Spatial);
-
+ GDCLASS(RayCast, Spatial);
bool enabled;
bool collided;
@@ -51,16 +50,15 @@ class RayCast : public Spatial {
uint32_t type_mask;
protected:
-
void _notification(int p_what);
void _update_raycast_state();
static void _bind_methods();
-public:
+public:
void set_enabled(bool p_enabled);
bool is_enabled() const;
- void set_cast_to(const Vector3& p_point);
+ void set_cast_to(const Vector3 &p_point);
Vector3 get_cast_to() const;
void set_layer_mask(uint32_t p_mask);
@@ -76,10 +74,10 @@ public:
Vector3 get_collision_point() const;
Vector3 get_collision_normal() const;
- void add_exception_rid(const RID& p_rid);
- void add_exception(const Object* p_object);
- void remove_exception_rid(const RID& p_rid);
- void remove_exception(const Object* p_object);
+ void add_exception_rid(const RID &p_rid);
+ void add_exception(const Object *p_object);
+ void remove_exception_rid(const RID &p_rid);
+ void remove_exception(const Object *p_object);
void clear_exceptions();
RayCast();
diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp
index db18e70ae1..90dbd51272 100644
--- a/scene/3d/reflection_probe.cpp
+++ b/scene/3d/reflection_probe.cpp
@@ -28,129 +28,119 @@
/*************************************************************************/
#include "reflection_probe.h"
-
void ReflectionProbe::set_intensity(float p_intensity) {
- intensity=p_intensity;
- VS::get_singleton()->reflection_probe_set_intensity(probe,p_intensity);
+ intensity = p_intensity;
+ VS::get_singleton()->reflection_probe_set_intensity(probe, p_intensity);
}
-float ReflectionProbe::get_intensity() const{
+float ReflectionProbe::get_intensity() const {
return intensity;
}
-
void ReflectionProbe::set_interior_ambient(Color p_ambient) {
- interior_ambient=p_ambient;
- VS::get_singleton()->reflection_probe_set_interior_ambient(probe,p_ambient);
+ interior_ambient = p_ambient;
+ VS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient);
}
void ReflectionProbe::set_interior_ambient_energy(float p_energy) {
- interior_ambient_energy=p_energy;
- VS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe,p_energy);
+ interior_ambient_energy = p_energy;
+ VS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy);
}
-float ReflectionProbe::get_interior_ambient_energy() const{
+float ReflectionProbe::get_interior_ambient_energy() const {
return interior_ambient_energy;
}
-
-Color ReflectionProbe::get_interior_ambient() const{
+Color ReflectionProbe::get_interior_ambient() const {
return interior_ambient;
}
void ReflectionProbe::set_interior_ambient_probe_contribution(float p_contribution) {
- interior_ambient_probe_contribution=p_contribution;
- VS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe,p_contribution);
+ interior_ambient_probe_contribution = p_contribution;
+ VS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution);
}
-float ReflectionProbe::get_interior_ambient_probe_contribution() const{
+float ReflectionProbe::get_interior_ambient_probe_contribution() const {
return interior_ambient_probe_contribution;
}
+void ReflectionProbe::set_max_distance(float p_distance) {
-void ReflectionProbe::set_max_distance(float p_distance){
-
- max_distance=p_distance;
- VS::get_singleton()->reflection_probe_set_max_distance(probe,p_distance);
+ max_distance = p_distance;
+ VS::get_singleton()->reflection_probe_set_max_distance(probe, p_distance);
}
-float ReflectionProbe::get_max_distance() const{
+float ReflectionProbe::get_max_distance() const {
return max_distance;
}
+void ReflectionProbe::set_extents(const Vector3 &p_extents) {
-void ReflectionProbe::set_extents(const Vector3& p_extents){
+ extents = p_extents;
- extents=p_extents;
-
- for(int i=0;i<3;i++) {
- if (extents[i]<0.01) {
- extents[i]=0.01;
+ for (int i = 0; i < 3; i++) {
+ if (extents[i] < 0.01) {
+ extents[i] = 0.01;
}
- if (extents[i]-0.01<ABS(origin_offset[i])) {
- origin_offset[i]=SGN(origin_offset[i])*(extents[i]-0.01);
+ if (extents[i] - 0.01 < ABS(origin_offset[i])) {
+ origin_offset[i] = SGN(origin_offset[i]) * (extents[i] - 0.01);
_change_notify("origin_offset");
}
}
- VS::get_singleton()->reflection_probe_set_extents(probe,extents);
- VS::get_singleton()->reflection_probe_set_origin_offset(probe,origin_offset);
+ VS::get_singleton()->reflection_probe_set_extents(probe, extents);
+ VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
_change_notify("extents");
update_gizmo();
-
}
-Vector3 ReflectionProbe::get_extents() const{
+Vector3 ReflectionProbe::get_extents() const {
return extents;
}
-void ReflectionProbe::set_origin_offset(const Vector3& p_extents){
+void ReflectionProbe::set_origin_offset(const Vector3 &p_extents) {
- origin_offset=p_extents;
+ origin_offset = p_extents;
- for(int i=0;i<3;i++) {
-
- if (extents[i]-0.01<ABS(origin_offset[i])) {
- origin_offset[i]=SGN(origin_offset[i])*(extents[i]-0.01);
+ for (int i = 0; i < 3; i++) {
+ if (extents[i] - 0.01 < ABS(origin_offset[i])) {
+ origin_offset[i] = SGN(origin_offset[i]) * (extents[i] - 0.01);
}
}
- VS::get_singleton()->reflection_probe_set_extents(probe,extents);
- VS::get_singleton()->reflection_probe_set_origin_offset(probe,origin_offset);
+ VS::get_singleton()->reflection_probe_set_extents(probe, extents);
+ VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
_change_notify("origin_offset");
update_gizmo();
}
-Vector3 ReflectionProbe::get_origin_offset() const{
+Vector3 ReflectionProbe::get_origin_offset() const {
return origin_offset;
}
-void ReflectionProbe::set_enable_box_projection(bool p_enable){
-
- box_projection=p_enable;
- VS::get_singleton()->reflection_probe_set_enable_box_projection(probe,p_enable);
+void ReflectionProbe::set_enable_box_projection(bool p_enable) {
+ box_projection = p_enable;
+ VS::get_singleton()->reflection_probe_set_enable_box_projection(probe, p_enable);
}
-bool ReflectionProbe::is_box_projection_enabled() const{
+bool ReflectionProbe::is_box_projection_enabled() const {
return box_projection;
}
-
void ReflectionProbe::set_as_interior(bool p_enable) {
- interior=p_enable;
- VS::get_singleton()->reflection_probe_set_as_interior(probe,interior);
+ interior = p_enable;
+ VS::get_singleton()->reflection_probe_set_as_interior(probe, interior);
_change_notify();
-
}
bool ReflectionProbe::is_set_as_interior() const {
@@ -158,12 +148,10 @@ bool ReflectionProbe::is_set_as_interior() const {
return interior;
}
-
-
void ReflectionProbe::set_enable_shadows(bool p_enable) {
- enable_shadows=p_enable;
- VS::get_singleton()->reflection_probe_set_enable_shadows(probe,p_enable);
+ enable_shadows = p_enable;
+ VS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_enable);
}
bool ReflectionProbe::are_shadows_enabled() const {
@@ -172,8 +160,8 @@ bool ReflectionProbe::are_shadows_enabled() const {
void ReflectionProbe::set_cull_mask(uint32_t p_layers) {
- cull_mask=p_layers;
- VS::get_singleton()->reflection_probe_set_enable_shadows(probe,p_layers);
+ cull_mask = p_layers;
+ VS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_layers);
}
uint32_t ReflectionProbe::get_cull_mask() const {
@@ -181,20 +169,19 @@ uint32_t ReflectionProbe::get_cull_mask() const {
}
void ReflectionProbe::set_update_mode(UpdateMode p_mode) {
- update_mode=p_mode;
- VS::get_singleton()->reflection_probe_set_update_mode(probe,VS::ReflectionProbeUpdateMode(p_mode));
+ update_mode = p_mode;
+ VS::get_singleton()->reflection_probe_set_update_mode(probe, VS::ReflectionProbeUpdateMode(p_mode));
}
ReflectionProbe::UpdateMode ReflectionProbe::get_update_mode() const {
return update_mode;
}
-
Rect3 ReflectionProbe::get_aabb() const {
Rect3 aabb;
- aabb.pos=-origin_offset;
- aabb.size=origin_offset+extents;
+ aabb.pos = -origin_offset;
+ aabb.size = origin_offset + extents;
return aabb;
}
PoolVector<Face3> ReflectionProbe::get_faces(uint32_t p_usage_flags) const {
@@ -202,92 +189,89 @@ PoolVector<Face3> ReflectionProbe::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
}
-void ReflectionProbe::_validate_property(PropertyInfo& property) const {
+void ReflectionProbe::_validate_property(PropertyInfo &property) const {
- if (property.name=="interior/ambient_color" || property.name=="interior/ambient_energy" || property.name=="interior/ambient_contrib") {
+ if (property.name == "interior/ambient_color" || property.name == "interior/ambient_energy" || property.name == "interior/ambient_contrib") {
if (!interior) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
+ property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
}
void ReflectionProbe::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_intensity","intensity"),&ReflectionProbe::set_intensity);
- ClassDB::bind_method(D_METHOD("get_intensity"),&ReflectionProbe::get_intensity);
-
- ClassDB::bind_method(D_METHOD("set_interior_ambient","ambient"),&ReflectionProbe::set_interior_ambient);
- ClassDB::bind_method(D_METHOD("get_interior_ambient"),&ReflectionProbe::get_interior_ambient);
-
- ClassDB::bind_method(D_METHOD("set_interior_ambient_energy","ambient_energy"),&ReflectionProbe::set_interior_ambient_energy);
- ClassDB::bind_method(D_METHOD("get_interior_ambient_energy"),&ReflectionProbe::get_interior_ambient_energy);
-
- ClassDB::bind_method(D_METHOD("set_interior_ambient_probe_contribution","ambient_probe_contribution"),&ReflectionProbe::set_interior_ambient_probe_contribution);
- ClassDB::bind_method(D_METHOD("get_interior_ambient_probe_contribution"),&ReflectionProbe::get_interior_ambient_probe_contribution);
+ ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &ReflectionProbe::set_intensity);
+ ClassDB::bind_method(D_METHOD("get_intensity"), &ReflectionProbe::get_intensity);
- ClassDB::bind_method(D_METHOD("set_max_distance","max_distance"),&ReflectionProbe::set_max_distance);
- ClassDB::bind_method(D_METHOD("get_max_distance"),&ReflectionProbe::get_max_distance);
+ ClassDB::bind_method(D_METHOD("set_interior_ambient", "ambient"), &ReflectionProbe::set_interior_ambient);
+ ClassDB::bind_method(D_METHOD("get_interior_ambient"), &ReflectionProbe::get_interior_ambient);
- ClassDB::bind_method(D_METHOD("set_extents","extents"),&ReflectionProbe::set_extents);
- ClassDB::bind_method(D_METHOD("get_extents"),&ReflectionProbe::get_extents);
+ ClassDB::bind_method(D_METHOD("set_interior_ambient_energy", "ambient_energy"), &ReflectionProbe::set_interior_ambient_energy);
+ ClassDB::bind_method(D_METHOD("get_interior_ambient_energy"), &ReflectionProbe::get_interior_ambient_energy);
- ClassDB::bind_method(D_METHOD("set_origin_offset","origin_offset"),&ReflectionProbe::set_origin_offset);
- ClassDB::bind_method(D_METHOD("get_origin_offset"),&ReflectionProbe::get_origin_offset);
+ ClassDB::bind_method(D_METHOD("set_interior_ambient_probe_contribution", "ambient_probe_contribution"), &ReflectionProbe::set_interior_ambient_probe_contribution);
+ ClassDB::bind_method(D_METHOD("get_interior_ambient_probe_contribution"), &ReflectionProbe::get_interior_ambient_probe_contribution);
- ClassDB::bind_method(D_METHOD("set_as_interior","enable"),&ReflectionProbe::set_as_interior);
- ClassDB::bind_method(D_METHOD("is_set_as_interior"),&ReflectionProbe::is_set_as_interior);
+ ClassDB::bind_method(D_METHOD("set_max_distance", "max_distance"), &ReflectionProbe::set_max_distance);
+ ClassDB::bind_method(D_METHOD("get_max_distance"), &ReflectionProbe::get_max_distance);
- ClassDB::bind_method(D_METHOD("set_enable_box_projection","enable"),&ReflectionProbe::set_enable_box_projection);
- ClassDB::bind_method(D_METHOD("is_box_projection_enabled"),&ReflectionProbe::is_box_projection_enabled);
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &ReflectionProbe::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &ReflectionProbe::get_extents);
+ ClassDB::bind_method(D_METHOD("set_origin_offset", "origin_offset"), &ReflectionProbe::set_origin_offset);
+ ClassDB::bind_method(D_METHOD("get_origin_offset"), &ReflectionProbe::get_origin_offset);
- ClassDB::bind_method(D_METHOD("set_enable_shadows","enable"),&ReflectionProbe::set_enable_shadows);
- ClassDB::bind_method(D_METHOD("are_shadows_enabled"),&ReflectionProbe::are_shadows_enabled);
+ ClassDB::bind_method(D_METHOD("set_as_interior", "enable"), &ReflectionProbe::set_as_interior);
+ ClassDB::bind_method(D_METHOD("is_set_as_interior"), &ReflectionProbe::is_set_as_interior);
- ClassDB::bind_method(D_METHOD("set_cull_mask","layers"),&ReflectionProbe::set_cull_mask);
- ClassDB::bind_method(D_METHOD("get_cull_mask"),&ReflectionProbe::get_cull_mask);
+ ClassDB::bind_method(D_METHOD("set_enable_box_projection", "enable"), &ReflectionProbe::set_enable_box_projection);
+ ClassDB::bind_method(D_METHOD("is_box_projection_enabled"), &ReflectionProbe::is_box_projection_enabled);
- ClassDB::bind_method(D_METHOD("set_update_mode","mode"),&ReflectionProbe::set_update_mode);
- ClassDB::bind_method(D_METHOD("get_update_mode"),&ReflectionProbe::get_update_mode);
+ ClassDB::bind_method(D_METHOD("set_enable_shadows", "enable"), &ReflectionProbe::set_enable_shadows);
+ ClassDB::bind_method(D_METHOD("are_shadows_enabled"), &ReflectionProbe::are_shadows_enabled);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"update_mode",PROPERTY_HINT_ENUM,"Once,Always"),"set_update_mode","get_update_mode");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"intensity",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_intensity","get_intensity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"max_distance",PROPERTY_HINT_RANGE,"0,16384,0.1"),"set_max_distance","get_max_distance");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"extents"),"set_extents","get_extents");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"origin_offset"),"set_origin_offset","get_origin_offset");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"box_projection"),"set_enable_box_projection","is_box_projection_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enable_shadows"),"set_enable_shadows","are_shadows_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cull_mask",PROPERTY_HINT_LAYERS_3D_RENDER),"set_cull_mask","get_cull_mask");
+ ClassDB::bind_method(D_METHOD("set_cull_mask", "layers"), &ReflectionProbe::set_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_cull_mask"), &ReflectionProbe::get_cull_mask);
- ADD_GROUP("Interior","interior_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"interior_enable"),"set_as_interior","is_set_as_interior");
- ADD_PROPERTY( PropertyInfo(Variant::COLOR,"interior_ambient_color",PROPERTY_HINT_COLOR_NO_ALPHA),"set_interior_ambient","get_interior_ambient");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"interior_ambient_energy",PROPERTY_HINT_RANGE,"0,16,0.01"),"set_interior_ambient_energy","get_interior_ambient_energy");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"interior_ambient_contrib",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_interior_ambient_probe_contribution","get_interior_ambient_probe_contribution");
+ ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &ReflectionProbe::set_update_mode);
+ ClassDB::bind_method(D_METHOD("get_update_mode"), &ReflectionProbe::get_update_mode);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Once,Always"), "set_update_mode", "get_update_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "intensity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_intensity", "get_intensity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,16384,0.1"), "set_max_distance", "get_max_distance");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "extents"), "set_extents", "get_extents");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "origin_offset"), "set_origin_offset", "get_origin_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "box_projection"), "set_enable_box_projection", "is_box_projection_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_shadows"), "set_enable_shadows", "are_shadows_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
- BIND_CONSTANT( UPDATE_ONCE );
- BIND_CONSTANT( UPDATE_ALWAYS );
+ ADD_GROUP("Interior", "interior_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior_enable"), "set_as_interior", "is_set_as_interior");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "interior_ambient_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_interior_ambient", "get_interior_ambient");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "interior_ambient_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_interior_ambient_energy", "get_interior_ambient_energy");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "interior_ambient_contrib", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_interior_ambient_probe_contribution", "get_interior_ambient_probe_contribution");
+ BIND_CONSTANT(UPDATE_ONCE);
+ BIND_CONSTANT(UPDATE_ALWAYS);
}
ReflectionProbe::ReflectionProbe() {
- intensity=1.0;
- interior_ambient=Color(0,0,0);
- interior_ambient_probe_contribution=0;
- interior_ambient_energy=1.0;
- max_distance=0;
- extents=Vector3(1,1,1);
- origin_offset=Vector3(0,0,0);
- box_projection=false;
- interior=false;
- enable_shadows=false;
- cull_mask=(1<<20)-1;
- update_mode=UPDATE_ONCE;
-
- probe=VisualServer::get_singleton()->reflection_probe_create();
- VS::get_singleton()->instance_set_base(get_instance(),probe);
+ intensity = 1.0;
+ interior_ambient = Color(0, 0, 0);
+ interior_ambient_probe_contribution = 0;
+ interior_ambient_energy = 1.0;
+ max_distance = 0;
+ extents = Vector3(1, 1, 1);
+ origin_offset = Vector3(0, 0, 0);
+ box_projection = false;
+ interior = false;
+ enable_shadows = false;
+ cull_mask = (1 << 20) - 1;
+ update_mode = UPDATE_ONCE;
+
+ probe = VisualServer::get_singleton()->reflection_probe_create();
+ VS::get_singleton()->instance_set_base(get_instance(), probe);
}
ReflectionProbe::~ReflectionProbe() {
diff --git a/scene/3d/reflection_probe.h b/scene/3d/reflection_probe.h
index cfda186d87..a2e4a18d68 100644
--- a/scene/3d/reflection_probe.h
+++ b/scene/3d/reflection_probe.h
@@ -30,23 +30,20 @@
#define REFLECTIONPROBE_H
#include "scene/3d/visual_instance.h"
-#include "scene/resources/texture.h"
#include "scene/resources/sky_box.h"
+#include "scene/resources/texture.h"
#include "servers/visual_server.h"
class ReflectionProbe : public VisualInstance {
- GDCLASS(ReflectionProbe,VisualInstance);
+ GDCLASS(ReflectionProbe, VisualInstance);
public:
-
enum UpdateMode {
UPDATE_ONCE,
UPDATE_ALWAYS,
};
-
private:
-
RID probe;
float intensity;
float max_distance;
@@ -63,12 +60,10 @@ private:
UpdateMode update_mode;
protected:
-
static void _bind_methods();
- void _validate_property(PropertyInfo& property) const;
+ void _validate_property(PropertyInfo &property) const;
public:
-
void set_intensity(float p_intensity);
float get_intensity() const;
@@ -84,10 +79,10 @@ public:
void set_max_distance(float p_distance);
float get_max_distance() const;
- void set_extents(const Vector3& p_extents);
+ void set_extents(const Vector3 &p_extents);
Vector3 get_extents() const;
- void set_origin_offset(const Vector3& p_extents);
+ void set_origin_offset(const Vector3 &p_extents);
Vector3 get_origin_offset() const;
void set_as_interior(bool p_enable);
@@ -108,13 +103,10 @@ public:
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
-
-
ReflectionProbe();
~ReflectionProbe();
};
-
-VARIANT_ENUM_CAST( ReflectionProbe::UpdateMode );
+VARIANT_ENUM_CAST(ReflectionProbe::UpdateMode);
#endif // REFLECTIONPROBE_H
diff --git a/scene/3d/remote_transform.cpp b/scene/3d/remote_transform.cpp
index 21ec65f5e0..202206dd02 100644
--- a/scene/3d/remote_transform.cpp
+++ b/scene/3d/remote_transform.cpp
@@ -31,20 +31,19 @@
#include "remote_transform.h"
void RemoteTransform::_update_cache() {
- cache=0;
+ cache = 0;
if (has_node(remote_node)) {
Node *node = get_node(remote_node);
- if (!node || this==node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) {
+ if (!node || this == node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) {
return;
}
- cache=node->get_instance_ID();
+ cache = node->get_instance_ID();
}
}
void RemoteTransform::_update_remote() {
-
if (!is_inside_tree())
return;
@@ -64,12 +63,11 @@ void RemoteTransform::_update_remote() {
//todo make faster
n->set_global_transform(get_global_transform());
-
}
void RemoteTransform::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_READY: {
@@ -83,30 +81,26 @@ void RemoteTransform::_notification(int p_what) {
if (cache) {
_update_remote();
-
}
} break;
-
}
}
+void RemoteTransform::set_remote_node(const NodePath &p_remote_node) {
-void RemoteTransform::set_remote_node(const NodePath& p_remote_node) {
-
- remote_node=p_remote_node;
+ remote_node = p_remote_node;
if (is_inside_tree())
_update_cache();
update_configuration_warning();
}
-NodePath RemoteTransform::get_remote_node() const{
+NodePath RemoteTransform::get_remote_node() const {
return remote_node;
}
-
String RemoteTransform::get_configuration_warning() const {
if (!has_node(remote_node) || !get_node(remote_node) || !get_node(remote_node)->cast_to<Spatial>()) {
@@ -118,16 +112,14 @@ String RemoteTransform::get_configuration_warning() const {
void RemoteTransform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_remote_node","path"),&RemoteTransform::set_remote_node);
- ClassDB::bind_method(D_METHOD("get_remote_node"),&RemoteTransform::get_remote_node);
+ ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform::set_remote_node);
+ ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform::get_remote_node);
- ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"remote_path"),"set_remote_node","get_remote_node");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "remote_path"), "set_remote_node", "get_remote_node");
}
RemoteTransform::RemoteTransform() {
- cache=0;
+ cache = 0;
set_notify_transform(true);
-
}
-
diff --git a/scene/3d/remote_transform.h b/scene/3d/remote_transform.h
index 6bc4763e2d..fdfd959a96 100644
--- a/scene/3d/remote_transform.h
+++ b/scene/3d/remote_transform.h
@@ -31,28 +31,27 @@
#include "scene/3d/spatial.h"
-class RemoteTransform : public Spatial
-{
- GDCLASS(RemoteTransform,Spatial);
-
+class RemoteTransform : public Spatial {
+ GDCLASS(RemoteTransform, Spatial);
+
NodePath remote_node;
ObjectID cache;
void _update_remote();
- void _update_cache();
-
+ void _update_cache();
+
protected:
static void _bind_methods();
void _notification(int p_what);
+
public:
- void set_remote_node(const NodePath& p_remote_node);
+ void set_remote_node(const NodePath &p_remote_node);
NodePath get_remote_node() const;
-
+
virtual String get_configuration_warning() const;
-
- RemoteTransform();
+ RemoteTransform();
};
#endif // REMOTETRANSFORM_H
diff --git a/scene/3d/room_instance.cpp b/scene/3d/room_instance.cpp
index b363c05ef7..3b6ae32d16 100644
--- a/scene/3d/room_instance.cpp
+++ b/scene/3d/room_instance.cpp
@@ -34,44 +34,35 @@
#include "global_config.h"
#include "scene/resources/surface_tool.h"
-
void Room::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
// go find parent level
- Node *parent_room=get_parent();
- level=0;
+ Node *parent_room = get_parent();
+ level = 0;
- while(parent_room) {
+ while (parent_room) {
Room *r = parent_room->cast_to<Room>();
if (r) {
- level=r->level+1;
+ level = r->level + 1;
break;
}
- parent_room=parent_room->get_parent();
+ parent_room = parent_room->get_parent();
}
-
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
} break;
case NOTIFICATION_EXIT_WORLD: {
-
-
- } break;
+ } break;
}
-
}
-
-
-
-
Rect3 Room::get_aabb() const {
if (room.is_null())
@@ -83,12 +74,11 @@ Rect3 Room::get_aabb() const {
PoolVector<Face3> Room::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
-
}
-void Room::set_room( const Ref<RoomBounds>& p_room ) {
+void Room::set_room(const Ref<RoomBounds> &p_room) {
- room=p_room;
+ room = p_room;
update_gizmo();
if (room.is_valid()) {
@@ -101,11 +91,8 @@ void Room::set_room( const Ref<RoomBounds>& p_room ) {
if (!is_inside_tree())
return;
-
propagate_notification(NOTIFICATION_AREA_CHANGED);
update_gizmo();
-
-
}
Ref<RoomBounds> Room::get_room() const {
@@ -113,75 +100,60 @@ Ref<RoomBounds> Room::get_room() const {
return room;
}
-void Room::_parse_node_faces(PoolVector<Face3> &all_faces,const Node *p_node) const {
+void Room::_parse_node_faces(PoolVector<Face3> &all_faces, const Node *p_node) const {
- const VisualInstance *vi=p_node->cast_to<VisualInstance>();
+ const VisualInstance *vi = p_node->cast_to<VisualInstance>();
if (vi) {
- PoolVector<Face3> faces=vi->get_faces(FACES_ENCLOSING);
+ PoolVector<Face3> faces = vi->get_faces(FACES_ENCLOSING);
if (faces.size()) {
- int old_len=all_faces.size();
- all_faces.resize( all_faces.size() + faces.size() );
- int new_len=all_faces.size();
- PoolVector<Face3>::Write all_facesw=all_faces.write();
- Face3 * all_facesptr=all_facesw.ptr();
+ int old_len = all_faces.size();
+ all_faces.resize(all_faces.size() + faces.size());
+ int new_len = all_faces.size();
+ PoolVector<Face3>::Write all_facesw = all_faces.write();
+ Face3 *all_facesptr = all_facesw.ptr();
- PoolVector<Face3>::Read facesr=faces.read();
- const Face3 * facesptr=facesr.ptr();
+ PoolVector<Face3>::Read facesr = faces.read();
+ const Face3 *facesptr = facesr.ptr();
- Transform tr=vi->get_relative_transform(this);
+ Transform tr = vi->get_relative_transform(this);
- for(int i=old_len;i<new_len;i++) {
+ for (int i = old_len; i < new_len; i++) {
- Face3 f=facesptr[i-old_len];
- for (int j=0;j<3;j++)
- f.vertex[j]=tr.xform(f.vertex[j]);
- all_facesptr[i]=f;
+ Face3 f = facesptr[i - old_len];
+ for (int j = 0; j < 3; j++)
+ f.vertex[j] = tr.xform(f.vertex[j]);
+ all_facesptr[i] = f;
}
}
}
+ for (int i = 0; i < p_node->get_child_count(); i++) {
- for (int i=0;i<p_node->get_child_count();i++) {
-
- _parse_node_faces(all_faces,p_node->get_child(i));
+ _parse_node_faces(all_faces, p_node->get_child(i));
}
-
}
-
-
void Room::_bounds_changed() {
update_gizmo();
}
-
-
void Room::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_room","room:Room"),&Room::set_room );
- ClassDB::bind_method(D_METHOD("get_room:Room"),&Room::get_room );
-
-
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "room/room", PROPERTY_HINT_RESOURCE_TYPE, "Area" ), "set_room", "get_room") ;
+ ClassDB::bind_method(D_METHOD("set_room", "room:Room"), &Room::set_room);
+ ClassDB::bind_method(D_METHOD("get_room:Room"), &Room::get_room);
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "room/room", PROPERTY_HINT_RESOURCE_TYPE, "Area"), "set_room", "get_room");
}
-
Room::Room() {
-// sound_enabled=false;
-
- level=0;
-
+ // sound_enabled=false;
+ level = 0;
}
-
Room::~Room() {
-
-
}
-
diff --git a/scene/3d/room_instance.h b/scene/3d/room_instance.h
index cbc1b12b7e..68be5eecf2 100644
--- a/scene/3d/room_instance.h
+++ b/scene/3d/room_instance.h
@@ -36,7 +36,6 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
/* RoomInstance Logic:
a) Instances that belong to the room are drawn only if the room is visible (seen through portal, or player inside)
b) Instances that don't belong to any room are considered to belong to the root room (RID empty)
@@ -44,52 +43,38 @@
*/
-
-
-
class Room : public VisualInstance {
- GDCLASS( Room, VisualInstance );
-public:
-
-
-
+ GDCLASS(Room, VisualInstance);
+public:
private:
Ref<RoomBounds> room;
-
int level;
- void _parse_node_faces(PoolVector<Face3> &all_faces,const Node *p_node) const;
-
+ void _parse_node_faces(PoolVector<Face3> &all_faces, const Node *p_node) const;
void _bounds_changed();
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
public:
-
enum {
// used to notify portals that the room in which they are has changed.
- NOTIFICATION_AREA_CHANGED=60
+ NOTIFICATION_AREA_CHANGED = 60
};
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
- void set_room( const Ref<RoomBounds>& p_room );
+ void set_room(const Ref<RoomBounds> &p_room);
Ref<RoomBounds> get_room() const;
-
Room();
~Room();
-
};
-
#endif // ROOM_INSTANCE_H
diff --git a/scene/3d/scenario_fx.cpp b/scene/3d/scenario_fx.cpp
index 145242ba7c..92ee608f73 100644
--- a/scene/3d/scenario_fx.cpp
+++ b/scene/3d/scenario_fx.cpp
@@ -28,49 +28,42 @@
/*************************************************************************/
#include "scenario_fx.h"
-
-
void WorldEnvironment::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_WORLD) {
+ if (p_what == NOTIFICATION_ENTER_WORLD) {
if (environment.is_valid()) {
if (get_world()->get_environment().is_valid()) {
WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding.");
}
get_world()->set_environment(environment);
- add_to_group("_world_environment_"+itos(get_world()->get_scenario().get_id()));
-
+ add_to_group("_world_environment_" + itos(get_world()->get_scenario().get_id()));
}
- } else if (p_what==NOTIFICATION_EXIT_WORLD) {
+ } else if (p_what == NOTIFICATION_EXIT_WORLD) {
- if (environment.is_valid() && get_world()->get_environment()==environment) {
+ if (environment.is_valid() && get_world()->get_environment() == environment) {
get_world()->set_environment(Ref<Environment>());
- remove_from_group("_world_environment_"+itos(get_world()->get_scenario().get_id()));
-
+ remove_from_group("_world_environment_" + itos(get_world()->get_scenario().get_id()));
}
}
}
-void WorldEnvironment::set_environment(const Ref<Environment>& p_environment) {
+void WorldEnvironment::set_environment(const Ref<Environment> &p_environment) {
- if (is_inside_world() && environment.is_valid() && get_world()->get_environment()==environment) {
+ if (is_inside_world() && environment.is_valid() && get_world()->get_environment() == environment) {
get_world()->set_environment(Ref<Environment>());
- remove_from_group("_world_environment_"+itos(get_world()->get_scenario().get_id()));
+ remove_from_group("_world_environment_" + itos(get_world()->get_scenario().get_id()));
//clean up
}
-
- environment=p_environment;
+ environment = p_environment;
if (is_inside_world() && environment.is_valid()) {
if (get_world()->get_environment().is_valid()) {
WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding.");
}
get_world()->set_environment(environment);
- add_to_group("_world_environment_"+itos(get_world()->get_scenario().get_id()));
-
+ add_to_group("_world_environment_" + itos(get_world()->get_scenario().get_id()));
}
update_configuration_warning();
@@ -86,29 +79,22 @@ String WorldEnvironment::get_configuration_warning() const {
if (!is_visible_in_tree() || !is_inside_tree() || !environment.is_valid())
return String();
- List<Node*> nodes;
- get_tree()->get_nodes_in_group("_world_environment_"+itos(get_world()->get_scenario().get_id()),&nodes);
+ List<Node *> nodes;
+ get_tree()->get_nodes_in_group("_world_environment_" + itos(get_world()->get_scenario().get_id()), &nodes);
- if (nodes.size()>1) {
+ if (nodes.size() > 1) {
return TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes).");
}
return String();
}
-
void WorldEnvironment::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_environment","env:Environment"),&WorldEnvironment::set_environment);
- ClassDB::bind_method(D_METHOD("get_environment:Environment"),&WorldEnvironment::get_environment);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment"),"set_environment","get_environment");
-
+ ClassDB::bind_method(D_METHOD("set_environment", "env:Environment"), &WorldEnvironment::set_environment);
+ ClassDB::bind_method(D_METHOD("get_environment:Environment"), &WorldEnvironment::get_environment);
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
}
-
WorldEnvironment::WorldEnvironment() {
-
-
}
-
-
diff --git a/scene/3d/scenario_fx.h b/scene/3d/scenario_fx.h
index ef5b70039c..bbdffdc131 100644
--- a/scene/3d/scenario_fx.h
+++ b/scene/3d/scenario_fx.h
@@ -31,30 +31,27 @@
#include "scene/3d/spatial.h"
-
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
class WorldEnvironment : public Spatial {
- GDCLASS(WorldEnvironment,Spatial );
+ GDCLASS(WorldEnvironment, Spatial);
Ref<Environment> environment;
protected:
-
void _notification(int p_what);
static void _bind_methods();
+
public:
- void set_environment(const Ref<Environment>& p_environment);
+ void set_environment(const Ref<Environment> &p_environment);
Ref<Environment> get_environment() const;
String get_configuration_warning() const;
WorldEnvironment();
-
};
#endif
diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp
index 04e82ba914..3a5453c8ef 100644
--- a/scene/3d/skeleton.cpp
+++ b/scene/3d/skeleton.cpp
@@ -30,50 +30,48 @@
#include "message_queue.h"
-#include "scene/resources/surface_tool.h"
#include "core/global_config.h"
+#include "scene/resources/surface_tool.h"
-
-bool Skeleton::_set(const StringName& p_path, const Variant& p_value) {
+bool Skeleton::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;
if (!path.begins_with("bones/"))
return false;
- int which=path.get_slicec('/',1).to_int();
- String what=path.get_slicec('/',2);
+ int which = path.get_slicec('/', 1).to_int();
+ String what = path.get_slicec('/', 2);
-
- if (which==bones.size() && what=="name") {
+ if (which == bones.size() && what == "name") {
add_bone(p_value);
return true;
}
- ERR_FAIL_INDEX_V( which, bones.size(), false );
+ ERR_FAIL_INDEX_V(which, bones.size(), false);
- if (what=="parent")
- set_bone_parent(which, p_value );
- else if (what=="rest")
+ if (what == "parent")
+ set_bone_parent(which, p_value);
+ else if (what == "rest")
set_bone_rest(which, p_value);
- else if (what=="enabled")
+ else if (what == "enabled")
set_bone_enabled(which, p_value);
- else if (what=="pose")
+ else if (what == "pose")
set_bone_pose(which, p_value);
- else if (what=="bound_childs") {
- Array children=p_value;
+ else if (what == "bound_childs") {
+ Array children = p_value;
if (is_inside_tree()) {
bones[which].nodes_bound.clear();
- for (int i=0;i<children.size();i++) {
+ for (int i = 0; i < children.size(); i++) {
- NodePath path=children[i];
- ERR_CONTINUE( path.operator String()=="" );
+ NodePath path = children[i];
+ ERR_CONTINUE(path.operator String() == "");
Node *node = get_node(path);
ERR_CONTINUE(!node);
- bind_child_node_to_bone(which,node);
+ bind_child_node_to_bone(which, node);
}
}
} else {
@@ -83,72 +81,70 @@ bool Skeleton::_set(const StringName& p_path, const Variant& p_value) {
return true;
}
-bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const {
+bool Skeleton::_get(const StringName &p_name, Variant &r_ret) const {
- String path=p_name;
+ String path = p_name;
if (!path.begins_with("bones/"))
return false;
- int which=path.get_slicec('/',1).to_int();
- String what=path.get_slicec('/',2);
-
- ERR_FAIL_INDEX_V( which, bones.size(), false );
-
- if (what=="name")
- r_ret=get_bone_name(which);
- else if (what=="parent")
- r_ret=get_bone_parent(which);
- else if (what=="rest")
- r_ret=get_bone_rest(which);
- else if (what=="enabled")
- r_ret=is_bone_enabled(which);
- else if (what=="pose")
- r_ret=get_bone_pose(which);
- else if (what=="bound_childs") {
+ int which = path.get_slicec('/', 1).to_int();
+ String what = path.get_slicec('/', 2);
+
+ ERR_FAIL_INDEX_V(which, bones.size(), false);
+
+ if (what == "name")
+ r_ret = get_bone_name(which);
+ else if (what == "parent")
+ r_ret = get_bone_parent(which);
+ else if (what == "rest")
+ r_ret = get_bone_rest(which);
+ else if (what == "enabled")
+ r_ret = is_bone_enabled(which);
+ else if (what == "pose")
+ r_ret = get_bone_pose(which);
+ else if (what == "bound_childs") {
Array children;
- for (const List<uint32_t>::Element *E=bones[which].nodes_bound.front();E;E=E->next()) {
+ for (const List<uint32_t>::Element *E = bones[which].nodes_bound.front(); E; E = E->next()) {
- Object *obj=ObjectDB::get_instance(E->get());
+ Object *obj = ObjectDB::get_instance(E->get());
ERR_CONTINUE(!obj);
- Node *node=obj->cast_to<Node>();
+ Node *node = obj->cast_to<Node>();
ERR_CONTINUE(!node);
- NodePath path=get_path_to(node);
+ NodePath path = get_path_to(node);
children.push_back(path);
-
}
- r_ret=children;
+ r_ret = children;
} else
return false;
return true;
-
}
-void Skeleton::_get_property_list( List<PropertyInfo>* p_list ) const {
+void Skeleton::_get_property_list(List<PropertyInfo> *p_list) const {
- for (int i=0;i<bones.size();i++) {
+ for (int i = 0; i < bones.size(); i++) {
- String prep="bones/"+itos(i)+"/";
- p_list->push_back( PropertyInfo( Variant::STRING, prep+"name" ) );
- p_list->push_back( PropertyInfo( Variant::INT, prep+"parent" , PROPERTY_HINT_RANGE,"-1,"+itos(i-1)+",1") );
- p_list->push_back( PropertyInfo( Variant::TRANSFORM, prep+"rest" ) );
- p_list->push_back( PropertyInfo( Variant::BOOL, prep+"enabled" ) );
- p_list->push_back( PropertyInfo( Variant::TRANSFORM, prep+"pose", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ) );
- p_list->push_back( PropertyInfo( Variant::ARRAY, prep+"bound_childs" ) );
+ String prep = "bones/" + itos(i) + "/";
+ p_list->push_back(PropertyInfo(Variant::STRING, prep + "name"));
+ p_list->push_back(PropertyInfo(Variant::INT, prep + "parent", PROPERTY_HINT_RANGE, "-1," + itos(i - 1) + ",1"));
+ p_list->push_back(PropertyInfo(Variant::TRANSFORM, prep + "rest"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, prep + "enabled"));
+ p_list->push_back(PropertyInfo(Variant::TRANSFORM, prep + "pose", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
+ p_list->push_back(PropertyInfo(Variant::ARRAY, prep + "bound_childs"));
}
}
void Skeleton::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
if (dirty) {
- dirty=false;
+ dirty = false;
_make_dirty(); // property make it dirty
}
@@ -158,97 +154,95 @@ void Skeleton::_notification(int p_what) {
} break;
case NOTIFICATION_UPDATE_SKELETON: {
+ VisualServer *vs = VisualServer::get_singleton();
+ Bone *bonesptr = &bones[0];
+ int len = bones.size();
- VisualServer *vs=VisualServer::get_singleton();
- Bone *bonesptr=&bones[0];
- int len=bones.size();
-
- vs->skeleton_allocate( skeleton, len ); // if same size, nothin really happens
+ vs->skeleton_allocate(skeleton, len); // if same size, nothin really happens
// pose changed, rebuild cache of inverses
if (rest_global_inverse_dirty) {
// calculate global rests and invert them
- for (int i=0;i<len;i++) {
- Bone &b=bonesptr[i];
- if (b.parent>=0)
- b.rest_global_inverse=bonesptr[b.parent].rest_global_inverse * b.rest;
+ for (int i = 0; i < len; i++) {
+ Bone &b = bonesptr[i];
+ if (b.parent >= 0)
+ b.rest_global_inverse = bonesptr[b.parent].rest_global_inverse * b.rest;
else
- b.rest_global_inverse=b.rest;
+ b.rest_global_inverse = b.rest;
}
- for (int i=0;i<len;i++) {
- Bone &b=bonesptr[i];
+ for (int i = 0; i < len; i++) {
+ Bone &b = bonesptr[i];
b.rest_global_inverse.affine_invert();
}
- rest_global_inverse_dirty=false;
-
+ rest_global_inverse_dirty = false;
}
- for (int i=0;i<len;i++) {
+ for (int i = 0; i < len; i++) {
- Bone &b=bonesptr[i];
+ Bone &b = bonesptr[i];
if (b.disable_rest) {
if (b.enabled) {
- Transform pose=b.pose;
+ Transform pose = b.pose;
if (b.custom_pose_enable) {
pose = b.custom_pose * pose;
}
- if (b.parent>=0) {
+ if (b.parent >= 0) {
- b.pose_global=bonesptr[b.parent].pose_global * pose;
+ b.pose_global = bonesptr[b.parent].pose_global * pose;
} else {
- b.pose_global=pose;
+ b.pose_global = pose;
}
} else {
- if (b.parent>=0) {
+ if (b.parent >= 0) {
- b.pose_global=bonesptr[b.parent].pose_global;
+ b.pose_global = bonesptr[b.parent].pose_global;
} else {
- b.pose_global=Transform();
+ b.pose_global = Transform();
}
}
} else {
if (b.enabled) {
- Transform pose=b.pose;
+ Transform pose = b.pose;
if (b.custom_pose_enable) {
pose = b.custom_pose * pose;
}
- if (b.parent>=0) {
+ if (b.parent >= 0) {
- b.pose_global=bonesptr[b.parent].pose_global * (b.rest * pose);
+ b.pose_global = bonesptr[b.parent].pose_global * (b.rest * pose);
} else {
- b.pose_global=b.rest * pose;
+ b.pose_global = b.rest * pose;
}
} else {
- if (b.parent>=0) {
+ if (b.parent >= 0) {
- b.pose_global=bonesptr[b.parent].pose_global * b.rest;
+ b.pose_global = bonesptr[b.parent].pose_global * b.rest;
} else {
- b.pose_global=b.rest;
+ b.pose_global = b.rest;
}
}
}
- vs->skeleton_bone_set_transform( skeleton, i, b.pose_global * b.rest_global_inverse );
+ vs->skeleton_bone_set_transform(skeleton, i, b.pose_global * b.rest_global_inverse);
- for(List<uint32_t>::Element *E=b.nodes_bound.front();E;E=E->next()) {
+ for (List<uint32_t>::Element *E = b.nodes_bound.front(); E; E = E->next()) {
- Object *obj=ObjectDB::get_instance(E->get());
+ Object *obj = ObjectDB::get_instance(E->get());
ERR_CONTINUE(!obj);
Spatial *sp = obj->cast_to<Spatial>();
ERR_CONTINUE(!sp);
@@ -256,38 +250,35 @@ void Skeleton::_notification(int p_what) {
}
}
- dirty=false;
+ dirty = false;
} break;
}
}
Transform Skeleton::get_bone_transform(int p_bone) const {
- ERR_FAIL_INDEX_V(p_bone,bones.size(),Transform());
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform());
if (dirty)
- const_cast<Skeleton*>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
+ const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
return bones[p_bone].pose_global * bones[p_bone].rest_global_inverse;
}
+void Skeleton::set_bone_global_pose(int p_bone, const Transform &p_pose) {
-void Skeleton::set_bone_global_pose(int p_bone,const Transform& p_pose) {
+ ERR_FAIL_INDEX(p_bone, bones.size());
+ if (bones[p_bone].parent == -1) {
- ERR_FAIL_INDEX(p_bone,bones.size());
- if (bones[p_bone].parent==-1) {
-
- set_bone_pose(p_bone,bones[p_bone].rest_global_inverse * p_pose); //fast
+ set_bone_pose(p_bone, bones[p_bone].rest_global_inverse * p_pose); //fast
} else {
set_bone_pose(p_bone, bones[p_bone].rest.affine_inverse() * (get_bone_global_pose(bones[p_bone].parent).affine_inverse() * p_pose)); //slow
-
}
-
}
Transform Skeleton::get_bone_global_pose(int p_bone) const {
- ERR_FAIL_INDEX_V(p_bone,bones.size(),Transform());
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform());
if (dirty)
- const_cast<Skeleton*>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
+ const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
return bones[p_bone].pose_global;
}
@@ -297,28 +288,28 @@ RID Skeleton::get_skeleton() const {
}
// skeleton creation api
-void Skeleton::add_bone(const String& p_name) {
+void Skeleton::add_bone(const String &p_name) {
- ERR_FAIL_COND( p_name=="" || p_name.find(":")!=-1 || p_name.find("/")!=-1 );
+ ERR_FAIL_COND(p_name == "" || p_name.find(":") != -1 || p_name.find("/") != -1);
- for (int i=0;i<bones.size();i++) {
+ for (int i = 0; i < bones.size(); i++) {
- ERR_FAIL_COND( bones[i].name=="p_name");
+ ERR_FAIL_COND(bones[i].name == "p_name");
}
Bone b;
- b.name=p_name;
+ b.name = p_name;
bones.push_back(b);
- rest_global_inverse_dirty=true;
+ rest_global_inverse_dirty = true;
_make_dirty();
update_gizmo();
}
int Skeleton::find_bone(String p_name) const {
- for (int i=0;i<bones.size();i++) {
+ for (int i = 0; i < bones.size(); i++) {
- if (bones[i].name==p_name)
+ if (bones[i].name == p_name)
return i;
}
@@ -326,7 +317,7 @@ int Skeleton::find_bone(String p_name) const {
}
String Skeleton::get_bone_name(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), "" );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), "");
return bones[p_bone].name;
}
@@ -338,248 +329,222 @@ int Skeleton::get_bone_count() const {
void Skeleton::set_bone_parent(int p_bone, int p_parent) {
- ERR_FAIL_INDEX( p_bone, bones.size() );
- ERR_FAIL_COND( p_parent!=-1 && (p_parent<0 || p_parent>=p_bone));
+ ERR_FAIL_INDEX(p_bone, bones.size());
+ ERR_FAIL_COND(p_parent != -1 && (p_parent < 0 || p_parent >= p_bone));
- bones[p_bone].parent=p_parent;
- rest_global_inverse_dirty=true;
+ bones[p_bone].parent = p_parent;
+ rest_global_inverse_dirty = true;
_make_dirty();
}
void Skeleton::unparent_bone_and_rest(int p_bone) {
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
- int parent=bones[p_bone].parent;
- while(parent>=0) {
+ int parent = bones[p_bone].parent;
+ while (parent >= 0) {
bones[p_bone].rest = bones[parent].rest * bones[p_bone].rest;
- parent=bones[parent].parent;
+ parent = bones[parent].parent;
}
- bones[p_bone].parent=-1;
- bones[p_bone].rest_global_inverse=bones[p_bone].rest.affine_inverse(); //same thing
+ bones[p_bone].parent = -1;
+ bones[p_bone].rest_global_inverse = bones[p_bone].rest.affine_inverse(); //same thing
_make_dirty();
-
}
void Skeleton::set_bone_disable_rest(int p_bone, bool p_disable) {
- ERR_FAIL_INDEX( p_bone, bones.size() );
- bones[p_bone].disable_rest=p_disable;
-
+ ERR_FAIL_INDEX(p_bone, bones.size());
+ bones[p_bone].disable_rest = p_disable;
}
bool Skeleton::is_bone_rest_disabled(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), false );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), false);
return bones[p_bone].disable_rest;
}
-
int Skeleton::get_bone_parent(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), -1 );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), -1);
return bones[p_bone].parent;
}
-void Skeleton::set_bone_rest(int p_bone, const Transform& p_rest) {
+void Skeleton::set_bone_rest(int p_bone, const Transform &p_rest) {
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
- bones[p_bone].rest=p_rest;
- rest_global_inverse_dirty=true;
+ bones[p_bone].rest = p_rest;
+ rest_global_inverse_dirty = true;
_make_dirty();
-
}
Transform Skeleton::get_bone_rest(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), Transform() );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform());
return bones[p_bone].rest;
-
}
void Skeleton::set_bone_enabled(int p_bone, bool p_enabled) {
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
- bones[p_bone].enabled=p_enabled;
- rest_global_inverse_dirty=true;
+ bones[p_bone].enabled = p_enabled;
+ rest_global_inverse_dirty = true;
_make_dirty();
}
bool Skeleton::is_bone_enabled(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), false );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), false);
return bones[p_bone].enabled;
-
}
-void Skeleton::bind_child_node_to_bone(int p_bone,Node *p_node) {
+void Skeleton::bind_child_node_to_bone(int p_bone, Node *p_node) {
ERR_FAIL_NULL(p_node);
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
- uint32_t id=p_node->get_instance_ID();
+ uint32_t id = p_node->get_instance_ID();
- for (List<uint32_t>::Element *E=bones[p_bone].nodes_bound.front();E;E=E->next()) {
+ for (List<uint32_t>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) {
- if (E->get()==id)
+ if (E->get() == id)
return; // already here
}
bones[p_bone].nodes_bound.push_back(id);
-
}
-void Skeleton::unbind_child_node_from_bone(int p_bone,Node *p_node) {
+void Skeleton::unbind_child_node_from_bone(int p_bone, Node *p_node) {
ERR_FAIL_NULL(p_node);
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
- uint32_t id=p_node->get_instance_ID();
+ uint32_t id = p_node->get_instance_ID();
bones[p_bone].nodes_bound.erase(id);
-
}
-void Skeleton::get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const {
+void Skeleton::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const {
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
- for (const List<uint32_t>::Element *E=bones[p_bone].nodes_bound.front();E;E=E->next()) {
+ for (const List<uint32_t>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) {
- Object *obj=ObjectDB::get_instance(E->get());
+ Object *obj = ObjectDB::get_instance(E->get());
ERR_CONTINUE(!obj);
p_bound->push_back(obj->cast_to<Node>());
}
-
}
void Skeleton::clear_bones() {
bones.clear();
- rest_global_inverse_dirty=true;
+ rest_global_inverse_dirty = true;
_make_dirty();
}
// posing api
-void Skeleton::set_bone_pose(int p_bone, const Transform& p_pose) {
-
- ERR_FAIL_INDEX( p_bone, bones.size() );
- ERR_FAIL_COND( !is_inside_tree() );
+void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) {
+ ERR_FAIL_INDEX(p_bone, bones.size());
+ ERR_FAIL_COND(!is_inside_tree());
- bones[p_bone].pose=p_pose;
+ bones[p_bone].pose = p_pose;
_make_dirty();
}
Transform Skeleton::get_bone_pose(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), Transform() );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform());
return bones[p_bone].pose;
-
}
-void Skeleton::set_bone_custom_pose(int p_bone, const Transform& p_custom_pose) {
+void Skeleton::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) {
- ERR_FAIL_INDEX( p_bone, bones.size() );
+ ERR_FAIL_INDEX(p_bone, bones.size());
//ERR_FAIL_COND( !is_inside_scene() );
-
- bones[p_bone].custom_pose_enable=(p_custom_pose!=Transform());
- bones[p_bone].custom_pose=p_custom_pose;
+ bones[p_bone].custom_pose_enable = (p_custom_pose != Transform());
+ bones[p_bone].custom_pose = p_custom_pose;
_make_dirty();
}
Transform Skeleton::get_bone_custom_pose(int p_bone) const {
- ERR_FAIL_INDEX_V( p_bone, bones.size(), Transform() );
+ ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform());
return bones[p_bone].custom_pose;
-
}
-
void Skeleton::_make_dirty() {
if (dirty)
return;
if (!is_inside_tree()) {
- dirty=true;
+ dirty = true;
return;
}
- MessageQueue::get_singleton()->push_notification( this, NOTIFICATION_UPDATE_SKELETON );
- dirty=true;
+ MessageQueue::get_singleton()->push_notification(this, NOTIFICATION_UPDATE_SKELETON);
+ dirty = true;
}
-
-
void Skeleton::localize_rests() {
- for(int i=bones.size()-1;i>=0;i--) {
+ for (int i = bones.size() - 1; i >= 0; i--) {
- if (bones[i].parent>=0)
- set_bone_rest(i,bones[bones[i].parent].rest.affine_inverse() * bones[i].rest);
+ if (bones[i].parent >= 0)
+ set_bone_rest(i, bones[bones[i].parent].rest.affine_inverse() * bones[i].rest);
}
}
-
-
void Skeleton::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("add_bone", "name"), &Skeleton::add_bone);
+ ClassDB::bind_method(D_METHOD("find_bone", "name"), &Skeleton::find_bone);
+ ClassDB::bind_method(D_METHOD("get_bone_name", "bone_idx"), &Skeleton::get_bone_name);
+ ClassDB::bind_method(D_METHOD("get_bone_parent", "bone_idx"), &Skeleton::get_bone_parent);
+ ClassDB::bind_method(D_METHOD("set_bone_parent", "bone_idx", "parent_idx"), &Skeleton::set_bone_parent);
+ ClassDB::bind_method(D_METHOD("get_bone_count"), &Skeleton::get_bone_count);
- ClassDB::bind_method(D_METHOD("add_bone","name"),&Skeleton::add_bone);
- ClassDB::bind_method(D_METHOD("find_bone","name"),&Skeleton::find_bone);
- ClassDB::bind_method(D_METHOD("get_bone_name","bone_idx"),&Skeleton::get_bone_name);
-
- ClassDB::bind_method(D_METHOD("get_bone_parent","bone_idx"),&Skeleton::get_bone_parent);
- ClassDB::bind_method(D_METHOD("set_bone_parent","bone_idx","parent_idx"),&Skeleton::set_bone_parent);
-
- ClassDB::bind_method(D_METHOD("get_bone_count"),&Skeleton::get_bone_count);
+ ClassDB::bind_method(D_METHOD("unparent_bone_and_rest", "bone_idx"), &Skeleton::unparent_bone_and_rest);
- ClassDB::bind_method(D_METHOD("unparent_bone_and_rest","bone_idx"),&Skeleton::unparent_bone_and_rest);
+ ClassDB::bind_method(D_METHOD("get_bone_rest", "bone_idx"), &Skeleton::get_bone_rest);
+ ClassDB::bind_method(D_METHOD("set_bone_rest", "bone_idx", "rest"), &Skeleton::set_bone_rest);
- ClassDB::bind_method(D_METHOD("get_bone_rest","bone_idx"),&Skeleton::get_bone_rest);
- ClassDB::bind_method(D_METHOD("set_bone_rest","bone_idx","rest"),&Skeleton::set_bone_rest);
+ ClassDB::bind_method(D_METHOD("set_bone_disable_rest", "bone_idx", "disable"), &Skeleton::set_bone_disable_rest);
+ ClassDB::bind_method(D_METHOD("is_bone_rest_disabled", "bone_idx"), &Skeleton::is_bone_rest_disabled);
- ClassDB::bind_method(D_METHOD("set_bone_disable_rest","bone_idx","disable"),&Skeleton::set_bone_disable_rest);
- ClassDB::bind_method(D_METHOD("is_bone_rest_disabled","bone_idx"),&Skeleton::is_bone_rest_disabled);
+ ClassDB::bind_method(D_METHOD("bind_child_node_to_bone", "bone_idx", "node:Node"), &Skeleton::bind_child_node_to_bone);
+ ClassDB::bind_method(D_METHOD("unbind_child_node_from_bone", "bone_idx", "node:Node"), &Skeleton::unbind_child_node_from_bone);
+ ClassDB::bind_method(D_METHOD("get_bound_child_nodes_to_bone", "bone_idx"), &Skeleton::_get_bound_child_nodes_to_bone);
- ClassDB::bind_method(D_METHOD("bind_child_node_to_bone","bone_idx","node:Node"),&Skeleton::bind_child_node_to_bone);
- ClassDB::bind_method(D_METHOD("unbind_child_node_from_bone","bone_idx","node:Node"),&Skeleton::unbind_child_node_from_bone);
- ClassDB::bind_method(D_METHOD("get_bound_child_nodes_to_bone","bone_idx"),&Skeleton::_get_bound_child_nodes_to_bone);
+ ClassDB::bind_method(D_METHOD("clear_bones"), &Skeleton::clear_bones);
- ClassDB::bind_method(D_METHOD("clear_bones"),&Skeleton::clear_bones);
+ ClassDB::bind_method(D_METHOD("get_bone_pose", "bone_idx"), &Skeleton::get_bone_pose);
+ ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton::set_bone_pose);
- ClassDB::bind_method(D_METHOD("get_bone_pose","bone_idx"),&Skeleton::get_bone_pose);
- ClassDB::bind_method(D_METHOD("set_bone_pose","bone_idx","pose"),&Skeleton::set_bone_pose);
+ ClassDB::bind_method(D_METHOD("set_bone_global_pose", "bone_idx", "pose"), &Skeleton::set_bone_global_pose);
+ ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton::get_bone_global_pose);
- ClassDB::bind_method(D_METHOD("set_bone_global_pose","bone_idx","pose"),&Skeleton::set_bone_global_pose);
- ClassDB::bind_method(D_METHOD("get_bone_global_pose","bone_idx"),&Skeleton::get_bone_global_pose);
+ ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton::get_bone_custom_pose);
+ ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton::set_bone_custom_pose);
- ClassDB::bind_method(D_METHOD("get_bone_custom_pose","bone_idx"),&Skeleton::get_bone_custom_pose);
- ClassDB::bind_method(D_METHOD("set_bone_custom_pose","bone_idx","custom_pose"),&Skeleton::set_bone_custom_pose);
+ ClassDB::bind_method(D_METHOD("get_bone_transform", "bone_idx"), &Skeleton::get_bone_transform);
- ClassDB::bind_method(D_METHOD("get_bone_transform","bone_idx"),&Skeleton::get_bone_transform);
-
- BIND_CONSTANT( NOTIFICATION_UPDATE_SKELETON );
+ BIND_CONSTANT(NOTIFICATION_UPDATE_SKELETON);
}
-
-
Skeleton::Skeleton() {
- rest_global_inverse_dirty=true;
- dirty=false;
- skeleton=VisualServer::get_singleton()->skeleton_create();
+ rest_global_inverse_dirty = true;
+ dirty = false;
+ skeleton = VisualServer::get_singleton()->skeleton_create();
}
-
Skeleton::~Skeleton() {
- VisualServer::get_singleton()->free( skeleton );
+ VisualServer::get_singleton()->free(skeleton);
}
-
-
diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h
index 04eb3e9009..7074289724 100644
--- a/scene/3d/skeleton.h
+++ b/scene/3d/skeleton.h
@@ -29,15 +29,15 @@
#ifndef SKELETON_H
#define SKELETON_H
-#include "scene/3d/spatial.h"
#include "rid.h"
+#include "scene/3d/spatial.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class Skeleton : public Spatial {
- GDCLASS( Skeleton, Spatial );
+ GDCLASS(Skeleton, Spatial);
struct Bone {
@@ -58,7 +58,12 @@ class Skeleton : public Spatial {
List<uint32_t> nodes_bound;
- Bone() { parent=-1; enabled=true; custom_pose_enable=false; disable_rest=false; }
+ Bone() {
+ parent = -1;
+ enabled = true;
+ custom_pose_enable = false;
+ disable_rest = false;
+ }
};
bool rest_global_inverse_dirty;
@@ -70,41 +75,37 @@ class Skeleton : public Spatial {
void _make_dirty();
bool dirty;
-//bind helpers
+ //bind helpers
Array _get_bound_child_nodes_to_bone(int p_bone) const {
Array bound;
- List<Node*> childs;
- get_bound_child_nodes_to_bone(p_bone,&childs);
+ List<Node *> childs;
+ get_bound_child_nodes_to_bone(p_bone, &childs);
- for (int i=0;i<childs.size();i++) {
+ for (int i = 0; i < childs.size(); i++) {
- bound.push_back( childs[i] );
+ bound.push_back(childs[i]);
}
return bound;
}
-
protected:
-
- bool _get(const StringName& p_name,Variant &r_ret) const;
- bool _set(const StringName& p_name, const Variant& p_value);
- void _get_property_list( List<PropertyInfo>* p_list ) const;
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
-
enum {
- NOTIFICATION_UPDATE_SKELETON=50
+ NOTIFICATION_UPDATE_SKELETON = 50
};
-
RID get_skeleton() const;
// skeleton creation api
- void add_bone(const String&p_name);
+ void add_bone(const String &p_name);
int find_bone(String p_name) const;
String get_bone_name(int p_bone) const;
@@ -118,35 +119,34 @@ public:
int get_bone_count() const;
- void set_bone_rest(int p_bone, const Transform& p_rest);
+ void set_bone_rest(int p_bone, const Transform &p_rest);
Transform get_bone_rest(int p_bone) const;
Transform get_bone_transform(int p_bone) const;
Transform get_bone_global_pose(int p_bone) const;
- void set_bone_global_pose(int p_bone,const Transform& p_pose);
+ void set_bone_global_pose(int p_bone, const Transform &p_pose);
void set_bone_enabled(int p_bone, bool p_enabled);
bool is_bone_enabled(int p_bone) const;
- void bind_child_node_to_bone(int p_bone,Node *p_node);
- void unbind_child_node_from_bone(int p_bone,Node *p_node);
- void get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const;
+ void bind_child_node_to_bone(int p_bone, Node *p_node);
+ void unbind_child_node_from_bone(int p_bone, Node *p_node);
+ void get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const;
void clear_bones();
// posing api
- void set_bone_pose(int p_bone, const Transform& p_pose);
+ void set_bone_pose(int p_bone, const Transform &p_pose);
Transform get_bone_pose(int p_bone) const;
- void set_bone_custom_pose(int p_bone, const Transform& p_custom_pose);
+ void set_bone_custom_pose(int p_bone, const Transform &p_custom_pose);
Transform get_bone_custom_pose(int p_bone) const;
void localize_rests(); // used for loaders and tools
Skeleton();
~Skeleton();
-
};
#endif
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index 58a6a24567..1125a7a4d2 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -28,8 +28,8 @@
/*************************************************************************/
#include "spatial.h"
-#include "scene/main/viewport.h"
#include "message_queue.h"
+#include "scene/main/viewport.h"
#include "scene/scene_string_names.h"
/*
@@ -66,10 +66,7 @@ future: no idea
*/
-
-
SpatialGizmo::SpatialGizmo() {
-
}
void Spatial::_notify_dirty() {
@@ -80,14 +77,12 @@ void Spatial::_notify_dirty() {
}
}
-
-
void Spatial::_update_local_transform() const {
data.local_transform.basis = Basis();
data.local_transform.basis.scale(data.scale);
data.local_transform.basis.rotate(data.rotation);
- data.dirty&=~DIRTY_LOCAL;
+ data.dirty &= ~DIRTY_LOCAL;
}
void Spatial::_propagate_transform_changed(Spatial *p_origin) {
@@ -102,48 +97,46 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) {
data.children_lock++;
- for (List<Spatial*>::Element *E=data.children.front();E;E=E->next()) {
+ for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) {
if (E->get()->data.toplevel_active)
continue; //don't propagate to a toplevel
E->get()->_propagate_transform_changed(p_origin);
}
-
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
get_tree()->xform_change_list.add(&xform_change);
-
}
- data.dirty|=DIRTY_GLOBAL;
+ data.dirty |= DIRTY_GLOBAL;
data.children_lock--;
}
void Spatial::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Node *p = get_parent();
if (p)
- data.parent=p->cast_to<Spatial>();
+ data.parent = p->cast_to<Spatial>();
if (data.parent)
- data.C=data.parent->data.children.push_back(this);
+ data.C = data.parent->data.children.push_back(this);
else
- data.C=NULL;
+ data.C = NULL;
if (data.toplevel && !get_tree()->is_editor_hint()) {
if (data.parent) {
data.local_transform = data.parent->get_global_transform() * get_transform();
- data.dirty=DIRTY_VECTORS; //global is always dirty upon entering a scene
+ data.dirty = DIRTY_VECTORS; //global is always dirty upon entering a scene
}
- data.toplevel_active=true;
+ data.toplevel_active = true;
}
- data.dirty|=DIRTY_GLOBAL; //global is always dirty upon entering a scene
+ data.dirty |= DIRTY_GLOBAL; //global is always dirty upon entering a scene
_notify_dirty();
notification(NOTIFICATION_ENTER_WORLD);
@@ -151,38 +144,37 @@ void Spatial::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
- notification(NOTIFICATION_EXIT_WORLD,true);
+ notification(NOTIFICATION_EXIT_WORLD, true);
if (xform_change.in_list())
get_tree()->xform_change_list.remove(&xform_change);
if (data.C)
data.parent->data.children.erase(data.C);
- data.parent=NULL;
- data.C=NULL;
- data.toplevel_active=false;
+ data.parent = NULL;
+ data.C = NULL;
+ data.toplevel_active = false;
} break;
case NOTIFICATION_ENTER_WORLD: {
- data.inside_world=true;
- data.viewport=NULL;
+ data.inside_world = true;
+ data.viewport = NULL;
Node *parent = get_parent();
- while(parent && !data.viewport) {
- data.viewport=parent->cast_to<Viewport>();
- parent=parent->get_parent();
+ while (parent && !data.viewport) {
+ data.viewport = parent->cast_to<Viewport>();
+ parent = parent->get_parent();
}
ERR_FAIL_COND(!data.viewport);
-
if (get_script_instance()) {
Variant::CallError err;
- get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world,NULL,0);
+ get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, NULL, 0);
}
#ifdef TOOLS_ENABLED
if (get_tree()->is_editor_hint()) {
//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this);
- get_tree()->call_group_flags(0,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this);
+ get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
if (!data.gizmo_disabled) {
if (data.gizmo.is_valid())
@@ -203,15 +195,14 @@ void Spatial::_notification(int p_what) {
if (get_script_instance()) {
Variant::CallError err;
- get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world,NULL,0);
+ get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, NULL, 0);
}
- data.viewport=NULL;
- data.inside_world=false;
+ data.viewport = NULL;
+ data.inside_world = false;
} break;
-
case NOTIFICATION_TRANSFORM_CHANGED: {
#ifdef TOOLS_ENABLED
@@ -225,10 +216,10 @@ void Spatial::_notification(int p_what) {
}
}
-void Spatial::set_transform(const Transform& p_transform) {
+void Spatial::set_transform(const Transform &p_transform) {
- data.local_transform=p_transform;
- data.dirty|=DIRTY_VECTORS;
+ data.local_transform = p_transform;
+ data.dirty |= DIRTY_VECTORS;
_change_notify("transform/translation");
_change_notify("transform/rotation");
_change_notify("transform/scale");
@@ -236,23 +227,18 @@ void Spatial::set_transform(const Transform& p_transform) {
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
}
-
-
-
}
-void Spatial::set_global_transform(const Transform& p_transform) {
+void Spatial::set_global_transform(const Transform &p_transform) {
Transform xform =
(data.parent && !data.toplevel_active) ?
- data.parent->get_global_transform().affine_inverse() * p_transform :
- p_transform;
+ data.parent->get_global_transform().affine_inverse() * p_transform :
+ p_transform;
set_transform(xform);
-
}
-
Transform Spatial::get_transform() const {
if (data.dirty & DIRTY_LOCAL) {
@@ -275,13 +261,13 @@ Transform Spatial::get_global_transform() const {
if (data.parent && !data.toplevel_active) {
- data.global_transform=data.parent->get_global_transform() * data.local_transform;
+ data.global_transform = data.parent->get_global_transform() * data.local_transform;
} else {
- data.global_transform=data.local_transform;
+ data.global_transform = data.local_transform;
}
- data.dirty&=~DIRTY_GLOBAL;
+ data.dirty &= ~DIRTY_GLOBAL;
}
return data.global_transform;
@@ -321,88 +307,83 @@ void Spatial::remove_child_notify(Node *p_child) {
Spatial *Spatial::get_parent_spatial() const {
return data.parent;
-
}
Transform Spatial::get_relative_transform(const Node *p_parent) const {
- if (p_parent==this)
+ if (p_parent == this)
return Transform();
- ERR_FAIL_COND_V(!data.parent,Transform());
+ ERR_FAIL_COND_V(!data.parent, Transform());
- if (p_parent==data.parent)
+ if (p_parent == data.parent)
return get_transform();
else
return data.parent->get_relative_transform(p_parent) * get_transform();
-
}
-void Spatial::set_translation(const Vector3& p_translation) {
+void Spatial::set_translation(const Vector3 &p_translation) {
- data.local_transform.origin=p_translation;
+ data.local_transform.origin = p_translation;
_propagate_transform_changed(this);
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
}
-
}
-void Spatial::set_rotation(const Vector3& p_euler_rad){
+void Spatial::set_rotation(const Vector3 &p_euler_rad) {
- if (data.dirty&DIRTY_VECTORS) {
- data.scale=data.local_transform.basis.get_scale();
- data.dirty&=~DIRTY_VECTORS;
+ if (data.dirty & DIRTY_VECTORS) {
+ data.scale = data.local_transform.basis.get_scale();
+ data.dirty &= ~DIRTY_VECTORS;
}
- data.rotation=p_euler_rad;
- data.dirty|=DIRTY_LOCAL;
+ data.rotation = p_euler_rad;
+ data.dirty |= DIRTY_LOCAL;
_propagate_transform_changed(this);
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
}
-
}
-void Spatial::set_rotation_in_degrees(const Vector3& p_euler_deg) {
+void Spatial::set_rotation_in_degrees(const Vector3 &p_euler_deg) {
set_rotation(p_euler_deg * Math_PI / 180.0);
}
-void Spatial::_set_rotation_deg(const Vector3& p_euler_deg) {
+void Spatial::_set_rotation_deg(const Vector3 &p_euler_deg) {
WARN_PRINT("Deprecated method Spatial._set_rotation_deg(): This method was renamed to set_rotation_deg. Please adapt your code accordingly, as the old method will be obsoleted.");
set_rotation_in_degrees(p_euler_deg);
}
-void Spatial::set_scale(const Vector3& p_scale){
+void Spatial::set_scale(const Vector3 &p_scale) {
- if (data.dirty&DIRTY_VECTORS) {
- data.rotation=data.local_transform.basis.get_rotation();
- data.dirty&=~DIRTY_VECTORS;
+ if (data.dirty & DIRTY_VECTORS) {
+ data.rotation = data.local_transform.basis.get_rotation();
+ data.dirty &= ~DIRTY_VECTORS;
}
- data.scale=p_scale;
- data.dirty|=DIRTY_LOCAL;
+ data.scale = p_scale;
+ data.dirty |= DIRTY_LOCAL;
_propagate_transform_changed(this);
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
}
-
}
-Vector3 Spatial::get_translation() const{
+Vector3 Spatial::get_translation() const {
return data.local_transform.origin;
}
-Vector3 Spatial::get_rotation() const{
+Vector3 Spatial::get_rotation() const {
- if (data.dirty&DIRTY_VECTORS) {
- data.scale=data.local_transform.basis.get_scale();
- data.rotation=data.local_transform.basis.get_rotation();
+ if (data.dirty & DIRTY_VECTORS) {
+ data.scale = data.local_transform.basis.get_scale();
+ data.rotation = data.local_transform.basis.get_rotation();
- data.dirty&=~DIRTY_VECTORS;
+ data.dirty &= ~DIRTY_VECTORS;
}
return data.rotation;
@@ -421,19 +402,18 @@ Vector3 Spatial::_get_rotation_deg() const {
return get_rotation_in_degrees();
}
-Vector3 Spatial::get_scale() const{
+Vector3 Spatial::get_scale() const {
- if (data.dirty&DIRTY_VECTORS) {
- data.scale=data.local_transform.basis.get_scale();
- data.rotation=data.local_transform.basis.get_rotation();
+ if (data.dirty & DIRTY_VECTORS) {
+ data.scale = data.local_transform.basis.get_scale();
+ data.rotation = data.local_transform.basis.get_rotation();
- data.dirty&=~DIRTY_VECTORS;
+ data.dirty &= ~DIRTY_VECTORS;
}
return data.scale;
}
-
void Spatial::update_gizmo() {
#ifdef TOOLS_ENABLED
@@ -443,12 +423,12 @@ void Spatial::update_gizmo() {
return;
if (data.gizmo_dirty)
return;
- data.gizmo_dirty=true;
- MessageQueue::get_singleton()->push_call(this,"_update_gizmo");
+ data.gizmo_dirty = true;
+ MessageQueue::get_singleton()->push_call(this, "_update_gizmo");
#endif
}
-void Spatial::set_gizmo(const Ref<SpatialGizmo>& p_gizmo) {
+void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) {
#ifdef TOOLS_ENABLED
@@ -456,7 +436,7 @@ void Spatial::set_gizmo(const Ref<SpatialGizmo>& p_gizmo) {
return;
if (data.gizmo.is_valid() && is_inside_world())
data.gizmo->free();
- data.gizmo=p_gizmo;
+ data.gizmo = p_gizmo;
if (data.gizmo.is_valid() && is_inside_world()) {
data.gizmo->create();
@@ -482,7 +462,7 @@ Ref<SpatialGizmo> Spatial::get_gizmo() const {
void Spatial::_update_gizmo() {
- data.gizmo_dirty=false;
+ data.gizmo_dirty = false;
if (data.gizmo.is_valid()) {
if (is_visible_in_tree())
data.gizmo->redraw();
@@ -491,19 +471,18 @@ void Spatial::_update_gizmo() {
}
}
-
void Spatial::set_disable_gizmo(bool p_enabled) {
- data.gizmo_disabled=p_enabled;
+ data.gizmo_disabled = p_enabled;
if (!p_enabled && data.gizmo.is_valid())
- data.gizmo=Ref<SpatialGizmo>();
+ data.gizmo = Ref<SpatialGizmo>();
}
#endif
void Spatial::set_as_toplevel(bool p_enabled) {
- if (data.toplevel==p_enabled)
+ if (data.toplevel == p_enabled)
return;
if (is_inside_tree() && !get_tree()->is_editor_hint()) {
@@ -512,30 +491,28 @@ void Spatial::set_as_toplevel(bool p_enabled) {
else if (data.parent)
set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
- data.toplevel=p_enabled;
- data.toplevel_active=p_enabled;
+ data.toplevel = p_enabled;
+ data.toplevel_active = p_enabled;
} else {
- data.toplevel=p_enabled;
+ data.toplevel = p_enabled;
}
-
}
-bool Spatial::is_set_as_toplevel() const{
+bool Spatial::is_set_as_toplevel() const {
return data.toplevel;
}
Ref<World> Spatial::get_world() const {
- ERR_FAIL_COND_V(!is_inside_world(),Ref<World>());
+ ERR_FAIL_COND_V(!is_inside_world(), Ref<World>());
return data.viewport->find_world();
-
}
#ifdef TOOLS_ENABLED
-void Spatial::set_import_transform(const Transform& p_transform) {
- data.import_transform=p_transform;
+void Spatial::set_import_transform(const Transform &p_transform) {
+ data.import_transform = p_transform;
}
Transform Spatial::get_import_transform() const {
@@ -544,7 +521,6 @@ Transform Spatial::get_import_transform() const {
}
#endif
-
void Spatial::_propagate_visibility_changed() {
notification(NOTIFICATION_VISIBILITY_CHANGED);
@@ -555,22 +531,21 @@ void Spatial::_propagate_visibility_changed() {
_update_gizmo();
#endif
- for (List<Spatial*>::Element*E=data.children.front();E;E=E->next()) {
+ for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) {
- Spatial *c=E->get();
+ Spatial *c = E->get();
if (!c || !c->data.visible)
continue;
c->_propagate_visibility_changed();
}
}
-
void Spatial::show() {
if (data.visible)
return;
- data.visible=true;
+ data.visible = true;
if (!is_inside_tree())
return;
@@ -581,35 +556,33 @@ void Spatial::show() {
}
}
-void Spatial::hide(){
+void Spatial::hide() {
if (!data.visible)
return;
bool was_visible = is_visible_in_tree();
- data.visible=false;
+ data.visible = false;
if (!data.parent || was_visible) {
_propagate_visibility_changed();
}
-
}
-bool Spatial::is_visible_in_tree() const{
+bool Spatial::is_visible_in_tree() const {
- const Spatial *s=this;
+ const Spatial *s = this;
- while(s) {
+ while (s) {
if (!s->data.visible) {
return false;
}
- s=s->data.parent;
+ s = s->data.parent;
}
return true;
}
-
void Spatial::set_visible(bool p_visible) {
if (p_visible)
@@ -623,64 +596,57 @@ bool Spatial::is_visible() const {
return data.visible;
}
-void Spatial::rotate(const Vector3& p_normal,float p_radians) {
+void Spatial::rotate(const Vector3 &p_normal, float p_radians) {
- Transform t =get_transform();
- t.basis.rotate(p_normal,p_radians);
+ Transform t = get_transform();
+ t.basis.rotate(p_normal, p_radians);
set_transform(t);
}
void Spatial::rotate_x(float p_radians) {
- Transform t =get_transform();
- t.basis.rotate(Vector3(1,0,0),p_radians);
+ Transform t = get_transform();
+ t.basis.rotate(Vector3(1, 0, 0), p_radians);
set_transform(t);
-
}
-void Spatial::rotate_y(float p_radians){
+void Spatial::rotate_y(float p_radians) {
- Transform t =get_transform();
- t.basis.rotate(Vector3(0,1,0),p_radians);
+ Transform t = get_transform();
+ t.basis.rotate(Vector3(0, 1, 0), p_radians);
set_transform(t);
-
}
-void Spatial::rotate_z(float p_radians){
+void Spatial::rotate_z(float p_radians) {
- Transform t =get_transform();
- t.basis.rotate(Vector3(0,0,1),p_radians);
+ Transform t = get_transform();
+ t.basis.rotate(Vector3(0, 0, 1), p_radians);
set_transform(t);
-
}
-void Spatial::translate(const Vector3& p_offset){
+void Spatial::translate(const Vector3 &p_offset) {
- Transform t =get_transform();
+ Transform t = get_transform();
t.translate(p_offset);
set_transform(t);
-
}
-void Spatial::scale(const Vector3& p_ratio){
+void Spatial::scale(const Vector3 &p_ratio) {
- Transform t =get_transform();
+ Transform t = get_transform();
t.basis.scale(p_ratio);
set_transform(t);
-
}
-void Spatial::global_rotate(const Vector3& p_normal,float p_radians){
+void Spatial::global_rotate(const Vector3 &p_normal, float p_radians) {
- Basis rotation(p_normal,p_radians);
+ Basis rotation(p_normal, p_radians);
Transform t = get_global_transform();
- t.basis= rotation * t.basis;
+ t.basis = rotation * t.basis;
set_global_transform(t);
-
}
-void Spatial::global_translate(const Vector3& p_offset){
+void Spatial::global_translate(const Vector3 &p_offset) {
Transform t = get_global_transform();
- t.origin+=p_offset;
+ t.origin += p_offset;
set_global_transform(t);
-
}
void Spatial::orthonormalize() {
@@ -688,44 +654,40 @@ void Spatial::orthonormalize() {
Transform t = get_transform();
t.orthonormalize();
set_transform(t);
-
}
void Spatial::set_identity() {
set_transform(Transform());
-
}
-
-void Spatial::look_at(const Vector3& p_target, const Vector3& p_up_normal) {
+void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up_normal) {
Transform lookat;
- lookat.origin=get_global_transform().origin;
- if (lookat.origin==p_target) {
+ lookat.origin = get_global_transform().origin;
+ if (lookat.origin == p_target) {
ERR_EXPLAIN("Node origin and target are in the same position, look_at() failed");
ERR_FAIL();
}
- if (p_up_normal.cross(p_target-lookat.origin)==Vector3()) {
+ if (p_up_normal.cross(p_target - lookat.origin) == Vector3()) {
ERR_EXPLAIN("Up vector and direction between node origin and target are aligned, look_at() failed");
ERR_FAIL();
}
- lookat=lookat.looking_at(p_target,p_up_normal);
+ lookat = lookat.looking_at(p_target, p_up_normal);
set_global_transform(lookat);
}
-void Spatial::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) {
+void Spatial::look_at_from_pos(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up_normal) {
Transform lookat;
- lookat.origin=p_pos;
- lookat=lookat.looking_at(p_target,p_up_normal);
+ lookat.origin = p_pos;
+ lookat = lookat.looking_at(p_target, p_up_normal);
set_global_transform(lookat);
-
}
void Spatial::set_notify_transform(bool p_enable) {
- data.notify_transform=p_enable;
+ data.notify_transform = p_enable;
}
bool Spatial::is_transform_notification_enabled() const {
@@ -733,7 +695,7 @@ bool Spatial::is_transform_notification_enabled() const {
}
void Spatial::set_notify_local_transform(bool p_enable) {
- data.notify_local_transform=p_enable;
+ data.notify_local_transform = p_enable;
}
bool Spatial::is_local_transform_notification_enabled() const {
@@ -742,37 +704,37 @@ bool Spatial::is_local_transform_notification_enabled() const {
void Spatial::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_transform","local"), &Spatial::set_transform);
+ ClassDB::bind_method(D_METHOD("set_transform", "local"), &Spatial::set_transform);
ClassDB::bind_method(D_METHOD("get_transform"), &Spatial::get_transform);
- ClassDB::bind_method(D_METHOD("set_translation","translation"), &Spatial::set_translation);
+ ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Spatial::set_translation);
ClassDB::bind_method(D_METHOD("get_translation"), &Spatial::get_translation);
- ClassDB::bind_method(D_METHOD("set_rotation","rotation_rad"), &Spatial::set_rotation);
+ ClassDB::bind_method(D_METHOD("set_rotation", "rotation_rad"), &Spatial::set_rotation);
ClassDB::bind_method(D_METHOD("get_rotation"), &Spatial::get_rotation);
- ClassDB::bind_method(D_METHOD("set_rotation_deg","rotation_deg"), &Spatial::set_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("set_rotation_deg", "rotation_deg"), &Spatial::set_rotation_in_degrees);
ClassDB::bind_method(D_METHOD("get_rotation_deg"), &Spatial::get_rotation_in_degrees);
- ClassDB::bind_method(D_METHOD("set_scale","scale"), &Spatial::set_scale);
+ ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Spatial::set_scale);
ClassDB::bind_method(D_METHOD("get_scale"), &Spatial::get_scale);
- ClassDB::bind_method(D_METHOD("set_global_transform","global"), &Spatial::set_global_transform);
+ ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Spatial::set_global_transform);
ClassDB::bind_method(D_METHOD("get_global_transform"), &Spatial::get_global_transform);
ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Spatial::get_parent_spatial);
- ClassDB::bind_method(D_METHOD("set_ignore_transform_notification","enabled"), &Spatial::set_ignore_transform_notification);
- ClassDB::bind_method(D_METHOD("set_as_toplevel","enable"), &Spatial::set_as_toplevel);
+ ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Spatial::set_ignore_transform_notification);
+ ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Spatial::set_as_toplevel);
ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Spatial::is_set_as_toplevel);
ClassDB::bind_method(D_METHOD("get_world:World"), &Spatial::get_world);
// TODO: Obsolete those two methods (old name) properly (GH-4397)
- ClassDB::bind_method(D_METHOD("_set_rotation_deg","rotation_deg"), &Spatial::_set_rotation_deg);
+ ClassDB::bind_method(D_METHOD("_set_rotation_deg", "rotation_deg"), &Spatial::_set_rotation_deg);
ClassDB::bind_method(D_METHOD("_get_rotation_deg"), &Spatial::_get_rotation_deg);
#ifdef TOOLS_ENABLED
ClassDB::bind_method(D_METHOD("_update_gizmo"), &Spatial::_update_gizmo);
ClassDB::bind_method(D_METHOD("_set_import_transform"), &Spatial::set_import_transform);
ClassDB::bind_method(D_METHOD("_get_import_transform"), &Spatial::get_import_transform);
- ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"_import_transform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_import_transform","_get_import_transform");
+ ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "_import_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_import_transform", "_get_import_transform");
#endif
ClassDB::bind_method(D_METHOD("update_gizmo"), &Spatial::update_gizmo);
- ClassDB::bind_method(D_METHOD("set_gizmo","gizmo:SpatialGizmo"), &Spatial::set_gizmo);
+ ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo:SpatialGizmo"), &Spatial::set_gizmo);
ClassDB::bind_method(D_METHOD("get_gizmo:SpatialGizmo"), &Spatial::get_gizmo);
ClassDB::bind_method(D_METHOD("set_visible"), &Spatial::set_visible);
@@ -781,84 +743,77 @@ void Spatial::_bind_methods() {
ClassDB::bind_method(D_METHOD("show"), &Spatial::show);
ClassDB::bind_method(D_METHOD("hide"), &Spatial::hide);
- ClassDB::bind_method(D_METHOD("set_notify_local_transform","enable"), &Spatial::set_notify_local_transform);
+ ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Spatial::set_notify_local_transform);
ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Spatial::is_local_transform_notification_enabled);
- ClassDB::bind_method(D_METHOD("set_notify_transform","enable"), &Spatial::set_notify_transform);
+ ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform);
ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled);
- void rotate(const Vector3& p_normal,float p_radians);
+ void rotate(const Vector3 &p_normal, float p_radians);
void rotate_x(float p_radians);
void rotate_y(float p_radians);
void rotate_z(float p_radians);
- void translate(const Vector3& p_offset);
- void scale(const Vector3& p_ratio);
- void global_rotate(const Vector3& p_normal,float p_radians);
- void global_translate(const Vector3& p_offset);
-
- ClassDB::bind_method( D_METHOD("rotate","normal","radians"),&Spatial::rotate );
- ClassDB::bind_method( D_METHOD("global_rotate","normal","radians"),&Spatial::global_rotate );
- ClassDB::bind_method( D_METHOD("rotate_x","radians"),&Spatial::rotate_x );
- ClassDB::bind_method( D_METHOD("rotate_y","radians"),&Spatial::rotate_y );
- ClassDB::bind_method( D_METHOD("rotate_z","radians"),&Spatial::rotate_z );
- ClassDB::bind_method( D_METHOD("translate","offset"),&Spatial::translate );
- ClassDB::bind_method( D_METHOD("global_translate","offset"),&Spatial::global_translate );
- ClassDB::bind_method( D_METHOD("orthonormalize"),&Spatial::orthonormalize );
- ClassDB::bind_method( D_METHOD("set_identity"),&Spatial::set_identity );
-
- ClassDB::bind_method( D_METHOD("look_at","target","up"),&Spatial::look_at );
- ClassDB::bind_method( D_METHOD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos );
-
- BIND_CONSTANT( NOTIFICATION_TRANSFORM_CHANGED );
- BIND_CONSTANT( NOTIFICATION_ENTER_WORLD );
- BIND_CONSTANT( NOTIFICATION_EXIT_WORLD );
- BIND_CONSTANT( NOTIFICATION_VISIBILITY_CHANGED );
+ void translate(const Vector3 &p_offset);
+ void scale(const Vector3 &p_ratio);
+ void global_rotate(const Vector3 &p_normal, float p_radians);
+ void global_translate(const Vector3 &p_offset);
+
+ ClassDB::bind_method(D_METHOD("rotate", "normal", "radians"), &Spatial::rotate);
+ ClassDB::bind_method(D_METHOD("global_rotate", "normal", "radians"), &Spatial::global_rotate);
+ ClassDB::bind_method(D_METHOD("rotate_x", "radians"), &Spatial::rotate_x);
+ ClassDB::bind_method(D_METHOD("rotate_y", "radians"), &Spatial::rotate_y);
+ ClassDB::bind_method(D_METHOD("rotate_z", "radians"), &Spatial::rotate_z);
+ ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate);
+ ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Spatial::global_translate);
+ ClassDB::bind_method(D_METHOD("orthonormalize"), &Spatial::orthonormalize);
+ ClassDB::bind_method(D_METHOD("set_identity"), &Spatial::set_identity);
+
+ ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Spatial::look_at);
+ ClassDB::bind_method(D_METHOD("look_at_from_pos", "pos", "target", "up"), &Spatial::look_at_from_pos);
+
+ BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
+ BIND_CONSTANT(NOTIFICATION_ENTER_WORLD);
+ BIND_CONSTANT(NOTIFICATION_EXIT_WORLD);
+ BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
//ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"transform/global",PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ), "set_global_transform", "get_global_transform") ;
- ADD_GROUP("Transform","");
- ADD_PROPERTYNZ( PropertyInfo(Variant::TRANSFORM,"transform",PROPERTY_HINT_NONE,""), "set_transform", "get_transform") ;
- ADD_PROPERTYNZ( PropertyInfo(Variant::TRANSFORM,"global_transform",PROPERTY_HINT_NONE,"",0), "set_global_transform", "get_global_transform") ;
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"translation",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR), "set_translation", "get_translation") ;
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"rotation_deg",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR), "set_rotation_deg", "get_rotation_deg") ;
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"rotation",PROPERTY_HINT_NONE,"",0), "set_rotation", "get_rotation") ;
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"scale",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR), "set_scale", "get_scale") ;
- ADD_GROUP("Visibility","");
- ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"visible"), "set_visible", "is_visible") ;
+ ADD_GROUP("Transform", "");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::TRANSFORM, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_translation", "get_translation");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_deg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_deg", "get_rotation_deg");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
+ ADD_GROUP("Visibility", "");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
//ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"transform/local"), "set_transform", "get_transform") ;
- ADD_SIGNAL( MethodInfo("visibility_changed" ) );
-
+ ADD_SIGNAL(MethodInfo("visibility_changed"));
}
+Spatial::Spatial()
+ : xform_change(this) {
-Spatial::Spatial() : xform_change(this)
-{
+ data.dirty = DIRTY_NONE;
+ data.children_lock = 0;
- data.dirty=DIRTY_NONE;
- data.children_lock=0;
-
- data.ignore_notification=false;
- data.toplevel=false;
- data.toplevel_active=false;
- data.scale=Vector3(1,1,1);
- data.viewport=NULL;
- data.inside_world=false;
- data.visible=true;
+ data.ignore_notification = false;
+ data.toplevel = false;
+ data.toplevel_active = false;
+ data.scale = Vector3(1, 1, 1);
+ data.viewport = NULL;
+ data.inside_world = false;
+ data.visible = true;
#ifdef TOOLS_ENABLED
- data.gizmo_disabled=false;
- data.gizmo_dirty=false;
+ data.gizmo_disabled = false;
+ data.gizmo_dirty = false;
#endif
- data.notify_local_transform=false;
- data.notify_transform=false;
- data.parent=NULL;
- data.C=NULL;
-
+ data.notify_local_transform = false;
+ data.notify_transform = false;
+ data.parent = NULL;
+ data.C = NULL;
}
-
Spatial::~Spatial() {
-
}
-
-
diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h
index 72daa472bd..e5817883dd 100644
--- a/scene/3d/spatial.h
+++ b/scene/3d/spatial.h
@@ -38,39 +38,34 @@
class SpatialGizmo : public Reference {
- GDCLASS(SpatialGizmo,Reference);
-
+ GDCLASS(SpatialGizmo, Reference);
public:
-
- virtual void create()=0;
- virtual void transform()=0;
- virtual void clear()=0;
- virtual void redraw()=0;
- virtual void free()=0;
+ virtual void create() = 0;
+ virtual void transform() = 0;
+ virtual void clear() = 0;
+ virtual void redraw() = 0;
+ virtual void free() = 0;
SpatialGizmo();
};
-
class Spatial : public Node {
- GDCLASS( Spatial, Node );
+ GDCLASS(Spatial, Node);
OBJ_CATEGORY("3D");
enum TransformDirty {
- DIRTY_NONE=0,
- DIRTY_VECTORS=1,
- DIRTY_LOCAL=2,
- DIRTY_GLOBAL=4
+ DIRTY_NONE = 0,
+ DIRTY_VECTORS = 1,
+ DIRTY_LOCAL = 2,
+ DIRTY_GLOBAL = 4
};
mutable SelfList<Node> xform_change;
struct Data {
-
-
mutable Transform global_transform;
mutable Transform local_transform;
mutable Vector3 rotation;
@@ -80,15 +75,14 @@ class Spatial : public Node {
Viewport *viewport;
-
bool toplevel_active;
bool toplevel;
bool inside_world;
int children_lock;
Spatial *parent;
- List<Spatial*> children;
- List<Spatial*>::Element *C;
+ List<Spatial *> children;
+ List<Spatial *>::Element *C;
bool ignore_notification;
bool notify_local_transform;
@@ -112,15 +106,13 @@ class Spatial : public Node {
void _propagate_transform_changed(Spatial *p_origin);
// Deprecated, should be removed in a future version.
- void _set_rotation_deg(const Vector3& p_euler_deg);
+ void _set_rotation_deg(const Vector3 &p_euler_deg);
Vector3 _get_rotation_deg() const;
void _propagate_visibility_changed();
-
protected:
-
- _FORCE_INLINE_ void set_ignore_transform_notification(bool p_ignore) { data.ignore_notification=p_ignore; }
+ _FORCE_INLINE_ void set_ignore_transform_notification(bool p_ignore) { data.ignore_notification = p_ignore; }
_FORCE_INLINE_ void _update_local_transform() const;
@@ -128,33 +120,31 @@ protected:
static void _bind_methods();
public:
-
enum {
- NOTIFICATION_TRANSFORM_CHANGED=SceneTree::NOTIFICATION_TRANSFORM_CHANGED,
- NOTIFICATION_ENTER_WORLD=41,
- NOTIFICATION_EXIT_WORLD=42,
- NOTIFICATION_VISIBILITY_CHANGED=43,
- NOTIFICATION_LOCAL_TRANSFORM_CHANGED=44,
+ NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED,
+ NOTIFICATION_ENTER_WORLD = 41,
+ NOTIFICATION_EXIT_WORLD = 42,
+ NOTIFICATION_VISIBILITY_CHANGED = 43,
+ NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 44,
};
Spatial *get_parent_spatial() const;
-
Ref<World> get_world() const;
- void set_translation(const Vector3& p_translation);
- void set_rotation(const Vector3& p_euler_rad);
- void set_rotation_in_degrees(const Vector3& p_euler_deg);
- void set_scale(const Vector3& p_scale);
+ void set_translation(const Vector3 &p_translation);
+ void set_rotation(const Vector3 &p_euler_rad);
+ void set_rotation_in_degrees(const Vector3 &p_euler_deg);
+ void set_scale(const Vector3 &p_scale);
Vector3 get_translation() const;
Vector3 get_rotation() const;
Vector3 get_rotation_in_degrees() const;
Vector3 get_scale() const;
- void set_transform(const Transform& p_transform);
- void set_global_transform(const Transform& p_transform);
+ void set_transform(const Transform &p_transform);
+ void set_global_transform(const Transform &p_transform);
Transform get_transform() const;
Transform get_global_transform() const;
@@ -164,24 +154,24 @@ public:
void set_disable_gizmo(bool p_enabled);
void update_gizmo();
- void set_gizmo(const Ref<SpatialGizmo>& p_gizmo);
+ void set_gizmo(const Ref<SpatialGizmo> &p_gizmo);
Ref<SpatialGizmo> get_gizmo() const;
_FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; }
Transform get_relative_transform(const Node *p_parent) const;
- void rotate(const Vector3& p_normal,float p_radians);
+ void rotate(const Vector3 &p_normal, float p_radians);
void rotate_x(float p_radians);
void rotate_y(float p_radians);
void rotate_z(float p_radians);
- void translate(const Vector3& p_offset);
- void scale(const Vector3& p_ratio);
- void global_rotate(const Vector3& p_normal,float p_radians);
- void global_translate(const Vector3& p_offset);
+ void translate(const Vector3 &p_offset);
+ void scale(const Vector3 &p_ratio);
+ void global_rotate(const Vector3 &p_normal, float p_radians);
+ void global_translate(const Vector3 &p_offset);
- void look_at(const Vector3& p_target, const Vector3& p_up_normal);
- void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal);
+ void look_at(const Vector3 &p_target, const Vector3 &p_up_normal);
+ void look_at_from_pos(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up_normal);
void set_notify_transform(bool p_enable);
bool is_transform_notification_enabled() const;
@@ -199,13 +189,12 @@ public:
bool is_visible_in_tree() const;
#ifdef TOOLS_ENABLED
- void set_import_transform(const Transform& p_transform) ;
+ void set_import_transform(const Transform &p_transform);
Transform get_import_transform() const;
#endif
Spatial();
~Spatial();
-
};
#endif
diff --git a/scene/3d/spatial_indexer.cpp b/scene/3d/spatial_indexer.cpp
index 6d6c272c25..cddbf9a4e8 100644
--- a/scene/3d/spatial_indexer.cpp
+++ b/scene/3d/spatial_indexer.cpp
@@ -30,8 +30,8 @@
#if 0
-#include "proximity_area.h"
#include "camera.h"
+#include "proximity_area.h"
#include "scene/scene_string_names.h"
void SpatialIndexer::add_camera(Camera* p_camera) {
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 5adb7050f8..062e3943b9 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -27,9 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "sprite_3d.h"
-#include "scene/scene_string_names.h"
#include "core_string_names.h"
-
+#include "scene/scene_string_names.h"
Color SpriteBase3D::_get_color_accum() {
@@ -37,15 +36,15 @@ Color SpriteBase3D::_get_color_accum() {
return color_accum;
if (parent_sprite)
- color_accum=parent_sprite->_get_color_accum();
+ color_accum = parent_sprite->_get_color_accum();
else
- color_accum=Color(1,1,1,1);
+ color_accum = Color(1, 1, 1, 1);
- color_accum.r*=modulate.r;
- color_accum.g*=modulate.g;
- color_accum.b*=modulate.b;
- color_accum.a*=modulate.a;
- color_dirty=false;
+ color_accum.r *= modulate.r;
+ color_accum.g *= modulate.g;
+ color_accum.b *= modulate.b;
+ color_accum.a *= modulate.a;
+ color_dirty = false;
return color_accum;
}
@@ -54,10 +53,10 @@ void SpriteBase3D::_propagate_color_changed() {
if (color_dirty)
return;
- color_dirty=true;
+ color_dirty = true;
_queue_update();
- for (List<SpriteBase3D*>::Element *E=children.front();E;E=E->next()) {
+ for (List<SpriteBase3D *>::Element *E = children.front(); E; E = E->next()) {
E->get()->_propagate_color_changed();
}
@@ -65,40 +64,36 @@ void SpriteBase3D::_propagate_color_changed() {
void SpriteBase3D::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
if (!pending_update)
_im_update();
- Node *parent=get_parent();
+ Node *parent = get_parent();
if (parent) {
- parent_sprite=parent->cast_to<SpriteBase3D>();
+ parent_sprite = parent->cast_to<SpriteBase3D>();
if (parent_sprite) {
- pI=parent_sprite->children.push_back(this);
+ pI = parent_sprite->children.push_back(this);
}
}
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
-
+ if (p_what == NOTIFICATION_EXIT_TREE) {
if (parent_sprite) {
parent_sprite->children.erase(pI);
- pI=NULL;
- parent_sprite=NULL;
+ pI = NULL;
+ parent_sprite = NULL;
}
}
-
}
-
void SpriteBase3D::set_centered(bool p_center) {
- centered=p_center;
+ centered = p_center;
_queue_update();
-
}
bool SpriteBase3D::is_centered() const {
@@ -106,11 +101,10 @@ bool SpriteBase3D::is_centered() const {
return centered;
}
-void SpriteBase3D::set_offset(const Point2& p_offset) {
+void SpriteBase3D::set_offset(const Point2 &p_offset) {
- offset=p_offset;
+ offset = p_offset;
_queue_update();
-
}
Point2 SpriteBase3D::get_offset() const {
@@ -119,7 +113,7 @@ Point2 SpriteBase3D::get_offset() const {
void SpriteBase3D::set_flip_h(bool p_flip) {
- hflip=p_flip;
+ hflip = p_flip;
_queue_update();
}
bool SpriteBase3D::is_flipped_h() const {
@@ -129,7 +123,7 @@ bool SpriteBase3D::is_flipped_h() const {
void SpriteBase3D::set_flip_v(bool p_flip) {
- vflip=p_flip;
+ vflip = p_flip;
_queue_update();
}
bool SpriteBase3D::is_flipped_v() const {
@@ -137,24 +131,21 @@ bool SpriteBase3D::is_flipped_v() const {
return vflip;
}
+void SpriteBase3D::set_modulate(const Color &p_color) {
-
-void SpriteBase3D::set_modulate(const Color& p_color) {
-
- modulate=p_color;
+ modulate = p_color;
_propagate_color_changed();
_queue_update();
}
-Color SpriteBase3D::get_modulate() const{
+Color SpriteBase3D::get_modulate() const {
return modulate;
}
-
void SpriteBase3D::set_pixel_size(float p_amount) {
- pixel_size=p_amount;
+ pixel_size = p_amount;
_queue_update();
}
float SpriteBase3D::get_pixel_size() const {
@@ -164,7 +155,7 @@ float SpriteBase3D::get_pixel_size() const {
void SpriteBase3D::set_opacity(float p_amount) {
- opacity=p_amount;
+ opacity = p_amount;
_queue_update();
}
float SpriteBase3D::get_opacity() const {
@@ -172,10 +163,9 @@ float SpriteBase3D::get_opacity() const {
return opacity;
}
-
void SpriteBase3D::set_axis(Vector3::Axis p_axis) {
- axis=p_axis;
+ axis = p_axis;
_queue_update();
}
Vector3::Axis SpriteBase3D::get_axis() const {
@@ -183,30 +173,24 @@ Vector3::Axis SpriteBase3D::get_axis() const {
return axis;
}
-
-
void SpriteBase3D::_im_update() {
-
_draw();
-
- pending_update=false;
+ pending_update = false;
//texture->draw_rect_region(ci,dst_rect,src_rect,modulate);
-
}
-void SpriteBase3D::_queue_update(){
+void SpriteBase3D::_queue_update() {
- if (pending_update)
+ if (pending_update)
return;
- pending_update=true;
+ pending_update = true;
call_deferred(SceneStringNames::get_singleton()->_im_update);
}
-
Rect3 SpriteBase3D::get_aabb() const {
return aabb;
@@ -214,135 +198,119 @@ Rect3 SpriteBase3D::get_aabb() const {
PoolVector<Face3> SpriteBase3D::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
-
}
-void SpriteBase3D::set_draw_flag(DrawFlags p_flag,bool p_enable) {
+void SpriteBase3D::set_draw_flag(DrawFlags p_flag, bool p_enable) {
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- flags[p_flag]=p_enable;
+ ERR_FAIL_INDEX(p_flag, FLAG_MAX);
+ flags[p_flag] = p_enable;
_queue_update();
}
-bool SpriteBase3D::get_draw_flag(DrawFlags p_flag) const{
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
+bool SpriteBase3D::get_draw_flag(DrawFlags p_flag) const {
+ ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
return flags[p_flag];
}
-void SpriteBase3D::set_alpha_cut_mode(AlphaCutMode p_mode){
+void SpriteBase3D::set_alpha_cut_mode(AlphaCutMode p_mode) {
- ERR_FAIL_INDEX(p_mode,3);
- alpha_cut=p_mode;
+ ERR_FAIL_INDEX(p_mode, 3);
+ alpha_cut = p_mode;
_queue_update();
-
}
-SpriteBase3D::AlphaCutMode SpriteBase3D::get_alpha_cut_mode() const{
+SpriteBase3D::AlphaCutMode SpriteBase3D::get_alpha_cut_mode() const {
return alpha_cut;
}
-
void SpriteBase3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_centered", "centered"), &SpriteBase3D::set_centered);
+ ClassDB::bind_method(D_METHOD("is_centered"), &SpriteBase3D::is_centered);
- ClassDB::bind_method(D_METHOD("set_centered","centered"),&SpriteBase3D::set_centered);
- ClassDB::bind_method(D_METHOD("is_centered"),&SpriteBase3D::is_centered);
-
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&SpriteBase3D::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&SpriteBase3D::get_offset);
-
- ClassDB::bind_method(D_METHOD("set_flip_h","flip_h"),&SpriteBase3D::set_flip_h);
- ClassDB::bind_method(D_METHOD("is_flipped_h"),&SpriteBase3D::is_flipped_h);
-
- ClassDB::bind_method(D_METHOD("set_flip_v","flip_v"),&SpriteBase3D::set_flip_v);
- ClassDB::bind_method(D_METHOD("is_flipped_v"),&SpriteBase3D::is_flipped_v);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &SpriteBase3D::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &SpriteBase3D::get_offset);
+ ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &SpriteBase3D::set_flip_h);
+ ClassDB::bind_method(D_METHOD("is_flipped_h"), &SpriteBase3D::is_flipped_h);
- ClassDB::bind_method(D_METHOD("set_modulate","modulate"),&SpriteBase3D::set_modulate);
- ClassDB::bind_method(D_METHOD("get_modulate"),&SpriteBase3D::get_modulate);
+ ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &SpriteBase3D::set_flip_v);
+ ClassDB::bind_method(D_METHOD("is_flipped_v"), &SpriteBase3D::is_flipped_v);
- ClassDB::bind_method(D_METHOD("set_opacity","opacity"),&SpriteBase3D::set_opacity);
- ClassDB::bind_method(D_METHOD("get_opacity"),&SpriteBase3D::get_opacity);
+ ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &SpriteBase3D::set_modulate);
+ ClassDB::bind_method(D_METHOD("get_modulate"), &SpriteBase3D::get_modulate);
- ClassDB::bind_method(D_METHOD("set_pixel_size","pixel_size"),&SpriteBase3D::set_pixel_size);
- ClassDB::bind_method(D_METHOD("get_pixel_size"),&SpriteBase3D::get_pixel_size);
+ ClassDB::bind_method(D_METHOD("set_opacity", "opacity"), &SpriteBase3D::set_opacity);
+ ClassDB::bind_method(D_METHOD("get_opacity"), &SpriteBase3D::get_opacity);
- ClassDB::bind_method(D_METHOD("set_axis","axis"),&SpriteBase3D::set_axis);
- ClassDB::bind_method(D_METHOD("get_axis"),&SpriteBase3D::get_axis);
+ ClassDB::bind_method(D_METHOD("set_pixel_size", "pixel_size"), &SpriteBase3D::set_pixel_size);
+ ClassDB::bind_method(D_METHOD("get_pixel_size"), &SpriteBase3D::get_pixel_size);
- ClassDB::bind_method(D_METHOD("set_draw_flag","flag","enabled"),&SpriteBase3D::set_draw_flag);
- ClassDB::bind_method(D_METHOD("get_draw_flag","flag"),&SpriteBase3D::get_draw_flag);
+ ClassDB::bind_method(D_METHOD("set_axis", "axis"), &SpriteBase3D::set_axis);
+ ClassDB::bind_method(D_METHOD("get_axis"), &SpriteBase3D::get_axis);
- ClassDB::bind_method(D_METHOD("set_alpha_cut_mode","mode"),&SpriteBase3D::set_alpha_cut_mode);
- ClassDB::bind_method(D_METHOD("get_alpha_cut_mode"),&SpriteBase3D::get_alpha_cut_mode);
+ ClassDB::bind_method(D_METHOD("set_draw_flag", "flag", "enabled"), &SpriteBase3D::set_draw_flag);
+ ClassDB::bind_method(D_METHOD("get_draw_flag", "flag"), &SpriteBase3D::get_draw_flag);
- ClassDB::bind_method(D_METHOD("get_item_rect"),&SpriteBase3D::get_item_rect);
+ ClassDB::bind_method(D_METHOD("set_alpha_cut_mode", "mode"), &SpriteBase3D::set_alpha_cut_mode);
+ ClassDB::bind_method(D_METHOD("get_alpha_cut_mode"), &SpriteBase3D::get_alpha_cut_mode);
- ClassDB::bind_method(D_METHOD("_queue_update"),&SpriteBase3D::_queue_update);
- ClassDB::bind_method(D_METHOD("_im_update"),&SpriteBase3D::_im_update);
+ ClassDB::bind_method(D_METHOD("get_item_rect"), &SpriteBase3D::get_item_rect);
+ ClassDB::bind_method(D_METHOD("_queue_update"), &SpriteBase3D::_queue_update);
+ ClassDB::bind_method(D_METHOD("_im_update"), &SpriteBase3D::_im_update);
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered"), "set_centered","is_centered");
- ADD_PROPERTY( PropertyInfo( Variant::VECTOR2, "offset"), "set_offset","get_offset");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_h"), "set_flip_h","is_flipped_h");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_v"), "set_flip_v","is_flipped_v");
- ADD_PROPERTY( PropertyInfo( Variant::COLOR, "modulate"), "set_modulate","get_modulate");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "opacity",PROPERTY_HINT_RANGE,"0,1,0.01"), "set_opacity","get_opacity");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "pixel_size",PROPERTY_HINT_RANGE,"0.0001,128,0.0001"), "set_pixel_size","get_pixel_size");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "axis",PROPERTY_HINT_ENUM,"X-Axis,Y-Axis,Z-Axis"), "set_axis","get_axis");
- ADD_GROUP("Flags","");
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "transparent"), "set_draw_flag","get_draw_flag",FLAG_TRANSPARENT);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "shaded"), "set_draw_flag","get_draw_flag",FLAG_SHADED);
- ADD_PROPERTY( PropertyInfo( Variant::INT, "alpha_cut",PROPERTY_HINT_ENUM,"Disabled,Discard,Opaque Pre-Pass"), "set_alpha_cut_mode","get_alpha_cut_mode");
-
-
- BIND_CONSTANT( FLAG_TRANSPARENT );
- BIND_CONSTANT( FLAG_SHADED );
- BIND_CONSTANT( FLAG_MAX );
-
- BIND_CONSTANT( ALPHA_CUT_DISABLED );
- BIND_CONSTANT( ALPHA_CUT_DISCARD );
- BIND_CONSTANT( ALPHA_CUT_OPAQUE_PREPASS );
-
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "opacity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_opacity", "get_opacity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pixel_size", PROPERTY_HINT_RANGE, "0.0001,128,0.0001"), "set_pixel_size", "get_pixel_size");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "axis", PROPERTY_HINT_ENUM, "X-Axis,Y-Axis,Z-Axis"), "set_axis", "get_axis");
+ ADD_GROUP("Flags", "");
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "transparent"), "set_draw_flag", "get_draw_flag", FLAG_TRANSPARENT);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "shaded"), "set_draw_flag", "get_draw_flag", FLAG_SHADED);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "alpha_cut", PROPERTY_HINT_ENUM, "Disabled,Discard,Opaque Pre-Pass"), "set_alpha_cut_mode", "get_alpha_cut_mode");
+ BIND_CONSTANT(FLAG_TRANSPARENT);
+ BIND_CONSTANT(FLAG_SHADED);
+ BIND_CONSTANT(FLAG_MAX);
+ BIND_CONSTANT(ALPHA_CUT_DISABLED);
+ BIND_CONSTANT(ALPHA_CUT_DISCARD);
+ BIND_CONSTANT(ALPHA_CUT_OPAQUE_PREPASS);
}
-
-
-
SpriteBase3D::SpriteBase3D() {
- color_dirty=true;
- centered=true;
- hflip=false;
- vflip=false;
- parent_sprite=NULL;
- pI=NULL;
-
- for(int i=0;i<FLAG_MAX;i++)
- flags[i]=i==FLAG_TRANSPARENT;
-
- axis=Vector3::AXIS_Z;
- pixel_size=0.01;
- modulate=Color(1,1,1,1);
- pending_update=false;
- opacity=1.0;
+ color_dirty = true;
+ centered = true;
+ hflip = false;
+ vflip = false;
+ parent_sprite = NULL;
+ pI = NULL;
+
+ for (int i = 0; i < FLAG_MAX; i++)
+ flags[i] = i == FLAG_TRANSPARENT;
+
+ axis = Vector3::AXIS_Z;
+ pixel_size = 0.01;
+ modulate = Color(1, 1, 1, 1);
+ pending_update = false;
+ opacity = 1.0;
immediate = VisualServer::get_singleton()->immediate_create();
set_base(immediate);
}
-
SpriteBase3D::~SpriteBase3D() {
VisualServer::get_singleton()->free(immediate);
}
-
///////////////////////////////////////////
-
void Sprite3D::_draw() {
RID immediate = get_immediate();
@@ -351,7 +319,7 @@ void Sprite3D::_draw() {
if (!texture.is_valid())
return; //no texuture no life
Vector2 tsize = texture->get_size();
- if (tsize.x==0 || tsize.y==0)
+ if (tsize.x == 0 || tsize.y == 0)
return;
Size2i s;
@@ -359,130 +327,122 @@ void Sprite3D::_draw() {
if (region) {
- s=region_rect.size;
- src_rect=region_rect;
+ s = region_rect.size;
+ src_rect = region_rect;
} else {
s = texture->get_size();
- s=s/Size2i(hframes,vframes);
-
- src_rect.size=s;
- src_rect.pos.x+=(frame%hframes)*s.x;
- src_rect.pos.y+=(frame/hframes)*s.y;
+ s = s / Size2i(hframes, vframes);
+ src_rect.size = s;
+ src_rect.pos.x += (frame % hframes) * s.x;
+ src_rect.pos.y += (frame / hframes) * s.y;
}
- Point2i ofs=get_offset();
+ Point2i ofs = get_offset();
if (is_centered())
- ofs-=s/2;
-
- Rect2i dst_rect(ofs,s);
+ ofs -= s / 2;
+ Rect2i dst_rect(ofs, s);
Rect2 final_rect;
Rect2 final_src_rect;
- if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect))
+ if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect))
return;
-
- if (final_rect.size.x==0 || final_rect.size.y==0)
+ if (final_rect.size.x == 0 || final_rect.size.y == 0)
return;
- Color color=_get_color_accum();
- color.a*=get_opacity();
+ Color color = _get_color_accum();
+ color.a *= get_opacity();
- float pixel_size=get_pixel_size();
+ float pixel_size = get_pixel_size();
- Vector2 vertices[4]={
+ Vector2 vertices[4] = {
- (final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size,
- (final_rect.pos+final_rect.size) * pixel_size,
- (final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size,
+ (final_rect.pos + Vector2(0, final_rect.size.y)) * pixel_size,
+ (final_rect.pos + final_rect.size) * pixel_size,
+ (final_rect.pos + Vector2(final_rect.size.x, 0)) * pixel_size,
final_rect.pos * pixel_size,
-
};
- Vector2 uvs[4]={
+ Vector2 uvs[4] = {
final_src_rect.pos / tsize,
- (final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize,
- (final_src_rect.pos+final_src_rect.size) / tsize,
- (final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize,
+ (final_src_rect.pos + Vector2(final_src_rect.size.x, 0)) / tsize,
+ (final_src_rect.pos + final_src_rect.size) / tsize,
+ (final_src_rect.pos + Vector2(0, final_src_rect.size.y)) / tsize,
};
if (is_flipped_h()) {
- SWAP(uvs[0],uvs[1]);
- SWAP(uvs[2],uvs[3]);
+ SWAP(uvs[0], uvs[1]);
+ SWAP(uvs[2], uvs[3]);
}
if (is_flipped_v()) {
- SWAP(uvs[0],uvs[3]);
- SWAP(uvs[1],uvs[2]);
+ SWAP(uvs[0], uvs[3]);
+ SWAP(uvs[1], uvs[2]);
}
-
Vector3 normal;
int axis = get_axis();
- normal[axis]=1.0;
+ normal[axis] = 1.0;
- RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS);
- VS::get_singleton()->immediate_set_material(immediate,mat);
+ RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS);
+ VS::get_singleton()->immediate_set_material(immediate, mat);
- VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid());
+ VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLE_FAN, texture->get_rid());
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
- if (axis!=Vector3::AXIS_Z) {
- SWAP(x_axis,y_axis);
+ if (axis != Vector3::AXIS_Z) {
+ SWAP(x_axis, y_axis);
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
//uvs[i] = Vector2(1.0,1.0)-uvs[i];
//SWAP(vertices[i].x,vertices[i].y);
- if (axis==Vector3::AXIS_Y) {
- vertices[i].y = - vertices[i].y;
- } else if (axis==Vector3::AXIS_X) {
- vertices[i].x = - vertices[i].x;
+ if (axis == Vector3::AXIS_Y) {
+ vertices[i].y = -vertices[i].y;
+ } else if (axis == Vector3::AXIS_X) {
+ vertices[i].x = -vertices[i].x;
}
}
}
Rect3 aabb;
- for(int i=0;i<4;i++) {
- VS::get_singleton()->immediate_normal(immediate,normal);
- VS::get_singleton()->immediate_color(immediate,color);
- VS::get_singleton()->immediate_uv(immediate,uvs[i]);
+ for (int i = 0; i < 4; i++) {
+ VS::get_singleton()->immediate_normal(immediate, normal);
+ VS::get_singleton()->immediate_color(immediate, color);
+ VS::get_singleton()->immediate_uv(immediate, uvs[i]);
Vector3 vtx;
- vtx[x_axis]=vertices[i][0];
- vtx[y_axis]=vertices[i][1];
- VS::get_singleton()->immediate_vertex(immediate,vtx);
- if (i==0) {
- aabb.pos=vtx;
- aabb.size=Vector3();
+ vtx[x_axis] = vertices[i][0];
+ vtx[y_axis] = vertices[i][1];
+ VS::get_singleton()->immediate_vertex(immediate, vtx);
+ if (i == 0) {
+ aabb.pos = vtx;
+ aabb.size = Vector3();
} else {
aabb.expand_to(vtx);
}
}
set_aabb(aabb);
VS::get_singleton()->immediate_end(immediate);
-
-
}
-void Sprite3D::set_texture(const Ref<Texture>& p_texture) {
+void Sprite3D::set_texture(const Ref<Texture> &p_texture) {
- if (p_texture==texture)
+ if (p_texture == texture)
return;
if (texture.is_valid()) {
- texture->disconnect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_queue_update);
+ texture->disconnect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->_queue_update);
}
- texture=p_texture;
+ texture = p_texture;
if (texture.is_valid()) {
texture->set_flags(texture->get_flags()); //remove repeat from texture, it looks bad in sprites
- texture->connect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_queue_update);
+ texture->connect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->_queue_update);
}
_queue_update();
-
}
Ref<Texture> Sprite3D::get_texture() const {
@@ -492,22 +452,22 @@ Ref<Texture> Sprite3D::get_texture() const {
void Sprite3D::set_region(bool p_region) {
- if (p_region==region)
+ if (p_region == region)
return;
- region=p_region;
+ region = p_region;
_queue_update();
}
-bool Sprite3D::is_region() const{
+bool Sprite3D::is_region() const {
return region;
}
-void Sprite3D::set_region_rect(const Rect2& p_region_rect) {
+void Sprite3D::set_region_rect(const Rect2 &p_region_rect) {
- bool changed=region_rect!=p_region_rect;
- region_rect=p_region_rect;
+ bool changed = region_rect != p_region_rect;
+ region_rect = p_region_rect;
if (region && changed) {
_queue_update();
}
@@ -520,14 +480,13 @@ Rect2 Sprite3D::get_region_rect() const {
void Sprite3D::set_frame(int p_frame) {
- ERR_FAIL_INDEX(p_frame,vframes*hframes);
+ ERR_FAIL_INDEX(p_frame, vframes * hframes);
if (frame != p_frame)
- frame=p_frame;
+ frame = p_frame;
_queue_update();
emit_signal(SceneStringNames::get_singleton()->frame_changed);
-
}
int Sprite3D::get_frame() const {
@@ -537,8 +496,8 @@ int Sprite3D::get_frame() const {
void Sprite3D::set_vframes(int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- vframes=p_amount;
+ ERR_FAIL_COND(p_amount < 1);
+ vframes = p_amount;
_queue_update();
_change_notify("frame");
}
@@ -549,8 +508,8 @@ int Sprite3D::get_vframes() const {
void Sprite3D::set_hframes(int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- hframes=p_amount;
+ ERR_FAIL_COND(p_amount < 1);
+ hframes = p_amount;
_queue_update();
_change_notify("frame");
}
@@ -562,7 +521,7 @@ int Sprite3D::get_hframes() const {
Rect2 Sprite3D::get_item_rect() const {
if (texture.is_null())
- return Rect2(0,0,1,1);
+ return Rect2(0, 0, 1, 1);
/*
if (texture.is_null())
return CanvasItem::get_item_rect();
@@ -572,72 +531,68 @@ Rect2 Sprite3D::get_item_rect() const {
if (region) {
- s=region_rect.size;
+ s = region_rect.size;
} else {
s = texture->get_size();
- s=s/Point2(hframes,vframes);
+ s = s / Point2(hframes, vframes);
}
- Point2i ofs=get_offset();
+ Point2i ofs = get_offset();
if (is_centered())
- ofs-=s/2;
+ ofs -= s / 2;
- if (s==Size2(0,0))
- s=Size2(1,1);
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
- return Rect2(ofs,s);
+ return Rect2(ofs, s);
}
+void Sprite3D::_validate_property(PropertyInfo &property) const {
-void Sprite3D::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="frame") {
+ if (property.name == "frame") {
- property.hint=PROPERTY_HINT_SPRITE_FRAME;
+ property.hint = PROPERTY_HINT_SPRITE_FRAME;
- property.hint_string="0,"+itos(vframes*hframes-1)+",1";
+ property.hint_string = "0," + itos(vframes * hframes - 1) + ",1";
}
}
void Sprite3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture","texture:Texture"),&Sprite3D::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture:Texture"),&Sprite3D::get_texture);
+ ClassDB::bind_method(D_METHOD("set_texture", "texture:Texture"), &Sprite3D::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture:Texture"), &Sprite3D::get_texture);
- ClassDB::bind_method(D_METHOD("set_region","enabled"),&Sprite3D::set_region);
- ClassDB::bind_method(D_METHOD("is_region"),&Sprite3D::is_region);
+ ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite3D::set_region);
+ ClassDB::bind_method(D_METHOD("is_region"), &Sprite3D::is_region);
- ClassDB::bind_method(D_METHOD("set_region_rect","rect"),&Sprite3D::set_region_rect);
- ClassDB::bind_method(D_METHOD("get_region_rect"),&Sprite3D::get_region_rect);
+ ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite3D::set_region_rect);
+ ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite3D::get_region_rect);
- ClassDB::bind_method(D_METHOD("set_frame","frame"),&Sprite3D::set_frame);
- ClassDB::bind_method(D_METHOD("get_frame"),&Sprite3D::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame", "frame"), &Sprite3D::set_frame);
+ ClassDB::bind_method(D_METHOD("get_frame"), &Sprite3D::get_frame);
- ClassDB::bind_method(D_METHOD("set_vframes","vframes"),&Sprite3D::set_vframes);
- ClassDB::bind_method(D_METHOD("get_vframes"),&Sprite3D::get_vframes);
+ ClassDB::bind_method(D_METHOD("set_vframes", "vframes"), &Sprite3D::set_vframes);
+ ClassDB::bind_method(D_METHOD("get_vframes"), &Sprite3D::get_vframes);
- ClassDB::bind_method(D_METHOD("set_hframes","hframes"),&Sprite3D::set_hframes);
- ClassDB::bind_method(D_METHOD("get_hframes"),&Sprite3D::get_hframes);
+ ClassDB::bind_method(D_METHOD("set_hframes", "hframes"), &Sprite3D::set_hframes);
+ ClassDB::bind_method(D_METHOD("get_hframes"), &Sprite3D::get_hframes);
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_texture","get_texture");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "vframes",PROPERTY_HINT_RANGE,"1,16384,1"), "set_vframes","get_vframes");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "hframes",PROPERTY_HINT_RANGE,"1,16384,1"), "set_hframes","get_hframes");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), "set_frame","get_frame");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "region"), "set_region","is_region");
- ADD_PROPERTY( PropertyInfo( Variant::RECT2, "region_rect"), "set_region_rect","get_region_rect");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "vframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_vframes", "get_vframes");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "hframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_hframes", "get_hframes");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "region"), "set_region", "is_region");
+ ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect");
ADD_SIGNAL(MethodInfo("frame_changed"));
-
}
Sprite3D::Sprite3D() {
-
- region=false;
- frame=0;
- vframes=1;
- hframes=1;
-
+ region = false;
+ frame = 0;
+ vframes = 1;
+ hframes = 1;
}
////////////////////////////////////////
@@ -853,22 +808,18 @@ AnimatedSprite3D::AnimatedSprite3D() {
frame=0;
}
-
-
#endif
-
void AnimatedSprite3D::_draw() {
RID immediate = get_immediate();
VS::get_singleton()->immediate_clear(immediate);
-
if (frames.is_null()) {
return;
}
- if (frame<0) {
+ if (frame < 0) {
return;
}
@@ -876,195 +827,185 @@ void AnimatedSprite3D::_draw() {
return;
}
-
- Ref<Texture> texture = frames->get_frame(animation,frame);
+ Ref<Texture> texture = frames->get_frame(animation, frame);
if (!texture.is_valid())
return; //no texuture no life
Vector2 tsize = texture->get_size();
- if (tsize.x==0 || tsize.y==0)
+ if (tsize.x == 0 || tsize.y == 0)
return;
- Size2i s=tsize;
+ Size2i s = tsize;
Rect2i src_rect;
- src_rect.size=s;
+ src_rect.size = s;
- Point2i ofs=get_offset();
+ Point2i ofs = get_offset();
if (is_centered())
- ofs-=s/2;
-
- Rect2i dst_rect(ofs,s);
+ ofs -= s / 2;
+ Rect2i dst_rect(ofs, s);
Rect2 final_rect;
Rect2 final_src_rect;
- if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect))
+ if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect))
return;
-
- if (final_rect.size.x==0 || final_rect.size.y==0)
+ if (final_rect.size.x == 0 || final_rect.size.y == 0)
return;
- Color color=_get_color_accum();
- color.a*=get_opacity();
+ Color color = _get_color_accum();
+ color.a *= get_opacity();
- float pixel_size=get_pixel_size();
+ float pixel_size = get_pixel_size();
- Vector2 vertices[4]={
+ Vector2 vertices[4] = {
- (final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size,
- (final_rect.pos+final_rect.size) * pixel_size,
- (final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size,
+ (final_rect.pos + Vector2(0, final_rect.size.y)) * pixel_size,
+ (final_rect.pos + final_rect.size) * pixel_size,
+ (final_rect.pos + Vector2(final_rect.size.x, 0)) * pixel_size,
final_rect.pos * pixel_size,
-
};
- Vector2 uvs[4]={
+ Vector2 uvs[4] = {
final_src_rect.pos / tsize,
- (final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize,
- (final_src_rect.pos+final_src_rect.size) / tsize,
- (final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize,
+ (final_src_rect.pos + Vector2(final_src_rect.size.x, 0)) / tsize,
+ (final_src_rect.pos + final_src_rect.size) / tsize,
+ (final_src_rect.pos + Vector2(0, final_src_rect.size.y)) / tsize,
};
if (is_flipped_h()) {
- SWAP(uvs[0],uvs[1]);
- SWAP(uvs[2],uvs[3]);
+ SWAP(uvs[0], uvs[1]);
+ SWAP(uvs[2], uvs[3]);
}
if (is_flipped_v()) {
- SWAP(uvs[0],uvs[3]);
- SWAP(uvs[1],uvs[2]);
+ SWAP(uvs[0], uvs[3]);
+ SWAP(uvs[1], uvs[2]);
}
-
Vector3 normal;
int axis = get_axis();
- normal[axis]=1.0;
+ normal[axis] = 1.0;
- RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS);
- VS::get_singleton()->immediate_set_material(immediate,mat);
+ RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS);
+ VS::get_singleton()->immediate_set_material(immediate, mat);
- VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid());
+ VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLE_FAN, texture->get_rid());
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
- if (axis!=Vector3::AXIS_Z) {
- SWAP(x_axis,y_axis);
+ if (axis != Vector3::AXIS_Z) {
+ SWAP(x_axis, y_axis);
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
//uvs[i] = Vector2(1.0,1.0)-uvs[i];
//SWAP(vertices[i].x,vertices[i].y);
- if (axis==Vector3::AXIS_Y) {
- vertices[i].y = - vertices[i].y;
- } else if (axis==Vector3::AXIS_X) {
- vertices[i].x = - vertices[i].x;
+ if (axis == Vector3::AXIS_Y) {
+ vertices[i].y = -vertices[i].y;
+ } else if (axis == Vector3::AXIS_X) {
+ vertices[i].x = -vertices[i].x;
}
}
}
Rect3 aabb;
- for(int i=0;i<4;i++) {
- VS::get_singleton()->immediate_normal(immediate,normal);
- VS::get_singleton()->immediate_color(immediate,color);
- VS::get_singleton()->immediate_uv(immediate,uvs[i]);
+ for (int i = 0; i < 4; i++) {
+ VS::get_singleton()->immediate_normal(immediate, normal);
+ VS::get_singleton()->immediate_color(immediate, color);
+ VS::get_singleton()->immediate_uv(immediate, uvs[i]);
Vector3 vtx;
- vtx[x_axis]=vertices[i][0];
- vtx[y_axis]=vertices[i][1];
- VS::get_singleton()->immediate_vertex(immediate,vtx);
- if (i==0) {
- aabb.pos=vtx;
- aabb.size=Vector3();
+ vtx[x_axis] = vertices[i][0];
+ vtx[y_axis] = vertices[i][1];
+ VS::get_singleton()->immediate_vertex(immediate, vtx);
+ if (i == 0) {
+ aabb.pos = vtx;
+ aabb.size = Vector3();
} else {
aabb.expand_to(vtx);
}
}
set_aabb(aabb);
VS::get_singleton()->immediate_end(immediate);
-
}
-
-
-void AnimatedSprite3D::_validate_property(PropertyInfo& property) const {
+void AnimatedSprite3D::_validate_property(PropertyInfo &property) const {
if (!frames.is_valid())
return;
- if (property.name=="animation") {
+ if (property.name == "animation") {
- property.hint=PROPERTY_HINT_ENUM;
+ property.hint = PROPERTY_HINT_ENUM;
List<StringName> names;
frames->get_animation_list(&names);
names.sort_custom<StringName::AlphCompare>();
- bool current_found=false;
+ bool current_found = false;
- for (List<StringName>::Element *E=names.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
if (E->prev()) {
- property.hint_string+=",";
+ property.hint_string += ",";
}
- property.hint_string+=String(E->get());
- if (animation==E->get()) {
- current_found=true;
+ property.hint_string += String(E->get());
+ if (animation == E->get()) {
+ current_found = true;
}
}
if (!current_found) {
- if (property.hint_string==String()) {
- property.hint_string=String(animation);
+ if (property.hint_string == String()) {
+ property.hint_string = String(animation);
} else {
- property.hint_string=String(animation)+","+property.hint_string;
+ property.hint_string = String(animation) + "," + property.hint_string;
}
}
}
+ if (property.name == "frame") {
- if (property.name=="frame") {
-
- property.hint=PROPERTY_HINT_RANGE;
+ property.hint = PROPERTY_HINT_RANGE;
if (frames->has_animation(animation)) {
- property.hint_string="0,"+itos(frames->get_frame_count(animation)-1)+",1";
+ property.hint_string = "0," + itos(frames->get_frame_count(animation) - 1) + ",1";
} else {
- property.hint_string="0,0,0";
+ property.hint_string = "0,0,0";
}
}
-
}
void AnimatedSprite3D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
if (frames.is_null())
return;
if (!frames->has_animation(animation))
return;
- if (frame<0)
+ if (frame < 0)
return;
float speed = frames->get_animation_speed(animation);
- if (speed==0)
+ if (speed == 0)
return; //do nothing
float remaining = get_process_delta_time();
- while(remaining) {
+ while (remaining) {
- if (timeout<=0) {
+ if (timeout <= 0) {
- timeout=1.0/speed;
+ timeout = 1.0 / speed;
int fc = frames->get_frame_count(animation);
- if (frame>=fc-1) {
+ if (frame >= fc - 1) {
if (frames->get_animation_loop(animation)) {
- frame=0;
+ frame = 0;
} else {
- frame=fc-1;
+ frame = fc - 1;
}
} else {
frame++;
@@ -1074,9 +1015,9 @@ void AnimatedSprite3D::_notification(int p_what) {
_change_notify("frame");
}
- float to_process = MIN(timeout,remaining);
- remaining-=to_process;
- timeout-=to_process;
+ float to_process = MIN(timeout, remaining);
+ remaining -= to_process;
+ timeout -= to_process;
}
} break;
#if 0
@@ -1137,30 +1078,26 @@ void AnimatedSprite3D::_notification(int p_what) {
} break;
#endif
}
-
}
void AnimatedSprite3D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
if (frames.is_valid())
- frames->disconnect("changed",this,"_res_changed");
- frames=p_frames;
+ frames->disconnect("changed", this, "_res_changed");
+ frames = p_frames;
if (frames.is_valid())
- frames->connect("changed",this,"_res_changed");
+ frames->connect("changed", this, "_res_changed");
if (!frames.is_valid()) {
- frame=0;
+ frame = 0;
} else {
set_frame(frame);
}
-
-
_change_notify();
_reset_timeout();
_queue_update();
update_configuration_warning();
-
}
Ref<SpriteFrames> AnimatedSprite3D::get_sprite_frames() const {
@@ -1176,55 +1113,48 @@ void AnimatedSprite3D::set_frame(int p_frame) {
if (frames->has_animation(animation)) {
int limit = frames->get_frame_count(animation);
- if (p_frame>=limit)
- p_frame=limit-1;
-
+ if (p_frame >= limit)
+ p_frame = limit - 1;
}
- if (p_frame<0)
- p_frame=0;
+ if (p_frame < 0)
+ p_frame = 0;
-
- if (frame==p_frame)
+ if (frame == p_frame)
return;
- frame=p_frame;
+ frame = p_frame;
_reset_timeout();
_queue_update();
_change_notify("frame");
emit_signal(SceneStringNames::get_singleton()->frame_changed);
-
-
-
}
int AnimatedSprite3D::get_frame() const {
return frame;
}
-
-
Rect2 AnimatedSprite3D::get_item_rect() const {
- if (!frames.is_valid() || !frames->has_animation(animation) || frame<0 || frame>=frames->get_frame_count(animation)) {
- return Rect2(0,0,1,1);
+ if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
+ return Rect2(0, 0, 1, 1);
}
Ref<Texture> t;
if (animation)
- t = frames->get_frame(animation,frame);
+ t = frames->get_frame(animation, frame);
if (t.is_null())
- return Rect2(0,0,1,1);
+ return Rect2(0, 0, 1, 1);
Size2i s = t->get_size();
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
- if (s==Size2(0,0))
- s=Size2(1,1);
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
- return Rect2(ofs,s);
+ return Rect2(ofs, s);
}
void AnimatedSprite3D::_res_changed() {
@@ -1237,9 +1167,9 @@ void AnimatedSprite3D::_res_changed() {
void AnimatedSprite3D::_set_playing(bool p_playing) {
- if (playing==p_playing)
+ if (playing == p_playing)
return;
- playing=p_playing;
+ playing = p_playing;
_reset_timeout();
set_process_internal(playing);
}
@@ -1249,14 +1179,14 @@ bool AnimatedSprite3D::_is_playing() const {
return playing;
}
-void AnimatedSprite3D::play(const StringName& p_animation) {
+void AnimatedSprite3D::play(const StringName &p_animation) {
if (p_animation)
set_animation(p_animation);
_set_playing(true);
}
-void AnimatedSprite3D::stop(){
+void AnimatedSprite3D::stop() {
_set_playing(false);
}
@@ -1273,29 +1203,28 @@ void AnimatedSprite3D::_reset_timeout() {
if (frames.is_valid() && frames->has_animation(animation)) {
float speed = frames->get_animation_speed(animation);
- if (speed>0) {
- timeout=1.0/speed;
+ if (speed > 0) {
+ timeout = 1.0 / speed;
} else {
- timeout=0;
+ timeout = 0;
}
} else {
- timeout=0;
+ timeout = 0;
}
-
}
-void AnimatedSprite3D::set_animation(const StringName& p_animation){
+void AnimatedSprite3D::set_animation(const StringName &p_animation) {
- if (animation==p_animation)
+ if (animation == p_animation)
return;
- animation=p_animation;
+ animation = p_animation;
_reset_timeout();
set_frame(0);
_change_notify();
_queue_update();
}
-StringName AnimatedSprite3D::get_animation() const{
+StringName AnimatedSprite3D::get_animation() const {
return animation;
}
@@ -1311,44 +1240,36 @@ String AnimatedSprite3D::get_configuration_warning() const {
void AnimatedSprite3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames:SpriteFrames"), &AnimatedSprite3D::set_sprite_frames);
+ ClassDB::bind_method(D_METHOD("get_sprite_frames:SpriteFrames"), &AnimatedSprite3D::get_sprite_frames);
- ClassDB::bind_method(D_METHOD("set_sprite_frames","sprite_frames:SpriteFrames"),&AnimatedSprite3D::set_sprite_frames);
- ClassDB::bind_method(D_METHOD("get_sprite_frames:SpriteFrames"),&AnimatedSprite3D::get_sprite_frames);
+ ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite3D::set_animation);
+ ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite3D::get_animation);
- ClassDB::bind_method(D_METHOD("set_animation","animation"),&AnimatedSprite3D::set_animation);
- ClassDB::bind_method(D_METHOD("get_animation"),&AnimatedSprite3D::get_animation);
+ ClassDB::bind_method(D_METHOD("_set_playing", "playing"), &AnimatedSprite3D::_set_playing);
+ ClassDB::bind_method(D_METHOD("_is_playing"), &AnimatedSprite3D::_is_playing);
- ClassDB::bind_method(D_METHOD("_set_playing","playing"),&AnimatedSprite3D::_set_playing);
- ClassDB::bind_method(D_METHOD("_is_playing"),&AnimatedSprite3D::_is_playing);
+ ClassDB::bind_method(D_METHOD("play", "anim"), &AnimatedSprite3D::play, DEFVAL(StringName()));
+ ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite3D::stop);
+ ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite3D::is_playing);
- ClassDB::bind_method(D_METHOD("play","anim"),&AnimatedSprite3D::play,DEFVAL(StringName()));
- ClassDB::bind_method(D_METHOD("stop"),&AnimatedSprite3D::stop);
- ClassDB::bind_method(D_METHOD("is_playing"),&AnimatedSprite3D::is_playing);
+ ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite3D::set_frame);
+ ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite3D::get_frame);
-
- ClassDB::bind_method(D_METHOD("set_frame","frame"),&AnimatedSprite3D::set_frame);
- ClassDB::bind_method(D_METHOD("get_frame"),&AnimatedSprite3D::get_frame);
-
- ClassDB::bind_method(D_METHOD("_res_changed"),&AnimatedSprite3D::_res_changed);
+ ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite3D::_res_changed);
ADD_SIGNAL(MethodInfo("frame_changed"));
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "frames",PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), "set_sprite_frames","get_sprite_frames");
- ADD_PROPERTY( PropertyInfo( Variant::STRING, "animation"), "set_animation","get_animation");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), "set_frame","get_frame");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "playing"), "_set_playing","_is_playing");
-
-
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing");
}
AnimatedSprite3D::AnimatedSprite3D() {
- frame=0;
- playing=false;
- animation="default";
- timeout=0;
-
-
+ frame = 0;
+ playing = false;
+ animation = "default";
+ timeout = 0;
}
-
-
diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h
index a14ce40495..d1de4e1b88 100644
--- a/scene/3d/sprite_3d.h
+++ b/scene/3d/sprite_3d.h
@@ -29,15 +29,14 @@
#ifndef SPRITE_3D_H
#define SPRITE_3D_H
-#include "scene/3d/visual_instance.h"
#include "scene/2d/animated_sprite.h"
-
+#include "scene/3d/visual_instance.h"
class SpriteBase3D : public GeometryInstance {
- GDCLASS(SpriteBase3D,GeometryInstance);
-public:
+ GDCLASS(SpriteBase3D, GeometryInstance);
+public:
enum DrawFlags {
FLAG_TRANSPARENT,
FLAG_SHADED,
@@ -52,14 +51,12 @@ public:
};
private:
-
-
bool color_dirty;
Color color_accum;
SpriteBase3D *parent_sprite;
- List<SpriteBase3D*> children;
- List<SpriteBase3D*>::Element *pI;
+ List<SpriteBase3D *> children;
+ List<SpriteBase3D *>::Element *pI;
bool centered;
Point2 offset;
@@ -67,7 +64,6 @@ private:
bool hflip;
bool vflip;
-
Color modulate;
float opacity;
@@ -82,24 +78,22 @@ private:
bool pending_update;
void _im_update();
-
void _propagate_color_changed();
protected:
-
Color _get_color_accum();
void _notification(int p_what);
static void _bind_methods();
- virtual void _draw()=0;
- _FORCE_INLINE_ void set_aabb(const Rect3& p_aabb) { aabb=p_aabb; }
- _FORCE_INLINE_ RID& get_immediate() { return immediate; }
+ virtual void _draw() = 0;
+ _FORCE_INLINE_ void set_aabb(const Rect3 &p_aabb) { aabb = p_aabb; }
+ _FORCE_INLINE_ RID &get_immediate() { return immediate; }
void _queue_update();
-public:
+public:
void set_centered(bool p_center);
bool is_centered() const;
- void set_offset(const Point2& p_offset);
+ void set_offset(const Point2 &p_offset);
Point2 get_offset() const;
void set_flip_h(bool p_flip);
@@ -111,10 +105,10 @@ public:
void set_region(bool p_region);
bool is_region() const;
- void set_region_rect(const Rect2& p_region_rect);
+ void set_region_rect(const Rect2 &p_region_rect);
Rect2 get_region_rect() const;
- void set_modulate(const Color& p_color);
+ void set_modulate(const Color &p_color);
Color get_modulate() const;
void set_opacity(float p_amount);
@@ -126,13 +120,13 @@ public:
void set_axis(Vector3::Axis p_amount);
Vector3::Axis get_axis() const;
- void set_draw_flag(DrawFlags p_flag,bool p_enable);
+ void set_draw_flag(DrawFlags p_flag, bool p_enable);
bool get_draw_flag(DrawFlags p_flag) const;
void set_alpha_cut_mode(AlphaCutMode p_mode);
AlphaCutMode get_alpha_cut_mode() const;
- virtual Rect2 get_item_rect() const=0;
+ virtual Rect2 get_item_rect() const = 0;
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
@@ -141,13 +135,11 @@ public:
~SpriteBase3D();
};
-
class Sprite3D : public SpriteBase3D {
- GDCLASS(Sprite3D,SpriteBase3D);
+ GDCLASS(Sprite3D, SpriteBase3D);
Ref<Texture> texture;
-
bool region;
Rect2 region_rect;
@@ -155,22 +147,21 @@ class Sprite3D : public SpriteBase3D {
int vframes;
int hframes;
+
protected:
virtual void _draw();
static void _bind_methods();
- virtual void _validate_property(PropertyInfo& property) const;
-public:
-
+ virtual void _validate_property(PropertyInfo &property) const;
-
- void set_texture(const Ref<Texture>& p_texture);
+public:
+ void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
void set_region(bool p_region);
bool is_region() const;
- void set_region_rect(const Rect2& p_region_rect);
+ void set_region_rect(const Rect2 &p_region_rect);
Rect2 get_region_rect() const;
void set_frame(int p_frame);
@@ -219,12 +210,9 @@ public:
};
#endif
-
-
-
class AnimatedSprite3D : public SpriteBase3D {
- GDCLASS(AnimatedSprite3D,SpriteBase3D);
+ GDCLASS(AnimatedSprite3D, SpriteBase3D);
Ref<SpriteFrames> frames;
bool playing;
@@ -247,39 +235,32 @@ class AnimatedSprite3D : public SpriteBase3D {
void _set_playing(bool p_playing);
bool _is_playing() const;
-
protected:
-
virtual void _draw();
static void _bind_methods();
void _notification(int p_what);
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
public:
-
-
-
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
Ref<SpriteFrames> get_sprite_frames() const;
- void play(const StringName& p_animation=StringName());
+ void play(const StringName &p_animation = StringName());
void stop();
bool is_playing() const;
- void set_animation(const StringName& p_animation);
+ void set_animation(const StringName &p_animation);
StringName get_animation() const;
void set_frame(int p_frame);
int get_frame() const;
-
virtual Rect2 get_item_rect() const;
virtual String get_configuration_warning() const;
AnimatedSprite3D();
};
-
VARIANT_ENUM_CAST(SpriteBase3D::DrawFlags);
VARIANT_ENUM_CAST(SpriteBase3D::AlphaCutMode);
#endif // SPRITE_3D_H
diff --git a/scene/3d/test_cube.cpp b/scene/3d/test_cube.cpp
index c52e596032..bab1d1e1c8 100644
--- a/scene/3d/test_cube.cpp
+++ b/scene/3d/test_cube.cpp
@@ -29,25 +29,19 @@
#include "test_cube.h"
#include "servers/visual_server.h"
-
-
Rect3 TestCube::get_aabb() const {
- return Rect3( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) );
+ return Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2));
}
PoolVector<Face3> TestCube::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
}
-
TestCube::TestCube() {
set_base(VisualServer::get_singleton()->get_test_cube());
}
-
TestCube::~TestCube() {
}
-
-
diff --git a/scene/3d/test_cube.h b/scene/3d/test_cube.h
index 4860bacd8d..d03bea7b68 100644
--- a/scene/3d/test_cube.h
+++ b/scene/3d/test_cube.h
@@ -29,29 +29,24 @@
#ifndef TEST_CUBE_H
#define TEST_CUBE_H
-
-#include "scene/3d/visual_instance.h"
#include "rid.h"
-
+#include "scene/3d/visual_instance.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class TestCube : public GeometryInstance {
- GDCLASS( TestCube, GeometryInstance );
+ GDCLASS(TestCube, GeometryInstance);
RID instance;
-
public:
-
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
TestCube();
~TestCube();
-
};
#endif
diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp
index 4b32c62d14..4a647fe682 100644
--- a/scene/3d/vehicle_body.cpp
+++ b/scene/3d/vehicle_body.cpp
@@ -30,78 +30,70 @@
#define ROLLING_INFLUENCE_FIX
-class btVehicleJacobianEntry
-{
+class btVehicleJacobianEntry {
public:
-
- Vector3 m_linearJointAxis;
- Vector3 m_aJ;
- Vector3 m_bJ;
- Vector3 m_0MinvJt;
- Vector3 m_1MinvJt;
+ Vector3 m_linearJointAxis;
+ Vector3 m_aJ;
+ Vector3 m_bJ;
+ Vector3 m_0MinvJt;
+ Vector3 m_1MinvJt;
//Optimization: can be stored in the w/last component of one of the vectors
- real_t m_Adiag;
+ real_t m_Adiag;
real_t getDiagonal() const { return m_Adiag; }
- btVehicleJacobianEntry() {};
- //constraint between two different rigidbodies
- btVehicleJacobianEntry(
- const Basis& world2A,
- const Basis& world2B,
- const Vector3& rel_pos1,
- const Vector3& rel_pos2,
- const Vector3& jointAxis,
- const Vector3& inertiaInvA,
+ btVehicleJacobianEntry(){};
+ //constraint between two different rigidbodies
+ btVehicleJacobianEntry(
+ const Basis &world2A,
+ const Basis &world2B,
+ const Vector3 &rel_pos1,
+ const Vector3 &rel_pos2,
+ const Vector3 &jointAxis,
+ const Vector3 &inertiaInvA,
const real_t massInvA,
- const Vector3& inertiaInvB,
+ const Vector3 &inertiaInvB,
const real_t massInvB)
- :m_linearJointAxis(jointAxis)
- {
- m_aJ = world2A.xform(rel_pos1.cross(m_linearJointAxis));
- m_bJ = world2B.xform(rel_pos2.cross(-m_linearJointAxis));
- m_0MinvJt = inertiaInvA * m_aJ;
- m_1MinvJt = inertiaInvB * m_bJ;
- m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ);
-
- //btAssert(m_Adiag > real_t(0.0));
- }
-
- real_t getRelativeVelocity(const Vector3& linvelA,const Vector3& angvelA,const Vector3& linvelB,const Vector3& angvelB)
- {
- Vector3 linrel = linvelA - linvelB;
- Vector3 angvela = angvelA * m_aJ;
- Vector3 angvelb = angvelB * m_bJ;
- linrel *= m_linearJointAxis;
- angvela += angvelb;
- angvela += linrel;
- real_t rel_vel2 = angvela[0]+angvela[1]+angvela[2];
- return rel_vel2 + CMP_EPSILON;
- }
-
+ : m_linearJointAxis(jointAxis) {
+ m_aJ = world2A.xform(rel_pos1.cross(m_linearJointAxis));
+ m_bJ = world2B.xform(rel_pos2.cross(-m_linearJointAxis));
+ m_0MinvJt = inertiaInvA * m_aJ;
+ m_1MinvJt = inertiaInvB * m_bJ;
+ m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ);
+
+ //btAssert(m_Adiag > real_t(0.0));
+ }
+ real_t getRelativeVelocity(const Vector3 &linvelA, const Vector3 &angvelA, const Vector3 &linvelB, const Vector3 &angvelB) {
+ Vector3 linrel = linvelA - linvelB;
+ Vector3 angvela = angvelA * m_aJ;
+ Vector3 angvelb = angvelB * m_bJ;
+ linrel *= m_linearJointAxis;
+ angvela += angvelb;
+ angvela += linrel;
+ real_t rel_vel2 = angvela[0] + angvela[1] + angvela[2];
+ return rel_vel2 + CMP_EPSILON;
+ }
};
void VehicleWheel::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
if (!get_parent())
return;
VehicleBody *cb = get_parent()->cast_to<VehicleBody>();
if (!cb)
return;
- body=cb;
- local_xform=get_transform();
+ body = cb;
+ local_xform = get_transform();
cb->wheels.push_back(this);
m_chassisConnectionPointCS = get_transform().origin;
m_wheelDirectionCS = -get_transform().basis.get_axis(Vector3::AXIS_Y).normalized();
m_wheelAxleCS = get_transform().basis.get_axis(Vector3::AXIS_X).normalized();
-
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
+ if (p_what == NOTIFICATION_EXIT_TREE) {
if (!get_parent())
return;
@@ -109,34 +101,27 @@ void VehicleWheel::_notification(int p_what) {
if (!cb)
return;
cb->wheels.erase(this);
- body=NULL;
+ body = NULL;
}
-
}
-
void VehicleWheel::_update(PhysicsDirectBodyState *s) {
-
-
if (m_raycastInfo.m_isInContact)
{
- real_t project= m_raycastInfo.m_contactNormalWS.dot( m_raycastInfo.m_wheelDirectionWS );
- Vector3 chassis_velocity_at_contactPoint;
+ real_t project = m_raycastInfo.m_contactNormalWS.dot(m_raycastInfo.m_wheelDirectionWS);
+ Vector3 chassis_velocity_at_contactPoint;
Vector3 relpos = m_raycastInfo.m_contactPointWS - s->get_transform().origin;
chassis_velocity_at_contactPoint = s->get_linear_velocity() +
- (s->get_angular_velocity()).cross(relpos);// * mPos);
+ (s->get_angular_velocity()).cross(relpos); // * mPos);
- real_t projVel = m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );
- if ( project >= real_t(-0.1))
- {
+ real_t projVel = m_raycastInfo.m_contactNormalWS.dot(chassis_velocity_at_contactPoint);
+ if (project >= real_t(-0.1)) {
m_suspensionRelativeVelocity = real_t(0.0);
m_clippedInvContactDotSuspension = real_t(1.0) / real_t(0.1);
- }
- else
- {
+ } else {
real_t inv = real_t(-1.) / project;
m_suspensionRelativeVelocity = projVel * inv;
m_clippedInvContactDotSuspension = inv;
@@ -144,7 +129,7 @@ void VehicleWheel::_update(PhysicsDirectBodyState *s) {
}
- else // Not in contact : position wheel in a nice (rest length) position
+ else // Not in contact : position wheel in a nice (rest length) position
{
m_raycastInfo.m_suspensionLength = m_suspensionRestLength;
m_suspensionRelativeVelocity = real_t(0.0);
@@ -155,160 +140,150 @@ void VehicleWheel::_update(PhysicsDirectBodyState *s) {
void VehicleWheel::set_radius(float p_radius) {
- m_wheelRadius=p_radius;
+ m_wheelRadius = p_radius;
update_gizmo();
}
-float VehicleWheel::get_radius() const{
+float VehicleWheel::get_radius() const {
return m_wheelRadius;
}
-void VehicleWheel::set_suspension_rest_length(float p_length){
+void VehicleWheel::set_suspension_rest_length(float p_length) {
- m_suspensionRestLength=p_length;
+ m_suspensionRestLength = p_length;
update_gizmo();
}
-float VehicleWheel::get_suspension_rest_length() const{
+float VehicleWheel::get_suspension_rest_length() const {
return m_suspensionRestLength;
}
-void VehicleWheel::set_suspension_travel(float p_length){
+void VehicleWheel::set_suspension_travel(float p_length) {
- m_maxSuspensionTravelCm=p_length/0.01;
+ m_maxSuspensionTravelCm = p_length / 0.01;
}
-float VehicleWheel::get_suspension_travel() const{
+float VehicleWheel::get_suspension_travel() const {
- return m_maxSuspensionTravelCm*0.01;
+ return m_maxSuspensionTravelCm * 0.01;
}
-void VehicleWheel::set_suspension_stiffness(float p_value){
+void VehicleWheel::set_suspension_stiffness(float p_value) {
- m_suspensionStiffness=p_value;
+ m_suspensionStiffness = p_value;
}
-float VehicleWheel::get_suspension_stiffness() const{
+float VehicleWheel::get_suspension_stiffness() const {
return m_suspensionStiffness;
}
-void VehicleWheel::set_suspension_max_force(float p_value){
+void VehicleWheel::set_suspension_max_force(float p_value) {
- m_maxSuspensionForce=p_value;
+ m_maxSuspensionForce = p_value;
}
-float VehicleWheel::get_suspension_max_force() const{
+float VehicleWheel::get_suspension_max_force() const {
return m_maxSuspensionForce;
}
-void VehicleWheel::set_damping_compression(float p_value){
+void VehicleWheel::set_damping_compression(float p_value) {
- m_wheelsDampingCompression=p_value;
+ m_wheelsDampingCompression = p_value;
}
-float VehicleWheel::get_damping_compression() const{
+float VehicleWheel::get_damping_compression() const {
return m_wheelsDampingCompression;
}
-void VehicleWheel::set_damping_relaxation(float p_value){
+void VehicleWheel::set_damping_relaxation(float p_value) {
- m_wheelsDampingRelaxation=p_value;
+ m_wheelsDampingRelaxation = p_value;
}
-float VehicleWheel::get_damping_relaxation() const{
+float VehicleWheel::get_damping_relaxation() const {
return m_wheelsDampingRelaxation;
}
void VehicleWheel::set_friction_slip(float p_value) {
- m_frictionSlip=p_value;
+ m_frictionSlip = p_value;
}
-float VehicleWheel::get_friction_slip() const{
+float VehicleWheel::get_friction_slip() const {
return m_frictionSlip;
}
-
void VehicleWheel::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel::set_radius);
+ ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel::get_radius);
- ClassDB::bind_method(D_METHOD("set_radius","length"),&VehicleWheel::set_radius);
- ClassDB::bind_method(D_METHOD("get_radius"),&VehicleWheel::get_radius);
-
- ClassDB::bind_method(D_METHOD("set_suspension_rest_length","length"),&VehicleWheel::set_suspension_rest_length);
- ClassDB::bind_method(D_METHOD("get_suspension_rest_length"),&VehicleWheel::get_suspension_rest_length);
-
- ClassDB::bind_method(D_METHOD("set_suspension_travel","length"),&VehicleWheel::set_suspension_travel);
- ClassDB::bind_method(D_METHOD("get_suspension_travel"),&VehicleWheel::get_suspension_travel);
-
- ClassDB::bind_method(D_METHOD("set_suspension_stiffness","length"),&VehicleWheel::set_suspension_stiffness);
- ClassDB::bind_method(D_METHOD("get_suspension_stiffness"),&VehicleWheel::get_suspension_stiffness);
-
- ClassDB::bind_method(D_METHOD("set_suspension_max_force","length"),&VehicleWheel::set_suspension_max_force);
- ClassDB::bind_method(D_METHOD("get_suspension_max_force"),&VehicleWheel::get_suspension_max_force);
+ ClassDB::bind_method(D_METHOD("set_suspension_rest_length", "length"), &VehicleWheel::set_suspension_rest_length);
+ ClassDB::bind_method(D_METHOD("get_suspension_rest_length"), &VehicleWheel::get_suspension_rest_length);
+ ClassDB::bind_method(D_METHOD("set_suspension_travel", "length"), &VehicleWheel::set_suspension_travel);
+ ClassDB::bind_method(D_METHOD("get_suspension_travel"), &VehicleWheel::get_suspension_travel);
- ClassDB::bind_method(D_METHOD("set_damping_compression","length"),&VehicleWheel::set_damping_compression);
- ClassDB::bind_method(D_METHOD("get_damping_compression"),&VehicleWheel::get_damping_compression);
+ ClassDB::bind_method(D_METHOD("set_suspension_stiffness", "length"), &VehicleWheel::set_suspension_stiffness);
+ ClassDB::bind_method(D_METHOD("get_suspension_stiffness"), &VehicleWheel::get_suspension_stiffness);
- ClassDB::bind_method(D_METHOD("set_damping_relaxation","length"),&VehicleWheel::set_damping_relaxation);
- ClassDB::bind_method(D_METHOD("get_damping_relaxation"),&VehicleWheel::get_damping_relaxation);
+ ClassDB::bind_method(D_METHOD("set_suspension_max_force", "length"), &VehicleWheel::set_suspension_max_force);
+ ClassDB::bind_method(D_METHOD("get_suspension_max_force"), &VehicleWheel::get_suspension_max_force);
- ClassDB::bind_method(D_METHOD("set_use_as_traction","enable"),&VehicleWheel::set_use_as_traction);
- ClassDB::bind_method(D_METHOD("is_used_as_traction"),&VehicleWheel::is_used_as_traction);
+ ClassDB::bind_method(D_METHOD("set_damping_compression", "length"), &VehicleWheel::set_damping_compression);
+ ClassDB::bind_method(D_METHOD("get_damping_compression"), &VehicleWheel::get_damping_compression);
- ClassDB::bind_method(D_METHOD("set_use_as_steering","enable"),&VehicleWheel::set_use_as_steering);
- ClassDB::bind_method(D_METHOD("is_used_as_steering"),&VehicleWheel::is_used_as_steering);
+ ClassDB::bind_method(D_METHOD("set_damping_relaxation", "length"), &VehicleWheel::set_damping_relaxation);
+ ClassDB::bind_method(D_METHOD("get_damping_relaxation"), &VehicleWheel::get_damping_relaxation);
- ClassDB::bind_method(D_METHOD("set_friction_slip","length"),&VehicleWheel::set_friction_slip);
- ClassDB::bind_method(D_METHOD("get_friction_slip"),&VehicleWheel::get_friction_slip);
+ ClassDB::bind_method(D_METHOD("set_use_as_traction", "enable"), &VehicleWheel::set_use_as_traction);
+ ClassDB::bind_method(D_METHOD("is_used_as_traction"), &VehicleWheel::is_used_as_traction);
+ ClassDB::bind_method(D_METHOD("set_use_as_steering", "enable"), &VehicleWheel::set_use_as_steering);
+ ClassDB::bind_method(D_METHOD("is_used_as_steering"), &VehicleWheel::is_used_as_steering);
+ ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel::set_friction_slip);
+ ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel::get_friction_slip);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"use_as_traction"),"set_use_as_traction","is_used_as_traction");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"use_as_steering"),"set_use_as_steering","is_used_as_steering");
- ADD_GROUP("Wheel","wheel_");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"wheel_radius"),"set_radius","get_radius");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"wheel_rest_length"),"set_suspension_rest_length","get_suspension_rest_length");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"wheel_friction_slip"),"set_friction_slip","get_friction_slip");
- ADD_GROUP("Suspension","suspension_");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"suspension_travel"),"set_suspension_travel","get_suspension_travel");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"suspension_stiffness"),"set_suspension_stiffness","get_suspension_stiffness");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"suspension_max_force"),"set_suspension_max_force","get_suspension_max_force");
- ADD_GROUP("Damping","damping_");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"damping_compression"),"set_damping_compression","get_damping_compression");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"damping_relaxation"),"set_damping_relaxation","get_damping_relaxation");
-
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering");
+ ADD_GROUP("Wheel", "wheel_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_radius"), "set_radius", "get_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_rest_length"), "set_suspension_rest_length", "get_suspension_rest_length");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_friction_slip"), "set_friction_slip", "get_friction_slip");
+ ADD_GROUP("Suspension", "suspension_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "suspension_travel"), "set_suspension_travel", "get_suspension_travel");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "suspension_stiffness"), "set_suspension_stiffness", "get_suspension_stiffness");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "suspension_max_force"), "set_suspension_max_force", "get_suspension_max_force");
+ ADD_GROUP("Damping", "damping_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "damping_compression"), "set_damping_compression", "get_damping_compression");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "damping_relaxation"), "set_damping_relaxation", "get_damping_relaxation");
}
-
void VehicleWheel::set_use_as_traction(bool p_enable) {
- engine_traction=p_enable;
+ engine_traction = p_enable;
}
-bool VehicleWheel::is_used_as_traction() const{
+bool VehicleWheel::is_used_as_traction() const {
return engine_traction;
}
+void VehicleWheel::set_use_as_steering(bool p_enabled) {
-void VehicleWheel::set_use_as_steering(bool p_enabled){
-
- steers=p_enabled;
+ steers = p_enabled;
}
-bool VehicleWheel::is_used_as_steering() const{
+bool VehicleWheel::is_used_as_steering() const {
return steers;
}
-
VehicleWheel::VehicleWheel() {
-
- steers=false;
- engine_traction=false;
+ steers = false;
+ engine_traction = false;
m_steering = real_t(0.);
//m_engineForce = real_t(0.);
@@ -318,7 +293,7 @@ VehicleWheel::VehicleWheel() {
m_rollInfluence = real_t(0.1);
m_suspensionRestLength = 0.15;
- m_wheelRadius = 0.5;//0.28;
+ m_wheelRadius = 0.5; //0.28;
m_suspensionStiffness = 5.88;
m_wheelsDampingCompression = 0.83;
m_wheelsDampingRelaxation = 0.88;
@@ -327,15 +302,14 @@ VehicleWheel::VehicleWheel() {
m_maxSuspensionTravelCm = 500;
m_maxSuspensionForce = 6000;
- m_suspensionRelativeVelocity=0;
- m_clippedInvContactDotSuspension=1.0;
- m_raycastInfo.m_isInContact=false;
+ m_suspensionRelativeVelocity = 0;
+ m_clippedInvContactDotSuspension = 1.0;
+ m_raycastInfo.m_isInContact = false;
- body=NULL;
+ body = NULL;
}
-
-void VehicleBody::_update_wheel_transform(VehicleWheel& wheel ,PhysicsDirectBodyState *s) {
+void VehicleBody::_update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBodyState *s) {
wheel.m_raycastInfo.m_isInContact = false;
@@ -346,31 +320,31 @@ void VehicleBody::_update_wheel_transform(VehicleWheel& wheel ,PhysicsDirectBody
}
*/
- wheel.m_raycastInfo.m_hardPointWS = chassisTrans.xform( wheel.m_chassisConnectionPointCS );
+ wheel.m_raycastInfo.m_hardPointWS = chassisTrans.xform(wheel.m_chassisConnectionPointCS);
//wheel.m_raycastInfo.m_hardPointWS+=s->get_linear_velocity()*s->get_step();
- wheel.m_raycastInfo.m_wheelDirectionWS = chassisTrans.get_basis().xform( wheel.m_wheelDirectionCS).normalized();
- wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.get_basis().xform( wheel.m_wheelAxleCS ).normalized();
+ wheel.m_raycastInfo.m_wheelDirectionWS = chassisTrans.get_basis().xform(wheel.m_wheelDirectionCS).normalized();
+ wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.get_basis().xform(wheel.m_wheelAxleCS).normalized();
}
-void VehicleBody::_update_wheel(int p_idx,PhysicsDirectBodyState *s) {
+void VehicleBody::_update_wheel(int p_idx, PhysicsDirectBodyState *s) {
- VehicleWheel& wheel = *wheels[p_idx];
- _update_wheel_transform(wheel,s);
+ VehicleWheel &wheel = *wheels[p_idx];
+ _update_wheel_transform(wheel, s);
Vector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
- const Vector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
+ const Vector3 &right = wheel.m_raycastInfo.m_wheelAxleWS;
Vector3 fwd = up.cross(right);
fwd = fwd.normalized();
//up = right.cross(fwd);
//up.normalize();
//rotate around steering over de wheelAxleWS
- real_t steering = wheel.steers?m_steeringValue:0.0;
+ real_t steering = wheel.steers ? m_steeringValue : 0.0;
//print_line(itos(p_idx)+": "+rtos(steering));
- Basis steeringMat(up,steering);
+ Basis steeringMat(up, steering);
- Basis rotatingMat(right,-wheel.m_rotation);
+ Basis rotatingMat(right, -wheel.m_rotation);
/*
if (p_idx==1)
@@ -378,82 +352,69 @@ void VehicleBody::_update_wheel(int p_idx,PhysicsDirectBodyState *s) {
*/
Basis basis2(
- right[0],up[0],fwd[0],
- right[1],up[1],fwd[1],
- right[2],up[2],fwd[2]
- );
+ right[0], up[0], fwd[0],
+ right[1], up[1], fwd[1],
+ right[2], up[2], fwd[2]);
wheel.m_worldTransform.set_basis(steeringMat * rotatingMat * basis2);
//wheel.m_worldTransform.set_basis(basis2 * (steeringMat * rotatingMat));
wheel.m_worldTransform.set_origin(
- wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
- );
-
+ wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength);
}
+real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) {
-real_t VehicleBody::_ray_cast(int p_idx,PhysicsDirectBodyState *s) {
-
-
- VehicleWheel& wheel = *wheels[p_idx];
-
- _update_wheel_transform(wheel,s);
+ VehicleWheel &wheel = *wheels[p_idx];
+ _update_wheel_transform(wheel, s);
real_t depth = -1;
- real_t raylen = wheel.m_suspensionRestLength+wheel.m_wheelRadius;
+ real_t raylen = wheel.m_suspensionRestLength + wheel.m_wheelRadius;
Vector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
Vector3 source = wheel.m_raycastInfo.m_hardPointWS;
wheel.m_raycastInfo.m_contactPointWS = source + rayvector;
- const Vector3& target = wheel.m_raycastInfo.m_contactPointWS;
- source-=wheel.m_wheelRadius * wheel.m_raycastInfo.m_wheelDirectionWS;
+ const Vector3 &target = wheel.m_raycastInfo.m_contactPointWS;
+ source -= wheel.m_wheelRadius * wheel.m_raycastInfo.m_wheelDirectionWS;
real_t param = real_t(0.);
-
PhysicsDirectSpaceState::RayResult rr;
+ PhysicsDirectSpaceState *ss = s->get_space_state();
- PhysicsDirectSpaceState *ss=s->get_space_state();
-
- bool col = ss->intersect_ray(source,target,rr,exclude);
-
+ bool col = ss->intersect_ray(source, target, rr, exclude);
wheel.m_raycastInfo.m_groundObject = 0;
- if (col)
- {
+ if (col) {
//print_line("WHEEL "+itos(p_idx)+" FROM "+source+" TO: "+target);
//print_line("WHEEL "+itos(p_idx)+" COLLIDE? "+itos(col));
- param = source.distance_to(rr.position)/source.distance_to(target);
+ param = source.distance_to(rr.position) / source.distance_to(target);
depth = raylen * param;
- wheel.m_raycastInfo.m_contactNormalWS = rr.normal;
+ wheel.m_raycastInfo.m_contactNormalWS = rr.normal;
wheel.m_raycastInfo.m_isInContact = true;
if (rr.collider)
- wheel.m_raycastInfo.m_groundObject=rr.collider->cast_to<PhysicsBody>();
-
+ wheel.m_raycastInfo.m_groundObject = rr.collider->cast_to<PhysicsBody>();
- real_t hitDistance = param*raylen;
+ real_t hitDistance = param * raylen;
wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelRadius;
//clamp on max suspension travel
- real_t minSuspensionLength = wheel.m_suspensionRestLength - wheel.m_maxSuspensionTravelCm*real_t(0.01);
- real_t maxSuspensionLength = wheel.m_suspensionRestLength+ wheel.m_maxSuspensionTravelCm*real_t(0.01);
- if (wheel.m_raycastInfo.m_suspensionLength < minSuspensionLength)
- {
+ real_t minSuspensionLength = wheel.m_suspensionRestLength - wheel.m_maxSuspensionTravelCm * real_t(0.01);
+ real_t maxSuspensionLength = wheel.m_suspensionRestLength + wheel.m_maxSuspensionTravelCm * real_t(0.01);
+ if (wheel.m_raycastInfo.m_suspensionLength < minSuspensionLength) {
wheel.m_raycastInfo.m_suspensionLength = minSuspensionLength;
}
- if (wheel.m_raycastInfo.m_suspensionLength > maxSuspensionLength)
- {
+ if (wheel.m_raycastInfo.m_suspensionLength > maxSuspensionLength) {
wheel.m_raycastInfo.m_suspensionLength = maxSuspensionLength;
}
wheel.m_raycastInfo.m_contactPointWS = rr.position;
- real_t denominator= wheel.m_raycastInfo.m_contactNormalWS.dot( wheel.m_raycastInfo.m_wheelDirectionWS );
+ real_t denominator = wheel.m_raycastInfo.m_contactNormalWS.dot(wheel.m_raycastInfo.m_wheelDirectionWS);
Vector3 chassis_velocity_at_contactPoint;
//Vector3 relpos = wheel.m_raycastInfo.m_contactPointWS-getRigidBody()->getCenterOfMassPosition();
@@ -461,72 +422,58 @@ real_t VehicleBody::_ray_cast(int p_idx,PhysicsDirectBodyState *s) {
//chassis_velocity_at_contactPoint = getRigidBody()->getVelocityInLocalPoint(relpos);
chassis_velocity_at_contactPoint = s->get_linear_velocity() +
- (s->get_angular_velocity()).cross(wheel.m_raycastInfo.m_contactPointWS-s->get_transform().origin);// * mPos);
-
+ (s->get_angular_velocity()).cross(wheel.m_raycastInfo.m_contactPointWS - s->get_transform().origin); // * mPos);
- real_t projVel = wheel.m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );
+ real_t projVel = wheel.m_raycastInfo.m_contactNormalWS.dot(chassis_velocity_at_contactPoint);
- if ( denominator >= real_t(-0.1))
- {
+ if (denominator >= real_t(-0.1)) {
wheel.m_suspensionRelativeVelocity = real_t(0.0);
wheel.m_clippedInvContactDotSuspension = real_t(1.0) / real_t(0.1);
- }
- else
- {
+ } else {
real_t inv = real_t(-1.) / denominator;
wheel.m_suspensionRelativeVelocity = projVel * inv;
wheel.m_clippedInvContactDotSuspension = inv;
}
- } else
- {
+ } else {
wheel.m_raycastInfo.m_isInContact = false;
//put wheel info as in rest position
wheel.m_raycastInfo.m_suspensionLength = wheel.m_suspensionRestLength;
wheel.m_suspensionRelativeVelocity = real_t(0.0);
- wheel.m_raycastInfo.m_contactNormalWS = - wheel.m_raycastInfo.m_wheelDirectionWS;
+ wheel.m_raycastInfo.m_contactNormalWS = -wheel.m_raycastInfo.m_wheelDirectionWS;
wheel.m_clippedInvContactDotSuspension = real_t(1.0);
}
return depth;
}
-
-void VehicleBody::_update_suspension(PhysicsDirectBodyState *s)
-{
+void VehicleBody::_update_suspension(PhysicsDirectBodyState *s) {
real_t chassisMass = mass;
- for (int w_it=0; w_it<wheels.size(); w_it++)
- {
- VehicleWheel& wheel_info = *wheels[w_it];
-
+ for (int w_it = 0; w_it < wheels.size(); w_it++) {
+ VehicleWheel &wheel_info = *wheels[w_it];
- if ( wheel_info.m_raycastInfo.m_isInContact )
- {
+ if (wheel_info.m_raycastInfo.m_isInContact) {
real_t force;
//Spring
{
- real_t susp_length = wheel_info.m_suspensionRestLength;
- real_t current_length = wheel_info.m_raycastInfo.m_suspensionLength;
+ real_t susp_length = wheel_info.m_suspensionRestLength;
+ real_t current_length = wheel_info.m_raycastInfo.m_suspensionLength;
real_t length_diff = (susp_length - current_length);
- force = wheel_info.m_suspensionStiffness
- * length_diff * wheel_info.m_clippedInvContactDotSuspension;
+ force = wheel_info.m_suspensionStiffness * length_diff * wheel_info.m_clippedInvContactDotSuspension;
}
// Damper
{
real_t projected_rel_vel = wheel_info.m_suspensionRelativeVelocity;
{
- real_t susp_damping;
- if ( projected_rel_vel < real_t(0.0) )
- {
+ real_t susp_damping;
+ if (projected_rel_vel < real_t(0.0)) {
susp_damping = wheel_info.m_wheelsDampingCompression;
- }
- else
- {
+ } else {
susp_damping = wheel_info.m_wheelsDampingRelaxation;
}
force -= susp_damping * projected_rel_vel;
@@ -535,30 +482,23 @@ void VehicleBody::_update_suspension(PhysicsDirectBodyState *s)
// RESULT
wheel_info.m_wheelsSuspensionForce = force * chassisMass;
- if (wheel_info.m_wheelsSuspensionForce < real_t(0.))
- {
+ if (wheel_info.m_wheelsSuspensionForce < real_t(0.)) {
wheel_info.m_wheelsSuspensionForce = real_t(0.);
}
- }
- else
- {
+ } else {
wheel_info.m_wheelsSuspensionForce = real_t(0.0);
}
}
-
}
-
//bilateral constraint between two dynamic objects
-void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3& pos1,
- PhysicsBody* body2, const Vector3& pos2, const Vector3& normal,real_t& impulse)
-{
+void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3 &pos1,
+ PhysicsBody *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse) {
real_t normalLenSqr = normal.length_squared();
//ERR_FAIL_COND( normalLenSqr < real_t(1.1));
- if (normalLenSqr > real_t(1.1))
- {
+ if (normalLenSqr > real_t(1.1)) {
impulse = real_t(0.);
return;
}
@@ -569,16 +509,16 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec
rel_pos2 = pos2 - body2->get_global_transform().origin;
//this jacobian entry could be re-used for all iterations
- Vector3 vel1 = s->get_linear_velocity() + (s->get_angular_velocity()).cross(rel_pos1);// * mPos);
+ Vector3 vel1 = s->get_linear_velocity() + (s->get_angular_velocity()).cross(rel_pos1); // * mPos);
Vector3 vel2;
if (body2)
- vel2=body2->get_linear_velocity() + body2->get_angular_velocity().cross(rel_pos2);
+ vel2 = body2->get_linear_velocity() + body2->get_angular_velocity().cross(rel_pos2);
Vector3 vel = vel1 - vel2;
Basis b2trans;
- float b2invmass=0;
+ float b2invmass = 0;
Vector3 b2lv;
Vector3 b2av;
Vector3 b2invinertia; //todo
@@ -590,24 +530,21 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec
b2av = body2->get_angular_velocity();
}
-
-
btVehicleJacobianEntry jac(s->get_transform().basis.transposed(),
- b2trans,
- rel_pos1,
- rel_pos2,
- normal,
- s->get_inverse_inertia_tensor().get_main_diagonal(),
- 1.0/mass,
- b2invinertia,
- b2invmass);
+ b2trans,
+ rel_pos1,
+ rel_pos2,
+ normal,
+ s->get_inverse_inertia_tensor().get_main_diagonal(),
+ 1.0 / mass,
+ b2invinertia,
+ b2invmass);
real_t rel_vel = jac.getRelativeVelocity(
- s->get_linear_velocity(),
- s->get_transform().basis.transposed().xform(s->get_angular_velocity()),
- b2lv,
- b2trans.xform(b2av));
-
+ s->get_linear_velocity(),
+ s->get_transform().basis.transposed().xform(s->get_angular_velocity()),
+ b2lv,
+ b2trans.xform(b2av));
rel_vel = normal.dot(vel);
@@ -615,32 +552,28 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec
real_t contactDamping = real_t(0.4);
#define ONLY_USE_LINEAR_MASS
#ifdef ONLY_USE_LINEAR_MASS
- real_t massTerm = real_t(1.) / ((1.0/mass) + b2invmass);
- impulse = - contactDamping * rel_vel * massTerm;
+ real_t massTerm = real_t(1.) / ((1.0 / mass) + b2invmass);
+ impulse = -contactDamping * rel_vel * massTerm;
#else
real_t velocityImpulse = -contactDamping * rel_vel * jacDiagABInv;
impulse = velocityImpulse;
#endif
-
}
-
-
-VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState *s,PhysicsBody* body1,const Vector3& frictionPosWorld,const Vector3& frictionDirectionWorld, real_t maxImpulse)
- :m_s(s),
- m_body1(body1),
- m_frictionPositionWorld(frictionPosWorld),
- m_frictionDirectionWorld(frictionDirectionWorld),
- m_maxImpulse(maxImpulse)
-{
- float denom0=0;
- float denom1=0;
+VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse)
+ : m_s(s),
+ m_body1(body1),
+ m_frictionPositionWorld(frictionPosWorld),
+ m_frictionDirectionWorld(frictionDirectionWorld),
+ m_maxImpulse(maxImpulse) {
+ float denom0 = 0;
+ float denom1 = 0;
{
Vector3 r0 = frictionPosWorld - s->get_transform().origin;
Vector3 c0 = (r0).cross(frictionDirectionWorld);
Vector3 vec = s->get_inverse_inertia_tensor().xform_inv(c0).cross(r0);
- denom0= s->get_inverse_mass() + frictionDirectionWorld.dot(vec);
+ denom0 = s->get_inverse_mass() + frictionDirectionWorld.dot(vec);
}
/* TODO: Why is this code unused?
@@ -654,30 +587,28 @@ VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirec
}
*/
- real_t relaxation = 1.f;
- m_jacDiagABInv = relaxation/(denom0+denom1);
+ real_t relaxation = 1.f;
+ m_jacDiagABInv = relaxation / (denom0 + denom1);
}
+real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint &contactPoint) {
-real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint& contactPoint) {
-
- real_t j1=0.f;
+ real_t j1 = 0.f;
- const Vector3& contactPosWorld = contactPoint.m_frictionPositionWorld;
+ const Vector3 &contactPosWorld = contactPoint.m_frictionPositionWorld;
Vector3 rel_pos1 = contactPosWorld - contactPoint.m_s->get_transform().origin;
Vector3 rel_pos2;
if (contactPoint.m_body1)
rel_pos2 = contactPosWorld - contactPoint.m_body1->get_global_transform().origin;
- real_t maxImpulse = contactPoint.m_maxImpulse;
+ real_t maxImpulse = contactPoint.m_maxImpulse;
- Vector3 vel1 = contactPoint.m_s->get_linear_velocity() + (contactPoint.m_s->get_angular_velocity()).cross(rel_pos1);// * mPos);
+ Vector3 vel1 = contactPoint.m_s->get_linear_velocity() + (contactPoint.m_s->get_angular_velocity()).cross(rel_pos1); // * mPos);
Vector3 vel2;
if (contactPoint.m_body1) {
- vel2=contactPoint.m_body1->get_linear_velocity() + contactPoint.m_body1->get_angular_velocity().cross(rel_pos2);
-
+ vel2 = contactPoint.m_body1->get_linear_velocity() + contactPoint.m_body1->get_angular_velocity().cross(rel_pos2);
}
Vector3 vel = vel1 - vel2;
@@ -687,10 +618,9 @@ real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint& contactPo
// calculate j that moves us to zero relative velocity
j1 = -vrel * contactPoint.m_jacDiagABInv;
- return CLAMP(j1,-maxImpulse,maxImpulse);
+ return CLAMP(j1, -maxImpulse, maxImpulse);
}
-
static const real_t sideFrictionStiffness2 = real_t(1.0);
void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
@@ -706,37 +636,31 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
int numWheelsOnGround = 0;
-
//collapse all those loops into one!
- for (int i=0;i<wheels.size();i++)
- {
- VehicleWheel& wheelInfo = *wheels[i];
+ for (int i = 0; i < wheels.size(); i++) {
+ VehicleWheel &wheelInfo = *wheels[i];
if (wheelInfo.m_raycastInfo.m_isInContact)
numWheelsOnGround++;
m_sideImpulse[i] = real_t(0.);
m_forwardImpulse[i] = real_t(0.);
-
}
{
- for (int i=0;i<wheels.size();i++)
- {
+ for (int i = 0; i < wheels.size(); i++) {
- VehicleWheel& wheelInfo = *wheels[i];
+ VehicleWheel &wheelInfo = *wheels[i];
-
- if (wheelInfo.m_raycastInfo.m_isInContact)
- {
+ if (wheelInfo.m_raycastInfo.m_isInContact) {
//const btTransform& wheelTrans = getWheelTransformWS( i );
- Basis wheelBasis0 = wheelInfo.m_worldTransform.basis;//get_global_transform().basis;
+ Basis wheelBasis0 = wheelInfo.m_worldTransform.basis; //get_global_transform().basis;
m_axle[i] = wheelBasis0.get_axis(Vector3::AXIS_X);
//m_axle[i] = wheelInfo.m_raycastInfo.m_wheelAxleWS;
- const Vector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
+ const Vector3 &surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
real_t proj = m_axle[i].dot(surfNormalWS);
m_axle[i] -= surfNormalWS * proj;
m_axle[i] = m_axle[i].normalized();
@@ -744,14 +668,11 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
m_forwardWS[i].normalize();
-
_resolve_single_bilateral(s, wheelInfo.m_raycastInfo.m_contactPointWS,
- wheelInfo.m_raycastInfo.m_groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
- m_axle[i],m_sideImpulse[i]);
+ wheelInfo.m_raycastInfo.m_groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
+ m_axle[i], m_sideImpulse[i]);
m_sideImpulse[i] *= sideFrictionStiffness2;
-
-
}
}
}
@@ -761,57 +682,46 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
bool sliding = false;
{
- for (int wheel =0;wheel <wheels.size();wheel++)
- {
- VehicleWheel& wheelInfo = *wheels[wheel];
-
+ for (int wheel = 0; wheel < wheels.size(); wheel++) {
+ VehicleWheel &wheelInfo = *wheels[wheel];
//class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
- real_t rollingFriction = 0.f;
+ real_t rollingFriction = 0.f;
- if (wheelInfo.m_raycastInfo.m_isInContact)
- {
- if (engine_force != 0.f)
- {
- rollingFriction = -engine_force* s->get_step();
- } else
- {
+ if (wheelInfo.m_raycastInfo.m_isInContact) {
+ if (engine_force != 0.f) {
+ rollingFriction = -engine_force * s->get_step();
+ } else {
real_t defaultRollingFrictionImpulse = 0.f;
- float cbrake = MAX(wheelInfo.m_brake,brake);
+ float cbrake = MAX(wheelInfo.m_brake, brake);
real_t maxImpulse = cbrake ? cbrake : defaultRollingFrictionImpulse;
- btVehicleWheelContactPoint contactPt(s,wheelInfo.m_raycastInfo.m_groundObject,wheelInfo.m_raycastInfo.m_contactPointWS,m_forwardWS[wheel],maxImpulse);
+ btVehicleWheelContactPoint contactPt(s, wheelInfo.m_raycastInfo.m_groundObject, wheelInfo.m_raycastInfo.m_contactPointWS, m_forwardWS[wheel], maxImpulse);
rollingFriction = _calc_rolling_friction(contactPt);
}
}
//switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)
-
-
-
m_forwardImpulse[wheel] = real_t(0.);
- wheelInfo.m_skidInfo= real_t(1.);
+ wheelInfo.m_skidInfo = real_t(1.);
- if (wheelInfo.m_raycastInfo.m_isInContact)
- {
- wheelInfo.m_skidInfo= real_t(1.);
+ if (wheelInfo.m_raycastInfo.m_isInContact) {
+ wheelInfo.m_skidInfo = real_t(1.);
real_t maximp = wheelInfo.m_wheelsSuspensionForce * s->get_step() * wheelInfo.m_frictionSlip;
real_t maximpSide = maximp;
real_t maximpSquared = maximp * maximpSide;
+ m_forwardImpulse[wheel] = rollingFriction; //wheelInfo.m_engineForce* timeStep;
- m_forwardImpulse[wheel] = rollingFriction;//wheelInfo.m_engineForce* timeStep;
+ real_t x = (m_forwardImpulse[wheel]) * fwdFactor;
+ real_t y = (m_sideImpulse[wheel]) * sideFactor;
- real_t x = (m_forwardImpulse[wheel] ) * fwdFactor;
- real_t y = (m_sideImpulse[wheel] ) * sideFactor;
+ real_t impulseSquared = (x * x + y * y);
- real_t impulseSquared = (x*x + y*y);
-
- if (impulseSquared > maximpSquared)
- {
+ if (impulseSquared > maximpSquared) {
sliding = true;
real_t factor = maximp / Math::sqrt(impulseSquared);
@@ -819,22 +729,14 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
wheelInfo.m_skidInfo *= factor;
}
}
-
}
}
-
-
-
- if (sliding)
- {
- for (int wheel = 0;wheel < wheels.size(); wheel++)
- {
- if (m_sideImpulse[wheel] != real_t(0.))
- {
- if (wheels[wheel]->m_skidInfo< real_t(1.))
- {
- m_forwardImpulse[wheel] *= wheels[wheel]->m_skidInfo;
+ if (sliding) {
+ for (int wheel = 0; wheel < wheels.size(); wheel++) {
+ if (m_sideImpulse[wheel] != real_t(0.)) {
+ if (wheels[wheel]->m_skidInfo < real_t(1.)) {
+ m_forwardImpulse[wheel] *= wheels[wheel]->m_skidInfo;
m_sideImpulse[wheel] *= wheels[wheel]->m_skidInfo;
}
}
@@ -843,36 +745,32 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
// apply the impulses
{
- for (int wheel = 0;wheel<wheels.size(); wheel++)
- {
- VehicleWheel& wheelInfo = *wheels[wheel];
+ for (int wheel = 0; wheel < wheels.size(); wheel++) {
+ VehicleWheel &wheelInfo = *wheels[wheel];
Vector3 rel_pos = wheelInfo.m_raycastInfo.m_contactPointWS -
- s->get_transform().origin;
+ s->get_transform().origin;
- if (m_forwardImpulse[wheel] != real_t(0.))
- {
- s->apply_impulse(rel_pos,m_forwardWS[wheel]*(m_forwardImpulse[wheel]));
+ if (m_forwardImpulse[wheel] != real_t(0.)) {
+ s->apply_impulse(rel_pos, m_forwardWS[wheel] * (m_forwardImpulse[wheel]));
}
- if (m_sideImpulse[wheel] != real_t(0.))
- {
- PhysicsBody* groundObject = wheelInfo.m_raycastInfo.m_groundObject;
+ if (m_sideImpulse[wheel] != real_t(0.)) {
+ PhysicsBody *groundObject = wheelInfo.m_raycastInfo.m_groundObject;
Vector3 rel_pos2;
if (groundObject) {
- rel_pos2=wheelInfo.m_raycastInfo.m_contactPointWS - groundObject->get_global_transform().origin;
+ rel_pos2 = wheelInfo.m_raycastInfo.m_contactPointWS - groundObject->get_global_transform().origin;
}
-
Vector3 sideImp = m_axle[wheel] * m_sideImpulse[wheel];
#if defined ROLLING_INFLUENCE_FIX // fix. It only worked if car's up was along Y - VT.
- Vector3 vChassisWorldUp = s->get_transform().basis.transposed()[1];//getRigidBody()->getCenterOfMassTransform().getBasis().getColumn(m_indexUpAxis);
- rel_pos -= vChassisWorldUp * (vChassisWorldUp.dot(rel_pos) * (1.f-wheelInfo.m_rollInfluence));
+ Vector3 vChassisWorldUp = s->get_transform().basis.transposed()[1]; //getRigidBody()->getCenterOfMassTransform().getBasis().getColumn(m_indexUpAxis);
+ rel_pos -= vChassisWorldUp * (vChassisWorldUp.dot(rel_pos) * (1.f - wheelInfo.m_rollInfluence));
#else
rel_pos[1] *= wheelInfo.m_rollInfluence; //?
#endif
- s->apply_impulse(rel_pos,sideImp);
+ s->apply_impulse(rel_pos, sideImp);
//apply friction impulse on the ground
//todo
@@ -880,74 +778,62 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
}
}
}
-
-
}
-
void VehicleBody::_direct_state_changed(Object *p_state) {
-
PhysicsDirectBodyState *s = p_state->cast_to<PhysicsDirectBodyState>();
set_ignore_transform_notification(true);
set_global_transform(s->get_transform());
set_ignore_transform_notification(false);
-
float step = s->get_step();
- for(int i=0;i<wheels.size();i++) {
+ for (int i = 0; i < wheels.size(); i++) {
- _update_wheel(i,s);
+ _update_wheel(i, s);
}
+ for (int i = 0; i < wheels.size(); i++) {
- for(int i=0;i<wheels.size();i++) {
-
- _ray_cast(i,s);
+ _ray_cast(i, s);
wheels[i]->set_transform(s->get_transform().inverse() * wheels[i]->m_worldTransform);
}
_update_suspension(s);
- for(int i=0;i<wheels.size();i++) {
+ for (int i = 0; i < wheels.size(); i++) {
//apply suspension force
- VehicleWheel& wheel = *wheels[i];
+ VehicleWheel &wheel = *wheels[i];
real_t suspensionForce = wheel.m_wheelsSuspensionForce;
- if (suspensionForce > wheel.m_maxSuspensionForce)
- {
+ if (suspensionForce > wheel.m_maxSuspensionForce) {
suspensionForce = wheel.m_maxSuspensionForce;
}
Vector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step;
Vector3 relpos = wheel.m_raycastInfo.m_contactPointWS - s->get_transform().origin;
- s->apply_impulse(relpos,impulse);
+ s->apply_impulse(relpos, impulse);
//getRigidBody()->applyImpulse(impulse, relpos);
-
}
-
_update_friction(s);
-
- for (int i=0;i<wheels.size();i++)
- {
- VehicleWheel& wheel = *wheels[i];
+ for (int i = 0; i < wheels.size(); i++) {
+ VehicleWheel &wheel = *wheels[i];
Vector3 relpos = wheel.m_raycastInfo.m_hardPointWS - s->get_transform().origin;
- Vector3 vel = s->get_linear_velocity() + (s->get_angular_velocity()).cross(relpos);// * mPos);
+ Vector3 vel = s->get_linear_velocity() + (s->get_angular_velocity()).cross(relpos); // * mPos);
- if (wheel.m_raycastInfo.m_isInContact)
- {
- const Transform& chassisWorldTransform = s->get_transform();
+ if (wheel.m_raycastInfo.m_isInContact) {
+ const Transform &chassisWorldTransform = s->get_transform();
- Vector3 fwd (
- chassisWorldTransform.basis[0][Vector3::AXIS_Z],
- chassisWorldTransform.basis[1][Vector3::AXIS_Z],
- chassisWorldTransform.basis[2][Vector3::AXIS_Z]);
+ Vector3 fwd(
+ chassisWorldTransform.basis[0][Vector3::AXIS_Z],
+ chassisWorldTransform.basis[1][Vector3::AXIS_Z],
+ chassisWorldTransform.basis[2][Vector3::AXIS_Z]);
real_t proj = fwd.dot(wheel.m_raycastInfo.m_contactNormalWS);
fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj;
@@ -957,126 +843,115 @@ void VehicleBody::_direct_state_changed(Object *p_state) {
wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelRadius);
wheel.m_rotation += wheel.m_deltaRotation;
- } else
- {
+ } else {
wheel.m_rotation += wheel.m_deltaRotation;
}
- wheel.m_deltaRotation *= real_t(0.99);//damping of rotation when not in contact
-
+ wheel.m_deltaRotation *= real_t(0.99); //damping of rotation when not in contact
}
linear_velocity = s->get_linear_velocity();
}
void VehicleBody::set_mass(real_t p_mass) {
- mass=p_mass;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_MASS,mass);
+ mass = p_mass;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_MASS, mass);
}
-real_t VehicleBody::get_mass() const{
+real_t VehicleBody::get_mass() const {
return mass;
}
-
void VehicleBody::set_friction(real_t p_friction) {
- friction=p_friction;
- PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_FRICTION,friction);
+ friction = p_friction;
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, friction);
}
-real_t VehicleBody::get_friction() const{
+real_t VehicleBody::get_friction() const {
return friction;
}
void VehicleBody::set_engine_force(float p_force) {
- engine_force=p_force;
+ engine_force = p_force;
}
-float VehicleBody::get_engine_force() const{
+float VehicleBody::get_engine_force() const {
return engine_force;
}
-void VehicleBody::set_brake(float p_brake){
+void VehicleBody::set_brake(float p_brake) {
- brake=p_brake;
+ brake = p_brake;
}
-float VehicleBody::get_brake() const{
+float VehicleBody::get_brake() const {
return brake;
}
-void VehicleBody::set_steering(float p_steering){
+void VehicleBody::set_steering(float p_steering) {
- m_steeringValue=p_steering;
+ m_steeringValue = p_steering;
}
-float VehicleBody::get_steering() const{
+float VehicleBody::get_steering() const {
return m_steeringValue;
}
-Vector3 VehicleBody::get_linear_velocity() const
-{
+Vector3 VehicleBody::get_linear_velocity() const {
return linear_velocity;
}
-void VehicleBody::_bind_methods(){
-
- ClassDB::bind_method(D_METHOD("set_mass","mass"),&VehicleBody::set_mass);
- ClassDB::bind_method(D_METHOD("get_mass"),&VehicleBody::get_mass);
-
- ClassDB::bind_method(D_METHOD("set_friction","friction"),&VehicleBody::set_friction);
- ClassDB::bind_method(D_METHOD("get_friction"),&VehicleBody::get_friction);
+void VehicleBody::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_engine_force","engine_force"),&VehicleBody::set_engine_force);
- ClassDB::bind_method(D_METHOD("get_engine_force"),&VehicleBody::get_engine_force);
+ ClassDB::bind_method(D_METHOD("set_mass", "mass"), &VehicleBody::set_mass);
+ ClassDB::bind_method(D_METHOD("get_mass"), &VehicleBody::get_mass);
- ClassDB::bind_method(D_METHOD("set_brake","brake"),&VehicleBody::set_brake);
- ClassDB::bind_method(D_METHOD("get_brake"),&VehicleBody::get_brake);
+ ClassDB::bind_method(D_METHOD("set_friction", "friction"), &VehicleBody::set_friction);
+ ClassDB::bind_method(D_METHOD("get_friction"), &VehicleBody::get_friction);
- ClassDB::bind_method(D_METHOD("set_steering","steering"),&VehicleBody::set_steering);
- ClassDB::bind_method(D_METHOD("get_steering"),&VehicleBody::get_steering);
+ ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleBody::set_engine_force);
+ ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleBody::get_engine_force);
- ClassDB::bind_method(D_METHOD("get_linear_velocity"),&VehicleBody::get_linear_velocity);
+ ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleBody::set_brake);
+ ClassDB::bind_method(D_METHOD("get_brake"), &VehicleBody::get_brake);
- ClassDB::bind_method(D_METHOD("_direct_state_changed"),&VehicleBody::_direct_state_changed);
+ ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleBody::set_steering);
+ ClassDB::bind_method(D_METHOD("get_steering"), &VehicleBody::get_steering);
- ADD_GROUP("Motion","");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"engine_force",PROPERTY_HINT_RANGE,"0.00,1024.0,0.01"),"set_engine_force","get_engine_force");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"brake",PROPERTY_HINT_RANGE,"0.0,1.0,0.01"),"set_brake","get_brake");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"steering",PROPERTY_HINT_RANGE,"-180,180.0,0.01"),"set_steering","get_steering");
- ADD_GROUP("Mass","");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"mass",PROPERTY_HINT_RANGE,"0.01,65536,0.01"),"set_mass","get_mass");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0.01,1,0.01"),"set_friction","get_friction");
+ ClassDB::bind_method(D_METHOD("get_linear_velocity"), &VehicleBody::get_linear_velocity);
+ ClassDB::bind_method(D_METHOD("_direct_state_changed"), &VehicleBody::_direct_state_changed);
+ ADD_GROUP("Motion", "");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "engine_force", PROPERTY_HINT_RANGE, "0.00,1024.0,0.01"), "set_engine_force", "get_engine_force");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "brake", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_brake", "get_brake");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "steering", PROPERTY_HINT_RANGE, "-180,180.0,0.01"), "set_steering", "get_steering");
+ ADD_GROUP("Mass", "");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "mass", PROPERTY_HINT_RANGE, "0.01,65536,0.01"), "set_mass", "get_mass");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction", PROPERTY_HINT_RANGE, "0.01,1,0.01"), "set_friction", "get_friction");
}
+VehicleBody::VehicleBody()
+ : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) {
-
-VehicleBody::VehicleBody() : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) {
-
-
- m_pitchControl=0;
+ m_pitchControl = 0;
m_currentVehicleSpeedKmHour = real_t(0.);
m_steeringValue = real_t(0.);
- engine_force=0;
- brake=0;
+ engine_force = 0;
+ brake = 0;
+ friction = 1;
-
- friction=1;
-
- ccd=false;
+ ccd = false;
exclude.insert(get_rid());
- PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(),this,"_direct_state_changed");
+ PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed");
set_mass(40);
}
-
diff --git a/scene/3d/vehicle_body.h b/scene/3d/vehicle_body.h
index 273e63d741..55b521cfa6 100644
--- a/scene/3d/vehicle_body.h
+++ b/scene/3d/vehicle_body.h
@@ -35,20 +35,18 @@ class VehicleBody;
class VehicleWheel : public Spatial {
- GDCLASS(VehicleWheel,Spatial);
-
-friend class VehicleBody;
+ GDCLASS(VehicleWheel, Spatial);
+ friend class VehicleBody;
Transform m_worldTransform;
Transform local_xform;
bool engine_traction;
bool steers;
-
- Vector3 m_chassisConnectionPointCS; //const
- Vector3 m_wheelDirectionCS;//const
- Vector3 m_wheelAxleCS; // const or modified by steering
+ Vector3 m_chassisConnectionPointCS; //const
+ Vector3 m_wheelDirectionCS; //const
+ Vector3 m_wheelAxleCS; // const or modified by steering
real_t m_suspensionRestLength;
real_t m_maxSuspensionTravelCm;
@@ -65,30 +63,29 @@ friend class VehicleBody;
//btVector3 m_wheelAxleCS; // const or modified by steering ?
- real_t m_steering;
- real_t m_rotation;
- real_t m_deltaRotation;
- real_t m_rollInfluence;
+ real_t m_steering;
+ real_t m_rotation;
+ real_t m_deltaRotation;
+ real_t m_rollInfluence;
//real_t m_engineForce;
- real_t m_brake;
+ real_t m_brake;
- real_t m_clippedInvContactDotSuspension;
- real_t m_suspensionRelativeVelocity;
+ real_t m_clippedInvContactDotSuspension;
+ real_t m_suspensionRelativeVelocity;
//calculated by suspension
- real_t m_wheelsSuspensionForce;
- real_t m_skidInfo;
-
+ real_t m_wheelsSuspensionForce;
+ real_t m_skidInfo;
struct RaycastInfo {
//set by raycaster
- Vector3 m_contactNormalWS;//contactnormal
- Vector3 m_contactPointWS;//raycast hitpoint
- real_t m_suspensionLength;
- Vector3 m_hardPointWS;//raycast starting point
- Vector3 m_wheelDirectionWS; //direction in worldspace
- Vector3 m_wheelAxleWS; // axle in worldspace
+ Vector3 m_contactNormalWS; //contactnormal
+ Vector3 m_contactPointWS; //raycast hitpoint
+ real_t m_suspensionLength;
+ Vector3 m_hardPointWS; //raycast starting point
+ Vector3 m_wheelDirectionWS; //direction in worldspace
+ Vector3 m_wheelAxleWS; // axle in worldspace
bool m_isInContact;
- PhysicsBody* m_groundObject; //could be general void* ptr
+ PhysicsBody *m_groundObject; //could be general void* ptr
} m_raycastInfo;
void _update(PhysicsDirectBodyState *s);
@@ -98,7 +95,6 @@ protected:
static void _bind_methods();
public:
-
void set_radius(float p_radius);
float get_radius() const;
@@ -130,13 +126,11 @@ public:
bool is_used_as_steering() const;
VehicleWheel();
-
};
-
class VehicleBody : public PhysicsBody {
- GDCLASS(VehicleBody,PhysicsBody);
+ GDCLASS(VehicleBody, PhysicsBody);
real_t mass;
real_t friction;
@@ -145,52 +139,48 @@ class VehicleBody : public PhysicsBody {
float brake;
Vector3 linear_velocity;
- Vector3 angular_velocity;
+ Vector3 angular_velocity;
bool ccd;
- real_t m_pitchControl;
- real_t m_steeringValue;
- real_t m_currentVehicleSpeedKmHour;
+ real_t m_pitchControl;
+ real_t m_steeringValue;
+ real_t m_currentVehicleSpeedKmHour;
Set<RID> exclude;
- Vector<Vector3> m_forwardWS;
- Vector<Vector3> m_axle;
- Vector<real_t> m_forwardImpulse;
- Vector<real_t> m_sideImpulse;
+ Vector<Vector3> m_forwardWS;
+ Vector<Vector3> m_axle;
+ Vector<real_t> m_forwardImpulse;
+ Vector<real_t> m_sideImpulse;
struct btVehicleWheelContactPoint {
PhysicsDirectBodyState *m_s;
- PhysicsBody* m_body1;
- Vector3 m_frictionPositionWorld;
- Vector3 m_frictionDirectionWorld;
- real_t m_jacDiagABInv;
- real_t m_maxImpulse;
+ PhysicsBody *m_body1;
+ Vector3 m_frictionPositionWorld;
+ Vector3 m_frictionDirectionWorld;
+ real_t m_jacDiagABInv;
+ real_t m_maxImpulse;
-
- btVehicleWheelContactPoint(PhysicsDirectBodyState *s,PhysicsBody* body1,const Vector3& frictionPosWorld,const Vector3& frictionDirectionWorld, real_t maxImpulse);
+ btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse);
};
- void _resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3& pos1, PhysicsBody* body2, const Vector3& pos2, const Vector3& normal, real_t& impulse);
- real_t _calc_rolling_friction(btVehicleWheelContactPoint& contactPoint);
+ void _resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3 &pos1, PhysicsBody *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse);
+ real_t _calc_rolling_friction(btVehicleWheelContactPoint &contactPoint);
void _update_friction(PhysicsDirectBodyState *s);
void _update_suspension(PhysicsDirectBodyState *s);
- real_t _ray_cast(int p_idx,PhysicsDirectBodyState *s);
- void _update_wheel_transform(VehicleWheel& wheel ,PhysicsDirectBodyState *s);
- void _update_wheel(int p_idx,PhysicsDirectBodyState *s);
-
-
+ real_t _ray_cast(int p_idx, PhysicsDirectBodyState *s);
+ void _update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBodyState *s);
+ void _update_wheel(int p_idx, PhysicsDirectBodyState *s);
-friend class VehicleWheel;
- Vector<VehicleWheel*> wheels;
+ friend class VehicleWheel;
+ Vector<VehicleWheel *> wheels;
static void _bind_methods();
void _direct_state_changed(Object *p_state);
-public:
-
+public:
void set_mass(real_t p_mass);
real_t get_mass() const;
diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp
index 0633846b5a..909ac002b0 100644
--- a/scene/3d/visibility_notifier.cpp
+++ b/scene/3d/visibility_notifier.cpp
@@ -28,71 +28,64 @@
/*************************************************************************/
#include "visibility_notifier.h"
-#include "scene/scene_string_names.h"
#include "scene/3d/physics_body.h"
#include "scene/animation/animation_player.h"
#include "scene/scene_string_names.h"
+#include "scene/scene_string_names.h"
-void VisibilityNotifier::_enter_camera(Camera* p_camera) {
+void VisibilityNotifier::_enter_camera(Camera *p_camera) {
ERR_FAIL_COND(cameras.has(p_camera));
cameras.insert(p_camera);
- if (cameras.size()==1) {
+ if (cameras.size() == 1) {
emit_signal(SceneStringNames::get_singleton()->screen_entered);
_screen_enter();
}
- emit_signal(SceneStringNames::get_singleton()->camera_entered,p_camera);
-
+ emit_signal(SceneStringNames::get_singleton()->camera_entered, p_camera);
}
-void VisibilityNotifier::_exit_camera(Camera* p_camera){
+void VisibilityNotifier::_exit_camera(Camera *p_camera) {
ERR_FAIL_COND(!cameras.has(p_camera));
cameras.erase(p_camera);
- emit_signal(SceneStringNames::get_singleton()->camera_exited,p_camera);
- if (cameras.size()==0) {
+ emit_signal(SceneStringNames::get_singleton()->camera_exited, p_camera);
+ if (cameras.size() == 0) {
emit_signal(SceneStringNames::get_singleton()->screen_exited);
_screen_exit();
-
}
}
+void VisibilityNotifier::set_aabb(const Rect3 &p_aabb) {
-void VisibilityNotifier::set_aabb(const Rect3& p_aabb){
-
- if (aabb==p_aabb)
+ if (aabb == p_aabb)
return;
- aabb=p_aabb;
+ aabb = p_aabb;
if (is_inside_world()) {
- get_world()->_update_notifier(this,get_global_transform().xform(aabb));
+ get_world()->_update_notifier(this, get_global_transform().xform(aabb));
}
_change_notify("aabb");
update_gizmo();
}
-Rect3 VisibilityNotifier::get_aabb() const{
+Rect3 VisibilityNotifier::get_aabb() const {
return aabb;
}
-
void VisibilityNotifier::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
-
- get_world()->_register_notifier(this,get_global_transform().xform(aabb));
+ get_world()->_register_notifier(this, get_global_transform().xform(aabb));
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
-
- get_world()->_update_notifier(this,get_global_transform().xform(aabb));
+ get_world()->_update_notifier(this, get_global_transform().xform(aabb));
} break;
case NOTIFICATION_EXIT_WORLD: {
@@ -101,76 +94,65 @@ void VisibilityNotifier::_notification(int p_what) {
}
}
-
bool VisibilityNotifier::is_on_screen() const {
- return cameras.size()!=0;
+ return cameras.size() != 0;
}
-void VisibilityNotifier::_bind_methods(){
+void VisibilityNotifier::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_aabb","rect"),&VisibilityNotifier::set_aabb);
- ClassDB::bind_method(D_METHOD("get_aabb"),&VisibilityNotifier::get_aabb);
- ClassDB::bind_method(D_METHOD("is_on_screen"),&VisibilityNotifier::is_on_screen);
+ ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier::set_aabb);
+ ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier::get_aabb);
+ ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier::is_on_screen);
- ADD_PROPERTY( PropertyInfo(Variant::RECT3,"aabb"),"set_aabb","get_aabb");
+ ADD_PROPERTY(PropertyInfo(Variant::RECT3, "aabb"), "set_aabb", "get_aabb");
- ADD_SIGNAL( MethodInfo("camera_entered",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera")) );
- ADD_SIGNAL( MethodInfo("camera_exited",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera")) );
- ADD_SIGNAL( MethodInfo("screen_entered"));
- ADD_SIGNAL( MethodInfo("screen_exited"));
+ ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera")));
+ ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera")));
+ ADD_SIGNAL(MethodInfo("screen_entered"));
+ ADD_SIGNAL(MethodInfo("screen_exited"));
}
-
VisibilityNotifier::VisibilityNotifier() {
- aabb=Rect3(Vector3(-1,-1,-1),Vector3(2,2,2));
+ aabb = Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2));
set_notify_transform(true);
-
}
-
-
-
-
//////////////////////////////////////
-
void VisibilityEnabler::_screen_enter() {
+ for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
- for(Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) {
-
- _change_node_state(E->key(),true);
+ _change_node_state(E->key(), true);
}
- visible=true;
+ visible = true;
}
void VisibilityEnabler::_screen_exit() {
- for(Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) {
+ for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
- _change_node_state(E->key(),false);
+ _change_node_state(E->key(), false);
}
- visible=false;
+ visible = false;
}
-void VisibilityEnabler::_find_nodes(Node* p_node) {
-
+void VisibilityEnabler::_find_nodes(Node *p_node) {
- bool add=false;
+ bool add = false;
Variant meta;
if (enabler[ENABLER_FREEZE_BODIES]) {
RigidBody *rb = p_node->cast_to<RigidBody>();
- if (rb && ((rb->get_mode()==RigidBody::MODE_CHARACTER || (rb->get_mode()==RigidBody::MODE_RIGID && !rb->is_able_to_sleep())))) {
+ if (rb && ((rb->get_mode() == RigidBody::MODE_CHARACTER || (rb->get_mode() == RigidBody::MODE_RIGID && !rb->is_able_to_sleep())))) {
-
- add=true;
- meta=rb->get_mode();
+ add = true;
+ meta = rb->get_mode();
}
}
@@ -178,63 +160,58 @@ void VisibilityEnabler::_find_nodes(Node* p_node) {
AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>();
if (ap) {
- add=true;
+ add = true;
}
}
if (add) {
- p_node->connect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed",varray(p_node),CONNECT_ONESHOT);
- nodes[p_node]=meta;
- _change_node_state(p_node,false);
+ p_node->connect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed", varray(p_node), CONNECT_ONESHOT);
+ nodes[p_node] = meta;
+ _change_node_state(p_node, false);
}
- for(int i=0;i<p_node->get_child_count();i++) {
+ for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (c->get_filename()!=String())
+ if (c->get_filename() != String())
continue; //skip, instance
_find_nodes(c);
}
-
}
-void VisibilityEnabler::_notification(int p_what){
+void VisibilityEnabler::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
if (get_tree()->is_editor_hint())
return;
-
Node *from = this;
//find where current scene starts
- while(from->get_parent() && from->get_filename()==String())
- from=from->get_parent();
+ while (from->get_parent() && from->get_filename() == String())
+ from = from->get_parent();
_find_nodes(from);
-
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
+ if (p_what == NOTIFICATION_EXIT_TREE) {
if (get_tree()->is_editor_hint())
return;
-
- for (Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) {
+ for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
if (!visible)
- _change_node_state(E->key(),true);
- E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed");
+ _change_node_state(E->key(), true);
+ E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed");
}
nodes.clear();
-
}
}
-void VisibilityEnabler::_change_node_state(Node* p_node,bool p_enabled) {
+void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) {
ERR_FAIL_COND(!nodes.has(p_node));
@@ -246,59 +223,52 @@ void VisibilityEnabler::_change_node_state(Node* p_node,bool p_enabled) {
}
{
- AnimationPlayer *ap=p_node->cast_to<AnimationPlayer>();
+ AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>();
if (ap) {
ap->set_active(p_enabled);
}
}
-
}
-
-void VisibilityEnabler::_node_removed(Node* p_node) {
+void VisibilityEnabler::_node_removed(Node *p_node) {
if (!visible)
- _change_node_state(p_node,true);
- p_node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed");
+ _change_node_state(p_node, true);
+ p_node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed");
nodes.erase(p_node);
-
}
-void VisibilityEnabler::_bind_methods(){
+void VisibilityEnabler::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_enabler","enabler","enabled"),&VisibilityEnabler::set_enabler);
- ClassDB::bind_method(D_METHOD("is_enabler_enabled","enabler"),&VisibilityEnabler::is_enabler_enabled);
- ClassDB::bind_method(D_METHOD("_node_removed"),&VisibilityEnabler::_node_removed);
+ ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler::set_enabler);
+ ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler::is_enabler_enabled);
+ ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler::_node_removed);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"pause_animations"),"set_enabler","is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS );
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"freeze_bodies"),"set_enabler","is_enabler_enabled", ENABLER_FREEZE_BODIES);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES);
- BIND_CONSTANT( ENABLER_FREEZE_BODIES );
- BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS );
- BIND_CONSTANT( ENABLER_MAX);
+ BIND_CONSTANT(ENABLER_FREEZE_BODIES);
+ BIND_CONSTANT(ENABLER_PAUSE_ANIMATIONS);
+ BIND_CONSTANT(ENABLER_MAX);
}
-void VisibilityEnabler::set_enabler(Enabler p_enabler,bool p_enable){
-
- ERR_FAIL_INDEX(p_enabler,ENABLER_MAX);
- enabler[p_enabler]=p_enable;
+void VisibilityEnabler::set_enabler(Enabler p_enabler, bool p_enable) {
+ ERR_FAIL_INDEX(p_enabler, ENABLER_MAX);
+ enabler[p_enabler] = p_enable;
}
-bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const{
+bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const {
- ERR_FAIL_INDEX_V(p_enabler,ENABLER_MAX,false);
+ ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false);
return enabler[p_enabler];
-
}
VisibilityEnabler::VisibilityEnabler() {
- for(int i=0;i<ENABLER_MAX;i++)
- enabler[i]=true;
-
- visible=false;
+ for (int i = 0; i < ENABLER_MAX; i++)
+ enabler[i] = true;
+ visible = false;
}
-
diff --git a/scene/3d/visibility_notifier.h b/scene/3d/visibility_notifier.h
index aa53e1bcd1..09c1175bf1 100644
--- a/scene/3d/visibility_notifier.h
+++ b/scene/3d/visibility_notifier.h
@@ -34,39 +34,36 @@
class Camera;
class VisibilityNotifier : public Spatial {
- GDCLASS(VisibilityNotifier,Spatial);
+ GDCLASS(VisibilityNotifier, Spatial);
- Set<Camera*> cameras;
+ Set<Camera *> cameras;
Rect3 aabb;
protected:
-
virtual void _screen_enter() {}
virtual void _screen_exit() {}
void _notification(int p_what);
static void _bind_methods();
-friend class SpatialIndexer;
+ friend class SpatialIndexer;
- void _enter_camera(Camera* p_camera);
- void _exit_camera(Camera* p_camera);
+ void _enter_camera(Camera *p_camera);
+ void _exit_camera(Camera *p_camera);
public:
-
- void set_aabb(const Rect3& p_aabb);
+ void set_aabb(const Rect3 &p_aabb);
Rect3 get_aabb() const;
bool is_on_screen() const;
VisibilityNotifier();
};
-
class VisibilityEnabler : public VisibilityNotifier {
- GDCLASS(VisibilityEnabler,VisibilityNotifier);
-public:
+ GDCLASS(VisibilityEnabler, VisibilityNotifier);
+public:
enum Enabler {
ENABLER_PAUSE_ANIMATIONS,
ENABLER_FREEZE_BODIES,
@@ -74,33 +71,29 @@ public:
};
protected:
-
virtual void _screen_enter();
virtual void _screen_exit();
bool visible;
- void _find_nodes(Node* p_node);
+ void _find_nodes(Node *p_node);
- Map<Node*,Variant> nodes;
- void _node_removed(Node* p_node);
+ Map<Node *, Variant> nodes;
+ void _node_removed(Node *p_node);
bool enabler[ENABLER_MAX];
- void _change_node_state(Node* p_node,bool p_enabled);
+ void _change_node_state(Node *p_node, bool p_enabled);
void _notification(int p_what);
static void _bind_methods();
public:
-
- void set_enabler(Enabler p_enabler,bool p_enable);
+ void set_enabler(Enabler p_enabler, bool p_enable);
bool is_enabler_enabled(Enabler p_enabler) const;
VisibilityEnabler();
-
};
VARIANT_ENUM_CAST(VisibilityEnabler::Enabler);
-
#endif // VISIBILITY_NOTIFIER_H
diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp
index bbcd54b36b..852881abd4 100644
--- a/scene/3d/visual_instance.cpp
+++ b/scene/3d/visual_instance.cpp
@@ -28,39 +28,37 @@
/*************************************************************************/
#include "visual_instance.h"
-#include "servers/visual_server.h"
#include "room_instance.h"
#include "scene/scene_string_names.h"
+#include "servers/visual_server.h"
#include "skeleton.h"
Rect3 VisualInstance::get_transformed_aabb() const {
- return get_global_transform().xform( get_aabb() );
+ return get_global_transform().xform(get_aabb());
}
-
void VisualInstance::_update_visibility() {
if (!is_inside_tree())
return;
_change_notify("visible");
- VS::get_singleton()->instance_set_visible(get_instance(),is_visible_in_tree());
+ VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree());
}
-
void VisualInstance::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
// CHECK ROOM
- Spatial * parent = get_parent_spatial();
- Room *room=NULL;
+ Spatial *parent = get_parent_spatial();
+ Room *room = NULL;
bool is_geom = cast_to<GeometryInstance>();
- /* while(parent) {
+ /* while(parent) {
room = parent->cast_to<Room>();
if (room)
@@ -74,11 +72,9 @@ void VisualInstance::_notification(int p_what) {
parent=parent->get_parent_spatial();
}*/
-
-
if (room) {
- VisualServer::get_singleton()->instance_set_room(instance,room->get_instance());
+ VisualServer::get_singleton()->instance_set_room(instance, room->get_instance());
}
// CHECK SKELETON => moving skeleton attaching logic to MeshInstance
/*
@@ -87,21 +83,20 @@ void VisualInstance::_notification(int p_what) {
VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
*/
- VisualServer::get_singleton()->instance_set_scenario( instance, get_world()->get_scenario() );
+ VisualServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario());
_update_visibility();
-
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform gt = get_global_transform();
- VisualServer::get_singleton()->instance_set_transform(instance,gt);
+ VisualServer::get_singleton()->instance_set_transform(instance, gt);
} break;
case NOTIFICATION_EXIT_WORLD: {
- VisualServer::get_singleton()->instance_set_scenario( instance, RID() );
- VisualServer::get_singleton()->instance_set_room(instance,RID());
- VisualServer::get_singleton()->instance_attach_skeleton( instance, RID() );
+ VisualServer::get_singleton()->instance_set_scenario(instance, RID());
+ VisualServer::get_singleton()->instance_set_room(instance, RID());
+ VisualServer::get_singleton()->instance_attach_skeleton(instance, RID());
//VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
} break;
@@ -109,7 +104,6 @@ void VisualInstance::_notification(int p_what) {
_update_visibility();
} break;
-
}
}
@@ -125,8 +119,8 @@ RID VisualInstance::_get_visual_instance_rid() const {
void VisualInstance::set_layer_mask(uint32_t p_mask) {
- layers=p_mask;
- VisualServer::get_singleton()->instance_set_layer_mask(instance,p_mask);
+ layers = p_mask;
+ VisualServer::get_singleton()->instance_set_layer_mask(instance, p_mask);
}
uint32_t VisualInstance::get_layer_mask() const {
@@ -134,76 +128,62 @@ uint32_t VisualInstance::get_layer_mask() const {
return layers;
}
-
void VisualInstance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"),&VisualInstance::_get_visual_instance_rid);
- ClassDB::bind_method(D_METHOD("set_base","base"), &VisualInstance::set_base);
- ClassDB::bind_method(D_METHOD("set_layer_mask","mask"), &VisualInstance::set_layer_mask);
+ ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance::_get_visual_instance_rid);
+ ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance::set_base);
+ ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &VisualInstance::set_layer_mask);
ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance::get_layer_mask);
ClassDB::bind_method(D_METHOD("get_transformed_aabb"), &VisualInstance::get_transformed_aabb);
- ADD_PROPERTY( PropertyInfo( Variant::INT, "layers",PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask");
-
-
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask");
}
+void VisualInstance::set_base(const RID &p_base) {
-void VisualInstance::set_base(const RID& p_base) {
-
- VisualServer::get_singleton()->instance_set_base(instance,p_base);
+ VisualServer::get_singleton()->instance_set_base(instance, p_base);
}
-
-VisualInstance::VisualInstance()
-{
+VisualInstance::VisualInstance() {
instance = VisualServer::get_singleton()->instance_create();
- VisualServer::get_singleton()->instance_attach_object_instance_ID( instance, get_instance_ID() );
- layers=1;
+ VisualServer::get_singleton()->instance_attach_object_instance_ID(instance, get_instance_ID());
+ layers = 1;
set_notify_transform(true);
}
-
VisualInstance::~VisualInstance() {
VisualServer::get_singleton()->free(instance);
}
+void GeometryInstance::set_material_override(const Ref<Material> &p_material) {
-
-
-void GeometryInstance::set_material_override(const Ref<Material>& p_material) {
-
- material_override=p_material;
- VS::get_singleton()->instance_geometry_set_material_override(get_instance(),p_material.is_valid() ? p_material->get_rid() : RID());
+ material_override = p_material;
+ VS::get_singleton()->instance_geometry_set_material_override(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID());
}
-Ref<Material> GeometryInstance::get_material_override() const{
+Ref<Material> GeometryInstance::get_material_override() const {
return material_override;
}
+void GeometryInstance::set_lod_min_distance(float p_dist) {
-
-void GeometryInstance::set_lod_min_distance(float p_dist){
-
- lod_min_distance=p_dist;
- VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
+ lod_min_distance = p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
}
-float GeometryInstance::get_lod_min_distance() const{
+float GeometryInstance::get_lod_min_distance() const {
return lod_min_distance;
}
-
void GeometryInstance::set_lod_max_distance(float p_dist) {
- lod_max_distance=p_dist;
- VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
-
+ lod_max_distance = p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
}
float GeometryInstance::get_lod_max_distance() const {
@@ -211,23 +191,21 @@ float GeometryInstance::get_lod_max_distance() const {
return lod_max_distance;
}
-void GeometryInstance::set_lod_min_hysteresis(float p_dist){
+void GeometryInstance::set_lod_min_hysteresis(float p_dist) {
- lod_min_hysteresis=p_dist;
- VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
+ lod_min_hysteresis = p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
}
-float GeometryInstance::get_lod_min_hysteresis() const{
+float GeometryInstance::get_lod_min_hysteresis() const {
return lod_min_hysteresis;
}
-
void GeometryInstance::set_lod_max_hysteresis(float p_dist) {
- lod_max_hysteresis=p_dist;
- VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
-
+ lod_max_hysteresis = p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
}
float GeometryInstance::get_lod_max_hysteresis() const {
@@ -235,64 +213,53 @@ float GeometryInstance::get_lod_max_hysteresis() const {
return lod_max_hysteresis;
}
-
void GeometryInstance::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_WORLD) {
+ if (p_what == NOTIFICATION_ENTER_WORLD) {
if (flags[FLAG_USE_BAKED_LIGHT]) {
-
}
-
- } else if (p_what==NOTIFICATION_EXIT_WORLD) {
+ } else if (p_what == NOTIFICATION_EXIT_WORLD) {
if (flags[FLAG_USE_BAKED_LIGHT]) {
-
-
}
-
}
-
}
-void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
+void GeometryInstance::set_flag(Flags p_flag, bool p_value) {
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- if (p_flag==FLAG_CAST_SHADOW) {
+ ERR_FAIL_INDEX(p_flag, FLAG_MAX);
+ if (p_flag == FLAG_CAST_SHADOW) {
if (p_value == true) {
set_cast_shadows_setting(SHADOW_CASTING_SETTING_ON);
- }
- else {
+ } else {
set_cast_shadows_setting(SHADOW_CASTING_SETTING_OFF);
}
}
- if (flags[p_flag]==p_value)
+ if (flags[p_flag] == p_value)
return;
- flags[p_flag]=p_value;
- VS::get_singleton()->instance_geometry_set_flag(get_instance(),(VS::InstanceFlags)p_flag,p_value);
- if (p_flag==FLAG_USE_BAKED_LIGHT) {
-
+ flags[p_flag] = p_value;
+ VS::get_singleton()->instance_geometry_set_flag(get_instance(), (VS::InstanceFlags)p_flag, p_value);
+ if (p_flag == FLAG_USE_BAKED_LIGHT) {
}
}
-bool GeometryInstance::get_flag(Flags p_flag) const{
+bool GeometryInstance::get_flag(Flags p_flag) const {
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
+ ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
if (p_flag == FLAG_CAST_SHADOW) {
if (shadow_casting_setting == SHADOW_CASTING_SETTING_OFF) {
return false;
- }
- else {
+ } else {
return true;
}
}
return flags[p_flag];
-
}
void GeometryInstance::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) {
@@ -307,99 +274,90 @@ GeometryInstance::ShadowCastingSetting GeometryInstance::get_cast_shadows_settin
return shadow_casting_setting;
}
-
-
-
void GeometryInstance::set_extra_cull_margin(float p_margin) {
- ERR_FAIL_COND(p_margin<0);
- extra_cull_margin=p_margin;
- VS::get_singleton()->instance_set_extra_visibility_margin(get_instance(),extra_cull_margin);
+ ERR_FAIL_COND(p_margin < 0);
+ extra_cull_margin = p_margin;
+ VS::get_singleton()->instance_set_extra_visibility_margin(get_instance(), extra_cull_margin);
}
-float GeometryInstance::get_extra_cull_margin() const{
+float GeometryInstance::get_extra_cull_margin() const {
return extra_cull_margin;
}
void GeometryInstance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_material_override","material"), &GeometryInstance::set_material_override);
+ ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance::set_material_override);
ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance::get_material_override);
- ClassDB::bind_method(D_METHOD("set_flag","flag","value"), &GeometryInstance::set_flag);
- ClassDB::bind_method(D_METHOD("get_flag","flag"), &GeometryInstance::get_flag);
+ ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance::set_flag);
+ ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance::get_flag);
ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance::set_cast_shadows_setting);
ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance::get_cast_shadows_setting);
- ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis","mode"), &GeometryInstance::set_lod_max_hysteresis);
+ ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance::set_lod_max_hysteresis);
ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance::get_lod_max_hysteresis);
- ClassDB::bind_method(D_METHOD("set_lod_max_distance","mode"), &GeometryInstance::set_lod_max_distance);
+ ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance::set_lod_max_distance);
ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance::get_lod_max_distance);
- ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis","mode"), &GeometryInstance::set_lod_min_hysteresis);
+ ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance::set_lod_min_hysteresis);
ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance::get_lod_min_hysteresis);
- ClassDB::bind_method(D_METHOD("set_lod_min_distance","mode"), &GeometryInstance::set_lod_min_distance);
+ ClassDB::bind_method(D_METHOD("set_lod_min_distance", "mode"), &GeometryInstance::set_lod_min_distance);
ClassDB::bind_method(D_METHOD("get_lod_min_distance"), &GeometryInstance::get_lod_min_distance);
-
- ClassDB::bind_method(D_METHOD("set_extra_cull_margin","margin"), &GeometryInstance::set_extra_cull_margin);
+ ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance::set_extra_cull_margin);
ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance::get_extra_cull_margin);
- ClassDB::bind_method(D_METHOD("get_aabb"),&GeometryInstance::get_aabb);
+ ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance::get_aabb);
-
- ADD_GROUP("Geometry","");
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "material_override",PROPERTY_HINT_RESOURCE_TYPE,"Material"), "set_material_override", "get_material_override");
+ ADD_GROUP("Geometry", "");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material_override", "get_material_override");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "extra_cull_margin",PROPERTY_HINT_RANGE,"0,16384,0"), "set_extra_cull_margin", "get_extra_cull_margin");
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "use_as_billboard"), "set_flag", "get_flag",FLAG_BILLBOARD);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "use_as_y_billboard"), "set_flag", "get_flag",FLAG_BILLBOARD_FIX_Y);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "use_depth_scale"), "set_flag", "get_flag",FLAG_DEPH_SCALE);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "visible_in_all_rooms"), "set_flag", "get_flag",FLAG_VISIBLE_IN_ALL_ROOMS);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "use_in_baked_light"), "set_flag", "get_flag",FLAG_USE_BAKED_LIGHT);
-
- ADD_GROUP("LOD","lod_");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "lod_min_distance",PROPERTY_HINT_RANGE,"0,32768,0.01"), "set_lod_min_distance", "get_lod_min_distance");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "lod_min_hysteresis",PROPERTY_HINT_RANGE,"0,32768,0.01"), "set_lod_min_hysteresis", "get_lod_min_hysteresis");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "lod_max_distance",PROPERTY_HINT_RANGE,"0,32768,0.01"), "set_lod_max_distance", "get_lod_max_distance");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "lod_max_hysteresis",PROPERTY_HINT_RANGE,"0,32768,0.01"), "set_lod_max_hysteresis", "get_lod_max_hysteresis");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0"), "set_extra_cull_margin", "get_extra_cull_margin");
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_as_billboard"), "set_flag", "get_flag", FLAG_BILLBOARD);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_as_y_billboard"), "set_flag", "get_flag", FLAG_BILLBOARD_FIX_Y);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_depth_scale"), "set_flag", "get_flag", FLAG_DEPH_SCALE);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "visible_in_all_rooms"), "set_flag", "get_flag", FLAG_VISIBLE_IN_ALL_ROOMS);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_in_baked_light"), "set_flag", "get_flag", FLAG_USE_BAKED_LIGHT);
+
+ ADD_GROUP("LOD", "lod_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_distance", "get_lod_min_distance");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_hysteresis", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_hysteresis", "get_lod_min_hysteresis");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_max_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_max_distance", "get_lod_max_distance");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_max_hysteresis", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_max_hysteresis", "get_lod_max_hysteresis");
//ADD_SIGNAL( MethodInfo("visibility_changed"));
- BIND_CONSTANT(FLAG_CAST_SHADOW );
- BIND_CONSTANT(FLAG_BILLBOARD );
- BIND_CONSTANT(FLAG_BILLBOARD_FIX_Y );
- BIND_CONSTANT(FLAG_DEPH_SCALE );
- BIND_CONSTANT(FLAG_VISIBLE_IN_ALL_ROOMS );
- BIND_CONSTANT(FLAG_MAX );
+ BIND_CONSTANT(FLAG_CAST_SHADOW);
+ BIND_CONSTANT(FLAG_BILLBOARD);
+ BIND_CONSTANT(FLAG_BILLBOARD_FIX_Y);
+ BIND_CONSTANT(FLAG_DEPH_SCALE);
+ BIND_CONSTANT(FLAG_VISIBLE_IN_ALL_ROOMS);
+ BIND_CONSTANT(FLAG_MAX);
BIND_CONSTANT(SHADOW_CASTING_SETTING_OFF);
BIND_CONSTANT(SHADOW_CASTING_SETTING_ON);
BIND_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
BIND_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
-
}
GeometryInstance::GeometryInstance() {
- lod_min_distance=0;
- lod_max_distance=0;
- lod_min_hysteresis=0;
- lod_max_hysteresis=0;
+ lod_min_distance = 0;
+ lod_max_distance = 0;
+ lod_min_hysteresis = 0;
+ lod_max_hysteresis = 0;
- for(int i=0;i<FLAG_MAX;i++) {
- flags[i]=false;
+ for (int i = 0; i < FLAG_MAX; i++) {
+ flags[i] = false;
}
+ flags[FLAG_CAST_SHADOW] = true;
- flags[FLAG_CAST_SHADOW]=true;
-
- shadow_casting_setting=SHADOW_CASTING_SETTING_ON;
- extra_cull_margin=0;
+ shadow_casting_setting = SHADOW_CASTING_SETTING_ON;
+ extra_cull_margin = 0;
//VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0);
-
-
}
diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h
index 5955dae236..9f1cba923f 100644
--- a/scene/3d/visual_instance.h
+++ b/scene/3d/visual_instance.h
@@ -29,85 +29,77 @@
#ifndef VISUAL_INSTANCE_H
#define VISUAL_INSTANCE_H
-#include "scene/3d/spatial.h"
#include "face3.h"
#include "rid.h"
+#include "scene/3d/spatial.h"
#include "scene/resources/material.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class VisualInstance : public Spatial {
- GDCLASS( VisualInstance, Spatial );
+ GDCLASS(VisualInstance, Spatial);
OBJ_CATEGORY("3D Visual Nodes");
RID instance;
uint32_t layers;
-
RID _get_visual_instance_rid() const;
-
-
protected:
-
void _update_visibility();
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
enum GetFacesFlags {
- FACES_SOLID=1, // solid geometry
- FACES_ENCLOSING=2,
- FACES_DYNAMIC=4 // dynamic object geometry
+ FACES_SOLID = 1, // solid geometry
+ FACES_ENCLOSING = 2,
+ FACES_DYNAMIC = 4 // dynamic object geometry
};
RID get_instance() const;
- virtual Rect3 get_aabb() const=0;
- virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const=0;
+ virtual Rect3 get_aabb() const = 0;
+ virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const = 0;
virtual Rect3 get_transformed_aabb() const; // helper
- void set_base(const RID& p_base);
+ void set_base(const RID &p_base);
void set_layer_mask(uint32_t p_mask);
uint32_t get_layer_mask() const;
-
VisualInstance();
~VisualInstance();
-
};
class BakedLight;
class GeometryInstance : public VisualInstance {
- GDCLASS( GeometryInstance, VisualInstance );
-public:
+ GDCLASS(GeometryInstance, VisualInstance);
+public:
enum Flags {
- FLAG_CAST_SHADOW=VS::INSTANCE_FLAG_CAST_SHADOW,
- FLAG_BILLBOARD=VS::INSTANCE_FLAG_BILLBOARD,
- FLAG_BILLBOARD_FIX_Y=VS::INSTANCE_FLAG_BILLBOARD_FIX_Y,
- FLAG_DEPH_SCALE=VS::INSTANCE_FLAG_DEPH_SCALE,
- FLAG_VISIBLE_IN_ALL_ROOMS=VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,
- FLAG_USE_BAKED_LIGHT=VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
- FLAG_MAX=VS::INSTANCE_FLAG_MAX,
+ FLAG_CAST_SHADOW = VS::INSTANCE_FLAG_CAST_SHADOW,
+ FLAG_BILLBOARD = VS::INSTANCE_FLAG_BILLBOARD,
+ FLAG_BILLBOARD_FIX_Y = VS::INSTANCE_FLAG_BILLBOARD_FIX_Y,
+ FLAG_DEPH_SCALE = VS::INSTANCE_FLAG_DEPH_SCALE,
+ FLAG_VISIBLE_IN_ALL_ROOMS = VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,
+ FLAG_USE_BAKED_LIGHT = VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
+ FLAG_MAX = VS::INSTANCE_FLAG_MAX,
};
-
enum ShadowCastingSetting {
- SHADOW_CASTING_SETTING_OFF=VS::SHADOW_CASTING_SETTING_OFF,
+ SHADOW_CASTING_SETTING_OFF = VS::SHADOW_CASTING_SETTING_OFF,
SHADOW_CASTING_SETTING_ON = VS::SHADOW_CASTING_SETTING_ON,
- SHADOW_CASTING_SETTING_DOUBLE_SIDED=VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED,
- SHADOW_CASTING_SETTING_SHADOWS_ONLY=VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY
+ SHADOW_CASTING_SETTING_DOUBLE_SIDED = VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED,
+ SHADOW_CASTING_SETTING_SHADOWS_ONLY = VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY
};
private:
-
bool flags[FLAG_MAX];
ShadowCastingSetting shadow_casting_setting;
Ref<Material> material_override;
@@ -119,12 +111,11 @@ private:
float extra_cull_margin;
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_flag(Flags p_flag,bool p_value);
+public:
+ void set_flag(Flags p_flag, bool p_value);
bool get_flag(Flags p_flag) const;
void set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
@@ -142,7 +133,7 @@ public:
void set_lod_max_hysteresis(float p_dist);
float get_lod_max_hysteresis() const;
- void set_material_override(const Ref<Material>& p_material);
+ void set_material_override(const Ref<Material> &p_material);
Ref<Material> get_material_override() const;
void set_extra_cull_margin(float p_margin);
@@ -151,8 +142,7 @@ public:
GeometryInstance();
};
-VARIANT_ENUM_CAST( GeometryInstance::Flags );
-VARIANT_ENUM_CAST( GeometryInstance::ShadowCastingSetting );
-
+VARIANT_ENUM_CAST(GeometryInstance::Flags);
+VARIANT_ENUM_CAST(GeometryInstance::ShadowCastingSetting);
#endif