diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-11-13 22:42:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 22:42:32 +0100 |
commit | f3d812e3a0549e1235184713c8ebe0c6b26c9fde (patch) | |
tree | dbf2c4aa963ae21d724d2a7486cff4bf99b4e836 | |
parent | 4755bc9e2b45d0ed79a54e847e175c4692fabb39 (diff) | |
parent | 06ce2e339e80048ae0b5076dbdd69577630bfaef (diff) |
Merge pull request #12811 from Chaosus/quadsize
Add size to QuadMesh
-rw-r--r-- | scene/resources/primitive_meshes.cpp | 38 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.h | 5 |
2 files changed, 30 insertions, 13 deletions
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index ba356d89b1..8e3899315c 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -1299,14 +1299,16 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { tangents.resize(4 * 4); uvs.resize(4); - for (int i = 0; i < 4; i++) { + Vector2 _size = Vector2(size.x / 2.0f, size.y / 2.0f); - static const Vector3 quad_faces[4] = { - Vector3(-1, -1, 0), - Vector3(-1, 1, 0), - Vector3(1, 1, 0), - Vector3(1, -1, 0), - }; + Vector3 quad_faces[4] = { + Vector3(-_size.x, -_size.y, 0), + Vector3(-_size.x, _size.y, 0), + Vector3(_size.x, _size.y, 0), + Vector3(_size.x, -_size.y, 0), + }; + + for (int i = 0; i < 4; i++) { faces.set(i, quad_faces[i]); normals.set(i, Vector3(0, 0, 1)); @@ -1325,18 +1327,30 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { uvs.set(i, quad_uv[i]); } - p_arr[ARRAY_VERTEX] = faces; - p_arr[ARRAY_NORMAL] = normals; - p_arr[ARRAY_TANGENT] = tangents; - p_arr[ARRAY_TEX_UV] = uvs; + p_arr[VS::ARRAY_VERTEX] = faces; + p_arr[VS::ARRAY_NORMAL] = normals; + p_arr[VS::ARRAY_TANGENT] = tangents; + p_arr[VS::ARRAY_TEX_UV] = uvs; }; void QuadMesh::_bind_methods() { - // nothing here yet... + ClassDB::bind_method(D_METHOD("set_size", "size"), &QuadMesh::set_size); + ClassDB::bind_method(D_METHOD("get_size"), &QuadMesh::get_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); } QuadMesh::QuadMesh() { primitive_type = PRIMITIVE_TRIANGLE_FAN; + size = Size2(1.0, 1.0); +} + +void QuadMesh::set_size(const Size2 &p_size) { + size = p_size; + _request_update(); +} + +Size2 QuadMesh::get_size() const { + return size; } /** diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index 38a5695883..f0c8935261 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -263,7 +263,7 @@ class QuadMesh : public PrimitiveMesh { GDCLASS(QuadMesh, PrimitiveMesh) private: - // nothing? really? Maybe add size some day atleast... :) + Size2 size; protected: static void _bind_methods(); @@ -271,6 +271,9 @@ protected: public: QuadMesh(); + + void set_size(const Size2 &p_size); + Size2 get_size() const; }; /** |