|
|
|
@ -28,6 +28,11 @@ |
|
|
|
<el-radio-button label="0.001" :value="0.001" /> |
|
|
|
</el-radio-group> |
|
|
|
</div> |
|
|
|
<div class="demo-color-block"> |
|
|
|
<span class="demonstration">物体数:<el-text type="danger">{{ restate.objects }}</el-text></span> |
|
|
|
<span class="demonstration"> 顶点数:<el-text type="danger">{{ restate.vertices }}</el-text></span> |
|
|
|
<span class="demonstration"> 三角形数:<el-text type="danger">{{ restate.faces }}</el-text></span> |
|
|
|
</div> |
|
|
|
</el-space> |
|
|
|
<div class="main-content"> |
|
|
|
<Split class="model3d-content" :direction="'horizontal'"> |
|
|
|
@ -92,7 +97,10 @@ let gui, tcontrols, modelGroup |
|
|
|
const restate = reactive({ |
|
|
|
targetColor: '#ff0000', |
|
|
|
loadScale: 1, |
|
|
|
mode: 'translate' |
|
|
|
mode: 'translate', |
|
|
|
objects: 0, |
|
|
|
vertices: 0, |
|
|
|
faces: 0 |
|
|
|
}) |
|
|
|
|
|
|
|
// 状态变量 |
|
|
|
@ -449,14 +457,8 @@ function handleMtlUpload(file) { |
|
|
|
|
|
|
|
const objLoader = new OBJLoader() |
|
|
|
objLoader.setMaterials(materials) |
|
|
|
modelGroup = objLoader.parse(lastObjfile) |
|
|
|
if (restate.loadScale) { |
|
|
|
modelGroup.scale.set(restate.loadScale, restate.loadScale, restate.loadScale) |
|
|
|
} |
|
|
|
|
|
|
|
scene.add(modelGroup) |
|
|
|
tcontrols.attach(modelGroup) |
|
|
|
transformEditCtl.value?.attachObject3D(modelGroup) |
|
|
|
const content = objLoader.parse(lastObjfile) |
|
|
|
addGroupToScene(content) |
|
|
|
}) |
|
|
|
} |
|
|
|
reader.readAsText(file) |
|
|
|
@ -465,6 +467,60 @@ function handleMtlUpload(file) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function addGroupToScene(group) { |
|
|
|
modelGroup = group |
|
|
|
if (restate.loadScale) { |
|
|
|
// 设置默认模型缩放 |
|
|
|
modelGroup.scale.set(restate.loadScale, restate.loadScale, restate.loadScale) |
|
|
|
} |
|
|
|
scene.add(modelGroup) |
|
|
|
tcontrols.attach(modelGroup) |
|
|
|
transformEditCtl.value?.attachObject3D(modelGroup) |
|
|
|
|
|
|
|
controls.target.copy(modelGroup.position) |
|
|
|
controls.update() |
|
|
|
|
|
|
|
// 遍历场景中的所有对象 |
|
|
|
let totalObjects = 0 |
|
|
|
let totalVertices = 0 |
|
|
|
let totalFaces = 0 |
|
|
|
modelGroup.traverse(function(child) { |
|
|
|
if (child.isMesh) { |
|
|
|
totalObjects++ |
|
|
|
|
|
|
|
// 获取几何体 |
|
|
|
const geometry = child.geometry |
|
|
|
|
|
|
|
// 如果几何体是 BufferGeometry 类型 |
|
|
|
if (geometry.isBufferGeometry) { |
|
|
|
// 计算顶点数 |
|
|
|
if (geometry.attributes.position) { |
|
|
|
totalVertices += geometry.attributes.position.count |
|
|
|
} |
|
|
|
|
|
|
|
// 计算面数(假设每个面都是由三个顶点组成的三角形) |
|
|
|
if (geometry.index) { |
|
|
|
totalFaces += geometry.index.count / 3 |
|
|
|
} else if (geometry.attributes.position) { |
|
|
|
// 如果没有索引,计算非索引几何体的面数 |
|
|
|
totalFaces += geometry.attributes.position.count / 3 |
|
|
|
} |
|
|
|
} |
|
|
|
// 如果几何体是 Geometry 类型(较旧的版本使用) |
|
|
|
else if (geometry.isGeometry) { |
|
|
|
// 计算顶点数 |
|
|
|
totalVertices += geometry.vertices.length |
|
|
|
|
|
|
|
// 计算面数 |
|
|
|
totalFaces += geometry.faces.length |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
restate.objects = totalObjects |
|
|
|
restate.vertices = totalVertices |
|
|
|
restate.faces = totalFaces |
|
|
|
} |
|
|
|
|
|
|
|
function handleFileChange(file) { |
|
|
|
console.log('file', file) |
|
|
|
if (!file) return |
|
|
|
@ -491,16 +547,7 @@ function handleFileChange(file) { |
|
|
|
const loader = new FBXLoader() |
|
|
|
const arrayBuffer = reader.result |
|
|
|
const content = loader.parse(arrayBuffer, '') |
|
|
|
modelGroup = content |
|
|
|
if (restate.loadScale) { |
|
|
|
modelGroup.scale.set(restate.loadScale, restate.loadScale, restate.loadScale) |
|
|
|
} |
|
|
|
scene.add(modelGroup) |
|
|
|
tcontrols.attach(modelGroup) |
|
|
|
transformEditCtl.value?.attachObject3D(modelGroup) |
|
|
|
|
|
|
|
controls.target.copy(modelGroup.position) |
|
|
|
controls.update() |
|
|
|
addGroupToScene(content) |
|
|
|
|
|
|
|
system.clearLoading() |
|
|
|
} |
|
|
|
@ -512,13 +559,8 @@ function handleFileChange(file) { |
|
|
|
const loader = new OBJLoader() |
|
|
|
lastObjfile = reader.result |
|
|
|
//@ts-ignore |
|
|
|
modelGroup = loader.parse(reader.result) |
|
|
|
if (restate.loadScale) { |
|
|
|
modelGroup.scale.set(restate.loadScale, restate.loadScale, restate.loadScale) |
|
|
|
} |
|
|
|
scene.add(modelGroup) |
|
|
|
tcontrols.attach(modelGroup) |
|
|
|
transformEditCtl.value?.attachObject3D(modelGroup) |
|
|
|
const content = loader.parse(reader.result) |
|
|
|
addGroupToScene(content) |
|
|
|
|
|
|
|
system.clearLoading() |
|
|
|
} |
|
|
|
@ -529,13 +571,7 @@ function handleFileChange(file) { |
|
|
|
const arrayBuffer = reader.result |
|
|
|
//@ts-ignore |
|
|
|
const content = loader.parse(arrayBuffer, '') |
|
|
|
modelGroup = content |
|
|
|
if (restate.loadScale) { |
|
|
|
modelGroup.scale.set(restate.loadScale, restate.loadScale, restate.loadScale) |
|
|
|
} |
|
|
|
scene.add(modelGroup) |
|
|
|
tcontrols.attach(modelGroup) |
|
|
|
transformEditCtl.value?.attachObject3D(modelGroup) |
|
|
|
addGroupToScene(content) |
|
|
|
|
|
|
|
system.clearLoading() |
|
|
|
} |
|
|
|
|