import React, { useRef, useState } from “react”;
import { useGLTF, Decal, useTexture } from “@react-three/drei”;
import { useControls } from “leva”;
import { degToRad } from “three/src/math/MathUtils.js”;
export function Mug(props) {
const { nodes, materials } = useGLTF(“/models/mug.glb”);
const texture = useTexture(“textures/david.png”);
const decal = useRef();
useControls({
angle: {
min: degToRad(60),
max: degToRad(300),
step: 0.01,
value: Math.PI / 4,
onChange: (value) => {
//decal.current.rotation.y = value;
const x = Math.cos(value);
const z = Math.sin(value);
const rot = Math.atan2(x, z);
setPos((pos) => [x, pos[1], z]);
setRotation((rotation) => [0, rot, 0]);
},
},
PosY: {
min: 0,
max: 3,
value: 0.4,
step: 0.01,
onChange: (value) => {
setPos((pos) => [pos[0], value, pos[2]]);
},
},
scale: {
min: 0.5,
max: 3,
value: 1,
step: 0.01,
onChange: (value) => {
setScale(() => [value, value, value]);
},
},
});
const [pos, setPos] = useState([0, 0.8, -0.5]);
const [rotation, setRotation] = useState([0, 0, 0]);
const [scale, setScale] = useState([1, 1, 1]);
return (
<group {…props} dispose={null}>
);
}
useGLTF.preload(“/models/mug.glb”);
this is code for sticky.
here I don’t know well about following part.
const rot = Math.atan2(x, z);
setPos((pos) => [x, pos[1], z]);
setRotation((rotation) => [0, rot, 0]);
why does this code need?