From: Ferran Sole Date: Tue, 17 Feb 2015 11:45:51 +0000 (+0000) Subject: Added API to generate a MeshData object for a Dali::Path object X-Git-Tag: dali_1.0.32~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F45%2F35545%2F2;p=platform%2Fcore%2Fuifw%2Fdali-core.git Added API to generate a MeshData object for a Dali::Path object 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 --- diff --git a/dali/public-api/geometry/mesh-factory.cpp b/dali/public-api/geometry/mesh-factory.cpp index c8e2737..03b9660 100644 --- a/dali/public-api/geometry/mesh-factory.cpp +++ b/dali/public-api/geometry/mesh-factory.cpp @@ -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(&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 diff --git a/dali/public-api/geometry/mesh-factory.h b/dali/public-api/geometry/mesh-factory.h index 2a57ee4..25c6176 100644 --- a/dali/public-api/geometry/mesh-factory.h +++ b/dali/public-api/geometry/mesh-factory.h @@ -18,6 +18,7 @@ */ #include +#include namespace Dali { @@ -42,6 +43,16 @@ DALI_IMPORT_API Dali::MeshData NewPlane( const float width, const int ySteps, const Rect& textureCoordinates = Rect(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