x
This commit is contained in:
+112
-23
@@ -278,30 +278,89 @@ class HTMLGenerator:
|
||||
}}
|
||||
|
||||
// 创建型腔(上半模 - 蓝色)
|
||||
const cavityGeometry = new THREE.BoxGeometry(width * 1.1, height * 0.3, depth * 1.1);
|
||||
const cavityMaterial = new THREE.MeshPhongMaterial({{
|
||||
color: 0x2196F3,
|
||||
transparent: true,
|
||||
opacity: 0.4,
|
||||
wireframe: false
|
||||
}});
|
||||
|
||||
cavityMesh = new THREE.Mesh(cavityGeometry, cavityMaterial);
|
||||
cavityMesh.position.set(0, height * 0.6, 0);
|
||||
scene.add(cavityMesh);
|
||||
// 尝试从后端数据获取实际几何,否则使用简化Box
|
||||
if (cavityData && cavityData.mold_cavities && cavityData.mold_cavities.cavity && cavityData.mold_cavities.cavity.vertices) {{
|
||||
const cavityVerts = cavityData.mold_cavities.cavity.vertices;
|
||||
const cavityFaces = cavityData.mold_cavities.cavity.faces;
|
||||
|
||||
if (cavityVerts.length > 0 && cavityFaces.length > 0) {{
|
||||
const cavityGeometry = new THREE.BufferGeometry();
|
||||
const positions = new Float32Array(cavityVerts);
|
||||
const indices = new Uint32Array(cavityFaces);
|
||||
cavityGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
cavityGeometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
cavityGeometry.computeVertexNormals();
|
||||
|
||||
const cavityMaterial = new THREE.MeshPhongMaterial({{
|
||||
color: 0x2196F3,
|
||||
transparent: true,
|
||||
opacity: 0.5,
|
||||
wireframe: false,
|
||||
side: THREE.DoubleSide
|
||||
}});
|
||||
|
||||
cavityMesh = new THREE.Mesh(cavityGeometry, cavityMaterial);
|
||||
scene.add(cavityMesh);
|
||||
|
||||
// 添加线框
|
||||
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);
|
||||
|
||||
// 设置相机目标为型腔中心
|
||||
cavityGeometry.computeBoundingBox();
|
||||
const cavityCenter = new THREE.Vector3();
|
||||
cavityGeometry.boundingBox.getCenter(cavityCenter);
|
||||
controls.target.set(cavityCenter.x, cavityCenter.y, cavityCenter.z);
|
||||
}} else {{
|
||||
createSimpleCavity(width, height, depth);
|
||||
}}
|
||||
}} else {{
|
||||
createSimpleCavity(width, height, depth);
|
||||
}}
|
||||
|
||||
// 创建型芯(下半模 - 橙色)
|
||||
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
|
||||
}});
|
||||
|
||||
coreMesh = new THREE.Mesh(coreGeometry, coreMaterial);
|
||||
coreMesh.position.set(0, -height * 0.6, 0);
|
||||
scene.add(coreMesh);
|
||||
if (cavityData && cavityData.mold_cavities && cavityData.mold_cavities.core && cavityData.mold_cavities.core.vertices) {{
|
||||
const coreVerts = cavityData.mold_cavities.core.vertices;
|
||||
const coreFaces = cavityData.mold_cavities.core.faces;
|
||||
|
||||
if (coreVerts.length > 0 && coreFaces.length > 0) {{
|
||||
const coreGeometry = new THREE.BufferGeometry();
|
||||
const positions = new Float32Array(coreVerts);
|
||||
const indices = new Uint32Array(coreFaces);
|
||||
coreGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
coreGeometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
coreGeometry.computeVertexNormals();
|
||||
|
||||
const coreMaterial = new THREE.MeshPhongMaterial({{
|
||||
color: 0xFF9800,
|
||||
transparent: true,
|
||||
opacity: 0.5,
|
||||
wireframe: false,
|
||||
side: THREE.DoubleSide
|
||||
}});
|
||||
|
||||
coreMesh = new THREE.Mesh(coreGeometry, coreMaterial);
|
||||
scene.add(coreMesh);
|
||||
|
||||
// 添加线框
|
||||
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);
|
||||
}} else {{
|
||||
createSimpleCore(width, height, depth);
|
||||
}}
|
||||
}} else {{
|
||||
createSimpleCore(width, height, depth);
|
||||
}}
|
||||
|
||||
// 创建分型面(红色平面)
|
||||
const partingGeometry = new THREE.PlaneGeometry(width * 1.2, depth * 1.2);
|
||||
@@ -317,7 +376,7 @@ class HTMLGenerator:
|
||||
partingMesh.position.set(0, 0, 0);
|
||||
scene.add(partingMesh);
|
||||
|
||||
// 添加线框
|
||||
// 添加产品线框
|
||||
if (productMesh) {{
|
||||
const productWireframe = new THREE.WireframeGeometry(productMesh.geometry);
|
||||
const productLine = new THREE.LineSegments(productWireframe);
|
||||
@@ -327,6 +386,21 @@ class HTMLGenerator:
|
||||
productLine.material.color = new THREE.Color(0x2E7D32);
|
||||
productMesh.add(productLine);
|
||||
}}
|
||||
}}
|
||||
|
||||
// 创建简化型腔(备用)
|
||||
function createSimpleCavity(width, height, depth) {{
|
||||
const cavityGeometry = new THREE.BoxGeometry(width * 1.2, height * 0.4, depth * 1.2);
|
||||
const cavityMaterial = new THREE.MeshPhongMaterial({{
|
||||
color: 0x2196F3,
|
||||
transparent: true,
|
||||
opacity: 0.4,
|
||||
wireframe: false
|
||||
}});
|
||||
|
||||
cavityMesh = new THREE.Mesh(cavityGeometry, cavityMaterial);
|
||||
cavityMesh.position.set(0, height * 0.7, 0);
|
||||
scene.add(cavityMesh);
|
||||
|
||||
const cavityWireframe = new THREE.WireframeGeometry(cavityGeometry);
|
||||
const cavityLine = new THREE.LineSegments(cavityWireframe);
|
||||
@@ -335,6 +409,21 @@ class HTMLGenerator:
|
||||
cavityLine.material.transparent = true;
|
||||
cavityLine.material.color = new THREE.Color(0x1565C0);
|
||||
cavityMesh.add(cavityLine);
|
||||
}}
|
||||
|
||||
// 创建简化型芯(备用)
|
||||
function createSimpleCore(width, height, depth) {{
|
||||
const coreGeometry = new THREE.BoxGeometry(width * 1.2, height * 0.4, depth * 1.2);
|
||||
const coreMaterial = new THREE.MeshPhongMaterial({{
|
||||
color: 0xFF9800,
|
||||
transparent: true,
|
||||
opacity: 0.4,
|
||||
wireframe: false
|
||||
}});
|
||||
|
||||
coreMesh = new THREE.Mesh(coreGeometry, coreMaterial);
|
||||
coreMesh.position.set(0, -height * 0.7, 0);
|
||||
scene.add(coreMesh);
|
||||
|
||||
const coreWireframe = new THREE.WireframeGeometry(coreGeometry);
|
||||
const coreLine = new THREE.LineSegments(coreWireframe);
|
||||
|
||||
Reference in New Issue
Block a user