Package: panda3d-viewer
panda3d_viewerA simple 3D geometry viewer based onPanda3Dgame engine.InstallUsing pippipinstallpanda3d_viewerFrom source codegitclonehttps://github.com/ikalevatykh/panda3d_viewer.gitcdpanda3d_viewer
pythonsetup.pyinstallExamplesA simple scene in a GUI windowfrompanda3d_viewerimportViewer,ViewerConfigconfig=ViewerConfig()config.set_window_size(320,240)config.enable_antialiasing(True,multisamples=4)withViewer(window_type='onscreen',window_title='example',config=config)asviewer:viewer.append_group('root')viewer.append_box('root','box_node',size=(1,1,1))viewer.append_sphere('root','sphere_node',radius=0.5)viewer.set_material('root','box_node',color_rgba=(0.7,0.1,0.1,1))viewer.set_material('root','sphere_node',color_rgba=(0.1,0.7,0.1,1))viewer.move_nodes('root',{'box_node':((0,0,0.5),(1,0,0,0)),'sphere_node':((0,0,1.5),(1,0,0,0))})viewer.reset_camera(pos=(4,4,2),look_at=(0,0,1))viewer.save_screenshot(filename='box_and_sphere.png')Render an animation offscreenfrommathimportcos,sin,piimportimageio# install imageio: pip install imageiofrompanda3d_viewerimportViewer,ViewerConfigconfig=ViewerConfig()config.set_window_size(320,240)config.enable_antialiasing(True,multisamples=4)config.enable_shadow(True)config.show_axes(False)config.show_grid(False)config.show_floor(True)viewer=Viewer(window_type='offscreen',config=config)viewer.append_group('root')viewer.append_sphere('root','sphere_node',radius=0.5)viewer.set_material('root','sphere_node',color_rgba=(0.1,0.7,0.1,1))withimageio.get_writer('sphere_anim.gif',mode='I')aswriter:foriinrange(50):angle=2*pi*i/50x=4*cos(angle)y=4*sin(angle)z=0.5+0.5*abs(sin(angle))viewer.move_nodes('root',{'sphere_node':((0,0,z),(1,0,0,0))})viewer.reset_camera(pos=(x,y,2),look_at=(0,0,1))image_rgb=viewer.get_screenshot(requested_format='RGB')writer.append_data(image_rgb)Render a point cloudimportnumpyasnpimporttimefrompanda3d_viewerimportViewer,ViewerConfigwithViewer(show_grid=False)asviewer:viewer.reset_camera((10,10,15),look_at=(0,0,0))viewer.append_group('root')viewer.append_cloud('root','cloud',thickness=4)whileTrue:vertices=np.random.randn(300000,3).astype(np.float32)colors=np.ones((300000,4),np.float32)colors[:,:3]=np.clip(np.abs(vertices),0,3)/3viewer.set_cloud_data('root','cloud',vertices,colors)time.sleep(0.03)Robotic examplesUsing with PinocchioPinocchiois a library for rigid multi-body dynamics computation. To see how to use this package with Pinocchio seeexample 1,example 2.Visualize the point cloud from a RealSense cameraimportnumpyasnpimportpyrealsense2asrsfrompanda3d_viewerimportViewer,ViewerConfigconfig=rs.config()config.enable_stream(rs.stream.depth,640,480,rs.format.z16,30)config.enable_stream(rs.stream.color,640,480,rs.format.bgr8,30)pipeline=rs.pipeline()pipeline.start(config)pc=rs.pointcloud()camera_frame=(0,0,0.2),(0.7071,-0.7071,0,0)withViewer(window_title='RealSense')asviewer:viewer.append_group('root',scale=2)viewer.append_cloud('root','camera',thickness=4,frame=camera_frame)whileTrue:frames=pipeline.wait_for_frames()color=frames.get_color_frame()depth=frames.get_depth_frame()ifcoloranddepth:pc.map_to(color)points=pc.calculate(depth)vertices=np.asarray(points.get_vertices())texture_coords=np.asanyarray(points.get_texture_coordinates())texture_image=np.asanyarray(color.get_data())viewer.set_cloud_data('root','camera',vertices=vertices,texture_coords=texture_coords,texture_image=texture_image)APIViewerThis package containsViewer, a thin wrapper on top ofPanda3D ShowBase, an application framework responsible for opening a graphical display, setting up input devices and creating the scene graph.Viewerconstructor takeswindow_typeparameter wich should be one of'onscreen','offscreen'. When selected'onscreen'the viewer open a GUI window. When selected'offscreen'the viewer render to an offscreen buffer.Optionalconfigparameter allows manage the viewer appearance. Configuration provided byViewerConfigclass, which contains methods:set_window_sizeset window size (default: 800x600)set_window_fixeddisable window resizing (default: on)enable_antialiasingturn antialiasing on or off and specify number of MSAA multisamples: 2,4,8,16 (default: off)enable_lightsturn lighting on or off (default: on)enable_shadowturn shadows rendering on or off (default: off)enable_hdrturn HDR effect on or off (default: off)enable_fogturn fog rendering on or off (default: off)show_axesturn the axes rendering on or off (default: on)show_gridturn the grid rendering on or off (default: on)show_floorturn the floor plane rendering on or off (default: off)To stop the viewer usestopmethod. Usejoinmethod to wait until a user close the window.Managing 3D sceneAll scene geometries organized in named groups. Each group contains arbitrary number of nodes. To manage the groups useappend_groupandremove_group. To hide or show all geometries inside a group useshow_group.To append a mesh node to a group useappend_mesh, to append a primitive geometry node useappend_capsule,append_cylinder,append_box,append_plane,append_sphere. To modify material of a node useset_material.To specify nodes position in the space usemove_nodesfunction. It takes a dictionary withnode_name-position, quaternionpairs, so you can specify the position of all/any nodes in a group simultaneously.Render to file or memory bufferTo capture an image and save it on the disk usesave_screenshot. Specify path to the image file with extention in afilenameparameter. If thefilenameis ommited it will be generated automatically based on the current date time.To capture an image to a memory buffer useget_screenshot. Specify the color channels order inrequested_formatparameter. Default format is BGRA, allow any combinations of R,G,B,A channels. The function returns an image as a numpy array.Scene appearanceTo move the camera usereset_cameramethod which takes the desired camera position and target point.Viewer provide several methods to manage visual appearance:set_background_colorchange background colorenable_lightsturn lighting on or offenable_shadowturn shadows rendering on or offenable_hdrturn HDR effect on or offenable_fogturn fog rendering on or offshow_axesturn the axes rendering on or offshow_gridturn the grid rendering on or offshow_floorturn the floor plane rendering on or offWindow controlKeyboard shortcuts:Show help:F1,hQuit window:Escape,qScreenshot:SpaceToggle axes:aToggle HDR:dToggle grid:gToggle fps meter:fToggle lighting:lToggle fog:oToggle plane:pReset camera:rToggle shadows:sToggle texture:tToggle wireframe:wMouse control:Move:LMBScale:RMB,Ctrl+LMBRotate:LMB+RMB,Alt+LMBTilt:Alt+Ctrl+LMBLicensepanda3d_viewer is licensed under the MIT License - see the LICENSE file for details