Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for fuel textures #342

Merged
merged 6 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions rmf_building_map_tools/building_map/floor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import math
import os
import shutil

import shapely.geometry
import shapely.ops

from xml.etree.ElementTree import SubElement
from ament_index_python.packages import get_package_share_directory

from .material_utils import copy_texture
from .param_value import ParamValue

triangulation_debugging = False
Expand Down Expand Up @@ -292,6 +291,8 @@ def generate(
if 'texture_name' in self.params:
texture_name = self.params['texture_name'].value

texture_filename = copy_texture(texture_name, meshes_path)

mtl_path = f'{model_path}/meshes/floor_{floor_cnt}.mtl'
with open(mtl_path, 'w') as f:
f.write('# The Great Editor v0.0.1\n')
Expand All @@ -303,13 +304,6 @@ def generate(
f.write('Ni 1.0\n') # no idea what this is
f.write('d 1.0\n') # alpha (maybe?)
f.write('illum 2\n') # illumination model (enum)
f.write(f'map_Kd {texture_name}.png\n')
f.write(f'map_Kd {texture_filename}\n')

print(f' wrote {mtl_path}')

texture_path_source = os.path.join(
get_package_share_directory('rmf_building_map_tools'),
f'textures/{texture_name}.png')
texture_path_dest = f'{model_path}/meshes/{texture_name}.png'
shutil.copyfile(texture_path_source, texture_path_dest)
print(f' wrote {texture_path_dest}')
32 changes: 32 additions & 0 deletions rmf_building_map_tools/building_map/material_utils.py
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
14 changes: 4 additions & 10 deletions rmf_building_map_tools/building_map/wall.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import math
import os
import shutil

import numpy as np

from xml.etree.ElementTree import SubElement
from ament_index_python.packages import get_package_share_directory

from .edge import Edge
from .material_utils import copy_texture
from .param_value import ParamValue


Expand Down Expand Up @@ -187,6 +186,8 @@ def generate_wall_visual_mesh(self, model_name, model_path):
f.write(f'f {w*8+2}/1/1 {w*8+6}/1/1 {w*8+4}/1/1\n')
f.write(f'f {w*8+2}/1/1 {w*8+8}/1/1 {w*8+6}/1/1\n')

texture_filename = copy_texture(self.texture_name, meshes_path)

mtl_path = f'{meshes_path}/wall_{self.wall_cnt}.mtl'
print(f' generating {mtl_path}')
with open(mtl_path, 'w') as f:
Expand All @@ -199,14 +200,7 @@ def generate_wall_visual_mesh(self, model_name, model_path):
f.write('Ni 1.0\n') # no idea what this is
f.write(f'd {self.alpha}\n') # alpha
f.write('illum 2\n') # illumination model (enum)
f.write(f'map_Kd {self.texture_name}.png\n')

print(f' copying wall textures into {meshes_path}')
texture_path_source = os.path.join(
get_package_share_directory('rmf_building_map_tools'),
f'textures/{self.texture_name}.png')
texture_path_dest = f'{meshes_path}/{self.texture_name}.png'
shutil.copyfile(texture_path_source, texture_path_dest)
f.write(f'map_Kd {texture_filename}\n')

def generate(
self,
Expand Down