|
@@ -1,7 +1,5 @@
|
|
-
|
|
|
|
import { Command } from '../Command.js';
|
|
import { Command } from '../Command.js';
|
|
-
|
|
|
|
-import * as THREE from '../../../build/three.module.js';
|
|
|
|
|
|
+import { ObjectLoader } from '../../../build/three.module.js';
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param editor Editor
|
|
* @param editor Editor
|
|
@@ -10,26 +8,26 @@ import * as THREE from '../../../build/three.module.js';
|
|
* @param newMap THREE.Texture
|
|
* @param newMap THREE.Texture
|
|
* @constructor
|
|
* @constructor
|
|
*/
|
|
*/
|
|
-function SetMaterialMapCommand( editor, object, mapName, newMap, materialSlot ) {
|
|
|
|
|
|
+class SetMaterialMapCommand extends Command {
|
|
|
|
|
|
- Command.call( this, editor );
|
|
|
|
|
|
+ constructor( editor, object, mapName, newMap, materialSlot ) {
|
|
|
|
|
|
- this.type = 'SetMaterialMapCommand';
|
|
|
|
- this.name = 'Set Material.' + mapName;
|
|
|
|
|
|
+ super( editor );
|
|
|
|
|
|
- this.object = object;
|
|
|
|
- this.material = this.editor.getObjectMaterial( object, materialSlot );
|
|
|
|
|
|
+ this.type = 'SetMaterialMapCommand';
|
|
|
|
+ this.name = `Set Material.${mapName}`;
|
|
|
|
|
|
- this.oldMap = ( object !== undefined ) ? this.material[ mapName ] : undefined;
|
|
|
|
- this.newMap = newMap;
|
|
|
|
|
|
+ this.object = object;
|
|
|
|
+ this.material = this.editor.getObjectMaterial( object, materialSlot );
|
|
|
|
|
|
- this.mapName = mapName;
|
|
|
|
|
|
+ this.oldMap = ( object !== undefined ) ? this.material[ mapName ] : undefined;
|
|
|
|
+ this.newMap = newMap;
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ this.mapName = mapName;
|
|
|
|
|
|
-SetMaterialMapCommand.prototype = {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- execute: function () {
|
|
|
|
|
|
+ execute() {
|
|
|
|
|
|
if ( this.oldMap !== null && this.oldMap !== undefined ) this.oldMap.dispose();
|
|
if ( this.oldMap !== null && this.oldMap !== undefined ) this.oldMap.dispose();
|
|
|
|
|
|
@@ -38,20 +36,20 @@ SetMaterialMapCommand.prototype = {
|
|
|
|
|
|
this.editor.signals.materialChanged.dispatch( this.material );
|
|
this.editor.signals.materialChanged.dispatch( this.material );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- undo: function () {
|
|
|
|
|
|
+ undo() {
|
|
|
|
|
|
this.material[ this.mapName ] = this.oldMap;
|
|
this.material[ this.mapName ] = this.oldMap;
|
|
this.material.needsUpdate = true;
|
|
this.material.needsUpdate = true;
|
|
|
|
|
|
this.editor.signals.materialChanged.dispatch( this.material );
|
|
this.editor.signals.materialChanged.dispatch( this.material );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- toJSON: function () {
|
|
|
|
|
|
+ toJSON() {
|
|
|
|
|
|
- var output = Command.prototype.toJSON.call( this );
|
|
|
|
|
|
+ const output = super.toJSON( this );
|
|
|
|
|
|
output.objectUuid = this.object.uuid;
|
|
output.objectUuid = this.object.uuid;
|
|
output.mapName = this.mapName;
|
|
output.mapName = this.mapName;
|
|
@@ -66,15 +64,15 @@ SetMaterialMapCommand.prototype = {
|
|
|
|
|
|
if ( map === null || map === undefined ) return null;
|
|
if ( map === null || map === undefined ) return null;
|
|
|
|
|
|
- var meta = {
|
|
|
|
|
|
+ const meta = {
|
|
geometries: {},
|
|
geometries: {},
|
|
materials: {},
|
|
materials: {},
|
|
textures: {},
|
|
textures: {},
|
|
images: {}
|
|
images: {}
|
|
};
|
|
};
|
|
|
|
|
|
- var json = map.toJSON( meta );
|
|
|
|
- var images = extractFromCache( meta.images );
|
|
|
|
|
|
+ const json = map.toJSON( meta );
|
|
|
|
+ const images = extractFromCache( meta.images );
|
|
if ( images.length > 0 ) json.images = images;
|
|
if ( images.length > 0 ) json.images = images;
|
|
json.sourceFile = map.sourceFile;
|
|
json.sourceFile = map.sourceFile;
|
|
|
|
|
|
@@ -89,10 +87,10 @@ SetMaterialMapCommand.prototype = {
|
|
// and return as array
|
|
// and return as array
|
|
function extractFromCache( cache ) {
|
|
function extractFromCache( cache ) {
|
|
|
|
|
|
- var values = [];
|
|
|
|
- for ( var key in cache ) {
|
|
|
|
|
|
+ const values = [];
|
|
|
|
+ for ( const key in cache ) {
|
|
|
|
|
|
- var data = cache[ key ];
|
|
|
|
|
|
+ const data = cache[ key ];
|
|
delete data.metadata;
|
|
delete data.metadata;
|
|
values.push( data );
|
|
values.push( data );
|
|
|
|
|
|
@@ -102,11 +100,11 @@ SetMaterialMapCommand.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- fromJSON: function ( json ) {
|
|
|
|
|
|
+ fromJSON( json ) {
|
|
|
|
|
|
- Command.prototype.fromJSON.call( this, json );
|
|
|
|
|
|
+ super.fromJSON( json );
|
|
|
|
|
|
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
this.mapName = json.mapName;
|
|
this.mapName = json.mapName;
|
|
@@ -115,12 +113,12 @@ SetMaterialMapCommand.prototype = {
|
|
|
|
|
|
function parseTexture( json ) {
|
|
function parseTexture( json ) {
|
|
|
|
|
|
- var map = null;
|
|
|
|
|
|
+ let map = null;
|
|
if ( json !== null ) {
|
|
if ( json !== null ) {
|
|
|
|
|
|
- var loader = new THREE.ObjectLoader();
|
|
|
|
- var images = loader.parseImages( json.images );
|
|
|
|
- var textures = loader.parseTextures( [ json ], images );
|
|
|
|
|
|
+ const loader = new ObjectLoader();
|
|
|
|
+ const images = loader.parseImages( json.images );
|
|
|
|
+ const textures = loader.parseTextures( [ json ], images );
|
|
map = textures[ json.uuid ];
|
|
map = textures[ json.uuid ];
|
|
map.sourceFile = json.sourceFile;
|
|
map.sourceFile = json.sourceFile;
|
|
|
|
|
|
@@ -132,6 +130,6 @@ SetMaterialMapCommand.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-};
|
|
|
|
|
|
+}
|
|
|
|
|
|
export { SetMaterialMapCommand };
|
|
export { SetMaterialMapCommand };
|