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
|
|
|
}; |
39
|
|
|
use \AframeVR\Core\Entity; |
40
|
|
|
|
41
|
|
|
trait Primitives |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Aframe Document Object Model |
46
|
|
|
* |
47
|
|
|
* @var \AframeVR\Core\DOM\AframeDOMDocument |
48
|
|
|
*/ |
49
|
|
|
protected $aframeDomObj; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Sphere primitives |
53
|
|
|
* |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
protected $spheres = array(); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Box primitives |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected $boxes = array(); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Cylinder primitives |
67
|
|
|
* |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
protected $cylinders = array(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Plane primitives |
74
|
|
|
* |
75
|
|
|
* @var array |
76
|
|
|
*/ |
77
|
|
|
protected $planes = array(); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Camera primitives |
81
|
|
|
* |
82
|
|
|
* @var array |
83
|
|
|
*/ |
84
|
|
|
protected $cameras = array(); |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* collada-model primitives |
88
|
|
|
* |
89
|
|
|
* @var array |
90
|
|
|
*/ |
91
|
|
|
protected $collada_models = array(); |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* |
95
|
|
|
* @var \AframeVR\Extras\Primitives\Sky $sky |
96
|
|
|
*/ |
97
|
|
|
protected $sky; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
* @var \AframeVR\Extras\Primitives\Videosphere $videosphere |
102
|
|
|
*/ |
103
|
|
|
protected $videosphere; |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* |
108
|
|
|
* @var array |
109
|
|
|
*/ |
110
|
|
|
protected $images = array(); |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
* @var lights |
115
|
|
|
*/ |
116
|
|
|
protected $lights = array(); |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* |
120
|
|
|
* @var videos |
121
|
|
|
*/ |
122
|
|
|
protected $videos = array(); |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* A-Frame Primitive box |
126
|
|
|
* |
127
|
|
|
* @param string $id |
128
|
|
|
* @return Entity |
129
|
|
|
*/ |
130
|
11 |
|
public function box(string $id = 'untitled'): Entity |
131
|
|
|
{ |
132
|
11 |
|
return $this->boxes[$id] ?? $this->boxes[$id] = new Box($id); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* A-Frame Primitive sphere |
137
|
|
|
* |
138
|
|
|
* @param string $id |
139
|
|
|
* @return Entity |
140
|
|
|
*/ |
141
|
7 |
|
public function sphere(string $id = 'untitled'): Entity |
142
|
|
|
{ |
143
|
7 |
|
return $this->spheres[$id] ?? $this->spheres[$id] = new Sphere($id); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* A-Frame Primitive cylinder |
148
|
|
|
* |
149
|
|
|
* @param string $id |
150
|
|
|
* @return Entity |
151
|
|
|
*/ |
152
|
7 |
|
public function cylinder(string $id = 'untitled'): Entity |
153
|
|
|
{ |
154
|
7 |
|
return $this->cylinders[$id] ?? $this->cylinders[$id] = new Cylinder($id); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* A-Frame Primitive plane |
159
|
|
|
* |
160
|
|
|
* @param string $id |
161
|
|
|
* @return Entity |
162
|
|
|
*/ |
163
|
7 |
|
public function plane(string $id = 'untitled'): Entity |
164
|
|
|
{ |
165
|
7 |
|
return $this->planes[$id] ?? $this->planes[$id] = new Plane($id); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* A-Frame Primitive camera |
170
|
|
|
* |
171
|
|
|
* @param string $id |
172
|
|
|
* @return Entity |
173
|
|
|
*/ |
174
|
6 |
|
public function camera(string $id = 'untitled'): Entity |
175
|
|
|
{ |
176
|
6 |
|
return $this->cameras[$id] ?? $this->cameras[$id] = new Camera($id); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* A-Frame Primitive collada-model |
181
|
|
|
* |
182
|
|
|
* @param string $id |
183
|
|
|
* @return Entity |
184
|
|
|
*/ |
185
|
3 |
|
public function colladaModel(string $id = 'untitled'): Entity |
186
|
|
|
{ |
187
|
3 |
|
return $this->collada_models[$id] ?? $this->collada_models[$id] = new ColladaModel($id); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* A-Frame Primitive image |
192
|
|
|
* |
193
|
|
|
* @param string $id |
194
|
|
|
* @return Entity |
195
|
|
|
*/ |
196
|
1 |
|
public function image(string $id = 'untitled'): Entity |
197
|
|
|
{ |
198
|
1 |
|
return $this->images[$id] ?? $this->images[$id] = new Image($id); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* A-Frame Primitive light |
203
|
|
|
* |
204
|
|
|
* @param string $id |
205
|
|
|
* @return Entity |
206
|
|
|
*/ |
207
|
6 |
|
public function light(string $id = 'untitled'): Entity |
208
|
|
|
{ |
209
|
6 |
|
return $this->lights[$id] ?? $this->lights[$id] = new Light($id); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* A-Frame Primitive video |
214
|
|
|
* |
215
|
|
|
* @param string $id |
216
|
|
|
* @return Entity |
217
|
|
|
*/ |
218
|
3 |
|
public function video(string $id = 'untitled'): Entity |
219
|
|
|
{ |
220
|
3 |
|
return $this->videos[$id] ?? $this->videos[$id] = new Video($id); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* A-Frame Primitive sky |
225
|
|
|
* |
226
|
|
|
* @return Entity |
227
|
|
|
*/ |
228
|
7 |
|
public function sky(): Entity |
229
|
|
|
{ |
230
|
7 |
|
return $this->sky = new Sky(); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* A-Frame Primitive sky |
235
|
|
|
* |
236
|
|
|
* @return Entity |
237
|
|
|
*/ |
238
|
3 |
|
public function videosphere(): Entity |
239
|
|
|
{ |
240
|
3 |
|
return $this->videosphere = new Videosphere(); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Add all used primitevs to the scene |
245
|
|
|
* |
246
|
|
|
* @return void |
247
|
|
|
*/ |
248
|
10 |
|
protected function preparePrimitives() |
249
|
|
|
{ |
250
|
|
|
/* Primitive collections */ |
251
|
10 |
|
$this->aframeDomObj->appendEntities($this->cameras); |
252
|
10 |
|
$this->aframeDomObj->appendEntities($this->boxes); |
253
|
10 |
|
$this->aframeDomObj->appendEntities($this->spheres); |
254
|
10 |
|
$this->aframeDomObj->appendEntities($this->cylinders); |
255
|
10 |
|
$this->aframeDomObj->appendEntities($this->planes); |
256
|
10 |
|
$this->aframeDomObj->appendEntities($this->collada_models); |
257
|
10 |
|
$this->aframeDomObj->appendEntities($this->images); |
258
|
10 |
|
$this->aframeDomObj->appendEntities($this->lights); |
259
|
10 |
|
$this->aframeDomObj->appendEntities($this->videos); |
260
|
|
|
/* Primitives which only one can be present */ |
261
|
10 |
|
(! $this->sky) ?: $this->aframeDomObj->appendEntity($this->sky); |
262
|
10 |
|
(! $this->videosphere) ?: $this->aframeDomObj->appendEntity($this->videosphere); |
263
|
10 |
|
} |
264
|
|
|
} |
265
|
|
|
|