Skip to content

Commit

Permalink
disable mouse look on checkbox selected
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Oct 17, 2023
1 parent aeb65c2 commit 5283c74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function Editor({confirmDialog,animationManager, blinkManager, lo
</div>
</div>
<Selector confirmDialog = {confirmDialog} animationManager={animationManager} templateInfo={templateInfo} blinkManager = {blinkManager} lookatManager = {lookatManager} effectManager = {effectManager}/>
<TraitInformation currentVRM={currentVRM} animationManager={animationManager}/>
<TraitInformation currentVRM={currentVRM} animationManager={animationManager} lookatManager={lookatManager}/>
</Fragment>
)
}
16 changes: 14 additions & 2 deletions src/components/TraitInformation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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){
Expand Down Expand Up @@ -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;
Expand All @@ -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 ? (
Expand Down Expand Up @@ -134,10 +141,15 @@ export default function TraitInformation({currentVRM, animationManager}){
<div className={styles["traitInfoText"]}>
<div className={styles["checkboxHolder"]}>
<div>

Mouse Follow
</div>
<label className={styles["custom-checkbox"]}>
<input type="checkbox" />
<input
type="checkbox"
checked={hasMouseLook}
onChange={handleMouseLookEnable}
/>
<div className={styles["checkbox-container"]}></div>
</label>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/library/lookatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,6 +57,9 @@ export class LookAtManager {
// this.update();
// }, 1000/60);
}
setActive(active){
this.enabled = active;
}
setCamera(camera){
this.camera = camera
}
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 5283c74

Please sign in to comment.