-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspring_present.html
More file actions
198 lines (180 loc) · 8.66 KB
/
spring_present.html
File metadata and controls
198 lines (180 loc) · 8.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Spring Present — Torrential Rain + Bloom</title>
<script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>
<script>
/* ---------- link + hover button helpers (VR clickable) ---------- */
AFRAME.registerComponent('link-on-click', {
schema: { href: {type: 'string'} },
init() {
this.el.addEventListener('click', () => {
if (this.data.href) window.location.href = this.data.href;
});
}
});
AFRAME.registerComponent('button-feedback', {
schema: { base: {default: '#6fcfb6'}, hover: {default: '#53b49a'}, down: {default: '#3b8a75'} },
init() {
this.el.setAttribute('material', {color: this.data.base, side: 'double'});
this.el.addEventListener('mouseenter', () => this.el.setAttribute('material','color',this.data.hover));
this.el.addEventListener('mouseleave', () => this.el.setAttribute('material','color',this.data.base));
this.el.addEventListener('mousedown', () => this.el.setAttribute('material','color',this.data.down));
this.el.addEventListener('mouseup', () => this.el.setAttribute('material','color',this.data.hover));
this.el.addEventListener('touchstart', () => this.el.setAttribute('material','color',this.data.down));
this.el.addEventListener('touchend', () => this.el.setAttribute('material','color',this.data.hover));
}
});
/* ---------- Rain (A-Frame 1.5 friendly) ---------- */
AFRAME.registerComponent('rain', {
schema: {
count: {type: 'int', default: 12000},
area: {type: 'vec3', default: {x: 32, y: 18, z: 32}},
speedMin: {type: 'number', default: 14},
speedMax: {type: 'number', default: 28},
dropLength: {type: 'number', default: 1.0},
color: {type: 'color', default: '#6c8ddf'},
opacity: {type: 'number', default: 1.0}
},
init() {
const THREE = AFRAME.THREE, d = this.data;
this._vel = new Float32Array(d.count);
this._pos = new Float32Array(d.count * 3);
const linePositions = new Float32Array(d.count * 2 * 3);
const rx = d.area.x, ry = d.area.y, rz = d.area.z;
for (let i=0;i<d.count;i++){
const i3 = i*3, l = i*6;
const x = (Math.random()-0.5)*rx;
const y = Math.random()*ry;
const z = (Math.random()-0.5)*rz;
this._pos[i3+0]=x; this._pos[i3+1]=y; this._pos[i3+2]=z;
this._vel[i] = d.speedMin + Math.random()*(d.speedMax-d.speedMin);
linePositions[l+0]=x; linePositions[l+1]=y; linePositions[l+2]=z;
linePositions[l+3]=x; linePositions[l+4]=y-d.dropLength; linePositions[l+5]=z;
}
const geom = new THREE.BufferGeometry();
geom.setAttribute('position', new THREE.BufferAttribute(linePositions,3));
const mat = new THREE.LineBasicMaterial({color:new THREE.Color(d.color),transparent:true,opacity:d.opacity});
this.mesh = new THREE.LineSegments(geom, mat);
this.el.setObject3D('mesh', this.mesh);
this._positions = linePositions;
this._geom = geom;
this._fading=false; this._fadeStart=0; this._fadeDur=1; this._startOpacity=d.opacity;
},
fadeOut(seconds=3){
this._fading=true;
this._fadeStart=performance.now()/1000;
this._fadeDur=seconds;
this._startOpacity=this.mesh.material.opacity;
},
tick(time, dtMS){
if(!this.mesh) return;
const dt=(dtMS||16)/1000, d=this.data, pos=this._positions, dropPos=this._pos, vel=this._vel;
for(let i=0;i<d.count;i++){
const i3=i*3, l=i*6;
let y=dropPos[i3+1]-vel[i]*dt;
if(y<-d.area.y*0.5){
y=d.area.y*0.5;
dropPos[i3+0]=(Math.random()-0.5)*d.area.x;
dropPos[i3+2]=(Math.random()-0.5)*d.area.z;
}
dropPos[i3+1]=y;
pos[l+0]=dropPos[i3+0]; pos[l+1]=y; pos[l+2]=dropPos[i3+2];
pos[l+3]=dropPos[i3+0]; pos[l+4]=y-d.dropLength; pos[l+5]=dropPos[i3+2];
}
this._geom.attributes.position.needsUpdate=true;
if(this._fading){
const t=performance.now()/1000;
const p=Math.min(1,(t-this._fadeStart)/this._fadeDur);
this.mesh.material.opacity=(1-p)*this._startOpacity;
if(p>=1){
this._fading=false;
this.el.setAttribute('visible',false);
this.el.emit('rain-faded');
}
}
}
});
/* ---------- Flower field spawner ---------- */
AFRAME.registerComponent('flower-field', {
schema: { radius: {type:'number', default: 4}, count: {type:'int', default: 50} },
init(){
const colors=['#ff6fb1','#ff9fd6','#ffd166','#98fb98','#7cdfff','#f9844a','#b28dff','#ff4d6d'];
for(let i=0;i<this.data.count;i++){
const angle=Math.random()*Math.PI*2;
const r=this.data.radius*(0.6+Math.random()*0.7);
const x=Math.cos(angle)*r, z=Math.sin(angle)*r, y=0.02, s=0.001;
const petal=document.createElement('a-entity');
petal.setAttribute('geometry','primitive: circle; radius: 0.13');
petal.setAttribute('material',`color: ${colors[i%colors.length]}; side: double`);
petal.setAttribute('position',`${x} ${y} ${z}`);
petal.setAttribute('rotation','-90 0 0');
petal.setAttribute('scale',`${s} ${s} ${s}`);
const delay=600+Math.random()*2000;
petal.setAttribute('animation__grow',`property: scale; to: 1 1 1; dur: 1500; delay: ${delay}; easing: easeOutBack`);
petal.setAttribute('animation__sway',`property: rotation; dir: alternate; to: -92 0 0; dur: 2000; loop: true; easing: easeInOutSine; delay: ${delay+1500}`);
this.el.appendChild(petal);
const center=document.createElement('a-entity');
center.setAttribute('geometry','primitive: circle; radius: 0.04');
center.setAttribute('material','color: #3b3b3b; side: double');
center.setAttribute('position',`${x} ${y+0.001} ${z}`);
center.setAttribute('rotation','-90 0 0');
center.setAttribute('scale',`${s} ${s} ${s}`);
center.setAttribute('animation__grow',`property: scale; to: 1 1 1; dur: 1500; delay: ${delay}; easing: easeOutBack`);
this.el.appendChild(center);
}
}
});
</script>
</head>
<body>
<a-scene>
<!-- Your 360 pano -->
<a-sky src="Gemini_Generated_Image_m92pdhm92pdhm92p.png" rotation="0 -90 0"></a-sky>
<!-- Camera + cursor/raycaster so buttons can be clicked -->
<a-entity id="cameraRig" position="0 0 0">
<a-entity camera look-controls position="0 1.6 0"
cursor="rayOrigin: mouse"
raycaster="objects: .clickable"></a-entity>
<!-- Optional gaze cursor for VR -->
<a-entity position="0 1.6 -1"
geometry="primitive: ring; radiusInner: 0.005; radiusOuter: 0.008"
material="color: white; shader: flat"></a-entity>
</a-entity>
<!-- HUD: Home button floating in front of the user -->
<a-entity id="hud" position="0 1.35 -1.2">
<a-plane class="clickable" width="0.5" height="0.18"
button-feedback link-on-click="href: index.html">
<a-entity text="value: Home; align: center; color: #0a2b22; width: 0.9" position="0 0 0.01"></a-entity>
</a-plane>
</a-entity>
<!-- Atmosphere darkener -->
<a-entity id="darkener">
<a-sphere radius="1000" position="0 0 0"
material="color: #000; opacity: 0.6; transparent: true; side: back"></a-sphere>
</a-entity>
<!-- Torrential rain volume -->
<a-entity id="rain" position="0 7 0"
rain="count: 12000; area: 36 18 36; dropLength: 1.1; speedMin: 16; speedMax: 30; color: #6c8ddf; opacity: 1">
</a-entity>
<!-- Where flowers will appear -->
<a-entity id="flowers" position="0 0 0" visible="false"></a-entity>
<script>
const rainEl = document.getElementById('rain');
const darkener = document.querySelector('#darkener a-sphere');
const flowers = document.getElementById('flowers');
// Let it pour for ~10s, then fade over 3s
setTimeout(() => { rainEl.components.rain.fadeOut(3); }, 10000);
// When rain fully faded, brighten and bloom
rainEl.addEventListener('rain-faded', () => {
darkener.setAttribute('animation__brighten',
'property: material.opacity; from: 0.6; to: 0.1; dur: 3000; easing: easeInOutSine');
flowers.setAttribute('visible', true);
flowers.setAttribute('flower-field', 'radius: 4.5; count: 70');
});
</script>
</a-scene>
</body>
</html>