~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to cobweb.js/tests/Components/Text/horizontal.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, 11 Sep 2015 17:20:16 GMT'/>
7
 
    <meta name='creator' content='Holger Seelig'/>
8
 
    <meta name='generator' content='Titania V1.4.9, http://titania.create3000.de'/>
9
 
    <meta name='identifier' content='file:///home/holger/Projekte/Cobweb/cobweb.js/tests/Components/Text/horizontal.x3d'/>
10
 
    <meta name='modified' content='Tue, 30 Aug 2016 04:07:18 GMT'/>
11
 
    <meta name='title' content='Text'/>
12
 
  </head>
13
 
  <Scene>
14
 
    <ProtoDeclare name='LineRectangle2D'>
15
 
      <ProtoBody>
16
 
        <IndexedLineSet
17
 
            coordIndex='0, 1, 2, 3, 0, -1'>
18
 
          <Coordinate
19
 
              point='-0.5 -0.5 0, 0.5 -0.5 0, 0.5 0.5 0, -0.5 0.5 0'/>
20
 
        </IndexedLineSet>
21
 
      </ProtoBody>
22
 
    </ProtoDeclare>
23
 
    <ProtoDeclare name='BBox2'>
24
 
      <ProtoInterface>
25
 
        <field accessType='inputOutput' type='SFVec3f' name='translation'/>
26
 
        <field accessType='inputOutput' type='SFVec3f' name='scale' value='1 1 1'/>
27
 
        <field accessType='inputOutput' type='SFColor' name='color' value='1 1 1'/>
28
 
      </ProtoInterface>
29
 
      <ProtoBody>
30
 
        <Transform>
31
 
          <IS>
32
 
            <connect nodeField='translation' protoField='translation'/>
33
 
            <connect nodeField='scale' protoField='scale'/>
34
 
          </IS>
35
 
          <Transform
36
 
              translation='0.5 -0.5 0'>
37
 
            <Shape>
38
 
              <Appearance>
39
 
                <Material>
40
 
                  <IS>
41
 
                    <connect nodeField='emissiveColor' protoField='color'/>
42
 
                  </IS>
43
 
                </Material>
44
 
              </Appearance>
45
 
              <ProtoInstance name='LineRectangle2D' containerField='geometry'/>
46
 
            </Shape>
47
 
          </Transform>
48
 
        </Transform>
49
 
      </ProtoBody>
50
 
    </ProtoDeclare>
51
 
    <WorldInfo
52
 
        title='Horizontal Text'>
53
 
      <MetadataSet DEF='Titania'
54
 
          name='Titania'
55
 
          reference='http://titania.create3000.de'>
56
 
        <MetadataSet DEF='NavigationInfo' containerField='value'
57
 
            name='NavigationInfo'
58
 
            reference='http://titania.create3000.de'>
59
 
          <MetadataString DEF='type' containerField='value'
60
 
              name='type'
61
 
              reference='http://titania.create3000.de'
62
 
              value='"EXAMINE"'/>
63
 
        </MetadataSet>
64
 
        <MetadataSet DEF='Viewpoint' containerField='value'
65
 
            name='Viewpoint'
66
 
            reference='http://titania.create3000.de'>
67
 
          <MetadataDouble DEF='position' containerField='value'
68
 
              name='position'
69
 
              reference='http://titania.create3000.de'
70
 
              value='0.228690132498741, -0.0604688674211502, 1.71641170978546'/>
71
 
          <MetadataDouble DEF='orientation' containerField='value'
72
 
              name='orientation'
73
 
              reference='http://titania.create3000.de'
74
 
              value='0.872291021747068, 0.488929089099191, 0.00753121584411764, 0.0424616187810779'/>
75
 
          <MetadataDouble DEF='centerOfRotation' containerField='value'
76
 
              name='centerOfRotation'
77
 
              reference='http://titania.create3000.de'
78
 
              value='0.192951887845993, 0.00326720159500837, -0.000781742099206895'/>
