Skip to content

Commit

Permalink
adds user data input (mrdoob#28489)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycw authored May 25, 2024
1 parent 0bc990f commit 6557739
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
51 changes: 50 additions & 1 deletion editor/js/Sidebar.Geometry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';

import { UIPanel, UIRow, UIText, UIInput, UIButton, UISpan } from './libs/ui.js';
import { UIPanel, UIRow, UIText, UIInput, UIButton, UISpan, UITextArea } from './libs/ui.js';

import { SetGeometryValueCommand } from './commands/SetGeometryValueCommand.js';

Expand Down Expand Up @@ -145,6 +145,53 @@ function SidebarGeometry( editor ) {
geometryBoundingBoxRow.add( geometryBoundingBox );
container.add( geometryBoundingBoxRow );

// userData

const geometryUserDataRow = new UIRow();
const geometryUserData = new UITextArea().setValue( '{}' ).setWidth( '150px' ).setHeight( '40px' ).setFontSize( '12px' ).onChange( function () {

try {

const userData = JSON.parse( geometryUserData.getValue() );

if ( JSON.stringify( editor.selected.geometry.userData ) != JSON.stringify( userData ) ) {

editor.execute( new SetGeometryValueCommand( editor, editor.selected, 'userData', userData ) );

build();

}

} catch ( exception ) {

console.warn( exception );

}

} );
geometryUserData.onKeyUp( function () {

try {

JSON.parse( geometryUserData.getValue() );

geometryUserData.dom.classList.add( 'success' );
geometryUserData.dom.classList.remove( 'fail' );

} catch ( error ) {

geometryUserData.dom.classList.remove( 'success' );
geometryUserData.dom.classList.add( 'fail' );

}

} );

geometryUserDataRow.add( new UIText( strings.getKey( 'sidebar/geometry/userdata' ) ).setClass( 'Label' ) );
geometryUserDataRow.add( geometryUserData );

container.add( geometryUserDataRow );

// Helpers

const helpersRow = new UIRow().setMarginLeft( '120px' );
Expand Down Expand Up @@ -247,6 +294,8 @@ function SidebarGeometry( editor ) {

helpersRow.setDisplay( geometry.hasAttribute( 'normal' ) ? '' : 'none' );

geometryUserData.setValue( JSON.stringify( geometry.userData, null, ' ' ) );

} else {

container.setDisplay( 'none' );
Expand Down
4 changes: 4 additions & 0 deletions editor/js/Strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function Strings( config ) {
'sidebar/geometry/uuid': 'UUID',
'sidebar/geometry/name': 'Name',
'sidebar/geometry/bounds': 'Bounds',
'sidebar/geometry/userdata': 'User Data',
'sidebar/geometry/show_vertex_normals': 'Show Vertex Normals',
'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
Expand Down Expand Up @@ -556,6 +557,7 @@ function Strings( config ) {
'sidebar/geometry/uuid': 'UUID',
'sidebar/geometry/name': 'Nom',
'sidebar/geometry/bounds': 'Limites',
'sidebar/geometry/userdata': 'Données utilisateur',
'sidebar/geometry/show_vertex_normals': 'Afficher normales',
'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
Expand Down Expand Up @@ -954,6 +956,7 @@ function Strings( config ) {
'sidebar/geometry/uuid': '识别码',
'sidebar/geometry/name': '名称',
'sidebar/geometry/bounds': '界限',
'sidebar/geometry/userdata': '自定义数据',
'sidebar/geometry/show_vertex_normals': '显示顶点法线',
'sidebar/geometry/compute_vertex_normals': '计算顶点法线',
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
Expand Down Expand Up @@ -1352,6 +1355,7 @@ function Strings( config ) {
'sidebar/geometry/uuid': 'UUID',
'sidebar/geometry/name': '名前',
'sidebar/geometry/bounds': '境界',
'sidebar/geometry/userdata': 'ユーザーデータ',
'sidebar/geometry/show_vertex_normals': '頂点法線を表示',
'sidebar/geometry/compute_vertex_normals': '頂点法線を計算',
'sidebar/geometry/compute_vertex_tangents': '接線を計算',
Expand Down

0 comments on commit 6557739

Please sign in to comment.