@canvas3/nuxt 0.1.34 → 0.1.36

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "canvas-nuxt-layout",
3
3
  "configKey": "canvas3Layout",
4
- "version": "0.1.34",
4
+ "version": "0.1.36",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -26,6 +26,17 @@ export const vCanvas3ScrollAction = {
26
26
  );
27
27
  }
28
28
  },
29
+ updated(el, binding) {
30
+ if (!Canvas3.canvasInitiated.value) return;
31
+ const newScrollSpeedValue = binding.value?.scrollSpeedSetTo?.value;
32
+ if (newScrollSpeedValue !== void 0 && newScrollSpeedValue !== binding.oldValue?.scrollSpeedSetTo?.value) {
33
+ Canvas3.updateOnScrollActiveElement({
34
+ elNode: el,
35
+ options: binding.value,
36
+ arg: binding.arg
37
+ });
38
+ }
39
+ },
29
40
  unmounted(el) {
30
41
  Canvas3.removeScrollActiveElement(el);
31
42
  },
@@ -38,7 +38,8 @@ watch(
38
38
  );
39
39
  emit("canvas3-ready");
40
40
  }
41
- }
41
+ },
42
+ { immediate: true }
42
43
  );
43
44
  </script>
44
45
 
@@ -42,7 +42,12 @@ declare class Canvas3Class {
42
42
  xPrev: number;
43
43
  yPrev: number;
44
44
  };
45
+ frameCount: number;
46
+ lastFpsTime: number;
47
+ fps: number;
48
+ fpsUpdateInterval: number;
45
49
  init(canvasElement: HTMLElement, scrollableContent: HTMLElement, canvas3Options: Canvas3OptionsType): Promise<void>;
50
+ setScrollShaderByName(shaderName: string): void;
46
51
  setRenderDisabled(status: boolean): void;
47
52
  setCanvasAndCamera(): void;
48
53
  resizeOnChange(): void;
