From 23253fdaace904484f84ff03c6bedf22e85561ff Mon Sep 17 00:00:00 2001 From: liteng <930372551@qq.com> Date: Thu, 27 Sep 2018 07:52:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=8F=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShadowEditor.Web/src/editor/StatusBar.js | 51 +++++++++++++- ShadowEditor.Web/src/event/EventDispatcher.js | 2 - .../event/statusBar/UpdateSceneStatusEvent.js | 70 ------------------- 3 files changed, 48 insertions(+), 75 deletions(-) delete mode 100644 ShadowEditor.Web/src/event/statusBar/UpdateSceneStatusEvent.js diff --git a/ShadowEditor.Web/src/editor/StatusBar.js b/ShadowEditor.Web/src/editor/StatusBar.js index b9cf9cf6..07d6828e 100644 --- a/ShadowEditor.Web/src/editor/StatusBar.js +++ b/ShadowEditor.Web/src/editor/StatusBar.js @@ -14,11 +14,8 @@ StatusBar.prototype = Object.create(UI.Control.prototype); StatusBar.prototype.constructor = StatusBar; StatusBar.prototype.render = function () { - var _this = this; - var data = { xtype: 'div', - id: 'statusBar', parent: this.parent, cls: 'statusBar', children: [{ @@ -29,6 +26,7 @@ StatusBar.prototype.render = function () { }, { xtype: 'text', id: 'objectsText', + scope: this.id, text: '0' // 物体数 }, { xtype: 'label', @@ -36,6 +34,7 @@ StatusBar.prototype.render = function () { }, { xtype: 'text', id: 'verticesText', + scope: this.id, text: '0' // 顶点数 }, { xtype: 'label', @@ -43,6 +42,7 @@ StatusBar.prototype.render = function () { }, { xtype: 'text', id: 'trianglesText', + scope: this.id, text: '0' // 三角形数 }] }] @@ -50,6 +50,51 @@ StatusBar.prototype.render = function () { var control = UI.create(data); control.render(); + + this.app.on('objectAdded.' + this.id, this.onUpdateInfo.bind(this)); + this.app.on('objectRemoved.' + this.id, this.onUpdateInfo.bind(this)); + this.app.on('geometryChanged.' + this.id, this.onUpdateInfo.bind(this)); +}; + +StatusBar.prototype.onUpdateInfo = function () { + var editor = this.app.editor; + + var scene = editor.scene; + + var objects = 0, vertices = 0, triangles = 0; + + for (var i = 0, l = scene.children.length; i < l; i++) { + var object = scene.children[i]; + + object.traverseVisible(function (object) { + objects++; + + if (object instanceof THREE.Mesh) { + var geometry = object.geometry; + + if (geometry instanceof THREE.Geometry) { + vertices += geometry.vertices.length; + triangles += geometry.faces.length; + } else if (geometry instanceof THREE.BufferGeometry) { + if (geometry.index !== null) { + vertices += geometry.index.count * 3; + triangles += geometry.index.count; + } else { + vertices += geometry.attributes.position.count; + triangles += geometry.attributes.position.count / 3; + } + } + } + }); + } + + var objectsText = UI.get('objectsText', this.id); + var verticesText = UI.get('verticesText', this.id); + var trianglesText = UI.get('trianglesText', this.id); + + objectsText.setValue(objects.format()); + verticesText.setValue(vertices.format()); + trianglesText.setValue(triangles.format()); }; export default StatusBar; \ No newline at end of file diff --git a/ShadowEditor.Web/src/event/EventDispatcher.js b/ShadowEditor.Web/src/event/EventDispatcher.js index dd3d168d..9db4d08d 100644 --- a/ShadowEditor.Web/src/event/EventDispatcher.js +++ b/ShadowEditor.Web/src/event/EventDispatcher.js @@ -16,7 +16,6 @@ import AddPhysicsWallEvent from './menu/physics/AddPhysicsWallEvent'; import AddPhysicsClothEvent from './menu/physics/AddPhysicsClothEvent'; import TransformControlsEvent from './viewport/TransformControlsEvent'; -import UpdateSceneStatusEvent from './statusBar/UpdateSceneStatusEvent'; import ObjectEvent from './viewport/ObjectEvent'; import PickEvent from './PickEvent'; import EditorControlsEvent from './viewport/EditorControlsEvent'; @@ -46,7 +45,6 @@ function EventDispatcher(app) { // viewport中的事件 new TransformControlsEvent(this.app), - new UpdateSceneStatusEvent(this.app), new ObjectEvent(this.app), new PickEvent(this.app), new EditorControlsEvent(this.app) diff --git a/ShadowEditor.Web/src/event/statusBar/UpdateSceneStatusEvent.js b/ShadowEditor.Web/src/event/statusBar/UpdateSceneStatusEvent.js deleted file mode 100644 index 1ee7bf8f..00000000 --- a/ShadowEditor.Web/src/event/statusBar/UpdateSceneStatusEvent.js +++ /dev/null @@ -1,70 +0,0 @@ -import BaseEvent from '../BaseEvent'; -import UI from '../../ui/UI'; - -/** - * 更新场景编辑区信息事件 - * @author tengge / https://github.com/tengge1 - * @param {*} app - */ -function UpdateSceneStatusEvent(app) { - BaseEvent.call(this, app); -} - -UpdateSceneStatusEvent.prototype = Object.create(BaseEvent.prototype); -UpdateSceneStatusEvent.prototype.constructor = UpdateSceneStatusEvent; - -UpdateSceneStatusEvent.prototype.start = function () { - var _this = this; - this.app.on('objectAdded.' + this.id, this.onUpdateInfo.bind(this)); - this.app.on('objectRemoved.' + this.id, this.onUpdateInfo.bind(this)); - this.app.on('geometryChanged.' + this.id, this.onUpdateInfo.bind(this)); -}; - -UpdateSceneStatusEvent.prototype.stop = function () { - this.app.on('objectAdded.' + this.id, null); - this.app.on('objectRemoved.' + this.id, null); - this.app.on('geometryChanged.' + this.id, null); -}; - -UpdateSceneStatusEvent.prototype.onUpdateInfo = function () { - var editor = this.app.editor; - - var scene = editor.scene; - - var objects = 0, vertices = 0, triangles = 0; - - for (var i = 0, l = scene.children.length; i < l; i++) { - var object = scene.children[i]; - - object.traverseVisible(function (object) { - objects++; - - if (object instanceof THREE.Mesh) { - var geometry = object.geometry; - - if (geometry instanceof THREE.Geometry) { - vertices += geometry.vertices.length; - triangles += geometry.faces.length; - } else if (geometry instanceof THREE.BufferGeometry) { - if (geometry.index !== null) { - vertices += geometry.index.count * 3; - triangles += geometry.index.count; - } else { - vertices += geometry.attributes.position.count; - triangles += geometry.attributes.position.count / 3; - } - } - } - }); - } - - var objectsText = UI.get('objectsText'); - var verticesText = UI.get('verticesText'); - var trianglesText = UI.get('trianglesText'); - - objectsText.setValue(objects.format()); - verticesText.setValue(vertices.format()); - trianglesText.setValue(triangles.format()); -}; - -export default UpdateSceneStatusEvent; \ No newline at end of file