easy-three-utils 0.0.2 → 0.0.31

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.ts CHANGED
@@ -3,9 +3,9 @@ import { useMark, EMarkDefaultStyle } from './src/common/useMark'
3
3
  import { useLine2 } from './src/common/useLine2'
4
4
  import { useLocationCalculator } from './src/common/useLocationCalculator'
5
5
  import { Animation } from './src/common/useTween'
6
+ import { useWeather, EWeatherType } from './src/common/useWeather'
6
7
  import { useThree } from './src/core/main'
7
8
 
8
-
9
9
  import type { IPathItem } from './src/common/useTween'
10
10
 
11
11
  export {
@@ -18,7 +18,10 @@ export {
18
18
 
19
19
  useLocationCalculator,
20
20
 
21
- Animation
21
+ Animation,
22
+
23
+ useWeather,
24
+ EWeatherType
22
25
  }
23
26
 
24
27
  export type {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-three-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.31",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -9,4 +9,4 @@
9
9
  "license": "ISC",
10
10
  "types": "./index.d.ts",
11
11
  "description": ""
12
- }
12
+ }
@@ -7,9 +7,8 @@ import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
7
7
  import { TGALoader } from 'three/examples/jsm/loaders/TGALoader.js'
8
8
  import { TilesRenderer } from '../tileRenderer'
9
9
  import { GoogleCloudAuthPlugin } from '../tileRenderer/plugins';
10
- import { enableDefaultEvent, EDefaultEvent } from '../core'
10
+ import { enableDefaultEvent, EDefaultEvent } from '../../index'
11
11
 
