diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-09-06 19:31:44 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-09-06 19:31:44 -0300 |
commit | f31400c04d49aee2d2433b5404e2f17cf54da3a1 (patch) | |
tree | 2d57cf437cce3978b834583334f1b453f4acfa2c | |
parent | 23ababdcd57079182172b1c5467fcd6bb0f303d3 (diff) |
Added option for UVs (and tangents) in adding sphere for ImmediateGeometry, closes #6398
-rw-r--r-- | scene/3d/immediate_geometry.cpp | 8 | ||||
-rw-r--r-- | scene/3d/immediate_geometry.h | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry.cpp index e83fa69b4f..c9319904bd 100644 --- a/scene/3d/immediate_geometry.cpp +++ b/scene/3d/immediate_geometry.cpp @@ -102,7 +102,7 @@ DVector<Face3> ImmediateGeometry::get_faces(uint32_t p_usage_flags) const { -void ImmediateGeometry::add_sphere(int p_lats,int p_lons,float p_radius) { +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); @@ -132,6 +132,10 @@ void ImmediateGeometry::add_sphere(int p_lats,int p_lons,float 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); @@ -156,7 +160,7 @@ void ImmediateGeometry::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_uv","uv"),&ImmediateGeometry::set_uv); ObjectTypeDB::bind_method(_MD("set_uv2","uv"),&ImmediateGeometry::set_uv2); ObjectTypeDB::bind_method(_MD("add_vertex","pos"),&ImmediateGeometry::add_vertex); - ObjectTypeDB::bind_method(_MD("add_sphere","lats","lons","radius"),&ImmediateGeometry::add_sphere); + ObjectTypeDB::bind_method(_MD("add_sphere","lats","lons","radius","add_uv"),&ImmediateGeometry::add_sphere,DEFVAL(true)); ObjectTypeDB::bind_method(_MD("end"),&ImmediateGeometry::end); ObjectTypeDB::bind_method(_MD("clear"),&ImmediateGeometry::clear); diff --git a/scene/3d/immediate_geometry.h b/scene/3d/immediate_geometry.h index c1cc4f87d5..fc7f4de634 100644 --- a/scene/3d/immediate_geometry.h +++ b/scene/3d/immediate_geometry.h @@ -62,7 +62,7 @@ public: void clear(); - void add_sphere(int p_lats,int p_lons,float p_radius); + void add_sphere(int p_lats,int p_lons,float p_radius,bool p_add_uv=true); |