From e5efa694c159817a2641e9e82eb47a08644c84a7 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Wed, 16 Jan 2019 13:52:16 -0800 Subject: [PATCH] eve7: add EveScene.js which is responsible for all scene operations --- etc/eve7/EveManager.js | 71 +++--- etc/eve7/EveScene.js | 253 ++++++++++++++++++++ etc/eve7/EveTable.controller.js | 10 +- etc/eve7/GL.controller.js | 401 ++++++++------------------------ 4 files changed, 384 insertions(+), 351 deletions(-) create mode 100644 etc/eve7/EveScene.js diff --git a/etc/eve7/EveManager.js b/etc/eve7/EveManager.js index c0dc37cabdcf2..c6008ac2c6d4b 100644 --- a/etc/eve7/EveManager.js +++ b/etc/eve7/EveManager.js @@ -84,18 +84,31 @@ this.handle.Send(JSON.stringify(obj)); } - /** Configure dependency for given element id - invoke function when element changed */ - EveManager.prototype.Register = function(id, receiver, func_name) { + /** Configure receiver for scene-respective events. Following event used: + * onSceneChanged */ + EveManager.prototype.RegisterSceneReceiver = function(id, receiver, func_name) { var elem = this.GetElement(id); - + if (!elem) return; if (!elem.$receivers) elem.$receivers = []; - elem.$receivers.push({ obj: receiver, func: func_name }); + if (elem.$receivers.indexOf(receiver)<0) + elem.$receivers.push(receiver); } + /** Invoke function on all receiver of scene events - when such function exists */ + EveManager.prototype.callSceneReceivers = function (scene, fname, arg) { + if (scene.$receivers) { + for (var i=0; i < scene.$receivers.length; i++) { + var receiver = scene.$receivers[i]; + if (typeof receiver[fname] == "function") + receiver[fname](arg); + } + } + } + /** returns master id for given element id * master id used for highlighting element in all dependent views */ EveManager.prototype.GetMasterId = function(elemid) { @@ -185,13 +198,10 @@ } EveManager.prototype.ProcessModified = function(sceneid) { - var elem = this.map[sceneid]; - if (!elem || !elem.$modified || !elem.$receivers) return; - - for (var k=0;k 0) + cont.remove(cont.children[0]); + + for (var k = 0; k < res3d.length; ++k) + cont.add(res3d[k]); + + this.viewer.render(); + } + + EveScene.prototype.getObj3D = function(elementId) + { + return this.id2obj_map[elementId]; + } + + EveScene.prototype.update3DObjectsVisibility = function(arr, all_ancestor_children_visible) + { + if (!arr) return; + + for (var k = 0; k < arr.length; ++k) + { + var elem = arr[k]; + if (elem.render_data) + { + var obj3d = this.getObj3D(elem.fElementId); + if (obj3d) + { + obj3d.visible = elem.fRnrSelf && all_ancestor_children_visible; + obj3d.all_ancestor_children_visible = all_ancestor_children_visible; + } + } + + this.update3DObjectsVisibility(elem.childs, elem.fRnrChildren && all_ancestor_children_visible); + } + } + + EveScene.prototype.visibilityChildrenChanged = function(el) + { + console.log("visibility children changed ", this.mgr, el); + + if (el.childs) + { + // XXXX Overkill, but I don't have obj3d for all elements. + // Also, can do this traversal once for the whole update package, + // needs to be managed from EveManager.js. + // Or marked here and then recomputed before rendering (probably better). + + var scene = this.mgr.GetElement(el.fSceneId); + + this.update3DObjectsVisibility(scene.childs, true); + + if (this.viewer) + this.viewer.render(); + } + } + + EveScene.prototype.colorChanged = function(el) + { + console.log("color change ", el.fElementId, el.fMainColor); + + this.replaceElement(el); + } + + EveScene.prototype.replaceElement = function(el) + { + if (!this.viewer) return; + + var obj3d = this.getObj3D(el.fElementId); + + var container = this.viewer.getThreejsContainer("scene" + this.id); + + container.remove(obj3d); + + obj3d = this.makeGLRepresentation(el); + + container.add(obj3d); + + this.id2obj_map[el.fElementId] = obj3d; + + this.viewer.render(); + } + + EveScene.prototype.elementAdded = function(el) { + if (!this.viewer) return; + + var obj3d = this.makeGLRepresentation(el); + if (!obj3d) return; + + var container = this.viewer.getThreejsContainer("scene" + this.id); + + container.add(obj3d); + console.log("element added ", el); + + this.viewer.render(); + } + + EveScene.prototype.visibilityChanged = function(el) + { + var obj3d = this.getObj3D( el.fElementId ); + + if (obj3d) + { + obj3d.visible = obj3d.all_ancestor_children_visible && el.fRnrSelf; + } + + if (this.viewer) + this.viewer.render(); + } + + + EveScene.prototype.elementRemoved = function() { + } + + EveScene.prototype.beginChanges = function() { + } + + EveScene.prototype.endChanges = function() { + } + + EveScene.prototype.onSceneChanged = function(id) + { + console.log("scene changed", id); + + this.redrawScene(); + } + + JSROOT.EVE.EveScene = EveScene; + + return JSROOT; + +})); diff --git a/etc/eve7/EveTable.controller.js b/etc/eve7/EveTable.controller.js index 67dbbfb79c18d..24600f7376a79 100644 --- a/etc/eve7/EveTable.controller.js +++ b/etc/eve7/EveTable.controller.js @@ -36,7 +36,7 @@ sap.ui.define([ var scene = element.childs[k]; console.log("FOUND scene", scene.fSceneId); - this.mgr.Register(scene.fSceneId, this, "onElementChanged"); + this.mgr.RegisterSceneReceiver(scene.fSceneId, this); this.setEveData(); } @@ -122,7 +122,7 @@ sap.ui.define([ onLoadScripts: function() { this._load_scripts = true; - this.checkScences(); + this.checkScenes(); }, acm:function() { @@ -133,7 +133,7 @@ sap.ui.define([ if (this.mgr) this.mgr.Unregister(this); }, - onElementChanged: function(id, element) { + onSceneChanged: function(element, id) { console.log("!!!CHANGED", id); this.setEveData(); @@ -157,10 +157,10 @@ sap.ui.define([ // only when rendering completed - register for modify events var element = this.mgr.GetElement(this.elementid); - this.checkScences(); + this.checkScenes(); }, - checkScences: function() { + checkScenes: function() { }, toggleTableEdit: function() { diff --git a/etc/eve7/GL.controller.js b/etc/eve7/GL.controller.js index 1042bc0d64302..95f6e2d3f03f1 100644 --- a/etc/eve7/GL.controller.js +++ b/etc/eve7/GL.controller.js @@ -42,13 +42,9 @@ sap.ui.define([ this.mgr.RegisterHighlight(this, "onElementHighlight"); - JSROOT.AssertPrerequisites("geom;user:evedir/EveElements.js", this.onLoadScripts.bind(this)); + JSROOT.AssertPrerequisites("geom;user:evedir/EveElements.js;evedir/EveScene.js", this.onLoadScripts.bind(this)); - // this.checkScences(); - - this.id2obj_map = {}; }, - // MT-HAKA createThreejsRenderer: function() @@ -78,38 +74,61 @@ sap.ui.define([ // ------- - var sphere = new THREE.SphereGeometry( 0.1, 8, 8 ); + // var sphere = new THREE.SphereGeometry( 0.1, 8, 8 ); // var lamp = new THREE.DirectionalLight( 0xff5050, 0.5 ); var lampR = new THREE.PointLight( 0xff5050, 0.7 ); - lampR.add(new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: lampR.color } ) )); + // lampR.add(new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: lampR.color } ) )); lampR.position.set(2, 2, -2); this.scene.add( lampR ); var lampG = new THREE.PointLight( 0x50ff50, 0.7 ); - lampG.add(new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: lampG.color } ) )); + // lampG.add(new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: lampG.color } ) )); lampG.position.set(-2, 2, 2); this.scene.add( lampG ); var lampB = new THREE.PointLight( 0x5050ff, 0.7 ); - lampB.add(new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: lampB.color } ) )); + // lampB.add(new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: lampB.color } ) )); lampB.position.set(2, 2, 2); this.scene.add( lampB ); - var plane = new THREE.GridHelper(20, 20, 0x80d080, 0x8080d0); - this.scene.add(plane); + //var plane = new THREE.GridHelper(20, 20, 0x80d080, 0x8080d0); + //this.scene.add(plane); }, + /** returns container for 3d objects */ + getThreejsContainer: function(name) + { + var prnt = null; + + if (!direct_threejs) + prnt = this.geo_painter.getExtrasContainer(); + else + prnt = this.scene; + + for (var k=0;k