Merge pull request #48763 from QbieShay/plane-offset

[3.x] Added a center_offset property to both plane primitive and quad primitive
This commit is contained in:
Rémi Verschelde 2021-07-12 10:32:19 +02:00 committed by GitHub
commit 6ec2caf12c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 6 deletions

View file

@ -12,6 +12,9 @@
<methods> <methods>
</methods> </methods>
<members> <members>
<member name="center_offset" type="Vector3" setter="set_center_offset" getter="get_center_offset" default="Vector3( 0, 0, 0 )">
Offset from the origin of the generated plane. Useful for particles.
</member>
<member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2( 2, 2 )"> <member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2( 2, 2 )">
Size of the generated plane. Size of the generated plane.
</member> </member>

View file

@ -13,6 +13,9 @@
<methods> <methods>
</methods> </methods>
<members> <members>
<member name="center_offset" type="Vector3" setter="set_center_offset" getter="get_center_offset" default="Vector3( 0, 0, 0 )">
Offset of the generated Quad. Useful for particles.
</member>
<member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2( 1, 1 )"> <member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2( 1, 1 )">
Size on the X and Y axes. Size on the X and Y axes.
</member> </member>

View file

@ -982,7 +982,7 @@ void PlaneMesh::_create_mesh_array(Array &p_arr) const {
u /= (subdivide_w + 1.0); u /= (subdivide_w + 1.0);
v /= (subdivide_d + 1.0); v /= (subdivide_d + 1.0);
points.push_back(Vector3(-x, 0.0, -z)); points.push_back(Vector3(-x, 0.0, -z) + center_offset);
normals.push_back(Vector3(0.0, 1.0, 0.0)); normals.push_back(Vector3(0.0, 1.0, 0.0));
ADD_TANGENT(1.0, 0.0, 0.0, 1.0); ADD_TANGENT(1.0, 0.0, 0.0, 1.0);
uvs.push_back(Vector2(1.0 - u, 1.0 - v)); /* 1.0 - uv to match orientation with Quad */ uvs.push_back(Vector2(1.0 - u, 1.0 - v)); /* 1.0 - uv to match orientation with Quad */
@ -1020,10 +1020,13 @@ void PlaneMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_subdivide_width"), &PlaneMesh::get_subdivide_width); ClassDB::bind_method(D_METHOD("get_subdivide_width"), &PlaneMesh::get_subdivide_width);
ClassDB::bind_method(D_METHOD("set_subdivide_depth", "subdivide"), &PlaneMesh::set_subdivide_depth); ClassDB::bind_method(D_METHOD("set_subdivide_depth", "subdivide"), &PlaneMesh::set_subdivide_depth);
ClassDB::bind_method(D_METHOD("get_subdivide_depth"), &PlaneMesh::get_subdivide_depth); ClassDB::bind_method(D_METHOD("get_subdivide_depth"), &PlaneMesh::get_subdivide_depth);
ClassDB::bind_method(D_METHOD("set_center_offset", "offset"), &PlaneMesh::set_center_offset);
ClassDB::bind_method(D_METHOD("get_center_offset"), &PlaneMesh::get_center_offset);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_width", "get_subdivide_width"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_width", "get_subdivide_width");
ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_depth", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_depth", "get_subdivide_depth"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_depth", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_depth", "get_subdivide_depth");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_offset"), "set_center_offset", "get_center_offset");
} }
void PlaneMesh::set_size(const Size2 &p_size) { void PlaneMesh::set_size(const Size2 &p_size) {
@ -1053,11 +1056,21 @@ int PlaneMesh::get_subdivide_depth() const {
return subdivide_d; return subdivide_d;
} }
void PlaneMesh::set_center_offset(const Vector3 p_offset) {
center_offset = p_offset;
_request_update();
}
Vector3 PlaneMesh::get_center_offset() const {
return center_offset;
}
PlaneMesh::PlaneMesh() { PlaneMesh::PlaneMesh() {
// defaults // defaults
size = Size2(2.0, 2.0); size = Size2(2.0, 2.0);
subdivide_w = 0; subdivide_w = 0;
subdivide_d = 0; subdivide_d = 0;
center_offset = Vector3(0.0, 0.0, 0.0);
} }
/** /**
@ -1365,10 +1378,10 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const {
Vector2 _size = Vector2(size.x / 2.0f, size.y / 2.0f); Vector2 _size = Vector2(size.x / 2.0f, size.y / 2.0f);
Vector3 quad_faces[4] = { Vector3 quad_faces[4] = {
Vector3(-_size.x, -_size.y, 0), Vector3(-_size.x, -_size.y, 0) + center_offset,
Vector3(-_size.x, _size.y, 0), Vector3(-_size.x, _size.y, 0) + center_offset,
Vector3(_size.x, _size.y, 0), Vector3(_size.x, _size.y, 0) + center_offset,
Vector3(_size.x, -_size.y, 0), Vector3(_size.x, -_size.y, 0) + center_offset,
}; };
static const int indices[6] = { static const int indices[6] = {
@ -1404,12 +1417,17 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const {
void QuadMesh::_bind_methods() { void QuadMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_size", "size"), &QuadMesh::set_size); ClassDB::bind_method(D_METHOD("set_size", "size"), &QuadMesh::set_size);
ClassDB::bind_method(D_METHOD("get_size"), &QuadMesh::get_size); ClassDB::bind_method(D_METHOD("get_size"), &QuadMesh::get_size);
ClassDB::bind_method(D_METHOD("set_center_offset", "center_offset"), &QuadMesh::set_center_offset);
ClassDB::bind_method(D_METHOD("get_center_offset"), &QuadMesh::get_center_offset);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_offset"), "set_center_offset", "get_center_offset");
} }
QuadMesh::QuadMesh() { QuadMesh::QuadMesh() {
primitive_type = PRIMITIVE_TRIANGLES; primitive_type = PRIMITIVE_TRIANGLES;
size = Size2(1.0, 1.0); size = Size2(1.0, 1.0);
center_offset = Vector3(0.0, 0.0, 0.0);
} }
void QuadMesh::set_size(const Size2 &p_size) { void QuadMesh::set_size(const Size2 &p_size) {
@ -1421,6 +1439,15 @@ Size2 QuadMesh::get_size() const {
return size; return size;
} }
void QuadMesh::set_center_offset(Vector3 p_center_offset) {
center_offset = p_center_offset;
_request_update();
}
Vector3 QuadMesh::get_center_offset() const {
return center_offset;
}
/** /**
SphereMesh SphereMesh
*/ */

View file

@ -205,6 +205,7 @@ private:
Size2 size; Size2 size;
int subdivide_w; int subdivide_w;
int subdivide_d; int subdivide_d;
Vector3 center_offset;
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -220,6 +221,9 @@ public:
void set_subdivide_depth(const int p_divisions); void set_subdivide_depth(const int p_divisions);
int get_subdivide_depth() const; int get_subdivide_depth() const;
void set_center_offset(const Vector3 p_offset);
Vector3 get_center_offset() const;
PlaneMesh(); PlaneMesh();
}; };
@ -268,6 +272,7 @@ class QuadMesh : public PrimitiveMesh {
private: private:
Size2 size; Size2 size;
Vector3 center_offset;
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -278,6 +283,9 @@ public:
void set_size(const Size2 &p_size); void set_size(const Size2 &p_size);
Size2 get_size() const; Size2 get_size() const;
void set_center_offset(const Vector3 p_offset);
Vector3 get_center_offset() const;
}; };
/** /**