@needle-tools/engine 4.10.0-beta.3 → 4.10.0-next.2abafea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,25 +18,21 @@ let ViewBox = ViewBox_1 = class ViewBox extends Behaviour {
18
18
  static instances = [];
19
19
  referenceFieldOfView = 60;
20
20
  debug = false;
21
- // awake() {
22
- // // this.referenceFieldOfView = (this.context.mainCamera as PerspectiveCamera)?.fov || 60;
23
- // setInterval(()=>{
24
- // if(Math.random() > .5)
25
- // this.enabled = !this.enabled
26
- // }, 1000)
27
- // }
21
+ awake() {
22
+ // this.referenceFieldOfView = (this.context.mainCamera as PerspectiveCamera)?.fov || 60;
23
+ // setInterval(()=>{
24
+ // this.enabled = !this.enabled
25
+ // }, 1000)
26
+ }
28
27
  onEnable() {
29
28
  if (debugParam || this.debug || isDevEnvironment())
30
29
  console.debug("[ViewBox] Using camera fov:", this.referenceFieldOfView);
31
30
  ViewBox_1.instances.push(this);
32
31
  }
33
32
  onDisable() {
34
- if (debugParam || this.debug)
35
- console.debug("[ViewBox] Disabled");
36
33
  const idx = ViewBox_1.instances.indexOf(this);
37
34
  if (idx !== -1)
38
35
  ViewBox_1.instances.splice(idx, 1);
39
- this._projectedBoxElement?.remove();
40
36
  }
41
37
  onBeforeRender() {
42
38
  if (this.context.isInXR)
@@ -81,66 +77,33 @@ let ViewBox = ViewBox_1 = class ViewBox extends Behaviour {
81
77
  diffWidth = domWidth / rectWidth;
82
78
  diffHeight = domHeight / rectHeight;
83
79
  }
80
+ // const view = camera.view;
84
81
  const view = camera.view;
85
82
  const zoom = camera.zoom;
86
83
  const aspect = camera.aspect;
87
84
  const fov = camera.fov;
88
85
  camera.view = null;
89
86
  camera.zoom = 1;
87
+ // camera.aspect = rectWidth / rectHeight;
90
88
  camera.fov = this.referenceFieldOfView;
91
89
  camera.updateProjectionMatrix();
92
90
  const boxPosition = this.gameObject.worldPosition;
93
91
  const boxScale = this.gameObject.worldScale;
94
- const cameraPosition = camera.worldPosition;
95
- const distance = cameraPosition.distanceTo(boxPosition);
96
- // #region camera fixes
97
- // If the camera is inside the box, move it out
98
- const boxSizeMax = Math.max(boxScale.x, boxScale.y, boxScale.z);
99
- const direction = getTempVector(cameraPosition).sub(boxPosition);
100
- if (distance < boxSizeMax) {
101
- // move camera out of bounds
102
- if (this.debug || debugParam)
103
- console.warn("[ViewBox] Moving camera out of bounds", distance, "<", boxSizeMax);
104
- const positionDirection = getTempVector(direction);
105
- positionDirection.y *= .00000001; // stay on horizontal plane mostly
106
- positionDirection.normalize();
107
- const lengthToMove = (boxSizeMax - distance) * 10; // move a bit more than needed
108
- const newPosition = cameraPosition.add(positionDirection.multiplyScalar(lengthToMove));
109
- camera.worldPosition = newPosition.lerp(cameraPosition, 1 - this.context.time.deltaTime);
110
- }
111
- // Ensure the camera looks at the ViewBox
112
- // TOOD: smooth lookat over multiple frames if we have multiple viewboxes
113
- // const dot = direction.normalize().dot(camera.worldForward);
114
- // if (dot < .9) {
115
- // console.log(dot);
116
- // const targetRotation = direction;
117
- // const rotation = getTempQuaternion();
118
- // rotation.setFromUnitVectors(camera.worldForward.multiplyScalar(-1), targetRotation);
119
- // camera.worldQuaternion = rotation;
120
- // camera.updateMatrixWorld();
121
- // }
122
- const boxPositionInCameraSpace = getTempVector(boxPosition);
123
- camera.worldToLocal(boxPositionInCameraSpace);
124
- camera.lookAt(boxPosition);
125
- camera.updateMatrixWorld();
126
- // #region calculate fit
92
+ // const fov = this.referenceFieldOfView
93
+ const distance = camera.worldPosition.distanceTo(boxPosition);
127
94
  const vFOV = this.referenceFieldOfView * Math.PI / 180; // convert vertical fov to radians
128
95
  const height = 2 * Math.tan(vFOV / 2) * distance; // visible height
129
96
  const width = height * camera.aspect; // visible width
130
- const projectedBox = this.projectBoxIntoCamera(boxPosition, boxScale, camera, 1);
131
- // return
97
+ const projectedBox = this.projectBoxIntoCamera(boxPosition, boxScale, camera, height * .5);
132
98
  const boxWidth = (projectedBox.maxX - projectedBox.minX);
133
99
  const boxHeight = (projectedBox.maxY - projectedBox.minY);
100
+ // TODO: take the rect size different into account
134
101
  const scale = this.fit(boxWidth * camera.aspect, boxHeight, width / diffWidth, height / diffHeight);
135
- // console.log({ scale, width, height, boxWidth: boxWidth * camera.aspect, boxHeight, diffWidth, diffHeight, aspect: camera.aspect, distance })
136
- // this.context.focusRectSettings.zoom = 1.39;
137
- // if (!this.context.focusRect) this.context.setCameraFocusRect(this.context.domElement);
138
- // return
139
102
  const vec = getTempVector(boxPosition);
140
103
  vec.project(camera);
141
104
  this.context.focusRectSettings.offsetX = vec.x;
142
105
  this.context.focusRectSettings.offsetY = vec.y;
143
- this.context.focusRectSettings.zoom = scale / (height * .5);
106
+ this.context.focusRectSettings.zoom = scale;
144
107
  // if we don't have a focus rect yet, set it to the dom element
145
108
  if (!this.context.focusRect)
146
109
  this.context.setCameraFocusRect(this.context.domElement);
@@ -165,8 +128,8 @@ let ViewBox = ViewBox_1 = class ViewBox extends Behaviour {
165
128
  const scaleY = height2 / height1;
166
129
  return Math.min(scaleX, scaleY);
167
130
  }
168
- projectBoxIntoCamera(position, scale, camera, _factor) {
169
- const factor = .5 * _factor;
131
+ projectBoxIntoCamera(position, scale, camera, diff) {
132
+ const factor = .5 * diff;
170
133
  const corners = [
171
134
  getTempVector(-scale.x * factor, -scale.y * factor, -scale.z * factor),
172
135
  getTempVector(scale.x * factor, -scale.y * factor, -scale.z * factor),
@@ -194,21 +157,18 @@ let ViewBox = ViewBox_1 = class ViewBox extends Behaviour {
194
157
  if (c.y > maxY)
195
158
  maxY = c.y;
196
159
  }
197
- if (debugParam) {
198
- if (!this._projectedBoxElement) {
199
- this._projectedBoxElement = document.createElement("div");
200
- }
201
- if (this._projectedBoxElement.parentElement !== this.context.domElement)
202
- this.context.domElement.appendChild(this._projectedBoxElement);
203
- this._projectedBoxElement.style.position = "fixed";
204
- this._projectedBoxElement.style.outline = "5px dotted red";
205
- this._projectedBoxElement.style.left = ((minX * .5 + .5) * this.context.domWidth) + "px";
206
- this._projectedBoxElement.style.top = ((-maxY * .5 + .5) * this.context.domHeight) + "px";
207
- this._projectedBoxElement.style.width = ((maxX - minX) * .5 * this.context.domWidth) + "px";
208
- this._projectedBoxElement.style.height = ((maxY - minY) * .5 * this.context.domHeight) + "px";
209
- this._projectedBoxElement.style.pointerEvents = "none";
210
- this._projectedBoxElement.style.zIndex = "1000";
211
- }
160
+ // if(!this._projectedBoxElement) {
161
+ // this._projectedBoxElement = document.createElement("div");
162
+ // this.context.domElement.appendChild(this._projectedBoxElement);
163
+ // }
164
+ // this._projectedBoxElement.style.position = "fixed";
165
+ // this._projectedBoxElement.style.outline = "10px solid red";
166
+ // this._projectedBoxElement.style.left = ((minX * .5 + .5) * this.context.domWidth) + "px";
167
+ // this._projectedBoxElement.style.top = ((-maxY * .5 + .5) * this.context.domHeight) + "px";
168
+ // this._projectedBoxElement.style.width = ((maxX - minX) * .5 * this.context.domWidth) + "px";
169
+ // this._projectedBoxElement.style.height = ((maxY - minY) * .5 * this.context.domHeight) + "px";
170
+ // this._projectedBoxElement.style.pointerEvents = "none";
171
+ // this._projectedBoxElement.style.zIndex = "1000";
212
172
  return { minX, maxX, minY, maxY };
213
173
  }
214
174
  _projectedBoxElement = null;
@@ -1 +1 @@
1
- {"version":3,"file":"ViewBox.js","sourceRoot":"","sources":["../../../src/engine-components/web/ViewBox.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAU,iBAAiB,EAAoB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAqB,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,QAAQ,EA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AC,CAAC;YAC3B,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI;gBAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9B;QAED,mCAAmC;QACnC,iEAAiE;QACjE,kEAAkE;QAClE,IAAI;QACJ,sDAAsD;QACtD,8DAA8D;QAC9D,4FAA4F;QAC5F,6FAA6F;QAC7F,+FAA+F;QAC/F,iGAAiG;QACjG,0DAA0D;QAC1D,mDAAmD;QAGnD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAEtC,CAAC;IACO,oBAAoB,GAAuB,IAAI,CAAC;;AAlLxD;IADC,YAAY,EAAE;qDACmB;AAGlC;IADC,YAAY,EAAE;sCACQ;AARd,OAAO;IADnB,YAAY;GACA,OAAO,CA4LnB;SA5LY,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "4.10.0-beta.3",
3
+ "version": "4.10.0-next.2abafea",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.",
5
5
  "main": "dist/needle-engine.min.js",
6
6
  "exports": {
@@ -168,4 +168,4 @@
168
168
  "module": "lib/needle-engine.js",
169
169
  "typings": "lib/needle-engine.d.ts",
170
170
  "types": "lib/needle-engine.d.ts"
171
- }
171
+ }
@@ -38,18 +38,14 @@ const observedAttributes = [
38
38
  "loadstart",
39
39
  "progress",
40
40
  "loadfinished",
41
-
42
41
  "dracoDecoderPath",
43
42
  "dracoDecoderType",
44
43
  "ktx2DecoderPath",
45
-
46
44
  "tone-mapping",
47
45
  "tone-mapping-exposure",
48
46
  "background-blurriness",
49
47
  "background-color",
50
48
  "environment-intensity",
51
-
52
- "focus-rect",
53
49
  ]
54
50
 
55
51
  // https://developers.google.com/web/fundamentals/web-components/customelements
@@ -99,7 +95,7 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
99
95
  if (value === null) this.removeAttribute("camera-controls");
100
96
  else this.setAttribute("camera-controls", value ? "true" : "false");
101
97
  }
102
-
98
+
103
99
 
104
100
  /**
105
101
  * Get the current context for this web component instance. The context is created when the src attribute is set and the loading has finished.
@@ -335,17 +331,17 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
335
331
  if (debug) console.log("ktx2DecoderPath", newValue);
336
332
  setKtx2TranscoderPath(newValue);
337
333
  break;
338
-
334
+
339
335
  case "tonemapping":
340
336
  case "tone-mapping":
341
337
  case "tone-mapping-exposure":
342
338
  case "background-blurriness":
343
339
  case "background-color":
344
340
  case "environment-intensity":
345
- {
346
- this.applyAttributes();
347
- break;
348
- }
341
+ {
342
+ this.applyAttributes();
343
+ break;
344
+ }
349
345
  case "public-key": {
350
346
  if (newValue != PUBLIC_KEY)
351
347
  this.setPublicKey();
@@ -356,25 +352,6 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
356
352
  this.setVersion();
357
353
  break;
358
354
  }
359
-
360
- case "focus-rect":
361
- {
362
- const focus_rect = this.getAttribute("focus-rect") as HTMLElement | string | null;
363
- if (focus_rect && this._context) {
364
- if (focus_rect === null) {
365
- this._context.setCameraFocusRect(null);
366
- }
367
- else if (typeof focus_rect === "string" && focus_rect.length > 0) {
368
- const element = document.querySelector(focus_rect);
369
- this._context.setCameraFocusRect(element instanceof HTMLElement ? element : null);
370
- }
371
- else if (focus_rect instanceof HTMLElement) {
372
- this._context.setCameraFocusRect(focus_rect);
373
- }
374
-
375
- }
376
- }
377
- break;
378
355
  }
379
356
  }
380
357
 
@@ -594,7 +571,7 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
594
571
  this.context.scene.background = null;
595
572
  }
596
573
  // HACK: if we set background-color to a color and then back to null we want the background-image attribute to re-apply
597
- else if (this.getAttribute("background-image")) {
574
+ else if(this.getAttribute("background-image")) {
598
575
  this.setAttribute("background-image", this.getAttribute("background-image")!);
599
576
  }
600
577
  }
@@ -122,7 +122,7 @@ function createDefaultCameraControls(context: IContext, cam?: ICamera) {
122
122
  orbit.autoRotate = autoRotate != "0" && autoRotate?.toLowerCase() != "false";
123
123
  const autoRotateSpeed = Number.parseFloat(autoRotate || ".5");
124
124
  orbit.autoRotateSpeed = !isNaN(autoRotateSpeed) ? autoRotateSpeed : .5;
125
- if(debug) console.log("Auto-rotate", orbit.autoRotate, "speed:", orbit.autoRotateSpeed);
125
+ console.log("Auto-rotate", orbit.autoRotate, "speed:", orbit.autoRotateSpeed);
126
126
  const autoFit = context.domElement.getAttribute("auto-fit");
127
127
  orbit.autoFit = autoFit !== "0" && autoFit?.toLowerCase() != "false";
128
128
  orbit.autoTarget = true;
@@ -435,7 +435,7 @@ export class ScrollFollow extends Behaviour {
435
435
  time += diff * weight;
436
436
  }
437
437
  }
438
- if (debug && this.context.time.frame % 20 === 0) console.log(time.toFixed(3), [...weightsArray])
438
+ if (this.context.time.frame % 20 === 0) console.log(time.toFixed(3), [...weightsArray])
439
439
  if (this.damping <= 0) {
440
440
  director.time = time;
441
441
  }
@@ -3,7 +3,7 @@ import { Camera, PerspectiveCamera, Vector2, Vector3 } from "three";
3
3
  import { isDevEnvironment } from "../../engine/debug/debug.js";
4
4
  import { Gizmos } from "../../engine/engine_gizmos.js";
5
5
  import { serializable } from "../../engine/engine_serialization_decorator.js";
6
- import { getTempQuaternion, getTempVector } from "../../engine/engine_three_utils.js";
6
+ import { getTempVector } from "../../engine/engine_three_utils.js";
7
7
  import { registerType } from "../../engine/engine_typestore.js";
8
8
  import { getParam } from "../../engine/engine_utils.js";
9
9
  import { Behaviour } from "../Component.js";
@@ -21,24 +21,20 @@ export class ViewBox extends Behaviour {
21
21
  @serializable()
22
22
  debug: boolean = false;
23
23
 
24
- // awake() {
25
- // // this.referenceFieldOfView = (this.context.mainCamera as PerspectiveCamera)?.fov || 60;
26
- // setInterval(()=>{
27
- // if(Math.random() > .5)
28
- // this.enabled = !this.enabled
29
- // }, 1000)
30
- // }
31
-
24
+ awake() {
25
+ // this.referenceFieldOfView = (this.context.mainCamera as PerspectiveCamera)?.fov || 60;
26
+ // setInterval(()=>{
27
+ // this.enabled = !this.enabled
28
+ // }, 1000)
29
+ }
32
30
  onEnable(): void {
33
31
  if (debugParam || this.debug || isDevEnvironment()) console.debug("[ViewBox] Using camera fov:", this.referenceFieldOfView);
34
32
  ViewBox.instances.push(this);
35
33
  }
36
34
 
37
35
  onDisable(): void {
38
- if (debugParam || this.debug) console.debug("[ViewBox] Disabled");
39
36
  const idx = ViewBox.instances.indexOf(this);
40
37
  if (idx !== -1) ViewBox.instances.splice(idx, 1);
41
- this._projectedBoxElement?.remove();
42
38
  }
43
39
 
44
40
  onBeforeRender() {
@@ -84,80 +80,44 @@ export class ViewBox extends Behaviour {
84
80
  diffHeight = domHeight / rectHeight;
85
81
  }
86
82
 
87
-
83
+ // const view = camera.view;
88
84
  const view = camera.view;
89
85
  const zoom = camera.zoom;
90
86
  const aspect = camera.aspect;
91
87
  const fov = camera.fov;
92
88
  camera.view = null;
93
89
  camera.zoom = 1;
90
+ // camera.aspect = rectWidth / rectHeight;
94
91
  camera.fov = this.referenceFieldOfView;
95
92
  camera.updateProjectionMatrix();
96
93
 
97
94
  const boxPosition = this.gameObject.worldPosition;
98
95
  const boxScale = this.gameObject.worldScale;
99
96
 
100
- const cameraPosition = camera.worldPosition;
101
- const distance = cameraPosition.distanceTo(boxPosition);
102
-
103
-
104
- // #region camera fixes
105
- // If the camera is inside the box, move it out
106
- const boxSizeMax = Math.max(boxScale.x, boxScale.y, boxScale.z);
107
- const direction = getTempVector(cameraPosition).sub(boxPosition);
108
- if (distance < boxSizeMax) {
109
- // move camera out of bounds
110
- if (this.debug || debugParam) console.warn("[ViewBox] Moving camera out of bounds", distance, "<", boxSizeMax);
111
- const positionDirection = getTempVector(direction);
112
- positionDirection.y *= .00000001; // stay on horizontal plane mostly
113
- positionDirection.normalize();
114
- const lengthToMove = (boxSizeMax - distance) * 10; // move a bit more than needed
115
- const newPosition = cameraPosition.add(positionDirection.multiplyScalar(lengthToMove));
116
- camera.worldPosition = newPosition.lerp(cameraPosition, 1 - this.context.time.deltaTime);
117
- }
118
-
119
- // Ensure the camera looks at the ViewBox
120
- // TOOD: smooth lookat over multiple frames if we have multiple viewboxes
121
- // const dot = direction.normalize().dot(camera.worldForward);
122
- // if (dot < .9) {
123
- // console.log(dot);
124
- // const targetRotation = direction;
125
- // const rotation = getTempQuaternion();
126
- // rotation.setFromUnitVectors(camera.worldForward.multiplyScalar(-1), targetRotation);
127
- // camera.worldQuaternion = rotation;
128
- // camera.updateMatrixWorld();
129
- // }
130
- const boxPositionInCameraSpace = getTempVector(boxPosition);
131
- camera.worldToLocal(boxPositionInCameraSpace);
132
- camera.lookAt(boxPosition);
133
- camera.updateMatrixWorld();
134
97
 
135
98
 
136
- // #region calculate fit
99
+ // const fov = this.referenceFieldOfView
100
+ const distance = camera.worldPosition.distanceTo(boxPosition);
137
101
  const vFOV = this.referenceFieldOfView * Math.PI / 180; // convert vertical fov to radians
138
102
  const height = 2 * Math.tan(vFOV / 2) * distance; // visible height
139
103
  const width = height * camera.aspect; // visible width
140
104
 
141
- const projectedBox = this.projectBoxIntoCamera(boxPosition, boxScale, camera, 1);
142
- // return
105
+ const projectedBox = this.projectBoxIntoCamera(boxPosition, boxScale, camera, height * .5);
143
106
  const boxWidth = (projectedBox.maxX - projectedBox.minX);
144
107
  const boxHeight = (projectedBox.maxY - projectedBox.minY);
145
108
 
109
+ // TODO: take the rect size different into account
146
110
  const scale = this.fit(
147
111
  boxWidth * camera.aspect,
148
112
  boxHeight,
149
113
  width / diffWidth,
150
114
  height / diffHeight
151
115
  );
152
- // console.log({ scale, width, height, boxWidth: boxWidth * camera.aspect, boxHeight, diffWidth, diffHeight, aspect: camera.aspect, distance })
153
- // this.context.focusRectSettings.zoom = 1.39;
154
- // if (!this.context.focusRect) this.context.setCameraFocusRect(this.context.domElement);
155
- // return
156
116
  const vec = getTempVector(boxPosition);
157
117
  vec.project(camera);
158
118
  this.context.focusRectSettings.offsetX = vec.x;
159
119
  this.context.focusRectSettings.offsetY = vec.y;
160
- this.context.focusRectSettings.zoom = scale / (height * .5);
120
+ this.context.focusRectSettings.zoom = scale;
161
121
  // if we don't have a focus rect yet, set it to the dom element
162
122
  if (!this.context.focusRect) this.context.setCameraFocusRect(this.context.domElement);
163
123
 
@@ -189,8 +149,9 @@ export class ViewBox extends Behaviour {
189
149
 
190
150
 
191
151
 
192
- private projectBoxIntoCamera(position: Vector3, scale: Vector3, camera: Camera, _factor: number) {
193
- const factor = .5 * _factor;
152
+ private projectBoxIntoCamera(position: Vector3, scale: Vector3, camera: Camera, diff: number) {
153
+
154
+ const factor = .5 * diff;
194
155
 
195
156
  const corners = [
196
157
  getTempVector(-scale.x * factor, -scale.y * factor, -scale.z * factor),
@@ -216,21 +177,18 @@ export class ViewBox extends Behaviour {
216
177
  if (c.y > maxY) maxY = c.y;
217
178
  }
218
179
 
219
- if (debugParam) {
220
- if (!this._projectedBoxElement) {
221
- this._projectedBoxElement = document.createElement("div");
222
- }
223
- if (this._projectedBoxElement.parentElement !== this.context.domElement)
224
- this.context.domElement.appendChild(this._projectedBoxElement);
225
- this._projectedBoxElement.style.position = "fixed";
226
- this._projectedBoxElement.style.outline = "5px dotted red";
227
- this._projectedBoxElement.style.left = ((minX * .5 + .5) * this.context.domWidth) + "px";
228
- this._projectedBoxElement.style.top = ((-maxY * .5 + .5) * this.context.domHeight) + "px";
229
- this._projectedBoxElement.style.width = ((maxX - minX) * .5 * this.context.domWidth) + "px";
230
- this._projectedBoxElement.style.height = ((maxY - minY) * .5 * this.context.domHeight) + "px";
231
- this._projectedBoxElement.style.pointerEvents = "none";
232
- this._projectedBoxElement.style.zIndex = "1000";
233
- }
180
+ // if(!this._projectedBoxElement) {
181
+ // this._projectedBoxElement = document.createElement("div");
182
+ // this.context.domElement.appendChild(this._projectedBoxElement);
183
+ // }
184
+ // this._projectedBoxElement.style.position = "fixed";
185
+ // this._projectedBoxElement.style.outline = "10px solid red";
186
+ // this._projectedBoxElement.style.left = ((minX * .5 + .5) * this.context.domWidth) + "px";
187
+ // this._projectedBoxElement.style.top = ((-maxY * .5 + .5) * this.context.domHeight) + "px";
188
+ // this._projectedBoxElement.style.width = ((maxX - minX) * .5 * this.context.domWidth) + "px";
189
+ // this._projectedBoxElement.style.height = ((maxY - minY) * .5 * this.context.domHeight) + "px";
190
+ // this._projectedBoxElement.style.pointerEvents = "none";
191
+ // this._projectedBoxElement.style.zIndex = "1000";
234
192
 
235
193
 
236
194
  return { minX, maxX, minY, maxY };