Exemple #1
0
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
Exemple #2
0
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 
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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)
Exemple #7
0
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
Exemple #8
0
def loadScene(renderGraph):
    '''Load or create our sceneGraph'''
    scene = dg.SceneGraph('Test1_SG')
    cam = scene.add(dgc.Camera('cam', scene))
    cam.setResolution((renderGraph.width, renderGraph.height))
    cam.setTranslate(0.,0.,0.)
    cam.setFOV(50.)
    sun = scene.add(dgs.PolySurface.polySphere('sun', scene, radius=.2))
    sun.setTranslate(0.,0.,-2.)
    sun.setRotate(10.,0.,0.)
    sunMaterial = scene.add(dgm.Lambert('sunMaterial',ambient=(1,1,0), amb_coeff=1., diffuse=(0,0,0), diff_coeff=0))
    sun.setMaterial(sunMaterial)
    mercury = scene.add(dgs.PolySurface.polySphere('mercury', sun, radius=.01))
    mercury.setTranslate(0.3,0.,0.)
    mercuryMaterial = scene.add(dgm.Lambert('mercuryMaterial',ambient=(0,0,0), amb_coeff=0., diffuse=(1.,.5,.3), diff_coeff=1))
    mercury.setMaterial(mercuryMaterial)
    venus = scene.add(dgs.PolySurface.polySphere('venus', sun, radius=.028))
    venus.setTranslate(0.425,0.,0.)
    venusMaterial = scene.add(dgm.Lambert('venusMaterial',ambient=(0,0,0), amb_coeff=0., diffuse=(1.,.6,.6), diff_coeff=1))
    venus.setMaterial(venusMaterial)
    earth = scene.add(dgs.PolySurface.polySphere('earth', sun, radius=.03))
    earth.setTranslate(0.6,0.,0.)
    earth.setRotate(0.,0.,15.)
    earthMaterial = scene.add(dgm.Lambert('earthMaterial',ambient=(0,0,0), amb_coeff=0., diffuse=(.25,.41,.879), diff_coeff=1))
    earth.setMaterial(earthMaterial)
    moon = scene.add(dgs.PolySurface.polySphere('moon', earth, radius=.005))
    moon.setTranslate(0.075,0.,0.)
    moonMaterial = scene.add(dgm.Lambert('moonMaterial',ambient=(0,0,0), amb_coeff=0., diffuse=(.7,.7,.7), diff_coeff=1))
    moon.setMaterial(moonMaterial)
    mars = scene.add(dgs.PolySurface.polySphere('mars', sun, radius=.015))
    mars.setTranslate(0.8,0.,0.)
    marsMaterial = scene.add(dgm.Lambert('marsMaterial',ambient=(0,0,0), amb_coeff=0., diffuse=(.8,.2,.2), diff_coeff=1))
    mars.setMaterial(marsMaterial)
    jupiter = scene.add(dgs.PolySurface.polySphere('jupiter', sun, radius=.1))
    jupiter.setTranslate(1.2,0.,0.)
    jupiterMaterial = scene.add(dgm.Lambert('jupiterMaterial',ambient=(0,0,0), amb_coeff=0., diffuse=(.867,.71875,.527), diff_coeff=1))
    jupiter.setMaterial(jupiterMaterial)
    renderGraph.frameBuffer.connectInput(cam)
    scene.add(renderGraph)
    return scene                                                         # Initialization Successful
Exemple #9
0
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
Exemple #10
0
                  su=7,
                  sv=7,
                  tol=9.223372037e+018,
                  fr=0,
                  dir=2)
bMirror = optimizeCVsForImage(bMirror,
                              screen,
                              pupilPoints,
                              virtualImage,
                              start=-0.037037037037037035,
                              iterations=13)

np.sum(cost)

# setup some nodes
world = dg.SceneGraph()
screen = dg.Plane('screen', world, 4, [0, -1, 0])
screen.setTranslate(*mc.xform('screen', q=1, ws=1, t=1))
screen.setRotate(*mc.xform('screen', q=1, ws=1, ro=1))
#screen.localPointToWorld(screen.point)
#screen.localVectorToWorld(screen.normal)

mirror = 'mirror1'
vi = 'virtualImage'
pupilPoints = [  # 4mm pupil
    np.array((-32.5, 0., 80.)),
    np.array((-30.5, 0., 80.)),
    np.array((-34.5, 0., 80.)),
    np.array((-32.5, 2, 80.)),
    np.array((-32.5, -2, 80.)),
]
Exemple #11
0
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