easy-threesdk 1.0.3 → 1.0.4
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 +78 -0
- 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 +43 -34
- 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
|
//初始化控制器
|
|
@@ -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
|