-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Moved Materials panel to its own file.
- Loading branch information
Showing
3 changed files
with
87 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { UIBreak, UIPanel, UIRow, UIText, UIListbox, UIButton } from './libs/ui.js'; | ||
|
||
import { SetMaterialCommand } from './commands/SetMaterialCommand.js'; | ||
|
||
function SidebarProjectMaterials( editor ) { | ||
|
||
var signals = editor.signals; | ||
var strings = editor.strings; | ||
|
||
var container = new UIPanel(); | ||
|
||
var headerRow = new UIRow(); | ||
headerRow.add( new UIText( strings.getKey( 'sidebar/project/materials' ).toUpperCase() ) ); | ||
|
||
container.add( headerRow ); | ||
|
||
var listbox = new UIListbox(); | ||
container.add( listbox ); | ||
|
||
container.add( new UIBreak() ); | ||
|
||
var buttonsRow = new UIRow(); | ||
container.add( buttonsRow ); | ||
|
||
var assignMaterial = new UIButton().setLabel( strings.getKey( 'sidebar/project/Assign' ) ); | ||
assignMaterial.onClick( function () { | ||
|
||
var selectedObject = editor.selected; | ||
|
||
if ( selectedObject !== null ) { | ||
|
||
var oldMaterial = selectedObject.material; | ||
|
||
// only assing materials to objects with a material property (e.g. avoid assigning material to THREE.Group) | ||
|
||
if ( oldMaterial !== undefined ) { | ||
|
||
var material = editor.getMaterialById( parseInt( listbox.getValue() ) ); | ||
|
||
if ( material !== undefined ) { | ||
|
||
editor.removeMaterial( oldMaterial ); | ||
editor.execute( new SetMaterialCommand( editor, selectedObject, material ) ); | ||
editor.addMaterial( material ); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} ); | ||
buttonsRow.add( assignMaterial ); | ||
|
||
// Signals | ||
|
||
function refreshMaterialBrowserUI() { | ||
|
||
listbox.setItems( Object.values( editor.materials ) ); | ||
|
||
} | ||
|
||
signals.objectSelected.add( function ( object ) { | ||
|
||
if ( object !== null ) { | ||
|
||
var index = Object.values( editor.materials ).indexOf( object.material ); | ||
listbox.selectIndex( index ); | ||
|
||
} | ||
|
||
} ); | ||
|
||
signals.materialAdded.add( refreshMaterialBrowserUI ); | ||
signals.materialChanged.add( refreshMaterialBrowserUI ); | ||
signals.materialRemoved.add( refreshMaterialBrowserUI ); | ||
|
||
return container; | ||
|
||
} | ||
|
||
export { SidebarProjectMaterials }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters