@openhps/core
Version:
Open Hybrid Positioning System - Core component
65 lines (61 loc) • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.frontFacing = exports.faceDirection = exports.default = void 0;
var _Node = _interopRequireDefault(require("../core/Node.js"));
var _TSLBase = require("../tsl/TSLBase.js");
var _constants = require("../../constants.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* This node can be used to evaluate whether a primitive is front or back facing.
*
* @augments Node
*/
class FrontFacingNode extends _Node.default {
static get type() {
return 'FrontFacingNode';
}
/**
* Constructs a new front facing node.
*/
constructor() {
super('bool');
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isFrontFacingNode = true;
}
generate(builder) {
const {
renderer,
material
} = builder;
if (renderer.coordinateSystem === _constants.WebGLCoordinateSystem) {
if (material.side === _constants.BackSide) {
return 'false';
}
}
return builder.getFrontFacing();
}
}
var _default = exports.default = FrontFacingNode;
/**
* TSL object that represents whether a primitive is front or back facing
*
* @tsl
* @type {FrontFacingNode<bool>}
*/
const frontFacing = exports.frontFacing = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(FrontFacingNode);
/**
* TSL object that represents the front facing status as a number instead of a bool.
* `1` means front facing, `-1` means back facing.
*
* @tsl
* @type {Node<float>}
*/
const faceDirection = exports.faceDirection = /*@__PURE__*/(0, _TSLBase.float)(frontFacing).mul(2.0).sub(1.0);