|
| 1 | +import * as THREE from "three"; |
| 2 | +import { |
| 3 | + BooleanSettingsControl, |
| 4 | + ColorSettingsControl, |
| 5 | + NumberSettingControl, |
| 6 | +} from "../../Types"; |
| 7 | +import { Configurator } from "../../ConfigManager"; |
| 8 | +import { SimpleGrid } from "./simple-grid"; |
| 9 | + |
| 10 | +type SimpleGridConfigType = { |
| 11 | + visible: BooleanSettingsControl; |
| 12 | + color: ColorSettingsControl; |
| 13 | + primarySize: NumberSettingControl; |
| 14 | + secondarySize: NumberSettingControl; |
| 15 | + distance: NumberSettingControl; |
| 16 | +}; |
| 17 | + |
| 18 | +/** |
| 19 | + * Configuration interface for the {@link SimpleGrid}. |
| 20 | + */ |
| 21 | +export interface SimpleGridConfig { |
| 22 | + /** |
| 23 | + * The color of the grid lines. |
| 24 | + */ |
| 25 | + color: THREE.Color; |
| 26 | + |
| 27 | + /** |
| 28 | + * The size of the primary grid lines. |
| 29 | + */ |
| 30 | + primarySize: number; |
| 31 | + |
| 32 | + /** |
| 33 | + * The size of the secondary grid lines. |
| 34 | + */ |
| 35 | + secondarySize: number; |
| 36 | + |
| 37 | + /** |
| 38 | + * The distance at which the grid lines start to fade away. |
| 39 | + */ |
| 40 | + distance: number; |
| 41 | +} |
| 42 | + |
| 43 | +export class SimpleGridConfigManager extends Configurator< |
| 44 | + SimpleGrid, |
| 45 | + SimpleGridConfigType |
| 46 | +> { |
| 47 | + protected _config: SimpleGridConfigType = { |
| 48 | + visible: { |
| 49 | + value: true, |
| 50 | + type: "Boolean" as const, |
| 51 | + }, |
| 52 | + color: { |
| 53 | + value: new THREE.Color() as THREE.Color, |
| 54 | + type: "Color" as const, |
| 55 | + }, |
| 56 | + primarySize: { |
| 57 | + type: "Number" as const, |
| 58 | + interpolable: true, |
| 59 | + value: 1, |
| 60 | + min: 0, |
| 61 | + max: 1000, |
| 62 | + }, |
| 63 | + secondarySize: { |
| 64 | + type: "Number" as const, |
| 65 | + interpolable: true, |
| 66 | + value: 10, |
| 67 | + min: 0, |
| 68 | + max: 1000, |
| 69 | + }, |
| 70 | + distance: { |
| 71 | + type: "Number" as const, |
| 72 | + interpolable: true, |
| 73 | + value: 500, |
| 74 | + min: 0, |
| 75 | + max: 500, |
| 76 | + }, |
| 77 | + }; |
| 78 | + |
| 79 | + get visible() { |
| 80 | + return this._config.visible.value; |
| 81 | + } |
| 82 | + |
| 83 | + set visible(value: boolean) { |
| 84 | + this._config.visible.value = value; |
| 85 | + this._component.visible = value; |
| 86 | + } |
| 87 | + |
| 88 | + get color() { |
| 89 | + return this._config.color.value; |
| 90 | + } |
| 91 | + |
| 92 | + set color(value: THREE.Color) { |
| 93 | + this._config.color.value = value; |
| 94 | + this._component.material.uniforms.uColor.value = value; |
| 95 | + this._component.material.uniformsNeedUpdate = true; |
| 96 | + } |
| 97 | + |
| 98 | + get primarySize() { |
| 99 | + return this._config.primarySize.value; |
| 100 | + } |
| 101 | + |
| 102 | + set primarySize(value: number) { |
| 103 | + this._config.primarySize.value = value; |
| 104 | + this._component.material.uniforms.uSize1.value = value; |
| 105 | + this._component.material.uniformsNeedUpdate = true; |
| 106 | + } |
| 107 | + |
| 108 | + get secondarySize() { |
| 109 | + return this._config.secondarySize.value; |
| 110 | + } |
| 111 | + |
| 112 | + set secondarySize(value: number) { |
| 113 | + this._config.secondarySize.value = value; |
| 114 | + this._component.material.uniforms.uSize2.value = value; |
| 115 | + this._component.material.uniformsNeedUpdate = true; |
| 116 | + } |
| 117 | + |
| 118 | + get distance() { |
| 119 | + return this._config.distance.value; |
| 120 | + } |
| 121 | + |
| 122 | + set distance(value: number) { |
| 123 | + this._config.distance.value = value; |
| 124 | + this._component.material.uniforms.uDistance.value = value; |
| 125 | + this._component.material.uniformsNeedUpdate = true; |
| 126 | + } |
| 127 | +} |
0 commit comments