Copyright (c) 2011 The Substance Project. All Rights Reserved. Licensed under the GNU LGPL. For full terms see the file COPYING or visit http://fsf.org
Contributors:
Clemens Klokmose: clemens@klokmose.net
from substance.environment.bootstrap import *
from substance.std.sharing.sharer import Sharer
from substance.std.sharing.mounter import Mounter
from image_broker import ImageBroker
This environment creates a scene graph, discovers a renderer which is shares the scenegraph with. The environment furthermore launches a webservices that will let you add images to the scenegraph on http://localhost:3444/
class Main(Facet):
We create our scene graph
scenegraph = local.new_child(self, "Scenegraph", "This is the root node of the scenegraph for WILD")
The scenegraph has a subtree of cursors
cursors = scenegraph.new_child(self, "cursors", "a directory for all active cursors")
It maintains a stackingorder of the displayed elements
scenegraph.new_value(self, "stacking_order", "The Z-axis stacking order of the gui elements", [])
Now the scenegraph is shared on the network
scenegraph.add_facet(self, Sharer())
scenegraph.Sharer.share(self, "SceneGraph", "Our scenegraph", "substance.examples")
Now we want to mount a renderer to display the scenegraph When calling the mount method we pass along a path that is used as callback when the renderer is found The mounter (and replicator as well) assumes two callback handlers share_mounted and share_disappeared
local.add_facet(self, Mounter())
local.Mounter.mount(self, "Renderer", "substance.renderers", self.get_path())
We set up a webserver for adding images to the scenegraph This can be accessed on http://localhost:3444 It is possible to add png, jpg and pdf
self.ib = local.new_child(self, "ImageBroker", "A webserver for adding images")
self.ib.set_dependency(self, "SceneGraph", scenegraph)
self.ib.add_facet(self, ImageBroker(3444))
This handler is called when the mounter mounts the share
@Facet.HANDLER("<void>::<share:string>:<domain:string>")
When the renderer is mounted we ask it to replicate our scenegraph Note that we provide coordinates for the the lower left corner of the area the renderer will render With outset in that corner the renderer renders an area matching its resolution This means that for a large scenegraph multiple renderers can render each a portion of it
renderer = share_path
renderer.CanvasNode.replicate_scenegraph(self, "SceneGraph", "substance.examples", 0, 0)
This handler is called when our mounted share is disconnected
@Facet.HANDLER("<void>::<share:string>:<domain:string>")
The standard bootstrapping
boot_std_default(name = "Main", description = "Substance Rendering")
boot.add_facet(Main(), environment / "app")
done_boot()