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
|
|
|
* Load component for this entity |
41
|
|
|
* |
42
|
|
|
* @param string $component_name |
43
|
|
|
* @throws \AframeVR\Core\Exceptions\BadComponentCallException |
44
|
|
|
* @return object|null |
45
|
|
|
*/ |
46
|
|
|
abstract public function component(string $component_name); |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* material.color |
50
|
|
|
* |
51
|
|
|
* @param string $color |
52
|
|
|
* @return EntityInterface |
53
|
|
|
*/ |
54
|
2 |
|
public function color(string $color = 'gray'): EntityInterface |
55
|
|
|
{ |
56
|
2 |
|
$this->component('Material') |
57
|
2 |
|
->shader() |
58
|
2 |
|
->color($color); |
59
|
2 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* material.metalness |
64
|
|
|
* |
65
|
|
|
* @param int|float $metalness |
66
|
|
|
* @return EntityInterface |
67
|
|
|
*/ |
68
|
|
|
public function metalness(float $metalness = 0): EntityInterface |
69
|
|
|
{ |
70
|
|
|
$this->component('Material') |
71
|
|
|
->shader() |
72
|
|
|
->metalness($metalness); |
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* material.roughness |
78
|
|
|
* |
79
|
|
|
* @param float $roughness |
80
|
|
|
* @return EntityInterface |
81
|
|
|
*/ |
82
|
|
|
public function roughness(float $roughness = 0.5): EntityInterface |
83
|
|
|
{ |
84
|
|
|
$this->component('Material') |
85
|
|
|
->shader() |
86
|
|
|
->roughness($roughness); |
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* material.src |
92
|
|
|
* |
93
|
|
|
* @param null|string $src |
94
|
|
|
* @return EntityInterface |
95
|
|
|
*/ |
96
|
|
|
public function src(string $src = null): EntityInterface |
97
|
|
|
{ |
98
|
|
|
$this->component('Material') |
99
|
|
|
->shader() |
100
|
|
|
->src($src); |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* geometry.translate |
106
|
|
|
* |
107
|
|
|
* @param int|float $x |
108
|
|
|
* @param int|float $y |
109
|
|
|
* @param int|float $z |
110
|
|
|
* @return EntityInterface |
111
|
|
|
*/ |
112
|
|
|
public function translate(float $x = 0, float $y = 0, float $z = 0): EntityInterface |
113
|
|
|
{ |
114
|
|
|
$this->component('Geometry')->translate($x, $y, $z); |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* material.shader |
120
|
|
|
* |
121
|
|
|
* @param string $shader |
122
|
|
|
* @return EntityInterface |
123
|
|
|
*/ |
124
|
|
|
public function shader($shader = 'standard'): EntityInterface |
125
|
|
|
{ |
126
|
|
|
$this->component('Material')->shader($shader); |
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* material.opacity |
132
|
|
|
* |
133
|
|
|
* @param float $opacity |
134
|
|
|
* @return EntityInterface |
135
|
|
|
*/ |
136
|
|
|
public function opacity(float $opacity = 1.0): EntityInterface |
137
|
|
|
{ |
138
|
|
|
$this->component('Material')->opacity($opacity); |
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* material.transparent |
144
|
|
|
* |
145
|
|
|
* @param bool $transparent |
146
|
|
|
* @return EntityInterface |
147
|
|
|
*/ |
148
|
2 |
|
public function transparent(bool $transparent = false): EntityInterface |
149
|
|
|
{ |
150
|
2 |
|
$this->component('Material')->transparent($transparent); |
151
|
2 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|