|
#1
|
|||
|
|||
How to make a glass window in Vizard
Hi,
How can I create a real like glass window in Vizard? I already have a mirror that gives the reflection, but to have a nice glass window you'll have to be able to see through the glass (it has to be transparent), but also see your reflection (it has to have some reflection). Does anyone have any suggestions how I could accomplish this? |
#2
|
|||
|
|||
You can use the node.alpha command to set the mirror transparency. This will still work with the mirror code you have. You can also use a static reflection texture instead of a real-time reflection, this is what most people do.
|
#3
|
|||
|
|||
I've tried the node.alpha command, but it doesn't work with my mirrorsurface. The texquad becomes transparent, but the reflection texture doesn't. So it tried tex.alpha(0.5) but that didn't work. Is there any way I can modify the mirrorsurface in the code below so that it reflects and is transparent? How would the static reflection texture work?
Code:
import viz viz.go() import viz viz.go() def addMirror(mirror,mat=None): #If mirror matrix is not specifed, get matrix of mirror object if mat is None: mat = mirror.getMatrix() #Position of mirror pos = viz.Vector(mat.getPosition()) #Direction mirror is pointing dir = viz.Vector(mat.getForward()) dir.normalize() #Quaternion rotation of mirror quat = mat.getQuat() #Create render texture tex = viz.addRenderTexture() #Create render node for rendering reflection lens = viz.addRenderNode(size=[1024,1024]) lens.attachTexture(tex) lens.setInheritView(True,viz.POST_MULT) lens.disable(viz.CULL_FACE,op=viz.OP_SET_OVERRIDE) #Setup reflection matrix rot = viz.Matrix.quat(quat) invRot = rot.inverse() lens.setMatrix(viz.Matrix.translate(pos*-1.0)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos)) #Setup reflection clip plane plane = vizmat.Plane(pos=pos,normal=dir) dist = plane.distance([0,0,0]) lens.clipPlane([-dir[0],-dir[1],-dir[2],dist+0.001]) #Project reflection texture onto mirror mirror.texture(tex) mirror.texGen(viz.TEXGEN_PROJECT_EYE) #Add gallery environment gallery = viz.add('gallery.ive') #Use existing painting as mirror and specify the matrix mirrorsurface = viz.addTexQuad() mirrorsurface.alpha(.5) mirrorsurface.setPosition([0, 1, 2]) #Y,Z,X mirrorsurfacerotation = [0,0,0] #rotation around the Z,Y,X axes mirrorsurface.rotate(mirrorsurfacerotation) m = viz.Matrix() m.setPosition(mirrorsurface.getPosition(viz.ABS_GLOBAL)) m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y #Apply mirror settings to mirror object addMirror(mirrorsurface,m) #Increase ambient lighting viz.MainView.getHeadLight().ambient(1,1,1) Last edited by Frank Verberne; 04-10-2008 at 06:38 AM. |
#4
|
|||
|
|||
BTW, if you want to see yourself in the mirror you can do this:
Code:
import viz viz.go() man = viz.add('male.cfg') man.translate(0,0,4) link = viz.link(viz.MainView,man) link.preTrans([0,-1.8,0]) def addMirror(mirror,mat=None): #If mirror matrix is not specifed, get matrix of mirror object if mat is None: mat = mirror.getMatrix() #Position of mirror pos = viz.Vector(mat.getPosition()) #Direction mirror is pointing dir = viz.Vector(mat.getForward()) dir.normalize() #Quaternion rotation of mirror quat = mat.getQuat() #Create render texture tex = viz.addRenderTexture() #Create render node for rendering reflection lens = viz.addRenderNode(size=[1024,1024]) lens.attachTexture(tex) lens.setInheritView(True,viz.POST_MULT) lens.disable(viz.CULL_FACE,op=viz.OP_SET_OVERRIDE) #Setup reflection matrix rot = viz.Matrix.quat(quat) invRot = rot.inverse() lens.setMatrix(viz.Matrix.translate(pos*-1.0)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos)) #Setup reflection clip plane plane = vizmat.Plane(pos=pos,normal=dir) dist = plane.distance([0,0,0]) lens.clipPlane([-dir[0],-dir[1],-dir[2],dist+0.001]) #Project reflection texture onto mirror mirror.texture(tex) mirror.texGen(viz.TEXGEN_PROJECT_EYE) #Add gallery environment gallery = viz.add('gallery.ive') #Use existing painting as mirror and specify the matrix mirrorsurface = viz.addTexQuad() mirrorsurface.alpha(.2) mirrorsurface.scale(.99,.74,1) mirrorsurface.setPosition([-.329, 1.8, 2.9]) #Y,Z,X mirrorsurfacerotation = [0,0,0] #rotation around the Z,Y,X axes mirrorsurface.rotate(mirrorsurfacerotation) m = viz.Matrix() m.setPosition(mirrorsurface.getPosition(viz.ABS_GLOBAL)) m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y #Apply mirror settings to mirror object addMirror(mirrorsurface,m) #Increase ambient lighting viz.MainView.getHeadLight().ambient(1,1,1) |
#5
|
|||
|
|||
@ Jerry: I already know how to see myself in the mirror. But I want to create a glass window where you can see through, but also reflects, like a real life glass window. So what I want to make is a transparent mirror. The problem is that I don't know how to make the reflection texture transparent.
|
#6
|
|||
|
|||
Using the following code makes the mirror semi-transparent for me:
Code:
mirrorsurface.alpha(.2) mirrorsurface.appearance(viz.TEXMODULATE) |
#7
|
|||
|
|||
I am also having a lot of trouble trying to implement a mirror. In this version I cannot seem to get the mirror to reflect avatars:
import viz import time import vizact viz.go() clock = 0 PERSON_HEIGHT = 1.5 GRAVITY = 9.81 OFFSET = 0 #Offset due to the room model load print OFFSET light = viz.MainView.getHeadLight() light.disable() roomGroup = None viz.clearcolor(0.1,0.1,0.3) labRoom = viz.add('LabRoom.ive') labRoom.setPosition(0, OFFSET, 0) #Correct view height viz.MainView.eyeheight(0) ##--------------------------------------------------------------------- ##Configure tracking ##--------------------------------------------------------------------- ##Orientation of the HMD #isense = viz.add('intersense.dls') ##isense.addTracker() #adding the tracker #Commented out because of the dls file (instead of a dle #view = viz.MainView #defining the main view #vrpn = viz.add('vrpn7.dle') #Interface with PPT computer #PPT_HOSTNAME = '171.64.33.43' #PPT IP address ##Adding the tracker to the orientation #headMarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 0) ##Linking the orientation to the main view #headOri = viz.link(isense, view, mask = viz.LINK_ORI, priority = 0) ##Linking the PPT to the mainview #headPos = viz.link(headMarker, view, mask = viz.LINK_POS, priority = 0) ##Specify HMD model #nvis.nvisorSX111() #-------------------------------------------------------- #Mirror #-------------------------------------------------------- REFLECT_MASK = viz.addNodeMask() def addMirror(mirror,mat=None,eye=viz.BOTH_EYE): #If mirror matrix is not specifed, get matrix of mirror object if mat is None: mat = mirror.getMatrix() #Position of mirror pos = viz.Vector(mat.getPosition()) #Direction mirror is pointing dir = viz.Vector(mat.getForward()) dir.normalize() #Quaternion rotation of mirror quat = mat.getQuat() #Create render texture tex = viz.addRenderTexture() #Create render node for rendering reflection lens = viz.addRenderNode(size=[512,512]) lens.attachTexture(tex) lens.setInheritView(True,viz.POST_MULT) lens.disable(viz.CULL_FACE,op=viz.OP_OVERRIDE) if eye == viz.LEFT_EYE: lens.disable(viz.RENDER_RIGHT) mirror.disable(viz.RENDER_RIGHT) elif eye == viz.RIGHT_EYE: lens.disable(viz.RENDER_LEFT) mirror.disable(viz.RENDER_LEFT) mirror.renderToAllRenderNodesExcept([lens]) #Setup reflection matrix rot = viz.Matrix.quat(quat) invRot = rot.inverse() lens.setMatrix(viz.Matrix.translate(-pos)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos)) #Setup reflection clip plane s = viz.sign(viz.Vector(dir) * viz.Vector(pos)) plane = vizmat.Plane(pos=pos,normal=dir) dist = plane.distance([0,0,0]) lens.clipPlane([dir[0],dir[1],dir[2],s*dist-0.01]) #Project reflection texture onto mirror mirror.texture(tex) mirror.texGen(viz.TEXGEN_PROJECT_EYE) viz.startlayer(viz.QUADS) #Hardcoding the mirror's plane viz.texcoord(0,0) viz.vertex( 6.35 , OFFSET + 1.4 , -3.1) viz.texcoord(0,1) viz.vertex( 6.35 , OFFSET + 2.85, -3.1) viz.texcoord(1,1) viz.vertex( 2.8 , OFFSET + 2.85, -3.1) viz.texcoord(1,0) viz.vertex( 2.8 , OFFSET + 1.4 , -3.1) mirrorRight = viz.endlayer( ) mirrorLeft = mirrorRight.copy() #specify the matrix m = viz.Matrix() m.setPosition([0.25,1,0.25]) m.setEuler(0 , 0 ,0) #This determines which way the mirror is facing #Apply mirror settings to mirror object addMirror(mirrorRight,m,viz.RIGHT_EYE) addMirror(mirrorLeft,m,viz.LEFT_EYE) #Increase ambient lighting #viz.MainView.getHeadLight().ambient(1,1,1) #-------------------------------------------------------- #Create a self avatar #-------------------------------------------------------- avatar = viz.add('vcc_female.cfg') avatar.setScale(1.7,1.7,1.7) #Link avatar body to viewpoint avatarLink = viz.link(viz.MainView,avatar) avatarLink.setPos([None,0,None]) #Keep avatar on floor avatarLink.setEuler([None,0,0]) #Only update avatar yaw avatar.setMask(viz.LEFT_MASK|viz.RIGHT_MASK,mode=v iz.MASK_REMOVE) #Only draw avatar in mirror #Link avatar head to viewpoint head = avatar.getBone('Bip01 Head') head.lock() viz.link(viz.MainView,head,mask=viz.LINK_ORI) avatar2 = viz.add('vcc_female.cfg') avatar2.setPosition(4, .1, 0) avatar2.setScale(1.7,1.7,1.7) |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating a Vizard Sensor Plugin | farshizzo | Plug-in development | 25 | 08-01-2019 01:24 AM |
Vizard and Augmented Reality | realvision | Vizard | 4 | 04-04-2008 11:59 AM |
Vizard won't run | wouters | Vizard | 5 | 02-05-2008 12:12 PM |
Fall 2007 release of Vizard R3 | 3 D | Announcements | 0 | 10-15-2007 05:50 PM |
wxPython with Vizard | farshizzo | Vizard | 18 | 09-29-2005 09:49 AM |