123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /**
- * @author dforrer / https://github.com/dforrer
- * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
- */
- import { Command } from '../Command.js';
- import * as THREE from '../../../build/three.module.js';
- /**
- * @param editor Editor
- * @param object THREE.Object3D
- * @param newScale THREE.Vector3
- * @param optionalOldScale THREE.Vector3
- * @constructor
- */
- function SetScaleCommand( editor, object, newScale, optionalOldScale ) {
- Command.call( this, editor );
- this.type = 'SetScaleCommand';
- this.name = 'Set Scale';
- this.updatable = true;
- this.object = object;
- if ( object !== undefined && newScale !== undefined ) {
- this.oldScale = object.scale.clone();
- this.newScale = newScale.clone();
- }
- if ( optionalOldScale !== undefined ) {
- this.oldScale = optionalOldScale.clone();
- }
- }
- SetScaleCommand.prototype = {
- execute: function () {
- this.object.scale.copy( this.newScale );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- undo: function () {
- this.object.scale.copy( this.oldScale );
- this.object.updateMatrixWorld( true );
- this.editor.signals.objectChanged.dispatch( this.object );
- },
- update: function ( command ) {
- this.newScale.copy( command.newScale );
- },
- toJSON: function () {
- var output = Command.prototype.toJSON.call( this );
- output.objectUuid = this.object.uuid;
- output.oldScale = this.oldScale.toArray();
- output.newScale = this.newScale.toArray();
- return output;
- },
- fromJSON: function ( json ) {
- Command.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
- this.newScale = new THREE.Vector3().fromArray( json.newScale );
- }
- };
- export { SetScaleCommand };
|