how to hide character or glb Models Element like Eye hair.. etc in React three fiber

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ม.ค. 2025

ความคิดเห็น • 1

  • @paradise_hope
    @paradise_hope  4 วันที่ผ่านมา

    import React, { useEffect, useRef } from 'react';
    import { useGLTF } from '@react-three/drei';
    import Charater from '../../assets/Character/Character.glb';
    function Model({ position }) {
    const group = useRef();
    const d = useGLTF(Charater);
    console.log("nodes",d)
    useEffect(() => {
    if (d.scene) {
    // Locate the eyes in the scene hierarchy
    const leftEye = d.scene.getObjectByName('EyeRight'); // Replace 'LeftEye' with the actual name
    const rightEye = d.scene.getObjectByName('Wolf3D_Hair'); // Replace 'RightEye' with the actual name
    if (leftEye) leftEye.visible = false; // Hide the left eye
    if (rightEye) rightEye.visible = false; // Hide the right eye
    if (leftEye) leftEye.position.set(1, 0.5, 0); // Example: Move left eye
    //if (rightEye) rightEye.position.set(-1, 0.5, 0); // Example: Move right eye
    }
    }, [d.scene]);
    return (

    );
    }
    export default Model;