@@ -39,7 +39,12 @@ import { TrackableValue, WatchableValue } from "#src/trackable_value.js";
3939import type { UserLayerWithAnnotations } from "#src/ui/annotations.js" ;
4040import { randomUint64 } from "#src/util/bigint.js" ;
4141import { RefCounted } from "#src/util/disposable.js" ;
42- import { parseUint64 , verifyFiniteFloat , verifyInt } from "#src/util/json.js" ;
42+ import {
43+ parseUint64 ,
44+ verifyFiniteFloat ,
45+ verifyInt ,
46+ verifyOptionalObjectProperty ,
47+ } from "#src/util/json.js" ;
4348import { TrackableEnum } from "#src/util/trackable_enum.js" ;
4449import { VoxelPreviewMultiscaleSource } from "#src/voxel_annotation/PreviewMultiscaleChunkSource.js" ;
4550import type { VoxelEditControllerHost } from "#src/voxel_annotation/edit_controller.js" ;
@@ -50,6 +55,12 @@ export enum BrushShape {
5055 SPHERE = 1 ,
5156}
5257
58+ const BRUSH_SIZE_JSON_KEY = "brushSize" ;
59+ const ERASE_MODE_JSON_KEY = "eraseMode" ;
60+ const BRUSH_SHAPE_JSON_KEY = "brushShape" ;
61+ const FLOOD_FILL_MAX_VOXELS_JSON_KEY = "floodFillMaxVoxels" ;
62+ const PAINT_VALUE_JSON_KEY = "paintValue" ;
63+
5364export class VoxelEditingContext
5465 extends RefCounted
5566 implements VoxelEditControllerHost
@@ -196,6 +207,25 @@ export function UserLayerWithVoxelEditingMixin<
196207 } ) ;
197208 }
198209
210+ toJSON ( ) {
211+ const json = super . toJSON ( ) ;
212+ json [ BRUSH_SIZE_JSON_KEY ] = this . voxBrushRadius . toJSON ( ) ;
213+ json [ ERASE_MODE_JSON_KEY ] = this . voxEraseMode . toJSON ( ) ;
214+ json [ BRUSH_SHAPE_JSON_KEY ] = this . voxBrushShape . toJSON ( ) ;
215+ json [ FLOOD_FILL_MAX_VOXELS_JSON_KEY ] = this . voxFloodMaxVoxels . toJSON ( ) ;
216+ json [ PAINT_VALUE_JSON_KEY ] = this . paintValue . toJSON ( ) ;
217+ return json ;
218+ }
219+
220+ restoreState ( specification : any ) {
221+ super . restoreState ( specification ) ;
222+ verifyOptionalObjectProperty ( specification , BRUSH_SIZE_JSON_KEY , v => this . voxBrushRadius . restoreState ( v ) ) ;
223+ verifyOptionalObjectProperty ( specification , ERASE_MODE_JSON_KEY , v => this . voxEraseMode . restoreState ( v ) ) ;
224+ verifyOptionalObjectProperty ( specification , BRUSH_SHAPE_JSON_KEY , v => this . voxBrushShape . restoreState ( v ) ) ;
225+ verifyOptionalObjectProperty ( specification , FLOOD_FILL_MAX_VOXELS_JSON_KEY , v => this . voxFloodMaxVoxels . restoreState ( v ) ) ;
226+ verifyOptionalObjectProperty ( specification , PAINT_VALUE_JSON_KEY , v => this . paintValue . restoreState ( v ) ) ;
227+ }
228+
199229 getVoxelPaintValue ( erase : boolean ) : bigint {
200230 if ( erase ) return 0n ;
201231 return this . paintValue . value ;
0 commit comments