~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to tests/Components/Shaders/LineMatrix3VertexAttribute.x3d

  • Committer: Holger Seelig
  • Date: 2017-08-22 04:53:24 UTC
  • Revision ID: holger.seelig@yahoo.de-20170822045324-4of4xxgt79669gbt
Switched to npm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd">
 
3
<X3D profile='Full' version='3.3' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.3.xsd'>
 
4
  <head>
 
5
    <meta name='comment' content='World of Titania'/>
 
6
    <meta name='created' content='Fri, 07 Oct 2016 02:56:59 GMT'/>
 
7
    <meta name='creator' content='Holger Seelig'/>
 
8
    <meta name='generator' content='Titania V2.0.1, http://titania.create3000.de'/>
 
9
    <meta name='identifier' content='file:///home/holger/Projekte/Cobweb/cobweb.js/tests/Components/Shaders/LineMatrix3VertexAttribute.x3d'/>
 
10
    <meta name='modified' content='Wed, 19 Oct 2016 08:51:01 GMT'/>
 
11
  </head>
 
12
  <Scene>
 
13
    <ProtoDeclare name='Grid'>
 
14
      <ProtoInterface>
 
15
        <field accessType='inputOutput' type='SFVec3f' name='translation'/>
 
16
        <field accessType='inputOutput' type='SFRotation' name='rotation'/>
 
17
        <field accessType='inputOutput' type='SFVec3f' name='scale' value='1 1 1'/>
 
18
        <field accessType='inputOutput' type='MFInt32' name='dimension' value='10, 10, 10'/>
 
19
        <field accessType='inputOutput' type='MFInt32' name='majorLineEvery' value='5, 5, 5'/>
 
20
        <field accessType='inputOutput' type='MFInt32' name='majorLineOffset' value='0, 0, 0'/>
 
21
        <field accessType='inputOutput' type='SFColor' name='color' value='0.5 0.5 0.5'/>
 
22
        <field accessType='inputOutput' type='SFFloat' name='transparency' value='0.61803'/>
 
23
        <field accessType='inputOutput' type='SFColor' name='lineColor' value='1 0.7 0.7'/>
 
24
        <field accessType='inputOutput' type='SFFloat' name='lineTransparency' value='0.8'/>
 
25
        <field accessType='inputOutput' type='SFColor' name='majorLineColor' value='1 0.7 0.7'/>
 
26
        <field accessType='inputOutput' type='SFFloat' name='majorLineTransparency' value='0.6'/>
 
27
        <field accessType='initializeOnly' type='SFBool' name='solid' value='true'/>
 
28
      </ProtoInterface>
 
29
      <ProtoBody>
 
30
        <Transform>
 
31
          <IS>
 
32
            <connect nodeField='translation' protoField='translation'/>
 
33
            <connect nodeField='rotation' protoField='rotation'/>
 
34
            <connect nodeField='scale' protoField='scale'/>
 
35
          </IS>
 
36
          <Transform DEF='Plane'
 
37
              rotation='-3.09087122910219e-08 0.70710528118436 0.707108281185553 3.14159'
 
38
              scale='10 10 1'>
 
39
            <Shape>
 
40
              <Appearance>
 
41
                <Material DEF='Material2'
 
42
                    diffuseColor='0 0 0'>
 
43
                  <IS>
 
44
                    <connect nodeField='emissiveColor' protoField='color'/>
 
45
                    <connect nodeField='transparency' protoField='transparency'/>
 
46
                  </IS>
 
47
                </Material>
 
48
              </Appearance>
 
49
              <Rectangle2D
 
50
                  size='1 1'>
 
51
                <IS>
 
52
                  <connect nodeField='solid' protoField='solid'/>
 
53
                </IS>
 
54
              </Rectangle2D>
 
55
            </Shape>
 
56
          </Transform>
 
57
          <Shape DEF='MajorGrid'>
 
58
            <Appearance>
 
59
              <Material DEF='MajorMaterial'>
 
60
                <IS>
 
61
                  <connect nodeField='emissiveColor' protoField='majorLineColor'/>
 
62
                  <connect nodeField='transparency' protoField='majorLineTransparency'/>
 
63
                </IS>
 
64
              </Material>
 
65
            </Appearance>
 
66
            <IndexedLineSet DEF='MajorGrid_1'
 
67
                coordIndex='0, 1, -1, 2, 3, -1, 4, 5, -1, 6, 7, -1, 8, 9, -1, 10, 11, -1'>
 
68
              <Coordinate
 
69
                  point='-5 0 -5.25, -5 0 5.25, 0 0 -5.25, 0 0 5.25, 5 0 -5.25, 5 0 5.25, -5.25 0 -5, 5.25 0 -5, -5.25 0 0, 5.25 0 0, -5.25 0 5, 5.25 0 5'/>
 
