three-base 2.0.95 → 2.0.97
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/Grass/Grass.d.ts +8 -0
- package/Grass/Grass.js +38 -0
- package/Grass/grass.jpg +0 -0
- package/Ground1/Ground1.d.ts +11 -0
- package/Ground1/Ground1.js +109 -0
- package/Ground1/floorMap1.png +0 -0
- package/Ground1/floorMap2.png +0 -0
- package/Ground1/floorMap3.png +0 -0
- package/Sky/Sky.d.ts +0 -4
- package/Sky/Sky.js +2 -8
- package/Sky/skyMap.png +0 -0
- package/package.json +3 -2
- package/threeLoader.js +6 -3
- package/Sky/bluesky.jpg +0 -0
- package/Sky/index.d.ts +0 -1
- package/Sky/index.js +0 -1
- package/tsconfig.json +0 -35
package/Grass/Grass.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Mesh, MeshLambertMaterial, PlaneGeometry } from "three";
|
|
2
|
+
export default class Grass extends Mesh {
|
|
3
|
+
constructor();
|
|
4
|
+
geometry: PlaneGeometry;
|
|
5
|
+
map: import("three").Texture;
|
|
6
|
+
material: MeshLambertMaterial;
|
|
7
|
+
setSize(width: number, height: number): void;
|
|
8
|
+
}
|
package/Grass/Grass.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-09-14 22:58:16
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-09-14 23:20:39
|
|
6
|
+
*/
|
|
7
|
+
import { DoubleSide, MathUtils, Mesh, MeshLambertMaterial, PlaneGeometry, RepeatWrapping, TextureLoader, } from "three";
|
|
8
|
+
import grassJPG from "./grass.jpg";
|
|
9
|
+
// 草地Mesh
|
|
10
|
+
export default class Grass extends Mesh {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
geometry = (() => {
|
|
15
|
+
const geometry = new PlaneGeometry(1, 1, 1, 1);
|
|
16
|
+
geometry.rotateX(MathUtils.degToRad(90));
|
|
17
|
+
return geometry;
|
|
18
|
+
})();
|
|
19
|
+
map = (() => {
|
|
20
|
+
const map = new TextureLoader().load(grassJPG);
|
|
21
|
+
map.wrapS = map.wrapT = RepeatWrapping;
|
|
22
|
+
map.repeat.set(1, 1);
|
|
23
|
+
return map;
|
|
24
|
+
})();
|
|
25
|
+
material = (() => {
|
|
26
|
+
const material = new MeshLambertMaterial({
|
|
27
|
+
map: this.map,
|
|
28
|
+
side: DoubleSide,
|
|
29
|
+
});
|
|
30
|
+
return material;
|
|
31
|
+
})();
|
|
32
|
+
// 设置尺寸
|
|
33
|
+
setSize(width, height) {
|
|
34
|
+
this.scale.set(width, 1, height);
|
|
35
|
+
this.map.repeat.set(width, height);
|
|
36
|
+
// this.material.uniforms.size.value.set(width * 0.001, height * 0.001);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/Grass/grass.jpg
ADDED
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BufferGeometry, Camera, Clock, Group, Material, Matrix4, Mesh, PlaneGeometry, Scene, ShaderMaterial, WebGLRenderer } from "three";
|
|
2
|
+
export default class Ground1 extends Mesh {
|
|
3
|
+
tempMatrix: Matrix4;
|
|
4
|
+
constructor();
|
|
5
|
+
renderOrder: number;
|
|
6
|
+
geometry: PlaneGeometry;
|
|
7
|
+
setSize(width: number, height: number): void;
|
|
8
|
+
clock: Clock;
|
|
9
|
+
onBeforeRender: (renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: Group) => void;
|
|
10
|
+
material: ShaderMaterial;
|
|
11
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-09-20 23:06:00
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-08-17 02:16:56
|
|
6
|
+
*/
|
|
7
|
+
import { Clock, Color, DoubleSide, Matrix4, Mesh, PlaneGeometry, ShaderChunk, ShaderMaterial, Vector2, } from "three";
|
|
8
|
+
import { degToRad } from "three/src/math/MathUtils";
|
|
9
|
+
import floorMap1PNG from "./floorMap1.png";
|
|
10
|
+
import floorMap2PNG from "./floorMap2.png";
|
|
11
|
+
import floorMap3PNG from "./floorMap3.png";
|
|
12
|
+
import threeLoader from "../threeLoader";
|
|
13
|
+
// 装饰地板1
|
|
14
|
+
export default class Ground1 extends Mesh {
|
|
15
|
+
tempMatrix = new Matrix4();
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
}
|
|
19
|
+
renderOrder = -1;
|
|
20
|
+
geometry = (() => {
|
|
21
|
+
const geo = new PlaneGeometry(1, 1, 1, 1);
|
|
22
|
+
geo.rotateX(degToRad(-90));
|
|
23
|
+
return geo;
|
|
24
|
+
})();
|
|
25
|
+
// 设置尺寸
|
|
26
|
+
setSize(width, height) {
|
|
27
|
+
this.scale.set(width, 1, height);
|
|
28
|
+
// this.material.uniforms.size.value.set(width * 0.001, height * 0.001);
|
|
29
|
+
}
|
|
30
|
+
clock = new Clock();
|
|
31
|
+
onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
|
|
32
|
+
const elapsedTime = this.clock.getElapsedTime();
|
|
33
|
+
this.material.uniforms.speed.value = (elapsedTime * 0.1) % 0.6;
|
|
34
|
+
this.material.uniforms.speed2.value = ((elapsedTime * 0.1) % 0.6) - 0.1;
|
|
35
|
+
};
|
|
36
|
+
material = new ShaderMaterial({
|
|
37
|
+
uniforms: {
|
|
38
|
+
size: { value: new Vector2(10, 10) },
|
|
39
|
+
speed: { value: 0 },
|
|
40
|
+
speed2: { value: 0 },
|
|
41
|
+
speedColor: { value: new Color("#8D108E") },
|
|
42
|
+
lineColor: { value: new Color("#263C56") },
|
|
43
|
+
map1: { value: threeLoader.getTexture(floorMap1PNG) },
|
|
44
|
+
map2: { value: threeLoader.getTexture(floorMap2PNG) },
|
|
45
|
+
map3: { value: threeLoader.getTexture(floorMap3PNG) }, // 贴图纹理
|
|
46
|
+
},
|
|
47
|
+
vertexShader: `
|
|
48
|
+
${ShaderChunk.common}
|
|
49
|
+
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
50
|
+
varying vec2 vUv;
|
|
51
|
+
void main() {
|
|
52
|
+
vUv = uv;
|
|
53
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
54
|
+
${ShaderChunk.logdepthbuf_vertex}
|
|
55
|
+
}
|
|
56
|
+
`,
|
|
57
|
+
fragmentShader: `
|
|
58
|
+
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
59
|
+
uniform sampler2D map1;
|
|
60
|
+
uniform sampler2D map2;
|
|
61
|
+
uniform sampler2D map3;
|
|
62
|
+
uniform vec2 size;
|
|
63
|
+
uniform vec3 lineColor;
|
|
64
|
+
uniform float speed;
|
|
65
|
+
uniform float speed2;
|
|
66
|
+
uniform vec3 speedColor;
|
|
67
|
+
varying vec2 vUv;
|
|
68
|
+
void main() {
|
|
69
|
+
|
|
70
|
+
// 中心点
|
|
71
|
+
vec2 center = vec2(0.5,0.5);
|
|
72
|
+
|
|
73
|
+
vec4 map1Color = texture2D(map1, fract( vUv * size) );
|
|
74
|
+
|
|
75
|
+
// 格子中心渐变颜色
|
|
76
|
+
if(distance( vUv , center ) < speed){
|
|
77
|
+
map1Color = mix(map1Color, vec4(speedColor, 1.0), clamp((1.0 - (distance(distance( vUv , center ), speed) * 8.0) ) * map1Color.a, 0.0, 1.0 ) );
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
vec4 map2Color = texture2D(map2, fract( vUv * size) );
|
|
81
|
+
|
|
82
|
+
vec4 map3Color = texture2D(map3, fract( vUv * size) );
|
|
83
|
+
|
|
84
|
+
// 正方形装饰中心渐变颜色
|
|
85
|
+
if(distance( vUv , center ) < speed2){
|
|
86
|
+
map3Color = mix(map3Color, map3Color * 3.0, clamp((1.0 - (distance(distance( vUv , center ), speed) * 4.0) ) * map3Color.a, 0.0, 1.0 ) );
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
vec4 mapColor = mix(map1Color, map2Color, map2Color.a);
|
|
90
|
+
|
|
91
|
+
mapColor = mix(mapColor, map3Color, map3Color.a);
|
|
92
|
+
|
|
93
|
+
//添加背景色
|
|
94
|
+
mapColor = mix(mapColor, vec4(lineColor.rgb, 1.0 ), 1.0 - mapColor.a);
|
|
95
|
+
|
|
96
|
+
// 设置透明度
|
|
97
|
+
mapColor.a = 1.0 - (distance( vUv , center ) * 2.0);
|
|
98
|
+
|
|
99
|
+
gl_FragColor = mapColor;
|
|
100
|
+
|
|
101
|
+
${ShaderChunk.logdepthbuf_fragment}
|
|
102
|
+
}
|
|
103
|
+
`,
|
|
104
|
+
depthTest: true,
|
|
105
|
+
depthWrite: true,
|
|
106
|
+
transparent: true,
|
|
107
|
+
side: DoubleSide,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/Sky/Sky.d.ts
CHANGED
package/Sky/Sky.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
8
8
|
import threeLoader from "../threeLoader";
|
|
9
|
-
import
|
|
9
|
+
import skyMapPNG from "./skyMap.png";
|
|
10
10
|
/**
|
|
11
11
|
* 天空球
|
|
12
12
|
*/
|
|
@@ -17,12 +17,6 @@ export default class Sky extends Mesh {
|
|
|
17
17
|
static geometry = new SphereGeometry(5000, 100, 100);
|
|
18
18
|
material = new MeshBasicMaterial({
|
|
19
19
|
side: DoubleSide,
|
|
20
|
-
map: threeLoader.getTexture(
|
|
20
|
+
map: threeLoader.getTexture(skyMapPNG),
|
|
21
21
|
});
|
|
22
|
-
/**
|
|
23
|
-
*设置贴图
|
|
24
|
-
*/
|
|
25
|
-
setMap(src) {
|
|
26
|
-
this.material.map = threeLoader.getTexture(src);
|
|
27
|
-
}
|
|
28
22
|
}
|
package/Sky/skyMap.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-base",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.97",
|
|
4
4
|
"description": "three 3d three-base",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"/**/*.gltf",
|
|
31
31
|
"/**/*.fbx",
|
|
32
32
|
"/**/*.glb",
|
|
33
|
-
"
|
|
33
|
+
"/package.json",
|
|
34
|
+
"/Text3D/gentilis.json",
|
|
34
35
|
"/**/*.wasm"
|
|
35
36
|
],
|
|
36
37
|
"license": "ISC",
|
package/threeLoader.js
CHANGED
|
@@ -22,10 +22,10 @@ import dracoWasmWrapperJS from "./lib/draco/draco_wasm_wrapper.js?url";
|
|
|
22
22
|
import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
|
|
23
23
|
//@ts-ignore
|
|
24
24
|
import axios from "axios";
|
|
25
|
+
import { isArray, isEmpty, isNull, isString, isUndefined } from "lodash";
|
|
26
|
+
import { generateUUID } from "three/src/math/MathUtils";
|
|
25
27
|
import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
|
|
26
28
|
import threeUtils from "./threeUtils";
|
|
27
|
-
import { generateUUID } from "three/src/math/MathUtils";
|
|
28
|
-
import { isEmpty, isString } from "lodash";
|
|
29
29
|
// 加载器
|
|
30
30
|
class ThreeLoader extends EventDispatcher {
|
|
31
31
|
constructor() {
|
|
@@ -181,7 +181,10 @@ class ThreeLoader extends EventDispatcher {
|
|
|
181
181
|
}
|
|
182
182
|
/** 加载模型支持glb,gltf,fbx,stl,obj,usdz,dae,zip */
|
|
183
183
|
async loadModel(url, filename = "") {
|
|
184
|
-
if (
|
|
184
|
+
if ((isString(url) || isArray(url)) &&
|
|
185
|
+
isEmpty(url) &&
|
|
186
|
+
isUndefined(url) &&
|
|
187
|
+
isNull(url)) {
|
|
185
188
|
throw new Error(`loadModel:无效的参数 url=${url}`);
|
|
186
189
|
}
|
|
187
190
|
// 本次需要销毁的bloburl,加载完成后就去销毁本次的文件
|
package/Sky/bluesky.jpg
DELETED
|
Binary file
|
package/Sky/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Sky";
|
package/Sky/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Sky";
|
package/tsconfig.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "esnext",
|
|
4
|
-
"lib": [
|
|
5
|
-
"dom",
|
|
6
|
-
"dom.iterable",
|
|
7
|
-
"esnext"
|
|
8
|
-
],
|
|
9
|
-
"types": [
|
|
10
|
-
"vite/client",
|
|
11
|
-
"node"
|
|
12
|
-
],
|
|
13
|
-
"sourceMap": false,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
"declarationDir": "./",
|
|
16
|
-
"allowJs": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"esModuleInterop": true,
|
|
19
|
-
"allowSyntheticDefaultImports": true,
|
|
20
|
-
"strict": false,
|
|
21
|
-
"forceConsistentCasingInFileNames": true,
|
|
22
|
-
"module": "esnext",
|
|
23
|
-
"moduleResolution": "node",
|
|
24
|
-
"resolveJsonModule": true,
|
|
25
|
-
"isolatedModules": false,
|
|
26
|
-
"noEmit": false,
|
|
27
|
-
"noImplicitAny": false,
|
|
28
|
-
},
|
|
29
|
-
"include": [
|
|
30
|
-
"./",
|
|
31
|
-
],
|
|
32
|
-
"exclude": [
|
|
33
|
-
"./lib/draco"
|
|
34
|
-
]
|
|
35
|
-
}
|