Completed
Pull Request — master (#60)
by Marko
04:06 queued 53s
created

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