79
 
        </MetadataSet>
80
 
        <MetadataSet DEF='Selection' containerField='value'
81
 
            name='Selection'
82
 
            reference='http://titania.create3000.de'>
83
 
          <MetadataSet DEF='previous' containerField='value'
84
 
              name='previous'
85
 
              reference='http://titania.create3000.de'/>
86
 
        </MetadataSet>
87
 
        <MetadataSet DEF='AngleGrid' containerField='value'
88
 
            name='AngleGrid'
89
 
            reference='http://titania.create3000.de'>
90
 
          <MetadataBoolean DEF='enabled' containerField='value'
91
 
              name='enabled'
92
 
              reference='http://titania.create3000.de'
93
 
              value='false'/>
94
 
        </MetadataSet>
95
 
        <MetadataSet DEF='Grid' containerField='value'
96
 
            name='Grid'
97
 
            reference='http://titania.create3000.de'>
98
 
          <MetadataBoolean DEF='enabled_1' containerField='value'
99
 
              name='enabled'
100
 
              reference='http://titania.create3000.de'
101
 
              value='true'/>
102
 
          <MetadataFloat DEF='rotation' containerField='value'
103
 
              name='rotation'
104
 
              reference='http://titania.create3000.de'
105
 
              value='1, 0, 0, 1.5708'/>
106
 
        </MetadataSet>
107
 
      </MetadataSet>
108
 
    </WorldInfo>
109
 
    <Background
110
 
        skyColor='0.2 0.2 0.2'/>
111
 
    <Viewpoint
112
 
        description='Viewpoint'
113
 
        position='0.365518 -0.30449 8.30129'
114
 
        orientation='0.872291021747068 0.488929089099191 0.00753121584411764 0.0424616187810779'
115
 
        centerOfRotation='0.192952 0.0032672 -0.000781742'/>
116
 
    <Transform DEF='Text'>
117
 
      <Shape>
118
 
        <Appearance>
119
 
          <Material
120
 
              diffuseColor='1 0 0'
121
 
              emissiveColor='1 1 1'/>
122
 
          <ImageTexture
123
 
              url='"http://cdn.rawgit.com/create3000/Library/master/Textures/Miscellaneous/lena.jpg", "https://cdn.rawgit.com/create3000/Library/master/Textures/Miscellaneous/lena.jpg", "http://rawgit.com/create3000/Library/master/Textures/Miscellaneous/lena.jpg", "https://rawgit.com/create3000/Library/master/Textures/Miscellaneous/lena.jpg"'/>
124
 
        </Appearance>
125
 
        <Text DEF='Text_1'
126
 
            string='"Bgre", "good old", "Texts", "today!"'
127
 
            length='1.66694, 2.95728, 1.82503, 2.17687'
128
 
            maxExtent='4.477'>
129
 
          <FontStyle
130
 
              family='"Ubuntu", "SANS"'
131
 
              style='BOLDITALIC'
132
 
              justify='"MIDDLE", "FIRST"'/>
133
 
        </Text>
134
 
      </Shape>
135
 
    </Transform>
136
 
    <Transform DEF='RedBox'
137
 
        translation='-0.5 0.5 0'>
138
 
      <Shape>
139
 
        <Appearance>
140
 
          <Material
141
 
              diffuseColor='1 0 0'
142
 
              transparency='0.854167'/>
143
 
        </Appearance>
144
 
        <Box
145
 
            size='1 1 1'/>
146
 
      </Shape>
147
 
    </Transform>
148
 
    <Transform DEF='GreenBox'
149
 
        translation='-0.5 -0.5 0'>
150
 
      <Shape>
151
 
        <Appearance>
152
 
          <Material
153
 
              diffuseColor='0 1 0'
154
 
              transparency='0.916667'/>
155
 
        </Appearance>
156
 
        <Box
157
 
            size='1 1 1'/>
158
 
      </Shape>
159
 
    </Transform>
