-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
TextGeometry changes and support in editor #27931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 3 commits
bea5c1f
be77eef
33a29dd
e646d48
89d73f3
b7645d8
67ae50e
575e31d
cf8174b
809ffb6
24fe50f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { TextGeometry } from 'three/addons/geometries/TextGeometry.js'; | ||
|
|
||
| import { UIDiv, UIRow, UIText, UINumber, UIInteger, UIInput, UICheckbox } from './libs/ui.js'; | ||
|
|
||
| import { SetGeometryCommand } from './commands/SetGeometryCommand.js'; | ||
|
|
||
| function GeometryParametersPanel( editor, object ) { | ||
|
|
||
| const strings = editor.strings; | ||
|
|
||
| const container = new UIDiv(); | ||
|
|
||
| const geometry = object.geometry; | ||
| const parameters = geometry.parameters.options; | ||
|
|
||
| // text | ||
|
|
||
| const textRow = new UIRow(); | ||
| const text = new UIInput().setValue( parameters.text ).onChange( update ); | ||
|
|
||
| textRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/text' ) ).setClass( 'Label' ) ); | ||
| textRow.add( text ); | ||
|
|
||
| container.add( textRow ); | ||
|
|
||
| // size | ||
|
|
||
| const sizeRow = new UIRow(); | ||
| const size = new UINumber().setPrecision( 3 ).setValue( parameters.size ).onChange( update ); | ||
|
|
||
| sizeRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/size' ) ).setClass( 'Label' ) ); | ||
| sizeRow.add( size ); | ||
|
|
||
| container.add( sizeRow ); | ||
|
|
||
| // depth | ||
|
|
||
| const depthRow = new UIRow(); | ||
| const depth = new UINumber().setPrecision( 3 ).setValue( parameters.depth ).onChange( update ); | ||
|
|
||
| depthRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/depth' ) ).setClass( 'Label' ) ); | ||
| depthRow.add( depth ); | ||
|
|
||
| container.add( depthRow ); | ||
|
|
||
| // curveSegments | ||
|
|
||
| const curveSegmentsRow = new UIRow(); | ||
| const curveSegments = new UIInteger( parameters.curveSegments ).setRange( 1, Infinity ).onChange( update ); | ||
|
|
||
| curveSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/curveseg' ) ).setClass( 'Label' ) ); | ||
| curveSegmentsRow.add( curveSegments ); | ||
|
|
||
| container.add( curveSegmentsRow ); | ||
|
|
||
|
|
||
| // scale | ||
|
|
||
| const scaleRow = new UIRow(); | ||
| const scale = new UINumber().setPrecision( 4 ).setValue( parameters.scale ).onChange( update ); | ||
|
|
||
| scaleRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/scale' ) ).setClass( 'Label' ) ); | ||
| scaleRow.add( scale ); | ||
|
|
||
| container.add( scaleRow ); | ||
|
|
||
| // bevelEnabled | ||
|
|
||
| const bevelEnabledRow = new UIRow(); | ||
| const bevelEnabled = new UICheckbox( parameters.bevelEnabled ).onChange( update ); | ||
|
|
||
| bevelEnabledRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/bevelenabled' ) ).setClass( 'Label' ) ); | ||
| bevelEnabledRow.add( bevelEnabled ); | ||
|
|
||
| container.add( bevelEnabledRow ); | ||
|
|
||
| // bevelThickness | ||
|
|
||
| const bevelThicknessRow = new UIRow(); | ||
| const bevelThickness = new UINumber( parameters.bevelThickness ).setPrecision( 3 ).setRange( 0, Infinity ).onChange( update ); | ||
|
|
||
| bevelThicknessRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/bevelthickness' ) ).setClass( 'Label' ) ); | ||
| bevelThicknessRow.add( bevelThickness ); | ||
|
|
||
| container.add( bevelThicknessRow ); | ||
|
|
||
| // bevelSize | ||
|
|
||
| const bevelSizeRow = new UIRow(); | ||
| const bevelSize = new UINumber( parameters.bevelSize ).setRange( 0, Infinity ).onChange( update ); | ||
|
|
||
| bevelSizeRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/bevelsize' ) ).setClass( 'Label' ) ); | ||
| bevelSizeRow.add( bevelSize ); | ||
|
|
||
| container.add( bevelSizeRow ); | ||
|
|
||
| // bevelOffset | ||
|
|
||
| const bevelOffsetRow = new UIRow(); | ||
| const bevelOffset = new UINumber( parameters.bevelOffset ).setRange( 0, Infinity ).onChange( update ); | ||
|
|
||
| bevelOffsetRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/bevelOffset' ) ).setClass( 'Label' ) ); | ||
| bevelOffsetRow.add( bevelOffset ); | ||
|
|
||
| container.add( bevelOffsetRow ); | ||
|
|
||
|
|
||
| // bevelSegments | ||
|
|
||
| const bevelSegmentsRow = new UIRow(); | ||
| const bevelSegments = new UIInteger( parameters.bevelSegments ).setRange( 0, Infinity ).onChange( update ); | ||
|
|
||
| bevelSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/text_geometry/bevelseg' ) ).setClass( 'Label' ) ); | ||
| bevelSegmentsRow.add( bevelSegments ); | ||
|
|
||
| container.add( bevelSegmentsRow ); | ||
|
|
||
| function update() { | ||
|
|
||
| const options = { | ||
|
|
||
| text: text.getValue(), | ||
| font: parameters.font, | ||
|
|
||
| size: size.getValue(), | ||
| depth: depth.getValue(), | ||
| curveSegments: curveSegments.getValue(), | ||
|
|
||
| bevelEnabled: bevelEnabled.getValue(), | ||
| bevelThickness: bevelThickness.getValue(), | ||
| bevelSize: bevelSize.getValue(), | ||
| bevelOffset: bevelOffset.getValue(), | ||
| bevelSegments: bevelSegments.getValue(), | ||
|
|
||
| scale: scale.getValue(), | ||
|
|
||
| }; | ||
|
|
||
| const geometry = new TextGeometry( options.text, options ); | ||
|
|
||
| editor.execute( new SetGeometryCommand( editor, object, geometry ) ); | ||
|
|
||
| } | ||
|
|
||
| return container; | ||
|
|
||
| } | ||
|
|
||
| export { GeometryParametersPanel }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| * } | ||
| */ | ||
|
|
||
| import { Font } from '../loaders/FontLoader.js'; | ||
| import { | ||
| ExtrudeGeometry | ||
| } from 'three'; | ||
|
|
@@ -35,7 +36,15 @@ class TextGeometry extends ExtrudeGeometry { | |
|
|
||
| // translate parameters to ExtrudeGeometry API | ||
|
|
||
| parameters.depth = parameters.height !== undefined ? parameters.height : 50; | ||
| if ( parameters.depth === undefined && parameters.height !== undefined ) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR does two things in one go. It adds support to the editor and renames the Ideally, there is a single PR for each change since both changes are independent of each other. Besides, if That said, I also favor Would you be okay with moving the renaming change to a separate PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I can do that. I'll wait on the confirmation of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually the change to extract is easier to do, so it's in #27949 |
||
|
|
||
| console.warn( '.height in TextGeometry is now depreciated. Please use .depth instead' ); | ||
|
|
||
| } | ||
|
|
||
| parameters.depth = parameters.depth !== undefined ? | ||
| parameters.depth : parameters.height !== undefined ? | ||
| parameters.height : 50; | ||
|
|
||
| // defaults | ||
|
|
||
|
|
@@ -45,12 +54,39 @@ class TextGeometry extends ExtrudeGeometry { | |
|
|
||
| super( shapes, parameters ); | ||
|
|
||
| // for conversion of font to object units (ie. px -> m) | ||
|
|
||
| const scale = parameters.scale; | ||
|
|
||
| if ( scale !== undefined ) { | ||
|
|
||
| this.computeBoundingBox(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the bounding box computed at this point? It will be automatically recomputed when calling
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW: Is the introduction of a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the reason to do it here is getting a scaled down (0.01) geometry mostly for connivence to be used in Editor. the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to keep the parameters of |
||
| this.scale( scale, scale, scale ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| this.type = 'TextGeometry'; | ||
|
|
||
| } | ||
|
|
||
| toJSON() { | ||
|
|
||
| const data = super.toJSON(); | ||
| return data; | ||
|
|
||
| } | ||
|
|
||
| static fromJSON( data ) { | ||
|
|
||
| const options = data.options; | ||
|
|
||
| options.font = new Font( options.font.data ); | ||
| return new TextGeometry( options.text, options ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.