WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-09-2008, 09:00 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
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?
Reply With Quote
  #2  
Old 04-09-2008, 06:09 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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.
Reply With Quote
  #3  
Old 04-10-2008, 06:33 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
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.
Reply With Quote
  #4  
Old 04-10-2008, 12:53 PM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
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)
Reply With Quote
  #5  
Old 04-10-2008, 02:23 PM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
@ 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.
Reply With Quote
  #6  
Old 04-10-2008, 03:26 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Using the following code makes the mirror semi-transparent for me:
Code:
mirrorsurface.alpha(.2)
mirrorsurface.appearance(viz.TEXMODULATE)
Reply With Quote
  #7  
Old 04-11-2008, 04:40 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Thanks, that was exactly what I was looking for!

I started playing around with two mirrors facing each other, but then the reflection of mirror1 is not reflected in mirror 2. Instead, you'll see a black square at the position of mirror2 in the reflection of mirror1. And when you look into mirror2, you'll see a black square at the position of mirror1. Both mirror reflections work well for the rest of the environment. I was wondering if it is possible at all to fix this. I don't really need the solution, I just want to know if it is possible. But if the solution is quite simple, then I'm all ears (or eyes).
Reply With Quote
  #8  
Old 04-11-2008, 05:04 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Thanks, that was exactly what I was looking for!

I started playing around with two mirrors facing each other, but then the reflection of mirror1 is not reflected in mirror 2. Instead, you'll see a black square at the position of mirror2 in the reflection of mirror1. And when you look into mirror2, you'll see a black square at the position of mirror1. Both mirror reflections work well for the rest of the environment. I was wondering if it is possible at all to fix this. I don't really need the solution, I just want to know if it is possible. But if the solution is quite simple, then I'm all ears (or eyes).

I also noticed a significant framerate drop when an avatar and it's reflection are in view. Is there any way the algorithm for the reflection texture can be modified so that the framerate won't drop (as much)? Now the drop is from 72 fps to 36 fps.
Reply With Quote
  #9  
Old 02-09-2011, 04:35 AM
chris_user chris_user is offline
Member
 
Join Date: Feb 2011
Posts: 20
hope anyone can help me with my problem;
when I apply the mirroring effect, the mirroring looks fine, but the reflected model is way too bright.

this line is the reason for the good looking mirror effect, but it also blows out the placed model if you take a direct look

viz.MainView.getHeadLight().ambient(1,1,1)

is there a possibility to exclude the effect for the model?
hope anybody can help

thanks in advance
Reply With Quote
  #10  
Old 07-27-2011, 04:47 PM
VHILRA VHILRA is offline
Member
 
Join Date: Jun 2011
Posts: 6
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)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -7. The time now is 07:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC