|
1
|
|
|
<?php |
|
2
|
|
|
/** @formatter:off |
|
3
|
|
|
* ****************************************************************** |
|
4
|
|
|
* Created by Marko Kungla on Jun 20, 2016 - 10:21:07 PM |
|
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 Primitives.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\Extras; |
|
25
|
|
|
|
|
26
|
|
|
use \AframeVR\Extras\Primitives\{ |
|
27
|
|
|
Sphere, |
|
28
|
|
|
Box, |
|
29
|
|
|
Circle, |
|
30
|
|
|
Cylinder, |
|
31
|
|
|
Image, |
|
32
|
|
|
Light, |
|
33
|
|
|
Plane, |
|
34
|
|
|
Sky, |
|
35
|
|
|
Camera, |
|
36
|
|
|
ColladaModel, |
|
37
|
|
|
Videosphere, |
|
38
|
|
|
Video, |
|
39
|
|
|
Torus, |
|
40
|
|
|
Ring, |
|
41
|
|
|
ObjModel, |
|
42
|
|
|
Curvedimage, |
|
43
|
|
|
Cone |
|
44
|
|
|
} |
|
45
|
|
|
; |
|
46
|
|
|
use \AframeVR\Core\Entity; |
|
47
|
|
|
|
|
48
|
|
|
trait Primitives |
|
49
|
|
|
{ |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Aframe Document Object Model |
|
53
|
|
|
* |
|
54
|
|
|
* @var \AframeVR\Core\DOM\AframeDOMDocument |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $aframeDomObj; |
|
57
|
|
|
protected $childrens = array(); |
|
58
|
|
|
/** |
|
59
|
|
|
* Sphere primitives |
|
60
|
|
|
* |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $spheres = array(); |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Box primitives |
|
67
|
|
|
* |
|
68
|
|
|
* @var array |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $boxes = array(); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Cylinder primitives |
|
74
|
|
|
* |
|
75
|
|
|
* @var array |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $cylinders = array(); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Plane primitives |
|
81
|
|
|
* |
|
82
|
|
|
* @var array |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $planes = array(); |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Camera primitives |
|
88
|
|
|
* |
|
89
|
|
|
* @var array |
|
90
|
|
|
*/ |
|
91
|
|
|
protected $cameras = array(); |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* collada-model primitives |
|
95
|
|
|
* |
|
96
|
|
|
* @var array |
|
97
|
|
|
*/ |
|
98
|
|
|
protected $collada_models = array(); |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* |
|
102
|
|
|
* @var \AframeVR\Extras\Primitives\Sky $sky |
|
103
|
|
|
*/ |
|
104
|
|
|
protected $sky; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* |
|
108
|
|
|
* @var \AframeVR\Extras\Primitives\Videosphere $videosphere |
|
109
|
|
|
*/ |
|
110
|
|
|
protected $videosphere; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* |
|
114
|
|
|
* @var array |
|
115
|
|
|
*/ |
|
116
|
|
|
protected $images = array(); |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* |
|
120
|
|
|
* @var lights |
|
121
|
|
|
*/ |
|
122
|
|
|
protected $lights = array(); |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* |
|
126
|
|
|
* @var videos |
|
127
|
|
|
*/ |
|
128
|
|
|
protected $videos = array(); |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* |
|
132
|
|
|
* @var $toruses |
|
133
|
|
|
*/ |
|
134
|
|
|
protected $toruses = array(); |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* |
|
138
|
|
|
* @var $rings |
|
139
|
|
|
*/ |
|
140
|
|
|
protected $rings = array(); |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* |
|
144
|
|
|
* @var $objmodels |
|
145
|
|
|
*/ |
|
146
|
|
|
protected $objmodels = array(); |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* |
|
150
|
|
|
* @var $curvedimages |
|
151
|
|
|
*/ |
|
152
|
|
|
protected $curvedimages = array(); |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* |
|
156
|
|
|
* @var $cones |
|
157
|
|
|
*/ |
|
158
|
|
|
protected $cones = array(); |
|
|
|
|
|
|
159
|
|
|
protected $circles = array(); |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* A-Frame Primitive box |
|
163
|
|
|
* |
|
164
|
|
|
* @param string $id |
|
165
|
|
|
* @return Entity |
|
166
|
|
|
*/ |
|
167
|
7 |
|
public function box(string $id = 'untitled'): Entity |
|
168
|
|
|
{ |
|
169
|
7 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Box($id); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* A-Frame Primitive sphere |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $id |
|
176
|
|
|
* @return Entity |
|
177
|
|
|
*/ |
|
178
|
1 |
|
public function sphere(string $id = 'untitled'): Entity |
|
179
|
|
|
{ |
|
180
|
1 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Sphere($id); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* A-Frame Primitive cylinder |
|
185
|
|
|
* |
|
186
|
|
|
* @param string $id |
|
187
|
|
|
* @return Entity |
|
188
|
|
|
*/ |
|
189
|
2 |
|
public function cylinder(string $id = 'untitled'): Entity |
|
190
|
|
|
{ |
|
191
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Cylinder($id); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* A-Frame Primitive plane |
|
196
|
|
|
* |
|
197
|
|
|
* @param string $id |
|
198
|
|
|
* @return Entity |
|
199
|
|
|
*/ |
|
200
|
1 |
|
public function plane(string $id = 'untitled'): Entity |
|
201
|
|
|
{ |
|
202
|
1 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Plane($id); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* A-Frame Primitive camera |
|
207
|
|
|
* |
|
208
|
|
|
* @param string $id |
|
209
|
|
|
* @return Entity |
|
210
|
|
|
*/ |
|
211
|
2 |
|
public function camera(string $id = 'untitled'): Entity |
|
212
|
|
|
{ |
|
213
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Camera($id); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* A-Frame Primitive collada-model |
|
218
|
|
|
* |
|
219
|
|
|
* @param string $id |
|
220
|
|
|
* @return Entity |
|
221
|
|
|
*/ |
|
222
|
2 |
|
public function colladaModel(string $id = 'untitled'): Entity |
|
223
|
|
|
{ |
|
224
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new ColladaModel($id); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* A-Frame Primitive image |
|
229
|
|
|
* |
|
230
|
|
|
* @param string $id |
|
231
|
|
|
* @return Entity |
|
232
|
|
|
*/ |
|
233
|
1 |
|
public function image(string $id = 'untitled'): Entity |
|
234
|
|
|
{ |
|
235
|
1 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Image($id); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* A-Frame Primitive light |
|
240
|
|
|
* |
|
241
|
|
|
* @param string $id |
|
242
|
|
|
* @return Entity |
|
243
|
|
|
*/ |
|
244
|
2 |
|
public function light(string $id = 'untitled'): Entity |
|
245
|
|
|
{ |
|
246
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Light($id); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* A-Frame Primitive video |
|
251
|
|
|
* |
|
252
|
|
|
* @param string $id |
|
253
|
|
|
* @return Entity |
|
254
|
|
|
*/ |
|
255
|
1 |
|
public function video(string $id = 'untitled'): Entity |
|
256
|
|
|
{ |
|
257
|
1 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Video($id); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* A-Frame Primitive torus |
|
262
|
|
|
* |
|
263
|
|
|
* @param string $id |
|
264
|
|
|
* @return Entity |
|
265
|
|
|
*/ |
|
266
|
1 |
|
public function torus(string $id = 'untitled'): Entity |
|
267
|
|
|
{ |
|
268
|
1 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Torus($id); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* A-Frame Primitive ring |
|
273
|
|
|
* |
|
274
|
|
|
* @param string $id |
|
275
|
|
|
* @return Entity |
|
276
|
|
|
*/ |
|
277
|
1 |
|
public function ring(string $id = 'untitled'): Entity |
|
278
|
|
|
{ |
|
279
|
1 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Ring($id); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* A-Frame Primitive obj model |
|
284
|
|
|
* |
|
285
|
|
|
* @return Entity |
|
286
|
|
|
*/ |
|
287
|
2 |
|
public function objmodel(string $id = 'untitled'): Entity |
|
288
|
|
|
{ |
|
289
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new ObjModel($id); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* A-Frame Primitive curvedimage |
|
294
|
|
|
* |
|
295
|
|
|
* @return Entity |
|
296
|
|
|
*/ |
|
297
|
2 |
|
public function curvedimage(string $id = 'untitled'): Entity |
|
298
|
|
|
{ |
|
299
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Curvedimage($id); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* A-Frame Primitive cone |
|
304
|
|
|
* |
|
305
|
|
|
* @return Entity |
|
306
|
|
|
*/ |
|
307
|
2 |
|
public function cone(string $id = 'untitled'): Entity |
|
308
|
|
|
{ |
|
309
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Cone($id); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* A-Frame Primitive circle |
|
314
|
|
|
* |
|
315
|
|
|
* @return Entity |
|
316
|
|
|
*/ |
|
317
|
2 |
|
public function circle(string $id = 'untitled'): Entity |
|
318
|
|
|
{ |
|
319
|
2 |
|
return $this->childrens[$id] ?? $this->childrens[$id] = new Circle($id); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* A-Frame Primitive sky |
|
324
|
|
|
* |
|
325
|
|
|
* @return Entity |
|
326
|
|
|
*/ |
|
327
|
2 |
|
public function sky(string $id = 'untitled'): Entity |
|
328
|
|
|
{ |
|
329
|
2 |
|
return $this->sky = new Sky($id); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* A-Frame Primitive videosphere |
|
334
|
|
|
* |
|
335
|
|
|
* @return Entity |
|
336
|
|
|
*/ |
|
337
|
2 |
|
public function videosphere(string $id = 'untitled'): Entity |
|
338
|
|
|
{ |
|
339
|
2 |
|
return $this->videosphere = new Videosphere($id); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* Add all used primitevs to the scene |
|
344
|
|
|
* |
|
345
|
|
|
* @return void |
|
346
|
|
|
*/ |
|
347
|
19 |
|
protected function preparePrimitives() |
|
348
|
|
|
{ |
|
349
|
|
|
/* Primitive collections */ |
|
350
|
19 |
|
$this->aframeDomObj->appendEntities($this->childrens); |
|
351
|
|
|
/* Primitives which only one can be present */ |
|
352
|
19 |
|
(! $this->sky) ?: $this->aframeDomObj->appendEntity($this->sky); |
|
353
|
19 |
|
(! $this->videosphere) ?: $this->aframeDomObj->appendEntity($this->videosphere); |
|
354
|
19 |
|
} |
|
355
|
|
|
} |
|
356
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.