1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 12:20:44 AM |
5
|
|
|
* Contact [email protected] |
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
7
|
|
|
* @license The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* @category AframeVR |
10
|
|
|
* @package aframe-php |
11
|
|
|
* |
12
|
|
|
* Lang PHP (php version >= 7) |
13
|
|
|
* Encoding UTF-8 |
14
|
|
|
* File Geometry.php |
15
|
|
|
* Code format PSR-2 and 12 |
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
17
|
|
|
^ @issues https://github.com/mkungla/aframe-php/issues |
18
|
|
|
* ******************************************************************** |
19
|
|
|
* Contributors: |
20
|
|
|
* @author Marko Kungla <[email protected]> |
21
|
|
|
* ******************************************************************** |
22
|
|
|
* Comments: |
23
|
|
|
* @formatter:on */ |
24
|
|
|
namespace AframeVR\Components; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\ComponentInterface; |
27
|
|
|
use \AframeVR\Core\Exceptions\{ |
28
|
|
|
InvalidComponentArgumentException, |
29
|
|
|
InvalidComponentMethodException |
30
|
|
|
}; |
31
|
|
|
use \DOMAttr; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The geometry component provides a basic shape for an entity. |
35
|
|
|
* The general geometry is defined by the primitive property. |
36
|
|
|
* Geometric primitives, in computer graphics, means an extremely basic shape. With the primitive defined, |
37
|
|
|
* additional properties are used to further define the geometry. A material component is usually defined alongside |
38
|
|
|
* to provide a appearance alongside the shape to create a complete mesh. |
39
|
|
|
*/ |
40
|
|
|
class Geometry implements ComponentInterface |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
const ALLOWED_PRIMITIVES = array( |
44
|
|
|
'box', |
45
|
|
|
'circle', |
46
|
|
|
'cone', |
47
|
|
|
'cylinder', |
48
|
|
|
'plane', |
49
|
|
|
'ring', |
50
|
|
|
'sphere', |
51
|
|
|
'torus', |
52
|
|
|
'torusKnot' |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Properties based on primitive |
57
|
|
|
*/ |
58
|
|
|
const P_COMMON_PROPS = array( |
59
|
|
|
|
60
|
|
|
/* One of box, circle, cone, cylinder, plane, ring, sphere, torus, torusKnot. */ |
61
|
|
|
'primitive' => null, |
62
|
|
|
|
63
|
|
|
/* The translate property translates the geometry. It is provided as a vec3. This is a useful short-hand for |
64
|
|
|
* translating the geometry to effectively move its pivot point when running animations. */ |
65
|
|
|
'translate' => '0 0 0', |
66
|
|
|
/* Transform geometry into a BufferGeometry to reduce memory usage at the cost of being harder to manipulate. */ |
67
|
|
|
'buffer' => true, |
68
|
|
|
/* Disable retrieving the shared geometry object from the cache. */ |
69
|
|
|
'skipCache' => false |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* The box primitive defines boxes (i.e., any quadilateral, not just cubes). |
74
|
|
|
*/ |
75
|
|
|
const P_BOX = array( |
76
|
|
|
/* Width (in meters) of the sides on the X axis. */ |
77
|
|
|
'width' => 1, |
78
|
|
|
/* Height (in meters) of the sides on the Y axis. */ |
79
|
|
|
'height' => 1, |
80
|
|
|
/* Depth (in meters) of the sides on the Z axis. */ |
81
|
|
|
'depth' => 1 |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The circle primitive defines two-dimensional circles, which can be complete circles or partial circles (like Pac-Man). |
86
|
|
|
* Note that because it is flat, only a single side of the circle will be rendered if “side: double” is not specified on the material component. |
87
|
|
|
*/ |
88
|
|
|
const P_CIRCLE = array( |
89
|
|
|
/* Radius (in meters) of the circle. */ |
90
|
|
|
'radius' => 1, |
91
|
|
|
/* Number of triangles to construct the circle, like pizza slices. A higher number of segments means the circle will be more round. */ |
92
|
|
|
'segments' => 32, |
93
|
|
|
/* Start angle for first segment. Can be used to define a partial circle. */ |
94
|
|
|
'thetaStart' => 0, |
95
|
|
|
/* The central angle (in degrees). Defaults to 360, which makes for a complete circle. */ |
96
|
|
|
'thetaLength' => 360 |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* The cone primitive under the hood is a cylinder primitive with varying top and bottom radiuses. |
101
|
|
|
*/ |
102
|
|
|
const P_CONE = array( |
103
|
|
|
/* Height of the cone. */ |
104
|
|
|
'height' => 2, |
105
|
|
|
/* Whether the ends of the cone are open (true) or capped ('false'). */ |
106
|
|
|
'openEnded' => 'false', |
107
|
|
|
/* Radius of the bottom end of the cone. */ |
108
|
|
|
'radiusBottom' => 1, |
109
|
|
|
/* Radius of the top end of the cone. */ |
110
|
|
|
'radiusTop' => 1, |
111
|
|
|
/* Number of segmented faces around the circumference of the cone. */ |
112
|
|
|
'segmentsRadial' => 36, |
113
|
|
|
/* Number of rows of faces along the height of the cone. */ |
114
|
|
|
'segmentsHeight' => 18, |
115
|
|
|
/* Starting angle in degrees. */ |
116
|
|
|
'thetaStart' => 0, |
117
|
|
|
/* Central angle in degrees. */ |
118
|
|
|
'thetaLength' => 360 |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* The cylinder primitive can define cylinders in the traditional sense like a Coca-Cola™ can, |
123
|
|
|
* but it can also define shapes such as tubes and curved surfaces. |
124
|
|
|
* We’ll go over some of these cylinder recipes below. |
125
|
|
|
* 1. Traditional cylinders can be defined by using only a height and a radius: |
126
|
|
|
* 2. Tubes can be defined by making the cylinder open-ended, which removes the top and bottom surfaces of the cylinder such that the inside is visible. |
127
|
|
|
* A double-sided material will be needed to render properly: |
128
|
|
|
* 3. Curved surfaces can be defined by specifying the angle via thetaLength such that the cylinder doesn’t curve all the way around, |
129
|
|
|
* making the cylinder open-ended, and then making the material double-sided. |
130
|
|
|
* 4. Other types of prisms can be defined by varying the number of radial segments (i.e., sides). For example, to make a hexagonal prism: |
131
|
|
|
*/ |
132
|
|
|
const P_CYLINDER = array( |
133
|
|
|
/* Radius of the cylinder. */ |
134
|
|
|
'height' => 3, |
135
|
|
|
/* Height of the cylinder. */ |
136
|
|
|
'radius' => 2, |
137
|
|
|
/* Number of segmented faces around the circumference of the cylinder. */ |
138
|
|
|
'segmentsRadial' => 36, |
139
|
|
|
/* Number of rows of faces along the height of the cylinder. */ |
140
|
|
|
'segmentsHeight' => 18, |
141
|
|
|
/* Whether the ends of the cylinder are open (true) or capped ('false'). */ |
142
|
|
|
'openEnded' => 'false', |
143
|
|
|
/* Starting angle in degrees. */ |
144
|
|
|
'thetaStart' => 0, |
145
|
|
|
/* Central angle in degrees. */ |
146
|
|
|
'thetaLength' => 360 |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* The plane primitive defines a flat surface. |
151
|
|
|
* Note that because it is flat, |
152
|
|
|
* only a single side of the plane will be rendered if side: double is not specified on the material component. |
153
|
|
|
*/ |
154
|
|
|
const P_PLANE = array( |
155
|
|
|
/* Width along the X axis. */ |
156
|
|
|
'width' => 1, |
157
|
|
|
/* Height along the Y axis. */ |
158
|
|
|
'height' => 1 |
159
|
|
|
); |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* The ring geometry defines a flat ring, like a CD. |
163
|
|
|
* Note that because it is flat, |
164
|
|
|
* only a single side of the ring will be rendered if side: double is not specified on the material component. |
165
|
|
|
*/ |
166
|
|
|
const P_RING = array( |
167
|
|
|
/* Radius of the inner hole of the ring. */ |
168
|
|
|
'radiusInner' => 1, |
169
|
|
|
/* Radius of the outer edge of the ring. */ |
170
|
|
|
'radiusOuter' => 1, |
171
|
|
|
/* Number of segments. A higher number means the ring will be more round */ |
172
|
|
|
'segmentsTheta' => 32, |
173
|
|
|
/* Number of triangles within each face defined by segmentsTheta. */ |
174
|
|
|
'segmentsPhi' => 8, |
175
|
|
|
/* Starting angle in degrees. */ |
176
|
|
|
'thetaStart' => 0, |
177
|
|
|
/* Central angle in degrees. */ |
178
|
|
|
'thetaLength' => 360 |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* The sphere primitive can define spheres in the traditional sense like a basketball. |
183
|
|
|
* |
184
|
|
|
* But it can also define various polyhedrons and abstract shapes given that it can specify |
185
|
|
|
* the number of horizontal and vertical angles and faces. |
186
|
|
|
* |
187
|
|
|
* Sticking with a basic sphere, the default number of segments is high enough to make the sphere appear round. |
188
|
|
|
*/ |
189
|
|
|
const P_SPHERE = array( |
190
|
|
|
/* Radius of the sphere. */ |
191
|
|
|
'radius' => 1, |
192
|
|
|
/* Number of horizontal segments. */ |
193
|
|
|
'segmentsWidth' => 18, |
194
|
|
|
/* Number of vertical segments. */ |
195
|
|
|
'segmentsHeight' => 36, |
196
|
|
|
/* Horizontal starting angle. */ |
197
|
|
|
'phiStart' => 0, |
198
|
|
|
/* Horizontal sweep angle size. */ |
199
|
|
|
'phiLength' => 360, |
200
|
|
|
/* Vertical starting angle. */ |
201
|
|
|
'thetaStart' => 0, |
202
|
|
|
/* Vertical sweep angle size. */ |
203
|
|
|
'thetaLength' => 360 |
204
|
|
|
); |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* The torus primitive defines a donut shape. |
208
|
|
|
*/ |
209
|
|
|
const P_TORUS = array( |
210
|
|
|
/* Radius of the outer edge of the torus. */ |
211
|
|
|
'radius' => 1, |
212
|
|
|
/* Radius of the tube. */ |
213
|
|
|
'radiusTubular' => 0.2, |
214
|
|
|
/* Number of segments along the circumference of the tube ends. A higher number means the tube will be more round. */ |
215
|
|
|
'segmentsRadial' => 36, |
216
|
|
|
/* Number of segments along the circumference of the tube face. A higher number means the tube will be more round. */ |
217
|
|
|
'segmentsTubular' => 32, |
218
|
|
|
/* Central angle. */ |
219
|
|
|
'arc' => 360 |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* The torus knot primitive defines a pretzel shape, the particular shape of which is defined by a pair of coprime integers, |
224
|
|
|
* p and q. |
225
|
|
|
* If p and q are not coprime the result will be a torus link. |
226
|
|
|
*/ |
227
|
|
|
const P_TORUS_KNOT = array( |
228
|
|
|
/* Radius that contains the torus knot. */ |
229
|
|
|
'radius' => 1, |
230
|
|
|
/* Radius of the tubes of the torus knot. */ |
231
|
|
|
'radiusTubular' => 0.2, |
232
|
|
|
/* Number of segments along the circumference of the tube ends. A higher number means the tube will be more round. */ |
233
|
|
|
'segmentsRadial' => 36, |
234
|
|
|
/* Number of segments along the circumference of the tube face. A higher number means the tube will be more round. */ |
235
|
|
|
'segmentsTubular' => 32, |
236
|
|
|
/* Number that helps define the pretzel shape. */ |
237
|
|
|
'p' => 2, |
238
|
|
|
/* Number that helps define the pretzel shape. */ |
239
|
|
|
'q' => 3 |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
/* DOM atrributes */ |
243
|
|
|
protected $primitive; |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Width |
247
|
|
|
* |
248
|
|
|
* BOX: Width (in meters) of the sides on the X axis. |
249
|
|
|
* PLANE: Width along the X axis. |
250
|
|
|
* |
251
|
|
|
* @var float |
252
|
|
|
*/ |
253
|
|
|
protected $width; |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Height |
257
|
|
|
* |
258
|
|
|
* BOX: Height (in meters) of the sides on the Y axis. |
259
|
|
|
* CONE: Height of the cone. |
260
|
|
|
* CYLINDER: Height of the cylinder. |
261
|
|
|
* PLANE: Height along the Y axis. |
262
|
|
|
* |
263
|
|
|
* @var float $height |
264
|
|
|
*/ |
265
|
|
|
protected $height; |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Depth |
269
|
|
|
* |
270
|
|
|
* BOX: Depth (in meters) of the sides on the Z axis. |
271
|
|
|
* |
272
|
|
|
* @var float $depth |
273
|
|
|
*/ |
274
|
|
|
protected $depth; |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Segments |
278
|
|
|
* |
279
|
|
|
* CIRCLE: Number of triangles to construct the circle, like pizza slices. |
280
|
|
|
* A higher number of segments means the circle will be more round. |
281
|
|
|
* |
282
|
|
|
* @var int $segments |
283
|
|
|
*/ |
284
|
|
|
protected $segments; |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Start angle for first segmen |
288
|
|
|
* |
289
|
|
|
* CIRCLE: Start angle for first segment. Can be used to define a partial circle. |
290
|
|
|
* CONE: Starting angle in degrees. |
291
|
|
|
* CYLINDER: Starting angle in degrees. |
292
|
|
|
* RING: Starting angle in degrees. |
293
|
|
|
* SPHERE: Vertical starting angle. |
294
|
|
|
* |
295
|
|
|
* @var float $thetaStart; |
296
|
|
|
*/ |
297
|
|
|
protected $thetaStart; |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* The central angle (in degrees). |
301
|
|
|
* |
302
|
|
|
* CIRCLE: Defaults to 360, which makes for a complete circle. |
303
|
|
|
* CONE: Central angle in degrees. |
304
|
|
|
* CYLINDER: Central angle in degrees. |
305
|
|
|
* RING: Central angle in degrees. |
306
|
|
|
* SPHERE: Vertical sweep angle size. |
307
|
|
|
* |
308
|
|
|
* @var float $thetaLength |
309
|
|
|
*/ |
310
|
|
|
protected $thetaLength; |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* openEnded |
314
|
|
|
* |
315
|
|
|
* CONE: Whether the ends of the cone are open (true) or capped (false). |
316
|
|
|
* CYLINDER: Whether the ends of the cylinder are open (true) or capped (false). |
317
|
|
|
* |
318
|
|
|
* @var string $openEnded |
319
|
|
|
*/ |
320
|
|
|
protected $openEnded; |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* segmentsRadial |
324
|
|
|
* |
325
|
|
|
* CONE: Number of segmented faces around the circumference of the cone. |
326
|
|
|
* CYLINDER: Number of segmented faces around the circumference of the cylinder. |
327
|
|
|
* TORUS: Number of segments along the circumference of the tube ends. |
328
|
|
|
* A higher number means the tube will be more round. |
329
|
|
|
* |
330
|
|
|
* @var int $segmentsRadial |
331
|
|
|
*/ |
332
|
|
|
protected $segmentsRadial; |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* segmentsHeight |
336
|
|
|
* |
337
|
|
|
* CONE: Number of rows of faces along the height of the cone. |
338
|
|
|
* CYLINDER: Number of rows of faces along the height of the cylinder. |
339
|
|
|
* SPHERE: Number of vertical segments. |
340
|
|
|
* |
341
|
|
|
* @var int $segmentsHeight |
342
|
|
|
*/ |
343
|
|
|
protected $segmentsHeight; |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* segmentsWidth |
347
|
|
|
* |
348
|
|
|
* SPHERE: Number of horizontal segments. |
349
|
|
|
* |
350
|
|
|
* @var int $segmentsWidth |
351
|
|
|
*/ |
352
|
|
|
protected $segmentsWidth; |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* segmentsTheta |
356
|
|
|
* |
357
|
|
|
* RING: Number of segments. A higher number means the ring will be more round. |
358
|
|
|
* |
359
|
|
|
* @var int $segmentsTheta |
360
|
|
|
*/ |
361
|
|
|
protected $segmentsTheta; |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* segmentsPhi |
365
|
|
|
* |
366
|
|
|
* RING: Number of triangles within each face defined by segmentsTheta. |
367
|
|
|
* |
368
|
|
|
* @var int $segmentsPhi |
369
|
|
|
*/ |
370
|
|
|
protected $segmentsPhi; |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* segmentsTubular |
374
|
|
|
* |
375
|
|
|
* TORUS: Number of segments along the circumference of the tube face. |
376
|
|
|
* A higher number means the tube will be more round. |
377
|
|
|
* |
378
|
|
|
* @var int $segmentsTubular |
379
|
|
|
*/ |
380
|
|
|
protected $segmentsTubular; |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* phiStart |
384
|
|
|
* |
385
|
|
|
* SPHERE: Horizontal starting angle. |
386
|
|
|
* |
387
|
|
|
* @var float $phiStart |
388
|
|
|
*/ |
389
|
|
|
protected $phiStart; |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* phiLength |
393
|
|
|
* |
394
|
|
|
* SPHERE: Horizontal sweep angle size. |
395
|
|
|
* |
396
|
|
|
* @var float $phiLength |
397
|
|
|
*/ |
398
|
|
|
protected $phiLength; |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Radius |
402
|
|
|
* |
403
|
|
|
* CIRCLE: Radius (in meters) of the circle. |
404
|
|
|
* CYLINDER: Radius of the cylinder. |
405
|
|
|
* SPHERE: Radius of the sphere. |
406
|
|
|
* TORUS: Radius of the outer edge of the torus. |
407
|
|
|
* |
408
|
|
|
* @var float $radius |
409
|
|
|
*/ |
410
|
|
|
protected $radius; |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* radiusTubular |
414
|
|
|
* |
415
|
|
|
* TORUS: Radius of the tube. |
416
|
|
|
* |
417
|
|
|
* @var float $radiusTubular |
418
|
|
|
*/ |
419
|
|
|
protected $radiusTubular; |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* radiusTop |
423
|
|
|
* |
424
|
|
|
* CONE: Radius of the top end of the cone. |
425
|
|
|
* |
426
|
|
|
* @var float $radiusTop |
427
|
|
|
*/ |
428
|
|
|
protected $radiusTop; |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* radiusBottom; |
432
|
|
|
* |
433
|
|
|
* CONE: Radius of the bottom end of the cone. |
434
|
|
|
* |
435
|
|
|
* @var float |
436
|
|
|
*/ |
437
|
|
|
protected $radiusBottom; |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* radiusInner |
441
|
|
|
* |
442
|
|
|
* RING: Radius of the inner hole of the ring. |
443
|
|
|
* |
444
|
|
|
* @var float $radiusInner |
445
|
|
|
*/ |
446
|
|
|
protected $radiusInner; |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* radiusOuter |
450
|
|
|
* |
451
|
|
|
* RING: Radius of the outer edge of the ring. |
452
|
|
|
* |
453
|
|
|
* @var float $radiusOuter |
454
|
|
|
*/ |
455
|
|
|
protected $radiusOuter; |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* arc |
459
|
|
|
* |
460
|
|
|
* TORUS: Central angle. |
461
|
|
|
* |
462
|
|
|
* @var float $arc |
463
|
|
|
*/ |
464
|
|
|
protected $arc; |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* p |
468
|
|
|
* |
469
|
|
|
* TORUSKNOT: Number that helps define the pretzel shape. |
470
|
|
|
* |
471
|
|
|
* @var int $p |
472
|
|
|
*/ |
473
|
|
|
protected $p; |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* q |
477
|
|
|
* |
478
|
|
|
* TORUSKNOT: Number that helps define the pretzel shape. |
479
|
|
|
* |
480
|
|
|
* @var unknown |
481
|
|
|
*/ |
482
|
|
|
protected $q; |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* Translates the geometry relative to its pivot point. |
486
|
|
|
* |
487
|
|
|
* @var string |
488
|
|
|
*/ |
489
|
|
|
protected $translate = '0 0 0'; |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Magic Call |
493
|
|
|
* |
494
|
|
|
* @param string $method |
495
|
|
|
* @param array $args |
496
|
|
|
* @throws InvalidComponentMethodException |
497
|
|
|
*/ |
498
|
34 |
|
public function __call($method, $args) |
499
|
|
|
{ |
500
|
34 |
|
if (method_exists($this, $method) && ($this->isPrimitiveMethod($method) || array_key_exists($method, self::P_COMMON_PROPS))) { |
|
|
|
|
501
|
34 |
|
return call_user_func_array(array( |
502
|
34 |
|
$this, |
503
|
34 |
|
$method |
504
|
|
|
), $args); |
505
|
|
|
} else { |
506
|
1 |
|
throw new InvalidComponentMethodException($method, 'Geometry::primitive ' . $this->primitive); |
507
|
|
|
} |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* Get Component scripts |
512
|
|
|
* |
513
|
|
|
* {@inheritdoc} |
514
|
|
|
* |
515
|
|
|
* @return array |
516
|
|
|
*/ |
517
|
1 |
|
public function getScripts(): array |
518
|
|
|
{ |
519
|
1 |
|
return array(); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* Does component have DOM Atributes |
524
|
|
|
* |
525
|
|
|
* {@inheritdoc} |
526
|
|
|
* |
527
|
|
|
* @return bool |
528
|
|
|
*/ |
529
|
1 |
|
public function hasDOMAttributes(): bool |
530
|
|
|
{ |
531
|
1 |
|
return ! empty(get_object_vars($this)); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Remove default DOMElement Attributes which are not required |
536
|
|
|
* |
537
|
|
|
* @return void |
538
|
|
|
*/ |
539
|
1 |
|
public function removeDefaultDOMAttributes() |
540
|
|
|
{ |
541
|
1 |
|
$defaults = $this->primitiveDefaults(); |
542
|
1 |
|
foreach (get_object_vars($this) as $name => $value) { |
543
|
1 |
|
if (empty($value) || (array_key_exists($name, self::P_COMMON_PROPS) && $value === self::P_COMMON_PROPS[$name]) || (array_key_exists($name, $defaults) && $value === $defaults[$name])) |
544
|
1 |
|
unset($this->$name); |
545
|
|
|
} |
546
|
1 |
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Get DOMAttr for the entity |
550
|
|
|
* |
551
|
|
|
* @return DOMAttr |
552
|
|
|
*/ |
553
|
1 |
|
public function getDOMAttributes(): DOMAttr |
554
|
|
|
{ |
555
|
1 |
|
$format = implode(': %s; ', array_keys(get_object_vars($this))) . ': %s;'; |
556
|
1 |
|
return new DOMAttr('geometry', vsprintf($format, array_values(get_object_vars($this)))); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Set primitive |
561
|
|
|
* |
562
|
|
|
* One of box, circle, cone, cylinder, plane, ring, sphere, torus, torusKnot. |
563
|
|
|
* |
564
|
|
|
* @param unknown $primitive |
|
|
|
|
565
|
|
|
* @throws InvalidComponentArgumentException |
566
|
|
|
*/ |
567
|
35 |
|
public function primitive($primitive = null) |
568
|
|
|
{ |
569
|
35 |
|
if (in_array($primitive, self::ALLOWED_PRIMITIVES)) { |
570
|
|
|
/* If primitive is changed we reset the object and releoad allowed attributes */ |
571
|
34 |
|
$this->primitive = $primitive; |
572
|
34 |
|
$defaults = $this->primitiveDefaults(); |
573
|
34 |
|
foreach (get_class_vars(get_class($this)) as $name => $default) { |
574
|
34 |
|
if ($name === 'primitive') |
575
|
34 |
|
continue; |
576
|
|
|
|
577
|
34 |
|
if (array_key_exists($name, $defaults)) |
578
|
34 |
|
$this->$name = $defaults[$name]; |
579
|
34 |
|
elseif (array_key_exists($name, self::P_COMMON_PROPS)) |
580
|
34 |
|
$this->$name = self::P_COMMON_PROPS[$name]; |
581
|
|
|
else |
582
|
34 |
|
unset($this->$name); |
583
|
|
|
} |
584
|
|
|
} else { |
585
|
2 |
|
throw new InvalidComponentArgumentException($primitive, 'Geometry::primitive'); |
|
|
|
|
586
|
|
|
} |
587
|
34 |
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* Set Buffer |
591
|
|
|
* |
592
|
|
|
* Transform geometry into a BufferGeometry to reduce memory usage at the cost of being harder to manipulate. |
593
|
|
|
* |
594
|
|
|
* @param bool $buffer |
595
|
|
|
*/ |
596
|
1 |
|
protected function buffer($buffer = true) |
597
|
|
|
{ |
598
|
1 |
|
$this->buffer = $buffer ? 'true' : 'false'; |
|
|
|
|
599
|
1 |
|
} |
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* skipCache |
603
|
|
|
* |
604
|
|
|
* Disable retrieving the shared geometry object from the cache. |
605
|
|
|
* |
606
|
|
|
* @param bool $skipCache |
607
|
|
|
*/ |
608
|
1 |
|
protected function skipCache($skipCache = false) |
609
|
|
|
{ |
610
|
1 |
|
$this->skipCache = $skipCache ? 'true' : 'false'; |
|
|
|
|
611
|
1 |
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Width |
615
|
|
|
* |
616
|
|
|
* {@inheritdoc} |
617
|
|
|
* |
618
|
|
|
* @param float $width |
|
|
|
|
619
|
|
|
*/ |
620
|
15 |
|
protected function width(float $width = null) |
621
|
|
|
{ |
622
|
15 |
|
$this->width = $width; |
623
|
15 |
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Height |
627
|
|
|
* |
628
|
|
|
* {@inheritdoc} |
629
|
|
|
* |
630
|
|
|
* @param float $height |
|
|
|
|
631
|
|
|
*/ |
632
|
21 |
|
protected function height(float $height = null) |
633
|
|
|
{ |
634
|
21 |
|
$this->height = $height; |
635
|
21 |
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* Depth |
639
|
|
|
* |
640
|
|
|
* {@inheritdoc} |
641
|
|
|
* |
642
|
|
|
* @param float $depth |
|
|
|
|
643
|
|
|
*/ |
644
|
10 |
|
protected function depth(float $depth = null) |
645
|
|
|
{ |
646
|
10 |
|
$this->depth = $depth; |
647
|
10 |
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Segments |
651
|
|
|
* |
652
|
|
|
* {@inheritdoc} |
653
|
|
|
* |
654
|
|
|
* @param int $segments |
655
|
|
|
*/ |
656
|
1 |
|
protected function segments($segments) |
657
|
|
|
{ |
658
|
1 |
|
$this->segments = $segments; |
659
|
1 |
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* Start angle for first segmen |
663
|
|
|
* |
664
|
|
|
* {@inheritdoc} |
665
|
|
|
* |
666
|
|
|
* @param float $thetaStart |
667
|
|
|
*/ |
668
|
10 |
|
protected function thetaStart($thetaStart) |
669
|
|
|
{ |
670
|
10 |
|
$this->thetaStart = $thetaStart; |
671
|
10 |
|
} |
672
|
|
|
|
673
|
|
|
/** |
674
|
|
|
* The central angle (in degrees). |
675
|
|
|
* |
676
|
|
|
* {@inheritdoc} |
677
|
|
|
* |
678
|
|
|
* @param float $thetaLength |
|
|
|
|
679
|
|
|
*/ |
680
|
10 |
|
protected function thetaLength(float $thetaLength = null) |
681
|
|
|
{ |
682
|
10 |
|
$this->thetaLength = $thetaLength; |
683
|
10 |
|
} |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* openEnded |
687
|
|
|
* |
688
|
|
|
* {@inheritdoc} |
689
|
|
|
* |
690
|
|
|
* @param bool $openEnded |
691
|
|
|
*/ |
692
|
7 |
|
protected function openEnded(bool $openEnded = false) |
693
|
|
|
{ |
694
|
7 |
|
$this->openEnded = $openEnded ? 'true' : 'false'; |
695
|
7 |
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* segmentsRadial |
699
|
|
|
* |
700
|
|
|
* {@inheritdoc} |
701
|
|
|
* |
702
|
|
|
* @param int $segmentsRadial |
|
|
|
|
703
|
|
|
*/ |
704
|
4 |
|
protected function segmentsRadial(int $segmentsRadial = null) |
705
|
|
|
{ |
706
|
4 |
|
$this->segmentsRadial = $segmentsRadial; |
707
|
4 |
|
} |
708
|
|
|
|
709
|
|
|
/** |
710
|
|
|
* segmentsHeight |
711
|
|
|
* |
712
|
|
|
* {@inheritdoc} |
713
|
|
|
* |
714
|
|
|
* @param int $segmentsHeight |
|
|
|
|
715
|
|
|
*/ |
716
|
16 |
|
protected function segmentsHeight(int $segmentsHeight = null) |
717
|
|
|
{ |
718
|
16 |
|
$this->segmentsHeight = $segmentsHeight; |
719
|
16 |
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* segmentsWidth |
723
|
|
|
* |
724
|
|
|
* {@inheritdoc} |
725
|
|
|
* |
726
|
|
|
* @param unknown $segmentsWidth |
|
|
|
|
727
|
|
|
*/ |
728
|
10 |
|
protected function segmentsWidth(int $segmentsWidth = null) |
729
|
|
|
{ |
730
|
10 |
|
$this->segmentsWidth = $segmentsWidth; |
731
|
10 |
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* segmentsTheta |
735
|
|
|
* |
736
|
|
|
* {@inheritdoc} |
737
|
|
|
* |
738
|
|
|
* @param int $segmentsTheta |
|
|
|
|
739
|
|
|
*/ |
740
|
1 |
|
protected function segmentsTheta(int $segmentsTheta = null) |
741
|
|
|
{ |
742
|
1 |
|
$this->segmentsTheta = $segmentsTheta; |
743
|
1 |
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* segmentsPhi |
747
|
|
|
* |
748
|
|
|
* {@inheritdoc} |
749
|
|
|
* |
750
|
|
|
* @param int $segmentsPhi |
|
|
|
|
751
|
|
|
*/ |
752
|
1 |
|
protected function segmentsPhi(int $segmentsPhi = null) |
753
|
|
|
{ |
754
|
1 |
|
$this->segmentsPhi = $segmentsPhi; |
755
|
1 |
|
} |
756
|
|
|
|
757
|
|
|
/** |
758
|
|
|
* segmentsTubular |
759
|
|
|
* |
760
|
|
|
* {@inheritdoc} |
761
|
|
|
* |
762
|
|
|
* @param unknown $segmentsTubular |
|
|
|
|
763
|
|
|
*/ |
764
|
2 |
|
protected function segmentsTubular(int $segmentsTubular = null) |
765
|
|
|
{ |
766
|
2 |
|
$this->segmentsTubular = $segmentsTubular; |
767
|
2 |
|
} |
768
|
|
|
|
769
|
|
|
/** |
770
|
|
|
* phiStart |
771
|
|
|
* |
772
|
|
|
* {@inheritdoc} |
773
|
|
|
* |
774
|
|
|
* @param float $phiStart |
|
|
|
|
775
|
|
|
*/ |
776
|
1 |
|
protected function phiStart(float $phiStart = null) |
777
|
|
|
{ |
778
|
1 |
|
$this->phiStart = $phiStart; |
779
|
1 |
|
} |
780
|
|
|
|
781
|
|
|
/** |
782
|
|
|
* phiLength |
783
|
|
|
* |
784
|
|
|
* {@inheritdoc} |
785
|
|
|
* |
786
|
|
|
* @param unknown $phiLength |
|
|
|
|
787
|
|
|
*/ |
788
|
1 |
|
protected function phiLength(float $phiLength = null) |
789
|
|
|
{ |
790
|
1 |
|
$this->phiLength = $phiLength; |
791
|
1 |
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* Radius |
795
|
|
|
* |
796
|
|
|
* {@inheritdoc} |
797
|
|
|
* |
798
|
|
|
* @param float $radius |
|
|
|
|
799
|
|
|
*/ |
800
|
18 |
|
protected function radius(float $radius = null) |
801
|
|
|
{ |
802
|
18 |
|
$this->radius = $radius; |
803
|
18 |
|
} |
804
|
|
|
|
805
|
|
|
/** |
806
|
|
|
* radiusTubular |
807
|
|
|
* |
808
|
|
|
* {@inheritdoc} |
809
|
|
|
* |
810
|
|
|
* @param float $radiusTubular |
|
|
|
|
811
|
|
|
*/ |
812
|
2 |
|
protected function radiusTubular(float $radiusTubular = null) |
813
|
|
|
{ |
814
|
2 |
|
$this->radiusTubular = $radiusTubular; |
815
|
2 |
|
} |
816
|
|
|
|
817
|
|
|
/** |
818
|
|
|
* radiusTop |
819
|
|
|
* |
820
|
|
|
* {@inheritdoc} |
821
|
|
|
* |
822
|
|
|
* @param float $radiusTop |
|
|
|
|
823
|
|
|
*/ |
824
|
1 |
|
protected function radiusTop(float $radiusTop = null) |
825
|
|
|
{ |
826
|
1 |
|
$this->radiusTop = $radiusTop; |
827
|
1 |
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* radiusBottom |
831
|
|
|
* |
832
|
|
|
* {@inheritdoc} |
833
|
|
|
* |
834
|
|
|
* @param float $radiusBottom |
|
|
|
|
835
|
|
|
*/ |
836
|
1 |
|
protected function radiusBottom(float $radiusBottom = null) |
837
|
|
|
{ |
838
|
1 |
|
$this->radiusBottom = $radiusBottom; |
839
|
1 |
|
} |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* radiusInner |
843
|
|
|
* |
844
|
|
|
* {@inheritdoc} |
845
|
|
|
* |
846
|
|
|
* @param unknown $radiusInner |
|
|
|
|
847
|
|
|
*/ |
848
|
1 |
|
protected function radiusInner(float $radiusInner = null) |
849
|
|
|
{ |
850
|
1 |
|
$this->radiusInner = $radiusInner; |
851
|
1 |
|
} |
852
|
|
|
|
853
|
|
|
/** |
854
|
|
|
* radiusOuter |
855
|
|
|
* |
856
|
|
|
* {@inheritdoc} |
857
|
|
|
* |
858
|
|
|
* @param unknown $radiusOuter |
|
|
|
|
859
|
|
|
*/ |
860
|
1 |
|
protected function radiusOuter(float $radiusOuter = null) |
861
|
|
|
{ |
862
|
1 |
|
$this->radiusOuter = $radiusOuter; |
863
|
1 |
|
} |
864
|
|
|
|
865
|
|
|
/** |
866
|
|
|
* arc |
867
|
|
|
* |
868
|
|
|
* {@inheritdoc} |
869
|
|
|
* |
870
|
|
|
* @param unknown $arc |
|
|
|
|
871
|
|
|
*/ |
872
|
1 |
|
protected function arc(float $arc = null) |
873
|
|
|
{ |
874
|
1 |
|
$this->arc = $arc; |
875
|
1 |
|
} |
876
|
|
|
|
877
|
|
|
/** |
878
|
|
|
* p |
879
|
|
|
* |
880
|
|
|
* {@inheritdoc} |
881
|
|
|
* |
882
|
|
|
* @param int $p |
|
|
|
|
883
|
|
|
*/ |
884
|
1 |
|
protected function p(int $p = null) |
885
|
|
|
{ |
886
|
1 |
|
$this->p = $p; |
887
|
1 |
|
} |
888
|
|
|
|
889
|
|
|
/** |
890
|
|
|
* q |
891
|
|
|
* |
892
|
|
|
* {@inheritdoc} |
893
|
|
|
* |
894
|
|
|
* @param int $q |
|
|
|
|
895
|
|
|
*/ |
896
|
1 |
|
protected function q(int $q = null) |
897
|
|
|
{ |
898
|
1 |
|
$this->q = $q; |
|
|
|
|
899
|
1 |
|
} |
900
|
|
|
|
901
|
|
|
/** |
902
|
|
|
* translate |
903
|
|
|
* |
904
|
|
|
* Translates the geometry relative to its pivot point. |
905
|
|
|
* |
906
|
|
|
* @param float $x |
|
|
|
|
907
|
|
|
* @param float $y |
|
|
|
|
908
|
|
|
* @param float $z |
|
|
|
|
909
|
|
|
*/ |
910
|
7 |
|
protected function translate(float $x = 0, float $y = 0, float $z = 0) |
911
|
|
|
{ |
912
|
7 |
|
$this->translate = sprintf('%d %d %d', $x, $y, $z); |
913
|
|
|
; |
914
|
7 |
|
} |
915
|
|
|
|
916
|
|
|
/** |
917
|
|
|
* Is called method allowed for current primitive |
918
|
|
|
* |
919
|
|
|
* @param unknown $method |
920
|
|
|
*/ |
921
|
34 |
|
protected function isPrimitiveMethod($method) |
922
|
|
|
{ |
923
|
34 |
|
$isPrimitiveMethod = false; |
924
|
|
|
|
925
|
34 |
|
switch ($this->primitive) { |
926
|
34 |
|
case 'box': |
927
|
10 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_BOX); |
928
|
10 |
|
break; |
929
|
25 |
|
case 'circle': |
930
|
1 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_CIRCLE); |
931
|
1 |
|
break; |
932
|
24 |
|
case 'cone': |
933
|
1 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_CONE); |
934
|
1 |
|
break; |
935
|
23 |
|
case 'cylinder': |
936
|
6 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_CYLINDER); |
937
|
6 |
|
break; |
938
|
18 |
|
case 'plane': |
939
|
6 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_PLANE); |
940
|
6 |
|
break; |
941
|
13 |
|
case 'ring': |
942
|
1 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_RING); |
943
|
1 |
|
break; |
944
|
12 |
|
case 'sphere': |
945
|
10 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_SPHERE); |
946
|
10 |
|
break; |
947
|
2 |
|
case 'torus': |
948
|
1 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_TORUS); |
949
|
1 |
|
break; |
950
|
1 |
|
case 'torusKnot': |
951
|
1 |
|
$isPrimitiveMethod = array_key_exists($method, self::P_TORUS_KNOT); |
952
|
1 |
|
break; |
953
|
|
|
} |
954
|
34 |
|
return $isPrimitiveMethod; |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
/** |
958
|
|
|
* Get defaults for current primitve type |
959
|
|
|
* |
960
|
|
|
* @return array; |
|
|
|
|
961
|
|
|
*/ |
962
|
34 |
|
protected function primitiveDefaults(): array |
963
|
|
|
{ |
964
|
34 |
|
$defaults = false; |
965
|
|
|
|
966
|
34 |
|
switch ($this->primitive) { |
967
|
34 |
|
case 'box': |
968
|
10 |
|
$defaults = self::P_BOX; |
969
|
10 |
|
break; |
970
|
25 |
|
case 'circle': |
971
|
1 |
|
$defaults = self::P_CIRCLE; |
972
|
1 |
|
break; |
973
|
24 |
|
case 'cone': |
974
|
1 |
|
$defaults = self::P_CONE; |
975
|
1 |
|
break; |
976
|
23 |
|
case 'cylinder': |
977
|
6 |
|
$defaults = self::P_CYLINDER; |
978
|
6 |
|
break; |
979
|
18 |
|
case 'plane': |
980
|
6 |
|
$defaults = self::P_PLANE; |
981
|
6 |
|
break; |
982
|
13 |
|
case 'ring': |
983
|
1 |
|
$defaults = self::P_RING; |
984
|
1 |
|
break; |
985
|
12 |
|
case 'sphere': |
986
|
10 |
|
$defaults = self::P_SPHERE; |
987
|
10 |
|
break; |
988
|
2 |
|
case 'torus': |
989
|
1 |
|
$defaults = self::P_TORUS; |
990
|
1 |
|
break; |
991
|
1 |
|
case 'torusKnot': |
992
|
1 |
|
$defaults = self::P_TORUS_KNOT; |
993
|
1 |
|
break; |
994
|
|
|
} |
995
|
34 |
|
return $defaults; |
996
|
|
|
} |
997
|
|
|
} |
998
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: