Skip to content

Commit ead7627

Browse files
FloppyRuthySheffi
authored andcommitted
LDraw: don't clear already-loaded materials on load (mrdoob#31150)
* LDraw: don't clear already-loaded materials on load * make addDefaultMaterials an explicit call
1 parent 8a5b86e commit ead7627

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

examples/jsm/loaders/LDrawLoader.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ class LDrawLoader extends Loader {
18851885

18861886
}
18871887

1888-
this.setMaterials( materials );
1888+
this.addMaterials( materials );
18891889

18901890
}
18911891

@@ -1907,7 +1907,7 @@ class LDrawLoader extends Loader {
19071907
fileLoader.load( url, text => {
19081908

19091909
// Initializes the materials library with default materials
1910-
this.setMaterials( [] );
1910+
this.addDefaultMaterials();
19111911

19121912
this.partsCache
19131913
.parseModel( text )
@@ -1950,14 +1950,36 @@ class LDrawLoader extends Loader {
19501950

19511951
setMaterials( materials ) {
19521952

1953+
this.clearMaterials();
1954+
this.addMaterials(materials);
1955+
1956+
return this;
1957+
1958+
}
1959+
1960+
clearMaterials() {
1961+
19531962
this.materialLibrary = {};
19541963
this.materials = [];
1964+
1965+
return this;
1966+
1967+
}
1968+
1969+
addMaterials( materials ) {
1970+
19551971
for ( let i = 0, l = materials.length; i < l; i ++ ) {
19561972

19571973
this.addMaterial( materials[ i ] );
19581974

19591975
}
19601976

1977+
return this;
1978+
1979+
}
1980+
1981+
addDefaultMaterials() {
1982+
19611983
// Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
19621984
this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ) );
19631985
this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) );

0 commit comments

Comments
 (0)