Added API to generate a MeshData object for a Dali::Path object 45/35545/2
authorFerran Sole <ferran.sole@samsung.com>
Tue, 17 Feb 2015 11:45:51 +0000 (11:45 +0000)
committerFerran Sole <ferran.sole@samsung.com>
Mon, 2 Mar 2015 15:41:01 +0000 (07:41 -0800)
The method aproximates the path by sampling at regular intervals and
connecting each sampled point to the next sample with a line.

Change-Id: Ia32751f4b5e9b55d679a7dd2c1592d12e566c52a

dali/public-api/geometry/mesh-factory.cpp
dali/public-api/geometry/mesh-factory.h

index c8e2737..03b9660 100644 (file)
@@ -105,5 +105,41 @@ Dali::MeshData NewPlane(const float width, const float height, const int xSteps,
   return meshData;
 }
 
+Dali::MeshData NewPath( Dali::Path path, const unsigned int resolution )
+{
+  MeshData meshData;
+  meshData.SetHasNormals(false);
+  meshData.SetHasTextureCoords(false);
+
+  if( resolution != 0 )
+  {
+    size_t vertexCount(resolution+1);
+    MeshData::VertexContainer vertex(vertexCount);
+
+    float sampleDelta = 1.0f/(float)resolution;
+    Vector3 tangent;
+    for( size_t i(0); i!=vertexCount; ++i )
+    {
+      //Sample path to get the vertex position
+      Vector3* vertexPosition = reinterpret_cast<Vector3*>(&vertex[i].x);
+      path.Sample( i*sampleDelta, *vertexPosition, tangent );
+    }
+
+    //Generate indices. Each vertex is connected to the next
+    size_t indexCount(resolution*2);
+    MeshData::FaceIndices index(indexCount);
+    unsigned int nIndex = 0;
+    for( size_t i(0); i!=indexCount; i+=2 )
+    {
+      index[i] = nIndex;
+      index[i+1] = ++nIndex;
+    }
+
+    meshData.SetLineData(vertex, index, Dali::Material::New("PathMat"));
+  }
+
+  return meshData;
+}
+
 } // MeshFactory
 } // Dali
index 2a57ee4..25c6176 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <dali/public-api/math/rect.h>
+#include <dali/public-api/animation/path.h>
 
 namespace Dali
 {
@@ -42,6 +43,16 @@ DALI_IMPORT_API Dali::MeshData NewPlane( const float width,
                                          const int ySteps,
                                          const Rect<float>& textureCoordinates = Rect<float>(0.0f, 0.0f, 1.0f, 1.0f) );
 
+/**
+ * @brief Create a mesh from a given path.
+ * The mesh generated will be a set of lines, each one connecting a point sampled from the path to the next sampled point.
+ *
+ * @param[in] path The path used to generate the mesh
+ * @param[in] resolution The number of vertices to generate
+ * @return A mesh data structure containing the path mesh
+ */
+DALI_IMPORT_API Dali::MeshData NewPath( Dali::Path path, const unsigned int resolution );
+
 } // MeshFactory
 } // Dali