@poggi/three-geojson 0.0.1-alpha.0 → 0.0.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -27,11 +27,139 @@ var __privateMethod = (obj, member, method) => {
27
27
  return method;
28
28
  };
29
29
  var _projection, _depth, _baseRenderOrder, _getLinePoints, getLinePoints_fn, _createExtrudeMesh, createExtrudeMesh_fn;
30
- import { Object3D, Vector3, Shape, ExtrudeGeometry, Mesh } from "three";
30
+ import { Color, ShaderMaterial, FrontSide, MeshBasicMaterial, Object3D, Vector3, Shape, ExtrudeGeometry, Mesh } from "three";
31
31
  import * as d3 from "d3";
32
- import { ColorSweepSideMaterial } from "./types.js";
33
- import { MapSweepSideMaterial } from "./types.js";
34
- import { useColorSweepSideMaterial, useMapSweepSideMaterial } from "./sideMaterial.js";
32
+ const ColorSweepSideMaterial = 0;
33
+ const MapSweepSideMaterial = 1;
34
+ function useColorSweepSideMaterial(depth, options = {}) {
35
+ if (!options.sweepSpeed)
36
+ options.sweepSpeed = 0.01;
37
+ if (!options.sweepLength)
38
+ options.sweepLength = 0.5;
39
+ if (!options.sweepInterval)
40
+ options.sweepInterval = 1;
41
+ const max = depth + options.sweepInterval + options.sweepLength;
42
+ const uniforms = {
43
+ color1: {
44
+ value: options.color1 || new Color("#3fdef3")
45
+ },
46
+ color2: {
47
+ value: options.color2 || new Color("#1668c6")
48
+ },
49
+ //光带当前的位置
50
+ height: {
51
+ value: -1
52
+ },
53
+ //光带颜色
54
+ glowColor: {
55
+ value: options.sweepColor || new Color("#90f2ff")
56
+ }
57
+ };
58
+ const material = new ShaderMaterial({
59
+ side: FrontSide,
60
+ uniforms,
61
+ vertexShader: `
62
+ varying vec2 vUv;
63
+ varying float v_pz;
64
+ void main() {
65
+ vUv = uv;
66
+ v_pz = position.z;
67
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
68
+ }
69
+ `,
70
+ fragmentShader: `
71
+ uniform vec3 color1;
72
+ uniform vec3 color2;
73
+ varying vec2 vUv;
74
+ uniform float height;
75
+ uniform vec3 glowColor;
76
+ varying float v_pz;
77
+ float plot(float pct){
78
+ return smoothstep(pct - ${options.sweepLength}, pct, v_pz) - smoothstep(pct, pct + 0.02, v_pz);
79
+ }
80
+ void main() {
81
+ gl_FragColor = vec4(mix(color1, color2, vUv.y), 1.0);
82
+
83
+ float f1 = plot(height);
84
+ gl_FragColor = mix(gl_FragColor,vec4(glowColor,1),f1);
85
+ }
86
+ `
87
+ });
88
+ const render = function() {
89
+ uniforms.height.value += options.sweepSpeed;
90
+ if (uniforms.height.value > max) {
91
+ uniforms.height.value = -1;
92
+ }
93
+ };
94
+ return {
95
+ material,
96
+ render
97
+ };
98
+ }
99
+ function useMapSweepSideMaterial(options = {}) {
100
+ if (!options.sweepSpeed)
101
+ options.sweepSpeed = 0.01;
102
+ const material = new MeshBasicMaterial({
103
+ color: 16777215,
104
+ map: options.map,
105
+ side: FrontSide
106
+ });
107
+ material.onBeforeCompile = function(shader) {
108
+ shader.uniforms = {
109
+ ...shader.uniforms,
110
+ color1: {
111
+ value: options.color1 || new Color("#3fdef3")
112
+ },
113
+ color2: {
114
+ value: options.color2 || new Color("#3fdef3")
115
+ }
116
+ };
117
+ shader.vertexShader = shader.vertexShader.replace(
118
+ "void main() {",
119
+ `
120
+ attribute float alpha;
121
+ varying vec3 vPosition;
122
+ varying float vAlpha;
123
+ void main() {
124
+ vAlpha = alpha;
125
+ vPosition = position;
126
+ `
127
+ );
128
+ shader.fragmentShader = shader.fragmentShader.replace(
129
+ "void main() {",
130
+ `
131
+ varying vec3 vPosition;
132
+ varying float vAlpha;
133
+ uniform vec3 color1;
134
+ uniform vec3 color2;
135
+ void main() {
136
+ `
137
+ );
138
+ shader.fragmentShader = shader.fragmentShader.replace(
139
+ "#include <opaque_fragment>",
140
+ `
141
+ #ifdef OPAQUE
142
+ diffuseColor.a = 1.0;
143
+ #endif
144
+ #ifdef USE_TRANSMISSION
145
+ diffuseColor.a *= transmissionAlpha + 0.1;
146
+ #endif
147
+ vec3 gradient = mix(color2, color1, vPosition.z / 1.2);
148
+ outgoingLight = outgoingLight * gradient;
149
+ gl_FragColor = vec4(outgoingLight, diffuseColor.a);
150
+ `
151
+ );
152
+ };
153
+ const render = function() {
154
+ if (options.map) {
155
+ options.map.offset.y += options.sweepSpeed;
156
+ }
157
+ };
158
+ return {
159
+ material,
160
+ render
161
+ };
162
+ }
35
163
  const generateUVs = function(geometry, minX, minY, dx, dy) {
36
164
  const position = geometry.attributes.position.array;
37
165
  const uv = geometry.attributes.uv.array;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poggi/three-geojson",
3
- "version": "0.0.1-alpha.0",
3
+ "version": "0.0.1-alpha.1",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "description": "三维Geojson类",
package/sideMaterial.js DELETED
@@ -1,134 +0,0 @@
1
- import { Color, ShaderMaterial, FrontSide, MeshBasicMaterial } from "three";
2
- function useColorSweepSideMaterial(depth, options = {}) {
3
- if (!options.sweepSpeed)
4
- options.sweepSpeed = 0.01;
5
- if (!options.sweepLength)
6
- options.sweepLength = 0.5;
7
- if (!options.sweepInterval)
8
- options.sweepInterval = 1;
9
- const max = depth + options.sweepInterval + options.sweepLength;
10
- const uniforms = {
11
- color1: {
12
- value: options.color1 || new Color("#3fdef3")
13
- },
14
- color2: {
15
- value: options.color2 || new Color("#1668c6")
16
- },
17
- //光带当前的位置
18
- height: {
19
- value: -1
20
- },
21
- //光带颜色
22
- glowColor: {
23
- value: options.sweepColor || new Color("#90f2ff")
24
- }
25
- };
26
- const material = new ShaderMaterial({
27
- side: FrontSide,
28
- uniforms,
29
- vertexShader: `
30
- varying vec2 vUv;
31
- varying float v_pz;
32
- void main() {
33
- vUv = uv;
34
- v_pz = position.z;
35
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
36
- }
37
- `,
38
- fragmentShader: `
39
- uniform vec3 color1;
40
- uniform vec3 color2;
41
- varying vec2 vUv;
42
- uniform float height;
43
- uniform vec3 glowColor;
44
- varying float v_pz;
45
- float plot(float pct){
46
- return smoothstep(pct - ${options.sweepLength}, pct, v_pz) - smoothstep(pct, pct + 0.02, v_pz);
47
- }
48
- void main() {
49
- gl_FragColor = vec4(mix(color1, color2, vUv.y), 1.0);
50
-
51
- float f1 = plot(height);
52
- gl_FragColor = mix(gl_FragColor,vec4(glowColor,1),f1);
53
- }
54
- `
55
- });
56
- const render = function() {
57
- uniforms.height.value += options.sweepSpeed;
58
- if (uniforms.height.value > max) {
59
- uniforms.height.value = -1;
60
- }
61
- };
62
- return {
63
- material,
64
- render
65
- };
66
- }
67
- function useMapSweepSideMaterial(options = {}) {
68
- if (!options.sweepSpeed)
69
- options.sweepSpeed = 0.01;
70
- const material = new MeshBasicMaterial({
71
- color: 16777215,
72
- map: options.map,
73
- side: FrontSide
74
- });
75
- material.onBeforeCompile = function(shader) {
76
- shader.uniforms = {
77
- ...shader.uniforms,
78
- color1: {
79
- value: options.color1 || new Color("#3fdef3")
80
- },
81
- color2: {
82
- value: options.color2 || new Color("#3fdef3")
83
- }
84
- };
85
- shader.vertexShader = shader.vertexShader.replace(
86
- "void main() {",
87
- `
88
- attribute float alpha;
89
- varying vec3 vPosition;
90
- varying float vAlpha;
91
- void main() {
92
- vAlpha = alpha;
93
- vPosition = position;
94
- `
95
- );
96
- shader.fragmentShader = shader.fragmentShader.replace(
97
- "void main() {",
98
- `
99
- varying vec3 vPosition;
100
- varying float vAlpha;
101
- uniform vec3 color1;
102
- uniform vec3 color2;
103
- void main() {
104
- `
105
- );
106
- shader.fragmentShader = shader.fragmentShader.replace(
107
- "#include <opaque_fragment>",
108
- `
109
- #ifdef OPAQUE
110
- diffuseColor.a = 1.0;
111
- #endif
112
- #ifdef USE_TRANSMISSION
113
- diffuseColor.a *= transmissionAlpha + 0.1;
114
- #endif
115
- vec3 gradient = mix(color2, color1, vPosition.z / 1.2);
116
- outgoingLight = outgoingLight * gradient;
117
- gl_FragColor = vec4(outgoingLight, diffuseColor.a);
118
- `
119
- );
120
- };
121
- const render = function() {
122
- if (options.map) {
123
- options.map.offset.y += options.sweepSpeed;
124
- }
125
- };
126
- return {
127
- material,
128
- render
129
- };
130
- }
131
- export {
132
- useColorSweepSideMaterial,
133
- useMapSweepSideMaterial
134
- };
package/types.js DELETED
@@ -1,6 +0,0 @@
1
- const ColorSweepSideMaterial = 0;
2
- const MapSweepSideMaterial = 1;
3
- export {
4
- ColorSweepSideMaterial,
5
- MapSweepSideMaterial
6
- };