packages = ['numpy'] [[fetch]] from = './viewer3d/' files = ['viewer3d.py'] [[fetch]] from = './scripts/sandbox3d/' files = ['smc_example.py', 'smc.py', 'hedac.py', 'hedac_example.py', 'common.py', 'ui.py']

(click on the green button to run the code)












from viewer3d import Viewer3D, configs from js import document # The configuration of each tab config = { 'SMC-tab': { 'scripts': { 'main': 'smc.py', 'user': 'smc_example.py', 'ui': 'ui.py', 'common': 'common.py', }, 'texts': { 'help': 'If you need context about how this code is used, see this script and this one', 'legend': '', }, }, 'HEDAC-tab': { 'scripts': { 'main': 'hedac.py', 'user': 'hedac_example.py', 'ui': 'ui.py', 'common': 'common.py', }, 'texts': { 'help': 'If you need context about how this code is used, see this script and this one', 'legend': '', }, } } # UI-related variables output = document.getElementById('output') help = document.getElementById('help') legend = document.getElementById('legend') # Create the Viewer3D object viewer3D = Viewer3D(document.getElementById('viewer3d')) # Load the scene and retrieve the robot viewer3D.loadScene('/scenes/panda.xml') robot = viewer3D.createRobot('panda', configs.Panda.new()) # Disable all robot controls (since the robot is controlled by our code) # viewer3D.controlsEnabled = False viewer3D.jointsManipulationEnabled = False viewer3D.endEffectorManipulationEnabled = False viewer3D.robotToolsEnabled = False def onTabClicked(event): switch_to_tab(event.target.id) # Initialise all the tabs for tab, entry in config.items(): scripts = entry['scripts'] for id, filename in scripts.items(): with open(filename, 'r') as f: code = f.read() scripts[id] = { 'filename': filename, 'code': code, } editor = document.getElementById(tab + '-repl') editor.textContent = scripts['user']['code'] button = document.getElementById(tab) button.onclick = onTabClicked def switch_to_tab(id): output.innerText = '' entry = config[id] texts = entry['texts'] help.innerHTML = texts['help'] legend.innerHTML = texts['legend'] scripts = entry['scripts'] exec(scripts['main']['code'], globals()) exec(scripts['ui']['code'], globals()) if 'common' in scripts: exec(scripts['common']['code'], globals()) editor = document.getElementById(id + '-repl') try: user_code = editor.getPySrc() except AttributeError: user_code = editor.textContent exec(user_code, globals()) reset() terminal = document.getElementsByClassName('py-terminal-docked') if terminal.length == 1: terminal[0].remove() switch_to_tab('SMC-tab')