feat: Enhance conveyor actions and event handling

- Added detailed logging for default conveyor actions in useConveyorActions.
- Integrated play and reset button states into useActionHandler for better control flow.
- Updated PointsCreator to conditionally render based on play state and improved event handling.
- Modified MaterialAnimator to support pause and resume functionality based on play state.
- Enhanced MaterialInstance to trigger actions upon animation completion.
- Implemented material clearing logic in Materials component on reset or stop.
- Updated Simulator to respect play and reset states during action handling.
- Improved trigger handling logic to accommodate new event retrieval methods.
- Added utility functions in useProductStore for fetching events by trigger and point UUIDs.
- Created a new file for default action handling in conveyor actions.
This commit is contained in:
2025-05-05 20:08:05 +05:30
parent 6b0ee0ae79
commit c89c4234a4
15 changed files with 656 additions and 362 deletions

View File

@@ -5,12 +5,16 @@ import { useProductStore } from '../../../../../store/simulation/useProductStore
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { MaterialModel } from '../material/materialModel';
import { useThree } from '@react-three/fiber';
import { useAnimationPlaySpeed } from '../../../../../store/usePlayButtonStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
function MaterialInstance({ material }: { material: MaterialSchema }) {
const matRef: any = useRef();
const { scene } = useThree();
const { getModelUuidByPointUuid, getPointByUuid, getEventByModelUuid } = useProductStore();
const { getModelUuidByPointUuid, getPointByUuid, getEventByModelUuid, getActionByUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct();
const { speed } = useAnimationPlaySpeed();
const { triggerPointActions } = useTriggerHandler();
const getWorldPositionFromScene = (pointUuid: string): THREE.Vector3 | null => {
const pointObj = scene.getObjectByProperty("uuid", pointUuid);
@@ -21,32 +25,32 @@ function MaterialInstance({ material }: { material: MaterialSchema }) {
return worldPosition;
};
const { position, rotation, speed } = useMemo(() => {
const { position, rotation, currentSpeed } = useMemo(() => {
if (!material.current?.pointUuid) {
return { position: new THREE.Vector3(0, 0, 0), rotation: new THREE.Vector3(0, 0, 0), speed: 1 };
return { position: new THREE.Vector3(0, 0, 0), rotation: new THREE.Vector3(0, 0, 0), currentSpeed: 1 };
}
const modelUuid = getModelUuidByPointUuid(selectedProduct.productId, material.current.pointUuid);
if (!modelUuid) {
return { position: new THREE.Vector3(0, 0, 0), rotation: new THREE.Vector3(0, 0, 0), speed: 1 };
return { position: new THREE.Vector3(0, 0, 0), rotation: new THREE.Vector3(0, 0, 0), currentSpeed: 1 };
}
const speed = getCurrentSpeed(selectedProduct.productId, modelUuid);
const currentSpeed = getCurrentSpeed(selectedProduct.productId, modelUuid);
const point = getPointByUuid(selectedProduct.productId, modelUuid, material.current.pointUuid);
if (!point) {
return { position: new THREE.Vector3(0, 0, 0), rotation: new THREE.Vector3(0, 0, 0), speed: 1 };
return { position: new THREE.Vector3(0, 0, 0), rotation: new THREE.Vector3(0, 0, 0), currentSpeed: 1 };
}
const position = getWorldPositionFromScene(point.uuid);
if (position) {
return { position: position, rotation: new THREE.Vector3(0, 0, 0), speed: 1 };
return { position: position, rotation: new THREE.Vector3(0, 0, 0), currentSpeed: 1 };
}
return {
position: new THREE.Vector3(...point.position),
rotation: new THREE.Vector3(...point.rotation),
speed: speed || 1
currentSpeed: currentSpeed || 1
};
}, [material, getPointByUuid]);
@@ -82,16 +86,25 @@ function MaterialInstance({ material }: { material: MaterialSchema }) {
// console.log('material: ', material);
}, [material])
const callTrigger = () => {
const action = getActionByUuid(selectedProduct.productId, material.current.actionUuid)
if (action) {
triggerPointActions(action);
}
}
return (
<>
<MaterialModel matRef={matRef} materialType={material.materialType} position={position} />
{material.isRendered &&
<MaterialModel matRef={matRef} materialType={material.materialType} visible={material.isVisible} position={position} />
}
<MaterialAnimator
matRef={matRef}
material={material}
speed={speed}
onAnimationComplete={() => { console.log('123');}}
currentSpeed={currentSpeed * speed}
onAnimationComplete={() => { callTrigger() }}
/>
</>
)