-
Notifications
You must be signed in to change notification settings - Fork 869
Update controls-related examples #2760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,8 +247,8 @@ <h4>Event listeners can cooperate with camera-controls</h4> | |
Math.abs(pointer.clientY - startY) > tapDistance) | ||
return; | ||
const rect = modelViewer.getBoundingClientRect(); | ||
const x = event.clientX - rect.left; | ||
const y = event.clientY - rect.top; | ||
const x = pointer.clientX - rect.left; | ||
const y = pointer.clientY - rect.top; | ||
const hit = modelViewer.positionAndNormalFromPoint(x, y); | ||
modelViewer.cameraTarget = | ||
hit == null ? 'auto auto auto' : hit.position.toString(); | ||
|
@@ -269,15 +269,15 @@ <h4>Event listeners can cooperate with camera-controls</h4> | |
}, true); | ||
|
||
modelViewer.addEventListener('touchstart', (event) => { | ||
startX = event.touches[0].clientX; | ||
startY = event.touches[0].clientY; | ||
panning = event.touches.length === 2; | ||
const {targetTouches, touches} = event; | ||
startX = targetTouches[0].clientX; | ||
startY = targetTouches[0].clientY; | ||
panning = targetTouches.length === 2 && targetTouches.length === touches.length; | ||
if (!panning) | ||
return; | ||
|
||
const {touches} = event; | ||
lastX = 0.5 * (touches[0].clientX + touches[1].clientX); | ||
lastY = 0.5 * (touches[0].clientY + touches[1].clientY); | ||
lastX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX); | ||
lastY = 0.5 * (targetTouches[0].clientY + targetTouches[1].clientY); | ||
startPan(); | ||
}, true); | ||
|
||
|
@@ -290,22 +290,26 @@ <h4>Event listeners can cooperate with camera-controls</h4> | |
}, true); | ||
|
||
modelViewer.addEventListener('touchmove', (event) => { | ||
if (!panning || event.touches.length !== 2) | ||
if (!panning || event.targetTouches.length !== 2) | ||
return; | ||
|
||
const {touches} = event; | ||
const thisX = 0.5 * (touches[0].clientX + touches[1].clientX); | ||
const thisY = 0.5 * (touches[0].clientY + touches[1].clientY); | ||
const {targetTouches} = event; | ||
const thisX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX); | ||
const thisY = 0.5 * (targetTouches[0].clientY + targetTouches[1].clientY); | ||
movePan(thisX, thisY); | ||
}, true); | ||
|
||
self.addEventListener('mouseup', (event) => { | ||
recenter(event); | ||
}, true); | ||
|
||
self.addEventListener('touchend', (event) => { | ||
if (event.touches.length === 0) { | ||
modelViewer.addEventListener('touchend', (event) => { | ||
if (event.targetTouches.length === 0) { | ||
recenter(event.changedTouches[0]); | ||
|
||
if (event.cancelable) { | ||
event.preventDefault(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevents emulation of |
||
} | ||
} | ||
}, true); | ||
})(); | ||
|
@@ -369,12 +373,12 @@ <h2 class="demo-title">Add other interactions like rotating the skybox</h2> | |
}, true); | ||
|
||
modelViewer.addEventListener('touchstart', (event) => { | ||
panning = event.touches.length === 2; | ||
const {targetTouches, touches} = event; | ||
panning = targetTouches.length === 2 && targetTouches.length === touches.length; | ||
if (!panning) | ||
return; | ||
|
||
const {touches} = event; | ||
lastX = 0.5 * (touches[0].clientX + touches[1].clientX); | ||
lastX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX); | ||
startPan(); | ||
}, true); | ||
|
||
|
@@ -387,19 +391,19 @@ <h2 class="demo-title">Add other interactions like rotating the skybox</h2> | |
}, true); | ||
|
||
modelViewer.addEventListener('touchmove', (event) => { | ||
if (!panning || event.touches.length !== 2) | ||
if (!panning || event.targetTouches.length !== 2) | ||
return; | ||
|
||
const {touches} = event; | ||
const thisX = 0.5 * (touches[0].clientX + touches[1].clientX); | ||
const {targetTouches} = event; | ||
const thisX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX); | ||
updatePan(thisX); | ||
}, true); | ||
|
||
self.addEventListener('mouseup', (event) => { | ||
panning = false; | ||
}, true); | ||
|
||
self.addEventListener('touchend', (event) => { | ||
modelViewer.addEventListener('touchend', (event) => { | ||
panning = false; | ||
}, true); | ||
</script> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lack of type-checking bit us again. Surprisingly, the browser injects
event
as a variable in the event handler scope.Try:
window.addEventListener('click', () => console.log(event))
It was working with mouse events because unlike
TouchEvent
,MouseEvent
has propertiesclientX
andclientY
.