Example #1
0
File: edit.py Project: Ilikia/naali
 def init_selection_box(self):
     # create a temporary selection box, we dont want to sync this for now
     # as there is no deletion code when you leave the server!
     self.selection_box_entity = naali.createEntity(comptypes = ["EC_SelectionBox", "EC_Name"], localonly = True, temporary = True)
     self.selection_box_entity.SetName("Python Selection Box")
     self.selection_box = self.selection_box_entity.GetOrCreateComponentRaw('EC_SelectionBox')
     self.selection_box.Hide()
     self.selection_box_inited = True
Example #2
0
 def init_selection_box(self):
     # create a temporary selection box, we dont want to sync this for now
     # as there is no deletion code when you leave the server!
     self.selection_box_entity = naali.createEntity(
         comptypes=["EC_SelectionBox", "EC_Name"],
         localonly=True,
         temporary=True)
     self.selection_box_entity.SetName("Python Selection Box")
     self.selection_box = self.selection_box_entity.GetOrCreateComponentRaw(
         'EC_SelectionBox')
     self.selection_box.Hide()
     self.selection_box_inited = True
Example #3
0
    def testBillboard(self):
        avatar = naali.getUserAvatar()
        avatar_pos = avatar.GetComponentRaw("EC_Placeable")

        self.pixmap_label = QLabel()
        self.pixmap_label.size = QSize(200, 200)
        self.pixmap_label.scaledContents = True
        self.pixmap_label.setPixmap(QPixmap('./data/ui/images/naali_icon.png'))

        self.text_label = QLabel()
        self.text_label.size = QSize(300, 50)
        self.text_label.text = "Hello world"

        self.my_widget = QWidget()
        self.my_widget.setLayout(QVBoxLayout())
        self.my_widget.layout().addWidget(self.pixmap_label)
        self.my_widget.layout().addWidget(self.text_label)

        if self.my_widget is None:
            print("Cannot find image file.")
            return

        self.my_entity = naali.createEntity()
        position = self.my_entity.GetOrCreateComponentRaw(
            "EC_Placeable", "pos",
            PythonQt.private.AttributeChange.Disconnected, False)
        position.position = avatar_pos.position

        self.ec_billboard = self.my_entity.GetOrCreateComponentRaw(
            "EC_BillboardWidget", "test",
            PythonQt.private.AttributeChange.Disconnected, False)
        if self.ec_billboard is None:
            print("Cannot create EC_Billboard component.")
            return

        self.ec_billboard.SetPosition(0, 0, 1)
        self.ec_billboard.SetWidth(1)
        self.ec_billboard.SetHeight(1)
        self.ec_billboard.SetWidget(self.my_widget)

        self.size_timer = QTimer()
        self.size_timer.connect("timeout()", self.animateSize)
        self.size_timer.start(100)

        self.text_timer = QTimer()
        self.text_timer.connect("timeout()", self.animateText)
        self.text_timer.start(1000)
Example #4
0
	def testBillboard(self):	
		avatar = naali.getUserAvatar()
		avatar_pos = avatar.GetComponentRaw("EC_Placeable")
		
		self.pixmap_label = QLabel()
		self.pixmap_label.size = QSize(200,200)
		self.pixmap_label.scaledContents = True
		self.pixmap_label.setPixmap(QPixmap('./data/ui/images/naali_icon.png'))

		self.text_label = QLabel()
		self.text_label.size = QSize(300,50)
		self.text_label.text = "Hello world"

		self.my_widget = QWidget()
		self.my_widget.setLayout(QVBoxLayout())
		self.my_widget.layout().addWidget(self.pixmap_label)
		self.my_widget.layout().addWidget(self.text_label)
		
		if self.my_widget is None:
			print("Cannot find image file.")
			return
			
		self.my_entity = naali.createEntity()
		position = self.my_entity.GetOrCreateComponentRaw("EC_Placeable", "pos", PythonQt.private.AttributeChange.Disconnected, False)
		position.position = avatar_pos.position
		
		self.ec_billboard = self.my_entity.GetOrCreateComponentRaw("EC_BillboardWidget", "test", PythonQt.private.AttributeChange.Disconnected, False)
		if self.ec_billboard is None:
			print("Cannot create EC_Billboard component.")
			return
	
		self.ec_billboard.SetPosition(0,0,1)
		self.ec_billboard.SetWidth(1)
		self.ec_billboard.SetHeight(1)
		self.ec_billboard.SetWidget(self.my_widget)
		
		self.size_timer = QTimer()
		self.size_timer.connect("timeout()", self.animateSize)
		self.size_timer.start(100)
		 
		self.text_timer = QTimer()
		self.text_timer.connect("timeout()", self.animateText)
		self.text_timer.start(1000)
