Skip to content

⬅️ Back to Table of Contents

📄 SetScaleCommand.js

📊 Analysis Summary

Metric Count
🔧 Functions 5
🧱 Classes 1
📦 Imports 2

📚 Table of Contents

🛠️ File Location:

📂 editor/js/commands/SetScaleCommand.js

📦 Imports

Name Source
Command ../Command.js
Vector3 three

Functions

SetScaleCommand.execute(): void

Returns: void

Calls:

  • this.object.scale.copy
  • this.object.updateMatrixWorld
  • this.editor.signals.objectChanged.dispatch
Code
execute() {

        this.object.scale.copy( this.newScale );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

SetScaleCommand.undo(): void

Returns: void

Calls:

  • this.object.scale.copy
  • this.object.updateMatrixWorld
  • this.editor.signals.objectChanged.dispatch
Code
undo() {

        this.object.scale.copy( this.oldScale );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

SetScaleCommand.update(command: any): void

Parameters:

  • command any

Returns: void

Calls:

  • this.newScale.copy
Code
update( command ) {

        this.newScale.copy( command.newScale );

    }

SetScaleCommand.toJSON(): { type: string; id: number; name: string; }

Returns: { type: string; id: number; name: string; }

Calls:

  • super.toJSON
  • this.oldScale.toArray
  • this.newScale.toArray
Code
toJSON() {

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.oldScale = this.oldScale.toArray();
        output.newScale = this.newScale.toArray();

        return output;

    }

SetScaleCommand.fromJSON(json: any): void

Parameters:

  • json any

Returns: void

Calls:

  • super.fromJSON
  • this.editor.objectByUuid
  • new Vector3().fromArray
Code
fromJSON( json ) {

        super.fromJSON( json );

        this.object = this.editor.objectByUuid( json.objectUuid );
        this.oldScale = new Vector3().fromArray( json.oldScale );
        this.newScale = new Vector3().fromArray( json.newScale );

    }

Classes

SetScaleCommand

Class Code
class SetScaleCommand extends Command {

    /**
     * @param {Editor} editor
     * @param {THREE.Object3D|null} object
     * @param {THREE.Vector3|null} newScale
     * @param {THREE.Vector3|null} optionalOldScale
     * @constructor
     */
    constructor( editor, object = null, newScale = null, optionalOldScale = null ) {

        super( editor );

        this.type = 'SetScaleCommand';
        this.name = editor.strings.getKey( 'command/SetScale' );
        this.updatable = true;

        this.object = object;

        if ( object !== null && newScale !== null ) {

            this.oldScale = object.scale.clone();
            this.newScale = newScale.clone();

        }

        if ( optionalOldScale !== null ) {

            this.oldScale = optionalOldScale.clone();

        }

    }

    execute() {

        this.object.scale.copy( this.newScale );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

    undo() {

        this.object.scale.copy( this.oldScale );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

    update( command ) {

        this.newScale.copy( command.newScale );

    }

    toJSON() {

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.oldScale = this.oldScale.toArray();
        output.newScale = this.newScale.toArray();

        return output;

    }

    fromJSON( json ) {

        super.fromJSON( json );

        this.object = this.editor.objectByUuid( json.objectUuid );
        this.oldScale = new Vector3().fromArray( json.oldScale );
        this.newScale = new Vector3().fromArray( json.newScale );

    }

}

Methods

execute(): void
Code
execute() {

        this.object.scale.copy( this.newScale );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }
undo(): void
Code
undo() {

        this.object.scale.copy( this.oldScale );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }
update(command: any): void
Code
update( command ) {

        this.newScale.copy( command.newScale );

    }
toJSON(): { type: string; id: number; name: string; }
Code
toJSON() {

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.oldScale = this.oldScale.toArray();
        output.newScale = this.newScale.toArray();

        return output;

    }
fromJSON(json: any): void
Code
fromJSON( json ) {

        super.fromJSON( json );

        this.object = this.editor.objectByUuid( json.objectUuid );
        this.oldScale = new Vector3().fromArray( json.oldScale );
        this.newScale = new Vector3().fromArray( json.newScale );

    }