@@ -10,10 +10,7 @@ import {
10
10
Matrix4 ,
11
11
Mesh ,
12
12
MeshStandardMaterial ,
13
- ShaderMaterial ,
14
13
SRGBColorSpace ,
15
- UniformsLib ,
16
- UniformsUtils ,
17
14
Vector3 ,
18
15
Ray
19
16
} from 'three' ;
@@ -45,140 +42,6 @@ const COLOR_SPACE_LDRAW = SRGBColorSpace;
45
42
const _tempVec0 = new Vector3 ( ) ;
46
43
const _tempVec1 = new Vector3 ( ) ;
47
44
48
- class LDrawConditionalLineMaterial extends ShaderMaterial {
49
-
50
- static get type ( ) {
51
-
52
- return 'LDrawConditionalLineMaterial' ;
53
-
54
- }
55
-
56
- constructor ( parameters ) {
57
-
58
- super ( {
59
-
60
- uniforms : UniformsUtils . merge ( [
61
- UniformsLib . fog ,
62
- {
63
- diffuse : {
64
- value : new Color ( )
65
- } ,
66
- opacity : {
67
- value : 1.0
68
- }
69
- }
70
- ] ) ,
71
-
72
- vertexShader : /* glsl */ `
73
- attribute vec3 control0;
74
- attribute vec3 control1;
75
- attribute vec3 direction;
76
- varying float discardFlag;
77
-
78
- #include <common>
79
- #include <color_pars_vertex>
80
- #include <fog_pars_vertex>
81
- #include <logdepthbuf_pars_vertex>
82
- #include <clipping_planes_pars_vertex>
83
- void main() {
84
- #include <color_vertex>
85
-
86
- vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
87
- gl_Position = projectionMatrix * mvPosition;
88
-
89
- // Transform the line segment ends and control points into camera clip space
90
- vec4 c0 = projectionMatrix * modelViewMatrix * vec4( control0, 1.0 );
91
- vec4 c1 = projectionMatrix * modelViewMatrix * vec4( control1, 1.0 );
92
- vec4 p0 = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
93
- vec4 p1 = projectionMatrix * modelViewMatrix * vec4( position + direction, 1.0 );
94
-
95
- c0.xy /= c0.w;
96
- c1.xy /= c1.w;
97
- p0.xy /= p0.w;
98
- p1.xy /= p1.w;
99
-
100
- // Get the direction of the segment and an orthogonal vector
101
- vec2 dir = p1.xy - p0.xy;
102
- vec2 norm = vec2( -dir.y, dir.x );
103
-
104
- // Get control point directions from the line
105
- vec2 c0dir = c0.xy - p1.xy;
106
- vec2 c1dir = c1.xy - p1.xy;
107
-
108
- // If the vectors to the controls points are pointed in different directions away
109
- // from the line segment then the line should not be drawn.
110
- float d0 = dot( normalize( norm ), normalize( c0dir ) );
111
- float d1 = dot( normalize( norm ), normalize( c1dir ) );
112
- discardFlag = float( sign( d0 ) != sign( d1 ) );
113
-
114
- #include <logdepthbuf_vertex>
115
- #include <clipping_planes_vertex>
116
- #include <fog_vertex>
117
- }
118
- ` ,
119
-
120
- fragmentShader : /* glsl */ `
121
- uniform vec3 diffuse;
122
- uniform float opacity;
123
- varying float discardFlag;
124
-
125
- #include <common>
126
- #include <color_pars_fragment>
127
- #include <fog_pars_fragment>
128
- #include <logdepthbuf_pars_fragment>
129
- #include <clipping_planes_pars_fragment>
130
- void main() {
131
-
132
- if ( discardFlag > 0.5 ) discard;
133
-
134
- #include <clipping_planes_fragment>
135
- vec3 outgoingLight = vec3( 0.0 );
136
- vec4 diffuseColor = vec4( diffuse, opacity );
137
- #include <logdepthbuf_fragment>
138
- #include <color_fragment>
139
- outgoingLight = diffuseColor.rgb; // simple shader
140
- gl_FragColor = vec4( outgoingLight, diffuseColor.a );
141
- #include <tonemapping_fragment>
142
- #include <colorspace_fragment>
143
- #include <fog_fragment>
144
- #include <premultiplied_alpha_fragment>
145
- }
146
- ` ,
147
-
148
- } ) ;
149
-
150
- Object . defineProperties ( this , {
151
-
152
- opacity : {
153
- get : function ( ) {
154
-
155
- return this . uniforms . opacity . value ;
156
-
157
- } ,
158
-
159
- set : function ( value ) {
160
-
161
- this . uniforms . opacity . value = value ;
162
-
163
- }
164
- } ,
165
-
166
- color : {
167
- get : function ( ) {
168
-
169
- return this . uniforms . diffuse . value ;
170
-
171
- }
172
- }
173
-
174
- } ) ;
175
-
176
- this . setValues ( parameters ) ;
177
- this . isLDrawConditionalLineMaterial = true ;
178
-
179
- }
180
-
181
- }
182
45
183
46
class ConditionalLineSegments extends LineSegments {
184
47
@@ -1903,19 +1766,19 @@ class LDrawLoader extends Loader {
1903
1766
// This object is a map from file names to paths. It agilizes the paths search. If it is not set then files will be searched by trial and error.
1904
1767
this . fileMap = { } ;
1905
1768
1906
- // Initializes the materials library with default materials
1907
- this . setMaterials ( [ ] ) ;
1908
-
1909
1769
// If this flag is set to true the vertex normals will be smoothed.
1910
1770
this . smoothNormals = true ;
1911
1771
1912
1772
// The path to load parts from the LDraw parts library from.
1913
1773
this . partsLibraryPath = '' ;
1914
1774
1775
+ // this material type must be injected via setConditionalLineMaterial()
1776
+ this . ConditionalLineMaterial = null ;
1777
+
1915
1778
// Material assigned to not available colors for meshes and edges
1916
1779
this . missingColorMaterial = new MeshStandardMaterial ( { name : Loader . DEFAULT_MATERIAL_NAME , color : 0xFF00FF , roughness : 0.3 , metalness : 0 } ) ;
1917
1780
this . missingEdgeColorMaterial = new LineBasicMaterial ( { name : Loader . DEFAULT_MATERIAL_NAME , color : 0xFF00FF } ) ;
1918
- this . missingConditionalEdgeColorMaterial = new LDrawConditionalLineMaterial ( { name : Loader . DEFAULT_MATERIAL_NAME , fog : true , color : 0xFF00FF } ) ;
1781
+ this . missingConditionalEdgeColorMaterial = null ;
1919
1782
this . edgeMaterialCache . set ( this . missingColorMaterial , this . missingEdgeColorMaterial ) ;
1920
1783
this . conditionalEdgeMaterialCache . set ( this . missingEdgeColorMaterial , this . missingConditionalEdgeColorMaterial ) ;
1921
1784
@@ -1928,6 +1791,14 @@ class LDrawLoader extends Loader {
1928
1791
1929
1792
}
1930
1793
1794
+ setConditionalLineMaterial ( type ) {
1795
+
1796
+ this . ConditionalLineMaterial = type ;
1797
+ this . missingConditionalEdgeColorMaterial = new this . ConditionalLineMaterial ( { name : Loader . DEFAULT_MATERIAL_NAME , fog : true , color : 0xFF00FF } ) ;
1798
+ return this ;
1799
+
1800
+ }
1801
+
1931
1802
async preloadMaterials ( url ) {
1932
1803
1933
1804
const fileLoader = new FileLoader ( this . manager ) ;
@@ -1964,6 +1835,9 @@ class LDrawLoader extends Loader {
1964
1835
fileLoader . setWithCredentials ( this . withCredentials ) ;
1965
1836
fileLoader . load ( url , text => {
1966
1837
1838
+ // Initializes the materials library with default materials
1839
+ this . setMaterials ( [ ] ) ;
1840
+
1967
1841
this . partsCache
1968
1842
. parseModel ( text , this . materialLibrary )
1969
1843
. then ( group => {
@@ -2390,8 +2264,14 @@ class LDrawLoader extends Loader {
2390
2264
edgeMaterial . userData . code = code ;
2391
2265
edgeMaterial . name = name + ' - Edge' ;
2392
2266
2267
+ if ( this . ConditionalLineMaterial === null ) {
2268
+
2269
+ throw new Error ( 'THREE.LDrawLoader: ConditionalLineMaterial type must be specificed via .setConditionalLineMaterial().' ) ;
2270
+
2271
+ }
2272
+
2393
2273
// This is the material used for conditional edges
2394
- const conditionalEdgeMaterial = new LDrawConditionalLineMaterial ( {
2274
+ const conditionalEdgeMaterial = new this . ConditionalLineMaterial ( {
2395
2275
2396
2276
fog : true ,
2397
2277
transparent : isTransparent ,
0 commit comments