This commit is contained in:
moxitech 2024-11-24 02:48:27 +07:00
parent 61912545e6
commit ef19da1ce0
4 changed files with 38 additions and 6 deletions

View File

@ -101,6 +101,13 @@ const FormComponent = <T extends Drone | BaseStation>({ entity, onUpdate }: Form
onChange={(e) => handleInputChange('signalRadius', +e.target.value)} onChange={(e) => handleInputChange('signalRadius', +e.target.value)}
/> />
</div> </div>
<div className="mb-4">
<label className="block mb-1 text-sm font-medium">Signal power:</label>
<input
className="w-full p-2 bg-gray-800 border border-gray-600 rounded focus:outline-none focus:border-blue-500"
type="number"
/>
</div>
{'antennaDirection' in formData && ( {'antennaDirection' in formData && (
<div className="mb-4"> <div className="mb-4">
<label className="block mb-1 text-sm font-medium">Antenna Direction (x, y, z):</label> <label className="block mb-1 text-sm font-medium">Antenna Direction (x, y, z):</label>

View File

@ -163,6 +163,7 @@ const PlayerTsInstance: React.FC<IPlayerTsInstance> = ({
const [drones, setDrones] = useState<DroneSim[]>([]); const [drones, setDrones] = useState<DroneSim[]>([]);
const [baseStations, setBaseStations] = useState<BaseStation[]>([]); const [baseStations, setBaseStations] = useState<BaseStation[]>([]);
const [isPlaying, setIsPlaying] = useState(false); // Флаг для управления анимацией const [isPlaying, setIsPlaying] = useState(false); // Флаг для управления анимацией
const [droneTrajectories, setDroneTrajectories] = useState<Record<string, [number, number, number][]>>({});
const intervalRef = useRef<NodeJS.Timeout | null>(null); const intervalRef = useRef<NodeJS.Timeout | null>(null);
@ -176,13 +177,26 @@ const PlayerTsInstance: React.FC<IPlayerTsInstance> = ({
const updateObjects = (timestamp: number) => { const updateObjects = (timestamp: number) => {
if (!Simulations) return; if (!Simulations) return;
const simulationStep = Simulations[timestamp]; const timestampKey = timestamp.toString();
const simulationStep = Simulations[timestampKey];
if (simulationStep) { if (simulationStep) {
const updatedDrones = Object.values(simulationStep).map((drone) => ({ const updatedDrones = Object.values(simulationStep).map((drone) => ({
...drone, ...drone,
})); }));
// @ts-ignore
setDrones(updatedDrones); setDrones(updatedDrones);
// Обновление траектории для каждого дрона
setDroneTrajectories((prevTrajectories) => {
const newTrajectories = { ...prevTrajectories };
updatedDrones.forEach((drone) => {
if (!newTrajectories[drone.name]) {
newTrajectories[drone.name] = [];
}
newTrajectories[drone.name] = [...newTrajectories[drone.name], drone.position];
});
return newTrajectories;
});
} }
}; };
@ -231,7 +245,7 @@ const PlayerTsInstance: React.FC<IPlayerTsInstance> = ({
<BaseStationModel <BaseStationModel
key={baseStation.id} key={baseStation.id}
position={baseStation.position} position={baseStation.position}
// @ts-ignore // @ts-ignore
baseStationName={baseStation.name} baseStationName={baseStation.name}
/> />
))} ))}
@ -244,6 +258,15 @@ const PlayerTsInstance: React.FC<IPlayerTsInstance> = ({
droneName={drone.name} droneName={drone.name}
/> />
))} ))}
{Object.entries(droneTrajectories).map(([droneName, positions]) => (
<Line
key={droneName}
points={positions} // массив позиций для линии
color="red" // цвет линии
lineWidth={2} // ширина линии
dashed={false}
/>
))}
</Canvas> </Canvas>
</div> </div>
@ -262,7 +285,6 @@ const PlayerTsInstance: React.FC<IPlayerTsInstance> = ({
); );
}; };
// Модель карты // Модель карты
const MapModel = () => { const MapModel = () => {
const { scene } = useGLTF('/map/map.glb'); const { scene } = useGLTF('/map/map.glb');

View File

@ -1,6 +1,6 @@
"use client"; "use client";
import { Canvas } from '@react-three/fiber'; import { Canvas } from '@react-three/fiber';
import { OrbitControls, useGLTF, Line, Text } from '@react-three/drei'; import { OrbitControls, useGLTF, Line, Text, Box } from '@react-three/drei';
import { useState, useEffect, useRef } from 'react'; import { useState, useEffect, useRef } from 'react';
import { Drone, BaseStation } from './Models'; import { Drone, BaseStation } from './Models';
import { PlayCircleIcon } from '@heroicons/react/24/outline'; import { PlayCircleIcon } from '@heroicons/react/24/outline';
@ -260,6 +260,9 @@ const DroneModel = ({ position, droneName, onClick, isSelected }: { position: [n
<meshBasicMaterial color="red" wireframe /> <meshBasicMaterial color="red" wireframe />
</mesh> </mesh>
)} )}
<Box position={position}>
<meshBasicMaterial color="green" wireframe />
</Box>
</group> </group>
); );
}; };

View File

@ -21,7 +21,7 @@ const Simulations: React.FC = () => {
position: drone.position, position: drone.position,
freq: drone.frequency, freq: drone.frequency,
radius: drone.signalRadius, radius: drone.signalRadius,
endpoints: [[0, 5, 1], [10, 5, 1]], // TODO: статические значения endpoints: [drone.position, [7, 5, 2], [9, 5, 2], [10, 5, 1]], // TODO: статические значения
speed: 1 // TODO: можно изменить при необходимости speed: 1 // TODO: можно изменить при необходимости
})); }));