160
 
    <Transform DEF='BlueBox'
161
 
        translation='-0.5 -1.5 0'>
162
 
      <Shape>
163
 
        <Appearance>
164
 
          <Material
165
 
              diffuseColor='0 0 1'
166
 
              transparency='0.5'/>
167
 
        </Appearance>
168
 
        <Box
169
 
            size='1 1 1'/>
170
 
      </Shape>
171
 
    </Transform>
172
 
    <Transform DEF='YellowBox'
173
 
        translation='6 1.5 0'
174
 
        scale='12 1 1'>
175
 
      <Shape>
176
 
        <Appearance>
177
 
          <Material
178
 
              diffuseColor='1 1 0'
179
 
              transparency='0.49'/>
180
 
        </Appearance>
181
 
        <Box
182
 
            size='1 1 1'/>
183
 
      </Shape>
184
 
    </Transform>
185
 
    <Transform DEF='LineBounds'
186
 
        translation='-1.47864 0.700938 0'>
187
 
      <ProtoInstance name='BBox2'>
188
 
        <fieldValue name='translation' value='0.64517 0 0'/>
189
 
        <fieldValue name='scale' value='1.66694 0.889938 1'/>
190
 
        <fieldValue name='color' value='1 0 1'/>
191
 
      </ProtoInstance>
192
 
      <ProtoInstance name='BBox2'>
193
 
        <fieldValue name='translation' value='0 -0.889938 0'/>
194
 
        <fieldValue name='scale' value='2.95728 1 1'/>
195
 
        <fieldValue name='color' value='0 1 0'/>
196
 
      </ProtoInstance>
197
 
      <ProtoInstance name='BBox2'>
198
 
        <fieldValue name='translation' value='0.566125 -1.88994 0'/>
199
 
        <fieldValue name='scale' value='1.82503 1 1'/>
200
 
        <fieldValue name='color' value='0 0 1'/>
201
 
      </ProtoInstance>
202
 
      <ProtoInstance name='BBox2'>
203
 
        <fieldValue name='translation' value='0.390205 -2.88994 0'/>
204
 
        <fieldValue name='scale' value='2.17687 1 1'/>
205
 
        <fieldValue name='color' value='1 1 0'/>
206
 
      </ProtoInstance>
207
 
    </Transform>
208
 
    <Transform DEF='TextBounds'
209
 
        translation='-1.47864 0.700938 0'
210
 
        scale='2.95728 3.88594 1'>
211
 
      <ProtoInstance name='BBox2'/>
212
 
    </Transform>
213
 
    <Script DEF='Bounds'>
214
 
      <field accessType='inputOnly' type='MFVec2f' name='set_lineBounds'/>
215
 
      <field accessType='inputOnly' type='SFVec2f' name='set_textBounds'/>
216
 
      <field accessType='outputOnly' type='SFVec3f' name='translation_changed'/>
217
 
      <field accessType='outputOnly' type='SFVec3f' name='scale_changed'/>
218
 
      <field accessType='initializeOnly' type='SFNode' name='lineBounds'>
219
 
        <Transform USE='LineBounds'/>
220
 
      </field>
221
 
      <field accessType='initializeOnly' type='MFColor' name='color' value='1 0 1, 0 1 0, 0 0 1, 1 1 0, 0 1 1, 1 0 0'/>
222
 
      <field accessType='initializeOnly' type='SFNode' name='text'>
223
 
        <Text USE='Text_1'/>
224
 
      </field>
225
 
