initial jscad integration #428
Reference in New Issue
Block a user
Delete Branch "kurt/411-demo-branch"
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?
Please review, and any feedback on coding style is welcome.
Also preview refresh uses direct access to threejs using useThree() and adds geometries to the scene and also removes and makes sure they are also diposed. I works so it is not critical to get it fixed now. Sbdy with more experience with react could maybe do it without direct access.
@@ -0,0 +1,625 @@(function(f) {I understand why you've done it, having this file just hanging in the public folder is not something I'd like to have long term, mostly because unlike the rest of the repo this isn't transpiled so suddenly we have to be concious of old browsers just for this one file.
@@ -0,0 +131,4 @@let workerBaseURIfunction require(url){👌 out of curiosity are we currently locked into the old node
requiresyntax only? Wondering if you have ideas forimportsyntax?@@ -0,0 +1,625 @@(function(f) {There are 2 ways to run a worker.
option 2. would enable bundling the code together with rest of the app and can be done in two ways
worker is still heavily under construction, and currently this way it is easier to debug for me. After it is further improved we will look to integrate it instead of having it like this in public folder.
@@ -0,0 +184,4 @@let pointerDown = falseconst moveHandler = (ev) => {I don't quiet follow how these handlers fit in? especially since this runs in the worker. Could you explain it a little?
@@ -0,0 +131,4 @@let workerBaseURIfunction require(url){it is just a piece of code I was able to hack-up that works. Like that hack
useThreefor react-fiber. The worker needs more refinement for sure.I'm a bit confused about this file, both in that you're exporting a function here but I can't figure out where it's imported and used? Also I noticed that a lot of the functions in this file are duplicated in the demo worker as well, what's going on there?
@@ -0,0 +184,4 @@let pointerDown = falseconst moveHandler = (ev) => {it is code when canvas is used directly
The worker has 3 parts:
I was not sure if we would go in direction of direct canvass access. for now, this integration only "script eval" part is needed.
I curently copy/pasta the worker from my other prototype. After I refine the prototype worker, I will have a version that only has "script eval" part.
it is a leftower from work in progress. I have deleted it
@@ -0,0 +127,4 @@})const waitResult = new Promise((resolve) => {resolveReference = resolvehmmm I might have a bit of think of how we might be able to change this, and a few other bits related to turning a worker message into a promise. assigning the resolve function to an upper scope var smells a bit off to me.
Nice work @hrgdavor.
So good to have another integration, three feels like a milestone somehow.
My thoughts are that there are a few things I'd like to see changed but think it makes sense to merge as is because it would be good to demo to the JSCAD team before putting too much effort into this (as we talked about previously). I think at the point where we are looking to allow users to save jscad projects, at that point I'll want to see a couple things changed.
I've commented on them above but's really just moving the worker out of public and probably something related to the promise from the worker message.
Also I'm curious if you would mind if I refactored some of the
jsCadControllerto make it a little morereact-three-fiber-centric?In regards to the change I made in
IdeViewerI got pretty stuck on that, I was certain we should have been able to render the result directly, but I found it would flash up and then disappear. Doing some logging revealed that the children would disappear after the first render in theGroup, I couldn't figure out where but I guessing something must have been mutating that object, and that's like the golden rule for react, not to mutate. Anyway glad I was able to sort it out.@@ -0,0 +184,4 @@let pointerDown = falseconst moveHandler = (ev) => {okay yup, cool.
@@ -0,0 +131,4 @@let workerBaseURIfunction require(url){yup, sweet.
@@ -0,0 +127,4 @@})const waitResult = new Promise((resolve) => {resolveReference = resolveI was thinking that I need to stop pervious job if next one comes before first one is finished. hence the upper scope.
@@ -0,0 +1,625 @@(function(f) {Fair enough.
Once you're happy with it/it's settled down a little, I'd be happy to work this into the bundle. I did something similar in another webpack project
https://github.com/zalo/CascadeStudio/pull/58/files#diff-d4a06c27ddf0c24f2ba6029bffc9b20062214e07d6ee72822997fb6941b2534d
I am glad you did that, I tried few things but could not exactly pinpoint the issue. I like to make things work first before looking for a better solution :)
I agree with mentioned changes to worker, it is a work in progress
Code/experience here could be extracted into a small lib that does jscad -> react-fiber integration for others interested.