This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 155
/
ShaderMaterialDescriptor.js
68 lines (51 loc) · 1.62 KB
/
ShaderMaterialDescriptor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as THREE from 'three';
import PropTypes from 'prop-types';
import MaterialDescriptorBase from './MaterialDescriptorBase';
import UniformContainer from '../../UniformContainer';
class ShaderMaterialDescriptor extends MaterialDescriptorBase {
constructor(react3RendererInstance) {
super(react3RendererInstance);
[
'vertexShader',
'fragmentShader',
].forEach((propName) => {
this.hasProp(propName, {
type: PropTypes.string,
update: this.triggerRemount,
});
});
this.hasProp('uniforms', {
type: PropTypes.any,
simple: true,
default: undefined,
});
this.hasWireframe();
}
getMaterialDescription(props) {
const materialDescription = super.getMaterialDescription(props);
if (props.hasOwnProperty('uniforms')) {
materialDescription.uniforms = props.uniforms;
}
if (props.hasOwnProperty('vertexShader')) {
materialDescription.vertexShader = props.vertexShader;
}
if (props.hasOwnProperty('fragmentShader')) {
materialDescription.fragmentShader = props.fragmentShader;
}
return materialDescription;
}
construct(props) {
const materialDescription = this.getMaterialDescription(props);
return new THREE.ShaderMaterial(materialDescription);
}
invalidChildInternal(child) {
return !(child instanceof UniformContainer || super.invalidChildInternal(child));
}
applyInitialProps(threeObject, props) {
super.applyInitialProps(threeObject, props);
if (!props.hasOwnProperty('uniforms')) {
threeObject.uniforms = {};
}
}
}
module.exports = ShaderMaterialDescriptor;