Use box size instead of extents for Shape dimensions

This commit is contained in:
Marcel Admiraal 2020-12-07 17:52:11 +00:00
parent d5d99aaed6
commit 43c9106806
6 changed files with 32 additions and 32 deletions

View file

@ -14,8 +14,8 @@
<methods>
</methods>
<members>
<member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 1, 1, 1 )">
The box's half extents. The width, height and depth of this shape is twice the half extents.
<member name="size" type="Vector3" setter="set_size" getter="get_size" default="Vector3( 2, 2, 2 )">
The box's width, height and depth.
</member>
</members>
<constants>

View file

@ -429,7 +429,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
CollisionShape3D *colshape = memnew(CollisionShape3D);
if (empty_draw_type == "CUBE") {
BoxShape3D *boxShape = memnew(BoxShape3D);
boxShape->set_extents(Vector3(1, 1, 1));
boxShape->set_size(Vector3(2, 2, 2));
colshape->set_shape(boxShape);
colshape->set_name("BoxShape3D");
} else if (empty_draw_type == "SINGLE_ARROW") {

View file

@ -3541,7 +3541,7 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g
}
if (Object::cast_to<BoxShape3D>(*s)) {
return "Extents";
return "Size";
}
if (Object::cast_to<CapsuleShape3D>(*s)) {
@ -3574,7 +3574,7 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo
if (Object::cast_to<BoxShape3D>(*s)) {
Ref<BoxShape3D> bs = s;
return bs->get_extents();
return bs->get_size();
}
if (Object::cast_to<CapsuleShape3D>(*s)) {
@ -3658,9 +3658,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
d = 0.001;
}
Vector3 he = bs->get_extents();
he[p_idx] = d;
bs->set_extents(he);
Vector3 he = bs->get_size();
he[p_idx] = d * 2;
bs->set_size(he);
}
if (Object::cast_to<CapsuleShape3D>(*s)) {
@ -3737,14 +3737,14 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int
if (Object::cast_to<BoxShape3D>(*s)) {
Ref<BoxShape3D> ss = s;
if (p_cancel) {
ss->set_extents(p_restore);
ss->set_size(p_restore);
return;
}
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
ur->create_action(TTR("Change Box Shape Extents"));
ur->add_do_method(ss.ptr(), "set_extents", ss->get_extents());
ur->add_undo_method(ss.ptr(), "set_extents", p_restore);
ur->create_action(TTR("Change Box Shape Size"));
ur->add_do_method(ss.ptr(), "set_size", ss->get_size());
ur->add_undo_method(ss.ptr(), "set_size", p_restore);
ur->commit_action();
}
@ -3878,8 +3878,8 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<BoxShape3D> bs = s;
Vector<Vector3> lines;
AABB aabb;
aabb.position = -bs->get_extents();
aabb.size = aabb.position * -2;
aabb.position = -bs->get_size() / 2;
aabb.size = bs->get_size();
for (int i = 0; i < 12; i++) {
Vector3 a, b;
@ -3892,7 +3892,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
for (int i = 0; i < 3; i++) {
Vector3 ax;
ax[i] = bs->get_extents()[i];
ax[i] = bs->get_size()[i] / 2;
handles.push_back(ax);
}

View file

@ -178,7 +178,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform p_accumulated_transform,
if (box) {
Ref<BoxMesh> box_mesh;
box_mesh.instance();
box_mesh->set_size(box->get_extents() * 2.0);
box_mesh->set_size(box->get_size());
mesh = box_mesh;
}

View file

@ -34,8 +34,8 @@
Vector<Vector3> BoxShape3D::get_debug_mesh_lines() const {
Vector<Vector3> lines;
AABB aabb;
aabb.position = -get_extents();
aabb.size = aabb.position * -2;
aabb.position = -size / 2;
aabb.size = size;
for (int i = 0; i < 12; i++) {
Vector3 a, b;
@ -48,33 +48,33 @@ Vector<Vector3> BoxShape3D::get_debug_mesh_lines() const {
}
real_t BoxShape3D::get_enclosing_radius() const {
return extents.length();
return size.length() / 2;
}
void BoxShape3D::_update_shape() {
PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), extents);
PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), size / 2);
Shape3D::_update_shape();
}
void BoxShape3D::set_extents(const Vector3 &p_extents) {
extents = p_extents;
void BoxShape3D::set_size(const Vector3 &p_size) {
size = p_size;
_update_shape();
notify_change_to_owners();
_change_notify("extents");
_change_notify("size");
}
Vector3 BoxShape3D::get_extents() const {
return extents;
Vector3 BoxShape3D::get_size() const {
return size;
}
void BoxShape3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_extents", "extents"), &BoxShape3D::set_extents);
ClassDB::bind_method(D_METHOD("get_extents"), &BoxShape3D::get_extents);
ClassDB::bind_method(D_METHOD("set_size", "size"), &BoxShape3D::set_size);
ClassDB::bind_method(D_METHOD("get_size"), &BoxShape3D::get_size);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size");
}
BoxShape3D::BoxShape3D() :
Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_BOX)) {
set_extents(Vector3(1, 1, 1));
set_size(Vector3(2, 2, 2));
}

View file

@ -35,7 +35,7 @@
class BoxShape3D : public Shape3D {
GDCLASS(BoxShape3D, Shape3D);
Vector3 extents;
Vector3 size;
protected:
static void _bind_methods();
@ -43,8 +43,8 @@ protected:
virtual void _update_shape() override;
public:
void set_extents(const Vector3 &p_extents);
Vector3 get_extents() const;
void set_size(const Vector3 &p_size);
Vector3 get_size() const;
virtual Vector<Vector3> get_debug_mesh_lines() const override;
virtual real_t get_enclosing_radius() const override;