9dd40534553e7a0b55c61d7be73d6b102a9b6f52
[platform/core/uifw/dali-toolkit.git] / node-addon / line-mesh.js
1  var window= {
2            x:0,
3            y:0,
4            width:1920,
5            height: 1080,
6            transparent: false,
7            name:'line-mesh-app'
8  };
9
10  var viewMode={
11        'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced,
12        'stereo-base': 65 // Distance in millimeters between left/right cameras typically between (50-70mm)
13  };
14
15  var options= {
16     'window': window,
17     'view-mode': viewMode,
18  }
19
20 var dali = require('./build/Release/dali')( options );
21
22 var daliApp = {};
23
24 daliApp.createMeshActor = function() {
25
26       // Create shader
27       var vertShader =
28                "attribute mediump vec2    aPosition1;\
29                 attribute mediump vec2    aPosition2;\
30                 uniform   mediump mat4    uMvpMatrix;\
31                 uniform   mediump vec3    uSize;\
32                 uniform   mediump float   uMorphAmount;\
33                 void main()\
34                 {\
35                   mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount);\
36                   mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0);\
37                   vertexPosition.xyz *= uSize;\
38                   vertexPosition = uMvpMatrix * vertexPosition;\
39                   gl_Position = vertexPosition;\
40                 }";
41
42       var fragShader =
43                "uniform lowp  vec4    uColor;\
44                 uniform sampler2D     sTexture;\
45                 void main()\
46                 {\
47                   gl_FragColor = uColor;\
48                 }";
49
50       var shaderOptions = {
51               vertexShader : vertShader,
52               fragmentShader: fragShader
53           };
54
55       var shader = new dali.Shader(shaderOptions);
56
57       var material = new dali.Material( shader );
58
59       // Create vertex buffer
60       var pentagonVertexFormat ={ "aPosition1" : dali.PROPERTY_VECTOR2 };
61
62       var pentagonVertexData = [    0,     1,
63                                 -0.95,  0.31,
64                                 -0.59, -0.81,
65                                  0.59, -0.81,
66                                  0.95,  0.31];
67
68       var pentagonVertexDataArray = new Float32Array(pentagonVertexData.length);
69       pentagonVertexDataArray.set(pentagonVertexData, 0);
70       var pentagonVertices = new dali.PropertyBuffer(pentagonVertexFormat, 5);
71       pentagonVertices.setData(pentagonVertexDataArray);
72
73       var pentacleVertexFormat ={ "aPosition2" : dali.PROPERTY_VECTOR2};
74
75       var pentacleVertexData = [    0,    -1,
76                                  0.59,  0.81,
77                                 -0.95, -0.31,
78                                  0.95, -0.31,
79                                 -0.59,  0.81];
80
81       var pentacleVertexDataArray = new Float32Array(pentacleVertexData.length);
82       pentacleVertexDataArray.set(pentacleVertexData, 0);
83       var pentacleVertices = new dali.PropertyBuffer(pentacleVertexFormat, 5);
84       pentacleVertices.setData(pentacleVertexDataArray);
85
86       var indexFormat ={ "indices" : dali.PROPERTY_INTEGER };
87
88       var indexData = [0, 1, 1, 2, 2, 3, 3, 4, 4, 0];
89
90       var indexDataArray = new Uint32Array(indexData.length);
91       indexDataArray.set(indexData, 0);
92       var indices = new dali.PropertyBuffer(indexFormat, 10);
93       indices.setData(indexDataArray);
94
95       // Create geometry
96       var geometry = new dali.Geometry();
97       geometry.addVertexBuffer( pentagonVertices );
98       geometry.addVertexBuffer( pentacleVertices );
99       geometry.setIndexBuffer( indices );
100       geometry.setGeometryType( dali.GEOMETRY_LINES );
101
102       var renderer = new dali.Renderer(geometry, material);
103       renderer.depthIndex = 0;
104
105       // Create mesh actor
106       var meshActor = new dali.Actor();
107       meshActor.addRenderer( renderer );
108       meshActor.size = [300, 300, 0];
109       meshActor.parentOrigin = dali.CENTER;
110       meshActor.anchorPoint = dali.CENTER;
111       meshActor.registerAnimatableProperty("uMorphAmount", 0.0);
112
113       dali.stage.add( meshActor );
114
115       // Animate the mesh actor
116       var animation = new dali.Animation(5);
117
118       var keyFramesIndex = [{progress:0.0, value: 0.0}, {progress:1.0, value:1.0}];
119       var animOptions = { alpha:"sin", delay:0, duration:5};
120
121       animation.animateBetween( meshActor, "uMorphAmount", keyFramesIndex, animOptions );
122       animation.setLooping(true);
123       animation.play();
124 }
125
126 function startup()
127 {
128   daliApp.init();
129 }
130
131 daliApp.init = function()
132 {
133   daliApp.createMeshActor();
134 }
135
136
137 startup();
138