Beispiel #1
0
Geometry BubbleEmitter::CreateGeometry( unsigned int numOfPatch )
{
  unsigned int numVertex = numOfPatch*4u;
  std::vector<Vertex> vertexData;
  vertexData.reserve( numVertex );

  unsigned int numIndex = numOfPatch*6u;
  Vector<unsigned int> indexData;
  indexData.Reserve( numIndex );

  for(unsigned int i = 0; i < numOfPatch; i++)
  {
    float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y, mRandomSeed);

    float index = static_cast<float>( i );
    vertexData.push_back( Vertex( index, Vector2(0.f,0.f),         Vector2(0.f,0.f) ) );
    vertexData.push_back( Vertex( index, Vector2(0.f,curSize),     Vector2(0.f,1.f)  ) );
    vertexData.push_back( Vertex( index, Vector2(curSize,curSize), Vector2(1.f,1.f)  ) );
    vertexData.push_back( Vertex( index, Vector2(curSize,0.f),     Vector2(1.f,0.f)  ) );

    unsigned int idx = index * 4;
    indexData.PushBack( idx );
    indexData.PushBack( idx+1 );
    indexData.PushBack( idx+2 );
    indexData.PushBack( idx );
    indexData.PushBack( idx+2 );
    indexData.PushBack( idx+3 );
  }

  Property::Map vertexFormat;
  vertexFormat["aIndex"] = Property::FLOAT;
  vertexFormat["aPosition"] = Property::VECTOR2;
  vertexFormat["aTexCoord"] = Property::VECTOR2;
  PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, numVertex  );
  vertices.SetData( &vertexData[0] );

  Property::Map indexFormat;
  indexFormat["indices"] = Property::INTEGER;
  PropertyBuffer indices = PropertyBuffer::New( indexFormat, numIndex  );
  indices.SetData( &indexData[0] );

  Geometry geometry = Geometry::New();
  geometry.AddVertexBuffer( vertices );
  geometry.SetIndexBuffer( indices );

  return geometry;
}
  /**
   * @brief Creates a geometry object from vertices and indices.
   * @param[in] vertices The object vertices
   * @param[in] indices The object indices
   * @return A geometry object
   */
  Geometry CreateTexturedGeometry( Vector<TexturedVertex>& vertices, Vector<unsigned short>& indices )
  {
    // Vertices
    Property::Map vertexFormat;
    vertexFormat[POSITION] = Property::VECTOR3;
    vertexFormat[NORMAL] =   Property::VECTOR3;
    vertexFormat[TEXTURE] =  Property::VECTOR2;

    PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat );
    surfaceVertices.SetData( &vertices[0u], vertices.Size() );

    Geometry geometry = Geometry::New();
    geometry.AddVertexBuffer( surfaceVertices );

    // Indices for triangle formulation
    geometry.SetIndexBuffer( &indices[0u], indices.Size() );
    return geometry;
  }
Beispiel #3
0
/**
 * Add a PropertyBuffer to be used as source of geometry vertices
 *
 * @method addVertexBuffer
 * @for Geometry
 * @param {Object} vertexBuffer PropertyBuffer to be used as source of geometry vertices
 * @return {interger} Index of the newly added buffer, can be used with RemoveVertexBuffer
 *                    to remove this buffer if no longer required
 * @example
 *```
 *    var vertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2 };
 *    var vertexData = [    0,     1,
 *                      -0.95,  0.31,
 *                      -0.59, -0.81,
 *                       0.59, -0.81,
 *                       0.95,  0.31];
 *
 *    var vertexDataArray = new Float32Array(vertexData.length);
 *    vertexDataArray.set(vertexData, 0);
 *    var vertices = new dali.PropertyBuffer(vertexFormat, 5);
 *    vertices.setData(vertexDataArray);
 *
 *    var geometry = new dali.Geometry();
 *    geometry.addVertexBuffer( vertices );
 *```
 */
void GeometryApi::AddVertexBuffer( const v8::FunctionCallbackInfo< v8::Value >& args )
{
  v8::Isolate* isolate = args.GetIsolate();
  v8::HandleScope handleScope( isolate );

  Geometry geometry = GetGeometry( isolate, args );

  bool found( false );
  PropertyBuffer vertexBuffer = PropertyBufferApi::GetPropertyBufferFromParams( 0, found, isolate, args );
  if( !found )
  {
    DALI_SCRIPT_EXCEPTION( isolate, "invalid property buffer parameter" );
  }
  else
  {
    args.GetReturnValue().Set( v8::Integer::New( isolate, geometry.AddVertexBuffer(vertexBuffer) ) );
  }
}
Geometry CreateQuadGeometry(void)
{
  PropertyBuffer vertexData = CreatePropertyBuffer();
  const float halfQuadSize = .5f;
  struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
  TexturedQuadVertex texturedQuadVertexData[4] = {
    { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
    { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
    { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
    { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
  vertexData.SetData(texturedQuadVertexData, 4);

  unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 };

  Geometry geometry = Geometry::New();
  geometry.AddVertexBuffer( vertexData );
  geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );

  return geometry;
}