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
|
|
|
} |
33
|
|
|
; |
34
|
|
|
use \AframeVR\Core\Entity; |
35
|
|
|
|
36
|
|
|
trait Primitives |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
protected $spheres; |
40
|
|
|
|
41
|
|
|
protected $boxes; |
42
|
|
|
|
43
|
|
|
protected $cylinders; |
44
|
|
|
|
45
|
|
|
protected $planes; |
46
|
|
|
|
47
|
|
|
protected $sky; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* A-Frame Primitive box |
51
|
|
|
* |
52
|
|
|
* @param string $name |
53
|
|
|
* @return Entity |
54
|
|
|
*/ |
55
|
5 |
|
public function box(string $name = 'untitled'): Entity |
56
|
|
|
{ |
57
|
5 |
|
return $this->boxes[$name] ?? $this->boxes[$name] = new Box(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* A-Frame Primitive camera |
62
|
|
|
* |
63
|
|
|
* @param string $name |
64
|
|
|
* @return Entity |
65
|
|
|
*/ |
66
|
|
|
public function camera(string $name = 'untitled'): Entity |
67
|
|
|
{ |
68
|
|
|
return $this->cameras[$name] ?? $this->cameras[$name] = new Camera(); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* A-Frame Primitive sphere |
73
|
|
|
* |
74
|
|
|
* @param string $name |
75
|
|
|
* @return Entity |
76
|
|
|
*/ |
77
|
5 |
|
public function sphere(string $name = 'untitled'): Entity |
78
|
|
|
{ |
79
|
5 |
|
return $this->spheres[$name] ?? $this->spheres[$name] = new Sphere(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* A-Frame Primitive cylinder |
86
|
|
|
* |
87
|
|
|
* @param string $name |
88
|
|
|
* @return Entity |
89
|
|
|
*/ |
90
|
5 |
|
public function cylinder(string $name = 'untitled'): Entity |
91
|
|
|
{ |
92
|
5 |
|
return $this->cylinders[$name] ?? $this->cylinders[$name] = new Cylinder(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* A-Frame Primitive plane |
97
|
|
|
* |
98
|
|
|
* @param string $name |
99
|
|
|
* @return Entity |
100
|
|
|
*/ |
101
|
5 |
|
public function plane(string $name = 'untitled'): Entity |
102
|
|
|
{ |
103
|
5 |
|
return $this->planes[$name] ?? $this->planes[$name] = new Plane(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* A-Frame Primitive sky |
108
|
|
|
* |
109
|
|
|
* @return Entity |
110
|
|
|
*/ |
111
|
5 |
|
public function sky(): Entity |
112
|
|
|
{ |
113
|
5 |
|
return $this->sky = new Sky(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Add all used primitevs to the scene |
118
|
|
|
* |
119
|
|
|
* @param \DOMDocument $aframe_dom |
120
|
|
|
* @param \DOMElement $scene |
121
|
|
|
*/ |
122
|
1 |
|
protected function DOMAppendPrimitives(\DOMDocument &$aframe_dom, \DOMElement &$scene) |
123
|
|
|
{ |
124
|
|
|
/* Add sphiers to DOM */ |
125
|
1 |
|
if (is_array($this->spheres)) { |
126
|
1 |
|
foreach ($this->spheres as $sphere) { |
127
|
1 |
|
$entity = $sphere->DOMElement($aframe_dom); |
128
|
1 |
|
$scene->appendChild($entity); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
/* Add boxes to DOM */ |
132
|
1 |
|
if (is_array($this->boxes)) { |
133
|
1 |
|
foreach ($this->boxes as $box) { |
134
|
1 |
|
$entity = $box->DOMElement($aframe_dom); |
135
|
1 |
|
$scene->appendChild($entity); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
/* Add cylinders to DOM */ |
139
|
1 |
|
if (is_array($this->cylinders)) { |
140
|
1 |
|
foreach ($this->cylinders as $cylinder) { |
141
|
1 |
|
$entity = $cylinder->DOMElement($aframe_dom); |
142
|
1 |
|
$scene->appendChild($entity); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
/* Add cylinders to DOM */ |
146
|
1 |
|
if (is_array($this->planes)) { |
147
|
1 |
|
foreach ($this->planes as $plane) { |
148
|
1 |
|
$entity = $plane->DOMElement($aframe_dom); |
149
|
1 |
|
$scene->appendChild($entity); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
/* Add cylinders to DOM */ |
153
|
1 |
|
if (is_object($this->sky)) { |
154
|
1 |
|
$entity = $this->sky->DOMElement($aframe_dom); |
155
|
1 |
|
$scene->appendChild($entity); |
156
|
|
|
} |
157
|
1 |
|
} |
158
|
|
|
} |
159
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: