-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: migrate to vite. add support for ESM #18
base: main
Are you sure you want to change the base?
feat: migrate to vite. add support for ESM #18
Conversation
timothydang
commented
Jul 7, 2023
•
edited
Loading
edited
- Upgrade to latest mind-ar release (1.2.3)
- Bump versions of other dependencies
- Migrate to vite from webpack in sync with mind-ar
- Add support for ESM
The issue with FaceTracking is sorted, just needed to add |
much thanks @tommasoturchi, face tracking example is now working for me with the changes you suggested. I'll spend some time later this week to look into the image tracking issue. i think it might be something else related to the recent changes from mind-ar. from what i can see, vite is importing webworker correctly. |
hi @tommasoturchi , i think i've managed to get image tracking to display, by moving this block
to before |
@timothydang I just found that detection works good if you change the input width and height to the 'real' sizesof your screen. I also noticed that if I had the Devtools open (small viewport) the model rendered in the expected position. screen-capture.webmI use your modified version of AR.js https://github.com/timothydang/react-three-mind/blob/feat/vite-esm-migration/src/AR.jsx#L87 so if we adjust those lines, you can see interesting results ;) controller = new ImageTargetController({
inputWidth: webcamRef.current.video.clientWidth,
inputHeight: webcamRef.current.video.clientHeight,
...
}); That explains why detection sometimes worked and why the position of the models were not the expected. However, it needs more investigation IMO. Also, mind-ar just dropped a new release 2 days ago, so the changes that you and @tommasoturchi suggested need to be in a PR to release a new version of react-three-mind. I did another example of the facemesh, so let me know if you need help to put this togheter or make anoter PR. Thanks to both of you for your effort here! |
Ok, after deep dive into this, I finally made it work. I figured out that the webcam component was inside a drei html, however I suggest to not put it in that way becuase that component is for adding annotations to the 3D models in the scene, makes it hard to get and set sizes like the width and height of the video element. So, the first thing i made was to move the webcam element outside of the Canvas component. Then, I updated the startTracking method by taking the latest version of https://github.com/hiukim/mind-ar-js/blob/master/src/image-target/three.js#L141 I also refactored the code and components by follow the style of this amazing repo https://github.com/krsbx/mind-ar-react Here's the result 🎉 screen-capture.webmI only tested this using 1 anchor so far. I hope to have a chance to experiments with others scenarios. I don't know if I'm following the best practices of react, so if anyone knows how to improve this, please let us know :) |
thanks so much for picking this up @Darkensses I'll try to resume working on this over the next couple of days. will report back if we could update it to the latest version of mind-ar along with merging in your suggested changes |
The problem I keep battling against is how to package this so that it correctly exports everything as a library that can be embedded on other react-three projects, given that it's using web workers. I'm not an expert on vite, but last time I tried I had that problem. It's "easy enough" to implement it in one's own repo and use it, since you just import mind-ar as an external dependency. Here what would be neat is for people to just import this library and it takes care of importing mind-ar implementing an interface react-three-compliant. At least that was my original idea, but now that mind-ar moved to vitejs I found it quite difficult. If you can find a way to sort this out that would be amazing! I'll look into this once more during the weekend :-) |
This would be much appreciated, it'd be super helpful to use MindAR within R3F! Thanks for your work! |
@Darkensses thx for your repo! I noticed even a better performance for multi image trackers with your implementation. What I can't understand is how would I implement Anchor found and lost events? I can't understand the logic in the ARAnchor component:
|
Hi @chillbert, the code you looked is very experimental, so I ommited the events that you mentioned, however you can implemented based on the code of this repo: https://github.com/tommasoturchi/react-three-mind/blob/main/src/AR.js#L302C3-L302C16 |
I actually did exactly that, uncommented the lines:
but as mentioned:
"the code you looked is very experimental" - I see; did you also change the logic somehow or why is your code so much faster (not the vite build process, the actuall app, recognition and tracking). |
aaah now I see, you moved the webcam view from the html drei component in its own canvas - this explains the performance boost much likely. |
That's right, html drei component is only recommended for text or small element, not for video |
I still didn't manage to fix the onAnchorLost trigger... In this code the visibility of the anchor children works, but the onAnchorLost callback is not triggered:
in this case, the onAnchorLost is triggered, but the elements on the anchor stays visible even when the anchor is lost:
I didn't manage to have both working in the same code... strange! |
finally:
|