easy-threesdk 1.0.3 → 1.0.5
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 +122 -44
- package/loader/WaterMaterial/index.js +35 -36
- package/loader/WaterMaterial/resource/textures/waternormals.jpg +0 -0
- package/package.json +1 -1
- package/plugins/LabelControl.js +566 -92
- package/plugins/ModelControl.js +67 -58
- package/tools/index.js +11 -4
- package/loader/WaterMaterial/WaterEffect.js +0 -255
- package/loader/WaterMaterial/resource/shaders/caustics/fragment.glsl +0 -24
- package/loader/WaterMaterial/resource/shaders/caustics/vertex.glsl +0 -34
- package/loader/WaterMaterial/resource/shaders/debug/fragment.glsl +0 -12
- package/loader/WaterMaterial/resource/shaders/debug/vertex.glsl +0 -10
- package/loader/WaterMaterial/resource/shaders/pool/fragment.glsl +0 -17
- package/loader/WaterMaterial/resource/shaders/pool/vertex.glsl +0 -16
- package/loader/WaterMaterial/resource/shaders/simulation/drop_fragment.glsl +0 -22
- package/loader/WaterMaterial/resource/shaders/simulation/normal_fragment.glsl +0 -19
- package/loader/WaterMaterial/resource/shaders/simulation/update_fragment.glsl +0 -33
- package/loader/WaterMaterial/resource/shaders/simulation/vertex.glsl +0 -9
- package/loader/WaterMaterial/resource/shaders/utils.glsl +0 -60
- package/loader/WaterMaterial/resource/shaders/water/fragment.glsl +0 -69
- package/loader/WaterMaterial/resource/shaders/water/vertex.glsl +0 -24
- package/loader/WaterMaterial/resource/tiles.jpg +0 -0
- package/loader/WaterMaterial/resource/vite.svg +0 -1
- package/loader/WaterMaterial/resource/xneg.jpg +0 -0
- package/loader/WaterMaterial/resource/xpos.jpg +0 -0
- package/loader/WaterMaterial/resource/ypos.jpg +0 -0
- package/loader/WaterMaterial/resource/zneg.jpg +0 -0
- package/loader/WaterMaterial/resource/zpos.jpg +0 -0
package/index.js
CHANGED
|
@@ -165,6 +165,7 @@ class ThreeSdk {
|
|
|
165
165
|
this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
|
166
166
|
this.renderer.setSize(width, height);
|
|
167
167
|
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
168
|
+
|
|
168
169
|
this.container.appendChild(this.renderer.domElement);
|
|
169
170
|
|
|
170
171
|
//初始化控制器
|
|
@@ -557,20 +558,20 @@ class ThreeSdk {
|
|
|
557
558
|
textureLoader.load(
|
|
558
559
|
textureImage,
|
|
559
560
|
(texture) => {
|
|
560
|
-
console.log("✅ 全景图片加载成功!");
|
|
561
|
-
console.log(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
);
|
|
561
|
+
// console.log("✅ 全景图片加载成功!");
|
|
562
|
+
// console.log(
|
|
563
|
+
// "图片尺寸:",
|
|
564
|
+
// texture.image.width,
|
|
565
|
+
// "x",
|
|
566
|
+
// texture.image.height
|
|
567
|
+
// );
|
|
567
568
|
//创建3d场景
|
|
568
569
|
|
|
569
570
|
//-------------------- 方法1:使用 EquirectangularReflectionMapping + 翻转X轴
|
|
570
571
|
|
|
571
|
-
console.log(
|
|
572
|
-
|
|
573
|
-
);
|
|
572
|
+
// console.log(
|
|
573
|
+
// "🔧 使用方法1: EquirectangularReflectionMapping + scale(1,-1,-1)"
|
|
574
|
+
// );
|
|
574
575
|
|
|
575
576
|
texture.mapping = THREE.EquirectangularReflectionMapping;
|
|
576
577
|
texture.minFilter = THREE.LinearFilter;
|
|
@@ -606,17 +607,17 @@ class ThreeSdk {
|
|
|
606
607
|
|
|
607
608
|
this.scene.add(this._PanoramaSphere);
|
|
608
609
|
|
|
609
|
-
console.log("✅ 全景球体创建成功!");
|
|
610
|
-
console.log("球体位置:", this._PanoramaSphere.position);
|
|
611
|
-
console.log("相机位置:", this.camera.position);
|
|
612
|
-
console.log("材质配置:", {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
});
|
|
610
|
+
// console.log("✅ 全景球体创建成功!");
|
|
611
|
+
// console.log("球体位置:", this._PanoramaSphere.position);
|
|
612
|
+
// console.log("相机位置:", this.camera.position);
|
|
613
|
+
// console.log("材质配置:", {
|
|
614
|
+
// hasTexture: !!this._PanoramaSphere.material.map,
|
|
615
|
+
// side: this._PanoramaSphere.material.side,
|
|
616
|
+
// mapping: texture.mapping,
|
|
617
|
+
// textureSize: texture.image
|
|
618
|
+
// ? `${texture.image.width}x${texture.image.height}`
|
|
619
|
+
// : "未知",
|
|
620
|
+
// });
|
|
620
621
|
|
|
621
622
|
// 确保相机朝向正确
|
|
622
623
|
// this.camera.lookAt(0, 0, -1);
|
|
@@ -625,11 +626,11 @@ class ThreeSdk {
|
|
|
625
626
|
// 加载进度
|
|
626
627
|
if (progress.total > 0) {
|
|
627
628
|
const percent = (progress.loaded / progress.total) * 100;
|
|
628
|
-
console.log("加载进度:", percent.toFixed(2) + "%");
|
|
629
|
+
// console.log("加载进度:", percent.toFixed(2) + "%");
|
|
629
630
|
}
|
|
630
631
|
},
|
|
631
632
|
(error) => {
|
|
632
|
-
console.error("❌ 全景图片加载失败:", error);
|
|
633
|
+
// console.error("❌ 全景图片加载失败:", error);
|
|
633
634
|
document.getElementById("loading").textContent =
|
|
634
635
|
"图片加载失败,请检查路径: ../resource/sence/citrus_orchard_road_puresky.jpg";
|
|
635
636
|
}
|
|
@@ -668,20 +669,20 @@ class ThreeSdk {
|
|
|
668
669
|
|
|
669
670
|
// 允许用户从各个角度查看(移除垂直角度限制)
|
|
670
671
|
this.controls.maxPolarAngle = Math.PI; // 允许从下方查看
|
|
671
|
-
console.log(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
);
|
|
678
|
-
console.log(
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
);
|
|
672
|
+
// console.log(
|
|
673
|
+
// ` 相机位置: (${this.camera.position.x.toFixed(
|
|
674
|
+
// 2
|
|
675
|
+
// )}, ${this.camera.position.y.toFixed(
|
|
676
|
+
// 2
|
|
677
|
+
// )}, ${this.camera.position.z.toFixed(2)})`
|
|
678
|
+
// );
|
|
679
|
+
// console.log(
|
|
680
|
+
// ` 控制器目标: (${this.controls.target.x.toFixed(
|
|
681
|
+
// 2
|
|
682
|
+
// )}, ${this.controls.target.y.toFixed(
|
|
683
|
+
// 2
|
|
684
|
+
// )}, ${this.controls.target.z.toFixed(2)})`
|
|
685
|
+
// );
|
|
685
686
|
console.log(`💡 现在可以用鼠标拖拽围绕相机自身旋转查看四周,滚轮缩放`);
|
|
686
687
|
}
|
|
687
688
|
|
|
@@ -752,13 +753,13 @@ class ThreeSdk {
|
|
|
752
753
|
this.camera.position.y = this._RoamConfig.cameraHeight;
|
|
753
754
|
}
|
|
754
755
|
|
|
755
|
-
console.log("✅ 进入视角漫游模式");
|
|
756
|
-
console.log("📍 当前相机位置:", this.camera.position);
|
|
757
|
-
console.log("⌨️ 操作说明:");
|
|
758
|
-
console.log(" • 鼠标悬停地面显示圆圈");
|
|
759
|
-
console.log(" • 点击地面跳转视角");
|
|
760
|
-
console.log(" • WASD/方向键移动");
|
|
761
|
-
console.log(" • 鼠标拖拽改变朝向");
|
|
756
|
+
// console.log("✅ 进入视角漫游模式");
|
|
757
|
+
// console.log("📍 当前相机位置:", this.camera.position);
|
|
758
|
+
// console.log("⌨️ 操作说明:");
|
|
759
|
+
// console.log(" • 鼠标悬停地面显示圆圈");
|
|
760
|
+
// console.log(" • 点击地面跳转视角");
|
|
761
|
+
// console.log(" • WASD/方向键移动");
|
|
762
|
+
// console.log(" • 鼠标拖拽改变朝向");
|
|
762
763
|
}
|
|
763
764
|
|
|
764
765
|
exitRoamMode() {
|
|
@@ -784,6 +785,83 @@ class ThreeSdk {
|
|
|
784
785
|
return threeGroup;
|
|
785
786
|
}
|
|
786
787
|
|
|
788
|
+
/**
|
|
789
|
+
* 获取 mesh 的信息并返回 JSON 对象
|
|
790
|
+
* @param {THREE.Mesh} mesh - 要获取信息的 mesh
|
|
791
|
+
* @returns {Object} 包含位置、旋转、缩放信息的 JSON 对象
|
|
792
|
+
*/
|
|
793
|
+
getMeshInfo(mesh) {
|
|
794
|
+
if (!mesh) {
|
|
795
|
+
return null;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const info = {
|
|
799
|
+
position: {
|
|
800
|
+
x: mesh.position.x,
|
|
801
|
+
y: mesh.position.y,
|
|
802
|
+
z: mesh.position.z,
|
|
803
|
+
},
|
|
804
|
+
rotation: {
|
|
805
|
+
x: mesh.rotation.x,
|
|
806
|
+
y: mesh.rotation.y,
|
|
807
|
+
z: mesh.rotation.z,
|
|
808
|
+
},
|
|
809
|
+
scale: {
|
|
810
|
+
x: mesh.scale.x,
|
|
811
|
+
y: mesh.scale.y,
|
|
812
|
+
z: mesh.scale.z,
|
|
813
|
+
},
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
return info;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* 将 JSON 信息应用到 mesh
|
|
821
|
+
* @param {THREE.Mesh} mesh - 要应用信息的 mesh
|
|
822
|
+
* @param {Object} infoJson - 包含位置、旋转、缩放信息的 JSON 对象
|
|
823
|
+
*/
|
|
824
|
+
applyMeshInfo(mesh, infoJson) {
|
|
825
|
+
if (!mesh || !infoJson) {
|
|
826
|
+
console.warn("⚠️ applyMeshInfo: mesh 或 infoJson 为空");
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// 应用位置
|
|
831
|
+
if (infoJson.position) {
|
|
832
|
+
mesh.position.set(
|
|
833
|
+
infoJson.position.x || 0,
|
|
834
|
+
infoJson.position.y || 0,
|
|
835
|
+
infoJson.position.z || 0
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// 应用旋转(弧度制)
|
|
840
|
+
if (infoJson.rotation) {
|
|
841
|
+
mesh.rotation.set(
|
|
842
|
+
infoJson.rotation.x || 0,
|
|
843
|
+
infoJson.rotation.y || 0,
|
|
844
|
+
infoJson.rotation.z || 0
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// 应用缩放
|
|
849
|
+
if (infoJson.scale) {
|
|
850
|
+
mesh.scale.set(
|
|
851
|
+
infoJson.scale.x || 1,
|
|
852
|
+
infoJson.scale.y || 1,
|
|
853
|
+
infoJson.scale.z || 1
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// 如果当前选中了该 mesh,更新 TransformControls
|
|
858
|
+
if (selectedMesh === mesh && transformControls) {
|
|
859
|
+
transformControls.updateMatrixWorld();
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// console.log("✅ 信息已应用到 mesh:", mesh.userData.name || "未命名对象");
|
|
863
|
+
}
|
|
864
|
+
|
|
787
865
|
/**
|
|
788
866
|
* 将相机平滑移动到指定位置,并可以围绕位置旋转查看
|
|
789
867
|
* @param {THREE.Vector3} position - 标签的3D位置
|
|
@@ -1,36 +1,35 @@
|
|
|
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
|
-
}
|
|
1
|
+
import { Water } from "three/examples/jsm/objects/Water.js";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import waterNormalMap from "./resource/textures/waternormals.jpg";
|
|
4
|
+
function createWaterLoader(scene) {
|
|
5
|
+
// 创建 PlaneGeometry 网格
|
|
6
|
+
const planeGeometry = new THREE.PlaneGeometry(10, 10);
|
|
7
|
+
|
|
8
|
+
const planeMesh = new Water(planeGeometry, {
|
|
9
|
+
textureWidth: 512,
|
|
10
|
+
textureHeight: 512,
|
|
11
|
+
waterNormals: new THREE.TextureLoader().load(
|
|
12
|
+
waterNormalMap,
|
|
13
|
+
function (texture) {
|
|
14
|
+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
15
|
+
}
|
|
16
|
+
),
|
|
17
|
+
sunDirection: new THREE.Vector3(),
|
|
18
|
+
sunColor: 0xffffff,
|
|
19
|
+
waterColor: 0x001e0f,
|
|
20
|
+
distortionScale: 3.7,
|
|
21
|
+
fog: scene.fog !== undefined,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
planeMesh.rotation.x = -Math.PI / 2;
|
|
25
|
+
|
|
26
|
+
function animate() {
|
|
27
|
+
planeMesh.material.uniforms["time"].value += 1.0 / 60.0;
|
|
28
|
+
|
|
29
|
+
requestAnimationFrame(animate);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
animate();
|
|
33
|
+
return planeMesh;
|
|
34
|
+
}
|
|
35
|
+
export default createWaterLoader;
|
|
Binary file
|