UNPKG

rl-loadout-lib

Version:

Load Rocket League assets into three.js

73 lines (71 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const extended_mesh_standard_material_1 = require("./extended-mesh-standard-material"); const three_1 = require("three"); const UNIFORMS = ` uniform vec3 paintColor; uniform int painted; uniform int colorOnly; `; const DIFFUSE_SHADER = ` // Look up a color from the texture. if (colorOnly == 0) { vec4 texelColor = texture2D(map, vUv); vec4 normalMapColor = texture2D(normalMap, vUv);; // paint if (painted == 1) { texelColor.rgb = blendNormal(texelColor.rgb, paintColor.rgb, mask); } texelColor = mapTexelToLinear(texelColor); diffuseColor *= texelColor; } `; class TireMaterial extends extended_mesh_standard_material_1.ExtendedMeshStandardMaterial { constructor(maskChannel, useN = false, invertMask = false) { super(); this.maskChannel = maskChannel; this.useN = useN; this.invertMask = invertMask; this.fragmentShader = extended_mesh_standard_material_1.ExtendedMeshStandardMaterial.createFragmentShader(UNIFORMS, DIFFUSE_SHADER.replace('mask', `${invertMask ? '1.0 - ' : ''}${useN ? 'normalMapColor' : 'texelColor'}.${maskChannel}`)); this.uniforms.paintColor = { value: new three_1.Color() }; this.uniforms.painted = { value: 0 }; } get color() { return this.uniforms.color.value; } set color(color) { this.uniforms.color.value = color; } get paintColor() { return this.uniforms.paintColor.value; } set paintColor(paintColor) { if (paintColor != undefined) { this.uniforms.paintColor.value.copy(paintColor); this.uniforms.painted.value = 1; } else { this.uniforms.painted.value = 0; } } get colorOnly() { return this.uniforms.colorOnly.value === 1; } set colorOnly(colorOnly) { this.uniforms.colorOnly.value = colorOnly ? 1 : 0; } } exports.TireMaterial = TireMaterial; class UnpaintableTireMaterial extends TireMaterial { constructor() { super('a'); } get paintColor() { return undefined; } set paintColor(paintColor) { super.paintColor = undefined; } } exports.UnpaintableTireMaterial = UnpaintableTireMaterial; //# sourceMappingURL=tire-material.js.map