Hi, Firstly I really tried to make a CodePen of this, but can’t get the imports for three.interactive working (duplicate THREE errors). So I’ll explain and hope it’s easy to follow. The latests dev version I’m referring to while writing is here: https://distilled.pagescreativetest.co.uk
I have a scene with some doors. When a user mouses-over those doors I want the colour to change slightly to show they are interactive. Here’s what I have so far:
-
To detect the mouse I’m using
three.interactive
, and firing a function on ‘mouseover’ and ‘mouseout’ events. -
I have two materials setup, except one is emissive, with an intensity of ‘0’.
-
I’m using GSAP to change the emissiveIntensity over a short duration, then back.
A problem can be seen on the dev site (https://distilled.pagescreativetest.co.uk) though. If I mouse over and out very fast and onto another door, multiple doors retain the wrong material. Please try it to see what I mean. Easiest way is to mouse across the whole line of doors.
What I have:
Imports:
import gsap from 'gsap'
import * as THREE from 'three'
import { InteractionManager } from 'three.interactive'
Materials:
const doorMaterial = new THREE.MeshPhongMaterial({
color: 0x9b6d54
});
const doorHoverMaterial = new THREE.MeshPhongMaterial({
color: 0x9b6d54,
emissive: 0xffffff,
emissiveIntensity: 0
});
Meshes:
// loader looping through a model assigning following for all door parts
child.addEventListener('mouseover', doorcolour)
child.addEventListener('mouseout', doorcolour)
The function:
function doorcolour(evt) {
if (evt.target.id != '') {
doorid = evt.target.id
} else {
return
}
doormesh = model.getObjectById(parseInt(doorid))
if (evt.type == 'mouseover') {
document.body.style.cursor = 'pointer'
doormesh.material = doorHoverMaterial
gsap.to(doorHoverMaterial,{
emissiveIntensity:0.1,
duration: 0.2
})
} else if (evt.type == 'mouseout') {
document.body.style.cursor = 'default'
gsap.to(doorHoverMaterial,{
emissiveIntensity:0,
duration: 0.2,
onComplete: function(){
doormesh.material = doorMaterial
}
})
} else {
return
}
}
Can anyone suggest I how should be waiting for animations to finish, or how maybe I can stop and reverse where an animation is. I’m guessing that sometimes the onComplete
doesn’t fire on the mouseout. But I do have the event’s console.logged and it doesn’t look like there’s always a mouseout
event for every interaction. Thank you for your time