-
Notifications
You must be signed in to change notification settings - Fork 35
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
Upgrade mathbox to new npm package, threejs => r137 #330
Upgrade mathbox to new npm package, threejs => r137 #330
Conversation
Scratch that, my typo. It works great now, except for mouse interaction! Tackling that will be next, probably three.js upgrade / OrbitControls related. |
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.
Some notes on the change.
client/public/index.html
Outdated
|
||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> |
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.
sorry, my linter tidied this up. I'll back all of the linter changes out.
@@ -17,7 +17,6 @@ | |||
<script src="/mathquill.min.js"></script> | |||
<link rel="stylesheet" href="/mathquill.css"> | |||
<!-- MathBox --> | |||
<script src="/mathbox-bundle.min.js"></script> |
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.
Woohoo!
* Some Comments: | ||
* - sincce there isn't a (relaiable, documented) mathbox npm package, | ||
* we load it as a script. | ||
* - Initializing mathbox inside a React Component led to some issues |
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.
I didn't make this change, so I'm not sure what this is about. Maybe there is a better way to initialize mathbox inside the react component that we can try.
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.
I'm not sure either. I did not run into this issue when playing around with mathbox 2.1.0 today.
@@ -93,11 +94,11 @@ export default class ScrollWithOverflow extends React.PureComponent<Props, State | |||
coverRef: { current: null | HTMLDivElement } | |||
|
|||
eventNames = [ | |||
'mousedown', 'mousemove', 'mouseup', 'wheel', | |||
'touchstart', 'touchmove', 'touchend' | |||
'pointerdown', 'pointermove', 'pointerup', |
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.
This change occurred in Three.js r120: https://github.com/mrdoob/three.js/wiki/Migration-Guide#r119--r120
Here's an example issue suggesting the fix that worked: mrdoob/three.js#20294 (comment)
@@ -1,6 +1,6 @@ | |||
// @flow | |||
|
|||
const THREE = window.THREE | |||
import { Color } from "three/src/math/Color.js"; |
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.
I've been enjoying these targeted imports.
@@ -27,6 +33,23 @@ type Props = { | |||
renderErrors: ErrorState, | |||
setError: SetError | |||
} | |||
|
|||
export const mathboxElement = document.getElementById("mathbox"); |
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.
okay, the next two const
s are the meat. Do we want these declared somewhere else?
this.canvas.addEventListener('touchstart', this.downHandler) | ||
this.canvas.addEventListener('mouseup', this.mouseUpHandler) | ||
this.canvas.addEventListener('touchend', this.touchExitHandler) | ||
this.canvas.addEventListener('pointerdown', this.downHandler) |
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.
my understanding (could be wrong!) is that pointer
replaces mouse
and touch
.
this.isPointerDown = false | ||
this.enterSlowMode() | ||
} | ||
|
||
touchExitHandler = async (event: TouchEvent) => { |
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.
which makes this unnecessary. What am I missing?
|
||
import { mathbox } from "containers/MathBoxScene/components/MathBoxScene.js"; | ||
|
||
export default function () { |
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.
I might suggest that this take mathbox
as an argument?
@@ -1,6 +1,7 @@ | |||
import React, { PureComponent } from 'react' | |||
import MathBoxContainer from 'containers/MathBoxContainer' | |||
import MathBoxScene from 'containers/MathBoxScene' | |||
import { mathboxElement } from "containers/MathBoxScene/components/MathBoxScene"; |
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.
easy as pie!
@ChristopherChudzicki commenting here since I edited the description above; this all works great and is ready for review! |
|
||
export default function () { | ||
const position: Array<number> = mathbox.three.camera.position.toArray(); | ||
const lookAt: Array<number> = mathbox.three.controls.target.toArray(); |
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.
this change from center
to target
happened in OrbitControls
a few versions ago.
@sritchie Awesome! Thanks for making this PR. I'm happy to take a look at the mouse interaction stuff. I did some very hacky things to enable this overflow: I saw the issue you wrote in math3d-next... Will send an email shortly. |
Mouse interaction is all solved! The big thing remaining is getting tests
to run now that we import three as a module. That seems to kill the test
runner and I don’t see how to modify it…
…On Saturday, February 19, 2022, Chris Chudzicki ***@***.***> wrote:
@sritchie <https://github.com/sritchie> Awesome! Thanks for making this
PR. I'm happy to take a look at the mouse interaction stuff. I did some
very hacky things to enable this overflow:
[image: Screen Shot 2022-02-19 at 2 30 21 PM]
<https://user-images.githubusercontent.com/9010790/154816148-dd57475f-ca55-44e9-b248-16cb487d80c7.png>
I saw the issue you wrote in math3d-next... Will send an email shortly.
—
Reply to this email directly, view it on GitHub
<#330 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAARAA4DWAYC6ORYCKDVAGLU37WCRANCNFSM5OVW2W7A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Sam Ritchie
|
@sritchie Re the failing tests: There were two separate issues:
I merged then fixed (1) on that separate PR. Thanks again for this... it's an enormous improvement. As I've said... very exciting. |
@ChristopherChudzicki, we're in business! This PR gets us onto the latest Mathbox, which can handle any version of three.js.
The script instantiation of everything is now gone. I didn't do any measuring of the production build size, but I bet it's smaller since mathbox is pulling in only what it needs from threejs now vs relying on the big global import.
The PR has comments inline describing in more detail what I had to change.
here are the new packages: