1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 2:56:57 AM |
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 MeshAttributes.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\Core\Helpers; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\EntityInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Many of the primitives are entities that compose a geometric mesh, meaning they |
30
|
|
|
* primarily prescribe the geometry and material components. |
31
|
|
|
* Most of the mesh |
32
|
|
|
* primitives share common attributes, especially for mapping to the material component. |
33
|
|
|
* These common attributes won’t be described in individual |
34
|
|
|
* documentation pages for each primitive so they will be listed here |
35
|
|
|
*/ |
36
|
|
|
trait MeshAttributes |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* material.color |
41
|
|
|
* |
42
|
|
|
* @param string $color |
43
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
44
|
|
|
*/ |
45
|
3 |
|
public function color(string $color = 'gray'): EntityInterface |
46
|
|
|
{ |
47
|
3 |
|
$this->component('Material') |
|
|
|
|
48
|
3 |
|
->shader() |
49
|
3 |
|
->color($color); |
50
|
3 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* material.metalness |
55
|
|
|
* |
56
|
|
|
* @param string $metalness |
|
|
|
|
57
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
58
|
|
|
*/ |
59
|
3 |
|
public function metalness($metalness = 0): EntityInterface |
60
|
|
|
{ |
61
|
3 |
|
$this->component('Material') |
|
|
|
|
62
|
3 |
|
->shader() |
63
|
3 |
|
->metalness($metalness); |
64
|
3 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* material.roughness |
69
|
|
|
* |
70
|
|
|
* @param string $roughness |
|
|
|
|
71
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
72
|
|
|
*/ |
73
|
3 |
|
public function roughness($roughness = 0.5): EntityInterface |
74
|
|
|
{ |
75
|
3 |
|
$this->component('Material') |
|
|
|
|
76
|
3 |
|
->shader() |
77
|
3 |
|
->roughness($roughness); |
78
|
3 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* material.src |
83
|
|
|
* |
84
|
|
|
* @param string $src |
|
|
|
|
85
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
86
|
|
|
*/ |
87
|
3 |
|
public function src(string $src = null): EntityInterface |
88
|
|
|
{ |
89
|
3 |
|
$this->component('Material') |
|
|
|
|
90
|
3 |
|
->shader() |
91
|
3 |
|
->src($src); |
92
|
3 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* geometry.translate |
97
|
|
|
* |
98
|
|
|
* @param string $translate |
99
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
100
|
|
|
*/ |
101
|
3 |
|
public function translate($translate = '0 0 0'): EntityInterface |
102
|
|
|
{ |
103
|
3 |
|
$this->component('Geometry')->translate($translate); |
|
|
|
|
104
|
3 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* material.shader |
109
|
|
|
* |
110
|
|
|
* @param string $shader |
111
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
112
|
|
|
*/ |
113
|
3 |
|
public function shader($shader = 'standard'): EntityInterface |
114
|
|
|
{ |
115
|
3 |
|
$this->component('Material')->shader($shader); |
|
|
|
|
116
|
3 |
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* material.opacity |
121
|
|
|
* |
122
|
|
|
* @param string $opacity |
|
|
|
|
123
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
124
|
|
|
*/ |
125
|
3 |
|
public function opacity(float $opacity = 1.0): EntityInterface |
126
|
|
|
{ |
127
|
3 |
|
$this->component('Material')->opacity($opacity); |
|
|
|
|
128
|
3 |
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* material.transparent |
133
|
|
|
* |
134
|
|
|
* @param string $transparent |
135
|
|
|
* @return \AframeVR\Core\Helpers\MeshAttributes |
|
|
|
|
136
|
|
|
*/ |
137
|
3 |
|
public function transparent(string $transparent = 'false'): EntityInterface |
138
|
|
|
{ |
139
|
3 |
|
$this->component('Material')->transparent($transparent); |
|
|
|
|
140
|
3 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.