UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

89 lines (85 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaneHelper = void 0; var _Line = require("../objects/Line.js"); var _Mesh = require("../objects/Mesh.js"); var _LineBasicMaterial = require("../materials/LineBasicMaterial.js"); var _MeshBasicMaterial = require("../materials/MeshBasicMaterial.js"); var _BufferAttribute = require("../core/BufferAttribute.js"); var _BufferGeometry = require("../core/BufferGeometry.js"); /** * A helper object to visualize an instance of {@link Plane}. * * ```js * const plane = new THREE.Plane( new THREE.Vector3( 1, 1, 0.2 ), 3 ); * const helper = new THREE.PlaneHelper( plane, 1, 0xffff00 ); * scene.add( helper ); * ``` * * @augments Line */ class PlaneHelper extends _Line.Line { /** * Constructs a new plane helper. * * @param {Plane} plane - The plane to be visualized. * @param {number} [size=1] - The side length of plane helper. * @param {number|Color|string} [hex=0xffff00] - The helper's color. */ constructor(plane, size = 1, hex = 0xffff00) { const color = hex; const positions = [1, -1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0]; const geometry = new _BufferGeometry.BufferGeometry(); geometry.setAttribute('position', new _BufferAttribute.Float32BufferAttribute(positions, 3)); geometry.computeBoundingSphere(); super(geometry, new _LineBasicMaterial.LineBasicMaterial({ color: color, toneMapped: false })); this.type = 'PlaneHelper'; /** * The plane being visualized. * * @type {Plane} */ this.plane = plane; /** * The side length of plane helper. * * @type {number} * @default 1 */ this.size = size; const positions2 = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0]; const geometry2 = new _BufferGeometry.BufferGeometry(); geometry2.setAttribute('position', new _BufferAttribute.Float32BufferAttribute(positions2, 3)); geometry2.computeBoundingSphere(); this.add(new _Mesh.Mesh(geometry2, new _MeshBasicMaterial.MeshBasicMaterial({ color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false }))); } updateMatrixWorld(force) { this.position.set(0, 0, 0); this.scale.set(0.5 * this.size, 0.5 * this.size, 1); this.lookAt(this.plane.normal); this.translateZ(-this.plane.constant); super.updateMatrixWorld(force); } /** * Updates the helper to match the position and direction of the * light being visualized. */ dispose() { this.geometry.dispose(); this.material.dispose(); this.children[0].geometry.dispose(); this.children[0].material.dispose(); } } exports.PlaneHelper = PlaneHelper;