|
@@ -15,7 +15,7 @@ import {
|
|
|
const MaterialHandler = function () {
|
|
|
|
|
|
this.logging = {
|
|
|
- enabled: true,
|
|
|
+ enabled: false,
|
|
|
debug: false
|
|
|
};
|
|
|
|
|
@@ -23,7 +23,6 @@ const MaterialHandler = function () {
|
|
|
onLoadMaterials: null
|
|
|
};
|
|
|
this.materials = {};
|
|
|
- this._createDefaultMaterials();
|
|
|
|
|
|
};
|
|
|
|
|
@@ -54,7 +53,12 @@ MaterialHandler.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- _createDefaultMaterials: function () {
|
|
|
+ /**
|
|
|
+ * Creates default materials and adds them to the materials object.
|
|
|
+ *
|
|
|
+ * @param overrideExisting boolean Override existing material
|
|
|
+ */
|
|
|
+ createDefaultMaterials: function ( overrideExisting ) {
|
|
|
|
|
|
let defaultMaterial = new MeshStandardMaterial( { color: 0xDCF1FF } );
|
|
|
defaultMaterial.name = 'defaultMaterial';
|
|
@@ -75,7 +79,7 @@ MaterialHandler.prototype = {
|
|
|
runtimeMaterials[ defaultLineMaterial.name ] = defaultLineMaterial;
|
|
|
runtimeMaterials[ defaultPointMaterial.name ] = defaultPointMaterial;
|
|
|
|
|
|
- this.addMaterials( runtimeMaterials );
|
|
|
+ this.addMaterials( runtimeMaterials, overrideExisting );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -118,7 +122,11 @@ MaterialHandler.prototype = {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- console.info( 'Requested material "' + materialNameOrg + '" is not available!' );
|
|
|
+ if ( this.logging.enabled) {
|
|
|
+
|
|
|
+ console.info( 'Requested material "' + materialNameOrg + '" is not available!' );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -135,7 +143,11 @@ MaterialHandler.prototype = {
|
|
|
if ( materialJson !== undefined && materialJson !== null ) {
|
|
|
|
|
|
material = loader.parse( materialJson );
|
|
|
- if ( this.logging.enabled ) console.info( 'De-serialized material with name "' + materialName + '" will be added.' );
|
|
|
+ if ( this.logging.enabled ) {
|
|
|
+
|
|
|
+ console.info( 'De-serialized material with name "' + materialName + '" will be added.' );
|
|
|
+
|
|
|
+ }
|
|
|
this.materials[ materialName ] = material;
|
|
|
newMaterials[ materialName ] = material;
|
|
|
|
|
@@ -145,7 +157,7 @@ MaterialHandler.prototype = {
|
|
|
|
|
|
}
|
|
|
materials = materialPayload.materials.runtimeMaterials;
|
|
|
- newMaterials = this.addMaterials( materials, newMaterials );
|
|
|
+ newMaterials = this.addMaterials( materials, true, newMaterials );
|
|
|
|
|
|
return newMaterials;
|
|
|
|
|
@@ -155,9 +167,10 @@ MaterialHandler.prototype = {
|
|
|
* Set materials loaded by any supplier of an Array of {@link Material}.
|
|
|
*
|
|
|
* @param materials Object with named {@link Material}
|
|
|
+ * @param overrideExisting boolean Override existing material
|
|
|
* @param newMaterials [Object] with named {@link Material}
|
|
|
*/
|
|
|
- addMaterials: function ( materials, newMaterials ) {
|
|
|
+ addMaterials: function ( materials, overrideExisting, newMaterials ) {
|
|
|
|
|
|
if ( newMaterials === undefined || newMaterials === null ) {
|
|
|
|
|
@@ -167,12 +180,29 @@ MaterialHandler.prototype = {
|
|
|
if ( materials !== undefined && materials !== null && Object.keys( materials ).length > 0 ) {
|
|
|
|
|
|
let material;
|
|
|
+ let existingMaterial;
|
|
|
+ let add;
|
|
|
for ( let materialName in materials ) {
|
|
|
|
|
|
material = materials[ materialName ];
|
|
|
- this.materials[ materialName ] = material;
|
|
|
- newMaterials[ materialName ] = material;
|
|
|
- if ( this.logging.enabled && this.logging.debug ) console.info( 'Material with name "' + materialName + '" was added.' );
|
|
|
+ add = overrideExisting === true;
|
|
|
+ if ( ! add ) {
|
|
|
+
|
|
|
+ existingMaterial = this.materials[ materialName ];
|
|
|
+ add = ( existingMaterial === null || existingMaterial === undefined );
|
|
|
+
|
|
|
+ }
|
|
|
+ if ( add ) {
|
|
|
+
|
|
|
+ this.materials[ materialName ] = material;
|
|
|
+ newMaterials[ materialName ] = material;
|
|
|
+
|
|
|
+ }
|
|
|
+ if ( this.logging.enabled && this.logging.debug ) {
|
|
|
+
|
|
|
+ console.info( 'Material with name "' + materialName + '" was added.' );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -227,6 +257,13 @@ MaterialHandler.prototype = {
|
|
|
|
|
|
return materialsJSON;
|
|
|
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Removes all materials
|
|
|
+ */
|
|
|
+ clearMaterials: function () {
|
|
|
+ this.materials = {};
|
|
|
}
|
|
|
|
|
|
};
|