Ejemplo n.º 1
0
def write_collada_scene(world,
                        dae_filename,
                        scale=1,
                        options=None,
                        flat=False,
                        color_generator=None):
    """
    """
    assert isinstance(world, World)
    if flat:
        name_all_elements(world.getbodies(), True)
    else:
        nonflatlist = [j.frames[1] for j in world.getjoints()]
        name_all_elements(nonflatlist, True)
    name_all_elements(world.itermovingsubframes(), True)

    if color_generator is None:
        color_generator = ColorGenerator(nb_colors=len(world.getbodies()))

    world.update_geometric()

    drawer = Drawer(pydaenimColladaDriver(dae_filename, scale, options), flat,
                    color_generator)
    world.parse(drawer)
    drawer.finish()
Ejemplo n.º 2
0
    def init(self, world, timeline):
        """
        """
        if self.daefile is None:
            tmp_daefile = tempfile.mkstemp(suffix='scene.dae', text=True)[1]
            write_collada_scene(world, tmp_daefile, flat=self.flat)
            self.app_call[1] = tmp_daefile

        try:
            subprocess.Popen(self.app_call)
            SocketCom.init(self, world, timeline)
        except OSError:
            warnings.warn(
                "Cannot find program " + self.app_call[0] +
                ". Please check where the arboris viewer (daenim) is installed on your computer."
            )

        self.world = world
        sleep(.1)
        if self.flat:
            name_all_elements(self.world.getbodies(), True)
        else:
            nonflatlist = [j.frames[1] for j in self.world.getjoints()]
            name_all_elements(nonflatlist, True)
        name_all_elements(self.world.itermovingsubframes(), True)
Ejemplo n.º 3
0
def write_collada_scene(world, dae_filename, scale=1, options=None, flat=False, color_generator=None):
    """Write a visual description of the scene in a collada file.

    :param world: the world to convert
    :type world: :class:`arboris.core.World` instance
    :param dae_filename: path of the output collada scene file
    :type dae_filename: str
    :param scale: the scale of the world
    :type scale: float
    :param options: the options to set the world drawing
    :type options: dict
    :param flat: if True, each body is a child of the ground. Otherwise
                 the hierarchy is copied from arboris
    :type flat: bool

    """
    assert isinstance(world, World)
    if flat:
        name_all_elements(world.getbodies(), True)
    else:
        nonflatlist = [j.frames[1] for j in world.getjoints()]
        name_all_elements(nonflatlist, True)
    name_all_elements(world.itermovingsubframes(), True)
    
    if color_generator is None:
        color_generator = ColorGenerator( nb_colors=len(world.getbodies()) )
    
    world.update_geometric()
    
    drawer = Drawer(DaenimColladaDriver(dae_filename, scale, options), flat, color_generator)
    world.parse(drawer)
    drawer.finish()
Ejemplo n.º 4
0
    def init(self, world, timeline):
        self._world = world
        self._nb_steps = len(timeline) - 1
        self._current_step = 0
        self._root = {}
        self._timeline = zeros(self._nb_steps)
        self._root["timeline"] = self._timeline

        if self._save_state:
            self._gpositions = {}
            self._gvelocities = {}
            self._root['gpositions'] = self._gpositions
            self._root['gvelocities'] = self._gvelocities
            name_all_elements(self._world.getjoints(), check_unicity=True)
            for j in self._world.getjoints():
                self._gpositions[j.name] = zeros((self._nb_steps, ) +
                                                 j.gpos.shape[:])
                self._gvelocities[j.name] = zeros((self._nb_steps, j.ndof))

        if self._save_transforms:
            self._arb_transforms = {}
            self._transforms = {}
            self._root['transforms'] = self._transforms
            if self._flat:
                name_all_elements(self._world.iterbodies(), True)
                for b in self._world.iterbodies():
                    self._arb_transforms[b.name] = b
            else:
                nonflatlist = [j.frames[1] for j in self._world.getjoints()]
                name_all_elements(nonflatlist, True)
                for j in self._world.getjoints():
                    self._arb_transforms[j.frames[1].name] = j
            name_all_elements(self._world.itermovingsubframes(), True)

            for f in self._world.itermovingsubframes():
                self._arb_transforms[f.name] = f

            for k in self._arb_transforms.keys():
                self._transforms[k] = zeros((self._nb_steps, 4, 4))

        if self._save_model:
            ndof = self._world.ndof
            self._model = {}
            self._root['model'] = self._model
            self._model["gvel"] = zeros((self._nb_steps, ndof))
            self._model["mass"] = zeros((self._nb_steps, ndof, ndof))
            self._model["admittance"] = zeros((self._nb_steps, ndof, ndof))
            self._model["nleffects"] = zeros((self._nb_steps, ndof, ndof))
            self._model["gforce"] = zeros((self._nb_steps, ndof))
Ejemplo n.º 5
0
def write_collada_scene(world, dae_filename, scale=1, options=None, flat=False, color_generator=None):
    """
    """
    assert isinstance(world, World)
    if flat:
        name_all_elements(world.getbodies(), True)
    else:
        nonflatlist = [j.frames[1] for j in world.getjoints()]
        name_all_elements(nonflatlist, True)
    name_all_elements(world.itermovingsubframes(), True)

    if color_generator is None:
        color_generator = ColorGenerator(nb_colors=len(world.getbodies()))

    world.update_geometric()

    drawer = Drawer(pydaenimColladaDriver(dae_filename, scale, options), flat, color_generator)
    world.parse(drawer)
    drawer.finish()
Ejemplo n.º 6
0
    def init(self, world, timeline):
        """
        """
        if self.daefile is None:
            tmp_daefile = tempfile.mkstemp(suffix='scene.dae', text=True)[1]
            write_collada_scene(world, tmp_daefile, flat=self.flat)
            self.app_call[1] = tmp_daefile

        try:
            subprocess.Popen(self.app_call)
            SocketCom.init(self, world, timeline)
        except OSError:
            warnings.warn("Cannot find program "+self.app_call[0]+". Please check where the arboris viewer (daenim) is installed on your computer.")
        
        self.world = world
        sleep(.1)
        if self.flat:
            name_all_elements(self.world.getbodies(), True)
        else:
            nonflatlist = [j.frames[1] for j in self.world.getjoints()]
            name_all_elements(nonflatlist, True)
        name_all_elements(self.world.itermovingsubframes(), True)
Ejemplo n.º 7
0
def write_collada_scene(world,
                        dae_filename,
                        scale=1,
                        options=None,
                        flat=False,
                        color_generator=None):
    """Write a visual description of the scene in a collada file.

    :param world: the world to convert
    :type world: :class:`arboris.core.World` instance
    :param dae_filename: path of the output collada scene file
    :type dae_filename: str
    :param scale: the scale of the world
    :type scale: float
    :param options: the options to set the world drawing
    :type options: dict
    :param flat: if True, each body is a child of the ground. Otherwise
                 the hierarchy is copied from arboris
    :type flat: bool

    """
    assert isinstance(world, World)
    if flat:
        name_all_elements(world.getbodies(), True)
    else:
        nonflatlist = [j.frames[1] for j in world.getjoints()]
        name_all_elements(nonflatlist, True)
    name_all_elements(world.itermovingsubframes(), True)

    if color_generator is None:
        color_generator = ColorGenerator(nb_colors=len(world.getbodies()))

    world.update_geometric()

    drawer = Drawer(DaenimColladaDriver(dae_filename, scale, options), flat,
                    color_generator)
    world.parse(drawer)
    drawer.finish()