~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to cobweb.js/tests/Components/Shaders/Matrix3VertexAttribute.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/Matrix3VertexAttribute.x3d'/>
10
 
    <meta name='modified' content='Wed, 19 Oct 2016 08:51:15 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
 
                <IndexedFaceSet
334
 
                    texCoordIndex='0, 1, 2, 3, -1'
335
 
                    coordIndex='0, 1, 2, -1, 0, 2, 3, -1'>
336
 
                  <Matrix3VertexAttribute
337
 
                      name='rotation'
338
 
                      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'/>
339
 
                  <TextureCoordinate
340
 
                      point='0 0, 1 0, 1 1, 0 1'/>
341
 
                  <Coordinate
342
 
                      point='0 -1 -1, 0 -1 1, 0 1 1, 0 1 -1'/>
343
 
                </IndexedFaceSet>
344
 
              </Shape>
345
 
            </Transform>
346
 
          </MetadataSet>
347
 
          <MetadataSet DEF='children' containerField='value'
348
 
              name='children'
349
 
              reference='http://titania.create3000.de'>
350
 
            <Transform DEF='Text' containerField='value'
351
 
                translation='-5.01454 -2.98505 0'>
352
 
              <Shape>
353
 
                <Appearance>
354
 
                  <Material/>
355
 
                </Appearance>
356
 
                <Text
357
 
                    string='"Must show a 2x2 rectangle."'
358
 
                    solid='true'>
359
 
                  <FontStyle DEF='_1'
360
 
                      size='0.39'/>
361
 
                </Text>
362
 
              </Shape>
363
 
            </Transform>
364
 
          </MetadataSet>
365
 
        </MetadataSet>
366
 
      </MetadataSet>
367
 
    </WorldInfo>
368
 
    <Viewpoint/>
369
 
    <ProtoInstance name='Grid'>
370
 
      <fieldValue name='rotation' value='1 0 0 1.5707963267949'/>
371
 
      <fieldValue name='transparency' value='0.8'/>
372
 
    </ProtoInstance>
373
 
    <Transform USE='Rectangle2D'/>
374
 
    <Transform USE='Text'/>
375
 
  </Scene>
376
 
</X3D>