1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jul 7, 2016 - 7:27:20 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 Torus.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\Primitives; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Extras\Primitives\TorusPrimitiveIF; |
27
|
|
|
use \AframeVR\Core\Entity; |
28
|
|
|
use \AframeVR\Core\Helpers\MeshAttributes; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* <a-torus> |
32
|
|
|
* |
33
|
|
|
* The torus primitive creates a donut or circular tube shape. It is an entity that prescribes the geometry with its |
34
|
|
|
* geometric primitive set to torus. |
35
|
|
|
*/ |
36
|
|
|
final class Torus extends Entity implements TorusPrimitiveIF |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
use MeshAttributes; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Init <a-sphere> |
43
|
|
|
* |
44
|
|
|
* The sphere primitive creates a spherical or polyhedron shapes. |
45
|
|
|
* It wraps an entity that prescribes the geometry component with its geometric primitive set to sphere. |
46
|
|
|
* |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
5 |
|
public function init() |
52
|
|
|
{ |
53
|
|
|
/* Load defaults */ |
54
|
5 |
|
$this->component('Geometry')->primitive('torus'); |
55
|
|
|
|
56
|
|
|
|
57
|
5 |
|
$this->radius(); |
58
|
5 |
|
$this->radiusTubular(); |
59
|
5 |
|
$this->segmentsRadial(); |
60
|
5 |
|
$this->segmentsTubular(); |
61
|
5 |
|
$this->arc(); |
62
|
5 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Radius of the outer edge of the torus. |
66
|
|
|
* |
67
|
|
|
* @param int|float $radius |
68
|
|
|
* @return TorusPrimitiveIF |
69
|
|
|
*/ |
70
|
5 |
|
public function radius(float $radius = 1): TorusPrimitiveIF |
71
|
|
|
{ |
72
|
5 |
|
$this->component('Geometry')->radius($radius); |
73
|
5 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Radius of the tube. |
78
|
|
|
* |
79
|
|
|
* @param double $radiusTubular |
80
|
|
|
* @return TorusPrimitiveIF |
81
|
|
|
*/ |
82
|
5 |
|
public function radiusTubular(float $radiusTubular = 0.2): TorusPrimitiveIF |
83
|
|
|
{ |
84
|
5 |
|
$this->component('Geometry')->radiusTubular($radiusTubular); |
85
|
5 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Number of segments along the circumference of the tube ends. |
90
|
|
|
* A higher number means the tube will be more round. |
91
|
|
|
* |
92
|
|
|
* @param int $segmentsRadial |
93
|
|
|
* @return TorusPrimitiveIF |
94
|
|
|
*/ |
95
|
5 |
|
public function segmentsRadial(int $segmentsRadial = 36): TorusPrimitiveIF |
96
|
|
|
{ |
97
|
5 |
|
$this->component('Geometry')->segmentsRadial($segmentsRadial); |
98
|
5 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Number of segments along the circumference of the tube face. |
103
|
|
|
* A higher number means the tube will be more round. |
104
|
|
|
* |
105
|
|
|
* @param int $segmentsTubular |
106
|
|
|
* @return TorusPrimitiveIF |
107
|
|
|
*/ |
108
|
5 |
|
public function segmentsTubular(int $segmentsTubular = 8): TorusPrimitiveIF |
109
|
|
|
{ |
110
|
5 |
|
$this->component('Geometry')->segmentsTubular($segmentsTubular); |
111
|
5 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Central angle. |
116
|
|
|
* |
117
|
|
|
* @param int|float $arc |
118
|
|
|
* @return TorusPrimitiveIF |
119
|
|
|
*/ |
120
|
5 |
|
public function arc(float $arc = 360): TorusPrimitiveIF |
121
|
|
|
{ |
122
|
5 |
|
$this->component('Geometry')->arc($arc); |
123
|
5 |
|
return $this; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|