@@ -51,6 +56,7 @@ declare class Canvas3Class {
51
56
  meshUniformsUpdate(id: string, uniforms: MeshMaterialUniform | BaseUniform): void;
52
57
  activateMesh(meshId: string, isActive: boolean): void;
53
58
  addOnScrollActivateElement(binding: ScrollActionBinding): void;
59
+ updateOnScrollActiveElement(updatedBinding: ScrollActionBinding): void;
54
60
  removeScrollActiveElement(elNode: HTMLElement): void;
55
61
  removeMesh(id: string): void;
56
62
  addAnimationToRender(callBackName: string, callBackSetup: AnimationCallSetup): void;
@@ -53,6 +53,11 @@ class Canvas3Class {
53
53
  customPass = null;
54
54
  animations = /* @__PURE__ */ new Map();
55
55
  mouse = { x: 0, y: 0, movementX: 0, movementY: 0, xPrev: 0, yPrev: 0 };
56
+ // FPS tracking
57
+ frameCount = 0;
58
+ lastFpsTime = 0;
59
+ fps = 0;
60
+ fpsUpdateInterval = 500;
56
61
  async init(canvasElement, scrollableContent, canvas3Options) {
57
62
  this.options = canvas3Options;
58
63
  this.scene = new THREE.Scene();
@@ -96,6 +101,15 @@ class Canvas3Class {
96
101
  this.canvasInitiated.value = true;
97
102
  studio783log();
98
103
  }
104
+ setScrollShaderByName(shaderName) {
105
+ const newShader = this.options.shaders[shaderName];
106
+ if (!newShader || !this.customPass) return;
107
+ this.myEffect.vertexShader = newShader.vertexShader;
108
+ this.myEffect.fragmentShader = newShader.fragmentShader;
109
+ this.customPass.material.vertexShader = newShader.vertexShader;
110
+ this.customPass.material.fragmentShader = newShader.fragmentShader;
111
+ this.customPass.material.needsUpdate = true;
112
+ }
99
113
  setRenderDisabled(status) {
100
114
  if (!status && this.renderDisabled) {
101
115
  this.renderDisabled = false;
@@ -213,6 +227,19 @@ class Canvas3Class {
213
227
  const newBinding = generateBindingLogic(binding);
214
228
  this.scroll?.DOM.onScrollActivateElements.push(newBinding);
215
229
  }
230
+ updateOnScrollActiveElement(updatedBinding) {
231
+ if (!this.scroll) return;
232
+ for (const [
233
+ index,
234
+ item
235
+ ] of this.scroll.DOM.onScrollActivateElements.entries()) {
236
+ if (item.elNode.dataset.scrollActivateId === updatedBinding.elNode.dataset.scrollActivateId) {
237
+ const updatedBindingFormated = generateBindingLogic(updatedBinding);
238
+ console.log("updatedBindingFormated", updatedBindingFormated);
239
+ this.scroll.DOM.onScrollActivateElements[index] = updatedBindingFormated;
240
+ }
241
+ }
242
+ }
216
243
  removeScrollActiveElement(elNode) {
217
244
  if (!elNode || !this.scroll?.DOM.onScrollActivateElements || this.scroll?.DOM.onScrollActivateElements.length === 0)
218
245
  return;
@@ -427,11 +454,40 @@ class Canvas3Class {
427
454
  if (!this.lastTime) this.lastTime = timestamp;
428
455
  const delta = (timestamp - this.lastTime) / 1e3;
429
456
  this.lastTime = timestamp;
457
+ if (!this.lastFpsTime) this.lastFpsTime = timestamp;
458
+ this.frameCount++;
459
+ const elapsedSinceFpsStart = timestamp - this.lastFpsTime;
460
+ if (elapsedSinceFpsStart >= this.fpsUpdateInterval) {
461
+ this.fps = Math.round(
462
+ this.frameCount * 1e3 / elapsedSinceFpsStart
463
+ );
464
+ this.frameCount = 0;
465
+ this.lastFpsTime = timestamp;
466
+ }
430
467
  this.render(delta);
431
468
  this.rafId = requestAnimationFrame(loop);
432
469
  };
433
470
  this.rafId = requestAnimationFrame(loop);
434
471
  }
472
+ // startRenderLoop() {
473
+ // if (this.rafId !== null) return
474
+ //
475
+ // const loop = (timestamp: number) => {
476
+ // this.rafId = null
477
+ //
478
+ // if (!this.documentVisibility || this.renderDisabled) return
479
+ //
480
+ // if (!this.lastTime) this.lastTime = timestamp
481
+ // const delta = (timestamp - this.lastTime) / 1000
482
+ // this.lastTime = timestamp
483
+ //
484
+ // this.render(delta)
485
+ //
486
+ // this.rafId = requestAnimationFrame(loop)
487
+ // }
488
+ //
489
+ // this.rafId = requestAnimationFrame(loop)
490
+ // }
435
491
  stopRenderLoop() {
436
492
  if (this.rafId !== null) {
437
493
  cancelAnimationFrame(this.rafId);
@@ -22,4 +22,5 @@ export declare const Canvas3: {
22
22
  getCamera: () => import("three").PerspectiveCamera | null;
23
23
  getRenderer: () => import("three").WebGLRenderer | null;
24
24
  getScene: () => import("three").Scene;
25
+ setScrollShaderByName: (shaderName: string) => void;
25
26
  };
@@ -31,5 +31,6 @@ export const Canvas3 = {
31
31
  },
32
32
  getCamera: () => mainClass.camera,
33
33
  getRenderer: () => mainClass.renderer,
34
- getScene: () => mainClass.scene
34
+ getScene: () => mainClass.scene,
35
+ setScrollShaderByName: mainClass.setScrollShaderByName.bind(mainClass)
35
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas3/nuxt",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },