def __init__(self, offset, particle=None, sensorNum=0, attachTo=viz.MainView, preTrans=[0, 0, 0.1778]): viz.EventClass.__init__(self) self.offset = offset self.particle = particle self.sensorNum = sensorNum self.attachTo = attachTo self.preTran = preTrans self.off = True self.vrpn = viz.add('vrpn6.dle') self.tracker = self.vrpn.addTracker('[email protected]', sensorNum) self.tracker.swapPos([1, 3, 2]) self.tracker.swapQuat([-1, -3, -2, 4]) self.preMat = vizmat.Transform() self.preMat.preEuler([-90, 0, 0]) self.preMat.preTrans(self.preTran) self.postMat = vizmat.Transform() self.postMat.postTrans(offset) vizact.ontimer(0, self.updateView) self.pos = [0, 0, 0] self.rot = [0, 0, 0, 0] self.turnOn()
def setStage(): """Creates grass textured groundplane""" ###should set this hope so it builds new tiles if you are reaching the boundary. fName = 'C:/VENLAB data/shared_modules/textures/strong_edge.bmp' #fName = 'strong_edge.bmp' # add groundplane (wrap mode) groundtexture = viz.addTexture(fName) groundtexture.wrap(viz.WRAP_T, viz.REPEAT) groundtexture.wrap(viz.WRAP_S, viz.REPEAT) groundtexture.anisotropy(16) groundplane = viz.addTexQuad() ##ground for right bends (tight) tilesize = 500 #planesize = tilesize/5 planesize = 40 groundplane.setScale(tilesize, tilesize, tilesize) groundplane.setEuler((0, 90, 0), viz.REL_LOCAL) #groundplane.setPosition((0,0,1000),viz.REL_LOCAL) #move forward 1km so don't need to render as much. matrix = vizmat.Transform() matrix.setScale(planesize, planesize, planesize) groundplane.texmat(matrix) groundplane.texture(groundtexture) groundplane.visible(1) viz.clearcolor(viz.SKYBLUE) return groundplane
def groundCreator(): viz.startLayer(viz.QUADS) viz.texCoord(0,0) viz.vertex(100, 0, -100) viz.texCoord(1,0) viz.vertex(100, 0, 100) viz.texCoord(1,1) viz.vertex(-100, 0, 100) viz.texCoord(0,1) viz.vertex(-100, 0, -100) ground = viz.endLayer() AreaScale_f = [16, 16 ,1] matrix_area_f = vizmat.Transform() matrix_area_f.setScale(AreaScale_f) ground.texmat(matrix_area_f) wallTex = viz.addTexture('wallTex.jpg') wallTex.wrap(viz.WRAP_T,viz.REPEAT) wallTex.wrap(viz.WRAP_S,viz.REPEAT) ground.texture(wallTex) return ground
def __init__(self): # open the fragment shader, assuming it's relative to this code file vertCode = "" with open( os.path.join(os.path.dirname(__file__), 'view_projector.vert'), 'r') as vertFile: vertCode = vertFile.read() fragCode = "" with open( os.path.join(os.path.dirname(__file__), 'view_projector.frag'), 'r') as fragFile: fragCode = fragFile.read() # Make a new shader, and assign some default values for the uniforms. # Thesewill be replaced on update. self._shader = viz.addShader(frag=fragCode, vert=vertCode) # temp mat to default set the uniforms mat = vizmat.Transform() # Holds the inverse transform of the main view. # This will help to calculate the model matrix inside the shader. # Such that vertices can be re-projected into view space of the projector. self._inv_view_uni = viz.addUniformMatrix('mainViewMat_inv', mat.get()) # View matrix of the projector. self._view_uni = viz.addUniformMatrix('viewMat', mat.get()) # Projection matrix of the projector. self._proj_uni = viz.addUniformMatrix('projMat', mat.get()) # Holds the depth texture to perform inverse shadow mapping. # This will allow for projecting only onto first fragment hit. self._depth_texture_uni = viz.addUniformInt('depth_tex', 3) # This allows for accumulation of the previous frames projection # along with the actual frames projection. self._prev_texture_uni = viz.addUniformInt('prev_frame_tex', 4) # specifies an additional scaling factor for frame based accumulation (value range [0.1,1.0]) self._frame_weight_uni = viz.addUniformFloat('frame_weight', 1.0) # specifies a scaling factor for the view cone aperture (value range [0.0,1.0]) self._aperture_scale_uni = viz.addUniformFloat('aperture_scale', 1.0) # attach all uniforms self._shader.attach([ self._inv_view_uni, self._view_uni, self._proj_uni, self._depth_texture_uni, self._prev_texture_uni, self._frame_weight_uni, self._aperture_scale_uni ]) # Camera used to capture the depth texture. self._depth_cam = viz.addRenderNode(inheritView=False) self._depth_cam.drawOrder(1000) self._depth_cam.setAutoClip(False) self._depth_cam.setRenderTexture( viz.addRenderTexture(format=viz.TEX_DEPTH), buffer=viz.RENDER_DEPTH)
def setStage(TILING=True): global ndots, tilesize fName = 'textures\\black.jpg' gtexture = viz.addTexture(fName) gtexture.wrap(viz.WRAP_T, viz.REPEAT) gtexture.wrap(viz.WRAP_S, viz.REPEAT) # #add groundplane (wrap mode) ###UNCOMMENT FOR TILING # Tiling saves memory by using two groundplane tiles instead of a massive groundplane. Since the drivers are essentially driving linearly forward, they cover a lot of distance across the z axis. gplane1 = viz.addTexQuad() ## tilesize = 2000 texture_z_size = tilesize * 2 planesize = tilesize / 5.0 gplane1.setScale(tilesize, tilesize * 2, tilesize) gplane1.setEuler((0, 90, 0), viz.REL_LOCAL) matrix = vizmat.Transform() matrix.setScale(planesize, planesize * 2, planesize) gplane1.texmat(matrix) gplane1.texture(gtexture) gplane1.visible(1) # if TILING: fName2 = 'textures\\black.jpg' gtexture2 = viz.addTexture(fName2) gtexture2.wrap(viz.WRAP_T, viz.REPEAT) gtexture2.wrap(viz.WRAP_S, viz.REPEAT) gplane2 = gplane1.copy() #create duplicate. gplane2.setScale(tilesize, tilesize * 2, tilesize) gplane2.setEuler((0, 90, 0), viz.REL_LOCAL) gplane2.setPosition( (0, 0, 1000), viz.REL_LOCAL) #move forward 1km so don't need to render as much. gplane2.texmat(matrix) gplane2.texture(gtexture2) gplane2.visible(1) gplane2.setPosition(0, 0, tilesize * 2) gplane2.zoffset(-1) else: gplane2 = [] # viz.startlayer(viz.POINTS) # viz.vertexColor(viz.WHITE) # viz.pointSize(2) # for i in range (0,trial_dots): # x = (random.random() - .5) * tilesize # z = (random.random() - .5) * tilesize # viz.vertex([x,0,z]) # dots = viz.endLayer() # dots.setPosition(0,0,0) # dots.visible(1) return (gplane1, gplane2, texture_z_size)
def setStage(TILING=True): """Creates grass textured groundplane""" global gtexture # background color viz.clearcolor(viz.SKYBLUE) #CODE UP TILE-WORK WITH GROUNDPLANE. ##should set this up so it builds new tiles if you are reaching the boundary. #fName = 'textures\\strong_edge_redoutline.bmp' fName = 'textures\\strong_edge.bmp' gtexture = viz.addTexture(fName) gtexture.wrap(viz.WRAP_T, viz.REPEAT) gtexture.wrap(viz.WRAP_S, viz.REPEAT) # #add groundplane (wrap mode) ###UNCOMMENT FOR TILING # Tiling saves memory by using two groundplane tiles instead of a massive groundplane. Since the drivers are essentially driving linearly forward, they cover a lot of distance across the z axis. gplane1 = viz.addTexQuad() ## tilesize = 3000 texture_z_size = tilesize * 2 #planesize = tilesize/5 planesize = tilesize / 5.0 gplane1.setScale(tilesize, tilesize * 2, tilesize) gplane1.setEuler((0, 90, 0), viz.REL_LOCAL) #groundplane.setPosition((0,0,1000),viz.REL_LOCAL) #move forward 1km so don't need to render as much (was originally commented out) matrix = vizmat.Transform() matrix.setScale(planesize, planesize * 2, planesize) gplane1.texmat(matrix) #gplane1.texture(gtexture) gplane1.texture(gtexture) gplane1.visible(1) # if TILING: # fName2 = 'textures\\strong_edge_blueoutline.bmp' #fName2 = 'textures\\strong_edge_blueoutline.bmp' fName2 = 'textures\\strong_edge.bmp' gtexture2 = viz.addTexture(fName2) gtexture2.wrap(viz.WRAP_T, viz.REPEAT) gtexture2.wrap(viz.WRAP_S, viz.REPEAT) gplane2 = gplane1.copy() #create duplicate. gplane2.setScale(tilesize, tilesize * 2, tilesize) gplane2.setEuler((0, 90, 0), viz.REL_LOCAL) #groundplane.setPosition((0,0,1000),viz.REL_LOCAL) #move forward 1km so don't need to render as much. gplane2.texmat(matrix) #gplane1.texture(gtexture) gplane2.texture(gtexture2) gplane2.visible(1) gplane2.setPosition(0, 0, tilesize * 2) gplane2.zoffset(-1) else: gplane2 = [] return (gplane1, gplane2, texture_z_size)
def __init__(self, physEnv, dimensions, axisAngle, position, texPath, texScale, planeABCD): # A wall object invludes a specialized node3D # This node3D is actually a texQuad ################################################################################################ ################################################################################################ ## Set variables self.dimensions = dimensions self.axisAngle = axisAngle self.position = position self.texPath = texPath self.texScale = texScale ################################################################################################ ################################################################################################ ## Create node3D: a texture quad self.node3D = viz.addTexQuad() self.node3D.setScale(dimensions[0], dimensions[1]) self.node3D.setPosition(position) self.node3D.setAxisAngle(axisAngle) self.node3D.disable(viz.DYNAMICS) self.node3D.enable([viz.LIGHTING, viz.CULL_FACE]) # Put texture on the quad matrix = vizmat.Transform() matrix.setScale( [dimensions[0] / texScale, dimensions[1] / texScale, texScale]) self.node3D.texmat(matrix) self.texObj = viz.addTexture(texPath) self.texObj.wrap(viz.WRAP_T, viz.REPEAT) self.texObj.wrap(viz.WRAP_S, viz.REPEAT) self.node3D.texture(self.texObj) ################################################################################################ ################################################################################################ ## Create physNode plane self.physNode = physEnv.makePhysNode('plane', planeABCD)
def build_env(): spaceSize = SIZE half = SIZE / 2 borders = [viz.addTexQuad(size=spaceSize) for x in range(6)] borders[0].setPosition([half, 0, 0]) borders[1].setPosition([-half, 0, 0]) borders[2].setPosition([0, half, 0]) borders[3].setPosition([0, -half, 0]) borders[4].setPosition([0, 0, half]) borders[5].setPosition([0, 0, -half]) borders[0].setAxisAngle([0, 1, 0, -90]) borders[1].setAxisAngle([0, 1, 0, 90]) borders[2].setAxisAngle([1, 0, 0, 90]) borders[3].setAxisAngle([1, 0, 0, -90]) borders[4].setAxisAngle([0, 0, 0, 90]) borders[5].setAxisAngle([0, 0, 0, -90]) grid = viz.addTexture('grid.png') roof = viz.addTexture('roof.png') floor = viz.addTexture('floor.png') wall = viz.addTexture('wall.png') for t in [grid, floor, roof, wall]: t.wrap(viz.WRAP_S, viz.REPEAT) t.wrap(viz.WRAP_T, viz.REPEAT) matrix = vizmat.Transform() scale = matrix.getScale() scale[0] = scale[1] = SIZE matrix.setScale(scale) def setTex(b, t): b.texture(t, '', 0) b.texmat(matrix, '', 0) #print(b.getAxisAngle()) setTex(borders[0], wall) setTex(borders[1], wall) setTex(borders[4], wall) setTex(borders[5], wall) setTex(borders[2], roof) setTex(borders[3], floor)
def __init__(self, physenv, dimensions, axis_angle, position, texture_path, texture_scale, plane_abcd): # A wall object invludes a specialized visNode # This visNode is actually a texQuad ################################################################################################ ################################################################################################ # Set variables self.dimensions = dimensions self.axis_angle = axis_angle self.position = position self.texture_path = texture_path self.texture_scale = texture_scale ################################################################################################ ################################################################################################ # Create visNode: a texture quad self.vis_node = viz.addTexQuad() self.vis_node.setScale(dimensions[0], dimensions[1]) self.vis_node.setPosition(position) self.vis_node.setAxisAngle(axis_angle) self.vis_node.disable(viz.DYNAMICS) self.vis_node.enable([viz.LIGHTING, viz.CULL_FACE]) # Put texture on the quad matrix = vizmat.Transform() matrix.setScale([dimensions[0] / texture_scale, dimensions[1] / texture_scale, texture_scale]) self.vis_node.texmat(matrix) self.texture_object = viz.addTexture(texture_path) self.texture_object.wrap(viz.WRAP_T, viz.REPEAT) self.texture_object.wrap(viz.WRAP_S, viz.REPEAT) self.vis_node.texture(self.texture_object) ################################################################################################ ################################################################################################ # Create physNode plane self.phys_node = physenv.makePhysNode('plane', plane_abcd)
fName = 'textures\\strong_edge_redoutline.bmp' gtexture = viz.addTexture(fName) gtexture.wrap(viz.WRAP_T, viz.REPEAT) gtexture.wrap(viz.WRAP_S, viz.REPEAT) gplane1 = viz.addTexQuad() ## tilesize = 5 planesize = tilesize / 5.0 gplane1.setScale(tilesize, tilesize * 2, tilesize) gplane1.setEuler((0, 90, 0), viz.REL_LOCAL) texture_z_size = tilesize * 2 matrix = vizmat.Transform() matrix.setScale(planesize, planesize * 2, planesize) gplane1.texmat(matrix) gplane1.texture(gtexture) gplane1.visible(1) #create second texture fName2 = 'textures\\strong_edge_blueoutline.bmp' gtexture2 = viz.addTexture(fName2) gtexture2.wrap(viz.WRAP_T, viz.REPEAT) gtexture2.wrap(viz.WRAP_S, viz.REPEAT) gplane2 = gplane1.copy() #create duplicate. gplane2.setScale(tilesize, tilesize * 2, tilesize) gplane2.setEuler((0, 90, 0), viz.REL_LOCAL)
def RoomCreator(length, width, height, offset): Room = viz.addGroup() room = [] viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(width / 2, 0, -offset) viz.texCoord(1, 0) viz.vertex(width / 2, 0, (length - offset)) viz.texCoord(1, 1) viz.vertex(width / 2, height, (length - offset)) viz.texCoord(0, 1) viz.vertex(width / 2, height, -offset) Wall_01 = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(width / 2, 0, (length - offset)) viz.texCoord(1, 0) viz.vertex(0.25, 0, (length - offset)) viz.texCoord(1, 1) viz.vertex(0.25, height, (length - offset)) viz.texCoord(0, 1) viz.vertex(width / 2, height, (length - offset)) Wall_02_1 = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(0.25, 2.5, (length - offset)) viz.texCoord(1, 0) viz.vertex(-0.25, 2.5, (length - offset)) viz.texCoord(1, 1) viz.vertex(-0.25, height, (length - offset)) viz.texCoord(0, 1) viz.vertex(0.25, height, (length - offset)) Wall_02_2 = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(-0.25, 0, (length - offset)) viz.texCoord(1, 0) viz.vertex(-width / 2, 0, (length - offset)) viz.texCoord(1, 1) viz.vertex(-width / 2, height, (length - offset)) viz.texCoord(0, 1) viz.vertex(-0.25, height, (length - offset)) Wall_02_3 = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(-width / 2, 0, (length - offset)) viz.texCoord(1, 0) viz.vertex(-width / 2, 0, -offset) viz.texCoord(1, 1) viz.vertex(-width / 2, height, -offset) viz.texCoord(0, 1) viz.vertex(-width / 2, height, (length - offset)) Wall_03 = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(-width / 2, 0, -offset) viz.texCoord(1, 0) viz.vertex(width / 2, 0, -offset) viz.texCoord(1, 1) viz.vertex(width / 2, height, -offset) viz.texCoord(0, 1) viz.vertex(-width / 2, height, -offset) Wall_04 = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(width / 2, 0, -offset) viz.texCoord(1, 0) viz.vertex(width / 2, 0, (length - offset)) viz.texCoord(1, 1) viz.vertex(-width / 2, 0, (length - offset)) viz.texCoord(0, 1) viz.vertex(-width / 2, 0, -offset) Floor = viz.endLayer() viz.startLayer(viz.QUADS) viz.texCoord(0, 0) viz.vertex(width / 2, height, -offset) viz.texCoord(1, 0) viz.vertex(width / 2, height, (length - offset)) viz.texCoord(1, 1) viz.vertex(-width / 2, height, (length - offset)) viz.texCoord(0, 1) viz.vertex(-width / 2, height, -offset) Ceiling = viz.endLayer() WallScale_small = [1, .25, 1] WallScale_large = [1, .25, 1] WallScale_w2l = [.5, .25, 1] AreaScale = [1, 1, 1] matrix_s = vizmat.Transform() matrix_s.setScale(WallScale_small) matrix_l = vizmat.Transform() matrix_l.setScale(WallScale_large) matrix_w2l = vizmat.Transform() matrix_w2l.setScale(WallScale_w2l) matrix_w2s = vizmat.Transform() matrix_w2s.setScale([0.04, 0.04, 1]) matrix_area = vizmat.Transform() matrix_area.setScale(AreaScale) Wall_01.texmat(matrix_s) Wall_02_1.texmat(matrix_w2l) Wall_02_2.texmat(matrix_w2s) Wall_02_3.texmat(matrix_w2l) Wall_03.texmat(matrix_s) Wall_04.texmat(matrix_l) Floor.texmat(matrix_area) Ceiling.texmat(matrix_area) wallTex = viz.addTexture('wallTex.jpg') wallTex.wrap(viz.WRAP_T, viz.REPEAT) wallTex.wrap(viz.WRAP_S, viz.REPEAT) wallTex_darker = viz.addTexture('wallTex_Dark.jpg') wallTex_darker.wrap(viz.WRAP_T, viz.REPEAT) wallTex_darker.wrap(viz.WRAP_S, viz.REPEAT) wallTex_bright = viz.addTexture('wallTex_Brightened.jpg') wallTex_bright.wrap(viz.WRAP_T, viz.REPEAT) wallTex_bright.wrap(viz.WRAP_S, viz.REPEAT) room.append(Wall_01) room.append(Wall_02_1) room.append(Wall_02_2) room.append(Wall_02_3) room.append(Wall_03) room.append(Wall_04) room.append(Floor) room.append(Ceiling) room[0].texture(wallTex) room[4].texture(wallTex) room[5].texture(wallTex) room[1].texture(wallTex_bright) room[2].texture(wallTex_bright) room[3].texture(wallTex_bright) room[6].texture(wallTex_darker) room[7].texture(wallTex_darker) for i in range(8): room[i].setParent(Room) return Room
def room(high, wide, dep): room = viz.addGroup() wall_positions = (([wide / 2, 0, dep / 2], [wide / 2, 0, (-dep / 2)], [wide / 2, high, (-dep / 2)], [wide / 2, high, dep / 2]), ([wide / 2, 0, (-dep / 2)], [-wide / 2, 0, (-dep / 2)], [-wide / 2, high, (-dep / 2)], [wide / 2, high, (-dep / 2)]), ([-wide / 2, 0, (-dep / 2)], [-wide / 2, 0, dep / 2], [-wide / 2, high, dep / 2], [-wide / 2, high, (-dep / 2)]), ([-wide / 2, 0, dep / 2], [wide / 2, 0, dep / 2], [wide / 2, high, dep / 2], [-wide / 2, high, dep / 2]), ([wide / 2, high, dep / 2], [wide / 2, high, (-dep / 2)], [-wide / 2, high, (-dep / 2)], [-wide / 2, high, dep / 2]), ([100, 0, -100], [100, 0, 100], [-100, 0, 100], [-100, 0, -100])) coord = ([0, 0], [1, 0], [1, 1], [0, 1]) WallScale_small = [1, .25, 1] WallScale_large = [1, .25, 1] AreaScale = [1, 1, 1] AreaScale_f = [16, 16, 1] matrix_s = vizmat.Transform() matrix_s.setScale(WallScale_small) matrix_l = vizmat.Transform() matrix_l.setScale(WallScale_large) matrix_area_f = vizmat.Transform() matrix_area_f.setScale(AreaScale_f) matrix_area = vizmat.Transform() matrix_area.setScale(AreaScale) wallTex = viz.addTexture('wallTex.jpg') wallTex.wrap(viz.WRAP_T, viz.REPEAT) wallTex.wrap(viz.WRAP_S, viz.REPEAT) wallTex_darker = viz.addTexture('wallTex_Dark.jpg') wallTex_darker.wrap(viz.WRAP_T, viz.REPEAT) wallTex_darker.wrap(viz.WRAP_S, viz.REPEAT) wallTex_bright = viz.addTexture('wallTex_Brightened.jpg') wallTex_bright.wrap(viz.WRAP_T, viz.REPEAT) wallTex_bright.wrap(viz.WRAP_S, viz.REPEAT) for i in range(6): viz.startLayer(viz.QUADS) for j in range(4): viz.texCoord(coord[j]) viz.vertex(wall_positions[i][j]) wall = viz.endLayer() if i < 4: if i % 2: wall.texmat(matrix_s) else: wall.texmat(matrix_l) if i == 3: wall.texture(wallTex_bright) else: wall.texture(wallTex) else: if i == 5: wall.texmat(matrix_area_f) else: wall.texmat(matrix_area) wall.texture(wallTex_darker) wall.setParent(room) return room