Source code for concepts.simulator.cad_asset_utils.alphabet_arial
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : alphabet_arial.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 08/1/2024
#
# This file is part of Project Concepts.
# Distributed under terms of the MIT license.
import os.path as osp
from concepts.simulator.urdf_utils.obj2urdf import ObjectUrdfBuilder
from concepts.simulator.cad_asset_utils.assets_base import CADAssetCollection
[docs]
class AlphabetArialCollection(CADAssetCollection):
"""A collection of object URDFs for the Arial alphabet."""
[docs]
def __init__(self):
self.root = self.get_assets_path('objects', 'alphabet_arial')
self.uppercase_root = self.get_assets_path('objects', 'alphabet_arial', 'upper')
self.lowercase_root = self.get_assets_path('objects', 'alphabet_arial', 'lower')
self.available_models = dict()
for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
self.available_models[letter] = osp.join(self.uppercase_root, f'{letter}.obj')
for letter in 'abcdefghijklmnopqrstuvwxyz':
self.available_models[letter] = osp.join(self.lowercase_root, f'{letter}.obj')
[docs]
def build_urdf(self, object_path) -> None:
object_dir = osp.dirname(object_path)
object_builder = ObjectUrdfBuilder(object_dir)
object_builder.build_urdf(object_path, force_overwrite=True, decompose_concave=True, force_decompose=False, center='mass')
[docs]
def assert_build_urdf(self, identifier) -> str:
assert identifier in self.available_models, f'Unknown identifier: {identifier}'
obj_path = self.available_models[identifier]
urdf_path = obj_path + '.urdf'
if not osp.isfile(urdf_path):
self.build_urdf(obj_path)
return urdf_path
[docs]
def get_urdf(self, identifier: str) -> str:
return self.assert_build_urdf(identifier)