Adjust openscad image to match viewer size #239
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
web/src/helpers/cadPackages/openScadController.jsis hardcoded to get a 500x500 imaged from the openscad renderer. This should instead match the size of the viewer panel. I would assume thatreact-mosaichas some kind of event for resizes that we can fire to adjust it.It should also detect if the device is retina display and double the resolution.
https://stackoverflow.com/questions/19689715/what-is-the-best-way-to-detect-retina-support-on-a-device-using-javascript#20413768
Hey @Irev-Dev in
openScadController.js, is thesizeproperty supposed to control the size of the image returned from OpenSCAD? I've been able to get the image full-size and added in theviewerSizebased on the on-screen size of the element toIdeState, passing it into the render call, but I'm still getting a 512 x 512px image back from OpenSCAD. I'm assigning thexandyvalues on lines 23 and 24 ofopenScadController.I'm guessing 512 is the default for openscad, I've had a quick look, and the number look like floating points to me not integers. so I'm guessing it's falling back to 512. Try rounding the numbers to integers.
I'll back to this in a couple hours. I should be able to tell you something more definite. ^ that's my suspicion.
Gold, that did the trick. I'll push up a commit now and then get the retina thing sorted in a final one before PR.
@Irev-Dev okay so now I'm on another issue, seems related to a comment you left on line 118 of
IdeViewer.jswhich I've tried to demonstrate in my latest commit. When the panes are dragged the image now corrects by fetching a new image ✔, but after having dragged the pane if you try to orbit the camera the preview uses a staleviewerSizevalue and goes back to incorrect proportions. You mentioned in that comment the need to use a locally-defined variable to overcome the stale code issue within this file, but though I've been able to do the same withviewerSizewithin the component itself, what is interesting to me is that therenderdispatched event withinideVieweruses a staleviewerSizevalue even when that value is not passed into therendercall, but used withinuseIde. I'll investigate more in the morning just wanted you to see what I'm working through, because it might be something a bit larger to sort out now before this stale state thing gives us perennial headaches.@franknoirot I had a bit of a play earlier and got something working.
One . . . interesting thing I did is to manage the viewer-dimension-state completely in the openscad controller so that openscad specific state isn't dirtying the ide state. It makes other things more complicated. e.g. When initing, the controller is expecting both the ideContainer and the viewer to call render, one gives it it's dimensions and the other it's camera and it doesn't return an image until the second render call, but other than that it also means it automatically renders a new image on resize.
So I think I've likely side stepped the issue you've run into. but I had ran into stale state in ideViewer too (I think somehow
react-three-fibernot being completely react through-and-through might be causing it) And 100% you found my work around on 118, raising a variable to module scope. I noticed that If I logged out the state inside ofIdeViewerit was showing the correct state, but when the callbackonCameraChangefired it would be state, so but updating a module level variable. Even thoughonCameraChangeis my own callback, it original spawns from line 77controls.current.addEventListener('end', dragCallback)and I guess this is from with three.js and yeah not sure why.Your point about it using the stale value even when not passed viewerSize. I think I ran into that too at some point. It's really confusing, not sure I can be of much help
If my work is of use to you you can checkout
kurt/239or look at the commitDemo of rotate -> resize -> rotate working
https://user-images.githubusercontent.com/29681384/111061307-c06b2280-84f6-11eb-8699-1a0af5c745dc.mov
Does that help?
I update the above comment a couple times after re reading your comment.
Ah nice @Irev-Dev , I thought the
viewerSizewould be useful across CAD packages initially but I like what you did way better, that's working great. I think you got it if you want to PR, sorry I couldn't be of more use on this one. Love the new sprinkles lolokay, I've put up #251, sorry didn't mean to steal your thunder.
No no worries!
@Irev-Dev okay I'm messaging in here before a PR because it seems to simple to be correct. I know you linked to that StackOverflow discussion but what I've put in my commit is inspired by this MDN article about using the
Window.devicePixelRatioproperty to correct the resolution of a canvas, which I all I believe we need correct? Just generate an OpenSCAD render that is the size of the container multiplied by the pixel density? It seems to work on my laptop, which has a pixel ratio of 1.25. Let me know if I'm misunderstanding the problem.@franknoirot Sounds like you understand the problem better than me 👏