Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import time
import numpy as np
import meshcat
import meshcat.geometry as g
verts = np.random.random((3, 100000)).astype(np.float32)
vis = meshcat.Visualizer().open()
vis.set_object(g.Points(
g.PointsGeometry(verts, color=verts),
g.PointsMaterial()
))
vis.close()
def initViewer(self, viewer=None, open=False, loadModel=False):
"""Start a new MeshCat server and client.
Note: the server can also be started separately using the "meshcat-server" command in a terminal:
this enables the server to remain active after the current script ends.
"""
import meshcat
self.viewer = meshcat.Visualizer() if viewer is None else viewer
if open:
self.viewer.open()
if loadModel:
self.loadViewerModel()
def _get_native_visualizer(viz):
# Resolve `viz` to a native `meshcat.Visualizer` instance. If `viz` is
# a pydrake `MeshcatVisualizer`, return the native visualizer.
if isinstance(viz, meshcat.Visualizer):
return viz
elif isinstance(viz, MeshcatVisualizer):
return viz.vis
else:
raise ValueError(
"Type {} is not {{meshcat.Visualizer, {}}}".format(
type(viz).__name__, MeshcatVisualizer.__name__))
from __future__ import absolute_import, division, print_function
import math
import time
import meshcat
vis = meshcat.Visualizer().open()
box = meshcat.geometry.Box([0.5, 0.5, 0.5])
vis.set_object(box)
draw_times = []
for i in range(200):
theta = (i + 1) / 100 * 2 * math.pi
now = time.time()
vis.set_transform(meshcat.transformations.rotation_matrix(theta, [0, 0, 1]))
draw_times.append(time.time() - now)
time.sleep(0.01)
print(sum(draw_times) / len(draw_times))
parser.add_argument('-c', '--cfree', action='store_true', help='Disables collisions when planning')
parser.add_argument('-v', '--visualizer', action='store_true', help='Use the drake visualizer')
parser.add_argument('-s', '--simulate', action='store_true', help='Simulates the system')
args = parser.parse_args()
problem_fn_from_name = {fn.__name__: fn for fn in PROBLEMS}
if args.problem not in problem_fn_from_name:
raise ValueError(args.problem)
print('Problem:', args.problem)
problem_fn = problem_fn_from_name[args.problem]
meshcat_vis = None
if not args.visualizer:
import meshcat
# Important that variable is saved
meshcat_vis = meshcat.Visualizer() # vis.set_object
# http://127.0.0.1:7000/static/
task, diagram, state_machine = problem_fn(time_step=time_step, use_meshcat=not args.visualizer,
use_controllers=args.simulate)
print(task)
##################################################
plant = task.mbp
#dump_plant(plant)
#dump_models(plant)
diagram_context = task.diagram_context
RenderSystemWithGraphviz(diagram) # Useful for getting port names
context = diagram.GetMutableSubsystemContext(plant, diagram_context)
task.set_initial()
def __init__(self,
zmq_url="tcp://127.0.0.1:6000",
visualize=False):
print("Opening meshcat vis... will hang if no server"
"\tis running.")
self.vis = None
if visualize:
self.vis = meshcat.Visualizer(zmq_url=zmq_url)
self.vis["perception"].delete()
self.vis["perception/tabletopsegmenter"].delete()
from mesh_creation import create_cut_cylinder
from pydrake.all import (
AutoDiffXd,
MathematicalProgram,
SolutionResult,
RollPitchYaw,
RotationMatrix)
import pydrake.math as drake_math
import pydrake.forwarddiff as forwarddiff
import meshcat
import meshcat.geometry as meshcat_g
import meshcat.transformations as meshcat_tf
vis = meshcat.Visualizer(zmq_url="tcp://127.0.0.1:6000")
vis["perception"]["fit"].delete()
points = np.load("cloud.npy")
print("Loaded %d points from cloud.npy" % points.shape[0])
colors = points.copy()
colors -= np.min(colors, axis=0)
colors /= np.max(colors, axis=0)
vis["perception"]["fit"]["points"].set_object(
meshcat_g.PointCloud(position=points.T,
color=colors.T,
size=0.001))
def vectorized_ad_helper(function, x):
x_ad = np.empty(x.shape, dtype=AutoDiffXd)
for i in range(x.size):