1 | import { Line } from '../objects/Line.js';
|
2 | import { Mesh } from '../objects/Mesh.js';
|
3 | import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
4 | import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
5 | import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
6 | import { BufferGeometry } from '../core/BufferGeometry.js';
|
7 | import { FrontSide, BackSide } from '../constants.js';
|
8 |
|
9 | class PlaneHelper extends Line {
|
10 |
|
11 | constructor( plane, size = 1, hex = 0xffff00 ) {
|
12 |
|
13 | const color = hex;
|
14 |
|
15 | const positions = [ 1, - 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ];
|
16 |
|
17 | const geometry = new BufferGeometry();
|
18 | geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
19 | geometry.computeBoundingSphere();
|
20 |
|
21 | super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
|
22 |
|
23 | this.type = 'PlaneHelper';
|
24 |
|
25 | this.plane = plane;
|
26 |
|
27 | this.size = size;
|
28 |
|
29 | const positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
|
30 |
|
31 | const geometry2 = new BufferGeometry();
|
32 | geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
|
33 | geometry2.computeBoundingSphere();
|
34 |
|
35 | this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
|
36 |
|
37 | }
|
38 |
|
39 | updateMatrixWorld( force ) {
|
40 |
|
41 | let scale = - this.plane.constant;
|
42 |
|
43 | if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8;
|
44 |
|
45 | this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
|
46 |
|
47 | this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide;
|
48 |
|
49 | this.lookAt( this.plane.normal );
|
50 |
|
51 | super.updateMatrixWorld( force );
|
52 |
|
53 | }
|
54 |
|
55 | }
|
56 |
|
57 | export { PlaneHelper };
|