Skip to content
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

Editor: Introduce SetShadowValueCommand. #28608

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Editor: Introduce SetShadowValueCommand.
  • Loading branch information
Mugen87 committed Jun 10, 2024
commit f77b4e895b02073686a5f6a5a78c730638e67312
9 changes: 5 additions & 4 deletions editor/js/Sidebar.Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SetPositionCommand } from './commands/SetPositionCommand.js';
import { SetRotationCommand } from './commands/SetRotationCommand.js';
import { SetScaleCommand } from './commands/SetScaleCommand.js';
import { SetColorCommand } from './commands/SetColorCommand.js';
import { SetShadowValueCommand } from './commands/SetShadowValueCommand.js';

import { SidebarObjectAnimation } from './Sidebar.Object.Animation.js';

Expand Down Expand Up @@ -593,25 +594,25 @@ function SidebarObject( editor ) {

if ( object.shadow.intensity !== objectShadowIntensity.getValue() ) {

editor.execute( new SetValueCommand( editor, object.shadow, 'intensity', objectShadowIntensity.getValue() ) );
editor.execute( new SetShadowValueCommand( editor, object, 'intensity', objectShadowIntensity.getValue() ) );

}

if ( object.shadow.bias !== objectShadowBias.getValue() ) {

editor.execute( new SetValueCommand( editor, object.shadow, 'bias', objectShadowBias.getValue() ) );
editor.execute( new SetShadowValueCommand( editor, object, 'bias', objectShadowBias.getValue() ) );

}

if ( object.shadow.normalBias !== objectShadowNormalBias.getValue() ) {

editor.execute( new SetValueCommand( editor, object.shadow, 'normalBias', objectShadowNormalBias.getValue() ) );
editor.execute( new SetShadowValueCommand( editor, object, 'normalBias', objectShadowNormalBias.getValue() ) );

}

if ( object.shadow.radius !== objectShadowRadius.getValue() ) {

editor.execute( new SetValueCommand( editor, object.shadow, 'radius', objectShadowRadius.getValue() ) );
editor.execute( new SetShadowValueCommand( editor, object, 'radius', objectShadowRadius.getValue() ) );

}

Expand Down
4 changes: 4 additions & 0 deletions editor/js/Strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Strings( config ) {
'command/SetScale': 'Set Scale',
'command/SetScene': 'Set Scene',
'command/SetScriptValue': 'Set Script Value',
'command/SetShadowValue': 'Set Shadow Value',
'command/SetUuid': 'Set UUID',
'command/SetValue': 'Set Value',

Expand Down Expand Up @@ -437,6 +438,7 @@ function Strings( config ) {
'command/SetScale': 'Définir l’échelle',
'command/SetScene': 'Planter le décor',
'command/SetScriptValue': 'Définir la valeur du script',
'command/SetShadowValue': 'Set Shadow Value',
'command/SetUuid': 'Définir l’UUID',
'command/SetValue': 'Définir la valeur',

Expand Down Expand Up @@ -838,6 +840,7 @@ function Strings( config ) {
'command/SetScale': '设置比例',
'command/SetScene': '设置布景',
'command/SetScriptValue': '设置脚本值',
'command/SetShadowValue': 'Set Shadow Value',
'command/SetUuid': '设置 UUID',
'command/SetValue': '设定值',

Expand Down Expand Up @@ -1239,6 +1242,7 @@ function Strings( config ) {
'command/SetScale': 'スケールを設定',
'command/SetScene': 'セットシーン',
'command/SetScriptValue': 'スクリプト値の設定',
'command/SetShadowValue': 'Set Shadow Value',
'command/SetUuid': 'UUIDの設定',
'command/SetValue': '値の設定',

Expand Down
1 change: 1 addition & 0 deletions editor/js/commands/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export { SetRotationCommand } from './SetRotationCommand.js';
export { SetScaleCommand } from './SetScaleCommand.js';
export { SetSceneCommand } from './SetSceneCommand.js';
export { SetScriptValueCommand } from './SetScriptValueCommand.js';
export { SetShadowValueCommand } from './SetShadowValueCommand.js';
export { SetUuidCommand } from './SetUuidCommand.js';
export { SetValueCommand } from './SetValueCommand.js';
66 changes: 66 additions & 0 deletions editor/js/commands/SetShadowValueCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Command } from '../Command.js';

/**
* @param editor Editor
* @param object THREE.Object3D
* @param attributeName string
* @param newValue number, string, boolean or object
* @constructor
*/
class SetShadowValueCommand extends Command {

constructor( editor, object = null, attributeName = '', newValue = null ) {

super( editor );

this.type = 'SetShadowValueCommand';
this.name = editor.strings.getKey( 'command/SetShadowValue' ) + ': ' + attributeName;

this.object = object;
this.attributeName = attributeName;
this.oldValue = ( object !== null ) ? object.shadow[ attributeName ] : null;
this.newValue = newValue;

}

execute() {

this.object.shadow[ this.attributeName ] = this.newValue;
this.editor.signals.objectChanged.dispatch( this.object );

}

undo() {

this.object.shadow[ this.attributeName ] = this.oldValue;
this.editor.signals.objectChanged.dispatch( this.object );

}

toJSON() {

const output = super.toJSON( this );

output.objectUuid = this.object.uuid;
output.attributeName = this.attributeName;
output.oldValue = this.oldValue;
output.newValue = this.newValue;

return output;

}

fromJSON( json ) {

super.fromJSON( json );

this.object = this.editor.objectByUuid( json.objectUuid );
this.attributeName = json.attributeName;
this.oldValue = json.oldValue;
this.newValue = json.newValue;

}

}

export { SetShadowValueCommand };