<![CDATA[javascript:
226
 
 
227
 
var
228
 
        BEGIN  = 0,
229
 
        FIRST  = 1,
230
 
        MIDDLE = 2,
231
 
        END    = 3;
232
 
 
233
 
function get_normalizedMajorAlignment (majorAlignment, normal)
234
 
{
235
 
        if (majorAlignment == 'END')
236
 
                return normal ? END : BEGIN;
237
 
 
238
 
        if (majorAlignment == 'MIDDLE')
239
 
                return MIDDLE;
240
 
 
241
 
        return normal ? BEGIN : END;
242
 
 
243
 
}
244
 
 
245
 
function get_majorAlignment (index)
246
 
{
247
 
        if (text .fontStyle .horizontal)
248
 
        {
249
 
                var major = get_normalizedMajorAlignment (text .fontStyle .justify [0], text .fontStyle .leftToRight);
250
 
        
251
 
                if (major == END)
252
 
                        return text .textBounds .x - text .lineBounds [index] .x;
253
 
 
254
 
                if (major == MIDDLE)
255
 
                        return (text .textBounds .x - text .lineBounds [index] .x) / 2;
256
 
 
257
 
                return 0;
258
 
        }
259
 
 
260
 
        var major = get_normalizedMajorAlignment (text .fontStyle .justify [0], text .fontStyle .topToBottom);
261
 
        
262
 
        if (major == END)
263
 
                return -text .textBounds .y + text .lineBounds [index] .y;
264
 
 
265
 
        if (major == MIDDLE)
266
 
                return (-text .textBounds .y + text .lineBounds [index] .y) / 2;
267
 
 
268
 
        return 0;
269
 
}
270
 
 
271
 
function set_lineBounds (value, time)
272
 
{
273
 
        var transforms = new MFNode ();
274
 
        
275
 
        var
276
 
                x = 0,
277
 
                y = 0;
278
 
                
279
 
        for (var i = 0; i < value .length; ++ i)
280
 
        {
281
 
                var transform = Browser .currentScene .createProto ('BBox2');
282
 
                
283
 
                if (text .fontStyle .horizontal)
284
 
                {
285
 
                        transform .translation = new SFVec3f (get_majorAlignment (i),
286
 
                                                              text .fontStyle .topToBottom ? y : y - text .textBounds .y,
287
 
                                                              0);
288
 
                        y += text .fontStyle .topToBottom ? -value [i] .y : value [i] .y;
289
 
 
290
 
                        transform .scale = new SFVec3f (value [i] .x,
291
 
                                                        text .fontStyle .topToBottom ? value [i] .y : -value [i] .y,
292
 
                                                        1);
293
 
                }
294
 
                else
295
 
                {
296
 
                        transform .translation = new SFVec3f (text .fontStyle .leftToRight ? x : x + text .textBounds .x,
297
 
                                                              get_majorAlignment (i),
298
 
                                                              0);
299
 
                
300
 
                        x += text .fontStyle .leftToRight ? value [i] .x : -value [i] .x;
301
 
 
302
 
                        transform .scale = new SFVec3f (text .fontStyle .leftToRight ? value [i] .x : -value [i] .x,
303
 
                                                        value [i] .y,
304
 
                                                        1);
305
 
                }
306
 
 
307
 
                transform .color = color [i % color .length];
308
 
 
309
 
                transforms [transforms .length] = transform;
310
 
        }
311
 
 
312
 
        lineBounds .children = transforms;
313
 
}
314
 
 
315
 
function set_textBounds (value, time)
316
 
{
317
 
        scale_changed = new SFVec3f (value .x, value .y, 1);
318
 
}
319
 
  ]]> 
320
 
    </Script>
321
 
    <ROUTE fromNode='Text_1' fromField='origin' toNode='LineBounds' toField='set_translation'/>
322
 
    <ROUTE fromNode='Text_1' fromField='lineBounds' toNode='Bounds' toField='set_lineBounds'/>
323
 
    <ROUTE fromNode='Text_1' fromField='textBounds' toNode='Bounds' toField='set_textBounds'/>
324
 
    <ROUTE fromNode='Text_1' fromField='origin' toNode='TextBounds' toField='set_translation'/>
325
 
    <ROUTE fromNode='Bounds' fromField='scale_changed' toNode='TextBounds' toField='set_scale'/>
326
 
  </Scene>
327
 
</X3D>