38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
import pybullet as p
|
||
|
||
|
||
class Pallet:
|
||
def __init__(
|
||
self, target=[1, 1, 0], size=[0.8, 1.2, 0.144], color=[0.6, 0.3, 0.1, 0.5]
|
||
):
|
||
self.size = size
|
||
self.position = [
|
||
(target[i] - self.size[i] * 0.5)
|
||
for i in range(len(target))
|
||
]
|
||
self.color = color
|
||
|
||
self.create_pallet()
|
||
|
||
def create_pallet(self):
|
||
half_size = [s * 0.5 for s in self.size]
|
||
|
||
# Создаем collision shape для паллеты
|
||
collision_shape = p.createCollisionShape(p.GEOM_BOX, halfExtents=half_size)
|
||
|
||
# Создаем визуальное отображение (shape) для паллеты
|
||
visual_shape = p.createVisualShape(
|
||
p.GEOM_BOX, halfExtents=half_size, rgbaColor=self.color
|
||
)
|
||
|
||
# Создаем объект паллеты в физическом мире
|
||
self.pallet_id = p.createMultiBody(
|
||
baseMass=0, # Масса 0, чтобы паллета не взаимодействовала с физикой
|
||
baseCollisionShapeIndex=collision_shape,
|
||
baseVisualShapeIndex=visual_shape,
|
||
basePosition=self.position,
|
||
)
|
||
|
||
# Устанавливаем позицию объекта паллеты в физическом мире
|
||
p.resetBasePositionAndOrientation(self.pallet_id, self.position, [0, 0, 0, 1])
|