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
|
|
|
use \AframeVR\Core\Entity; |
34
|
|
|
|
35
|
|
|
trait Primitives |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
protected $spheres; |
39
|
|
|
|
40
|
|
|
protected $boxes; |
41
|
|
|
|
42
|
|
|
protected $cylinders; |
43
|
|
|
|
44
|
|
|
protected $planes; |
45
|
|
|
|
46
|
|
|
protected $sky; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* A-Frame Primitive box |
50
|
|
|
* |
51
|
|
|
* @param string $name |
52
|
|
|
* @return Entity |
53
|
|
|
*/ |
54
|
9 |
|
public function box(string $name = 'untitled'): Entity |
55
|
|
|
{ |
56
|
9 |
|
return $this->boxes[$name] ?? $this->boxes[$name] = new Box(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* A-Frame Primitive sphere |
61
|
|
|
* |
62
|
|
|
* @param string $name |
63
|
|
|
* @return Entity |
64
|
|
|
*/ |
65
|
5 |
|
public function sphere(string $name = 'untitled'): Entity |
66
|
|
|
{ |
67
|
5 |
|
return $this->spheres[$name] ?? $this->spheres[$name] = new Sphere(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* A-Frame Primitive cylinder |
72
|
|
|
* |
73
|
|
|
* @param string $name |
74
|
|
|
* @return Entity |
75
|
|
|
*/ |
76
|
5 |
|
public function cylinder(string $name = 'untitled'): Entity |
77
|
|
|
{ |
78
|
5 |
|
return $this->cylinders[$name] ?? $this->cylinders[$name] = new Cylinder(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* A-Frame Primitive plane |
83
|
|
|
* |
84
|
|
|
* @param string $name |
85
|
|
|
* @return Entity |
86
|
|
|
*/ |
87
|
5 |
|
public function plane(string $name = 'untitled'): Entity |
88
|
|
|
{ |
89
|
5 |
|
return $this->planes[$name] ?? $this->planes[$name] = new Plane(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* A-Frame Primitive sky |
94
|
|
|
* |
95
|
|
|
* @return Entity |
96
|
|
|
*/ |
97
|
5 |
|
public function sky(): Entity |
98
|
|
|
{ |
99
|
5 |
|
return $this->sky = new Sky(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Add all used primitevs to the scene |
104
|
|
|
* |
105
|
|
|
* @param \DOMDocument $aframe_dom |
106
|
|
|
* @param \DOMElement $scene |
107
|
|
|
*/ |
108
|
6 |
|
protected function DOMAppendPrimitives(\DOMDocument &$aframe_dom, \DOMElement &$scene) |
109
|
|
|
{ |
110
|
|
|
/* Add sphiers to DOM */ |
111
|
6 |
|
if (is_array($this->spheres)) { |
112
|
1 |
|
foreach ($this->spheres as $sphere) { |
113
|
1 |
|
$entity = $sphere->DOMElement($aframe_dom); |
114
|
1 |
|
$scene->appendChild($entity); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
/* Add boxes to DOM */ |
118
|
6 |
|
if (is_array($this->boxes)) { |
119
|
1 |
|
foreach ($this->boxes as $box) { |
120
|
1 |
|
$entity = $box->DOMElement($aframe_dom); |
121
|
1 |
|
$scene->appendChild($entity); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
/* Add cylinders to DOM */ |
125
|
6 |
|
if (is_array($this->cylinders)) { |
126
|
1 |
|
foreach ($this->cylinders as $cylinder) { |
127
|
1 |
|
$entity = $cylinder->DOMElement($aframe_dom); |
128
|
1 |
|
$scene->appendChild($entity); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
/* Add cylinders to DOM */ |
132
|
6 |
|
if (is_array($this->planes)) { |
133
|
1 |
|
foreach ($this->planes as $plane) { |
134
|
1 |
|
$entity = $plane->DOMElement($aframe_dom); |
135
|
1 |
|
$scene->appendChild($entity); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
/* Add cylinders to DOM */ |
139
|
6 |
|
if (is_object($this->sky)) { |
140
|
1 |
|
$entity = $this->sky->DOMElement($aframe_dom); |
141
|
1 |
|
$scene->appendChild($entity); |
142
|
|
|
} |
143
|
6 |
|
} |
144
|
|
|
} |
145
|
|
|
|