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