Completed
Push — master ( c59f6c...f3d74b )
by Marko
02:18
created

Standard::defaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 21, 2016 - 1:53:21 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         Standard.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\Shaders;
25
26
use \AframeVR\Interfaces\ShaderInterface;
27
use \AframeVR\Core\Helpers\ShaderAbstract;
28
29
class Standard extends ShaderAbstract implements ShaderInterface
30
{
31
32
    /**
33
     * Base diffuse color.
34
     *
35
     * @var string $color
36
     */
37
    protected $color = '#fff';
38
39
    /**
40
     * Height of video (in pixels), if defining a video texture.
41
     *
42
     * @var int $height
43
     */
44
    protected $height = 360;
45
46
    /**
47
     * Environment cubemap texture for reflections.
48
     *
49
     * Can be a selector to or a comma-separated list of URLs.
50
     *
51
     * @var string|null $envMap
52
     */
53
    protected $envMap = null;
54
55
    /**
56
     * Whether or not material is affected by fog.
57
     *
58
     * @var string $fog
59
     */
60
    protected $fog = 'true';
61
62
    /**
63
     * How metallic the material is from 0 to 1.
64
     *
65
     * @var float $metalness
66
     */
67
    protected $metalness = 0.5;
68
69
    /**
70
     * How many times a texture (defined by src) repeats in the X and Y direction.
71
     *
72
     * @var string $repeat
73
     */
74
    protected $repeat = '1 1';
75
76
    /**
77
     * How rough the material is from 0 to 1.
78
     * A rougher material will scatter
79
     * reflected light in more directions than a smooth material.
80
     *
81
     * @var float $roughness
82
     */
83
    protected $roughness = 0.5;
84
85
    /**
86
     * Image or video texture map.
87
     * Can either be a selector to an <img> or <video>, or an inline URL.
88
     *
89
     * @var string|null $src
90
     */
91
    protected $src = null;
92
93
    /**
94
     * Width of video (in pixels), if defining a video texture.
95
     *
96
     * @var int $width
97
     */
98
    protected $width = 640;
99
100
    /**
101
     * Set shader defaults
102
     *
103
     * @return void
104
     */
105 1
    public function defaults()
106
    {
107 1
        $this->color('#fff');
108 1
        $this->height(360);
109 1
        $this->envMap();
110 1
        $this->fog(true);
111 1
        $this->metalness(0.5);
112 1
        $this->repeat(1, 1);
113 1
        $this->roughness(0.5);
114 1
        $this->src();
115 1
        $this->width(640);
116 1
    }
117
    
118
    /**
119
     * Base diffuse color
120
     *
121
     * @param string $color            
122
     */
123 12
    public function color(string $color)
124
    {
125 12
        $this->color = $color;
126 12
    }
127
128
    /**
129
     * Height of video (in pixels), if defining a video texture.
130
     *
131
     * @param int $height            
132
     */
133 2
    public function height($height)
134
    {
135 2
        $this->height = $height;
136 2
    }
137
138
    /**
139
     * envMap
140
     *
141
     * Environment cubemap texture for reflections.
142
     * Can be a selector to or a comma-separated list of URLs.
143
     *
144
     * @param string|null $envMap            
145
     */
146 2
    public function envMap(string $envMap = null)
147
    {
148 2
        $this->envMap = $envMap;
149 2
    }
150
151
    /**
152
     * Whether or not material is affected by fog.
153
     *
154
     * @param bool $fog            
155
     */
156 2
    public function fog($fog)
157
    {
158 2
        $this->fog = $fog ? 'true' : 'false';
159 2
    }
160
161
    /**
162
     * How metallic the material is from 0 to 1.
163
     *
164
     * @param float $metalness            
165
     */
166 7
    public function metalness($metalness)
167
    {
168 7
        $this->metalness = $metalness;
169 7
    }
170
171
    /**
172
     * repeat
173
     *
174
     * @param float $x            
175
     * @param float $y            
176
     */
177 2
    public function repeat(float $x, float $y)
178
    {
179 2
        $this->repeat = sprintf('%d %d', $x, $y);
180 2
    }
181
182
    /**
183
     * How rough the material is from 0 to 1
184
     *
185
     * A rougher material will scatter reflected light in more directions than a smooth material.
186
     *
187
     * @param float $roughness            
188
     */
189 7
    public function roughness(float $roughness)
190
    {
191 7
        $this->roughness = $roughness;
192 7
    }
193
194
    /**
195
     * How many times a texture (defined by src) repeats in the X and Y direction.
196
     *
197
     * @param string|null $src            
198
     */
199 8
    public function src(string $src = null)
200
    {
201 8
        $this->src = $src;
202 8
    }
203
204
    /**
205
     * Width of video (in pixels), if defining a video texture.
206
     *
207
     * @param int $width            
208
     */
209 2
    public function width(int $width)
210
    {
211 2
        $this->width = $width;
212 2
    }
213
}
214