123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /**
- * 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 = {
- execute: function () {
- 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.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.oldGeometryJSON = this.oldGeometryJSON;
- output.newGeometryJSON = this.newGeometryJSON;
- return output;
- },
- fromJSON: function ( json ) {
- Cmd.prototype.fromJSON.call( this, json );
- this.object = this.editor.objectByUuid( json.objectUuid );
- this.objectUuid = json.objectUuid;
- this.oldGeometryJSON = json.oldGeometryJSON;
- this.newGeometryJSON = json.newGeometryJSON;
- this.oldGeometry = parseGeometry( this.oldGeometryJSON );
- this.newGeometry = parseGeometry( this.newGeometryJSON );
- function parseGeometry ( data ) {
- var loader = new THREE.ObjectLoader();
- return loader.parseGeometries( [ data ] )[ data.uuid ];
- }
- }
- };
|