@@ -2,17 +2,20 @@ var canvasManipulator = (function () {
22
33 var colors = {
44 darkred : "darkred" ,
5+ red : "red" ,
56 black : "black" ,
67 orange : "orange" ,
78 darkorange : "darkorange"
8- }
9+ } ;
910
1011 var scene = { } ;
1112 var threeJSScene = { } ;
1213
1314 var camera ;
1415 var initialCameraView ;
1516
17+ var testEntity ;
18+
1619 function initialize ( ) {
1720
1821 scene = document . getElementById ( canvasId ) ;
@@ -27,12 +30,22 @@ var canvasManipulator = (function () {
2730
2831 // working - save old transparency in case it is not 0?
2932 function changeTransparencyOfEntities ( entities , value ) {
30- entities . forEach ( function ( entity ) {
33+ entities . forEach ( function ( entity2 ) {
34+ // getting the entity again here, because without it the check if originalTransparency is defined fails sometimes
35+ let entity = model . getEntityById ( entity2 . id ) ;
3136 let component = document . getElementById ( entity . id ) ;
3237 if ( component == undefined ) {
3338 events . log . error . publish ( { text : "CanvasManipualtor - changeTransparencyOfEntities - components for entityIds not found" } ) ;
3439 return ;
3540 }
41+ if ( entity . originalTransparency === undefined ) {
42+ entity . originalTransparency = { } ;
43+ entity . currentTransparency = { } ;
44+ if ( component . getAttribute ( "material" ) . opacity ) {
45+ entity . originalTransparency = 1 - component . getAttribute ( "material" ) . opacity ;
46+ }
47+ }
48+ entity . currentTransparency = value ;
3649 setTransparency ( component , value ) ;
3750 } ) ;
3851 }
@@ -45,41 +58,61 @@ var canvasManipulator = (function () {
4558 events . log . error . publish ( { text : "CanvasManipualtor - resetTransparencyOfEntities - components for entityIds not found" } ) ;
4659 return ;
4760 }
48- setTransparency ( component , 1 ) ;
61+ if ( ! ( entity . originalTransparency == undefined ) ) {
62+ entity . currentTransparency = entity . originalTransparency ;
63+ setTransparency ( component , entity . originalTransparency ) ;
64+ }
4965 } ) ;
5066 }
5167
5268
5369 // working
5470 function changeColorOfEntities ( entities , color ) {
5571 entities . forEach ( function ( entity ) {
56- // in x3dom this function would get entities of the model to change the color of the related object
57- // for reference in canvasHoverController.js: var entity = model.getEntityById(multipartEvent.partID);
58- // this entity gets handed over to the ActionController.js as part of an ApplicationEvent
59- if ( ! ( entity == undefined ) ) {
60- var component = document . getElementById ( entity . id ) ;
61- }
62- if ( component == undefined ) {
63- events . log . error . publish ( { text : "CanvasManipualtor - changeColorOfEntities - components for entityIds not found" } ) ;
64- return ;
72+ // in x3dom this function would get entities of the model to change the color of the related object
73+ // for reference in canvasHoverController.js: var entity = model.getEntityById(multipartEvent.partID);
74+ // this entity gets handed over to the ActionController.js as part of an ApplicationEvent
75+ if ( ! ( entity == undefined ) ) {
76+ var component = document . getElementById ( entity . id ) ;
77+ }
78+ if ( component == undefined ) {
79+ events . log . error . publish ( { text : "CanvasManipualtor - changeColorOfEntities - components for entityIds not found" } ) ;
80+ return ;
81+ }
82+ if ( entity . originalColor == undefined ) {
83+ entity . originalColor = component . getAttribute ( "color" ) ;
84+ }
85+ entity . currentColor = color ;
86+ setColor ( component , color ) ;
6587 }
66- setColor ( component , color ) ;
67- } ) ;
88+ ) ;
6889 }
6990
70- // working
91+ // working
7192 function resetColorOfEntities ( entities ) {
7293 entities . forEach ( function ( entity ) {
7394 let component = document . getElementById ( entity . id ) ;
7495 if ( component == undefined ) {
7596 events . log . error . publish ( { text : "CanvasManipualtor - resetColorOfEntities - components for entityIds not found" } ) ;
7697 return ;
7798 }
78- setColor ( component , component . getAttribute ( "color" ) ) ;
99+ if ( entity . originalColor ) {
100+ entity . currentColor = entity . originalColor ;
101+ setColor ( component , entity . originalColor ) ;
102+ }
79103 } ) ;
80104 }
81105
82- // working
106+ function setColor ( object , color ) {
107+ color == colors . darkred ? color = colors . red : color = color ;
108+ let colorValues = color . split ( " " ) ;
109+ if ( colorValues . length == 3 ) {
110+ color = "#" + parseInt ( colorValues [ 0 ] ) . toString ( 16 ) + "" + parseInt ( colorValues [ 1 ] ) . toString ( 16 ) + "" + parseInt ( colorValues [ 2 ] ) . toString ( 16 ) ;
111+ }
112+ object . setAttribute ( "color" , color ) ;
113+ }
114+
115+ // working
83116 function hideEntities ( entities ) {
84117 entities . forEach ( function ( entity ) {
85118 let component = document . getElementById ( entity . id ) ;
@@ -91,7 +124,7 @@ var canvasManipulator = (function () {
91124 } ) ;
92125 }
93126
94- // working
127+ // working
95128 function showEntities ( entities ) {
96129 entities . forEach ( function ( entity ) {
97130 let component = document . getElementById ( entity . id ) ;
@@ -104,13 +137,29 @@ var canvasManipulator = (function () {
104137 }
105138
106139 function highlightEntities ( entities , color ) {
107- entities . forEach ( function ( entity ) {
140+ entities . forEach ( function ( entity2 ) {
141+ // getting the entity again here, because without it the check if originalTransparency is defined fails sometimes
142+ let entity = model . getEntityById ( entity2 . id ) ;
108143 let component = document . getElementById ( entity . id ) ;
109144 if ( component == undefined ) {
110145 events . log . error . publish ( { text : "CanvasManipualtor - highlightEntities - components for entityIds not found" } ) ;
111146 return ;
112147 }
148+ if ( entity . originalColor == undefined ) {
149+ entity . originalColor = component . getAttribute ( "color" ) ;
150+ entity . currentColor = entity . originalColor ;
151+ }
152+ if ( entity [ "originalTransparency" ] === undefined ) {
153+ // in case "material".opacity is undefined originalTransparency gets set to 0 which would be the default value anyways
154+ entity . originalTransparency = { } ;
155+ entity . currentTransparency = { } ;
156+ if ( component . getAttribute ( "material" ) . opacity ) {
157+ entity . originalTransparency = 1 - component . getAttribute ( "material" ) . opacity ;
158+ } else entity . originalTransparency = 0 ;
159+ entity . currentTransparency = entity . originalTransparency ;
160+ }
113161 setColor ( component , color ) ;
162+ setTransparency ( component , 0 ) ;
114163 } ) ;
115164 }
116165
@@ -121,12 +170,13 @@ var canvasManipulator = (function () {
121170 events . log . error . publish ( { text : "CanvasManipualtor - unhighlightEntities - components for entityIds not found" } ) ;
122171 return ;
123172 }
124- setColor ( component , component . getAttribute ( "color" ) ) ;
173+ setTransparency ( component , entity . currentTransparency ) ;
174+ setColor ( component , entity . currentColor ) ;
125175 } ) ;
126176 }
127177
128- // after clicking an entity fit the camera to show this entity (angle stays the same)
129- // not working
178+ // after clicking an entity fit the camera to show this entity (angle stays the same)
179+ // not working
130180 function flyToEntity ( entity ) {
131181 /*document.querySelector("#camera").object3D.position = {x: 1, y: 2, z: 3};
132182 console.debug(document.querySelector("#camera").object3D.position);*/
@@ -143,8 +193,8 @@ var canvasManipulator = (function () {
143193 }
144194
145195
146- // not working yet
147- // gets called from Mark- and SelectController if specified in the config
196+ // not working yet
197+ // gets called from Mark- and SelectController if specified in the config
148198 function setCenterOfRotation ( entity , setFocus ) {
149199 var centerOfPart = getCenterOfEntity ( entity ) ;
150200
@@ -177,27 +227,9 @@ var canvasManipulator = (function () {
177227 return centerOfPart ;
178228 }
179229
180-
181- //Helper
182- function getPart ( entity ) {
183- if ( entity . part == undefined ) {
184- var part = multiPart . getParts ( [ entity . id ] ) ;
185- entity . part = part ;
186- }
187-
188- return entity . part ;
189- }
190-
191- // working
192- function setColor ( object , color ) {
193- object . setAttribute ( "material" , {
194- color : color
195- } ) ;
196- }
197-
198230 function setTransparency ( object , value ) {
199231 object . setAttribute ( 'material' , {
200- opacity : value
232+ opacity : 1 - value
201233 } ) ;
202234 }
203235
@@ -206,6 +238,17 @@ var canvasManipulator = (function () {
206238 object . setAttribute ( "visible" , visibility ) ;
207239 }
208240
241+ function getElementIds ( ) {
242+ let sceneArray = Array . from ( scene . children ) ;
243+ sceneArray . shift ( ) ; // so camera entity needs to be first in model.html
244+ sceneArray . pop ( ) ; // last element is of class "a-canvas"
245+ let elementIds = [ ] ;
246+ sceneArray . forEach ( function ( object ) {
247+ elementIds . push ( object . id ) ;
248+ } ) ;
249+ return elementIds ;
250+ }
251+
209252 return {
210253 initialize : initialize ,
211254 reset : reset ,
@@ -231,6 +274,9 @@ var canvasManipulator = (function () {
231274
232275 setCenterOfRotation : setCenterOfRotation ,
233276 getCenterOfEntity : getCenterOfEntity ,
277+
278+ getElementIds : getElementIds
234279 } ;
235280
236- } ) ( ) ;
281+ } )
282+ ( ) ;
0 commit comments