From 5283c74050dc0753d5bf1962b3e9b613a8b630e9 Mon Sep 17 00:00:00 2001 From: memelotsqui Date: Tue, 17 Oct 2023 17:23:46 -0600 Subject: [PATCH] disable mouse look on checkbox selected --- src/components/Editor.jsx | 2 +- src/components/TraitInformation.jsx | 16 ++++++++++++++-- src/library/lookatManager.js | 6 +++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/Editor.jsx b/src/components/Editor.jsx index 5acf8ace..d24aaa56 100644 --- a/src/components/Editor.jsx +++ b/src/components/Editor.jsx @@ -115,7 +115,7 @@ export default function Editor({confirmDialog,animationManager, blinkManager, lo - + ) } diff --git a/src/components/TraitInformation.jsx b/src/components/TraitInformation.jsx index 12369704..d9043cf1 100644 --- a/src/components/TraitInformation.jsx +++ b/src/components/TraitInformation.jsx @@ -5,7 +5,7 @@ import { SceneContext } from "../context/SceneContext"; import Slider from "./Slider"; import { cullHiddenMeshes } from "../library/utils"; -export default function TraitInformation({currentVRM, animationManager}){ +export default function TraitInformation({currentVRM, animationManager, lookatManager}){ const { displayTraitOption, avatar @@ -15,6 +15,7 @@ export default function TraitInformation({currentVRM, animationManager}){ const [cullInDistance, setCullInDistance] = useState(0); const [cullLayer, setCullLayer] = useState(0); const [animationName, setAnimationName] = useState(animationManager.getCurrentAnimationName()); + const [hasMouseLook, setHasMouseLook] = useState(lookatManager.enabled); useEffect(() => { if (currentVRM != null){ @@ -47,6 +48,7 @@ export default function TraitInformation({currentVRM, animationManager}){ }; const handleCullLayerChange = (event) => { + console.log(lookatManager.enabled); if (currentVRM?.data){ setCullLayer(event.target.value); currentVRM.data.cullingLayer = event.target.value; @@ -62,6 +64,11 @@ export default function TraitInformation({currentVRM, animationManager}){ await animationManager.loadPreviousAnimation(); setAnimationName(animationManager.getCurrentAnimationName()); } + const handleMouseLookEnable = (event) => { + setHasMouseLook(event.target.checked); + lookatManager.setActive(event.target.checked); + // Perform any additional actions or logic based on the checkbox state change + }; return ( displayTraitOption != null ? ( @@ -134,10 +141,15 @@ export default function TraitInformation({currentVRM, animationManager}){
+ Mouse Follow
diff --git a/src/library/lookatManager.js b/src/library/lookatManager.js index 4e745f44..4dfdde30 100644 --- a/src/library/lookatManager.js +++ b/src/library/lookatManager.js @@ -9,6 +9,7 @@ export class LookAtManager { this.leftEyeBones = [] this.rightEyesBones = [] this.curMousePos = new THREE.Vector2() + this.enabled = true; this.hotzoneSection = getHotzoneSection() this.enabled = true @@ -56,6 +57,9 @@ export class LookAtManager { // this.update(); // }, 1000/60); } + setActive(active){ + this.enabled = active; + } setCamera(camera){ this.camera = camera } @@ -127,7 +131,7 @@ export class LookAtManager { const cameraRotationThreshold = localVector.z > 0.; // if camera rotation is not larger than 90 if (this.curMousePos.x > this.hotzoneSection.xStart && this.curMousePos.x < this.hotzoneSection.xEnd && this.curMousePos.y > this.hotzoneSection.yStart && this.curMousePos.y < this.hotzoneSection.yEnd && - cameraRotationThreshold) { + cameraRotationThreshold && this.enabled) { this.neckBones.forEach(neck => { this._moveJoint(neck, this.maxLookPercent.neck) })