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

UUID caching #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 12 additions & 2 deletions src/meshcat/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def lower(self, object_data):


class Object(SceneElement):
sent_geom_uuids = set()
sent_material_uuids = set()

def __init__(self, geometry, material=MeshPhongMaterial()):
super(Object, self).__init__()
self.geometry = geometry
Expand All @@ -289,8 +292,15 @@ def lower(self):
u"matrix": list(self.geometry.intrinsic_transform().flatten())
}
}
self.geometry.lower_in_object(data)
self.material.lower_in_object(data)
# If this geometry or material has been previously sent,
# then we don't need to populate these fields; the server
# will load the matching geometry or material from its cache.
if self.geometry.uuid not in self.sent_geom_uuids:
self.sent_geom_uuids.add(self.geometry.uuid)
self.geometry.lower_in_object(data)
if self.material.uuid not in self.sent_material_uuids:
self.sent_material_uuids.add(self.material.uuid)
self.material.lower_in_object(data)
return data


Expand Down
34 changes: 34 additions & 0 deletions src/meshcat/tests/test_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,40 @@ def runTest(self):
v.set_object(g.TriangularMeshGeometry(vertices, faces, colors), g.MeshLambertMaterial(vertexColors=True, wireframe=True))


class TestUUIDCloning(VisualizerTest):
def runTest(self):
"""
Test that geometry with identical UUIDs are handled correctly.
"""
v = self.vis["triangular_mesh"]
v.set_transform(tf.rotation_matrix(np.pi/2, [0., 0, 1]))
vertices = np.array([
[0, 0, 0],
[1, 0, 0],
[1, 0, 1],
[0, 0, 1]
])
faces = np.array([
[0, 1, 2],
[3, 0, 2]
])
geom = g.TriangularMeshGeometry(vertices, faces)
mat = g.MeshLambertMaterial(color=0xeedd22, wireframe=True)
geom.uuid = 1234
mat.uuid = 5678
v.set_object(geom, mat)

# This should be drawn as a duplicate of the first geometry
# at and offset; if nothing appears, or the material is different,
# the UUID lookup did not succeed.
geom_2 = g.TriangularMeshGeometry(np.empty((0, 3)), np.empty((0, 3)))
mat_2 = g.MeshLambertMaterial(color=0x000000, wireframe=False)
geom_2.uuid = 1234
mat_2.uuid = 5678
v2 = v["duplicate"]
v2.set_transform(tf.translation_matrix([2., 0., 0.]))
v2.set_object(geom_2, mat_2)

class TestOrthographicCamera(VisualizerTest):
def runTest(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/meshcat/viewer