WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Information associated with a model (https://forum.worldviz.com/showthread.php?t=5121)

roobert 07-31-2014 09:28 AM

Information associated with a model
 
Can I associate information to a model? so when I go in, this information is displayed

I use sensor proximity.

#Create proximity manager
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

#Add main viewpoint as proximity target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)

#MODEL
newTarget=viz.add('model/objeto.dae', pos=[0,0,0])
newTarget.collideBox()
newTarget.alpha(0.8)
sensor = vizproximity.addBoundingSphereSensor(newTarget,sca le=2)
manager.addSensor(sensor)

#ACTIVE SENSOR
def EnterProximity(e):
print "SHOW INFORMATION"

#OFF SENSOR
def ExitProximity(e):
print "HIDDEN INFORMATION"

Frank Verberne 07-31-2014 11:34 AM

There's a similar thread where you can find the answer: http://forum.worldviz.com/showthread...ight=proximity. I don't know what kind of information you want to show, but if you make a 2D text object of that information, you can toggle the visibility of the text while entering or leaving the proximity sensor area.

roobert 07-31-2014 04:03 PM

It correct but when I'll have more of one model the text is variable, how come I can do?

import vizmat
import vizact
import vizproximity
import vizdlg

viz.go()
viz.setMultiSample(4)
viz.fov(60)
viz.clearcolor(viz.SKYBLUE)
viz.collision(viz.ON)

ground = viz.add('tut_ground.wrl') # PISO
ground.collidePlane()

COMPLEJO01 = viz.addChild('sky_day.osgb')
COMPLEJO01.collideMesh()

viz.MainView.move([0,0,-5]) #Mi primera posición

#GRAVEDAD
viz.phys.enable()
viz.phys.setGravity(0,-9.8,0)

#Create proximity manager
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

#Add main viewpoint as proximity target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)

##############PANEL DE INFORMACIÓN#########
myPanel = vizdlg.Panel()
viz.link(viz.CenterCenter,myPanel,offset=(-350,50,0))
myPanel.enable()

##############ACCIONES DEL SENSOR###################
#CREANDO ACCIÓN CUANDO ENTRE ACTIVO EL SENSOR
def EnterProximity(e):
global myPanel
myPanel.reset()
myPanel.visible(viz.ON)
model=e.sensor.getSourceObject()
posicion=str(model.getPosition())
posicion=viz.addText('Posición: '+posicion)
#I would like the text will be variable
#The text panel is cleaned before it appears
text1.visible(viz.ON)
myPanel.addItem(posicion,align=vizdlg.ALIGN_CENTER )
myPanel.addItem(text1,align=vizdlg.ALIGN_CENTER)
##############I WOULD LIKE THAT TEXT1 WILL BE VARIABLE#######

#CAMBIANDO LA ACCIÓN CUANDO EL USUARIO SE ALEJA
def ExitProximity(e):
global myPanel
myPanel.visible(viz.OFF)
text1.visible(viz.OFF)

#MODELOS ESTÁTICOS
house1=viz.add('box.wrl', pos=[-10,0,-20])
house1.collideBox()
text1=viz.addText('house1',parent=house1)
text1.visible(viz.OFF)
sensor1 = vizproximity.addBoundingSphereSensor(house1,scale= 1)
manager.addSensor(sensor1)
manager.onEnter(sensor1,EnterProximity)
manager.onExit(sensor1,ExitProximity)

house2=viz.add('ball.wrl', pos=[0,0,0])
house2.collideBox()
text2=viz.addText('house2',parent=house2)
text2.visible(viz.OFF)
sensor2 = vizproximity.addBoundingSphereSensor(house2,scale= 1)
manager.addSensor(sensor2)
manager.onEnter(sensor2,EnterProximity)
manager.onExit(sensor2,ExitProximity)

house3=viz.add('duck.wrl', pos=[10,0,20])
house3.collideBox()
text3=viz.addText('house3',parent=house3)
text3.visible(viz.OFF)
sensor3 = vizproximity.addBoundingSphereSensor(house3,scale= 1)
manager.addSensor(sensor3)
manager.onEnter(sensor3,EnterProximity)
manager.onExit(sensor3,ExitProximity)

Frank Verberne 08-01-2014 02:10 AM

When posting code, please use the code tags by clicking the hashtag symbol (#), as it keeps indentation which is essential for python code. This should do the trick, every sensor has it's own text that becomes visible when entering the sensor area:
Code:

import vizmat
import vizact
import vizproximity
import vizdlg

viz.go()
viz.setMultiSample(4)
viz.fov(60)
viz.clearcolor(viz.SKYBLUE)
viz.collision(viz.ON)

ground = viz.add('tut_ground.wrl') # PISO
ground.collidePlane()

COMPLEJO01 = viz.addChild('sky_day.osgb')
COMPLEJO01.collideMesh()

viz.MainView.move([0,0,-5]) #Mi primera posición

#GRAVEDAD
viz.phys.enable()
viz.phys.setGravity(0,-9.8,0)

#Create proximity manager
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

#Add main viewpoint as proximity target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)

##############PANEL DE INFORMACIÓN#########
myPanel = vizdlg.Panel()
viz.link(viz.CenterCenter,myPanel,offset=(-350,50,0))
myPanel.enable()

##############ACCIONES DEL SENSOR###################
#CREANDO ACCIÓN CUANDO ENTRE ACTIVO EL SENSOR
def EnterProximity(e):
        global myPanel
        myPanel.reset()
        myPanel.visible(viz.ON)
        model=e.sensor.getSourceObject()
        posicion=str(model.getPosition())
        posicion=viz.addText('Posición: '+posicion)
        #I would like the text will be variable
        #The text panel is cleaned before it appears
        e.sensor.text.visible(viz.ON)
        myPanel.addItem(posicion,align=vizdlg.ALIGN_CENTER)
##############I WOULD LIKE THAT TEXT1 WILL BE VARIABLE#######

#CAMBIANDO LA ACCIÓN CUANDO EL USUARIO SE ALEJA
def ExitProximity(e):
        global myPanel
        myPanel.visible(viz.OFF)
        e.sensor.text.visible(viz.OFF)

class house():
        def __init__(self, object, text, position):
                self.obj = viz.add(object, pos = position)
                self.obj.collideBox()
                sensor = vizproximity.addBoundingSphereSensor(self.obj,scale= 5)
                sensor.text = viz.addText(text,parent = self.obj)
                sensor.text.visible(viz.OFF)
                manager.addSensor(sensor)

house1 = house('box.wrl', 'house1', [-10,0,-20])
house2 = house('ball.wrl', 'house2', [0,0,0])
house3 = house('duck.wrl', 'house3', [10,0,20])

manager.onEnter(None,EnterProximity)
manager.onExit(None,ExitProximity)


roobert 08-01-2014 07:40 AM

Frank.
Is exactly what you wanted, you're a genius.
Thanks

roobert 08-01-2014 08:25 AM

And if I want get the text that put in the node, how I do?

house1 = house('box.wrl', 'HOUSE_GET_TEXT', [-10,0,-20])

sensor.text = viz.addText(text,parent = self.obj)


e.sensor.text.visible(viz.ON)
X=e.sensor.text.getText()
print X => "HOUSE_GET_TEXT"

roobert 08-01-2014 08:45 AM

I do that, thanks

X=e.sensor.text.getMessage()
print X => "HOUSE_GET_TEXT"

Frank Verberne 08-01-2014 09:34 AM

Quote:

Originally Posted by roobert (Post 16402)
Frank.
Is exactly what you wanted, you're a genius.
Thanks

You're welcome;)! And well done on finding the answer to your last question on your own!


All times are GMT -7. The time now is 10:14 PM.

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