123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import * as THREE from 'three';
- import { UIDiv, UIRow, UIText, UINumber, UIInteger } from './libs/ui.js';
- import { SetGeometryCommand } from './commands/SetGeometryCommand.js';
- function GeometryParametersPanel( editor, object ) {
- const strings = editor.strings;
- const signals = editor.signals;
- const container = new UIDiv();
- const geometry = object.geometry;
- const parameters = geometry.parameters;
- // width
- const widthRow = new UIRow();
- const width = new UINumber().setPrecision( 3 ).setValue( parameters.width ).onChange( update );
- widthRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/width' ) ).setClass( 'Label' ) );
- widthRow.add( width );
- container.add( widthRow );
- // height
- const heightRow = new UIRow();
- const height = new UINumber().setPrecision( 3 ).setValue( parameters.height ).onChange( update );
- heightRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/height' ) ).setClass( 'Label' ) );
- heightRow.add( height );
- container.add( heightRow );
- // depth
- const depthRow = new UIRow();
- const depth = new UINumber().setPrecision( 3 ).setValue( parameters.depth ).onChange( update );
- depthRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/depth' ) ).setClass( 'Label' ) );
- depthRow.add( depth );
- container.add( depthRow );
- // widthSegments
- const widthSegmentsRow = new UIRow();
- const widthSegments = new UIInteger( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
- widthSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/widthseg' ) ).setClass( 'Label' ) );
- widthSegmentsRow.add( widthSegments );
- container.add( widthSegmentsRow );
- // heightSegments
- const heightSegmentsRow = new UIRow();
- const heightSegments = new UIInteger( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
- heightSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/heightseg' ) ).setClass( 'Label' ) );
- heightSegmentsRow.add( heightSegments );
- container.add( heightSegmentsRow );
- // depthSegments
- const depthSegmentsRow = new UIRow();
- const depthSegments = new UIInteger( parameters.depthSegments ).setRange( 1, Infinity ).onChange( update );
- depthSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/depthseg' ) ).setClass( 'Label' ) );
- depthSegmentsRow.add( depthSegments );
- container.add( depthSegmentsRow );
- //
- function refreshUI() {
- const parameters = object.geometry.parameters;
- width.setValue( parameters.width );
- height.setValue( parameters.height );
- depth.setValue( parameters.depth );
- widthSegments.setValue( parameters.widthSegments );
- heightSegments.setValue( parameters.heightSegments );
- depthSegments.setValue( parameters.depthSegments );
- }
- signals.geometryChanged.add( function ( mesh ) {
- if ( mesh === object ) {
- refreshUI();
- }
- } );
- //
- function update() {
- editor.execute( new SetGeometryCommand( editor, object, new THREE.BoxGeometry(
- width.getValue(),
- height.getValue(),
- depth.getValue(),
- widthSegments.getValue(),
- heightSegments.getValue(),
- depthSegments.getValue()
- ) ) );
- }
- return container;
- }
- export { GeometryParametersPanel };
|