1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

update event order

This commit is contained in:
Sander Moolin 2021-03-23 09:41:32 -04:00
parent cfbca7934b
commit 975e0661b3

View File

@ -96,6 +96,21 @@ export default {
this.intersects || scene.children this.intersects || scene.children
); );
// capture expired intersects
if (this.onPointerLeave) {
const newObjects = intersects.map(intersect => {
return {
object: intersect.object,
instanceId: intersect.instanceId
}
});
// TODO: optimize
const expiredIntersects = this._intersects.filter(intersect => !newObjects.find(val => val.object === intersect.object && val.instanceId === intersect.instanceId));
if (expiredIntersects.length) {
this.onPointerLeave(expiredIntersects)
}
}
// capture new intersects // capture new intersects
if (this.onPointerEnter) { if (this.onPointerEnter) {
const old = this._intersects.map(intersect => { const old = this._intersects.map(intersect => {
@ -116,21 +131,6 @@ export default {
this.onPointerOver(intersects) this.onPointerOver(intersects)
} }
// capture expired intersects
if (this.onPointerLeave) {
const newObjects = intersects.map(intersect => {
return {
object: intersect.object,
instanceId: intersect.instanceId
}
});
// TODO: optimize
const expiredIntersects = this._intersects.filter(intersect => !newObjects.find(val => val.object === intersect.object && val.instanceId === intersect.instanceId));
if (expiredIntersects.length) {
this.onPointerLeave(expiredIntersects)
}
}
// save internal intersect list // save internal intersect list
this._intersects = intersects; this._intersects = intersects;
}, },