70
            </IndexedLineSet>
 
71
          </Shape>
 
72
          <Shape DEF='MinorGrid'>
 
73
            <Appearance>
 
74
              <Material DEF='MinorMaterial'>
 
75
                <IS>
 
76
                  <connect nodeField='emissiveColor' protoField='lineColor'/>
 
77
                  <connect nodeField='transparency' protoField='lineTransparency'/>
 
78
                </IS>
 
79
              </Material>
 
80
            </Appearance>
 
81
            <IndexedLineSet DEF='MinorGrid_1'
 
82
                coordIndex='0, 1, -1, 2, 3, -1, 4, 5, -1, 6, 7, -1, 8, 9, -1, 10, 11, -1, 12, 13, -1, 14, 15, -1, 16, 17, -1, 18, 19, -1, 20, 21, -1, 22, 23, -1, 24, 25, -1, 26, 27, -1, 28, 29, -1, 30, 31, -1'>
 
83
              <Coordinate
 
84
                  point='-4 0 -5, -4 0 5, -3 0 -5, -3 0 5, -2 0 -5, -2 0 5, -1 0 -5, -1 0 5, 1 0 -5, 1 0 5, 2 0 -5, 2 0 5, 3 0 -5, 3 0 5, 4 0 -5, 4 0 5, -5 0 -4, 5 0 -4, -5 0 -3, 5 0 -3, -5 0 -2, 5 0 -2, -5 0 -1, 5 0 -1, -5 0 1, 5 0 1, -5 0 2, 5 0 2, -5 0 3, 5 0 3, -5 0 4, 5 0 4'/>
 
85
            </IndexedLineSet>
 
86
          </Shape>
 
87
          <Shape DEF='MajorPoints'>
 
88
            <Appearance>
 
89
              <LineProperties
 
90
                  linewidthScaleFactor='6'/>
 
91
              <Material USE='MajorMaterial'/>
 
92
            </Appearance>
 
93
            <PointSet DEF='MajorPoints_1'>
 
94
              <Coordinate
 
95
                  point='0 -5 0, 0 0 0, 0 5 0'/>
 
96
            </PointSet>
 
97
          </Shape>
 
98
          <Shape DEF='MinorPoints'>
 
99
            <Appearance>
 
100
              <LineProperties
 
101
                  linewidthScaleFactor='4'/>
 
102
              <Material USE='MinorMaterial'/>
 
103
            </Appearance>
 
104
            <PointSet DEF='MinorPoints_1'>
 
105
              <Coordinate
 
106
                  point='0 -4 0, 0 -3 0, 0 -2 0, 0 -1 0, 0 1 0, 0 2 0, 0 3 0, 0 4 0'/>
 
107
            </PointSet>
 
108
          </Shape>
 
109
        </Transform>
 
110
        <Script DEF='GridScript'
 
111
            directOutput='true'
 
112
            mustEvaluate='true'>
 
113
          <field accessType='inputOutput' type='MFInt32' name='dimension'/>
 
114
          <field accessType='inputOutput' type='MFInt32' name='majorLineEvery'/>
 
115
          <field accessType='inputOutput' type='MFInt32' name='majorLineOffset'/>
 
116
          <field accessType='initializeOnly' type='SFNode' name='plane'>
 
117
            <Transform USE='Plane'/>
 
118
          </field>
 
119
          <field accessType='initializeOnly' type='SFNode' name='majorGrid'>
 
120
            <IndexedLineSet USE='MajorGrid_1'/>
 
121
          </field>
 
122
          <field accessType='initializeOnly' type='SFNode' name='minorGrid'>
 
123
            <IndexedLineSet USE='MinorGrid_1'/>
 
124
          </field>
 
125
          <field accessType='initializeOnly' type='SFNode' name='majorPoints'>
 
126
            <PointSet USE='MajorPoints_1'/>
 
127
          </field>
 
128
          <field accessType='initializeOnly' type='SFNode' name='minorPoints'>
 
129
            <PointSet USE='MinorPoints_1'/>
 
130
          </field>
 
131
          <IS>
 
132
            <connect nodeField='dimension' protoField='dimension'/>
 
133
            <connect nodeField='majorLineEvery' protoField='majorLineEvery'/>
 
134
            <connect nodeField='majorLineOffset' protoField='majorLineOffset'/>
 
135
          </IS>
 
