def set_world_object(self, world_object): object_name = world_object.name if hasattr(world_object, "transform"): object_data = to_shape3d(world_object.transform()) else: object_data = to_shape3d(world_object) self.object_repr[object_name] = object_data if isinstance(object_data,Scene): self.add_scene(world_object, object_data, **world_object.kwargs)
def setScene(self, scenes): """ Set the scene (erase old scene if necessary) :param scene: dict with every sub-scenes to add """ self.scene.clear() for s in scenes: world_obj = scenes[s] if isinstance(world_obj, WorldObject): if hasattr(world_obj, "transform"): obj = to_shape3d(world_obj.transform()) if world_obj.in_scene: obj = to_shape3d(world_obj) else: obj = None else: obj = to_shape3d(world_obj) if obj: self.scene += to_shape3d(obj) self.draw()
from openalea.oalab.service.geometry import to_shape3d, register_shape3d class MyObject(object): def __init__(self, n): self.points = numpy.random.randn(n, 3) * 100 self.colors = zip(numpy.random.randint(0, 255, n).tolist(), numpy.random.randint(0, 255, n).tolist(), numpy.random.randint(0, 255, n).tolist()) def myobjectIn3d(obj): return PointSet(obj.points, colorList=Color4Array(map(Color4, obj.colors))) register_shape3d(MyObject, myobjectIn3d) if __name__ == '__main__': from openalea.vpltk.qt import QtGui instance = QtGui.QApplication.instance() if instance is None : app = QtGui.QApplication([]) else : app = instance t = MyObject(100) Viewer.display(to_shape3d(t)) if instance is None : app.exec_()
class MyObject(object): def __init__(self, n): self.points = numpy.random.randn(n, 3) * 100 self.colors = zip( numpy.random.randint(0, 255, n).tolist(), numpy.random.randint(0, 255, n).tolist(), numpy.random.randint(0, 255, n).tolist()) def myobjectIn3d(obj): return PointSet(obj.points, colorList=Color4Array(map(Color4, obj.colors))) register_shape3d(MyObject, myobjectIn3d) if __name__ == '__main__': from openalea.vpltk.qt import QtGui instance = QtGui.QApplication.instance() if instance is None: app = QtGui.QApplication([]) else: app = instance t = MyObject(100) Viewer.display(to_shape3d(t)) if instance is None: app.exec_()