UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

119 lines (111 loc) 3.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.cubeTexture = void 0; var _TextureNode = _interopRequireDefault(require("./TextureNode.js")); var _ReflectVector = require("./ReflectVector.js"); var _TSLBase = require("../tsl/TSLBase.js"); var _constants = require("../../constants.js"); var _MaterialProperties = require("./MaterialProperties.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * This type of uniform node represents a cube texture. * * @augments TextureNode */ class CubeTextureNode extends _TextureNode.default { static get type() { return 'CubeTextureNode'; } /** * Constructs a new cube texture node. * * @param {CubeTexture} value - The cube texture. * @param {?Node<vec3>} [uvNode=null] - The uv node. * @param {?Node<int>} [levelNode=null] - The level node. * @param {?Node<float>} [biasNode=null] - The bias node. */ constructor(value, uvNode = null, levelNode = null, biasNode = null) { super(value, uvNode, levelNode, biasNode); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isCubeTextureNode = true; } /** * Overwrites the default implementation to return a fixed value `'cubeTexture'`. * * @param {NodeBuilder} builder - The current node builder. * @return {string} The input type. */ getInputType( /*builder*/ ) { return 'cubeTexture'; } /** * Returns a default uvs based on the mapping type of the cube texture. * * @return {Node<vec3>} The default uv attribute. */ getDefaultUV() { const texture = this.value; if (texture.mapping === _constants.CubeReflectionMapping) { return _ReflectVector.reflectVector; } else if (texture.mapping === _constants.CubeRefractionMapping) { return _ReflectVector.refractVector; } else { console.error('THREE.CubeTextureNode: Mapping "%s" not supported.', texture.mapping); return (0, _TSLBase.vec3)(0, 0, 0); } } /** * Overwritten with an empty implementation since the `updateMatrix` flag is ignored * for cube textures. The uv transformation matrix is not applied to cube textures. * * @param {boolean} value - The update toggle. */ setUpdateMatrix( /*updateMatrix*/) {} // Ignore .updateMatrix for CubeTextureNode /** * Setups the uv node. Depending on the backend as well as the texture type, it might be necessary * to modify the uv node for correct sampling. * * @param {NodeBuilder} builder - The current node builder. * @param {Node} uvNode - The uv node to setup. * @return {Node} The updated uv node. */ setupUV(builder, uvNode) { const texture = this.value; if (builder.renderer.coordinateSystem === _constants.WebGPUCoordinateSystem || !texture.isRenderTargetTexture) { uvNode = (0, _TSLBase.vec3)(uvNode.x.negate(), uvNode.yz); } return _MaterialProperties.materialEnvRotation.mul(uvNode); } /** * Generates the uv code snippet. * * @param {NodeBuilder} builder - The current node builder. * @param {Node} cubeUV - The uv node to generate code for. * @return {string} The generated code snippet. */ generateUV(builder, cubeUV) { return cubeUV.build(builder, 'vec3'); } } var _default = exports.default = CubeTextureNode; /** * TSL function for creating a cube texture node. * * @tsl * @function * @param {CubeTexture} value - The cube texture. * @param {?Node<vec3>} [uvNode=null] - The uv node. * @param {?Node<int>} [levelNode=null] - The level node. * @param {?Node<float>} [biasNode=null] - The bias node. * @returns {CubeTextureNode} */ const cubeTexture = exports.cubeTexture = /*@__PURE__*/(0, _TSLBase.nodeProxy)(CubeTextureNode).setParameterLength(1, 4).setName('cubeTexture');