x
This commit is contained in:
+105
-13
@@ -175,10 +175,19 @@ class HTMLGenerator:
|
|||||||
<div id="controls">
|
<div id="controls">
|
||||||
<button onclick="resetView()">重置视图</button>
|
<button onclick="resetView()">重置视图</button>
|
||||||
<button onclick="toggleWireframe()">切换线框</button>
|
<button onclick="toggleWireframe()">切换线框</button>
|
||||||
|
<button onclick="toggleProduct()">显示/隐藏产品</button>
|
||||||
|
<button onclick="toggleMold()">显示/隐藏模具</button>
|
||||||
|
<button onclick="toggleParting()">显示/隐藏分型面</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 全局变量
|
||||||
|
let productMesh, cavityMesh, coreMesh, partingMesh;
|
||||||
|
let productVisible = true;
|
||||||
|
let moldVisible = true;
|
||||||
|
let partingVisible = true;
|
||||||
|
|
||||||
// 初始化Three.js场景
|
// 初始化Three.js场景
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||||
@@ -201,6 +210,7 @@ class HTMLGenerator:
|
|||||||
|
|
||||||
// 创建几何体(模拟模具形状)
|
// 创建几何体(模拟模具形状)
|
||||||
const geometryData = {json.dumps(geometry_data, indent=2)};
|
const geometryData = {json.dumps(geometry_data, indent=2)};
|
||||||
|
const cavityData = {json.dumps(cavity_data, indent=2) if cavity_data else 'null'};
|
||||||
|
|
||||||
// 根据边界框创建模拟几何体
|
// 根据边界框创建模拟几何体
|
||||||
const bbox = geometryData.bounding_box;
|
const bbox = geometryData.bounding_box;
|
||||||
@@ -209,25 +219,85 @@ class HTMLGenerator:
|
|||||||
const height = bbox.dimensions ? bbox.dimensions[1] : 100;
|
const height = bbox.dimensions ? bbox.dimensions[1] : 100;
|
||||||
const depth = bbox.dimensions ? bbox.dimensions[2] : 100;
|
const depth = bbox.dimensions ? bbox.dimensions[2] : 100;
|
||||||
|
|
||||||
// 创建基础几何体
|
// 创建产品几何体(半透明绿色)
|
||||||
const geometry = new THREE.BoxGeometry(width, height, depth);
|
const productGeometry = new THREE.BoxGeometry(width * 0.9, height * 0.9, depth * 0.9);
|
||||||
const material = new THREE.MeshPhongMaterial({{
|
const productMaterial = new THREE.MeshPhongMaterial({{
|
||||||
color: 0x4CAF50,
|
color: 0x4CAF50,
|
||||||
transparent: true,
|
transparent: true,
|
||||||
opacity: 0.8,
|
opacity: 0.6,
|
||||||
wireframe: false
|
wireframe: false
|
||||||
}});
|
}});
|
||||||
|
|
||||||
const mesh = new THREE.Mesh(geometry, material);
|
const productMesh = new THREE.Mesh(productGeometry, productMaterial);
|
||||||
scene.add(mesh);
|
productMesh.position.set(0, 0, 0);
|
||||||
|
scene.add(productMesh);
|
||||||
|
|
||||||
// 添加线框
|
// 创建型腔(上半模 - 蓝色)
|
||||||
const wireframe = new THREE.WireframeGeometry(geometry);
|
const cavityGeometry = new THREE.BoxGeometry(width * 1.1, height * 0.3, depth * 1.1);
|
||||||
const line = new THREE.LineSegments(wireframe);
|
const cavityMaterial = new THREE.MeshPhongMaterial({{
|
||||||
line.material.depthTest = false;
|
color: 0x2196F3,
|
||||||
line.material.opacity = 0.25;
|
transparent: true,
|
||||||
line.material.transparent = true;
|
opacity: 0.4,
|
||||||
scene.add(line);
|
wireframe: false
|
||||||
|
}});
|
||||||
|
|
||||||
|
const cavityMesh = new THREE.Mesh(cavityGeometry, cavityMaterial);
|
||||||
|
cavityMesh.position.set(0, height * 0.6, 0);
|
||||||
|
scene.add(cavityMesh);
|
||||||
|
|
||||||
|
// 创建型芯(下半模 - 橙色)
|
||||||
|
const coreGeometry = new THREE.BoxGeometry(width * 1.1, height * 0.3, depth * 1.1);
|
||||||
|
const coreMaterial = new THREE.MeshPhongMaterial({{
|
||||||
|
color: 0xFF9800,
|
||||||
|
transparent: true,
|
||||||
|
opacity: 0.4,
|
||||||
|
wireframe: false
|
||||||
|
}});
|
||||||
|
|
||||||
|
const coreMesh = new THREE.Mesh(coreGeometry, coreMaterial);
|
||||||
|
coreMesh.position.set(0, -height * 0.6, 0);
|
||||||
|
scene.add(coreMesh);
|
||||||
|
|
||||||
|
// 创建分型面(红色平面)
|
||||||
|
const partingGeometry = new THREE.PlaneGeometry(width * 1.2, depth * 1.2);
|
||||||
|
const partingMaterial = new THREE.MeshBasicMaterial({{
|
||||||
|
color: 0xF44336,
|
||||||
|
transparent: true,
|
||||||
|
opacity: 0.3,
|
||||||
|
side: THREE.DoubleSide
|
||||||
|
}});
|
||||||
|
|
||||||
|
const partingMesh = new THREE.Mesh(partingGeometry, partingMaterial);
|
||||||
|
partingMesh.rotation.x = Math.PI / 2;
|
||||||
|
partingMesh.position.set(0, 0, 0);
|
||||||
|
scene.add(partingMesh);
|
||||||
|
|
||||||
|
// 添加产品线框
|
||||||
|
const productWireframe = new THREE.WireframeGeometry(productGeometry);
|
||||||
|
const productLine = new THREE.LineSegments(productWireframe);
|
||||||
|
productLine.material.depthTest = false;
|
||||||
|
productLine.material.opacity = 0.5;
|
||||||
|
productLine.material.transparent = true;
|
||||||
|
productLine.material.color = new THREE.Color(0x2E7D32);
|
||||||
|
productMesh.add(productLine);
|
||||||
|
|
||||||
|
// 添加型腔线框
|
||||||
|
const cavityWireframe = new THREE.WireframeGeometry(cavityGeometry);
|
||||||
|
const cavityLine = new THREE.LineSegments(cavityWireframe);
|
||||||
|
cavityLine.material.depthTest = false;
|
||||||
|
cavityLine.material.opacity = 0.6;
|
||||||
|
cavityLine.material.transparent = true;
|
||||||
|
cavityLine.material.color = new THREE.Color(0x1565C0);
|
||||||
|
cavityMesh.add(cavityLine);
|
||||||
|
|
||||||
|
// 添加型芯线框
|
||||||
|
const coreWireframe = new THREE.WireframeGeometry(coreGeometry);
|
||||||
|
const coreLine = new THREE.LineSegments(coreWireframe);
|
||||||
|
coreLine.material.depthTest = false;
|
||||||
|
coreLine.material.opacity = 0.6;
|
||||||
|
coreLine.material.transparent = true;
|
||||||
|
coreLine.material.color = new THREE.Color(0xE65100);
|
||||||
|
coreMesh.add(coreLine);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// 设置相机位置
|
// 设置相机位置
|
||||||
@@ -267,6 +337,28 @@ class HTMLGenerator:
|
|||||||
}}
|
}}
|
||||||
}});
|
}});
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
function toggleProduct() {{
|
||||||
|
if (productMesh) {{
|
||||||
|
productVisible = !productVisible;
|
||||||
|
productMesh.visible = productVisible;
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
|
||||||
|
function toggleMold() {{
|
||||||
|
if (cavityMesh && coreMesh) {{
|
||||||
|
moldVisible = !moldVisible;
|
||||||
|
cavityMesh.visible = moldVisible;
|
||||||
|
coreMesh.visible = moldVisible;
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
|
||||||
|
function toggleParting() {{
|
||||||
|
if (partingMesh) {{
|
||||||
|
partingVisible = !partingVisible;
|
||||||
|
partingMesh.visible = partingVisible;
|
||||||
|
}}
|
||||||
|
}}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user