cheryglsljs 1.0.0 → 1.0.2
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.
@@ -1,12 +1,3 @@
|
|
1
|
-
/*!
|
2
|
-
* GSAP 3.13.0
|
3
|
-
* https://gsap.com
|
4
|
-
*
|
5
|
-
* @license Copyright 2008-2025, GreenSock. All rights reserved.
|
6
|
-
* Subject to the terms at https://gsap.com/standard-license
|
7
|
-
* @author: Jack Doyle, jack@greensock.com
|
8
|
-
*/
|
9
|
-
|
10
1
|
/**
|
11
2
|
* @license
|
12
3
|
* Copyright 2010-2025 Three.js Authors
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cheryglsljs",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"description": "\"It is threejs,glsl and gsap based js library\"",
|
5
5
|
"main": "src/cherry.js",
|
6
6
|
"scripts": {
|
@@ -24,7 +24,7 @@
|
|
24
24
|
},
|
25
25
|
"files": [
|
26
26
|
"dist/",
|
27
|
-
"src/
|
27
|
+
"src/"
|
28
28
|
],
|
29
29
|
"devDependencies": {
|
30
30
|
"css-loader": "^6.8.1",
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import createWaveAssets from '../../utils/init.js';
|
2
|
+
import { fragmentShader } from './FragementShader.glsl.js';
|
3
|
+
import vertexShader from './Vertexshader.glsl.js';
|
4
|
+
|
5
|
+
const CherryWave = ({ container, image, speed = 0.05, strength = 8, hover = false }) => {
|
6
|
+
if (!image) {
|
7
|
+
console.log("No image provided");
|
8
|
+
return;
|
9
|
+
}
|
10
|
+
|
11
|
+
const textureLoader = new THREE.TextureLoader();
|
12
|
+
textureLoader.load(image.src, (texture) => {
|
13
|
+
const uniforms = {
|
14
|
+
uImage: { value: texture },
|
15
|
+
uTime: { value: 0.0 },
|
16
|
+
uStrength: { value: hover ? 0 : strength }
|
17
|
+
};
|
18
|
+
|
19
|
+
const waveassets = createWaveAssets(container.clientWidth, container.clientHeight);
|
20
|
+
waveassets.camera.position.z = 190;
|
21
|
+
|
22
|
+
let mesh;
|
23
|
+
const raycaster = new THREE.Raycaster();
|
24
|
+
const mouse = new THREE.Vector2();
|
25
|
+
let isHovering = false;
|
26
|
+
|
27
|
+
function createMesh(width, height) {
|
28
|
+
const geometry = new THREE.PlaneGeometry(width, height, 100, 100);
|
29
|
+
const material = new THREE.ShaderMaterial({
|
30
|
+
vertexShader,
|
31
|
+
fragmentShader,
|
32
|
+
uniforms
|
33
|
+
});
|
34
|
+
return new THREE.Mesh(geometry, material);
|
35
|
+
}
|
36
|
+
|
37
|
+
function addMesh() {
|
38
|
+
const containerWidth = container.clientWidth;
|
39
|
+
const containerHeight = container.clientHeight;
|
40
|
+
const containerAspect = containerWidth / containerHeight;
|
41
|
+
const imageAspect = image.naturalWidth / image.naturalHeight;
|
42
|
+
|
43
|
+
let scaleWidth, scaleHeight;
|
44
|
+
if (containerAspect < imageAspect) {
|
45
|
+
scaleWidth = containerWidth;
|
46
|
+
scaleHeight = containerWidth / imageAspect;
|
47
|
+
} else {
|
48
|
+
scaleHeight = containerHeight;
|
49
|
+
scaleWidth = containerHeight * imageAspect;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (mesh) {
|
53
|
+
waveassets.Scene.remove(mesh);
|
54
|
+
mesh.geometry.dispose();
|
55
|
+
mesh.material.dispose();
|
56
|
+
}
|
57
|
+
|
58
|
+
mesh = createMesh(scaleWidth, scaleHeight);
|
59
|
+
waveassets.mesh = mesh;
|
60
|
+
waveassets.Scene.add(mesh);
|
61
|
+
}
|
62
|
+
|
63
|
+
function onResize() {
|
64
|
+
const width = container.clientWidth;
|
65
|
+
const height = container.clientHeight;
|
66
|
+
|
67
|
+
waveassets.renderer.setSize(width, height);
|
68
|
+
waveassets.renderer.setPixelRatio(window.devicePixelRatio);
|
69
|
+
|
70
|
+
waveassets.camera.aspect = width / height;
|
71
|
+
waveassets.camera.updateProjectionMatrix();
|
72
|
+
|
73
|
+
addMesh();
|
74
|
+
}
|
75
|
+
|
76
|
+
function onMouseMove(event) {
|
77
|
+
const bounds = container.getBoundingClientRect();
|
78
|
+
mouse.x = ((event.clientX - bounds.left) / bounds.width) * 2 - 1;
|
79
|
+
mouse.y = -((event.clientY - bounds.top) / bounds.height) * 2 + 1;
|
80
|
+
}
|
81
|
+
|
82
|
+
if (hover) {
|
83
|
+
container.addEventListener('mousemove', onMouseMove);
|
84
|
+
|
85
|
+
container.addEventListener('mouseenter', () => {
|
86
|
+
gsap.to(uniforms.uStrength, {
|
87
|
+
value: strength,
|
88
|
+
duration: 0.5,
|
89
|
+
ease: 'power2.out'
|
90
|
+
});
|
91
|
+
});
|
92
|
+
|
93
|
+
container.addEventListener('mouseleave', () => {
|
94
|
+
gsap.to(uniforms.uStrength, {
|
95
|
+
value: 0,
|
96
|
+
duration: 0.5,
|
97
|
+
ease: 'power2.out'
|
98
|
+
});
|
99
|
+
});
|
100
|
+
}
|
101
|
+
|
102
|
+
container.innerHTML = '';
|
103
|
+
container.appendChild(waveassets.renderer.domElement);
|
104
|
+
window.addEventListener('resize', onResize);
|
105
|
+
addMesh();
|
106
|
+
|
107
|
+
function animate() {
|
108
|
+
uniforms.uTime.value += speed;
|
109
|
+
waveassets.renderer.render(waveassets.Scene, waveassets.camera);
|
110
|
+
requestAnimationFrame(animate);
|
111
|
+
}
|
112
|
+
|
113
|
+
animate();
|
114
|
+
|
115
|
+
return {
|
116
|
+
mesh: waveassets.mesh,
|
117
|
+
geometry: waveassets.geometry,
|
118
|
+
renderer: waveassets.renderer,
|
119
|
+
Scene: waveassets.Scene
|
120
|
+
};
|
121
|
+
});
|
122
|
+
};
|
123
|
+
|
124
|
+
export default CherryWave;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export const fragmentShader = `
|
2
|
+
varying vec2 vUv;
|
3
|
+
uniform sampler2D uImage;
|
4
|
+
uniform float uTime;
|
5
|
+
uniform float uStrength;
|
6
|
+
void main() {
|
7
|
+
// Create a wave effect by modifying the y coordinate
|
8
|
+
vec2 uv = vUv;
|
9
|
+
|
10
|
+
|
11
|
+
uv.y += uStrength/400.0 * sin(10.0 * uv.x + uTime * 2.0);
|
12
|
+
uv.x += uStrength/400.0 * sin(10.0 * uv.y + uTime * 2.0);
|
13
|
+
|
14
|
+
vec4 color = texture2D(uImage, uv);
|
15
|
+
gl_FragColor = color;
|
16
|
+
}
|
17
|
+
`;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
const vertexShader = `
|
2
|
+
varying vec2 vUv;
|
3
|
+
varying vec3 pos;
|
4
|
+
uniform float uTime;
|
5
|
+
uniform float uStrength;
|
6
|
+
|
7
|
+
void main() {
|
8
|
+
|
9
|
+
vUv = uv;
|
10
|
+
|
11
|
+
vec3 newPosition = position;
|
12
|
+
|
13
|
+
// Enhanced wave effect: move vertices in all directions
|
14
|
+
float waveX = uStrength * sin(10.0 * uv.y + uTime * 2.0);
|
15
|
+
float waveY = uStrength * cos(12.0 * uv.x + uTime * 1.5);
|
16
|
+
|
17
|
+
float waveZ = uStrength * sin(10.0 * uv.x + uTime * 2.5);
|
18
|
+
|
19
|
+
newPosition.x += waveX;
|
20
|
+
newPosition.y += waveY;
|
21
|
+
newPosition.z += waveZ;
|
22
|
+
|
23
|
+
pos = (modelViewMatrix * vec4(newPosition, 1.0)).xyz;
|
24
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
|
25
|
+
}
|
26
|
+
`;
|
27
|
+
|
28
|
+
export default vertexShader;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import *as THREE from 'three';
|
2
|
+
import gsap from 'gsap';
|
3
|
+
const Scene = () => new THREE.Scene();
|
4
|
+
const camera = () => new THREE.PerspectiveCamera(
|
5
|
+
75,
|
6
|
+
window.innerWidth / window.innerHeight,
|
7
|
+
0.1,
|
8
|
+
1000
|
9
|
+
);
|
10
|
+
const renderer = () => new THREE.WebGLRenderer({alpha:true});
|
11
|
+
|
12
|
+
export default function createWaveAssets(width = 400, height = 400) {
|
13
|
+
const SceneInstance = Scene();
|
14
|
+
const cameraInstance = camera();
|
15
|
+
const rendererInstance = renderer();
|
16
|
+
rendererInstance.setSize(width, height);
|
17
|
+
return {
|
18
|
+
Scene: SceneInstance,
|
19
|
+
camera: cameraInstance,
|
20
|
+
renderer: rendererInstance,
|
21
|
+
};
|
22
|
+
}
|