@canvas3/nuxt 0.1.18 → 0.1.19
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 +1 -1
- package/dist/runtime/types/types.d.ts +8 -1
- package/dist/runtime/utils/canvas3/canvas3.d.ts +8 -3
- package/dist/runtime/utils/canvas3/canvas3.js +33 -131
- package/dist/runtime/utils/exports.d.ts +2 -1
- package/dist/runtime/utils/exports.js +1 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -19,7 +19,14 @@ type MeshAnimation = {
|
|
|
19
19
|
ease: string;
|
|
20
20
|
};
|
|
21
21
|
export type AnimationCallback = () => void;
|
|
22
|
-
export type
|
|
22
|
+
export type AnimationCallOptions = {
|
|
23
|
+
onScroll: boolean;
|
|
24
|
+
onResize: boolean;
|
|
25
|
+
onMouseMove: boolean;
|
|
26
|
+
onAnimationsRender: boolean;
|
|
27
|
+
animationCallback: AnimationCallback;
|
|
28
|
+
};
|
|
29
|
+
export type AnimationCallbacks = Map<string, AnimationCallOptions>;
|
|
23
30
|
export type MeshMaterialUniform = Record<string, {
|
|
24
31
|
duration: number;
|
|
25
32
|
ease: string | null | undefined;
|
|
@@ -4,10 +4,13 @@ import type { Pass } from 'three/addons/postprocessing/Pass.js';
|
|
|
4
4
|
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
5
5
|
import type { ShaderMaterial, WebGLRenderer } from 'three';
|
|
6
6
|
import Scroll from '#canvas3-nuxt/utils/canvas3/scroll';
|
|
7
|
-
import type {
|
|
7
|
+
import type { AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType, AnimationCallOptions } from '#canvas3-nuxt/types/types';
|
|
8
8
|
declare class Canvas3Class {
|
|
9
9
|
canvasInitiated: import("vue").Ref<boolean, boolean>;
|
|
10
|
-
|
|
10
|
+
mouseMoveInProgress: boolean;
|
|
11
|
+
animationsRender: boolean;
|
|
12
|
+
resizeInProgress: boolean;
|
|
13
|
+
meshPositionsUpdate: boolean;
|
|
11
14
|
canvasContainer: HTMLElement | null;
|
|
12
15
|
scrollableContent: HTMLElement | null;
|
|
13
16
|
time: number;
|
|
@@ -46,7 +49,7 @@ declare class Canvas3Class {
|
|
|
46
49
|
updateOnScrollActiveElement(updatedBinding: ScrollActionBinding): void;
|
|
47
50
|
removeScrollActiveElement(elNode: HTMLElement): void;
|
|
48
51
|
removeMesh(id: string): void;
|
|
49
|
-
addAnimationToRender(callBackName: string,
|
|
52
|
+
addAnimationToRender(callBackName: string, callBackOptions: AnimationCallOptions): void;
|
|
50
53
|
removeAnimationFromRender(callBackName: string): void;
|
|
51
54
|
addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
|
|
52
55
|
composerPass(): void;
|
|
@@ -55,6 +58,8 @@ declare class Canvas3Class {
|
|
|
55
58
|
scrollTo(position: number, delay?: number): void;
|
|
56
59
|
scrollToElBySelector(elQuerySelector: string, delay?: number, margin?: number): void;
|
|
57
60
|
setMeshPositionsUpdate(state: boolean): void;
|
|
61
|
+
setAnimationsToRender(state: boolean): void;
|
|
62
|
+
externalAnimationsRender(): void;
|
|
58
63
|
render(): void;
|
|
59
64
|
}
|
|
60
65
|
export declare const Canvas3: Canvas3Class;
|
|
@@ -14,7 +14,10 @@ import { studio783log } from "#canvas3-nuxt/constants/studio783Log";
|
|
|
14
14
|
const canvasInitiated = ref(false);
|
|
15
15
|
class Canvas3Class {
|
|
16
16
|
canvasInitiated = canvasInitiated;
|
|
17
|
-
|
|
17
|
+
mouseMoveInProgress = false;
|
|
18
|
+
animationsRender = false;
|
|
19
|
+
resizeInProgress = false;
|
|
20
|
+
meshPositionsUpdate = false;
|
|
18
21
|
canvasContainer = null;
|
|
19
22
|
scrollableContent = null;
|
|
20
23
|
time = 0;
|
|
@@ -59,6 +62,7 @@ class Canvas3Class {
|
|
|
59
62
|
this.composerPass();
|
|
60
63
|
this.render();
|
|
61
64
|
window.addEventListener("mousemove", (event) => {
|
|
65
|
+
this.mouseMoveInProgress = true;
|
|
62
66
|
this.mouse.x = event.clientX / this.width;
|
|
63
67
|
this.mouse.y = event.clientY / this.height;
|
|
64
68
|
setTimeout(() => {
|
|
@@ -69,6 +73,9 @@ class Canvas3Class {
|
|
|
69
73
|
this.mouse.movementX = this.mouse.x;
|
|
70
74
|
this.mouse.movementY = this.mouse.y;
|
|
71
75
|
}
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
this.mouseMoveInProgress = false;
|
|
78
|
+
}, 0);
|
|
72
79
|
});
|
|
73
80
|
this.canvasInitiated.value = true;
|
|
74
81
|
studio783log();
|
|
@@ -91,10 +98,14 @@ class Canvas3Class {
|
|
|
91
98
|
this.canvasContainer?.appendChild(this.renderer.domElement);
|
|
92
99
|
}
|
|
93
100
|
resizeOnChange() {
|
|
101
|
+
this.resizeInProgress = true;
|
|
94
102
|
this.setSize();
|
|
95
103
|
this.resizeImageStore();
|
|
96
104
|
this.scroll?.resizeMobileBreakEvents();
|
|
97
105
|
this.scroll?.setSize();
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
this.resizeInProgress = false;
|
|
108
|
+
}, 0);
|
|
98
109
|
}
|
|
99
110
|
resizeImageStore() {
|
|
100
111
|
for (const item of this.imageStore) {
|
|
@@ -110,19 +121,6 @@ class Canvas3Class {
|
|
|
110
121
|
}
|
|
111
122
|
this.setImageMeshPositions();
|
|
112
123
|
}
|
|
113
|
-
// resizeTextStore() {
|
|
114
|
-
// for (const item of this.textStore) {
|
|
115
|
-
// const bounds = item.htmlEl.getBoundingClientRect()
|
|
116
|
-
// const { scaleX, scaleY } = getMSDFFontMeshScales(
|
|
117
|
-
// bounds.width,
|
|
118
|
-
// item.mesh.geometry?._layout?._width,
|
|
119
|
-
// )
|
|
120
|
-
// item.mesh.scale.set(scaleX, scaleY, 1)
|
|
121
|
-
// item.width = bounds.width
|
|
122
|
-
// item.height = bounds.height * heightPositionCoef
|
|
123
|
-
// }
|
|
124
|
-
// this.setTextMeshPositions()
|
|
125
|
-
// }
|
|
126
124
|
setImageMeshPositions() {
|
|
127
125
|
if (this.imageStore.length === 0) return;
|
|
128
126
|
for (const item of this.imageStore) {
|
|
@@ -130,17 +128,6 @@ class Canvas3Class {
|
|
|
130
128
|
item.mesh.position.y = -item.htmlEl.getBoundingClientRect().top + this.height / 2 - item.height / 2;
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
|
-
// setTextMeshPositions() {
|
|
134
|
-
// if (this.textStore.length === 0) return
|
|
135
|
-
// for (const item of this.textStore) {
|
|
136
|
-
// item.mesh.position.x
|
|
137
|
-
// = item.htmlEl.getBoundingClientRect().left - this.width / 2
|
|
138
|
-
// item.mesh.position.y
|
|
139
|
-
// = -item.htmlEl.getBoundingClientRect().top
|
|
140
|
-
// + this.height / 2
|
|
141
|
-
// - item.height / 2
|
|
142
|
-
// }
|
|
143
|
-
// }
|
|
144
131
|
meshUniformsUpdate(id, uniforms) {
|
|
145
132
|
const mesh = this.scene.getObjectByName(id);
|
|
146
133
|
if (!mesh) return;
|
|
@@ -252,112 +239,13 @@ class Canvas3Class {
|
|
|
252
239
|
this.activateMeshUniformMap.delete(id);
|
|
253
240
|
this.imageStore = this.imageStore.filter((item) => item.name !== id);
|
|
254
241
|
}
|
|
255
|
-
addAnimationToRender(callBackName,
|
|
242
|
+
addAnimationToRender(callBackName, callBackOptions) {
|
|
256
243
|
if (this.animations.has(callBackName)) return;
|
|
257
|
-
this.animations.set(callBackName,
|
|
244
|
+
this.animations.set(callBackName, callBackOptions);
|
|
258
245
|
}
|
|
259
246
|
removeAnimationFromRender(callBackName) {
|
|
260
247
|
this.animations.delete(callBackName);
|
|
261
248
|
}
|
|
262
|
-
// addTextAsMSDF(shaderName: string, meshId: string, htmlEl: HTMLElement, textContent: string, theme: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform) {
|
|
263
|
-
// this.activateMeshUniformMap.set(meshId, activateMeshUniforms)
|
|
264
|
-
//
|
|
265
|
-
// let vertexShader = this.options.shaders.default.textVertex
|
|
266
|
-
// let fragmentShader = this.options.shaders.default.textFragment
|
|
267
|
-
// if (shaderName && this.options.shaders[shaderName]) {
|
|
268
|
-
// vertexShader = this.options.shaders[shaderName].vertexShader
|
|
269
|
-
// fragmentShader = this.options.shaders[shaderName].fragmentShader
|
|
270
|
-
// }
|
|
271
|
-
//
|
|
272
|
-
// const bounds = htmlEl.getBoundingClientRect()
|
|
273
|
-
// const position = { top: bounds.top, left: bounds.left }
|
|
274
|
-
// position.top += this.currentScroll
|
|
275
|
-
//
|
|
276
|
-
// //* ****************************
|
|
277
|
-
// // MSDF
|
|
278
|
-
// //* ****************************
|
|
279
|
-
//
|
|
280
|
-
// const geometry = new MSDFTextGeometry({
|
|
281
|
-
// text: textContent.trim(),
|
|
282
|
-
// font: this.MSDFTextGeometryFont.data,
|
|
283
|
-
// })
|
|
284
|
-
//
|
|
285
|
-
// const material = new THREE.ShaderMaterial({
|
|
286
|
-
// side: THREE.DoubleSide,
|
|
287
|
-
// transparent: true,
|
|
288
|
-
// defines: {
|
|
289
|
-
// IS_SMALL: false, // false,
|
|
290
|
-
// },
|
|
291
|
-
// uniforms: {
|
|
292
|
-
// uDevicePixelRatio: { value: window.devicePixelRatio },
|
|
293
|
-
// uColor: {
|
|
294
|
-
// // TODO: colors dynamic from component
|
|
295
|
-
// value: new THREE.Vector4(
|
|
296
|
-
// theme === 'dark' ? 27 / 255 : 191 / 255, // R
|
|
297
|
-
// theme === 'dark' ? 24 / 255 : 192 / 255, // G
|
|
298
|
-
// theme === 'dark' ? 24 / 255 : 178 / 255, // B
|
|
299
|
-
// ),
|
|
300
|
-
// },
|
|
301
|
-
// uViewport: {
|
|
302
|
-
// value: new THREE.Vector2(this.width, this.height),
|
|
303
|
-
// },
|
|
304
|
-
// // Common
|
|
305
|
-
// uMouse: { value: new THREE.Vector2(0, 0) },
|
|
306
|
-
// uMouseMovement: { value: new THREE.Vector2(0, 0) },
|
|
307
|
-
// uFooterGameBall: { value: new THREE.Vector2(0, 0) },
|
|
308
|
-
// uMap: { value: null },
|
|
309
|
-
// // Rendering
|
|
310
|
-
// uThreshold: { value: 0.05 },
|
|
311
|
-
// uAlphaTest: { value: 0.01 },
|
|
312
|
-
// uStrokeOutsetWidth: { value: 0.0 },
|
|
313
|
-
// uStrokeInsetWidth: { value: 0.3 }, // 0.3
|
|
314
|
-
// // new generic
|
|
315
|
-
// uTime: { value: 0 },
|
|
316
|
-
// uMeshSize: { value: new THREE.Vector2(bounds.width, bounds.height) },
|
|
317
|
-
// ...this.options.activateMeshOptions.text,
|
|
318
|
-
// ...activateMeshUniforms,
|
|
319
|
-
// ...meshUniforms,
|
|
320
|
-
// },
|
|
321
|
-
// vertexShader: vertexShader,
|
|
322
|
-
// fragmentShader: fragmentShader,
|
|
323
|
-
// })
|
|
324
|
-
//
|
|
325
|
-
// if (material.uniforms.uMap)
|
|
326
|
-
// material.uniforms.uMap.value = this.MSDFTextGeometryAtlas
|
|
327
|
-
//
|
|
328
|
-
// this.materials.push(material)
|
|
329
|
-
//
|
|
330
|
-
// const mesh = new THREE.Mesh(geometry, material)
|
|
331
|
-
// mesh.name = meshId
|
|
332
|
-
// mesh.renderOrder = 1
|
|
333
|
-
//
|
|
334
|
-
// const { scaleX, scaleY } = getMSDFFontMeshScales(
|
|
335
|
-
// bounds.width,
|
|
336
|
-
// mesh.geometry?._layout?._width,
|
|
337
|
-
// )
|
|
338
|
-
//
|
|
339
|
-
// mesh.scale.set(scaleX, scaleY, 1)
|
|
340
|
-
//
|
|
341
|
-
// this.scene.add(mesh)
|
|
342
|
-
//
|
|
343
|
-
// const newMesh: MeshType = {
|
|
344
|
-
// name: meshId,
|
|
345
|
-
// htmlEl: htmlEl,
|
|
346
|
-
// mesh: mesh,
|
|
347
|
-
// top: position.top,
|
|
348
|
-
// left: position.left,
|
|
349
|
-
// width: bounds.width,
|
|
350
|
-
// height: bounds.height * heightPositionCoef,
|
|
351
|
-
// }
|
|
352
|
-
//
|
|
353
|
-
// this.textStore.push(newMesh)
|
|
354
|
-
//
|
|
355
|
-
// this.setTextMeshPositions()
|
|
356
|
-
//
|
|
357
|
-
// if (htmlEl.dataset.activeScroll === 'true') {
|
|
358
|
-
// this.activateMesh(meshId, true)
|
|
359
|
-
// }
|
|
360
|
-
// }
|
|
361
249
|
async addImageAsMesh(imgHtmlEl, shaderName, meshId, meshUniforms, activateMeshUniforms) {
|
|
362
250
|
if (activateMeshUniforms) {
|
|
363
251
|
this.activateMeshUniformMap.set(meshId, activateMeshUniforms);
|
|
@@ -474,7 +362,23 @@ class Canvas3Class {
|
|
|
474
362
|
}, delay * 1e3);
|
|
475
363
|
}
|
|
476
364
|
setMeshPositionsUpdate(state) {
|
|
477
|
-
this.
|
|
365
|
+
this.meshPositionsUpdate = state;
|
|
366
|
+
}
|
|
367
|
+
setAnimationsToRender(state) {
|
|
368
|
+
this.animationsRender = state;
|
|
369
|
+
}
|
|
370
|
+
externalAnimationsRender() {
|
|
371
|
+
for (const [_key, callbackOption] of this.animations.entries()) {
|
|
372
|
+
const callBack = callbackOption.animationCallback;
|
|
373
|
+
if (!callBack) return;
|
|
374
|
+
const shouldRunOnScroll = callbackOption.onScroll && this.scroll?.scrollInProgress;
|
|
375
|
+
const shouldRunOnAnimationsRender = callbackOption.onAnimationsRender && this.animationsRender;
|
|
376
|
+
const shouldRunOnResize = callbackOption.onResize && this.resizeInProgress;
|
|
377
|
+
const shouldRunOnMouseMove = callbackOption.onMouseMove && this.mouseMoveInProgress;
|
|
378
|
+
if (shouldRunOnScroll || shouldRunOnAnimationsRender || shouldRunOnResize || shouldRunOnMouseMove) {
|
|
379
|
+
callBack();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
478
382
|
}
|
|
479
383
|
render() {
|
|
480
384
|
this.time += 0.05;
|
|
@@ -484,9 +388,10 @@ class Canvas3Class {
|
|
|
484
388
|
this.customPass.uniforms.scrollSpeed.value = this.scroll?.speedTarget;
|
|
485
389
|
this.setImageMeshPositions();
|
|
486
390
|
}
|
|
487
|
-
if (this.
|
|
391
|
+
if (this.meshPositionsUpdate) {
|
|
488
392
|
this.resizeImageStore();
|
|
489
393
|
}
|
|
394
|
+
this.externalAnimationsRender();
|
|
490
395
|
if (this.materials.length > 0) {
|
|
491
396
|
for (const material of this.materials) {
|
|
492
397
|
if (material.uniforms.uTime)
|
|
@@ -503,9 +408,6 @@ class Canvas3Class {
|
|
|
503
408
|
);
|
|
504
409
|
}
|
|
505
410
|
}
|
|
506
|
-
for (const [_key, callback] of this.animations.entries()) {
|
|
507
|
-
callback?.();
|
|
508
|
-
}
|
|
509
411
|
if (this.composer) {
|
|
510
412
|
this.composer.render();
|
|
511
413
|
} else if (this.renderer && this.camera) {
|
|
@@ -3,11 +3,12 @@ import { getShaderMaterial } from '#canvas3-nuxt/utils/canvas3/helpers';
|
|
|
3
3
|
export declare const Canvas3: {
|
|
4
4
|
addMeshToScene: (mesh: Mesh) => void;
|
|
5
5
|
getMeshFromSceneByName: (meshName: string) => import("three").Object3D<import("three").Object3DEventMap> | undefined;
|
|
6
|
-
addAnimationToRender: (callBackName: string,
|
|
6
|
+
addAnimationToRender: (callBackName: string, callBackOptions: import("../types/types.js").AnimationCallOptions) => void;
|
|
7
7
|
removeAnimationFromRender: (callBackName: string) => void;
|
|
8
8
|
addImageAsMesh: (imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: import("../types/types.js").MeshMaterialUniform, activateMeshUniforms: import("../types/types.js").MeshMaterialUniform) => Promise<void>;
|
|
9
9
|
getShaderMaterial: typeof getShaderMaterial;
|
|
10
10
|
removeMesh: (id: string) => void;
|
|
11
|
+
setAnimationsToRender: (state: boolean) => void;
|
|
11
12
|
resizeOnChange: () => void;
|
|
12
13
|
scrollToElBySelector: (elQuerySelector: string, delay?: number, margin?: number) => void;
|
|
13
14
|
setMeshPositionsUpdate: (state: boolean) => void;
|
|
@@ -12,6 +12,7 @@ export const Canvas3 = {
|
|
|
12
12
|
addImageAsMesh: mainClass.addImageAsMesh.bind(mainClass),
|
|
13
13
|
getShaderMaterial,
|
|
14
14
|
removeMesh: mainClass.removeMesh.bind(mainClass),
|
|
15
|
+
setAnimationsToRender: mainClass.setAnimationsToRender.bind(mainClass),
|
|
15
16
|
resizeOnChange: mainClass.resizeOnChange.bind(mainClass),
|
|
16
17
|
scrollToElBySelector: mainClass.scrollToElBySelector.bind(mainClass),
|
|
17
18
|
setMeshPositionsUpdate: mainClass.setMeshPositionsUpdate.bind(mainClass),
|