diff --git a/app/src/modules/scene/physics/conveyor/ribbonCollider.tsx b/app/src/modules/scene/physics/conveyor/ribbonCollider.tsx
index a4f5e35..5702a20 100644
--- a/app/src/modules/scene/physics/conveyor/ribbonCollider.tsx
+++ b/app/src/modules/scene/physics/conveyor/ribbonCollider.tsx
@@ -15,10 +15,12 @@ function RibbonCollider({
}) {
const [forward, setForward] = useState(false);
+ // console.log('ribbonData: ', ribbonData);
return (
<>
{ribbonData.type === 'normal' && (
)}
{ribbonData.type === 'y-Split' && (
)}
>
diff --git a/app/src/modules/scene/physics/conveyor/types/curvedConveyorCollider.tsx b/app/src/modules/scene/physics/conveyor/types/curvedConveyorCollider.tsx
index d68668e..fa67e0f 100644
--- a/app/src/modules/scene/physics/conveyor/types/curvedConveyorCollider.tsx
+++ b/app/src/modules/scene/physics/conveyor/types/curvedConveyorCollider.tsx
@@ -3,23 +3,25 @@ import { CollisionPayload, RigidBody } from '@react-three/rapier';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useFrame } from '@react-three/fiber';
-function CurvedConveyorCollider({
- points,
- boundingBox,
- asset,
- forward: initialForward,
+function CurvedConveyorCollider({
+ points,
+ boundingBox,
+ asset,
+ forward,
isPaused,
+ onDirectionChange
}: {
points: [number, number, number][][];
boundingBox: THREE.Box3 | null;
asset: Asset;
forward: boolean;
isPaused: boolean;
+ onDirectionChange?: (newDirection: boolean) => void;
}) {
const conveyorRef = useRef(null);
const [objectsOnConveyor, setObjectsOnConveyor] = useState>(new Set());
const conveyorDirection = useRef(new THREE.Vector3());
- const [forward, setForward] = useState(initialForward);
+ // const [forward, setForward] = useState(initialForward);
const [showDirection, setShowDirection] = useState(false);
const [hoverState, setHoverState] = useState(false);
const conveyorSpeed = 2;
@@ -32,9 +34,11 @@ function CurvedConveyorCollider({
const handleClick = (e: MouseEvent) => {
if (e.button === 2 && hoverState) { // Right click and hovering over conveyor
const now = Date.now();
- if (now - lastClickTime.current < 300) {
-
- setForward(prev => !prev);
+ if (now - lastClickTime.current < 300) {
+ if (onDirectionChange) {
+ console.log('forwardcurve: ', forward);
+ onDirectionChange(!forward);
+ }
}
lastClickTime.current = now;
}
@@ -44,7 +48,7 @@ function CurvedConveyorCollider({
return () => window.removeEventListener('mousedown', handleClick);
}, [forward, hoverState]);
-
+
const bezierPoints = useMemo(() => {
const segments = 20;
const allPoints: THREE.Vector3[] = [];
@@ -72,7 +76,7 @@ function CurvedConveyorCollider({
return allPoints;
}, [points, forward]);
-
+
const geometries = useMemo(() => {
const width = 1;
const segments = 20;
@@ -131,15 +135,15 @@ function CurvedConveyorCollider({
return geos;
}, [points, asset.position, asset.rotation]);
-useEffect(() => {
- if (bezierPoints.length >= 2) {
- const start = bezierPoints[0];
- const end = bezierPoints[bezierPoints.length - 1];
- conveyorDirection.current.copy(end).sub(start).normalize();
- const rotation = new THREE.Euler().fromArray(asset.rotation || [0, 0, 0]);
- conveyorDirection.current.applyEuler(rotation);
- }
-}, [bezierPoints, forward, asset.rotation]);
+ useEffect(() => {
+ if (bezierPoints.length >= 2) {
+ const start = bezierPoints[0];
+ const end = bezierPoints[bezierPoints.length - 1];
+ conveyorDirection.current.copy(end).sub(start).normalize();
+ const rotation = new THREE.Euler().fromArray(asset.rotation || [0, 0, 0]);
+ conveyorDirection.current.applyEuler(rotation);
+ }
+ }, [bezierPoints, forward, asset.rotation]);
const handleMaterialEnter = (e: CollisionPayload) => {
@@ -165,7 +169,7 @@ useEffect(() => {
useFrame(({ clock }) => {
if (isPaused) return;
-
+
// Physics simulation
const assetPos = new THREE.Vector3(...(asset.position || [0, 0, 0]));
const assetRot = new THREE.Euler(...(asset.rotation || [0, 0, 0]));
@@ -210,7 +214,7 @@ useEffect(() => {
// Pulse animation
const pulseScale = 0.9 + 0.1 * Math.sin(elapsedTime * 5 + index * 0.5);
arrowGroup.scale.setScalar(pulseScale);
-
+
// Flow animation (color intensity)
const intensity = 0.7 + 0.3 * Math.sin(elapsedTime * 3 + index * 0.3);
arrowGroup.children.forEach(child => {
@@ -231,12 +235,12 @@ useEffect(() => {
// Create curved direction indicators
const directionArrows = useMemo(() => {
if (!showDirection) return null;
-
+
const arrows: THREE.Group[] = [];
const arrowHeight = 0.2;
const arrowRadius = 0.05;
const segments = 8; // Fewer arrows for curved conveyors
-
+
points.forEach(segment => {
let vectorPoints = segment.map(p => new THREE.Vector3(...p));
if (!forward) vectorPoints.reverse();
@@ -263,25 +267,25 @@ useEffect(() => {
// Create arrow group
const arrowGroup = new THREE.Group();
-
+
// Arrow shaft (cylinder)
const shaftLength = arrowHeight * 0.7;
const shaftGeometry = new THREE.CylinderGeometry(arrowRadius * 0.3, arrowRadius * 0.3, shaftLength, 8);
- const shaftMaterial = new THREE.MeshBasicMaterial({
- color: forward ? 0x00ff00 : 0xff0000
+ const shaftMaterial = new THREE.MeshBasicMaterial({
+ color: forward ? 0x00ff00 : 0xff0000
});
const shaft = new THREE.Mesh(shaftGeometry, shaftMaterial);
shaft.position.y = shaftLength / 2;
shaft.rotation.x = Math.PI / 2;
-
+
// Arrow head (cone)
const headGeometry = new THREE.ConeGeometry(arrowRadius, arrowHeight * 0.3, 8);
- const headMaterial = new THREE.MeshBasicMaterial({
- color: forward ? 0x00ff00 : 0xff0000
+ const headMaterial = new THREE.MeshBasicMaterial({
+ color: forward ? 0x00ff00 : 0xff0000
});
const head = new THREE.Mesh(headGeometry, headMaterial);
head.position.y = shaftLength;
-
+
// Position and orient the entire arrow
arrowGroup.add(shaft);
arrowGroup.add(head);
@@ -291,12 +295,12 @@ useEffect(() => {
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(tangent.x, 0.1, tangent.z)
);
-
+
arrows.push(arrowGroup);
}
}
});
-
+
arrowRefs.current = arrows;
return arrows;
}, [points, showDirection, forward]);
@@ -326,22 +330,22 @@ useEffect(() => {
>
{geometries.map((geometry, index) => (
-
))}
)}
-
+
{/* Direction indicators */}
{showDirection && directionArrows?.map((arrow, i) => (
))}
-
+
{/* Hover highlight */}
{hoverState && (
@@ -351,9 +355,9 @@ useEffect(() => {
geometry={geometry}
position={[0, 0.002, 0]} // Slightly above conveyor
>
-
diff --git a/app/src/modules/scene/physics/conveyor/types/normalConveyorCollider.tsx b/app/src/modules/scene/physics/conveyor/types/normalConveyorCollider.tsx
index 227736a..7766b83 100644
--- a/app/src/modules/scene/physics/conveyor/types/normalConveyorCollider.tsx
+++ b/app/src/modules/scene/physics/conveyor/types/normalConveyorCollider.tsx
@@ -3,36 +3,32 @@ import { CollisionPayload, RigidBody } from '@react-three/rapier';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useFrame } from '@react-three/fiber';
-function NormalConveyorCollider({
- points,
- boundingBox,
- asset,
- forward,
- isPaused,
- onDirectionChange
-}: {
+interface NormalConveyorColliderProps {
points: [number, number, number][][];
boundingBox: THREE.Box3 | null;
asset: Asset;
forward: boolean;
isPaused: boolean;
onDirectionChange?: (newDirection: boolean) => void;
-}) {
+}
+
+function NormalConveyorCollider({ points, boundingBox, asset, forward, isPaused, onDirectionChange }: NormalConveyorColliderProps) {
const conveyorRefs = useRef<(any)[]>([]);
- const [objectsOnConveyor, setObjectsOnConveyor] = useState>(new Set());
+ const [objectsOnGeometry, setObjectsOnGeometry] = useState