awv3
Version:
⚡ AWV3 embedded CAD
99 lines (72 loc) • 7.78 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _three = require('three');
var THREE = _interopRequireWildcard(_three);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MeshPhongMaterial = function (_THREE$MeshPhongMater) {
(0, _inherits3.default)(MeshPhongMaterial, _THREE$MeshPhongMater);
function MeshPhongMaterial(options) {
(0, _classCallCheck3.default)(this, MeshPhongMaterial);
var _this = (0, _possibleConstructorReturn3.default)(this, (MeshPhongMaterial.__proto__ || (0, _getPrototypeOf2.default)(MeshPhongMaterial)).call(this));
_this.type = 'AWV3.MeshPhongMaterial';
_this.fog = false;
_this.transparent = true;
_this.polygonOffset = true;
_this.polygonOffsetFactor = 1;
_this.polygonOffsetUnits = 1;
_this.uniforms = THREE.UniformsUtils.merge([THREE.UniformsLib['common'], THREE.UniformsLib['aomap'], THREE.UniformsLib['lightmap'], THREE.UniformsLib['emissivemap'], THREE.UniformsLib['bumpmap'], THREE.UniformsLib['normalmap'], THREE.UniformsLib['displacementmap'], THREE.UniformsLib['fog'], THREE.UniformsLib['lights'], {
"emissive": { type: "c", value: new THREE.Color(0x000000) },
"specular": { type: "c", value: new THREE.Color(0x111111) },
"shininess": { type: "1f", value: 30 },
"reflection": { type: "f", value: 1.0 },
"contrast": { type: "f", value: 0.0 },
"crosslight": { type: "f", value: 1.0 },
"intensity": { type: "f", value: 0.0 },
"flatspot": { type: "f", value: 0.0 }
}]);
_this.vertexShader = THREE.ShaderChunk['meshphong_vert'];
_this.fragmentShader = '\n #define PHONG\n\n uniform vec3 diffuse;\n uniform vec3 emissive;\n uniform vec3 specular;\n uniform float shininess;\n uniform float opacity;\n\n uniform float crosslight;\n uniform float reflection;\n uniform float contrast;\n uniform float intensity;\n uniform float flatspot;\n\n #include <common>\n #include <packing>\n #include <color_pars_fragment>\n #include <uv_pars_fragment>\n #include <uv2_pars_fragment>\n #include <map_pars_fragment>\n #include <alphamap_pars_fragment>\n #include <aomap_pars_fragment>\n #include <lightmap_pars_fragment>\n #include <emissivemap_pars_fragment>\n #include <envmap_pars_fragment>\n #include <fog_pars_fragment>\n #include <bsdfs>\n #include <lights_pars>\n #include <lights_phong_pars_fragment>\n #include <shadowmap_pars_fragment>\n #include <bumpmap_pars_fragment>\n #include <normalmap_pars_fragment>\n #include <specularmap_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n #include <clipping_planes_pars_fragment>\n\n void main() {\n\n \t#include <clipping_planes_fragment>\n\n vec3 eyeDirection = normalize(vViewPosition.xyz);\n vec3 reflectionDirection = reflect(eyeDirection, vNormal);\n float specularLightWeighting = dot(reflectionDirection, eyeDirection);\n float specularLightWeighting2 = dot(-reflectionDirection, eyeDirection);\n float directionalLightWeighting = max(dot(vNormal, eyeDirection), 1.0-reflection);\n vec3 lightWeighting = max(specularLightWeighting, directionalLightWeighting) + vec3(contrast) * specularLightWeighting;\n float crossLevel = crosslight > 0.0 ? dot(lightWeighting, crosslight * eyeDirection) : 1.0;\n float spot = 1.0;\n if (flatspot != 0.0) spot = dot(flatspot * reflectionDirection, eyeDirection) > 0.5 ? 1.4 : 1.0;\n\n vec4 diffuseColor = vec4(diffuse * crossLevel * spot + diffuse * intensity, opacity);\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n\n #include <logdepthbuf_fragment>\n \t#include <map_fragment>\n \t#include <color_fragment>\n \t#include <alphamap_fragment>\n \t#include <alphatest_fragment>\n \t#include <specularmap_fragment>\n \t#include <normal_flip>\n \t#include <normal_fragment>\n \t#include <emissivemap_fragment>\n\n \t// accumulation\n \t#include <lights_phong_fragment>\n \t#include <lights_template>\n\n \t// modulation\n \t#include <aomap_fragment>\n\n \tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\n \t#include <envmap_fragment>\n\n \tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\n \t#include <premultiplied_alpha_fragment>\n \t#include <tonemapping_fragment>\n \t#include <encodings_fragment>\n \t#include <fog_fragment>\n }';
_this.setValues(options);
return _this;
}
(0, _createClass3.default)(MeshPhongMaterial, [{
key: 'clone',
value: function clone() {
var material = new MeshPhongMaterial();
(0, _get3.default)(MeshPhongMaterial.prototype.__proto__ || (0, _getPrototypeOf2.default)(MeshPhongMaterial.prototype), 'clone', this).call(this, material);
material.color.copy(this.color);
material.fragmentShader = this.fragmentShader;
material.vertexShader = this.vertexShader;
material.uniforms = THREE.UniformsUtils.clone(this.uniforms);
material.attributes = this.attributes;
material.defines = this.defines;
material.shading = this.shading;
material.wireframe = this.wireframe;
material.wireframeLinewidth = this.wireframeLinewidth;
material.fog = this.fog;
material.lights = this.lights;
material.vertexColors = this.vertexColors;
material.skinning = this.skinning;
material.morphTargets = this.morphTargets;
material.morphNormals = this.morphNormals;
return material;
}
}]);
return MeshPhongMaterial;
}(THREE.MeshPhongMaterial);
exports.default = MeshPhongMaterial;