Skip to content

⬅️ Back to Table of Contents

📄 RemoveObjectCommand.js

📊 Analysis Summary

Metric Count
🔧 Functions 4
🧱 Classes 1
📦 Imports 2
📊 Variables & Constants 1

📚 Table of Contents

🛠️ File Location:

📂 editor/js/commands/RemoveObjectCommand.js

📦 Imports

Name Source
Command ../Command.js
ObjectLoader three

Variables & Constants

Name Type Kind Value Exported
loader any let/var new ObjectLoader()

Functions

RemoveObjectCommand.execute(): void

Returns: void

Calls:

  • this.editor.removeObject
  • this.editor.deselect
Code
execute() {

        this.editor.removeObject( this.object );
        this.editor.deselect();

    }

RemoveObjectCommand.undo(): void

Returns: void

Calls:

  • this.editor.addObject
  • this.editor.select
Code
undo() {

        this.editor.addObject( this.object, this.parent, this.index );
        this.editor.select( this.object );

    }

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

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

Calls:

  • super.toJSON
  • this.object.toJSON
Code
toJSON() {

        const output = super.toJSON( this );

        output.object = this.object.toJSON();
        output.index = this.index;
        output.parentUuid = this.parent.uuid;

        return output;

    }

RemoveObjectCommand.fromJSON(json: any): void

Parameters:

  • json any

Returns: void

Calls:

  • super.fromJSON
  • this.editor.objectByUuid
  • loader.parse
Code
fromJSON( json ) {

        super.fromJSON( json );

        this.parent = this.editor.objectByUuid( json.parentUuid );
        if ( this.parent === undefined ) {

            this.parent = this.editor.scene;

        }

        this.index = json.index;

        this.object = this.editor.objectByUuid( json.object.object.uuid );

        if ( this.object === undefined ) {

            const loader = new ObjectLoader();
            this.object = loader.parse( json.object );

        }

    }

Classes

RemoveObjectCommand

Class Code
class RemoveObjectCommand extends Command {

    /**
     * @param {Editor} editor
     * @param {THREE.Object3D|null} [object=null]
     * @constructor
     */
    constructor( editor, object = null ) {

        super( editor );

        this.type = 'RemoveObjectCommand';

        this.object = object;
        this.parent = ( object !== null ) ? object.parent : null;

        if ( this.parent !== null ) {

            this.index = this.parent.children.indexOf( this.object );

        }

        if ( object !== null ) {

            this.name = editor.strings.getKey( 'command/RemoveObject' ) + ': ' + object.name;


        }

    }

    execute() {

        this.editor.removeObject( this.object );
        this.editor.deselect();

    }

    undo() {

        this.editor.addObject( this.object, this.parent, this.index );
        this.editor.select( this.object );

    }

    toJSON() {

        const output = super.toJSON( this );

        output.object = this.object.toJSON();
        output.index = this.index;
        output.parentUuid = this.parent.uuid;

        return output;

    }

    fromJSON( json ) {

        super.fromJSON( json );

        this.parent = this.editor.objectByUuid( json.parentUuid );
        if ( this.parent === undefined ) {

            this.parent = this.editor.scene;

        }

        this.index = json.index;

        this.object = this.editor.objectByUuid( json.object.object.uuid );

        if ( this.object === undefined ) {

            const loader = new ObjectLoader();
            this.object = loader.parse( json.object );

        }

    }

}

Methods

execute(): void
Code
execute() {

        this.editor.removeObject( this.object );
        this.editor.deselect();

    }
undo(): void
Code
undo() {

        this.editor.addObject( this.object, this.parent, this.index );
        this.editor.select( this.object );

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

        const output = super.toJSON( this );

        output.object = this.object.toJSON();
        output.index = this.index;
        output.parentUuid = this.parent.uuid;

        return output;

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

        super.fromJSON( json );

        this.parent = this.editor.objectByUuid( json.parentUuid );
        if ( this.parent === undefined ) {

            this.parent = this.editor.scene;

        }

        this.index = json.index;

        this.object = this.editor.objectByUuid( json.object.object.uuid );

        if ( this.object === undefined ) {

            const loader = new ObjectLoader();
            this.object = loader.parse( json.object );

        }

    }