hpg-r3f-model-scene
Version:
Pretty Footer react component used in ant.design
186 lines (185 loc) • 12.6 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MaterialLoader = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _three = require("three");
var MaterialLoader = /*#__PURE__*/function () {
function MaterialLoader() {
(0, _classCallCheck2.default)(this, MaterialLoader);
this.textures = void 0;
this.textures = {};
}
(0, _createClass2.default)(MaterialLoader, [{
key: "parse",
value: function parse(json1) {
var _this = this;
var json = JSON.parse(json1);
var getTexture = function getTexture(name) {
if (_this.textures[name] === undefined) {
console.warn('THREE.MaterialLoader: Undefined texture', name);
}
return _this.textures[name];
};
var material = MaterialLoader.createMaterialFromType(json.type);
if (json.uuid !== undefined) material.uuid = json.uuid;
if (json.name !== undefined) material.name = json.name;
if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
if (json.roughness !== undefined) material.roughness = json.roughness;
if (json.metalness !== undefined) material.metalness = json.metalness;
if (json.sheen !== undefined) material.sheen = json.sheen;
if (json.sheenColor !== undefined) material.sheenColor = new _three.Color().setHex(json.sheenColor);
if (json.sheenRoughness !== undefined) material.sheenRoughness = json.sheenRoughness;
if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
if (json.specularIntensity !== undefined) material.specularIntensity = json.specularIntensity;
if (json.specularColor !== undefined && material.specularColor !== undefined) material.specularColor.setHex(json.specularColor);
if (json.shininess !== undefined) material.shininess = json.shininess;
if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
if (json.iridescence !== undefined) material.iridescence = json.iridescence;
if (json.iridescenceIOR !== undefined) material.iridescenceIOR = json.iridescenceIOR;
if (json.iridescenceThicknessRange !== undefined) material.iridescenceThicknessRange = json.iridescenceThicknessRange;
if (json.transmission !== undefined) material.transmission = json.transmission;
if (json.thickness !== undefined) material.thickness = json.thickness;
if (json.attenuationDistance !== undefined) material.attenuationDistance = json.attenuationDistance;
if (json.attenuationColor !== undefined && material.attenuationColor !== undefined) material.attenuationColor.setHex(json.attenuationColor);
if (json.fog !== undefined) material.fog = json.fog;
if (json.flatShading !== undefined) material.flatShading = json.flatShading;
if (json.blending !== undefined) material.blending = json.blending;
if (json.combine !== undefined) material.combine = json.combine;
if (json.side !== undefined) material.side = json.side;
if (json.shadowSide !== undefined) material.shadowSide = json.shadowSide;
if (json.opacity !== undefined) material.opacity = json.opacity;
if (json.transparent !== undefined) material.transparent = json.transparent;
if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
if (json.depthTest !== undefined) material.depthTest = json.depthTest;
if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
if (json.wireframe !== undefined) material.wireframe = json.wireframe;
if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
if (json.rotation !== undefined) material.rotation = json.rotation;
if (json.linewidth !== 1) material.linewidth = json.linewidth;
if (json.dashSize !== undefined) material.dashSize = json.dashSize;
if (json.gapSize !== undefined) material.gapSize = json.gapSize;
if (json.scale !== undefined) material.scale = json.scale;
if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
if (json.dithering !== undefined) material.dithering = json.dithering;
if (json.alphaToCoverage !== undefined) material.alphaToCoverage = json.alphaToCoverage;
if (json.premultipliedAlpha !== undefined) material.premultipliedAlpha = json.premultipliedAlpha;
if (json.forceSinglePass !== undefined) material.forceSinglePass = json.forceSinglePass;
if (json.visible !== undefined) material.visible = json.visible;
if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
if (json.userData !== undefined) material.userData = json.userData;
if (json.vertexColors !== undefined) {
if (typeof json.vertexColors === 'number') {
material.vertexColors = json.vertexColors > 0 ? true : false;
} else {
material.vertexColors = json.vertexColors;
}
}
if (json.defines !== undefined) material.defines = json.defines;
if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
if (json.glslVersion !== undefined) material.glslVersion = json.glslVersion;
if (json.extensions !== undefined) {
for (var key in json.extensions) {
material.extensions[key] = json.extensions[key];
}
}
if (json.lights !== undefined) material.lights = json.lights;
if (json.clipping !== undefined) material.clipping = json.clipping;
// for PointsMaterial
if (json.size !== undefined) material.size = json.size;
if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation;
// maps
if (json.map !== undefined) material.map = getTexture(json.map);
if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
if (json.normalScale !== undefined) {
var normalScale = json.normalScale;
if (Array.isArray(normalScale) === false) {
// Blender exporter used to export a scalar. See #7459
normalScale = [normalScale, normalScale];
}
material.normalScale = new _three.Vector2().fromArray(normalScale);
}
if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
if (json.specularIntensityMap !== undefined) material.specularIntensityMap = getTexture(json.specularIntensityMap);
if (json.specularColorMap !== undefined) material.specularColorMap = getTexture(json.specularColorMap);
if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new _three.Vector2().fromArray(json.clearcoatNormalScale);
if (json.iridescenceMap !== undefined) material.iridescenceMap = getTexture(json.iridescenceMap);
if (json.iridescenceThicknessMap !== undefined) material.iridescenceThicknessMap = getTexture(json.iridescenceThicknessMap);
if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
if (json.thicknessMap !== undefined) material.thicknessMap = getTexture(json.thicknessMap);
if (json.sheenColorMap !== undefined) material.sheenColorMap = getTexture(json.sheenColorMap);
if (json.sheenRoughnessMap !== undefined) material.sheenRoughnessMap = getTexture(json.sheenRoughnessMap);
return material;
}
}], [{
key: "createMaterialFromType",
value: function createMaterialFromType(type) {
var materialLib = {
ShadowMaterial: _three.ShadowMaterial,
SpriteMaterial: _three.SpriteMaterial,
RawShaderMaterial: _three.RawShaderMaterial,
ShaderMaterial: _three.ShaderMaterial,
PointsMaterial: _three.PointsMaterial,
MeshPhysicalMaterial: _three.MeshPhysicalMaterial,
MeshStandardMaterial: _three.MeshStandardMaterial,
MeshPhongMaterial: _three.MeshPhongMaterial,
MeshToonMaterial: _three.MeshToonMaterial,
MeshNormalMaterial: _three.MeshNormalMaterial,
MeshLambertMaterial: _three.MeshLambertMaterial,
MeshDepthMaterial: _three.MeshDepthMaterial,
MeshDistanceMaterial: _three.MeshDistanceMaterial,
MeshBasicMaterial: _three.MeshBasicMaterial,
MeshMatcapMaterial: _three.MeshMatcapMaterial,
LineDashedMaterial: _three.LineDashedMaterial,
LineBasicMaterial: _three.LineBasicMaterial,
Material: _three.Material
};
return new materialLib[type]();
}
}]);
return MaterialLoader;
}();
exports.MaterialLoader = MaterialLoader;