12
- //todo 1.曝光
13
12
  interface IThreeLoaders {
14
13
  GLTFLoader: GLTFLoader | null,
15
14
  DRACOLoader: DRACOLoader | null,
@@ -159,7 +158,6 @@ const useLoader = () => {
159
158
  callback && callback(tilesRenderer, clear)
160
159
  }
161
160
 
162
- //todo 1.多动画封装 2.动画库封装 3.多动画加载时间差 4.同模型克隆
163
161
  const useMixer: (object: THREE.Object3D, animate: THREE.AnimationClip) => { mixer: THREE.AnimationMixer, action: THREE.AnimationAction } = (object: THREE.Object3D, animate: THREE.AnimationClip) => {
164
162
  const mixer = new THREE.AnimationMixer(object)
165
163
  const action = mixer.clipAction(animate);
@@ -0,0 +1,71 @@
1
+ import * as THREE from 'three'
2
+ import { snowVertexShader, snowFragmentShader } from '../shader/snow'
3
+
4
+ enum EWeatherType {
5
+ NORMAL = 'normal',
6
+ SNOW = 'snow'
7
+ }
8
+
9
+ const useWeather = () => {
10
+ const snowGroup = new THREE.Group()
11
+ snowGroup.name = 'weather_' + 'snow_' + new Date().getTime()
12
+ let globalConfig: ITHREEConfiguration | null = null
13
+
14
+ const initSnow = (config: ITHREEConfiguration) => {
15
+ const { width, height } = config.renderer!.getDrawingBufferSize(
16
+ new THREE.Vector2()
17
+ );
18
+
19
+ const shader = new THREE.ShaderMaterial({
20
+ vertexShader: snowVertexShader,
21
+ fragmentShader: snowFragmentShader,
22
+ uniforms: {
23
+ iResolution: { value: new THREE.Vector2(width, height) },
24
+ iTime: { value: 0 }
25
+ },
26
+ });
27
+
28
+ const plane = new THREE.Mesh(new THREE.PlaneGeometry(1000, 1000), shader);
29
+ plane.name = 'snowPlane'
30
+ plane.material.transparent = true
31
+ plane.onBeforeRender = () => {
32
+ shader.uniforms.iTime.value += 0.01;
33
+ };
34
+
35
+ config.control?.addEventListener('change', () => {
36
+ const plane = config.scene?.getObjectByName('snowPlane')
37
+ if (plane) {
38
+ plane.position.copy(config.camera!.position);
39
+ plane.rotation.copy(config.camera!.rotation);
40
+ plane.translateZ(-10);
41
+ }
42
+ })
43
+
44
+ snowGroup.add(plane)
45
+ }
46
+
47
+ const updateWeatherEffect = (type: EWeatherType, config: ITHREEConfiguration) => {
48
+ if (!globalConfig) {
49
+ globalConfig = config
50
+ initSnow(config)
51
+ }
52
+
53
+ switch (type) {
54
+ case EWeatherType.NORMAL:
55
+ config.scene.remove(snowGroup)
56
+ break;
57
+ case EWeatherType.SNOW:
58
+ config.scene.add(snowGroup)
59
+ break;
60
+ }
61
+ }
62
+
63
+ return {
64
+ updateWeatherEffect
65
+ }
66
+ }
67
+
68
+ export {
69
+ useWeather,
70
+ EWeatherType
71
+ }
package/src/core/main.ts CHANGED
@@ -122,7 +122,6 @@ const useThree = () => {
122
122
  succeededCallback && succeededCallback(threeConfiguration)
123
123
  }
124
124
 
125
- //todo 设置参数 光源辅助线
126
125
  const setScene = (options: ITHREEOptions) => {
127
126
  threeConfiguration.scene?.add(threeConfiguration.light.ambient!)
128
127
  threeConfiguration.scene?.add(threeConfiguration.light.directional.light!)
@@ -0,0 +1,48 @@
1
+ const snowVertexShader = `
2
+ varying vec2 vUv;
3
+ void main() {
4
+ vUv = uv;
5
+ vec4 viewPosition = modelViewMatrix * vec4(position, 1.0);
6
+ gl_Position = projectionMatrix * viewPosition;
7
+ }`
8
+
9
+ const snowFragmentShader = `
10
+ varying vec2 vUv;
11
+ uniform vec3 iResolution;
12
+ uniform float iTime;
13
+ void main()
14
+ {
15
+ float snow = 0.0;
16
+ float gradient = (1.0-float(gl_FragCoord.y / iResolution.x))*0.4;
17
+ float random = fract(sin(dot(gl_FragCoord.xy,vec2(12.9898,78.233)))* 43758.5453);
18
+ for(int k=0;k<6;k++){
19
+ for(int i=0;i<12;i++){
20
+ float cellSize = 2.0 + (float(i)*3.0);
21
+ float downSpeed = 0.3+(sin(iTime*0.4+float(k+i*20))+1.0)*0.00008;
22
+ vec2 uv = (gl_FragCoord.xy / iResolution.x)+vec2(0.01*sin((iTime+float(k*6185))*0.6+float(i))*(5.0/float(i)),downSpeed*(iTime+float(k*1352))*(1.0/float(i)));
23
+ vec2 uvStep = (ceil((uv)*cellSize-vec2(0.5,0.5))/cellSize);
24
+ float x = fract(sin(dot(uvStep.xy,vec2(12.9898+float(k)*12.0,78.233+float(k)*315.156)))* 43758.5453+float(k)*12.0)-0.5;
25
+ float y = fract(sin(dot(uvStep.xy,vec2(62.2364+float(k)*23.0,94.674+float(k)*95.0)))* 62159.8432+float(k)*12.0)-0.5;
26
+
27
+ float randomMagnitude1 = sin(iTime*2.5)*0.7/cellSize;
28
+ float randomMagnitude2 = cos(iTime*2.5)*0.7/cellSize;
29
+
30
+ float d = 5.0*distance((uvStep.xy + vec2(x*sin(y),y)*randomMagnitude1 + vec2(y,x)*randomMagnitude2),uv.xy);
31
+
32
+ float omiVal = fract(sin(dot(uvStep.xy,vec2(32.4691,94.615)))* 31572.1684);
33
+ if(omiVal<0.08?true:false){
34
+ float newd = (x+1.0)*0.4*clamp(1.9-d*(15.0+(x*6.3))*(cellSize/1.4),0.0,1.0);
35
+ /*snow += d<(0.08+(x*0.3))/(cellSize/1.4)?
36
+ newd
37
+ :newd;*/
38
+ snow += newd;
39
+ }
40
+ }
41
+ }
42
+ gl_FragColor = vec4(snow)+gradient*vec4(0.4,0.8,1.0,0.0) + random*0.01;
43
+ }`
44
+
45
+ export {
46
+ snowVertexShader,
47
+ snowFragmentShader
48
+ }