136
<![CDATA[javascript:
 
137
 
 
138
function initialize ()
 
139
{
 
140
        eventsProcessed ();
 
141
}
 
142
 
 
143
function eventsProcessed ()
 
144
{
 
145
        // Plane
 
146
 
 
147
        plane .scale = new SFVec3f (dimension [0], dimension [2], 1);
 
148
 
 
149
        // Grid
 
150
 
 
151
        generateGrid (true, majorGrid);
 
152
        generateGrid (false, minorGrid);
 
153
 
 
154
        // Points
 
155
 
 
156
        generatePoints (true,  majorPoints .coord .point);
 
157
        generatePoints (false, minorPoints .coord .point);
 
158
}
 
159
 
 
160
function generateGrid (major, grid)
 
161
{
 
162
        var point       = grid .coord .point;
 
163
        var coordIndex  = new MFInt32 ();
 
164
        var scaleX1_2   = dimension [0] / 2;
 
165
        var scaleZ1_2   = dimension [2] / 2;
 
166
        var majorAdd    = major / 4;
 
167
        var p           = 0;
 
168
 
 
169
        for (var i = 0, size = dimension [0] + 1; i < size; ++ i)
 
170
        {
 
171
                if (major - isMajorLine (i, 0))
 
172
                        continue;
 
173
 
 
174
                var x = -scaleX1_2 + i;
 
175
 
 
176
                point [p]     = new SFVec3f (x, 0, -scaleZ1_2 - majorAdd);
 
177
                point [p + 1] = new SFVec3f (x, 0,  scaleZ1_2 + majorAdd);
 
178
                coordIndex [coordIndex .length] = p;
 
179
                coordIndex [coordIndex .length] = p + 1;
 
180
                coordIndex [coordIndex .length] = -1;
 
181
                        
 
182
                p += 2;
 
183
        }
 
184
 
 
185
        for (var i = 0, size = dimension [2] + 1; i < size; ++ i)
 
186
        {
 
187
                if (major - isMajorLine (i, 2))
 
188
                        continue;
 
189
 
 
190
                var z = -scaleZ1_2 + i;
 
191
 
 
192
                point [p]     = new SFVec3f (-scaleX1_2 - majorAdd, 0, z);
 
193
                point [p + 1] = new SFVec3f ( scaleX1_2 + majorAdd, 0, z);
 
194
                coordIndex [coordIndex .length] = p;
 
195
                coordIndex [coordIndex .length] = p + 1;
 
196
                coordIndex [coordIndex .length] = -1;
 
197
                
 
198
                p += 2;
 
199
        }
 
200
 
 
201
        point .length = p;
 
202
 
 
203
        grid .set_coordIndex = coordIndex;
 
204
}
 
205
 
 
206
function generatePoints (major, point)
 
207
{
 
208
        var scaleY1_2 = -dimension [1] / 2;
 
209
        var p         = 0;
 
210
 
 
211
        for (var i = 0, size = dimension [1] + 1; i < size; ++ i)
 
212
        {
 
213
                if (major - isMajorLine (i, 1))
 
214
                        continue;
 
215
 
 
216
                point [p] = new SFVec3f (0, scaleY1_2 + i, 0);
 
217
                ++ p;
 
218
        }
 
219
 
 
220
        point .length = p;
 
221
}
 
222
 
 
223
function isMajorLine (i, index)
 
224
{
 
225
        for (var d = index; d < majorLineEvery .length; d += 3)
 
226
        {
 
227
                if (isMajor (i, dimension [index], majorLineEvery [d], majorLineOffset [d]))
 
228
                        return true;
 
229
        }
 
230
 
 
231
        return false;
 
232
}
 
233
 
 
234
function isMajor (i, dimension, majorLineEvery, majorLineOffset)
 
235
{
 
236
        if (majorLineEvery)
 
237
        {
 
238
                var index = Math .floor (i - dimension / 2 - majorLineOffset);
 
239
 
 
240
                return !(index % majorLineEvery);
 
241
        }
 
242
 
 
243
        return false;
 
244
}
 
245
]]> 
 
246
        </Script>
 
247
      </ProtoBody>
 
248
    </ProtoDeclare>
 
249
    <WorldInfo>
 
250
      <MetadataSet DEF='Titania'
 
251
          name='Titania'
 
252
          reference='http://titania.create3000.de'>
 
253
        <MetadataSet DEF='AngleGrid' containerField='value'
 
254
            name='AngleGrid'
 
255
            reference='http://titania.create3000.de'>
 
256
          <MetadataBoolean DEF='enabled' containerField='value'
 
257
              name='enabled'
 
258
              reference='http://titania.create3000.de'
 
259
              value='false'/>
 
260
        </MetadataSet>
 
261
        <MetadataSet DEF='Grid' containerField='value'
 
262
            name='Grid'
 
263
            reference='http://titania.create3000.de'>
 
264
          <MetadataBoolean DEF='enabled_1' containerField='value'
 
265
              name='enabled'
 
266
              reference='http://titania.create3000.de'
 
