Completed
Pull Request — master (#60)
by Marko
07:48
created

Primitives::objmodel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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