123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /**
- * Created by Daniel on 21.07.15.
- */
- CmdSetGeometry = function ( object, newGeometry ) {
- Cmd.call( this );
- this.type = 'CmdSetGeometry';
- this.name = 'Set Geometry';
- this.updatable = true;
- this.object = object;
- this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
- this.oldGeometry = ( object !== undefined ) ? object.geometry : undefined;
- this.newGeometry = newGeometry;
- this.oldGeometryJSON = ( object !== undefined ) ? object.geometry.toJSON() : undefined;
- this.newGeometryJSON = ( newGeometry !== undefined ) ? newGeometry.toJSON() : undefined;
- };
- CmdSetGeometry.prototype = {
- init: function () {
- if ( this.object === undefined ) {
- this.object = this.editor.objectByUuid( this.objectUuid );
- }
- if ( this.oldGeometry === undefined ) {
- this.oldGeometry = parseGeometry( this.oldGeometryJSON );
- }
- if ( this.newGeometry === undefined ) {
- this.newGeometry = parseGeometry( this.newGeometryJSON );
- }
- function parseGeometry ( data ) {
- var loader = new THREE.ObjectLoader();
- return loader.parseGeometries( [ data ] )[ data.uuid ];
- }
- },
- execute: function () {
- this.init();
- this.object.geometry.dispose();
- this.object.geometry = this.newGeometry;
- this.object.geometry.computeBoundingSphere();
- this.editor.signals.geometryChanged.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- undo: function () {
- this.init();
- this.object.geometry.dispose();
- this.object.geometry = this.oldGeometry;
- this.object.geometry.computeBoundingSphere();
- this.editor.signals.geometryChanged.dispatch( this.object );
- this.editor.signals.sceneGraphChanged.dispatch();
- },
- update: function ( cmd ) {
- this.newGeometry = cmd.newGeometry;
- this.newGeometryJSON = cmd.newGeometry.toJSON();
- },
- toJSON: function () {
- var output = Cmd.prototype.toJSON.call( this );
- output.objectUuid = this.objectUuid;
- output.oldGeometry = this.oldGeometryJSON;
- output.newGeometry = this.newGeometryJSON;
- return output;
- },
- fromJSON: function ( json ) {
- Cmd.prototype.fromJSON.call( this, json );
- this.objectUuid = json.objectUuid;
- this.oldGeometryJSON = json.oldGeometry;
- this.newGeometryJSON = json.newGeometry;
- }
- };
|