267
              value='false'/>
 
268
        </MetadataSet>
 
269
        <MetadataSet DEF='NavigationInfo' containerField='value'
 
270
            name='NavigationInfo'
 
271
            reference='http://titania.create3000.de'>
 
272
          <MetadataString DEF='type' containerField='value'
 
273
              name='type'
 
274
              reference='http://titania.create3000.de'
 
275
              value='"NONE"'/>
 
276
        </MetadataSet>
 
277
        <MetadataSet DEF='Viewpoint' containerField='value'
 
278
            name='Viewpoint'
 
279
            reference='http://titania.create3000.de'>
 
280
          <MetadataDouble DEF='position' containerField='value'
 
281
              name='position'
 
282
              reference='http://titania.create3000.de'
 
283
              value='0, 0, 10'/>
 
284
          <MetadataDouble DEF='orientation' containerField='value'
 
285
              name='orientation'
 
286
              reference='http://titania.create3000.de'
 
287
              value='0, 0, 1, 0'/>
 
288
          <MetadataDouble DEF='centerOfRotation' containerField='value'
 
289
              name='centerOfRotation'
 
290
              reference='http://titania.create3000.de'
 
291
              value='0, 0, 0'/>
 
292
        </MetadataSet>
 
293
        <MetadataSet DEF='Selection' containerField='value'
 
294
            name='Selection'
 
295
            reference='http://titania.create3000.de'>
 
296
          <MetadataSet DEF='previous' containerField='value'
 
297
              name='previous'
 
298
              reference='http://titania.create3000.de'>
 
299
            <Transform DEF='Rectangle2D' containerField='value'>
 
300
              <Shape>
 
301
                <Appearance>
 
302
                  <Material/>
 
303
                  <ComposedShader>
 
304
                    <ShaderPart>
 
305
<![CDATA[data:text/plain,
 
306
 
 
307
uniform mat4 x3d_ProjectionMatrix;
 
308
uniform mat4 x3d_ModelViewMatrix;
 
309
 
 
310
attribute vec4 x3d_Vertex;
 
311
attribute mat3 rotation;
 
312
 
 
313
void
 
314
main ()
 
315
{
 
316
        vec4 vertex = vec4 (rotation * vec3 (x3d_Vertex), 1.0);
 
317
 
 
318
        gl_Position = x3d_ProjectionMatrix * x3d_ModelViewMatrix * vertex;
 
319
}]]> 
 
320
                    </ShaderPart>
 
321
                    <ShaderPart
 
322
                        type='FRAGMENT'>
 
323
<![CDATA[data:text/plain,
 
324
 
 
325
void
 
326
main ()
 
327
{
 
328
        gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);
 
329
}]]> 
 
330
                    </ShaderPart>
 
331
                  </ComposedShader>
 
332
                </Appearance>
 
333
                <IndexedLineSet
 
334
                    coordIndex='0, 1, 2, 0, -1, 2, 3, 0'>
 
335
                  <Matrix3VertexAttribute
 
336
                      name='rotation'
 
337
                      value='0 0 -1 0 1 0 1 0 0, 0 0 -1 0 1 0 1 0 0, 0 0 -1 0 1 0 1 0 0, 0 0 -1 0 1 0 1 0 0'/>
 
338
                  <Coordinate
 
339
                      point='0 -1 -1, 0 -1 1, 0 1 1, 0 1 -1'/>
 
340
                </IndexedLineSet>
 
341
              </Shape>
 
342
            </Transform>
 
343
          </MetadataSet>
 
344
          <MetadataSet DEF='children' containerField='value'
 
345
              name='children'
 
346
              reference='http://titania.create3000.de'>
 
347
            <Transform DEF='Text' containerField='value'
 
348
                translation='-5.01454 -2.98505 0'>
 
349
              <Shape>
 
350
                <Appearance>
 
351
                  <Material/>
 
352
                </Appearance>
 
353
                <Text
 
354
                    string='"Must show a 2x2 rectangle."'
 
355
                    solid='true'>
 
356
                  <FontStyle DEF='_1'
 
357
                      size='0.39'/>
 
358
                </Text>
 
359
              </Shape>
 
360
            </Transform>
 
361
          </MetadataSet>
 
362
        </MetadataSet>
 
363
      </MetadataSet>
 
364
    </WorldInfo>
 
365
    <Viewpoint/>
 
366
    <ProtoInstance name='Grid'>
 
367
      <fieldValue name='rotation' value='1 0 0 1.5707963267949'/>
 
368
      <fieldValue name='transparency' value='0.8'/>
 
369
    </ProtoInstance>
 
370
    <Transform USE='Rectangle2D'/>
 
371
    <Transform USE='Text'/>
 
372
  </Scene>
 
373
</X3D>