1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 2:19:19 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 Flat.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 Flat extends ShaderAbstract implements ShaderInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Base diffuse color. |
34
|
|
|
* |
35
|
|
|
* @var string $color |
36
|
|
|
*/ |
37
|
|
|
public $color = '#fff'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Whether or not material is affected by fog. |
41
|
|
|
* |
42
|
|
|
* @var string $fog |
43
|
|
|
*/ |
44
|
|
|
public $fog = 'true'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Height of video (in pixels), if defining a video texture. |
48
|
|
|
* |
49
|
|
|
* @var int $height |
50
|
|
|
*/ |
51
|
|
|
public $height = 360; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* How many times a texture (defined by src) repeats in the X and Y direction. |
55
|
|
|
* |
56
|
|
|
* @var string $repeat |
57
|
|
|
*/ |
58
|
|
|
public $repeat = '1 1'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Image or video texture map. |
62
|
|
|
* Can either be a selector to an <img> or <video>, or an inline URL. |
63
|
|
|
* |
64
|
|
|
* @var string|null $src |
65
|
|
|
*/ |
66
|
|
|
public $src = null; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Width of video (in pixels), if defining a video texture. |
70
|
|
|
* |
71
|
|
|
* @var int $width |
72
|
|
|
*/ |
73
|
|
|
public $width = 640; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Base diffuse color |
77
|
|
|
* |
78
|
|
|
* @param string $color |
79
|
|
|
*/ |
80
|
1 |
|
public function color(string $color = '#fff') |
81
|
|
|
{ |
82
|
1 |
|
$this->color = $color; |
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Whether or not material is affected by fog. |
87
|
|
|
* |
88
|
|
|
* @param bool $fog |
89
|
|
|
*/ |
90
|
1 |
|
public function fog(bool $fog = true) |
91
|
|
|
{ |
92
|
1 |
|
$this->fog = $fog ? 'true' : 'false'; |
93
|
1 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Height of video (in pixels), if defining a video texture. |
97
|
|
|
* |
98
|
|
|
* @param int $height |
99
|
|
|
*/ |
100
|
1 |
|
public function height(int $height = 360) |
101
|
|
|
{ |
102
|
1 |
|
$this->height = $height; |
103
|
1 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* |
107
|
|
|
* @param int|float $x |
108
|
|
|
* @param int|float $y |
109
|
|
|
*/ |
110
|
1 |
|
public function repeat(float $x = 1, float $y = 1) |
111
|
|
|
{ |
112
|
1 |
|
$this->repeat = sprintf('%d %d', $x, $y); |
113
|
1 |
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* How many times a texture (defined by src) repeats in the X and Y direction. |
117
|
|
|
* |
118
|
|
|
* @param null|string $src |
119
|
|
|
*/ |
120
|
1 |
|
public function src(string $src = null) |
121
|
|
|
{ |
122
|
1 |
|
$this->src = $src; |
123
|
1 |
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Width of video (in pixels), if defining a video texture. |
127
|
|
|
* |
128
|
|
|
* @param int $width |
129
|
|
|
*/ |
130
|
1 |
|
public function width(int $width = 360) |
131
|
|
|
{ |
132
|
1 |
|
$this->width = $width; |
133
|
1 |
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* removeDefaultDOMAttributes |
137
|
|
|
* |
138
|
|
|
* @return void |
139
|
|
|
*/ |
140
|
1 |
View Code Duplication |
public function removeDefaultDOMAttributes() |
|
|
|
|
141
|
|
|
{ |
142
|
1 |
|
$defaults = $this->getShaderClassDefaultVars(); |
143
|
1 |
|
foreach ($this as $name => $value) { |
|
|
|
|
144
|
1 |
|
if (empty($value) || $value === $defaults[$name]) |
145
|
1 |
|
unset($this->$name); |
146
|
|
|
} |
147
|
1 |
|
} |
148
|
|
|
} |
149
|
|
|
|
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.