Skip to content

Commit 2c86fbb

Browse files
committed
Dumb material.clone() for the rest of the materials.
1 parent aadb1d7 commit 2c86fbb

12 files changed

Lines changed: 231 additions & 48 deletions

build/Three.js

Lines changed: 24 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/custom/ThreeCanvas.js

Lines changed: 19 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/custom/ThreeWebGL.js

Lines changed: 23 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/materials/LineBasicMaterial.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
4141

4242
THREE.LineBasicMaterial.prototype.clone = function () {
4343

44-
return new THREE.LineBasicMaterial( this );
44+
var material = new THREE.LineBasicMaterial();
45+
46+
THREE.Material.prototype.clone.call( this, material );
47+
48+
material.color.copy( this.color );
49+
50+
material.linewidth = this.linewidth;
51+
material.linecap = this.linecap;
52+
material.linejoin = this.linejoin;
53+
54+
material.vertexColors = this.vertexColors;
55+
56+
material.fog = this.fog;
57+
58+
return material;
4559

4660
};

src/materials/Material.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ THREE.Material.prototype.setValues = function ( values ) {
4343

4444
for ( var key in values ) {
4545

46-
var value = values[ key ];
47-
4846
if ( this[ key ] !== undefined ) {
4947

50-
this[ key ] = value;
48+
this[ key ] = values[ key ];
5149

5250
}
5351

@@ -57,6 +55,8 @@ THREE.Material.prototype.setValues = function ( values ) {
5755

5856
THREE.Material.prototype.clone = function ( material ) {
5957

58+
if ( material === undefined ) material = new THREE.material()
59+
6060
material.name = this.name;
6161

6262
material.side = this.side;
@@ -83,6 +83,8 @@ THREE.Material.prototype.clone = function ( material ) {
8383

8484
material.visible = this.visible;
8585

86+
return material;
87+
8688
};
8789

8890
THREE.MaterialCount = 0;

src/materials/MeshDepthMaterial.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ THREE.MeshDepthMaterial = function ( parameters ) {
1717

1818
THREE.Material.call( this );
1919

20-
this.shading = THREE.SmoothShading; // doesn't really apply here, normals are not used
21-
2220
this.wireframe = false;
2321
this.wireframeLinewidth = 1;
2422

@@ -30,6 +28,13 @@ THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
3028

3129
THREE.MeshDepthMaterial.prototype.clone = function () {
3230

33-
return new THREE.MeshDepthMaterial( this );
31+
var material = new THREE.LineBasicMaterial();
32+
33+
THREE.Material.prototype.clone.call( this, material );
34+
35+
material.wireframe = this.wireframe;
36+
material.wireframeLinewidth = this.wireframeLinewidth;
37+
38+
return material;
3439

3540
};

src/materials/MeshLambertMaterial.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@ THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
7777

7878
THREE.MeshLambertMaterial.prototype.clone = function () {
7979

80-
return new THREE.MeshLambertMaterial( this );
80+
var material = new THREE.MeshLambertMaterial();
81+
82+
THREE.Material.prototype.clone.call( this, material );
83+
84+
material.color.copy( this.color );
85+
material.ambient.copy( this.ambient );
86+
material.emissive.copy( this.emissive );
87+
88+
material.wrapAround = this.wrapAround;
89+
material.wrapRGB.copy( this.wrapRGB );
90+
91+
material.map = this.map;
92+
93+
material.lightMap = this.lightMap;
94+
95+
material.envMap = this.envMap;
96+
material.combine = this.combine;
97+
material.reflectivity = this.reflectivity;
98+
material.refractionRatio = this.refractionRatio;
99+
100+
material.fog = this.fog;
101+
102+
material.shading = this.shading;
103+
104+
material.wireframe = this.wireframe;
105+
material.wireframeLinewidth = this.wireframeLinewidth;
106+
material.wireframeLinecap = this.wireframeLinecap;
107+
material.wireframeLinejoin = this.wireframeLinejoin;
108+
109+
material.vertexColors = this.vertexColors;
110+
111+
material.skinning = this.skinning;
112+
material.morphTargets = this.morphTargets;
113+
material.morphNormals = this.morphNormals;
114+
115+
return material;
81116

82117
};

src/materials/MeshNormalMaterial.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
3030

3131
THREE.MeshNormalMaterial.prototype.clone = function () {
3232

33-
return new THREE.MeshNormalMaterial( this );
33+
var material = new THREE.MeshNormalMaterial();
34+
35+
THREE.Material.prototype.clone.call( this, material );
36+
37+
material.shading = this.shading;
38+
39+
material.wireframe = this.wireframe;
40+
material.wireframeLinewidth = this.wireframeLinewidth;
41+
42+
return material;
3443

3544
};

src/materials/MeshPhongMaterial.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,46 @@ THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
8484

8585
THREE.MeshPhongMaterial.prototype.clone = function () {
8686

87-
return new THREE.MeshPhongMaterial( this );
87+
var material = new THREE.MeshPhongMaterial();
88+
89+
THREE.Material.prototype.clone.call( this, material );
90+
91+
material.color.copy( this.color );
92+
material.ambient.copy( this.ambient );
93+
material.emissive.copy( this.emissive );
94+
material.specular.copy( this.specular );
95+
material.shininess = this.shininess;
96+
97+
material.metal = this.metal;
98+
material.perPixel = this.perPixel;
99+
100+
material.wrapAround = this.wrapAround;
101+
material.wrapRGB.copy( this.wrapRGB );
102+
103+
material.map = this.map;
104+
105+
material.lightMap = this.lightMap;
106+
107+
material.envMap = this.envMap;
108+
material.combine = this.combine;
109+
material.reflectivity = this.reflectivity;
110+
material.refractionRatio = this.refractionRatio;
111+
112+
material.fog = this.fog;
113+
114+
material.shading = this.shading;
115+
116+
material.wireframe = this.wireframe;
117+
material.wireframeLinewidth = this.wireframeLinewidth;
118+
material.wireframeLinecap = this.wireframeLinecap;
119+
material.wireframeLinejoin = this.wireframeLinejoin;
120+
121+
material.vertexColors = this.vertexColors;
122+
123+
material.skinning = this.skinning;
124+
material.morphTargets = this.morphTargets;
125+
material.morphNormals = this.morphNormals;
126+
127+
return material;
88128

89129
};

src/materials/ParticleBasicMaterial.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ THREE.ParticleBasicMaterial.prototype = Object.create( THREE.Material.prototype
4141

4242
THREE.ParticleBasicMaterial.prototype.clone = function () {
4343

44-
return new THREE.ParticleBasicMaterial( this );
44+
var material = new THREE.ParticleBasicMaterial();
45+
46+
THREE.Material.prototype.clone.call( this, material );
47+
48+
material.color.copy( this.color );
49+
50+
material.map = this.map;
51+
52+
material.size = this.size;
53+
material.sizeAttenuation = this.sizeAttenuation;
54+
55+
material.vertexColors = this.vertexColors;
56+
57+
material.fog = this.fog;
58+
59+
return material;
4560

4661
};

0 commit comments

Comments
 (0)