Selaa lähdekoodia

LDraw: don't clear already-loaded materials on load (#31150)

* LDraw: don't clear already-loaded materials on load

* make addDefaultMaterials an explicit call
James Smith 7 kuukautta sitten
vanhempi
sitoutus
523e440665
1 muutettua tiedostoa jossa 24 lisäystä ja 2 poistoa
  1. 24 2
      examples/jsm/loaders/LDrawLoader.js

+ 24 - 2
examples/jsm/loaders/LDrawLoader.js

@@ -1885,7 +1885,7 @@ class LDrawLoader extends Loader {
 
 
 		}
 		}
 
 
-		this.setMaterials( materials );
+		this.addMaterials( materials );
 
 
 	}
 	}
 
 
@@ -1907,7 +1907,7 @@ class LDrawLoader extends Loader {
 		fileLoader.load( url, text => {
 		fileLoader.load( url, text => {
 
 
 			// Initializes the materials library with default materials
 			// Initializes the materials library with default materials
-			this.setMaterials( [] );
+			this.addDefaultMaterials();
 
 
 			this.partsCache
 			this.partsCache
 				.parseModel( text )
 				.parseModel( text )
@@ -1950,14 +1950,36 @@ class LDrawLoader extends Loader {
 
 
 	setMaterials( materials ) {
 	setMaterials( materials ) {
 
 
+		this.clearMaterials();
+		this.addMaterials(materials);
+
+		return this;
+
+	}
+
+	clearMaterials() {
+
 		this.materialLibrary = {};
 		this.materialLibrary = {};
 		this.materials = [];
 		this.materials = [];
+
+		return this;
+
+	}
+
+	addMaterials( materials ) {
+
 		for ( let i = 0, l = materials.length; i < l; i ++ ) {
 		for ( let i = 0, l = materials.length; i < l; i ++ ) {
 
 
 			this.addMaterial( materials[ i ] );
 			this.addMaterial( materials[ i ] );
 
 
 		}
 		}
 
 
+		return this;
+
+	}
+
+	addDefaultMaterials() {
+
 		// Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
 		// Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
 		this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ) );
 		this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ) );
 		this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) );
 		this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) );

粤ICP备19079148号