Skip to content

⬅️ Back to Table of Contents

📄 SetPositionCommand.js

📊 Analysis Summary

Metric Count
🔧 Functions 5
🧱 Classes 1
📦 Imports 2

📚 Table of Contents

🛠️ File Location:

📂 editor/js/commands/SetPositionCommand.js

📦 Imports

Name Source
Command ../Command.js
Vector3 three

Functions

SetPositionCommand.execute(): void

Returns: void

Calls:

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

        this.object.position.copy( this.newPosition );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

SetPositionCommand.undo(): void

Returns: void

Calls:

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

        this.object.position.copy( this.oldPosition );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

SetPositionCommand.update(command: any): void

Parameters:

  • command any

Returns: void

Calls:

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

        this.newPosition.copy( command.newPosition );

    }

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

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

Calls:

  • super.toJSON
  • this.oldPosition.toArray
  • this.newPosition.toArray
Code
toJSON() {

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.oldPosition = this.oldPosition.toArray();
        output.newPosition = this.newPosition.toArray();

        return output;

    }

SetPositionCommand.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.oldPosition = new Vector3().fromArray( json.oldPosition );
        this.newPosition = new Vector3().fromArray( json.newPosition );

    }

Classes

SetPositionCommand

Class Code
class SetPositionCommand extends Command {

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

        super( editor );

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

        this.object = object;

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

            this.oldPosition = object.position.clone();
            this.newPosition = newPosition.clone();

        }

        if ( optionalOldPosition !== null ) {

            this.oldPosition = optionalOldPosition.clone();

        }

    }

    execute() {

        this.object.position.copy( this.newPosition );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

    undo() {

        this.object.position.copy( this.oldPosition );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }

    update( command ) {

        this.newPosition.copy( command.newPosition );

    }

    toJSON() {

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.oldPosition = this.oldPosition.toArray();
        output.newPosition = this.newPosition.toArray();

        return output;

    }

    fromJSON( json ) {

        super.fromJSON( json );

        this.object = this.editor.objectByUuid( json.objectUuid );
        this.oldPosition = new Vector3().fromArray( json.oldPosition );
        this.newPosition = new Vector3().fromArray( json.newPosition );

    }

}

Methods

execute(): void
Code
execute() {

        this.object.position.copy( this.newPosition );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

    }
undo(): void
Code
undo() {

        this.object.position.copy( this.oldPosition );
        this.object.updateMatrixWorld( true );
        this.editor.signals.objectChanged.dispatch( this.object );

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

        this.newPosition.copy( command.newPosition );

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

        const output = super.toJSON( this );

        output.objectUuid = this.object.uuid;
        output.oldPosition = this.oldPosition.toArray();
        output.newPosition = this.newPosition.toArray();

        return output;

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

        super.fromJSON( json );

        this.object = this.editor.objectByUuid( json.objectUuid );
        this.oldPosition = new Vector3().fromArray( json.oldPosition );
        this.newPosition = new Vector3().fromArray( json.newPosition );

    }