rayzee 7.15.2 → 7.16.0

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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rayzee Engine
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/rayzee?label=npm)](https://www.npmjs.com/package/rayzee)
4
- [![minzipped size](https://img.shields.io/badge/minzipped-170.1%20KB-blue)](https://www.npmjs.com/package/rayzee)
4
+ [![minzipped size](https://img.shields.io/badge/minzipped-170.7%20KB-blue)](https://www.npmjs.com/package/rayzee)
5
5
  [![downloads](https://img.shields.io/npm/dw/rayzee?label=downloads)](https://www.npmjs.com/package/rayzee)
6
6
  [![jsDelivr](https://img.shields.io/jsdelivr/npm/hm/rayzee?label=jsDelivr)](https://www.jsdelivr.com/package/npm/rayzee)
7
7
 
package/dist/rayzee.es.js CHANGED
@@ -14283,21 +14283,21 @@ var rf = {
14283
14283
  prev: i
14284
14284
  }));
14285
14285
  }
14286
- setMany(e, { silent: t } = {}) {
14287
- let n = !1;
14288
- for (let [r, i] of Object.entries(e)) {
14289
- let e = this._values.get(r);
14286
+ setMany(e, { silent: t, reset: n } = {}) {
14287
+ let r = !1;
14288
+ for (let [n, i] of Object.entries(e)) {
14289
+ let e = this._values.get(n);
14290
14290
  if (e === i) continue;
14291
- this._values.set(r, i);
14292
- let a = of[r];
14293
- a && (this._applyRoute(a, i, e), (a.reset ?? !0) && (n = !0), t || this.dispatchEvent({
14291
+ this._values.set(n, i);
14292
+ let a = of[n];
14293
+ a && (this._applyRoute(a, i, e), (a.reset ?? !0) && (r = !0), t || this.dispatchEvent({
14294
14294
  type: Y.SETTING_CHANGED,
14295
- key: r,
14295
+ key: n,
14296
14296
  value: i,
14297
14297
  prev: e
14298
14298
  }));
14299
14299
  }
14300
- n && this._resetCallback?.();
14300
+ (n === void 0 ? r : n) && this._resetCallback?.();
14301
14301
  }
14302
14302
  get(e) {
14303
14303
  return this._values.get(e);
@@ -14322,44 +14322,89 @@ var rf = {
14322
14322
  constructor(e) {
14323
14323
  super();
14324
14324
  let t = e.clientWidth, n = e.clientHeight;
14325
- this.camera = new At(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new gn(this.camera, e), this.controls.screenSpacePanning = !0, this.controls.zoomToCursor = !0, this.controls.saveState(), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this.autoFocusMode = xr.SMOOTHING_FACTOR ? "auto" : "manual", this.afScreenPoint = {
14325
+ this.camera = new At(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new gn(this.camera, e), this.controls.screenSpacePanning = !0, this.controls.zoomToCursor = !0, this.controls.saveState(), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this._userCameraCounter = 0, this.autoFocusMode = xr.SMOOTHING_FACTOR ? "auto" : "manual", this.afScreenPoint = {
14326
14326
  x: .5,
14327
14327
  y: .5
14328
- }, this.afSmoothingFactor = xr.SMOOTHING_FACTOR, this._lastValidFocusDistance = null, this._smoothedFocusDistance = null, this._afPointDirty = !1, this._afSuspended = !1, this._defaultCameraState = null, this._onResize = null, this._onReset = null, this._getSettings = null;
14328
+ }, this.afSmoothingFactor = xr.SMOOTHING_FACTOR, this._lastValidFocusDistance = null, this._smoothedFocusDistance = null, this._afPointDirty = !1, this._afSuspended = !1, this._defaultCameraState = null, this._onResize = null, this._onReset = null, this._getSettings = null, this._applySettings = null;
14329
14329
  }
14330
14330
  setCameras(e) {
14331
- this.cameras = e;
14331
+ this.cameras = e, this._userCameraCounter = 0;
14332
+ }
14333
+ addCameraFromView(e) {
14334
+ let t = this.camera, n = new At(t.fov, t.aspect, t.near, t.far);
14335
+ return n.position.copy(t.position), n.quaternion.copy(t.quaternion), n.updateMatrixWorld(!0), n.userData.__rayzeeUserCamera = !0, n.userData.__rayzeeEffects = this._captureEffects(), this.controls && (n.userData.__rayzeeOrbitTarget = this.controls.target.clone()), this._userCameraCounter += 1, n.name = e || `View Camera ${this._userCameraCounter}`, this.cameras.push(n), this.cameras.length - 1;
14336
+ }
14337
+ removeCamera(e) {
14338
+ if (!Number.isInteger(e) || e <= 0 || e >= this.cameras.length || !this.cameras[e]?.userData?.__rayzeeUserCamera) return !1;
14339
+ let t = this.currentCameraIndex === e;
14340
+ return this.cameras.splice(e, 1), t ? (this.currentCameraIndex = -1, this.switchCamera(0)) : this.currentCameraIndex > e && --this.currentCameraIndex, !0;
14332
14341
  }
14333
14342
  getCameraNames() {
14334
14343
  return !this.cameras || this.cameras.length === 0 ? ["Default Camera"] : this.cameras.map((e, t) => t === 0 ? "Default Camera" : e.name || `Camera ${t}`);
14335
14344
  }
14336
- initCallbacks({ onResize: e, onReset: t, getSettings: n }) {
14337
- this._onResize = e, this._onReset = t, this._getSettings = n;
14345
+ initCallbacks({ onResize: e, onReset: t, getSettings: n, applySettings: r }) {
14346
+ this._onResize = e, this._onReset = t, this._getSettings = n, this._applySettings = r;
14347
+ }
14348
+ _captureEffects() {
14349
+ let e = this._getSettings;
14350
+ return e ? {
14351
+ enableDOF: e("enableDOF"),
14352
+ focusDistance: e("focusDistance"),
14353
+ aperture: e("aperture"),
14354
+ focalLength: e("focalLength"),
14355
+ apertureScale: e("apertureScale"),
14356
+ anamorphicRatio: e("anamorphicRatio"),
14357
+ autoFocusMode: this.autoFocusMode,
14358
+ afScreenPoint: { ...this.afScreenPoint }
14359
+ } : null;
14360
+ }
14361
+ _applyEffects(e) {
14362
+ e && (this._applySettings?.({
14363
+ enableDOF: e.enableDOF,
14364
+ focusDistance: e.focusDistance,
14365
+ aperture: e.aperture,
14366
+ focalLength: e.focalLength,
14367
+ apertureScale: e.apertureScale,
14368
+ anamorphicRatio: e.anamorphicRatio
14369
+ }), e.autoFocusMode !== void 0 && this.setAutoFocusMode(e.autoFocusMode), e.afScreenPoint && this.setAFScreenPoint(e.afScreenPoint.x, e.afScreenPoint.y));
14370
+ }
14371
+ _getSceneScale() {
14372
+ return this._afContext?.assetLoader?.getSceneScale?.() || 1;
14338
14373
  }
14339
14374
  switchCamera(e, t, n, r) {
14340
- if (t ??= this._getSettings?.("focusDistance"), n ??= this._onResize, r ??= this._onReset, !(!this.cameras || this.cameras.length === 0)) {
14341
- if ((e < 0 || e >= this.cameras.length) && (console.warn(`CameraManager: Invalid camera index ${e}. Using default camera.`), e = 0), this.currentCameraIndex === 0 && e !== 0 && (this._defaultCameraState = {
14342
- position: this.camera.position.clone(),
14343
- quaternion: this.camera.quaternion.clone(),
14344
- fov: this.camera.fov,
14345
- near: this.camera.near,
14346
- far: this.camera.far,
14347
- target: this.controls ? this.controls.target.clone() : null
14348
- }), this.currentCameraIndex = e, e === 0 && this._defaultCameraState) {
14349
- let e = this._defaultCameraState;
14350
- this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.fov = e.fov, this.camera.near = e.near, this.camera.far = e.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls && e.target && (this.controls.target.copy(e.target), this.controls.update());
14351
- } else {
14352
- let n = this.cameras[e];
14353
- if (this.camera.position.copy(n.position), this.camera.quaternion.copy(n.quaternion), this.camera.fov = n.fov, this.camera.near = n.near, this.camera.far = n.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls) {
14375
+ if (t ??= this._getSettings?.("focusDistance"), n ??= this._onResize, r ??= this._onReset, !this.cameras || this.cameras.length === 0) return;
14376
+ (e < 0 || e >= this.cameras.length) && (console.warn(`CameraManager: Invalid camera index ${e}. Using default camera.`), e = 0);
14377
+ let i = this.cameras[this.currentCameraIndex];
14378
+ if (i && (i.userData.__rayzeeEffects = this._captureEffects()), this.currentCameraIndex === 0 && e !== 0 && (this._defaultCameraState = {
14379
+ position: this.camera.position.clone(),
14380
+ quaternion: this.camera.quaternion.clone(),
14381
+ fov: this.camera.fov,
14382
+ near: this.camera.near,
14383
+ far: this.camera.far,
14384
+ target: this.controls ? this.controls.target.clone() : null
14385
+ }), this.currentCameraIndex = e, e === 0 && this._defaultCameraState) {
14386
+ let e = this._defaultCameraState;
14387
+ this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.fov = e.fov, this.camera.near = e.near, this.camera.far = e.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls && e.target && (this.controls.target.copy(e.target), this.controls.update());
14388
+ } else {
14389
+ let n = this.cameras[e];
14390
+ if (this.camera.position.copy(n.position), this.camera.quaternion.copy(n.quaternion), this.camera.fov = n.fov, this.camera.near = n.near, this.camera.far = n.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls) {
14391
+ let e = n.userData?.__rayzeeOrbitTarget;
14392
+ if (e) this.controls.target.copy(e);
14393
+ else {
14354
14394
  let e = new rn(0, 0, -1).applyQuaternion(n.quaternion), r = t || 5;
14355
- this.controls.target.copy(this.camera.position).addScaledVector(e, r), this.controls.update();
14395
+ this.controls.target.copy(this.camera.position).addScaledVector(e, r);
14356
14396
  }
14397
+ this.controls.update();
14357
14398
  }
14358
- n?.(), r?.(), this.dispatchEvent({
14359
- type: "CameraSwitched",
14360
- cameraIndex: e
14361
- });
14362
14399
  }
14400
+ this._applyEffects(this.cameras[e]?.userData?.__rayzeeEffects), n?.(), r?.();
14401
+ let a = this._captureEffects();
14402
+ a && (a.focusDistance /= this._getSceneScale()), this.dispatchEvent({
14403
+ type: "CameraSwitched",
14404
+ cameraIndex: e,
14405
+ effects: a,
14406
+ fov: this.camera.fov
14407
+ });
14363
14408
  }
14364
14409
  focusOn(e) {
14365
14410
  !e || !this.controls || (this.controls.target.copy(e), this.controls.update(), this._onReset?.());
@@ -16372,11 +16417,7 @@ var Yf = {
16372
16417
  if (this._loadingInProgress) throw Error("PathTracerApp: another load is already in progress");
16373
16418
  this._loadingInProgress = !0;
16374
16419
  try {
16375
- await e(), this._emissiveSamplingUserSet = !1, this._clearAppendedModels(), this._syncControlsAfterLoad(), await this.loadSceneData(), this.pipeline?.eventBus.emit("autoexposure:resetHistory"), this.reset(), this.cameraManager.currentCameraIndex = 0, this.dispatchEvent(t), this.dispatchEvent({
16376
- type: "CamerasUpdated",
16377
- cameras: this.cameraManager.cameras,
16378
- cameraNames: this.cameraManager.getCameraNames()
16379
- });
16420
+ await e(), this._emissiveSamplingUserSet = !1, this._clearAppendedModels(), this._syncControlsAfterLoad(), await this.loadSceneData(), this.pipeline?.eventBus.emit("autoexposure:resetHistory"), this.reset(), this.cameraManager.currentCameraIndex = 0, this.dispatchEvent(t), this._dispatchCamerasUpdated();
16380
16421
  } finally {
16381
16422
  this._loadingInProgress = !1;
16382
16423
  }
@@ -16469,6 +16510,24 @@ var Yf = {
16469
16510
  setSceneObjectVisibility(e, t) {
16470
16511
  return this.setMeshVisibilityByUuid(e, t);
16471
16512
  }
16513
+ get currentCameraIndex() {
16514
+ return this.cameraManager?.currentCameraIndex ?? 0;
16515
+ }
16516
+ addCamera({ name: e } = {}) {
16517
+ let t = this.cameraManager.addCameraFromView(e);
16518
+ return this.cameraManager.switchCamera(t), this._dispatchCamerasUpdated(), t;
16519
+ }
16520
+ removeCamera(e) {
16521
+ let t = this.cameraManager.removeCamera(e);
16522
+ return t && this._dispatchCamerasUpdated(), t;
16523
+ }
16524
+ _dispatchCamerasUpdated() {
16525
+ this.dispatchEvent({
16526
+ type: "CamerasUpdated",
16527
+ cameras: this.cameraManager.cameras,
16528
+ cameraNames: this.cameraManager.getCameraNames()
16529
+ });
16530
+ }
16472
16531
  async refitBVH(e, t) {
16473
16532
  let n = await this._sdf.refitBVH(e, t);
16474
16533
  return this.stages.pathTracer.updateTriangleData(this._sdf.triangleData), this.stages.pathTracer.updateBVHData(this._sdf.bvhData), this.reset(), n;
@@ -16699,7 +16758,11 @@ var Yf = {
16699
16758
  }), this.cameraManager.initCallbacks({
16700
16759
  onResize: () => this.onResize(),
16701
16760
  onReset: () => this.reset(),
16702
- getSettings: (e) => this.settings.get(e)
16761
+ getSettings: (e) => this.settings.get(e),
16762
+ applySettings: (e) => this.settings.setMany(e, {
16763
+ silent: !0,
16764
+ reset: !1
16765
+ })
16703
16766
  }), this.cameraManager.initAutoFocus({
16704
16767
  meshScene: this.meshScene,
16705
16768
  assetLoader: this.assetLoader,