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.
Files changed (28) hide show
  1. package/index.js +122 -44
  2. package/loader/WaterMaterial/index.js +35 -36
  3. package/loader/WaterMaterial/resource/textures/waternormals.jpg +0 -0
  4. package/package.json +1 -1
  5. package/plugins/LabelControl.js +566 -92
  6. package/plugins/ModelControl.js +67 -58
  7. package/tools/index.js +11 -4
  8. package/loader/WaterMaterial/WaterEffect.js +0 -255
  9. package/loader/WaterMaterial/resource/shaders/caustics/fragment.glsl +0 -24
  10. package/loader/WaterMaterial/resource/shaders/caustics/vertex.glsl +0 -34
  11. package/loader/WaterMaterial/resource/shaders/debug/fragment.glsl +0 -12
  12. package/loader/WaterMaterial/resource/shaders/debug/vertex.glsl +0 -10
  13. package/loader/WaterMaterial/resource/shaders/pool/fragment.glsl +0 -17
  14. package/loader/WaterMaterial/resource/shaders/pool/vertex.glsl +0 -16
  15. package/loader/WaterMaterial/resource/shaders/simulation/drop_fragment.glsl +0 -22
  16. package/loader/WaterMaterial/resource/shaders/simulation/normal_fragment.glsl +0 -19
  17. package/loader/WaterMaterial/resource/shaders/simulation/update_fragment.glsl +0 -33
  18. package/loader/WaterMaterial/resource/shaders/simulation/vertex.glsl +0 -9
  19. package/loader/WaterMaterial/resource/shaders/utils.glsl +0 -60
  20. package/loader/WaterMaterial/resource/shaders/water/fragment.glsl +0 -69
  21. package/loader/WaterMaterial/resource/shaders/water/vertex.glsl +0 -24
  22. package/loader/WaterMaterial/resource/tiles.jpg +0 -0
  23. package/loader/WaterMaterial/resource/vite.svg +0 -1
  24. package/loader/WaterMaterial/resource/xneg.jpg +0 -0
  25. package/loader/WaterMaterial/resource/xpos.jpg +0 -0
  26. package/loader/WaterMaterial/resource/ypos.jpg +0 -0
  27. package/loader/WaterMaterial/resource/zneg.jpg +0 -0
  28. 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
- texture.image.width,
564
- "x",
565
- texture.image.height
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
- "🔧 使用方法1: EquirectangularReflectionMapping + scale(1,-1,-1)"
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
- hasTexture: !!this._PanoramaSphere.material.map,
614
- side: this._PanoramaSphere.material.side,
615
- mapping: texture.mapping,
616
- textureSize: texture.image
617
- ? `${texture.image.width}x${texture.image.height}`
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
- ` 相机位置: (${this.camera.position.x.toFixed(
673
- 2
674
- )}, ${this.camera.position.y.toFixed(
675
- 2
676
- )}, ${this.camera.position.z.toFixed(2)})`
677
- );
678
- console.log(
679
- ` 控制器目标: (${this.controls.target.x.toFixed(
680
- 2
681
- )}, ${this.controls.target.y.toFixed(
682
- 2
683
- )}, ${this.controls.target.z.toFixed(2)})`
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
- function createWaterLoader(renderer, camera, scene) {
2
- // Load Textures
3
- const cubetextureloader = new THREE.CubeTextureLoader();
4
- const textureCube = cubetextureloader.load([
5
- '/resource/xpos.jpg', '/resource/xneg.jpg',
6
- '/resource/ypos.jpg', '/resource/ypos.jpg',
7
- '/resource/zpos.jpg', '/resource/zneg.jpg',
8
- ]);
9
-
10
- const textureloader = new THREE.TextureLoader();
11
- const tiles = textureloader.load('/resource/tiles.jpg');
12
-
13
- // Initialize Water Effect
14
- const waterEffect = new WaterEffect(renderer, camera, scene, {
15
- tiles: tiles,
16
- skybox: textureCube
17
- });
18
-
19
- function animate() {
20
- // Update water effect
21
- waterEffect.update();
22
-
23
- // Clear and Render Scene
24
- renderer.setClearColor(new THREE.Color('white'), 1);
25
- renderer.clear();
26
-
27
- renderer.render(scene, camera);
28
-
29
- controls.update();
30
-
31
- requestAnimationFrame(animate);
32
- }
33
-
34
- animate();
35
- return waterEffect;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-threesdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "����Threejs��װ�ij��ù��ܵ�sdk",
5
5
  "main": "index.js",
6
6
  "private": false,