-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for fuel textures (#342)
Signed-off-by: Luca Della Vedova <[email protected]>
- Loading branch information
1 parent
1426675
commit d346e75
Showing
3 changed files
with
40 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import requests | ||
import shutil | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
from urllib.parse import urlparse | ||
from xml.etree.ElementTree import ElementTree, Element, SubElement | ||
|
||
|
||
def copy_texture(texture_name, dest_path): | ||
texture_filename = f'{texture_name}.png' | ||
texture_path_dest = f'{dest_path}/{texture_filename}' | ||
# If the texture name is a URL fetch it | ||
result = urlparse(texture_name) | ||
texture_is_url = all([result.scheme, result.netloc, result.path]) | ||
if texture_is_url: | ||
# Update filename from the URL | ||
texture_filename = texture_name.split('/')[-1] | ||
texture_path_dest = f'{dest_path}/{texture_filename}' | ||
# Skip downloading if existing | ||
if not os.path.isfile(texture_path_dest): | ||
req = requests.get(texture_name) | ||
with open(texture_path_dest, 'wb') as f: | ||
f.write(req.content) | ||
else: | ||
texture_path_source = os.path.join( | ||
get_package_share_directory('rmf_building_map_tools'), | ||
f'textures/{texture_filename}') | ||
shutil.copyfile(texture_path_source, texture_path_dest) | ||
|
||
print(f' wrote {texture_path_dest}') | ||
return texture_filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters