Completed
Push — master ( 95af13...697c38 )
by Marko
8s
created

Primitives::camera()   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
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
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
    Plane,
31
    Sky,
32
    Camera,
33
    ColladaModel
34
};
35
use \AframeVR\Core\Entity;
36
37
trait Primitives
38
{
39
40
    /**
41
     * Aframe Document Object Model
42
     *
43
     * @var \AframeVR\Core\DOM\AframeDOMDocument
44
     */
45
    protected $aframeDomObj;
46
47
    /**
48
     * Sphere primitives
49
     *
50
     * @var array
51
     */
52
    protected $spheres = array();
53
54
    /**
55
     * Box primitives
56
     * 
57
     * @var array
58
     */
59
    protected $boxes = array();
60
61
    /**
62
     * Cylinder primitives
63
     * 
64
     * @var array
65
     */
66
    protected $cylinders = array();
67
68
    /**
69
     * Plane primitives
70
     * 
71
     * @var array
72
     */
73
    protected $planes = array();
74
    
75
    /**
76
     * Camera primitives
77
     * 
78
     * @var array
79
     */
80
    protected $cameras = array();
81
82
    /**
83
     * collada-model primitives
84
     * 
85
     * @var array
86
     */
87
    protected $collada_models = array();
88
    
89
    /**
90
     *
91
     * @var \AframeVR\Extras\Primitives\Sky $sky
92
     */
93
    protected $sky;
94
95
    /**
96
     * A-Frame Primitive box
97
     *
98
     * @param string $name            
99
     * @return Entity
100
     */
101 11
    public function box(string $name = 'untitled'): Entity
102
    {
103 11
        return $this->boxes[$name] ?? $this->boxes[$name] = new Box();
104
    }
105
106
    /**
107
     * A-Frame Primitive sphere
108
     *
109
     * @param string $name            
110
     * @return Entity
111
     */
112 7
    public function sphere(string $name = 'untitled'): Entity
113
    {
114 7
        return $this->spheres[$name] ?? $this->spheres[$name] = new Sphere();
115
    }
116
117
    /**
118
     * A-Frame Primitive cylinder
119
     *
120
     * @param string $name            
121
     * @return Entity
122
     */
123 7
    public function cylinder(string $name = 'untitled'): Entity
124
    {
125 7
        return $this->cylinders[$name] ?? $this->cylinders[$name] = new Cylinder();
126
    }
127
128
    /**
129
     * A-Frame Primitive plane
130
     *
131
     * @param string $name            
132
     * @return Entity
133
     */
134 7
    public function plane(string $name = 'untitled'): Entity
135
    {
136 7
        return $this->planes[$name] ?? $this->planes[$name] = new Plane();
137
    }
138
139
    /**
140
     * A-Frame Primitive camera
141
     *
142
     * @param string $name
143
     * @return Entity
144
     */
145 6
    public function camera(string $name = 'untitled'): Entity
146
    {
147 6
        return $this->cameras[$name] ?? $this->cameras[$name] = new Camera();
148
    }
149
    
150
    /**
151
     * A-Frame Primitive collada-model
152
     *
153
     * @param string $name
154
     * @return Entity
155
     */
156 3
    public function colladaModel(string $name = 'untitled'): Entity
157
    {
158 3
        return $this->collada_models[$name] ?? $this->collada_models[$name] = new ColladaModel();
159
    }
160
    
161
    /**
162
     * A-Frame Primitive sky
163
     *
164
     * @return Entity
165
     */
166 7
    public function sky(): Entity
167
    {
168 7
        return $this->sky = new Sky();
169
    }
170
171
    /**
172
     * Add all used primitevs to the scene
173
     *
174
     * @return void
175
     */
176 7
    protected function preparePrimitives()
177
    {
178
        /* Primitive collections */
179 7
        $this->aframeDomObj->appendEntities($this->cameras);
180 7
        $this->aframeDomObj->appendEntities($this->boxes);
181 7
        $this->aframeDomObj->appendEntities($this->spheres);
182 7
        $this->aframeDomObj->appendEntities($this->cylinders);
183 7
        $this->aframeDomObj->appendEntities($this->planes);
184 7
        $this->aframeDomObj->appendEntities($this->collada_models);
185
        
186
        /* Primitives which only one can be present */
187 7
        (! $this->sky) ?: $this->aframeDomObj->appendEntity($this->sky);
188 7
    }
189
}
190