from klampt import * from klampt.io import loader, resource from klampt.math import se3 from klampt.model.trajectory import Trajectory, RobotTrajectory from klampt.model.multipath import MultiPath from klampt.model import types from klampt import vis from klampt.vis.glcommon import GLMultiViewportProgram vis.init("PyQt5") from klampt.vis.backends.vis_gl import GLVisualizationPlugin from klampt.vis.backends.qtbackend import QtGLWindow import sys, os, time from PyQt5 import QtGui from PyQt5 import QtCore from PyQt5 import QtWidgets world_item_extensions = set(['.obj', '.rob', '.urdf', '.env']) robot_override_types = ['Config', 'Configs'] animation_types = ['Trajectory', 'LinearPath', 'MultiPath'] create_types = resource.visualEditTypes()[:-1] def save(obj, fn): if hasattr(obj, 'saveFile'): return obj.saveFile(fn) if hasattr(obj, 'save'): return obj.save(fn) type = loader.filenameToType(fn) return loader.save(obj, type, fn)
glClearColor(0.8, 0.8, 0.9, 0) # Default light source glLightfv(GL_LIGHT0, GL_POSITION, [0, -1, 2, 0]) glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1, 1]) glLightfv(GL_LIGHT0, GL_SPECULAR, [1, 1, 1, 1]) glEnable(GL_LIGHT0) glLightfv(GL_LIGHT1, GL_POSITION, [-1, 2, 1, 0]) glLightfv(GL_LIGHT1, GL_DIFFUSE, [0.5, 0.5, 0.5, 1]) glLightfv(GL_LIGHT1, GL_SPECULAR, [0.5, 0.5, 0.5, 1]) glEnable(GL_LIGHT1) do_snapshot() show_snapshot_matplotlib() else: vis.init() vis.setBackgroundColor(1, 0, 0) vis.show() vis.add("world", world) while vis.shown(): time.sleep(0.25) vis.lock() #vis.show(False) q0 = robot.getConfig() vmax = robot.getVelocityLimits() for i in range(len(q0)): q0[i] += random.uniform(-vmax[i], vmax[i]) * 0.1 robot.setConfig(q0) vis.unlock() show_snapshot_matplotlib(True)
from klampt import WorldModel, vis world = WorldModel() world.readFile("world.xml") vis.init("IPython") vis.add("world", world) vis.show() #string = vis.nativeWindow().page() #with open("vis.html", "w") as f: # f.write(string)
import sys import klampt from klampt import vis from klampt.robotsim import setRandomSeed from klampt.vis.glcommon import GLWidgetPlugin from klampt import RobotPoser from klampt.model import ik, coordinates, config, trajectory, collide from klampt.math import vectorops, so3, se3 from klampt.vis import GLSimulationPlugin, glinit import time import math #Can choose 'PyQt', 'PyQt5', 'PyQt4', or 'GLUT'. This will be passed to vis.init() BACKEND = None #BACKEND = 'GLUT' vis.init(BACKEND) #set this to True to test multi-threaded visualization, False to test single-threaded MULTITHREADED = vis.multithreaded() #set this to True to demonstrate the code for manually animating a path MANUAL_ANIMATION = False #set this to True to demonstrate the code for manually setting up editing widgets in a GLPluginInterface MANUAL_EDITING = False def basic_template(world): """Shows how to pop up a visualization window with a world""" #add the world to the visualizer vis.add("world", world) #adding a point