def loadScene(renderGraph, file=None): '''Load or create our sceneGraph''' scene = renderGraph.add(dg.SceneGraph('DoF_Scene', file)) # Lights scene.ambientLight = np.array([1, 1, 1], np.float32) * 0.2 scene.lights.append( dgl.PointLight(intensity=np.array([0, 1, 1], np.float32), position=np.array([2, 3, 4], np.float32))) scene.lights.append( dgl.DirectionLight(intensity=np.array([1, 0, 1], np.float32), direction=np.array([-1, 0.2, 1], np.float32))) # This guy has mtl and textures cube = scene.add( dgs.PolySurface('cube', scene, file='%s/TexturedCube.obj' % MODELDIR)) cube.setScale(.2, .2, .2) cube.setTranslate(-0.1, 0., -2.) cube.setRotate(25., 25. + 0 * 90, 23.) # This guy has mtl and textures sphere = scene.add( dgs.PolySurface('sphere', scene, file='%s/TexturedSphere.obj' % MODELDIR)) sphere.setScale(.2, .2, .2) sphere.setTranslate(-.7, 0., -1.8) sphere.setRotate(25., 25. + 0 * 90, 23.) # This will use default material teapot = scene.add( dgs.PolySurface('teapot', scene, file='%s/teapot.obj' % MODELDIR)) teapot.setScale(.4, .4, .4) teapot.setTranslate(.5, -.2, -1.5) teapot.setRotate(5., 0., 0.) teapot.material.diffuseColor = np.array([1.0, 1.0, 0.8]) * 0.5 teapot.material.specularColor = np.array([1.0, 0.8, 0.7]) * 0.5 teapot.material.glossiness = 100 # Tick camera = scene.add(dgc.Camera('scene', scene)) camera.setResolution((renderGraph.width, renderGraph.height)) camera.setTranslate(0., 0., 0.) camera.setFOV(50.) # Final renderGraph.frameBuffer.connectInput(camera) return True # Initialization Successful
def loadScene(renderStack, file=None, cross=False): '''Load or create our sceneGraph''' scene = dg.SceneGraph(file) stereoCam = dgc.StereoCamera('front', scene) stereoCam.setResolution((renderStack.width/2, renderStack.height)) stereoCam.setTranslate(0.,-.06,0.) stereoCam.setRotate(20.,0.,0.) stereoCam.setFOV(50.) stereoCam.IPD = .062 crosses = [ #np.array((.031,.0,-10.)), #np.array((-.031,.0,-10.)), np.array((-.2,-.2,-10.)), np.array((-.2,.0,-10.)), np.array((-.2,.2,-10.)), np.array((.0,-.2,-10.)), np.array((.0,.0,-10.)), np.array((.0,.2,-10.)), np.array((.2,-.2,-10.)), np.array((.2,.0,-10.)), np.array((.2,.2,-10.)), ] for idx, position in enumerate(crosses): cross = dgs.PolySurface('cross%s'%idx, scene, file = '%s/cross.obj'%MODELDIR) cross.setScale(.01,.01,.01) cross.translate = position renderStack.objects[cross.name] = cross print(1,(idx/3.)/3.+1/3.,(idx%3)/3.+1/3.) material = dgm.Material('material%s'%idx,ambient=(1,(idx/3.)/3.+1/3.,(idx%3)/3.+1/3.), amb_coeff=.5) #material = dgm.Lambert('material%s'%idx,ambient=(1,0,0), amb_coeff=.5, diffuse=(1,1,1), diff_coeff=1) cross.setMaterial(material) renderStack.cameras = [stereoCam] renderStack.append(stereoCam) return True
def loadScene(renderStacks, file=None): '''Load or create our sceneGraph''' scene = dg.SceneGraph(file) cam = dgc.StereoCamera('cam', scene) cam.right.setResolution((renderStacks[0].width, renderStacks[0].height)) cam.left.setResolution((renderStacks[1].width, renderStacks[1].height)) cam.setTranslate(0., 0., 0.) cam.setFOV(50.) for rs in renderStacks: rs.cameras.append(cam) teapot = dgs.PolySurface('teapot', scene, file='%s/teapot.obj' % MODELDIR) teapot.setScale(.1, .1, .1) teapot.setTranslate(.0, -.05, -2.) teapot.setRotate(5., 0., 0.) for rs in renderStacks: rs.objects['teapot'] = teapot material1 = dgm.Test('material1', ambient=(1, 0, 0), amb_coeff=0.2, diffuse=(1, 1, 1), diff_coeff=1) teapot.setMaterial(material1) #for obj in renderStack.objects.values(): # obj.setMaterial(material1) renderStacks[0].append(cam.right) #warp = dgm.warp.Lookup('lookup1',lutFile='%s/warp_0020.npy'%MODELDIR) #renderStacks[0].append(warp) renderStacks[1].append(cam.left) #warp = dgm.warp.Lookup('lookup1',lutFile='%s/warp_0000.npy'%MODELDIR) #renderStacks[1].append(warp) return scene
def loadScene(renderGraph, file=None): '''Load or create our sceneGraph''' scene = renderGraph.add(dg.SceneGraph('DoF_Scene', file)) # Lights scene.ambientLight = np.array([1, 1, 1], np.float32) * 0.2 scene.lights.append( dgl.PointLight(intensity=np.array([1, 1, 1], np.float32) * 0.7, position=np.array([2, 3, 4], np.float32))) scene.lights.append( dgl.DirectionLight(intensity=np.array([1, 1, 1], np.float32) * 0.7, direction=np.array([-1, 0.2, 1], np.float32))) # This guy has mtl and textures cube = scene.add( dgs.PolySurface('alien', scene, file='%s/alien/alien.obj' % MODELDIR)) #cube = scene.add(dgs.PolySurface('alien', scene, file = '/playpen/git/PerceptualHMD/cad/alien.obj')) cube.setScale(0.8, 0.8, 0.8) cube.setTranslate(0, -0.5, -2) cube.setRotate(0, 0, 0) # Tick camera = scene.add(dgc.Camera('scene', scene)) camera.setResolution((renderGraph.width, renderGraph.height)) camera.setTranslate(0., 0., 0.) camera.setFOV(50.) # Final renderGraph.frameBuffer.connectInput(camera) return True # Initialization Successful
def loadScene(renderGraph): '''Load or create our sceneGraph''' scene = dg.SceneGraph('Test0_SG') cam = scene.add(dgc.Camera('cam', scene)) cam.setResolution((renderGraph.width, renderGraph.height)) cam.setTranslate(0., 0., 0.) cam.setFOV(50.) #teapot = scene.add(dgs.PolySurface('teapot', scene, file = '%s/teapot.obj'%MODELDIR)) teapot = scene.add( dgs.PolySurface('teapot', scene, file='%s/octoAlien.obj' % MODELDIR)) teapot.setScale(.4, .4, .4) teapot.setTranslate(0., -.20, -1.) teapot.setRotate(0., 0., 0.) # Materials material1 = scene.add(dgm.Material('material1')) material1.diffuseColor *= 0.4 for obj in scene.shapes: scene[obj].setMaterial(material1) # Lights scene.ambientLight = np.array([1, 1, 1], np.float32) * 0.2 scene.lights.append(dgl.PointLight(intensity=(0, 1, 1), position=(2, 3, 4))) scene.lights.append( dgl.DirectionLight(intensity=(1, 0, 1), direction=(-1, 0.5, 0.1))) # Animate scene.animateFunc = animateScene # Render renderGraph.frameBuffer.connectInput(cam) scene.add(renderGraph) return scene
def loadScene(renderGraph): '''Load or create our sceneGraph''' scene = dg.SceneGraph('Test3_SG') cam = scene.add(dgc.StereoCamera('cam', scene)) cam.setResolution((renderGraph.width, renderGraph.height)) cam.setTranslate(0.,0.,0.) cam.setFOV(50.) teapot = scene.add(dgs.PolySurface('teapot', scene, file = '%s/teapot.obj'%MODELDIR)) teapot.setScale(.35,.35,.35) teapot.setTranslate(-.02,.02,-2.) teapot.setRotate(5.,-15.,0.) material1 = scene.add(dgm.Material('material1')) for obj in scene.shapes: scene[obj].setMaterial(material1) scene.ambientLight = np.array([1,1,1], np.float32) * 0.2 scene.lights.append(dgl.PointLight(intensity = (0,1,1), position = (2,3,4))) scene.lights.append(dgl.DirectionLight(intensity = (1,0,1), direction = (-1,0.5,0.1))) renderGraph.frameBuffer.connectInput(cam.left, posWidth=0, posHeight=0, width=.5, height=1) renderGraph.frameBuffer.connectInput(cam.right, posWidth=.5, posHeight=0, width=.5, height=1) scene.add(renderGraph) #warp = dgm.warp.Lookup('lookup1',lutFile='%s/warp_0020.npy'%MODELDIR) #renderStack.append(warp) return scene
def loadScene(renderStack,file=None): '''Load or create our sceneGraph''' scene = dg.SceneGraph(file) cam = dgc.Camera('cam', scene) cam.setResolution((renderStack.width, renderStack.height)) cam.setTranslate(0.,0.,0.) cam.setFOV(50.) renderStack.cameras.append(cam) teapot = dgs.PolySurface('teapot', scene, file = '%s/teapot.obj'%MODELDIR) teapot.setScale(.4,.4,.4) teapot.setTranslate(-.02,.02,-2.) teapot.setRotate(5.,-15.,0.) renderStack.objects['teapot'] = teapot material1 = dgm.Test('material1',ambient=(1,0,0), amb_coeff=0.2, diffuse=(1,1,1), diff_coeff=1) for obj in renderStack.objects.values(): obj.setMaterial(material1) renderStack.append(cam) warp = dgm.warp.Lookup('lookup1',lutFile='%s/warp_0000.npy'%MODELDIR) renderStack.append(warp) return scene
"px_size_mm": 0.09766, # px size of the display in mm "distance_cm": 20, # distance from the viewer in cm, #"is_hmd": False, #"warp_path": 'data/calibration/newRight/', }, ] def loadScene(renderStack,file=None): '''Load or create our sceneGraph''' scene = dg.SceneGraph(file) cam = dgc.Camera('cam', scene) cam.setResolution((renderStack.width, renderStack.height)) cam.setTranslate(0.,0.,0.) cam.setFOV(50.) rs.cameras.append(cam) teapot = dgs.PolySurface('teapot', scene, file = '%s/teapot.obj'%MODELDIR) teapot.setScale(.1,.1,.1) teapot.setTranslate(.0,-.05,-2.) teapot.setRotate(5.,0.,0.) for rs in renderStacks: rs.objects['teapot'] = teapot material1 = dgm.Test('material1',ambient=(1,0,0), amb_coeff=0.2, diffuse=(1,1,1), diff_coeff=1) teapot.setMaterial(material1) #for obj in renderStack.objects.itervalues(): # obj.setMaterial(material1) renderStacks[0].append(cam.right) #warp = dgm.warp.Lookup('lookup1',lutFile='%s/warp_0020.npy'%MODELDIR) #renderStacks[0].append(warp)
def loadScene(renderGraph, file=None): '''Load or create our sceneGraph''' scene = renderGraph.add(dg.SceneGraph('DoF_Scene', file)) cube = scene.add( dgs.PolySurface('cube', scene, file='%s/TexturedCube.obj' % MODELDIR)) cube.setScale(1, 1, 1) cube.setTranslate(0., 0., -4) cube.setRotate(25., 65., 23.) teapot = scene.add( dgs.PolySurface('teapot', scene, file='%s/teapot.obj' % MODELDIR)) teapot.setScale(.4, .4, .4) teapot.setTranslate(.5, -.2, -1.5) teapot.setRotate(5., 0., 0.) teapot.material.diffuseColor = np.array([1.0, 1.0, 0.8]) * 0.5 teapot.material.specularColor = np.array([1.0, 0.8, 0.7]) * 0.5 teapot.material.glossiness = 20 renderGraph.focus = 2. renderGraph.focusChanged = False display = renderGraph['Fake Display'] imageScale = display.width / (renderGraph.width) pixelDiameter = imageScale * display.pixelSize()[0] # Tick camera = scene.add(dgc.Camera('scene', scene)) camera.setResolution((renderGraph.width, renderGraph.height)) camera.setTranslate(0., 0., 0.) camera.setFOV(50.) # Tock camBuffer = renderGraph.add( dgr.FrameBuffer('camera_fbo', onScreen=False, depthIsTexture=True)) camBuffer.connectInput(camera) # Tick gaussMip = renderGraph.add(dgshdr.GaussMIPMap('imageGaussMip')) gaussMip.connectInput(camBuffer.rgba, 'inputImage') gaussMip._width = display.width gaussMip._height = display.height # This should not be called here but we need to to be able to call gaussMip.mipLevelCount) - design flaw? # Tock gaussMipBuffer = renderGraph.add( dgr.FrameBuffer('gaussMip_fbo', onScreen=False, mipLevels=gaussMip.mipLevelCount)) gaussMipBuffer.connectInput(gaussMip) # Tick glDepthToLinear = renderGraph.add( dgshdr.GLDepthToLinear('glDepthToLinear')) glDepthToLinear.inputRange[ 1] = 1 # The depth scaling is not necessary if one assumes the world is properly modeled with units in meters glDepthToLinear.outputRange[1] = 1 #0.1 glDepthToLinear.projectionMatrix = camera.filmMatrix glDepthToLinear.connectInput(camBuffer.depth, 'glDepthTexture2D') # Tock linDepthBuffer = renderGraph.add( dgr.FrameBuffer('linDepth_fbo', onScreen=False, isf=GL_R32F)) linDepthBuffer.connectInput(glDepthToLinear) # Tick dof = renderGraph.add(dgshdr.DepthOfField('depthOfField')) renderGraph.focusDistanceLog = 0.1 dof.focalPlaneMeters = 10**renderGraph.focusDistanceLog print("Current focal depth = %.3f D / %.2f meters" % (1.0 / renderGraph['depthOfField'].focalPlaneMeters, renderGraph['depthOfField'].focalPlaneMeters)) dof.pixelSizeMm = pixelDiameter * 1e3 dof.apertureMm = 3.0 * 10 dof.connectInput(gaussMipBuffer.rgba, 'imageTexture') dof.connectInput(linDepthBuffer.rgba, 'depthTexture') # Final renderGraph.frameBuffer.connectInput(dof) return True # Initialization Successful