From cf463e8798c3fcfae51cb5db4e0fdf12ef4740cb Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Sun, 10 Mar 2019 15:17:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=9C=BA=E6=99=AF=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E6=A8=A1=E5=9E=8B=E6=97=B6=EF=BC=8C=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E6=A0=91=E7=8A=B6=E5=9B=BE=E4=BC=98=E5=85=88=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E6=95=B4=E4=B8=AA=E6=A8=A1=E5=9E=8B=EF=BC=8C=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E6=A8=A1=E5=9E=8B=E7=9A=84=E4=B8=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=EF=BC=8C=E8=80=8C=E4=B8=94=E4=BC=9A=E8=87=AA=E5=8A=A8=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E5=B9=B6=E6=BB=9A=E5=8A=A8=E5=88=B0=E6=89=80=E9=80=89?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + ShadowEditor.Web/src/event/PickEvent.js | 36 ++++++++++++++++++++++++- ShadowEditor.Web/src/ui/Tree.js | 11 +++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 567dd4c0..8b5878ec 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Language: 中文 / [English](README-en.md) 15. 修复创建脚本注释未汉化bug。 16. 折叠底部面板功能。 17. 重写场景树状图控件,支持折叠,暂时不支持拖拽。 +18. 点击场景选中模型时,场景树状图优先选中整个模型,而不是模型的一部分,而且会自动展开并滚动到所选模型。 ## v0.1.5更新 diff --git a/ShadowEditor.Web/src/event/PickEvent.js b/ShadowEditor.Web/src/event/PickEvent.js index 4b62b1ca..5c879e31 100644 --- a/ShadowEditor.Web/src/event/PickEvent.js +++ b/ShadowEditor.Web/src/event/PickEvent.js @@ -101,7 +101,7 @@ PickEvent.prototype.handleClick = function () { // helper editor.select(object.userData.object); } else { - editor.select(object); + editor.select(this.partToMesh(object)); } } else { editor.select(null); @@ -121,4 +121,38 @@ PickEvent.prototype.handleClick = function () { } }; +/** + * 如果选中的是模型的一部分,改为选择整个模型 + * @param {*} obj + */ +PickEvent.prototype.partToMesh = function (obj) { + var scene = this.app.editor.scene; + + if (obj === scene || obj.userData && obj.userData.Server === true) { // 场景或服务端模型 + return obj; + } + + // 判断obj是否是模型的一部分 + var model = obj; + var 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 PickEvent; \ No newline at end of file diff --git a/ShadowEditor.Web/src/ui/Tree.js b/ShadowEditor.Web/src/ui/Tree.js index 5978250e..0c00ac7d 100644 --- a/ShadowEditor.Web/src/ui/Tree.js +++ b/ShadowEditor.Web/src/ui/Tree.js @@ -240,15 +240,18 @@ Tree.prototype.select = function (value) { /** * 展开选中的节点的所有父节点 * @param {*} dom + * @param {*} isParent */ -Tree.prototype._expandSelected = function (dom) { +Tree.prototype._expandSelected = function (dom, isParent = false) { if (dom.classList.contains('Tree')) { // 根节点,默认展开 return; } else if (dom.classList.contains('SubTree')) { // 子树,展开父节点 - this._expandSelected(dom.parentNode); + this._expandSelected(dom.parentNode, true); } else if (dom.classList.contains('Node')) { // 节点,展开 - this.expand(dom.data.value); - this._expandSelected(dom.parentNode); + if (isParent) { + this.expand(dom.data.value); + } + this._expandSelected(dom.parentNode, true); } else { console.warn(`Tree: Unknown node.`); }