Skip to content

Commit

Permalink
new version + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tommasoturchi committed Nov 20, 2022
1 parent f9c7818 commit 16dd6d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-three-mind",
"version": "0.1.7",
"version": "0.1.8",
"description": "MindAR components for @react-three/fiber",
"main": "dist/index.js",
"author": "Tommaso Turchi",
Expand Down
39 changes: 22 additions & 17 deletions src/AR.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const ARProvider = forwardRef(
filterBeta = null,
warmupTolerance = null,
missTolerance = null,
onReady = null,
onError = null,
},
ref
) => {
Expand All @@ -49,11 +51,6 @@ const ARProvider = forwardRef(
const [faceMeshes] = useAtom(faceMeshesAtom);

const { width, height } = useWindowSize();
const isLandscape = useMemo(() => height <= width, [height, width]);
const ratio = useMemo(
() => (isLandscape ? width / height : height / width),
[isLandscape, width, height]
);

useEffect(() => {
if (controllerRef.current) {
Expand Down Expand Up @@ -202,6 +199,8 @@ const ARProvider = forwardRef(
controller.processVideo(webcamRef.current.video);

controllerRef.current = controller;

onReady && onReady();
}
}, [
ready,
Expand Down Expand Up @@ -253,20 +252,19 @@ const ARProvider = forwardRef(
}, [autoplay, ready, startTracking]);

const fixStyle = () => {
let offset = 0
if(webcamRef.current?.video?.clientWidth>0){
let offset = 0;
if (webcamRef.current?.video?.clientWidth > 0) {
offset = (width - webcamRef.current.video.clientWidth) / 2;
}
offset = parseInt(offset+'')
return(
{
width: "auto",
maxWidth: "none",
height: 'inherit',
marginLeft: offset+'px'
}
)
}
offset = parseInt(offset + "");

return {
width: "auto",
maxWidth: "none",
height: "inherit",
marginLeft: offset + "px",
};
};

return (
<>
Expand All @@ -279,6 +277,9 @@ const ARProvider = forwardRef(
<Webcam
ref={webcamRef}
onUserMedia={handleStream}
onUserMediaError={(e) => {
onError && onError(e);
}}
height={height}
width={width}
videoConstraints={{
Expand All @@ -304,6 +305,8 @@ const ARView = forwardRef(
filterBeta,
warmupTolerance,
missTolerance,
onReady,
onError,
...rest
},
ref
Expand Down Expand Up @@ -333,6 +336,8 @@ const ARView = forwardRef(
filterBeta,
warmupTolerance,
missTolerance,
onReady,
onError,
}}
ref={ARRef}
>
Expand Down

0 comments on commit 16dd6d2

Please sign in to comment.