Added option for UVs (and tangents) in adding sphere for ImmediateGeometry, closes #6398

(cherry picked from commit f31400c04d)
This commit is contained in:
Juan Linietsky 2016-09-06 19:31:44 -03:00 committed by Rémi Verschelde
parent c007d31e52
commit 7178399548
2 changed files with 7 additions and 3 deletions

View file

@ -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);

View file

@ -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);