ShadowEditor/web/src/utils/MeshUtils.js
2020-05-01 09:07:57 +08:00

62 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 模型工具类
*/
const MeshUtils = {
/**
* 遍历模型子元素得到uuid列表
* @param {THREE.Object3D} children 模型的children数组
* @param {Array} list uuid数组
*/
traverseUUID(children, list) {
for (let i = 0; i < children.length; i++) {
let child = children[i];
let list1 = [];
if (child.children && child.children.length > 0) {
this.traverseUUID(child.children, list1);
}
list.push({
uuid: child.uuid,
children: list1
});
}
},
/**
* 通过模型组件获取整个模型
* @param {*} obj 通过模型的一部分获取整个模型
* @returns {*} 整体模型
*/
partToMesh(obj) {
let scene = app.editor.scene;
if (obj === scene || obj.userData && obj.userData.Server === true) { // 场景或服务端模型
return obj;
}
// 判断obj是否是模型的一部分
let model = obj;
let isPart = false;
while (model) {
if (model === scene) {
break;
}
if (model.userData && model.userData.Server === true) {
isPart = true;
break;
}
model = model.parent;
}
if (isPart) {
return model;
}
return obj;
}
};
export default MeshUtils;