UNPKG

awv3

Version:
47 lines (40 loc) 1.42 kB
import * as THREE from 'three'; import InfinitePlane from '../../../three/infiniteplane'; import BaseGraphics from './base'; const LinesCount = 1e3; export default class Sketch extends BaseGraphics { constructor() { super(); this.measurable = false; this.step = undefined; this.grid = undefined; this.axes = undefined; this.plane = new InfinitePlane(); this.plane.plane.normal.set(0, 0, 1); this.add(this.plane); } update(newStep) { if (newStep !== this.step) { this.step = newStep; if (this.grid) { this.remove(this.grid); this.grid.geometry.dispose(); } this.grid = new THREE.GridHelper(newStep * LinesCount, LinesCount, 0x9f9f9f, 0xcfcfcf); this.grid.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), new THREE.Vector3(0, 1, 0)); this.grid.interactive = false; this.add(this.grid); if (this.axes) { this.remove(this.axes); this.axes.geometry.dispose(); } this.axes = new THREE.AxisHelper(newStep * 5); this.axes.position.z = 1e-3 * newStep; this.axes.interactive = false; this.add(this.axes); } } updateFromSketcherAndId(sketcher, id) { this.update(sketcher.gridStep); } }