bug fix human
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import * as Types from "../../../../types/world/worldTypes";
|
||||
import { useGLTF } from "@react-three/drei";
|
||||
import { Tube, useGLTF } from "@react-three/drei";
|
||||
import * as THREE from "three";
|
||||
import { useFrame, useThree } from "@react-three/fiber";
|
||||
import { useSelectedEventSphere, useIsDragging, useIsRotating, } from "../../../../store/simulation/useSimulationStore";
|
||||
@@ -17,8 +17,6 @@ import { useVersionContext } from "../../../builder/version/versionContext";
|
||||
const VehicleUI = () => {
|
||||
const { scene: startScene } = useGLTF(startPoint) as any;
|
||||
const { scene: endScene } = useGLTF(startEnd) as any;
|
||||
const startMarker = useRef<Group>(null);
|
||||
const endMarker = useRef<Group>(null);
|
||||
const prevMousePos = useRef({ x: 0, y: 0 });
|
||||
const { selectedEventSphere } = useSelectedEventSphere();
|
||||
const { selectedProductStore } = useProductContext();
|
||||
@@ -163,7 +161,7 @@ const VehicleUI = () => {
|
||||
let globalStartPosition = null;
|
||||
let globalEndPosition = null;
|
||||
|
||||
if (outerGroup.current && startMarker.current && endMarker.current) {
|
||||
if (outerGroup.current) {
|
||||
const worldPosStart = new Vector3(...startPosition);
|
||||
globalStartPosition = outerGroup.current.localToWorld(
|
||||
worldPosStart.clone()
|
||||
@@ -278,24 +276,19 @@ const VehicleUI = () => {
|
||||
const currentPointerX = state.pointer.x;
|
||||
const deltaX = currentPointerX - prevMousePos.current.x;
|
||||
prevMousePos.current.x = currentPointerX;
|
||||
const marker =
|
||||
isRotating === "start" ? startMarker.current : endMarker.current;
|
||||
if (marker) {
|
||||
const rotationSpeed = 10;
|
||||
marker.rotation.y += deltaX * rotationSpeed;
|
||||
if (isRotating === "start") {
|
||||
setStartRotation([
|
||||
marker.rotation.x,
|
||||
marker.rotation.y,
|
||||
marker.rotation.z,
|
||||
]);
|
||||
} else {
|
||||
setEndRotation([
|
||||
marker.rotation.x,
|
||||
marker.rotation.y,
|
||||
marker.rotation.z,
|
||||
]);
|
||||
}
|
||||
const rotationSpeed = 10;
|
||||
if (isRotating === "start") {
|
||||
setStartRotation([
|
||||
startRotation[0],
|
||||
startRotation[1] + deltaX * rotationSpeed,
|
||||
startRotation[2],
|
||||
]);
|
||||
} else {
|
||||
setEndRotation([
|
||||
endRotation[0],
|
||||
endRotation[1] + deltaX * rotationSpeed,
|
||||
endRotation[2],
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -362,7 +355,7 @@ const VehicleUI = () => {
|
||||
position={endPosition}
|
||||
rotation={endRotation}
|
||||
outerGroupRef={outerGroup}
|
||||
color="red"
|
||||
color="orange"
|
||||
handlePointerDown={handlePointerDown}
|
||||
setIsDragging={setIsDragging}
|
||||
setIsRotating={setIsRotating}
|
||||
@@ -394,10 +387,10 @@ export const VehicleMarkerPrimitive = ({
|
||||
setIsDragging: (val: any) => void;
|
||||
setIsRotating: (val: any) => void;
|
||||
}) => {
|
||||
const { scene } = useThree();
|
||||
const { scene, camera } = useThree();
|
||||
const markerRef = useRef<THREE.Group>(null);
|
||||
const lineRef = useRef<THREE.BufferGeometry>(null);
|
||||
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
|
||||
const [curve, setCurve] = useState<THREE.CatmullRomCurve3 | null>(null);
|
||||
|
||||
useFrame(() => {
|
||||
if (!markerRef.current || !outerGroupRef.current) return;
|
||||
@@ -409,6 +402,7 @@ export const VehicleMarkerPrimitive = ({
|
||||
const rayOrigin = worldPos.clone();
|
||||
const direction = new THREE.Vector3(0, -1, 0);
|
||||
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
|
||||
raycaster.camera = camera;
|
||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
|
||||
const hit = intersects.find(i => i.object.name !== name);
|
||||
@@ -416,16 +410,14 @@ export const VehicleMarkerPrimitive = ({
|
||||
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
|
||||
setHitPoint(localHit);
|
||||
|
||||
if (lineRef.current) {
|
||||
const positions = new Float32Array([
|
||||
localMarkerPos.x, localMarkerPos.y, localMarkerPos.z,
|
||||
localHit.x, localHit.y, localHit.z
|
||||
]);
|
||||
lineRef.current.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
lineRef.current.attributes.position.needsUpdate = true;
|
||||
}
|
||||
const newCurve = new THREE.CatmullRomCurve3([
|
||||
localMarkerPos.clone(),
|
||||
localHit.clone(),
|
||||
]);
|
||||
setCurve(newCurve);
|
||||
} else {
|
||||
setHitPoint(null);
|
||||
setCurve(null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -437,7 +429,13 @@ export const VehicleMarkerPrimitive = ({
|
||||
object={object}
|
||||
position={position}
|
||||
rotation={rotation}
|
||||
onPointerDown={(e: any) => handlePointerDown(e, name === "startMarker" ? "start" : "end", name === "startMarker" ? "start" : "end")}
|
||||
onPointerDown={(e: any) =>
|
||||
handlePointerDown(
|
||||
e,
|
||||
name === "startMarker" ? "start" : "end",
|
||||
name === "startMarker" ? "start" : "end"
|
||||
)
|
||||
}
|
||||
onPointerMissed={() => {
|
||||
setIsDragging(null);
|
||||
setIsRotating(null);
|
||||
@@ -446,15 +444,20 @@ export const VehicleMarkerPrimitive = ({
|
||||
|
||||
{hitPoint && (
|
||||
<>
|
||||
<mesh name={`${name}-torus`} position={hitPoint} rotation={[-Math.PI / 2, 0, 0]}>
|
||||
<mesh
|
||||
name={`${name}-torus`}
|
||||
position={hitPoint}
|
||||
rotation={[-Math.PI / 2, 0, 0]}
|
||||
>
|
||||
<torusGeometry args={[0.15, 0.02, 3, 32]} />
|
||||
<meshBasicMaterial color={color} transparent opacity={0.8} depthWrite={false} />
|
||||
<meshBasicMaterial color={color} depthWrite={false} />
|
||||
</mesh>
|
||||
|
||||
<line>
|
||||
<bufferGeometry ref={lineRef} />
|
||||
<lineBasicMaterial color={color} />
|
||||
</line>
|
||||
{curve && (
|
||||
<Tube args={[curve, 20, 0.01, 8, true]}>
|
||||
<meshBasicMaterial color={color} depthWrite={false} />
|
||||
</Tube>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user