MeshAttributes::shader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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 or set it's attr
41
     *
42
     * @param string $component_name
43
     * @param null|string $attr_data
44
     * @throws \AframeVR\Core\Exceptions\BadComponentCallException
45
     * @return object|null
46
     */
47
    abstract public function attr(string $component_name, string $attr_data = null);
48
49
    /**
50
     * material.color
51
     *
52
     * @param string $color            
53
     * @return EntityInterface
54
     */
55 11
    public function color(string $color): EntityInterface
56
    {
57 11
        $this->attr('Material')
58 11
            ->shader()
59 11
            ->color($color);
60 11
        return $this;
61
    }
62
63
    /**
64
     * material.metalness
65
     *
66
     * @param int|float $metalness            
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $metalness a bit more specific; maybe use double.
Loading history...
67
     * @return EntityInterface
68
     */
69 2
    public function metalness(float $metalness): EntityInterface
70
    {
71 2
        $this->attr('Material')
72 2
            ->shader()
73 2
            ->metalness($metalness);
74 2
        return $this;
75
    }
76
77
    /**
78
     * material.opacity
79
     *
80
     * @param float $opacity
81
     * @return EntityInterface
82
     */
83 2
    public function opacity(float $opacity): EntityInterface
84
    {
85 2
        $this->attr('Material')->opacity($opacity);
86 2
        return $this;
87
    }
88
    
89
    /**
90
     * material.repeat
91
     * 
92
     * @param float $x
93
     * @param float $y
94
     * 
95
     * @return EntityInterface
96
     */
97 3
    public function repeat(float $x, float $y): EntityInterface
98
    {
99 3
        $this->attr('Material')->repeat($x, $y);
100 3
        return $this;
101
    }
102
    
103
    /**
104
     * material.roughness
105
     *
106
     * @param float $roughness            
107
     * @return EntityInterface
108
     */
109 2
    public function roughness(float $roughness): EntityInterface
110
    {
111 2
        $this->attr('Material')
112 2
            ->shader()
113 2
            ->roughness($roughness);
114 2
        return $this;
115
    }
116
117
    /**
118
     * material.shader
119
     *
120
     * @param string $shader
121
     * @return EntityInterface
122
     */
123 2
    public function shader($shader): EntityInterface
124
    {
125 2
        $this->attr('Material')->shader($shader);
126 2
        return $this;
127
    }
128
    
129
    
130
    /**
131
     * material.src
132
     *
133
     * @param null|string $src            
134
     * @return EntityInterface
135
     */
136 2
    public function src(string $src = null): EntityInterface
137
    {
138 2
        $this->attr('Material')
139 2
            ->shader()
140 2
            ->src($src);
141 2
        return $this;
142
    }
143
144
    /**
145
     * material.transparent
146
     *
147
     * @param bool $transparent            
148
     * @return EntityInterface
149
     */
150 6
    public function transparent(bool $transparent = false): EntityInterface
151
    {
152 6
        $this->attr('Material')->transparent($transparent);
153 6
        return $this;
154
    }
155
}
156