x
This commit is contained in:
@@ -210,6 +210,11 @@ class HTMLGenerator:
|
||||
const axesHelper = new THREE.AxesHelper(50);
|
||||
scene.add(axesHelper);
|
||||
|
||||
// 添加轨道控制器 - 必须在使用之前定义
|
||||
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
||||
controls.enableDamping = true;
|
||||
controls.dampingFactor = 0.25;
|
||||
|
||||
// 创建几何体(使用点云数据或模拟模具形状)
|
||||
const geometryData = {json.dumps(geometry_data, indent=2)};
|
||||
const cavityData = {json.dumps(cavity_data, indent=2) if cavity_data else 'null'};
|
||||
@@ -238,9 +243,9 @@ class HTMLGenerator:
|
||||
// 创建点云材质
|
||||
const pointMaterial = new THREE.PointsMaterial({{
|
||||
color: 0x4CAF50,
|
||||
size: 0.5,
|
||||
size: 1.0,
|
||||
transparent: true,
|
||||
opacity: 0.8
|
||||
opacity: 0.9
|
||||
}});
|
||||
|
||||
pointcloudMesh = new THREE.Points(pointGeometry, pointMaterial);
|
||||
@@ -251,6 +256,12 @@ class HTMLGenerator:
|
||||
pointGeometry.computeBoundingBox();
|
||||
pointGeometry.boundingBox.getCenter(center);
|
||||
controls.target.set(center.x, center.y, center.z);
|
||||
|
||||
// 根据边界框大小调整相机距离
|
||||
const boundingSphere = new THREE.Sphere();
|
||||
pointGeometry.boundingBox.getBoundingSphere(boundingSphere);
|
||||
const cameraDistance = boundingSphere.radius * 3;
|
||||
camera.position.set(cameraDistance, cameraDistance, cameraDistance);
|
||||
}} else {{
|
||||
// 创建产品几何体(半透明绿色)
|
||||
const productGeometry = new THREE.BoxGeometry(width * 0.9, height * 0.9, depth * 0.9);
|
||||
@@ -338,11 +349,6 @@ class HTMLGenerator:
|
||||
camera.position.set(200, 200, 200);
|
||||
camera.lookAt(0, 0, 0);
|
||||
|
||||
// 添加轨道控制器
|
||||
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
||||
controls.enableDamping = true;
|
||||
controls.dampingFactor = 0.25;
|
||||
|
||||
// 动画循环
|
||||
function animate() {{
|
||||
requestAnimationFrame(animate);
|
||||
|
||||
Reference in New Issue
Block a user