@@ -2,8 +2,8 @@ import { GridHelper, Vector3 } from "three";
22import { Line2 } from "three/examples/jsm/lines/Line2" ;
33import { LineGeometry } from "three/examples/jsm/lines/LineGeometry" ;
44import { LineMaterial } from "three/examples/jsm/lines/LineMaterial" ;
5- import { AxesConfig , AxisConfig } from "./axes.config" ;
6- import { AxesParams , AxisParams } from "./axes.params" ;
5+ import { AxesConfig , AxisConfig , GridConfig } from "./axes.config" ;
6+ import { AxesParams , AxisParams , GridParams } from "./axes.params" ;
77import { Framed } from "./plot" ;
88import { Label , LabelProperties } from "./label" ;
99
@@ -28,7 +28,12 @@ export const NamedAxis = {
2828export class Axis extends Line2 {
2929 config : AxisConfig ;
3030
31- constructor ( direction : Vector3 , private length : number , params : AxisParams , public axisIdentifier : keyof typeof NamedAxis ) {
31+ constructor (
32+ direction : Vector3 ,
33+ private length : number ,
34+ params : AxisParams ,
35+ public axisIdentifier : keyof typeof NamedAxis
36+ ) {
3237 const points = [ new Vector3 ( ) , direction . clone ( ) . multiplyScalar ( length ) ] ;
3338
3439 const geometry = new LineGeometry ( ) ;
@@ -51,17 +56,22 @@ export class Axis extends Line2 {
5156}
5257
5358export class Axes extends Framed {
54- public gridXZ : GridHelper ;
55- public gridXY : GridHelper ;
56- public gridYZ : GridHelper ;
57- private config : AxesConfig ;
58-
59- constructor ( private lengthX : number , private lengthY : number , private lengthZ : number , options ?: AxesParams ) {
59+ private axesConfig : AxesConfig ;
60+ private gridsConfig : GridConfig ;
61+
62+ constructor (
63+ private lengthX : number ,
64+ private lengthY : number ,
65+ private lengthZ : number ,
66+ axesParams ?: AxesParams ,
67+ gridsParams ?: GridParams
68+ ) {
6069 super ( ) ;
6170
62- this . config = new AxesConfig ( options ) ;
71+ this . axesConfig = new AxesConfig ( axesParams ) ;
72+ this . gridsConfig = new GridConfig ( gridsParams ) ;
6373
64- const { x, y, z } = this . config ;
74+ const { x, y, z } = this . axesConfig ;
6575
6676 if ( x ) {
6777 const xAxis = new Axis ( NamedAxis . x . unit , lengthX * 1.1 , x , NamedAxis . x . name ) ;
@@ -83,18 +93,27 @@ export class Axes extends Framed {
8393 }
8494
8595 private setGrids ( ) {
86- this . gridXZ = new GridHelper ( Math . max ( this . lengthX , this . lengthZ ) ) ;
87- this . gridXZ . position . setX ( this . lengthX / 2 ) ;
88- this . gridXZ . position . setZ ( this . lengthZ / 2 ) ;
89-
90- this . gridXY = new GridHelper ( Math . max ( this . lengthX , this . lengthY ) ) ;
91- this . gridXY . position . setX ( this . lengthX / 2 ) ;
92- this . gridXY . position . setY ( this . lengthY / 2 ) ;
93- this . gridXY . rotateOnAxis ( NamedAxis . x . unit , Math . PI / 2 ) ;
94-
95- this . gridYZ = new GridHelper ( Math . max ( this . lengthY , this . lengthZ ) ) ;
96- this . gridYZ . position . setY ( this . lengthY / 2 ) ;
97- this . gridYZ . position . setZ ( this . lengthZ / 2 ) ;
98- this . gridYZ . rotateOnAxis ( NamedAxis . z . unit , Math . PI / 2 ) ;
96+ if ( this . gridsConfig . xz ) {
97+ const gridXZ = new GridHelper ( Math . max ( this . lengthX , this . lengthZ ) ) ;
98+ gridXZ . position . setX ( this . lengthX / 2 ) ;
99+ gridXZ . position . setZ ( this . lengthZ / 2 ) ;
100+ this . drawables . push ( gridXZ ) ;
101+ }
102+
103+ if ( this . gridsConfig . xy ) {
104+ const gridXY = new GridHelper ( Math . max ( this . lengthX , this . lengthY ) ) ;
105+ gridXY . position . setX ( this . lengthX / 2 ) ;
106+ gridXY . position . setY ( this . lengthY / 2 ) ;
107+ gridXY . rotateOnAxis ( NamedAxis . x . unit , Math . PI / 2 ) ;
108+ this . drawables . push ( gridXY ) ;
109+ }
110+
111+ if ( this . gridsConfig . yz ) {
112+ const gridYZ = new GridHelper ( Math . max ( this . lengthY , this . lengthZ ) ) ;
113+ gridYZ . position . setY ( this . lengthY / 2 ) ;
114+ gridYZ . position . setZ ( this . lengthZ / 2 ) ;
115+ gridYZ . rotateOnAxis ( NamedAxis . z . unit , Math . PI / 2 ) ;
116+ this . drawables . push ( gridYZ ) ;
117+ }
99118 }
100119}
0 commit comments