Skip to content
Jiri Hnidek edited this page Jul 6, 2014 · 5 revisions

Instances of VerseLayer are used for creating new layers at Verse server. Layers can be used for sharing arrays, sparse matrixes, vectores, etc. When other client creates layer in subscribed node, then instance of VerseLayer is automatically created and stored in dictionary node.layers (key is id of layer).

Creating of Layers

New VerseLayer can be created using following code:

import vrsent
import verse as vas
session = vrsent.VerseSession(hostname='localhost', service='12345', \
    callback_thread=True, username='joe', password='pass')
# Create node that will contain layer
node = vrsent.VerseNode(session, custom_type=100)
# Create layer
layer = vrsent.VerseLayer(node=node, \
                parent_layer=None, \
                data_type=vrs.VALUE_TYPE_UINT8, \
                count=1,
                custom_type=128)
while(session.state != 'DISCONNECTED'):
    session.callback_update()
    time.sleep(1.0/session.fps)

Adding/Changing Items of Layer

When layer is created, then you can add items to the layer. Item of layer can be only tuple and tuple can contain max 4 values of int/float. You can add item to layer using following code:

layer.items[0] = (1.0, -1.0, 0.0)

Keep in mind that item of layer has to be tuple. When we want to have item only with one scalar value, then we has to use one item tuple:

other_layer.items[0] = (1.0,)

The layer.items is subclass of dictionary. Assigning value to the item automatically sends value to the Verse server.

When we want to change some existing item layer.items[0] = (0,), then we use same code: layer.items[0] = (0,).

Deleting of Items

When we want to "delete" (better term is unset) some item of layer, then we simply remove item from layer using pop():

# Add two items to layer
layer.items[0] = (1, 0, 0)
layer.items[1] = (0, 1, 0)
# Remove second item from layer
layer.pop(1)

Examples of Code

Clone this wiki locally