-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add "touching edge" and tight bounding box functionality #119
Conversation
This fixes a WebGL warning when we tried to render skins that had no texture. Now, we return before trying to render them.
Unfortunately, handling this properly involves a lot of edge cases. We have to implement the bounding box correctly even for sprites with distortion effects, and the pixels' area must be accounted for.
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 looks really clean! Thanks a million for putting this thorough implementation together, I definitely didn't expect anything like it so quickly :)
I have a couple comments but they're small and mostly requesting some further details / exploration. In general this pull looks good to me. Thank you!
const EPSILON = 1e-3; | ||
|
||
// Transform a texture-space point using the effects defined on the given drawable. | ||
const effectTransformPoint = (drawable, src, dst) => { |
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.
Simulating effect transformations in JavaScript is really interesting to me, even though the details are a bit beyond my comprehension :P
I think it'd be interesting to look over the discussion/summary in scratchfoundation/scratch-render#196 and try testing the example project in Leopard with these changes and "if on edge, bounce" implemented.
Now that we're caching the same Rectangle object, we need to copy it before snapping it to int bounds.
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.
Error I noticed: Changing a sprite's size
does not cause its appearance to change until some other update (like moving or rotating) makes Leopard "notice" that something is different.
I should say, by the way, that this update is absolutely amazing and way above my pay grade. Thank you for the amazing work @adroitwhiz! 🤩 |
Whoops, fixed those issues. I'm definitely in support of converting stuff over to TypeScript now that we have a build step. |
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.
Took a while of updating my local setup but I got Leopard working locally and tested this out with a new example project—it looks like it works great :)
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.
A thorough review of all the code is beyond my abilities, but the behavior looks good in my test project, and @towerofnix signed off on the behavior in their own test project, so I am content.
BTW, I tested these changes with the ifOnEdgeBounce implementation from #114 and it works very well -- see my most recent post in that PR for screenshots of improved performance. Excellent work!! |
This is necessary for implementing #114.
There are a few changes to the renderer I made here:
SkinCache
class with aWeakMap
ofCostume
s toSkin
sSkinCache
existed was to associate renderer-specificSkin
data (which holds a costume's WebGL texture and other rendering stuff) with correspondingCostume
s. We don't want to hold onto that data if those costumes are deleted, which is why I created a deletion mechanism. However, we can just use aWeakMap
instead._setSkinUniforms
with_renderSkin
Skin
s associated withCostume
s, we now haveDrawable
s associated withSprite
s. The transformation matrix is now stored here, and only recalculated when a sprite's transform-related properties change. Ideally, the sprite would signal this itself by setting a flag whenever its position, size, or rotation change, but I'm not sure about whether we want that sort of cross-cutting here, so I just added diff checking for all the properties that cause the transformation matrix to be recalculated.getImageData
method to skinseffectTransformPoint
function, which replicates the whirl, fisheye, pixelate, and mosaic effects in JavaScriptscratch-render
convex hull code and my Rust version of it.There's still no "touching edge" support for the
sb-edit
Leopard code generator--that needs to be implemented separately.