-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path3MFLoader_alpha.patch
More file actions
70 lines (61 loc) · 2.18 KB
/
3MFLoader_alpha.patch
File metadata and controls
70 lines (61 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--- three.js/examples/jsm/loaders/3MFLoader.js.ref 2021-07-26 01:04:58.408999530 +0200
+++ three.js/examples/jsm/loaders/3MFLoader.js 2021-07-26 01:12:16.725813819 +0200
@@ -373,7 +373,16 @@
colorObject.setStyle( color.substring( 0, 7 ) );
colorObject.convertSRGBToLinear(); // color is in sRGB
- colors.push( colorObject.r, colorObject.g, colorObject.b );
+ // process alpha if set
+
+ var alpha = 1.0;
+ if ( color.length === 9 ) {
+
+ alpha = parseInt( color.charAt( 7 ) + color.charAt( 8 ), 16 ) / 255;
+
+ }
+
+ colors.push( colorObject.r, colorObject.g, colorObject.b, alpha );
}
@@ -1042,17 +1051,17 @@
const p2 = ( triangleProperty.p2 !== undefined ) ? triangleProperty.p2 : p1;
const p3 = ( triangleProperty.p3 !== undefined ) ? triangleProperty.p3 : p1;
- colorData.push( colors[ ( p1 * 3 ) + 0 ] );
- colorData.push( colors[ ( p1 * 3 ) + 1 ] );
- colorData.push( colors[ ( p1 * 3 ) + 2 ] );
-
- colorData.push( colors[ ( p2 * 3 ) + 0 ] );
- colorData.push( colors[ ( p2 * 3 ) + 1 ] );
- colorData.push( colors[ ( p2 * 3 ) + 2 ] );
-
- colorData.push( colors[ ( p3 * 3 ) + 0 ] );
- colorData.push( colors[ ( p3 * 3 ) + 1 ] );
- colorData.push( colors[ ( p3 * 3 ) + 2 ] );
+ colorData.push( colors[ ( p1 * 4 ) + 0 ] );
+ colorData.push( colors[ ( p1 * 4 ) + 1 ] );
+ colorData.push( colors[ ( p1 * 4 ) + 2 ] );
+
+ colorData.push( colors[ ( p2 * 4 ) + 0 ] );
+ colorData.push( colors[ ( p2 * 4 ) + 1 ] );
+ colorData.push( colors[ ( p2 * 4 ) + 2 ] );
+
+ colorData.push( colors[ ( p3 * 4 ) + 0 ] );
+ colorData.push( colors[ ( p3 * 4 ) + 1 ] );
+ colorData.push( colors[ ( p3 * 4 ) + 2 ] );
}
@@ -1063,6 +1072,20 @@
const material = new MeshPhongMaterial( { vertexColors: true, flatShading: true } );
+ // Just use the average of all alpha values for now
+ var alpha_sum = 0.0;
+ for ( let i = 0, l = colors.length; i < l; i += 4 ) {
+ alpha_sum += colors[ i + 3 ];
+ }
+ const alpha = alpha_sum / ( colors.length / 4 );
+
+ if ( alpha !== 1.0 ) {
+
+ material.transparent = true;
+ material.opacity = alpha;
+
+ }
+
// mesh
const mesh = new Mesh( geometry, material );