106 lines
4.5 KiB
JavaScript
106 lines
4.5 KiB
JavaScript
// Bold scene roughness animation state
|
|
export let boldRoughnessAnimation = {
|
|
isActive: false,
|
|
startTime: 0,
|
|
delayDuration: 1.0, // 1 second delay (will be dynamic)
|
|
transitionDuration: 1.0, // 1 second transition
|
|
startRoughness: 0.5,
|
|
endRoughness: 0.05,
|
|
materials: [] // Store references to bold materials
|
|
};
|
|
|
|
// Innovation glass animation state
|
|
export let innovationGlassAnimation = {
|
|
isActive: false,
|
|
startTime: 0,
|
|
transitionDuration: 0.2,
|
|
startIor: 1.0,
|
|
endIor: 2.0,
|
|
startThickness: 1.0,
|
|
endThickness: 2.0,
|
|
materials: [] // Store references to innovation glass materials
|
|
};
|
|
|
|
// Start/restart bold roughness animation with optional delay control
|
|
export function startBoldRoughnessAnimation(withDelay = true) {
|
|
console.log('Starting/restarting bold roughness animation');
|
|
// Reset all bold glass materials to starting roughness value
|
|
boldRoughnessAnimation.materials.forEach(material => {
|
|
material.roughness = boldRoughnessAnimation.startRoughness;
|
|
material.needsUpdate = true;
|
|
});
|
|
boldRoughnessAnimation.isActive = true;
|
|
boldRoughnessAnimation.startTime = performance.now();
|
|
// Set delayDuration based on withDelay parameter
|
|
boldRoughnessAnimation.delayDuration = withDelay ? 1.0 : 0.0;
|
|
console.log('Bold roughness animation started with delay:', withDelay);
|
|
}
|
|
|
|
// Start innovation glass animation
|
|
export function startInnovationGlassAnimation() {
|
|
console.log('Starting innovation glass animation');
|
|
// Reset all innovation glass materials to starting values
|
|
innovationGlassAnimation.materials.forEach(material => {
|
|
material.ior = innovationGlassAnimation.startIor;
|
|
material.thickness = innovationGlassAnimation.startThickness;
|
|
material.needsUpdate = true;
|
|
});
|
|
innovationGlassAnimation.isActive = true;
|
|
innovationGlassAnimation.startTime = performance.now();
|
|
console.log('Innovation glass animation started');
|
|
}
|
|
|
|
export function updateBoldRoughnessAnimation() {
|
|
if (boldRoughnessAnimation.isActive) {
|
|
const elapsed = (performance.now() - boldRoughnessAnimation.startTime) / 1000;
|
|
if (elapsed >= boldRoughnessAnimation.delayDuration) {
|
|
// Delay period is over, start roughness transition
|
|
const transitionElapsed = elapsed - boldRoughnessAnimation.delayDuration;
|
|
const transitionProgress = Math.min(transitionElapsed / boldRoughnessAnimation.transitionDuration, 1);
|
|
// Smooth easing function (ease-in-out)
|
|
const easeInOut = (t) => t * t * (3 - 2 * t);
|
|
const easedProgress = easeInOut(transitionProgress);
|
|
// Interpolate roughness from 0.5 to 0.05
|
|
const currentRoughness = boldRoughnessAnimation.startRoughness +
|
|
(boldRoughnessAnimation.endRoughness - boldRoughnessAnimation.startRoughness) * easedProgress;
|
|
// Apply to all bold materials
|
|
boldRoughnessAnimation.materials.forEach(material => {
|
|
material.roughness = currentRoughness;
|
|
material.needsUpdate = true;
|
|
});
|
|
// End animation when complete
|
|
if (transitionProgress >= 1) {
|
|
boldRoughnessAnimation.isActive = false;
|
|
console.log('Bold roughness animation completed');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export function updateInnovationGlassAnimation() {
|
|
if (innovationGlassAnimation.isActive) {
|
|
const elapsed = (performance.now() - innovationGlassAnimation.startTime) / 1000;
|
|
const transitionProgress = Math.min(elapsed / innovationGlassAnimation.transitionDuration, 1);
|
|
// Smooth easing function (ease-in-out)
|
|
const easeInOut = (t) => t * t * (3 - 2 * t);
|
|
const easedProgress = easeInOut(transitionProgress);
|
|
// Interpolate IOR from 1.0 to 2.0
|
|
const currentIor = innovationGlassAnimation.startIor +
|
|
(innovationGlassAnimation.endIor - innovationGlassAnimation.startIor) * easedProgress;
|
|
// Interpolate thickness from 1.0 to 2.0
|
|
const currentThickness = innovationGlassAnimation.startThickness +
|
|
(innovationGlassAnimation.endThickness - innovationGlassAnimation.startThickness) * easedProgress;
|
|
// Apply to all innovation glass materials
|
|
innovationGlassAnimation.materials.forEach(material => {
|
|
material.ior = currentIor;
|
|
material.thickness = currentThickness;
|
|
material.needsUpdate = true;
|
|
});
|
|
// End animation when complete
|
|
if (transitionProgress >= 1) {
|
|
innovationGlassAnimation.isActive = false;
|
|
console.log('Innovation glass animation completed');
|
|
}
|
|
}
|
|
}
|
|
|