@canvas3/nuxt 0.0.1 → 0.0.3
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/components/canvas3-image.vue +1 -1
- package/dist/runtime/constants/studio783Log.d.ts +1 -0
- package/dist/runtime/constants/studio783Log.js +22 -0
- package/dist/runtime/directives/canvas3-image.client.d.ts +3 -0
- package/dist/runtime/directives/{canvas3-image-directive.client.js → canvas3-image.client.js} +4 -4
- package/dist/runtime/plugins/directives.js +1 -1
- package/dist/runtime/types/types.d.ts +30 -10
- package/dist/runtime/types/types.js +1 -0
- package/dist/runtime/types/vue-directives.d.ts +10 -0
- package/dist/runtime/utils/canvas3/canvas3.d.ts +5 -10
- package/dist/runtime/utils/canvas3/canvas3.js +66 -81
- package/dist/runtime/utils/canvas3/helpers.d.ts +5 -3
- package/dist/runtime/utils/canvas3/helpers.js +4 -4
- package/package.json +1 -1
- package/dist/runtime/directives/canvas3-image-directive.client.d.ts +0 -6
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/plugin.js +0 -3
- package/dist/runtime/types/three-msdf-text-utils.d.ts +0 -36
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.d.ts +0 -1
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.d.ts +0 -1
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.d.ts +0 -1
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.d.ts +0 -1
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.d.ts +0 -1
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.js +0 -0
package/dist/module.json
CHANGED
|
@@ -37,7 +37,7 @@ const addImageToCanvas = async () => {
|
|
|
37
37
|
if (!image.value || Canvas3.canvasInitiated.value === false || Canvas3.options?.disabled || imgAddedToCanvas.value) return;
|
|
38
38
|
if (image.value.naturalWidth === 0) return;
|
|
39
39
|
image.value.dataset.meshId = generatedMeshId;
|
|
40
|
-
Canvas3.addImageAsMesh(
|
|
40
|
+
await Canvas3.addImageAsMesh(
|
|
41
41
|
image.value,
|
|
42
42
|
props.options.shaderName,
|
|
43
43
|
generatedMeshId,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const studio783log: () => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const studio783log = () => {
|
|
2
|
+
console.log(`
|
|
3
|
+
Animation package Canvas3 developed by
|
|
4
|
+
|
|
5
|
+
\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588
|
|
6
|
+
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
|
|
7
|
+
\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
|
|
8
|
+
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
|
|
9
|
+
\u2588\u2588\u2588\u2588 \u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588
|
|
10
|
+
|
|
11
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
|
|
12
|
+
\u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588
|
|
13
|
+
\u2591\u2591\u2591 \u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2591\u2591 \u2591\u2588\u2588\u2588
|
|
14
|
+
\u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2591
|
|
15
|
+
\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588
|
|
16
|
+
\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588 \u2591\u2588\u2588\u2588
|
|
17
|
+
\u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
|
|
18
|
+
\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591
|
|
19
|
+
|
|
20
|
+
`);
|
|
21
|
+
console.log("%chttps://783studio.com", "font-size:20px; font-weight:600;");
|
|
22
|
+
};
|
package/dist/runtime/directives/{canvas3-image-directive.client.js → canvas3-image.client.js}
RENAMED
|
@@ -23,9 +23,9 @@ async function tryAdd(el, options) {
|
|
|
23
23
|
meshIdMap.set(el, meshId);
|
|
24
24
|
el.dataset.meshId = meshId;
|
|
25
25
|
}
|
|
26
|
-
Canvas3.addImageAsMesh(
|
|
26
|
+
await Canvas3.addImageAsMesh(
|
|
27
27
|
el,
|
|
28
|
-
options
|
|
28
|
+
options.shaderName ?? null,
|
|
29
29
|
meshId,
|
|
30
30
|
options?.uniforms ?? {},
|
|
31
31
|
options?.activateMeshUniforms ?? {}
|
|
@@ -53,7 +53,7 @@ export const vCanvas3Image = {
|
|
|
53
53
|
if (el.tagName !== "IMG") {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
const options = binding.value
|
|
56
|
+
const options = binding.value ?? {};
|
|
57
57
|
const stop = watch(
|
|
58
58
|
() => Canvas3.canvasInitiated.value,
|
|
59
59
|
(ready) => {
|
|
@@ -70,7 +70,7 @@ export const vCanvas3Image = {
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
updated(el, binding) {
|
|
73
|
-
const options = binding.value
|
|
73
|
+
const options = binding.value ?? {};
|
|
74
74
|
const meshId = meshIdMap.get(el);
|
|
75
75
|
if (meshId && options?.uniforms) {
|
|
76
76
|
Canvas3.meshUniformsUpdate(meshId, options.uniforms);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { vOnScrollActivate } from "../directives/action-on-scroll.js";
|
|
2
2
|
import { vSetDataAttribute } from "../directives/set-data-attributes.js";
|
|
3
|
-
import { vCanvas3Image } from "../directives/canvas3-image
|
|
3
|
+
import { vCanvas3Image } from "../directives/canvas3-image.client.js";
|
|
4
4
|
import { defineNuxtPlugin } from "#app";
|
|
5
5
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
6
6
|
nuxtApp.vueApp.directive("action-on-scroll", vOnScrollActivate);
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import type { Mesh } from 'three';
|
|
2
|
-
import type { DirectiveBinding } from 'vue';
|
|
3
|
-
export type AnimationCallback = () => void;
|
|
4
|
-
export type AnimationCallbacks = Map<string, AnimationCallback>;
|
|
5
|
-
export type MeshMaterialUniform = Record<string, {
|
|
6
|
-
duration: number;
|
|
7
|
-
ease: string;
|
|
8
|
-
value: number;
|
|
9
|
-
}>;
|
|
1
|
+
import type { Mesh, Vector2 } from 'three';
|
|
2
|
+
import type { DirectiveBinding, ObjectDirective } from 'vue';
|
|
10
3
|
type Shader = {
|
|
11
4
|
fragmentShader: string;
|
|
12
5
|
vertexShader: string;
|
|
@@ -25,6 +18,18 @@ type MeshAnimation = {
|
|
|
25
18
|
duration: number;
|
|
26
19
|
ease: string;
|
|
27
20
|
};
|
|
21
|
+
export type AnimationCallback = () => void;
|
|
22
|
+
export type AnimationCallbacks = Map<string, AnimationCallback>;
|
|
23
|
+
export type MeshMaterialUniform = Record<string, {
|
|
24
|
+
duration: number;
|
|
25
|
+
ease: string | null | undefined;
|
|
26
|
+
value: number;
|
|
27
|
+
}>;
|
|
28
|
+
export type BaseUniform = Record<string, {
|
|
29
|
+
value: Vector2 | number | null;
|
|
30
|
+
duration?: number;
|
|
31
|
+
ease?: string | null | undefined;
|
|
32
|
+
}>;
|
|
28
33
|
export type Canvas3OptionsType = {
|
|
29
34
|
font: Font;
|
|
30
35
|
shaders: Shaders;
|
|
@@ -58,7 +63,7 @@ export type ScrollActionType = {
|
|
|
58
63
|
options: DirectiveBinding['value'];
|
|
59
64
|
arg: DirectiveBinding['arg'];
|
|
60
65
|
containedMeshIds?: string[];
|
|
61
|
-
bounds
|
|
66
|
+
bounds?: DOMRect;
|
|
62
67
|
containerId?: string;
|
|
63
68
|
fixPosition?: number;
|
|
64
69
|
containerEl?: HTMLElement;
|
|
@@ -68,4 +73,19 @@ export type ScrollActionType = {
|
|
|
68
73
|
containerBottom?: number;
|
|
69
74
|
trackOnly?: boolean;
|
|
70
75
|
};
|
|
76
|
+
export type myEffectType = {
|
|
77
|
+
uniforms: BaseUniform;
|
|
78
|
+
vertexShader: string;
|
|
79
|
+
fragmentShader: string;
|
|
80
|
+
};
|
|
81
|
+
export type Canvas3ImageBinding = {
|
|
82
|
+
shaderName?: string;
|
|
83
|
+
uniforms?: MeshMaterialUniform;
|
|
84
|
+
activateMeshUniforms?: MeshMaterialUniform;
|
|
85
|
+
};
|
|
86
|
+
declare module 'vue' {
|
|
87
|
+
interface GlobalDirectives {
|
|
88
|
+
'canvas3-image': ObjectDirective<HTMLImageElement, Canvas3ImageBinding>;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
71
91
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ObjectDirective } from 'vue'
|
|
2
|
+
import type { Canvas3ImageBinding } from '~/src/runtime/types/types'
|
|
3
|
+
|
|
4
|
+
declare module 'vue' {
|
|
5
|
+
export interface GlobalDirectives {
|
|
6
|
+
'canvas3-image': ObjectDirective<HTMLImageElement, Canvas3ImageBinding>
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {}
|
|
@@ -2,9 +2,9 @@ import * as THREE from 'three';
|
|
|
2
2
|
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
|
3
3
|
import type { Pass } from 'three/addons/postprocessing/Pass.js';
|
|
4
4
|
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
5
|
-
import type { ShaderMaterial } from 'three';
|
|
5
|
+
import type { ShaderMaterial, WebGLRenderer } from 'three';
|
|
6
6
|
import Scroll from '#canvas3-nuxt/utils/canvas3/scroll';
|
|
7
|
-
import type { AnimationCallback, AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType } from '#canvas3-nuxt/types/types';
|
|
7
|
+
import type { AnimationCallback, AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType } from '#canvas3-nuxt/types/types';
|
|
8
8
|
declare class Canvas3Class {
|
|
9
9
|
canvasInitiated: import("vue").Ref<boolean, boolean>;
|
|
10
10
|
animateImageMesh: boolean;
|
|
@@ -12,11 +12,8 @@ declare class Canvas3Class {
|
|
|
12
12
|
scrollableContent: HTMLElement | null;
|
|
13
13
|
time: number;
|
|
14
14
|
scene: THREE.Scene;
|
|
15
|
-
MSDFTextGeometryAtlas: any;
|
|
16
|
-
MSDFTextGeometryFont: any;
|
|
17
15
|
materials: ShaderMaterial[];
|
|
18
16
|
imageStore: MeshType[];
|
|
19
|
-
textStore: MeshType[];
|
|
20
17
|
activateMeshUniformMap: Map<string, MeshMaterialUniform>;
|
|
21
18
|
scroll: Scroll | null;
|
|
22
19
|
currentScroll: number;
|
|
@@ -26,8 +23,8 @@ declare class Canvas3Class {
|
|
|
26
23
|
camera: THREE.PerspectiveCamera | null;
|
|
27
24
|
composer: EffectComposer | null;
|
|
28
25
|
renderPass: Pass | null;
|
|
29
|
-
renderer:
|
|
30
|
-
myEffect:
|
|
26
|
+
renderer: WebGLRenderer | null;
|
|
27
|
+
myEffect: myEffectType;
|
|
31
28
|
customPass: ShaderPass | null;
|
|
32
29
|
animations: AnimationCallbacks;
|
|
33
30
|
mouse: {
|
|
@@ -42,9 +39,7 @@ declare class Canvas3Class {
|
|
|
42
39
|
setCanvasAndCamera(): void;
|
|
43
40
|
resizeOnChange(): void;
|
|
44
41
|
resizeImageStore(): void;
|
|
45
|
-
resizeTextStore(): void;
|
|
46
42
|
setImageMeshPositions(): void;
|
|
47
|
-
setTextMeshPositions(): void;
|
|
48
43
|
meshUniformsUpdate(id: string, uniforms: MeshMaterialUniform): void;
|
|
49
44
|
activateMesh(meshId: string, isActive: boolean): void;
|
|
50
45
|
addOnScrollActivateElement(binding: ScrollActionBinding): void;
|
|
@@ -52,7 +47,7 @@ declare class Canvas3Class {
|
|
|
52
47
|
removeScrollActiveElement(elNode: HTMLElement): void;
|
|
53
48
|
removeMesh(id: string): void;
|
|
54
49
|
addAnimationToRender(callBackName: string, callBackFunction: AnimationCallback): void;
|
|
55
|
-
addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
|
|
50
|
+
addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
|
|
56
51
|
composerPass(): void;
|
|
57
52
|
setSize(): void;
|
|
58
53
|
scrollToTop(delay?: number): void;
|
|
@@ -6,12 +6,12 @@ import { ShaderPass } from "three/addons/postprocessing/ShaderPass.js";
|
|
|
6
6
|
import { gsap } from "gsap";
|
|
7
7
|
import {
|
|
8
8
|
generateBindingLogic,
|
|
9
|
-
|
|
10
|
-
heightPositionCoef,
|
|
9
|
+
getShaderMaterial,
|
|
11
10
|
loadTexture
|
|
12
11
|
} from "./helpers.js";
|
|
13
12
|
import Scroll from "#canvas3-nuxt/utils/canvas3/scroll";
|
|
14
13
|
import { defaultCanvas3Options } from "#canvas3-nuxt/constants/default-canvas3-options";
|
|
14
|
+
import { studio783log } from "#canvas3-nuxt/constants/studio783Log";
|
|
15
15
|
const canvasInitiated = ref(false);
|
|
16
16
|
class Canvas3Class {
|
|
17
17
|
canvasInitiated = canvasInitiated;
|
|
@@ -20,11 +20,11 @@ class Canvas3Class {
|
|
|
20
20
|
scrollableContent = null;
|
|
21
21
|
time = 0;
|
|
22
22
|
scene = new THREE.Scene();
|
|
23
|
-
MSDFTextGeometryAtlas
|
|
24
|
-
MSDFTextGeometryFont
|
|
23
|
+
// MSDFTextGeometryAtlas: any
|
|
24
|
+
// MSDFTextGeometryFont: any
|
|
25
25
|
materials = [];
|
|
26
26
|
imageStore = [];
|
|
27
|
-
textStore = []
|
|
27
|
+
// textStore: MeshType[] = []
|
|
28
28
|
activateMeshUniformMap = /* @__PURE__ */ new Map();
|
|
29
29
|
scroll = null;
|
|
30
30
|
currentScroll = 0;
|
|
@@ -34,15 +34,18 @@ class Canvas3Class {
|
|
|
34
34
|
camera = null;
|
|
35
35
|
composer = null;
|
|
36
36
|
renderPass = null;
|
|
37
|
-
renderer;
|
|
38
|
-
myEffect
|
|
37
|
+
renderer = null;
|
|
38
|
+
myEffect = {
|
|
39
|
+
uniforms: {
|
|
40
|
+
tDiffuse: { value: null },
|
|
41
|
+
scrollSpeed: { value: null }
|
|
42
|
+
},
|
|
43
|
+
vertexShader: "",
|
|
44
|
+
fragmentShader: ""
|
|
45
|
+
};
|
|
39
46
|
customPass = null;
|
|
40
47
|
animations = /* @__PURE__ */ new Map();
|
|
41
48
|
mouse = { x: 0, y: 0, movementX: 0, movementY: 0, xPrev: 0, yPrev: 0 };
|
|
42
|
-
// triggerSectionPositions= {};
|
|
43
|
-
// constructor({ canvasOptions }) {
|
|
44
|
-
// this.options = canvasOptions;
|
|
45
|
-
// }
|
|
46
49
|
async init(canvasElement, scrollableContent, canvas3Options) {
|
|
47
50
|
this.options = canvas3Options;
|
|
48
51
|
this.scene = new THREE.Scene();
|
|
@@ -69,6 +72,7 @@ class Canvas3Class {
|
|
|
69
72
|
}
|
|
70
73
|
});
|
|
71
74
|
this.canvasInitiated.value = true;
|
|
75
|
+
studio783log();
|
|
72
76
|
}
|
|
73
77
|
setCanvasAndCamera() {
|
|
74
78
|
this.width = this.canvasContainer?.offsetWidth ?? 0;
|
|
@@ -87,33 +91,9 @@ class Canvas3Class {
|
|
|
87
91
|
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
|
|
88
92
|
this.canvasContainer?.appendChild(this.renderer.domElement);
|
|
89
93
|
}
|
|
90
|
-
// async loadFontMSDF() {
|
|
91
|
-
// const loadFontAtlas = (path: string) => {
|
|
92
|
-
// return new Promise((resolve) => {
|
|
93
|
-
// const loader = new THREE.TextureLoader()
|
|
94
|
-
// loader.load(path, resolve)
|
|
95
|
-
// })
|
|
96
|
-
// }
|
|
97
|
-
// const loadFont = (path: string) => {
|
|
98
|
-
// return new Promise((resolve) => {
|
|
99
|
-
// const loader = new FontLoader()
|
|
100
|
-
// loader.load(path, resolve)
|
|
101
|
-
// })
|
|
102
|
-
// }
|
|
103
|
-
// await Promise.all([
|
|
104
|
-
// loadFontAtlas(this.options.font.atlas),
|
|
105
|
-
// loadFont(this.options.font.fnt),
|
|
106
|
-
// ]).then(([atlas, font]) => {
|
|
107
|
-
// if (atlas)
|
|
108
|
-
// this.MSDFTextGeometryAtlas = atlas
|
|
109
|
-
// if (font)
|
|
110
|
-
// this.MSDFTextGeometryFont = font
|
|
111
|
-
// })
|
|
112
|
-
// }
|
|
113
94
|
resizeOnChange() {
|
|
114
95
|
this.setSize();
|
|
115
96
|
this.resizeImageStore();
|
|
116
|
-
this.resizeTextStore();
|
|
117
97
|
this.scroll?.resizeMobileBreakEvents();
|
|
118
98
|
this.scroll?.setSize();
|
|
119
99
|
}
|
|
@@ -123,29 +103,27 @@ class Canvas3Class {
|
|
|
123
103
|
const bounds = item.htmlEl.getBoundingClientRect();
|
|
124
104
|
if (!bounds) return;
|
|
125
105
|
item.mesh.scale.set(bounds.width, bounds.height, 1);
|
|
126
|
-
item.mesh
|
|
127
|
-
|
|
128
|
-
bounds.height ?? 0
|
|
129
|
-
);
|
|
106
|
+
const material = getShaderMaterial(item.mesh);
|
|
107
|
+
material.uniforms.uMeshSize?.value.set(bounds.width ?? 0, bounds.height ?? 0);
|
|
130
108
|
item.width = bounds.width;
|
|
131
109
|
item.height = bounds.height;
|
|
132
110
|
}
|
|
133
111
|
}
|
|
134
112
|
this.setImageMeshPositions();
|
|
135
113
|
}
|
|
136
|
-
resizeTextStore() {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
114
|
+
// resizeTextStore() {
|
|
115
|
+
// for (const item of this.textStore) {
|
|
116
|
+
// const bounds = item.htmlEl.getBoundingClientRect()
|
|
117
|
+
// const { scaleX, scaleY } = getMSDFFontMeshScales(
|
|
118
|
+
// bounds.width,
|
|
119
|
+
// item.mesh.geometry?._layout?._width,
|
|
120
|
+
// )
|
|
121
|
+
// item.mesh.scale.set(scaleX, scaleY, 1)
|
|
122
|
+
// item.width = bounds.width
|
|
123
|
+
// item.height = bounds.height * heightPositionCoef
|
|
124
|
+
// }
|
|
125
|
+
// this.setTextMeshPositions()
|
|
126
|
+
// }
|
|
149
127
|
setImageMeshPositions() {
|
|
150
128
|
if (this.imageStore.length === 0) return;
|
|
151
129
|
for (const item of this.imageStore) {
|
|
@@ -153,24 +131,28 @@ class Canvas3Class {
|
|
|
153
131
|
item.mesh.position.y = -item.htmlEl.getBoundingClientRect().top + this.height / 2 - item.height / 2;
|
|
154
132
|
}
|
|
155
133
|
}
|
|
156
|
-
setTextMeshPositions() {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
134
|
+
// setTextMeshPositions() {
|
|
135
|
+
// if (this.textStore.length === 0) return
|
|
136
|
+
// for (const item of this.textStore) {
|
|
137
|
+
// item.mesh.position.x
|
|
138
|
+
// = item.htmlEl.getBoundingClientRect().left - this.width / 2
|
|
139
|
+
// item.mesh.position.y
|
|
140
|
+
// = -item.htmlEl.getBoundingClientRect().top
|
|
141
|
+
// + this.height / 2
|
|
142
|
+
// - item.height / 2
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
163
145
|
meshUniformsUpdate(id, uniforms) {
|
|
164
146
|
const mesh = this.scene.getObjectByName(id);
|
|
165
147
|
if (!mesh) return;
|
|
148
|
+
const material = getShaderMaterial(mesh);
|
|
166
149
|
for (const uniKey in uniforms) {
|
|
167
150
|
if (uniforms[uniKey]) {
|
|
168
|
-
if (!
|
|
169
|
-
|
|
170
|
-
value: uniforms[uniKey].value
|
|
171
|
-
duration: 0
|
|
151
|
+
if (!material.uniforms[uniKey])
|
|
152
|
+
material.uniforms[uniKey] = {
|
|
153
|
+
value: uniforms[uniKey].value
|
|
172
154
|
};
|
|
173
|
-
gsap.to(
|
|
155
|
+
gsap.to(material.uniforms[uniKey], {
|
|
174
156
|
duration: uniforms[uniKey].duration,
|
|
175
157
|
value: uniforms[uniKey].value,
|
|
176
158
|
ease: uniforms[uniKey].ease ?? "power1.inOut"
|
|
@@ -184,15 +166,16 @@ class Canvas3Class {
|
|
|
184
166
|
console.error("no Mesh found with ID: " + meshId);
|
|
185
167
|
return;
|
|
186
168
|
}
|
|
187
|
-
|
|
188
|
-
|
|
169
|
+
const material = getShaderMaterial(mesh);
|
|
170
|
+
if (material.uniforms.uAniInImage && this.options.activateMeshOptions.image.uAniInImage) {
|
|
171
|
+
gsap.to(material.uniforms.uAniInImage, {
|
|
189
172
|
duration: this.options.activateMeshOptions.image.uAniInImage.duration,
|
|
190
173
|
value: isActive ? 1 : 0,
|
|
191
174
|
ease: this.options.activateMeshOptions.image.uAniInImage.ease
|
|
192
175
|
});
|
|
193
176
|
}
|
|
194
|
-
if (
|
|
195
|
-
gsap.to(
|
|
177
|
+
if (material.uniforms.uAniInText && this.options.activateMeshOptions.text.uAniInText) {
|
|
178
|
+
gsap.to(material.uniforms.uAniInText, {
|
|
196
179
|
duration: this.options.activateMeshOptions.text.uAniInText.duration,
|
|
197
180
|
value: isActive ? 1 : 0,
|
|
198
181
|
ease: this.options.activateMeshOptions.text.uAniInText.ease
|
|
@@ -201,8 +184,9 @@ class Canvas3Class {
|
|
|
201
184
|
const activateMeshUniforms = this.activateMeshUniformMap.get(meshId) ?? null;
|
|
202
185
|
if (activateMeshUniforms) {
|
|
203
186
|
for (const [key, value] of Object.entries(activateMeshUniforms)) {
|
|
204
|
-
|
|
205
|
-
|
|
187
|
+
const material2 = getShaderMaterial(mesh);
|
|
188
|
+
if (material2.uniforms[key]) {
|
|
189
|
+
gsap.to(material2.uniforms[key], {
|
|
206
190
|
duration: value.duration,
|
|
207
191
|
value: isActive ? 1 : 0,
|
|
208
192
|
ease: value.ease ?? "power1.inOut"
|
|
@@ -240,11 +224,12 @@ class Canvas3Class {
|
|
|
240
224
|
}
|
|
241
225
|
}
|
|
242
226
|
removeMesh(id) {
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
this.scene.remove(
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
const meshToRemove = this.scene.getObjectByName(id);
|
|
228
|
+
if (!meshToRemove) return;
|
|
229
|
+
this.scene.remove(meshToRemove);
|
|
230
|
+
meshToRemove.geometry.dispose();
|
|
231
|
+
const material = getShaderMaterial(meshToRemove);
|
|
232
|
+
material.dispose();
|
|
248
233
|
for (const [index, item] of this.imageStore.entries()) {
|
|
249
234
|
if (item.name === id) {
|
|
250
235
|
this.imageStore.splice(index, 1);
|
|
@@ -417,7 +402,7 @@ class Canvas3Class {
|
|
|
417
402
|
this.setImageMeshPositions();
|
|
418
403
|
}
|
|
419
404
|
composerPass() {
|
|
420
|
-
if (!this.options.shaders.scroll) return;
|
|
405
|
+
if (!this.options.shaders.scroll || !this.renderer) return;
|
|
421
406
|
this.composer = new EffectComposer(this.renderer);
|
|
422
407
|
if (this.camera)
|
|
423
408
|
this.renderPass = new RenderPass(this.scene, this.camera);
|
|
@@ -442,9 +427,11 @@ class Canvas3Class {
|
|
|
442
427
|
this.camera.aspect = this.width / this.height;
|
|
443
428
|
this.camera.updateProjectionMatrix();
|
|
444
429
|
}
|
|
445
|
-
this.renderer
|
|
446
|
-
|
|
447
|
-
|
|
430
|
+
if (this.renderer) {
|
|
431
|
+
this.renderer.setSize(this.width, this.height);
|
|
432
|
+
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
433
|
+
this.renderer.render(this.scene, this.camera);
|
|
434
|
+
}
|
|
448
435
|
}
|
|
449
436
|
scrollToTop(delay = 0) {
|
|
450
437
|
setTimeout(() => {
|
|
@@ -474,11 +461,9 @@ class Canvas3Class {
|
|
|
474
461
|
if (this.customPass && this.customPass.uniforms.scrollSpeed)
|
|
475
462
|
this.customPass.uniforms.scrollSpeed.value = this.scroll?.speedTarget;
|
|
476
463
|
this.setImageMeshPositions();
|
|
477
|
-
this.setTextMeshPositions();
|
|
478
464
|
}
|
|
479
465
|
if (this.animateImageMesh) {
|
|
480
466
|
this.resizeImageStore();
|
|
481
|
-
this.resizeTextStore();
|
|
482
467
|
}
|
|
483
468
|
for (const material of this.materials) {
|
|
484
469
|
if (material.uniforms.uTime)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ScrollActionType } from '#canvas3-nuxt/types/types';
|
|
2
|
+
import type { Mesh, ShaderMaterial, Texture } from 'three';
|
|
3
|
+
export declare function generateBindingLogic(newBindingData: ScrollActionType): ScrollActionType;
|
|
3
4
|
export declare function findMeshIDs(elParent: HTMLElement): false | string[];
|
|
4
|
-
export declare function loadTexture(src: string): Promise<
|
|
5
|
+
export declare function loadTexture(src: string): Promise<Texture>;
|
|
5
6
|
export declare const heightPositionCoef = 1.38;
|
|
6
7
|
export declare function getMSDFFontMeshScales(boundsWidth: number, geometryWidth: number): {
|
|
7
8
|
scaleX: number;
|
|
@@ -10,3 +11,4 @@ export declare function getMSDFFontMeshScales(boundsWidth: number, geometryWidth
|
|
|
10
11
|
export declare function setScrollActiveElements(elNode: HTMLElement, meshIds: string[], state: string): void;
|
|
11
12
|
export declare function elementNearViewport(bounds: DOMRect, margin?: number): boolean;
|
|
12
13
|
export declare const lerp: (a: number, b: number, n: number) => number;
|
|
14
|
+
export declare function getShaderMaterial(mesh: Mesh): ShaderMaterial;
|
|
@@ -62,14 +62,11 @@ export function findMeshIDs(elParent) {
|
|
|
62
62
|
export function loadTexture(src) {
|
|
63
63
|
return new Promise((resolve, reject) => {
|
|
64
64
|
const loader = new THREE.TextureLoader();
|
|
65
|
-
loader.load(
|
|
65
|
+
return loader.load(
|
|
66
66
|
src,
|
|
67
67
|
(texture) => resolve(texture),
|
|
68
|
-
// On success
|
|
69
68
|
void 0,
|
|
70
|
-
// On progress (optional)
|
|
71
69
|
(err) => reject(err)
|
|
72
|
-
// On error
|
|
73
70
|
);
|
|
74
71
|
});
|
|
75
72
|
}
|
|
@@ -94,3 +91,6 @@ export function elementNearViewport(bounds, margin = 200) {
|
|
|
94
91
|
return bounds.top >= -margin && bounds.top <= windowHeight || bounds.bottom >= -margin && bounds.bottom <= windowHeight || bounds.top <= -margin && bounds.bottom >= windowHeight;
|
|
95
92
|
}
|
|
96
93
|
export const lerp = (a, b, n) => (1 - n) * a + n * b;
|
|
94
|
+
export function getShaderMaterial(mesh) {
|
|
95
|
+
return mesh.material;
|
|
96
|
+
}
|
package/package.json
CHANGED
package/dist/runtime/plugin.d.ts
DELETED
package/dist/runtime/plugin.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
declare module 'three-msdf-text-utils' {
|
|
2
|
-
import * as THREE from 'three'
|
|
3
|
-
|
|
4
|
-
export interface GlyphGeometryOptions {
|
|
5
|
-
flipY?: boolean
|
|
6
|
-
negate?: boolean
|
|
7
|
-
multipage?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class GlyphGeometry extends THREE.BufferGeometry {
|
|
11
|
-
constructor(text: string, font: any, options?: GlyphGeometryOptions)
|
|
12
|
-
layout: any
|
|
13
|
-
update(text: string): void
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface MSDFShaderOptions {
|
|
17
|
-
map?: THREE.Texture
|
|
18
|
-
color?: THREE.Color | string | number
|
|
19
|
-
opacity?: number
|
|
20
|
-
alphaTest?: number
|
|
21
|
-
negate?: boolean
|
|
22
|
-
precision?: string
|
|
23
|
-
multipage?: boolean
|
|
24
|
-
side?: THREE.Side
|
|
25
|
-
transparent?: boolean
|
|
26
|
-
defines?: { [key: string]: any }
|
|
27
|
-
uniforms?: { [key: string]: any }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function createMSDFShader(options?: MSDFShaderOptions): {
|
|
31
|
-
uniforms: { [key: string]: THREE.IUniform }
|
|
32
|
-
vertexShader: string
|
|
33
|
-
fragmentShader: string
|
|
34
|
-
defines: { [key: string]: any }
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|