Example #5
0
	def __init__(self, info):
		self.info = info
		if naali: self.entity = naali.createEntity()#; print( self.entity, dir(self.entity) )
		else: self.entity = tundra.Helper().CreateEntity()
		#self.entity.SetName( info['object'] )
		self.components = {}
		extras = []

		T = info[ P.type ]
		self.data_name = info[ P.data ][ P.name ]

		if T == 'MESH':
			extras.append( 'EC_Mesh' )
			self._mesh_url = 'local://%s.mesh' %self.data_name
			self._materials = info['materials']

		elif T == 'LAMP':
			extras.append( 'EC_Light' )

		#EC_TransformGizmo
		for tag in 'EC_Name EC_Placeable'.split() + extras:
			ec = self.entity.GetOrCreateComponentRaw( tag )
			self.components[ tag ] = ec
			setattr( self, tag, ec )
			print( ec, dir(ec) )

			if tag == 'EC_Light':
				ec.castShadows = True
				print( ec.diffColor, dir(ec.diffColor) )
				ec.constAtten = 1.0	# sane default

			if tag == 'EC_Mesh':
				print( '-'*80 )
				ec.SetMeshRef( self._mesh_url )
				#matname = ec.GetMaterialName( index )
				#print( 'EC_MESH - material name', matname )
				print( ec.meshMaterial, dir(ec.meshMaterial) )
				for i,matname in enumerate(self._materials):
					#u = 'local:///tmp/%s.material' %matname
					u = 'local://%s.material' %matname
					print( 'SETTING MATERIAL', u )
					#assert ec.SetMaterial( i, u )
					ec.SetMaterial( i, u )
Example #6
0
if 0: #local object creation, testing if local previews of .scenes would work
    from PythonQt.QtGui import QVector3D as Vec3
    from PythonQt.QtGui import QQuaternion as Quat

    print "hep"
    e = r.createEntity("Jack.mesh", 1515)
    print e
    e.placeable.Position = Vec3(128, 128, 60)
    e.placeable.Scale = Vec3(5, 5, 5)
    e.placeable.Orientation = Quat(0, 0, 0, 1)

if 0: #createentity directly from the c++ scenemanager where it's a qt slot now
    #s = naali.getDefaultScene()
    #id = s.NextFreeId()
    #ent = s.CreateEntityRaw(id)
    ent = naali.createEntity()
    print "new entity created:", ent, ent.Id

if 0: #running localscene dotscene loader
    import localscene.loader
    localscene.loader = reload(localscene.loader)

    filename = "pymodules/localscene/test.scene"
    localscene.loader.load_dotscene(filename)

    #avatar = r.getEntity(r.getUserAvatarId())
    #print avatar.placeable.Position.toString()

if 0: #loadurl handler import test
    import loadurlhandler
    loadurlhandler = reload(loadurlhandler)
Example #7
0
    def do_api_calls(self):
        yield "createMeshEntity"
        e = naali.createMeshEntity("axes.mesh")

        from PythonQt.QtGui import QVector3D, QQuaternion
        e.placeable.position = QVector3D(128, 128, 60)
        e.placeable.Scale = QVector3D(5, 5, 5)
        e.placeable.Orientation = QQuaternion(0, 0, 0, 1)
        r.removeEntity(e.Id)

        yield "EC_Touchable & EC_Highlight"
        for longname, shortname in [("EC_Touchable", 'touchable'), ("EC_Highlight", 'highlight')]:
            e = naali.getUserAvatar()
            e.GetOrCreateComponentRaw(longname)
            x = getattr(e, shortname)
            x.Show()
            x.Hide()
            assert x.IsVisible() == False

        yield "naali.createEntity"
        ent = naali.createEntity()
        print "new entity created:", ent

        yield "get camera FOV"
        fov = naali.getCamera().camera.GetVerticalFov()
        
        yield "avatar position"
        p = naali.getUserAvatar().placeable.position

        yield "avatar animation controller"
        naali.getUserAvatar().animationcontroller.EnableAnimation("Walk")

        yield "test sendChat"
        r.sendChat("test chat")

        yield "test logInfo"
        r.logInfo("test log message")

        #XXX deprecate
        yield "test camera yaw/itch"
        r.setCameraYawPitch(.1, .5)
        r.getCameraYawPitch()
        
        yield "test webview"
        import PythonQt
        wv = PythonQt.QtWebKit.QWebView()
        wv.show()

        yield "test dotscene loading"
        from localscene import loader
        loader.load_dotscene("pymodules/localscene/test.scene")
    
        yield "test dynamic component"
        ent = naali.getUserAvatar()
        ent.GetOrCreateComponentRaw("EC_DynamicComponent")
        print ent, type(ent)
        d = ent.EC_DynamicComponent
        d.CreateAttribute("real", 42.0)
        d.ComponentChanged(0)
        d.SetAttribute("real", 8.5)
        d.ComponentChanged(0)
        d.RemoveAttribute("real")
        d.ComponentChanged(0)

        yield "test javascript"
        cam = naali.getCamera()
        naali.runjs('print("Hello from JS! " + x)', {'x': naali.renderer})
        naali.runjs('print("Another hello from JS! " + x)', {'x': naali.inputcontext})
        naali.runjs('print("Some camera! " + x)', {'x': cam.camera})
        #py objects are not qobjects. naali.runjs('print("Some camera, using naali :O ! " + x.getCamera())', {'x': naali})
        naali.runjs('print("Camera Entity " + x)', {'x': cam})
        naali.runjs('print("Camera placeable pos: " + pos)', {'pos': cam.placeable.position})
        #not exposed yet. naali.runjs('print("QVector3D: " + new QVector3D())', {})
        #naali.runjs('var a = {"a": true, "b": 2};')
        #naali.runjs('print(a.a + ", " + a.b)')
        #naali.runjs('print(JSON.stringify(a))')
        #naali.runjs('print("1 + 1 == " + 1 + 1)')
        #naali.runjs('print("1 - 1 == " + 1 - 1)')
        print ", done."

        if 0:
            runjs('var b = new QPushButton;')
            runjs('b.text = "hep";')
            runjs('b.show();')
