-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef1822e
commit 01d64d6
Showing
9 changed files
with
208 additions
and
109 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
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
Empty file.
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,61 @@ | ||
from lxml import etree | ||
from lxml import etree as ET | ||
|
||
|
||
class GazeboSimInterface: | ||
def __init__(self): | ||
pass | ||
|
||
def check_world(self, template_world_path): | ||
"""Load world and asserts if basic tags are there.""" | ||
parser = ET.XMLParser(recover=True, remove_blank_text=True) | ||
|
||
tree = etree.parse(template_world_path, parser=parser) | ||
|
||
root = tree.getroot() | ||
world_xml = root.find("world") | ||
return world_xml is not None | ||
|
||
def add_model_to_xml( | ||
self, model_name, pose_x, pose_y, pose_z, pose_roll, pose_pitch, pose_yaw, uri | ||
): | ||
# Create the new <include> element | ||
include = ET.Element("include") | ||
|
||
name = ET.SubElement(include, "name") | ||
name.text = model_name | ||
|
||
pose = ET.SubElement(include, "pose") | ||
pose.text = f"{pose_x} {pose_y} {pose_z} {pose_roll} {pose_pitch} {pose_yaw}" | ||
|
||
uri_element = ET.SubElement(include, "uri") | ||
uri_element.text = uri | ||
|
||
return include | ||
|
||
def save_xml(self, xml_file, template_world_path, include_tags): | ||
parser = ET.XMLParser(recover=True, remove_blank_text=True) | ||
|
||
tree = etree.parse(template_world_path, parser=parser) | ||
|
||
root = tree.getroot() | ||
|
||
world_xml = root.find("world") | ||
|
||
for include in include_tags: | ||
world_xml.append(include) | ||
|
||
# Indent the XML with two spaces | ||
tree_str = ET.tostring( | ||
root, | ||
pretty_print=True, | ||
encoding="utf-8", | ||
xml_declaration=True, | ||
with_tail=True, | ||
) | ||
|
||
# parsed_tree = ET.fromstring(tree_str) | ||
|
||
# Save the formatted XML to the file | ||
with open(xml_file, "wb") as file: | ||
file.write(tree_str) |
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,62 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import objaverse | ||
import trimesh | ||
from obj2mjcf.cli import Args, process_obj | ||
|
||
|
||
class MujocoSimInterface: | ||
def __init__(self): | ||
pass | ||
|
||
def check_world(self, world): | ||
pass | ||
|
||
def generate_world(self): | ||
world = {"World": "None"} | ||
template_world_path = os.path.join(cache.worlds_path, "empty.sdf") | ||
|
||
def find_entry_by_name(self, name, full_list): | ||
for entry in full_list: | ||
if entry["name"] == name: | ||
return entry | ||
return None | ||
|
||
def add_models(self, placed_models, models): | ||
full_placed_models = [] | ||
|
||
for model in placed_models: | ||
if model_entry := self.find_entry_by_name(model["Model"], models): | ||
model_entry.update(model) | ||
full_placed_models.append(model_entry) | ||
print(model_entry) | ||
print(full_placed_models) | ||
|
||
# model_db_interface.load_models(full_placed_models) | ||
objects = objaverse.load_objects( | ||
uids=[entry["uuid"] for entry in full_placed_models] | ||
) | ||
obj_locs = list(objects.values()) | ||
|
||
print(obj_locs) | ||
|
||
for i in range(len(full_placed_models)): | ||
full_placed_models[i]["model_loc"] = obj_locs[i] | ||
|
||
mesh = trimesh.load(obj_locs[i]) | ||
# trimesh.exchange.obj.export_obj(mesh) | ||
obj, data = trimesh.exchange.export.export_obj( | ||
mesh, include_texture=True, return_texture=True | ||
) | ||
|
||
obj_path = f"./converted/{full_placed_models[i]['uuid']}.obj" | ||
with open(obj_path, "w") as f: | ||
f.write(obj) | ||
# save the MTL and images | ||
for k, v in data.items(): | ||
with open(os.path.join("./converted/", k), "wb") as f: | ||
f.write(v) | ||
args = Args("./", save_mjcf=True, compile_model=True, overwrite=True) | ||
|
||
process_obj(Path(obj_path), args) |
Oops, something went wrong.