|
| 1 | +import NodeMaterial from './NodeMaterial.js'; |
| 2 | +import { MultiplyOperation, TangentSpaceNormalMap } from '../../../src/constants.js'; |
| 3 | +import { Vector2 } from '../../../src/math/Vector2.js'; |
| 4 | +import { Color } from '../../../src/math/Color.js'; |
| 5 | +import { Euler } from '../../../src/math/Euler.js'; |
| 6 | + |
| 7 | +import { |
| 8 | + shininess, specularColor, |
| 9 | + materialShininess, materialSpecular |
| 10 | +} from '../nodes/Nodes.js'; |
| 11 | + |
| 12 | +import PhongLightingModel from '../nodes/functions/PhongLightingModel.js'; |
| 13 | + |
| 14 | +class MeshPhongMaterial extends NodeMaterial { |
| 15 | + |
| 16 | + constructor( parameters ) { |
| 17 | + |
| 18 | + super(); |
| 19 | + |
| 20 | + this.isMeshPhongMaterial = true; |
| 21 | + |
| 22 | + this.color = new Color( 0xffffff ); // diffuse |
| 23 | + this.specular = new Color( 0x111111 ); |
| 24 | + this.shininess = 30; |
| 25 | + |
| 26 | + this.map = null; |
| 27 | + |
| 28 | + this.lightMap = null; |
| 29 | + this.lightMapIntensity = 1.0; |
| 30 | + |
| 31 | + this.aoMap = null; |
| 32 | + this.aoMapIntensity = 1.0; |
| 33 | + |
| 34 | + this.emissive = new Color( 0x000000 ); |
| 35 | + this.emissiveIntensity = 1.0; |
| 36 | + this.emissiveMap = null; |
| 37 | + |
| 38 | + this.bumpMap = null; |
| 39 | + this.bumpScale = 1; |
| 40 | + |
| 41 | + this.normalMap = null; |
| 42 | + this.normalMapType = TangentSpaceNormalMap; |
| 43 | + this.normalScale = new Vector2( 1, 1 ); |
| 44 | + |
| 45 | + this.displacementMap = null; |
| 46 | + this.displacementScale = 1; |
| 47 | + this.displacementBias = 0; |
| 48 | + |
| 49 | + this.specularMap = null; |
| 50 | + |
| 51 | + this.alphaMap = null; |
| 52 | + |
| 53 | + this.envMap = null; |
| 54 | + this.envMapRotation = new Euler(); |
| 55 | + this.combine = MultiplyOperation; |
| 56 | + this.reflectivity = 1; |
| 57 | + this.refractionRatio = 0.98; |
| 58 | + |
| 59 | + this.wireframe = false; |
| 60 | + this.wireframeLinewidth = 1; |
| 61 | + this.wireframeLinecap = 'round'; |
| 62 | + this.wireframeLinejoin = 'round'; |
| 63 | + |
| 64 | + this.flatShading = false; |
| 65 | + |
| 66 | + this.fog = true; |
| 67 | + |
| 68 | + this.lights = true; |
| 69 | + |
| 70 | + this.setValues( parameters ); |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + setupLightingModel( /*builder*/ ) { |
| 75 | + |
| 76 | + return new PhongLightingModel(); |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + setupVariants() { |
| 81 | + |
| 82 | + shininess.assign( materialShininess.max( 1e-4 ) ); // to prevent pow( 0.0, 0.0 ) ); |
| 83 | + specularColor.assign( materialSpecular ); |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + copy( source ) { |
| 88 | + |
| 89 | + super.copy( source ); |
| 90 | + |
| 91 | + this.color.copy( source.color ); |
| 92 | + this.specular.copy( source.specular ); |
| 93 | + this.shininess = source.shininess; |
| 94 | + |
| 95 | + this.map = source.map; |
| 96 | + |
| 97 | + this.lightMap = source.lightMap; |
| 98 | + this.lightMapIntensity = source.lightMapIntensity; |
| 99 | + |
| 100 | + this.aoMap = source.aoMap; |
| 101 | + this.aoMapIntensity = source.aoMapIntensity; |
| 102 | + |
| 103 | + this.emissive.copy( source.emissive ); |
| 104 | + this.emissiveMap = source.emissiveMap; |
| 105 | + this.emissiveIntensity = source.emissiveIntensity; |
| 106 | + |
| 107 | + this.bumpMap = source.bumpMap; |
| 108 | + this.bumpScale = source.bumpScale; |
| 109 | + |
| 110 | + this.normalMap = source.normalMap; |
| 111 | + this.normalMapType = source.normalMapType; |
| 112 | + this.normalScale.copy( source.normalScale ); |
| 113 | + |
| 114 | + this.displacementMap = source.displacementMap; |
| 115 | + this.displacementScale = source.displacementScale; |
| 116 | + this.displacementBias = source.displacementBias; |
| 117 | + |
| 118 | + this.specularMap = source.specularMap; |
| 119 | + |
| 120 | + this.alphaMap = source.alphaMap; |
| 121 | + |
| 122 | + this.envMap = source.envMap; |
| 123 | + this.envMapRotation.copy( source.envMapRotation ); |
| 124 | + this.combine = source.combine; |
| 125 | + this.reflectivity = source.reflectivity; |
| 126 | + this.refractionRatio = source.refractionRatio; |
| 127 | + |
| 128 | + this.wireframe = source.wireframe; |
| 129 | + this.wireframeLinewidth = source.wireframeLinewidth; |
| 130 | + this.wireframeLinecap = source.wireframeLinecap; |
| 131 | + this.wireframeLinejoin = source.wireframeLinejoin; |
| 132 | + |
| 133 | + this.flatShading = source.flatShading; |
| 134 | + |
| 135 | + this.fog = source.fog; |
| 136 | + |
| 137 | + return this; |
| 138 | + |
| 139 | + } |
| 140 | + |
| 141 | +} |
| 142 | + |
| 143 | +export default MeshPhongMaterial; |
0 commit comments