Example #8
0
    def do_api_calls(self):
        yield "createMeshEntity"
        e = naali.createMeshEntity("axes.mesh")

        from PythonQt.QtGui import QVector3D, QQuaternion
        e.placeable.position = QVector3D(128, 128, 60)
        e.placeable.Scale = QVector3D(5, 5, 5)
        e.placeable.Orientation = QQuaternion(0, 0, 0, 1)
        r.removeEntity(e.Id)

        yield "EC_Touchable & EC_Highlight"
        for longname, shortname in [("EC_Touchable", 'touchable'),
                                    ("EC_Highlight", 'highlight')]:
            e = naali.getUserAvatar()
            e.GetOrCreateComponentRaw(longname)
            x = getattr(e, shortname)
            x.Show()
            x.Hide()
            assert x.IsVisible() == False

        yield "naali.createEntity"
        ent = naali.createEntity()
        print "new entity created:", ent

        yield "get camera FOV"
        fov = naali.getCamera().camera.GetVerticalFov()

        yield "avatar position"
        p = naali.getUserAvatar().placeable.position

        yield "avatar animation controller"
        naali.getUserAvatar().animationcontroller.EnableAnimation("Walk")

        yield "test sendChat"
        r.sendChat("test chat")

        yield "test logInfo"
        r.logInfo("test log message")

        #XXX deprecate
        yield "test camera yaw/itch"
        r.setCameraYawPitch(.1, .5)
        r.getCameraYawPitch()

        yield "test webview"
        import PythonQt
        wv = PythonQt.QtWebKit.QWebView()
        wv.show()

        yield "test dotscene loading"
        from localscene import loader
        loader.load_dotscene("pymodules/localscene/test.scene")

        yield "test dynamic component"
        ent = naali.getUserAvatar()
        ent.GetOrCreateComponentRaw("EC_DynamicComponent")
        print ent, type(ent)
        d = ent.EC_DynamicComponent
        d.CreateAttribute("real", 42.0)
        d.ComponentChanged(0)
        d.SetAttribute("real", 8.5)
        d.ComponentChanged(0)
        d.RemoveAttribute("real")
        d.ComponentChanged(0)

        yield "test javascript"
        cam = naali.getCamera()
        naali.runjs('print("Hello from JS! " + x)', {'x': naali.renderer})
        naali.runjs('print("Another hello from JS! " + x)',
                    {'x': naali.inputcontext})
        naali.runjs('print("Some camera! " + x)', {'x': cam.camera})
        #py objects are not qobjects. naali.runjs('print("Some camera, using naali :O ! " + x.getCamera())', {'x': naali})
        naali.runjs('print("Camera Entity " + x)', {'x': cam})
        naali.runjs('print("Camera placeable pos: " + pos)',
                    {'pos': cam.placeable.position})
        #not exposed yet. naali.runjs('print("QVector3D: " + new QVector3D())', {})
        #naali.runjs('var a = {"a": true, "b": 2};')
        #naali.runjs('print(a.a + ", " + a.b)')
        #naali.runjs('print(JSON.stringify(a))')
        #naali.runjs('print("1 + 1 == " + 1 + 1)')
        #naali.runjs('print("1 - 1 == " + 1 - 1)')
        print ", done."

        if 0:
            runjs('var b = new QPushButton;')
            runjs('b.text = "hep";')
            runjs('b.show();')
Example #9
0
if 0:  #local object creation, testing if local previews of .scenes would work
    from PythonQt.QtGui import QVector3D as Vec3
    from PythonQt.QtGui import QQuaternion as Quat

    print "hep"
    e = r.createEntity("Jack.mesh", 1515)
    print e
    e.placeable.Position = Vec3(128, 128, 60)
    e.placeable.Scale = Vec3(5, 5, 5)
    e.placeable.Orientation = Quat(0, 0, 0, 1)

if 0:  #createentity directly from the c++ scenemanager where it's a qt slot now
    #s = naali.getDefaultScene()
    #id = s.NextFreeId()
    #ent = s.CreateEntityRaw(id)
    ent = naali.createEntity()
    print "new entity created:", ent, ent.Id

if 0:  #running localscene dotscene loader
    import localscene.loader
    localscene.loader = reload(localscene.loader)

    filename = "pymodules/localscene/test.scene"
    localscene.loader.load_dotscene(filename)

    #avatar = r.getEntity(r.getUserAvatarId())
    #print avatar.placeable.Position.toString()

if 0:  #loadurl handler import test
    import loadurlhandler
    loadurlhandler = reload(loadurlhandler)