@@ -9,26 +9,29 @@ var canvasManipulator = (function () {
99 } ;
1010
1111 var scene = { } ;
12- var threeJSScene = { } ;
1312
14- var camera ;
15- var initialCameraView ;
16-
17- var testEntity ;
13+ var initialCameraView = { } ;
1814
1915 function initialize ( ) {
2016
2117 scene = document . querySelector ( "a-scene" ) ;
22- threeJSScene = scene . object3D ;
23- camera = document . getElementById ( "camera" ) ;
2418
19+ initialCameraView . target = globalCamera . target ;
20+ initialCameraView . position = globalCamera . object . position ;
21+ initialCameraView . spherical = globalCamera . spherical ;
2522 }
2623
2724 function reset ( ) {
25+ let offset = new THREE . Vector3 ( ) ;
26+ offset . subVectors ( initialCameraView . target , globalCamera . target ) . multiplyScalar ( globalCamera . data . panSpeed ) ;
27+ globalCamera . panOffset . add ( offset ) ;
28+
29+ globalCamera . sphericalDelta . phi = 0.25 * ( initialCameraView . spherical . phi - globalCamera . spherical . phi ) ;
30+ globalCamera . sphericalDelta . theta = 0.25 * ( initialCameraView . spherical . theta - globalCamera . spherical . theta ) ;
2831
32+ globalCamera . scale = initialCameraView . spherical . radius / globalCamera . spherical . radius ;
2933 }
3034
31- // working - save old transparency in case it is not 0?
3235 function changeTransparencyOfEntities ( entities , value ) {
3336 entities . forEach ( function ( entity2 ) {
3437 // getting the entity again here, because without it the check if originalTransparency is defined fails sometimes
@@ -50,7 +53,6 @@ var canvasManipulator = (function () {
5053 } ) ;
5154 }
5255
53- // working
5456 function resetTransparencyOfEntities ( entities ) {
5557 entities . forEach ( function ( entity ) {
5658 let component = document . getElementById ( entity . id ) ;
@@ -65,13 +67,8 @@ var canvasManipulator = (function () {
6567 } ) ;
6668 }
6769
68-
69- // working
7070 function changeColorOfEntities ( entities , color ) {
7171 entities . forEach ( function ( entity ) {
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
7572 if ( ! ( entity == undefined ) ) {
7673 var component = document . getElementById ( entity . id ) ;
7774 }
@@ -88,7 +85,6 @@ var canvasManipulator = (function () {
8885 ) ;
8986 }
9087
91- // working
9288 function resetColorOfEntities ( entities ) {
9389 entities . forEach ( function ( entity ) {
9490 let component = document . getElementById ( entity . id ) ;
@@ -112,7 +108,6 @@ var canvasManipulator = (function () {
112108 object . setAttribute ( "color" , color ) ;
113109 }
114110
115- // working
116111 function hideEntities ( entities ) {
117112 entities . forEach ( function ( entity ) {
118113 let component = document . getElementById ( entity . id ) ;
@@ -124,7 +119,6 @@ var canvasManipulator = (function () {
124119 } ) ;
125120 }
126121
127- // working
128122 function showEntities ( entities ) {
129123 entities . forEach ( function ( entity ) {
130124 let component = document . getElementById ( entity . id ) ;
@@ -175,11 +169,11 @@ var canvasManipulator = (function () {
175169 } ) ;
176170 }
177171
178- // after clicking an entity fit the camera to show this entity (angle stays the same)
179- // not working
180172 function flyToEntity ( entity ) {
181- /*document.querySelector("#camera").object3D.position = {x: 1, y: 2, z: 3};
182- console.debug(document.querySelector("#camera").object3D.position);*/
173+ setCenterOfRotation ( entity ) ;
174+ let object = document . getElementById ( entity . id ) ;
175+ let boundingSphereRadius = object . object3DMap . mesh . geometry . boundingSphere . radius ;
176+ globalCamera . scale = boundingSphereRadius / globalCamera . spherical . radius ;
183177 }
184178
185179 function addElement ( element ) {
@@ -192,29 +186,10 @@ var canvasManipulator = (function () {
192186 }
193187
194188
195- // not working yet
196- // gets called from Mark- and SelectController if specified in the config
197- function setCenterOfRotation ( entity , setFocus ) {
198- var centerOfPart = getCenterOfEntity ( entity ) ;
199-
200- viewpoint . setCenterOfRotation ( centerOfPart ) ;
201-
202- if ( setFocus ) {
203- var mat = viewarea . getViewMatrix ( ) . inverse ( ) ;
204-
205- var from = mat . e3 ( ) ;
206- var at = viewarea . _pick ;
207- var up = mat . e1 ( ) ;
208-
209- var norm = mat . e0 ( ) . cross ( up ) . normalize ( ) ;
210- // get distance between look-at point and viewing plane
211- var dist = norm . dot ( viewarea . _pick . subtract ( from ) ) ;
212-
213- from = at . addScaled ( norm , - dist ) ;
214- mat = x3dom . fields . SFMatrix4f . lookAt ( from , at , up ) ;
215-
216- viewarea . animateTo ( mat . inverse ( ) , viewpoint ) ;
217- }
189+ function setCenterOfRotation ( entity ) {
190+ let offset = new THREE . Vector3 ( ) ;
191+ offset . subVectors ( getCenterOfEntity ( entity ) , globalCamera . target ) . multiplyScalar ( globalCamera . data . panSpeed ) ;
192+ globalCamera . panOffset . add ( offset ) ;
218193 }
219194
220195 function getCenterOfEntity ( entity ) {
@@ -270,7 +245,6 @@ var canvasManipulator = (function () {
270245 addElement : addElement ,
271246 removeElement : removeElement ,
272247
273-
274248 setCenterOfRotation : setCenterOfRotation ,
275249 getCenterOfEntity : getCenterOfEntity ,
276250
0 commit comments