Drone model

This commit is contained in:
moxitech 2024-10-01 05:52:45 +07:00
parent 6225ef638d
commit dabd81ecfb
2 changed files with 53 additions and 14 deletions

View File

@ -1,32 +1,71 @@
// Drone.js
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
export class Drone {
constructor() {
this.drone = new THREE.Object3D();
// Создаем основное тело дрона
const bodyGeometry = new THREE.BoxGeometry(1, 0.3, 1);
const bodyMaterial = new THREE.MeshBasicMaterial({ color: 0x0077ff });
// Создаем основное тело дрона (цилиндрическая форма)
const bodyGeometry = new THREE.CylinderGeometry(0.4, 0.6, 1, 32);
const bodyMaterial = new THREE.MeshStandardMaterial({ color: 0x0077ff, metalness: 0.6, roughness: 0.4 });
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.rotation.z = Math.PI / 2; // Поворачиваем для более аэродинамической формы
this.drone.add(body);
// Добавляем четыре пропеллера
const propellerGeometry = new THREE.CylinderGeometry(0.1, 0.1, 0.02, 32);
const propellerMaterial = new THREE.MeshBasicMaterial({ color: 0x333333 });
const positions = [
[-0.5, 0.2, -0.5],
[-0.5, 0.2, 0.5],
[0.5, 0.2, -0.5],
[0.5, 0.2, 0.5],
// Добавляем 4 стойки шасси
const legGeometry = new THREE.CylinderGeometry(0.05, 0.05, 0.6, 16);
const legMaterial = new THREE.MeshBasicMaterial({ color: 0x444444 });
const legPositions = [
[-0.4, -0.6, -0.4],
[-0.4, -0.6, 0.4],
[0.4, -0.6, -0.4],
[0.4, -0.6, 0.4],
];
legPositions.forEach((position) => {
const leg = new THREE.Mesh(legGeometry, legMaterial);
leg.position.set(...position);
leg.rotation.x = Math.PI / 2;
this.drone.add(leg);
});
positions.forEach((position) => {
// Создаем пропеллеры
const propellerGeometry = new THREE.BoxGeometry(0.2, 0.02, 1.2);
const propellerMaterial = new THREE.MeshBasicMaterial({ color: 0x333333 });
const propellerPositions = [
[-0.6, 0.4, -0.6],
[-0.6, 0.4, 0.6],
[0.6, 0.4, -0.6],
[0.6, 0.4, 0.6],
];
this.propellers = [];
propellerPositions.forEach((position) => {
const propeller = new THREE.Mesh(propellerGeometry, propellerMaterial);
propeller.rotation.x = Math.PI / 2;
propeller.position.set(...position);
propeller.rotation.y = Math.PI / 2;
this.propellers.push(propeller);
this.drone.add(propeller);
});
// Загрузка более детализированной 3D модели (опционально)
// const loader = new GLTFLoader();
// loader.load(
// './path_to_your_drone_model.glb',
// (gltf) => {
// this.drone.add(gltf.scene);
// },
// undefined,
// (error) => {
// console.error('Ошибка при загрузке модели:', error);
// }
// );
}
// Метод для вращения пропеллеров
rotatePropellers(speed) {
this.propellers.forEach((propeller) => {
propeller.rotation.z += speed;
});
}
// Метод для установки позиции дрона