WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-13-2008, 10:34 AM
burt01041 burt01041 is offline
Member
 
Join Date: Aug 2008
Posts: 6
how to bind text to objects

i have a question, you know how in the tutorials it shows how to bind the mona lisa video to the screen? how would i do this with text... so that if also the player press a button, the screen would go up, and the text along with it.
any suggestions...?
Reply With Quote
  #2  
Old 08-13-2008, 02:00 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You will need to manually scale and position the text so that it lies on the screen surface. You will probably need to use the zoffset command also, to prevent z-fighting artifacts.
Reply With Quote
  #3  
Old 08-14-2008, 08:18 AM
burt01041 burt01041 is offline
Member
 
Join Date: Aug 2008
Posts: 6
i don't understand too well, what you mean by this... is there a tutorial on such thing?
thanks btw
Reply With Quote
  #4  
Old 08-14-2008, 04:57 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
There is no tutorial that directly addresses this issue. You just need to use the standard node.setPosition/setEuler/setScale functions to place the text where you want it to show up, in this case on top of the screen.
Reply With Quote
  #5  
Old 08-14-2008, 07:00 PM
John P John P is offline
Member
 
Join Date: Jun 2006
Posts: 8
I have some code that you can feel free to use. It might be overkill but it should do the job.

It uses an action to build a billboard like behavior. eg. the billboard node looks directly at the camera position rather than matching the camera alignment. It was useful in a cave scenario. It also deals with Z order and depth write to ensure the text is visible.

Otherwise you just call AttachSpeechBubble to float some text above an object.

Code:
import viz

viz.go()

#########Utility Class and Functions for Speech Bubble############
# all you need to call is AttachSpeechBubble
#code is based upon worldviz avatar lookat tutorial
MAXLINELENGTH = 60
class BillboardToNodeAction(viz.ActionClass):	
	def begin(self,object):
		"""Called once when action starts"""
		self.nodeToLookAt = self._actiondata_.data[0]
		self.nodeToModify = self._actiondata_.data[1]
		self.duration = self._actiondata_.data[2]        
		self.blendIn = self._actiondata_.data[3]
		self.timeElapsed = 0
		self.startQuat = self.nodeToModify.getQuat()
	def update(self,elapsed,object):
		self.timeElapsed += elapsed     
		p = 1
		if self.blendIn <> 0.0:
			p = self.timeElapsed / self.blendIn
			
		positionToLookAt = self.nodeToLookAt.getPosition()
		for ix in range(3):
			positionToLookAt[ix] = self.nodeToModify.getPosition()[ix] + self.nodeToModify.getPosition()[ix] - positionToLookAt[ix]
		if self.duration > 0.0 and self.timeElapsed > self.duration:
			self.nodeToModify.lookat(positionToLookAt, 0, viz.ABS_GLOBAL)
			self.end(object) 
		elif p < 1.0:
			self.nodeToModify.lookat( positionToLookAt, 0, viz.ABS_GLOBAL )
			targetQuat = self.nodeToModify.getQuat()
			nextQuad = vizmat.slerp(self.startQuat,targetQuat,p)
			self.nodeToModify.setQuat(nextQuad)
		else:
			self.nodeToModify.lookat(positionToLookAt, 0, viz.ABS_GLOBAL)
	def end(self,object):
		viz.ActionClass.end(self,object)

#Function to construct the action instance
def billboardNode( nodeToLookAt, nodeToModify, duration = viz.FOREVER, blendIn = 0.0):
    action = viz.ActionData()
    action.data = [ nodeToLookAt, nodeToModify, duration, blendIn ]
    action.actionclass = BillboardToNodeAction
    return action

def FormatTextbox(msg):
	length = len(msg)
			
	lastspace = 0	
	while lastspace + MAXLINELENGTH < length and lastspace <> -1:
		lastspace = msg.rfind(' ',lastspace, lastspace + MAXLINELENGTH)
		if lastspace > 0 and lastspace < length:
			msg = msg[:lastspace] + '\n' + msg[lastspace+1:]
		else:
			lastspace = -1
			
	lines = msg.splitlines()
						
	return lines

def AttachSpeechBubble(dest,message, height = 1.8):
	
	lines = FormatTextbox(message)
	
	rootline = 0
	parentline = 0
	for lineix in range(len(lines),0,-1):
		speechline = viz.addText(lines[lineix-1])
		speechline.alignment(viz.TEXT_CENTER_BOTTOM)
		if not rootline:
			rootline = speechline
			parentline = speechline
		else:
			speechline.parent(parentline)		
			parentline = speechline
			speechline.translate([0,1.0,0])
		speechline.draworder(13)
		speechline.depthFunc(viz.GL_ALWAYS)
		speechline.disable(viz.DEPTH_WRITE)
		
	speechtext = rootline

	speechbox = speechtext.getBoundingBox()
	speechtext.setScale([0.12,0.12,0.12])

	viz.startlayer(viz.QUADS)
	viz.vertex(speechbox.xmin-0.1,speechbox.ymax+0.1,0)
	viz.vertex(speechbox.xmax+0.1,speechbox.ymax+0.1,0)
	viz.vertex(speechbox.xmax+0.1,speechbox.ymin-0.1,0)
	viz.vertex(speechbox.xmin-0.1,speechbox.ymin-0.1,0)
	speechquad = viz.endlayer()
	speechquad.color([0,0,0])
	speechquad.disable(viz.CULL_FACE)
	speechquad.parent(speechtext)
	speechquad.draworder(12)
	speechquad.alpha(0.5)
	speechquad.depthFunc(viz.GL_ALWAYS)
	speechquad.disable(viz.DEPTH_WRITE)
	
	if type(dest) == list:
		speechtext.translate(dest)
	else:
		linkposition = viz.link(dest, speechtext)
		linkposition.setMask(viz.LINK_POS)
		linkposition.preTrans([0, height, 0])

	speechtext.addAction(billboardNode(viz.MainView,speechtext))
	
	return speechtext
#################################	
	
viz.clearcolor(0,0,0.5)
box = viz.add("box.wrl")
box.setPosition(0,2,7)

AttachSpeechBubble(dest = box,message = "This text floats above the box",height = 1.0)
Reply With Quote
  #6  
Old 08-18-2008, 10:16 AM
burt01041 burt01041 is offline
Member
 
Join Date: Aug 2008
Posts: 6
what is this 'AttachSpeechBubble' you speak of? will it allow an avatar to have a floating text bubble if an event is triggered?
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
Improve performance with large number of onthefly objects? Fox5 Vizard 7 04-28-2008 05:19 PM
text output jaclyn.bill Vizard 2 10-24-2007 06:37 AM
Could not find plugin to load objects... halley Vizard 1 05-30-2006 11:01 AM
adding 2D text via script V.shazzle Vizard 3 09-19-2005 02:45 PM
3d Text with Transparent Borders vjosh Vizard 3 12-01-2004 10:50 AM


All times are GMT -7. The time now is 11:02 PM.


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