completed init movement for human

This commit is contained in:
2025-07-03 18:01:11 +05:30
parent 1e715cee50
commit 7cf82629e9
16 changed files with 302 additions and 567 deletions

View File

@@ -40,15 +40,10 @@ function HumanMechanics() {
selectedEventData.selectedPoint
) as HumanPointSchema | undefined;
if (point?.actions) {
if (point?.action) {
setSelectedPointData(point);
if (point.actions.length > 0) {
setSelectedAction(point.actions[0].actionUuid, point.actions[0].actionName);
const asset = getAssetById(selectedEventData.data.modelUuid);
if (asset && asset.animations) {
setAnimationOptions(asset.animations)
}
}
setCurrentAction(point.action);
setSelectedAction(point.action.actionUuid, point.action.actionName);
}
} else {
clearSelectedAction();
@@ -57,31 +52,17 @@ function HumanMechanics() {
useEffect(() => {
if (selectedEventData && selectedProduct.productUuid) {
const event = getEventByModelUuid(
selectedProduct.productUuid,
selectedEventData.data.modelUuid
) as HumanEventSchema | undefined;
if (event?.speed !== undefined) {
setSpeed(event.speed.toString());
}
const point = getPointByUuid(
selectedProduct.productUuid,
selectedEventData.data.modelUuid,
selectedEventData.selectedPoint
) as HumanPointSchema | undefined;
if (point?.actions) {
if (point?.action) {
setSelectedPointData(point);
const action = point.actions.find((a) => a.actionUuid === selectedAction.actionId);
if (action) {
setCurrentAction(action);
setActiveOption(action.actionType as "worker");
if (action.animationSequences.length > 0) {
setSelectedAnimation(action.animationSequences[0]);
}
}
setCurrentAction(point.action);
setActiveOption(point.action.actionType);
setSelectedAction(point.action.actionUuid, point.action.actionName);
}
} else {
clearSelectedAction();
@@ -108,17 +89,8 @@ function HumanMechanics() {
const handleSelectActionType = (actionType: string) => {
if (!selectedAction.actionId || !currentAction || !selectedPointData) return;
const updatedAction = {
...currentAction,
actionType: actionType as "worker"
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const updatedAction = { ...currentAction, actionType: actionType as "worker" };
const updatedPoint = { ...selectedPointData, action: updatedAction };
const event = updateAction(
selectedProduct.productUuid,
@@ -134,43 +106,6 @@ function HumanMechanics() {
setSelectedPointData(updatedPoint);
};
const handleChooseAnimation = (animationOption: string) => {
if (!selectedAction.actionId || !currentAction || !selectedAnimation || !selectedPointData) return;
const updatedAnimation = {
...selectedAnimation,
animation: animationOption
};
const updatedAction = {
...currentAction,
animationSequences: currentAction.animationSequences.map(anim =>
anim.animationUuid === selectedAnimation.animationUuid ? updatedAnimation : anim
)
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const event = updateAction(
selectedProduct.productUuid,
selectedAction.actionId,
updatedAction
);
if (event) {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
setCurrentAction(updatedAction);
setSelectedAnimation(updatedAnimation);
setSelectedPointData(updatedPoint);
};
const handleSpeedChange = (value: string) => {
if (!selectedEventData) return;
@@ -195,31 +130,14 @@ function HumanMechanics() {
setSpeed(value);
};
const handleClearPoints = (animationUuid: string) => {
const handleClearPoints = () => {
if (!currentAction || !selectedPointData || !selectedAction.actionId) return;
const updatedAnimation = currentAction.animationSequences.find(anim =>
anim.animationUuid === animationUuid
);
const updatedAction = { ...currentAction };
delete updatedAction.pickUpPoint;
delete updatedAction.dropPoint;
if (!updatedAnimation) return;
delete updatedAnimation.startPoint;
delete updatedAnimation.endPoint;
const updatedAction = {
...currentAction,
animationSequences: currentAction.animationSequences.map(anim =>
anim.animationUuid === animationUuid ? updatedAnimation : anim
)
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const updatedPoint = { ...selectedPointData, action: updatedAction };
const event = updateAction(
selectedProduct.productUuid,
@@ -233,9 +151,6 @@ function HumanMechanics() {
setCurrentAction(updatedAction);
setSelectedPointData(updatedPoint);
if (selectedAnimation?.animationUuid === animationUuid) {
setSelectedAnimation(updatedAnimation);
}
};
const handleAddAction = () => {
@@ -243,16 +158,8 @@ function HumanMechanics() {
const newAction: HumanAction = {
actionUuid: MathUtils.generateUUID(),
actionName: `Action ${selectedPointData.actions.length + 1}`,
actionName: `Action`,
actionType: "worker",
animationSequences: [
{
animationUuid: MathUtils.generateUUID(),
animationName: 'Animation 1',
animationType: 'behaviour',
animation: null
}
],
loadCapacity: 1,
triggers: [],
};
@@ -268,217 +175,27 @@ function HumanMechanics() {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
const updatedPoint = { ...selectedPointData, actions: [...selectedPointData.actions, newAction] };
const updatedPoint = { ...selectedPointData, action: newAction };
setSelectedPointData(updatedPoint);
setSelectedAction(newAction.actionUuid, newAction.actionName);
};
const handleDeleteAction = (actionUuid: string) => {
const handleDeleteAction = () => {
if (!selectedPointData) return;
const event = removeAction(selectedProduct.productUuid, actionUuid);
if (event) {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
const index = selectedPointData.actions.findIndex((a) => a.actionUuid === actionUuid);
const newActions = selectedPointData.actions.filter((a) => a.actionUuid !== actionUuid);
const updatedPoint = { ...selectedPointData, actions: newActions };
setSelectedPointData(updatedPoint);
if (selectedAction.actionId === actionUuid) {
const nextAction = newActions[index] || newActions[index - 1];
if (nextAction) {
setSelectedAction(nextAction.actionUuid, nextAction.actionName);
} else {
clearSelectedAction();
}
}
};
const handleAddAnimation = () => {
if (!currentAction || !selectedPointData || !selectedAction.actionId) return;
const newAnimation = {
animationUuid: MathUtils.generateUUID(),
animationName: `Animation ${currentAction.animationSequences.length + 1}`,
animationType: 'behaviour' as "behaviour",
animation: null
};
const updatedAction = {
...currentAction,
animationSequences: [...currentAction.animationSequences, newAnimation]
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const event = updateAction(
const event = removeAction(
selectedProduct.productUuid,
selectedAction.actionId,
updatedAction
selectedPointData.action.actionUuid
);
if (event) {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
setCurrentAction(updatedAction);
const updatedPoint = { ...selectedPointData, action: undefined as any };
setSelectedPointData(updatedPoint);
setSelectedAnimation(newAnimation);
};
const handleRemoveAnimation = (animationUuid: string) => {
if (!currentAction || !selectedPointData || !selectedAction.actionId) return;
const updatedAction = {
...currentAction,
animationSequences: currentAction.animationSequences.filter(
anim => anim.animationUuid !== animationUuid
)
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const event = updateAction(
selectedProduct.productUuid,
selectedAction.actionId,
updatedAction
);
if (event) {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
setCurrentAction(updatedAction);
setSelectedPointData(updatedPoint);
if (selectedAnimation?.animationUuid === animationUuid) {
setSelectedAnimation(updatedAction.animationSequences[0] || undefined);
}
};
const handleAnimationTypeChange = (animationUuid: string, newType: "behaviour" | "animatedTravel") => {
if (!currentAction || !selectedPointData || !selectedAction.actionId) return;
const updatedAnimationSequences = currentAction.animationSequences.map(anim => {
if (anim.animationUuid === animationUuid) {
const updatedAnim = {
...anim,
animationType: newType
};
delete updatedAnim.startPoint;
delete updatedAnim.endPoint;
return updatedAnim;
}
return anim;
});
const updatedAction = {
...currentAction,
animationSequences: updatedAnimationSequences
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const event = updateAction(
selectedProduct.productUuid,
selectedAction.actionId,
updatedAction
);
if (event) {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
setCurrentAction(updatedAction);
setSelectedPointData(updatedPoint);
if (selectedAnimation?.animationUuid === animationUuid) {
const updatedAnimation = updatedAnimationSequences.find(anim =>
anim.animationUuid === animationUuid
);
if (updatedAnimation) {
setSelectedAnimation(updatedAnimation);
}
}
};
const handleAnimationSelect = (animationUuid: string) => {
if (!currentAction || !selectedAction.actionId) return;
const animation = currentAction.animationSequences.find(
anim => anim.animationUuid === animationUuid
);
if (animation) {
setSelectedAnimation(animation);
}
};
const handleRenameAnimation = (animationUuid: string, newName: string) => {
if (!currentAction || !selectedPointData || !selectedAction.actionId) return;
const updatedAnimation = currentAction.animationSequences.find(anim =>
anim.animationUuid === animationUuid
);
if (!updatedAnimation) return;
const renamedAnimation = { ...updatedAnimation, animationName: newName };
const updatedAction = {
...currentAction,
animationSequences: currentAction.animationSequences.map(anim =>
anim.animationUuid === animationUuid ? renamedAnimation : anim
)
};
const updatedPoint = {
...selectedPointData,
actions: selectedPointData.actions.map(action =>
action.actionUuid === selectedAction.actionId ? updatedAction : action
)
};
const event = updateAction(
selectedProduct.productUuid,
selectedAction.actionId,
updatedAction
);
if (event) {
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
}
setCurrentAction(updatedAction);
setSelectedPointData(updatedPoint);
if (selectedAnimation?.animationUuid === animationUuid) {
setSelectedAnimation(renamedAnimation);
}
};
const availableActions = {
defaultOption: "worker",
options: ["worker"],
clearSelectedAction();
setCurrentAction(undefined);
};
return (
@@ -503,7 +220,7 @@ function HumanMechanics() {
<section>
<ActionsList
selectedPointData={selectedPointData}
multipleAction
multipleAction={false}
handleAddAction={handleAddAction}
handleDeleteAction={handleDeleteAction}
/>
@@ -511,69 +228,20 @@ function HumanMechanics() {
{selectedAction.actionId && currentAction && (
<div className="selected-actions-details">
<div className="selected-actions-header">
<RenameInput
value={selectedAction.actionName || ""}
canEdit={false}
/>
<RenameInput value={selectedAction.actionName || ""} canEdit={false} />
</div>
<div className="selected-actions-list">
<LabledDropdown
label="Action Type"
defaultOption={activeOption}
options={availableActions.options}
options={["worker"]}
onSelect={handleSelectActionType}
disabled={true}
/>
</div>
<AnimationList
animationOptions={animationOptions}
animationSequences={currentAction?.animationSequences || []}
onAddAnimation={handleAddAnimation}
onRemoveAnimation={handleRemoveAnimation}
handleAnimationSelect={handleAnimationSelect}
handleRenameAnimation={handleRenameAnimation}
/>
{selectedAnimation && (
<>
<div className="selected-actions-header">
<RenameInput
value={selectedAnimation.animationName || ""}
canEdit={false}
/>
</div>
<div className="animation-controls">
<LabledDropdown
label="Animation Type"
defaultOption={selectedAnimation.animationType}
options={["behaviour", "animatedTravel"]}
onSelect={(type) =>
handleAnimationTypeChange(
selectedAnimation.animationUuid,
type as "behaviour" | "animatedTravel"
)
}
/>
<LabledDropdown
label="Animation"
defaultOption={selectedAnimation.animation || ''}
options={animationOptions}
onSelect={handleChooseAnimation}
disabled={true}
/>
{selectedAnimation.animationType === "animatedTravel" && (
<PickAndPlaceAction
clearPoints={() => handleClearPoints(selectedAnimation.animationUuid)}
/>
)}
</div>
</>
)}
<PickAndPlaceAction clearPoints={handleClearPoints} />
<div className="tirgger">
<Trigger
selectedPointData={selectedPointData as any}
type={"Human"}
/>
<Trigger selectedPointData={selectedPointData as any} type="Human" />
</div>
</div>
)}