diff options
author | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2016-04-18 20:33:54 +0300 |
---|---|---|
committer | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2016-04-18 20:33:54 +0300 |
commit | 325a02e4af082fcef6173fb1a100eab2ecd936b1 (patch) | |
tree | 6bf575b6274aeed0ad0e7a797ee72ccc542b80c5 /scene/resources | |
parent | bf0f9141409fd5f754c2b4e8dea0e5ea6f156896 (diff) |
Add a add_triangle_fan method to SurfaceTool
Closes #4298
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/surface_tool.cpp | 31 | ||||
-rw-r--r-- | scene/resources/surface_tool.h | 2 |
2 files changed, 33 insertions, 0 deletions
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index e3a02420c7..de4bb4122d 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "surface_tool.h" +#include "method_bind_ext.inc" #define _VERTEX_SNAP 0.0001 #define EQ_VERTEX_DIST 0.00001 @@ -196,6 +197,35 @@ void SurfaceTool::add_smooth_group(bool p_smooth) { } } +void SurfaceTool::add_triangle_fan(const Vector<Vector3>& p_vertexes, const Vector<Vector2>& p_uvs, const Vector<Color>& p_colors,const Vector<Vector2>& p_uv2s, const Vector<Vector3>& p_normals, const Vector<Plane>& p_tangents) { + ERR_FAIL_COND(!begun); + ERR_FAIL_COND(primitive!=Mesh::PRIMITIVE_TRIANGLES); + ERR_FAIL_COND(p_vertexes.size()<3); + +#define ADD_POINT(n)\ + {\ + if(p_colors.size() > n)\ + add_color(p_colors[n]);\ + if(p_uvs.size() > n)\ + add_uv(p_uvs[n]);\ + if(p_uv2s.size() > n)\ + add_uv2(p_uv2s[n]);\ + if(p_normals.size() > n)\ + add_normal(p_normals[n]);\ + if(p_tangents.size() > n)\ + add_tangent(p_tangents[n]);\ + add_vertex(p_vertexes[n]);\ + } + + for(int i=0;i<p_vertexes.size() - 2;i++) { + ADD_POINT(0); + ADD_POINT(i+1); + ADD_POINT(i+2); + } + +#undef ADD_POINT + +} void SurfaceTool::add_index( int p_index) { @@ -826,6 +856,7 @@ void SurfaceTool::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_bones","bones"),&SurfaceTool::add_bones); ObjectTypeDB::bind_method(_MD("add_weights","weights"),&SurfaceTool::add_weights); ObjectTypeDB::bind_method(_MD("add_smooth_group","smooth"),&SurfaceTool::add_smooth_group); + ObjectTypeDB::bind_method(_MD("add_triangle_fan", "vertexes", "uvs", "colors", "uv2s", "normals", "tangents"),&SurfaceTool::add_triangle_fan, DEFVAL(Vector<Vector2>()), DEFVAL(Vector<Color>()), DEFVAL(Vector<Vector2>()),DEFVAL(Vector<Vector3>()), DEFVAL(Vector<Plane>())); ObjectTypeDB::bind_method(_MD("set_material","material:Material"),&SurfaceTool::set_material); ObjectTypeDB::bind_method(_MD("index"),&SurfaceTool::index); ObjectTypeDB::bind_method(_MD("deindex"),&SurfaceTool::deindex); diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h index 1d329f23c0..fa9724b142 100644 --- a/scene/resources/surface_tool.h +++ b/scene/resources/surface_tool.h @@ -108,6 +108,8 @@ public: void add_weights( const Vector<float>& p_weights); void add_smooth_group(bool p_smooth); + void add_triangle_fan( const Vector<Vector3>& p_vertexes, const Vector<Vector2>& p_uvs=Vector<Vector2>(), const Vector<Color>& p_colors=Vector<Color>(), const Vector<Vector2>& p_uv2s=Vector<Vector2>(), const Vector<Vector3>& p_normals=Vector<Vector3>(), const Vector<Plane>& p_tangents=Vector<Plane>() ); + void add_index( int p_index); void index(); |