1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 20, 2016 - 10:28:02 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 Primitive.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\Core\Entity; |
27
|
|
|
use \AframeVR\Core\Helpers\MeshAttributes; |
28
|
|
|
use \AframeVR\Interfaces\PrimitiveInterface; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* <a-sphere> |
32
|
|
|
* |
33
|
|
|
* The sphere primitive creates a spherical or polyhedron shapes. |
34
|
|
|
* It wraps an entity that prescribes the geometry component with its geometric primitive set to sphere. |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
class Sphere extends Entity implements PrimitiveInterface |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
use MeshAttributes; |
39
|
|
|
|
40
|
9 |
|
public function init() |
41
|
|
|
{ |
42
|
9 |
|
$this->component('Material'); |
43
|
9 |
|
$this->component('Geometry')->primitive('sphere'); |
|
|
|
|
44
|
|
|
|
45
|
|
|
/* Load defaults */ |
46
|
9 |
|
$this->defaults(); |
47
|
9 |
|
} |
48
|
|
|
|
49
|
9 |
|
public function radius(float $radius = 0.85): Entity |
50
|
|
|
{ |
51
|
9 |
|
$this->component('Geometry')->radius($radius); |
|
|
|
|
52
|
9 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
9 |
|
public function segmentsHeight($segmentsHeigh = 18) |
56
|
|
|
{ |
57
|
9 |
|
$this->component('Geometry')->segmentsHeight($segmentsHeigh); |
|
|
|
|
58
|
9 |
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
9 |
|
public function segmentsWidth($segmentsWidth = 36) |
62
|
|
|
{ |
63
|
9 |
|
$this->component('Geometry')->segmentsWidth($segmentsWidth); |
|
|
|
|
64
|
9 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
5 |
|
public function defaults() |
68
|
|
|
{ |
69
|
5 |
|
$this->radius(); |
70
|
5 |
|
$this->segmentsHeight(); |
71
|
5 |
|
$this->segmentsWidth(); |
72
|
5 |
|
} |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.