Ejemplo n.º 1
0
    def animate(self, time=None, rpc=None):
        """Updates the path from the world.  If the world wasn't a simulator, the time
        argument needs to be provided.

        If you want to include extra things, provide them in the rpc argument (as a list
        of KlamptFrontend rpc calls)
        """
        if self.sim is not None and time is None:
            time = self.sim.getTime()
            self.sim.updateWorld()
        if time is None:
            raise ValueError("Time needs to be provided")
        dt = time - self.last_t
        if self.dt == 0:
            self.dt = dt
        if self.dt == 0:
            return
        if abs(dt - self.dt) <= 1e-6:
            dt = self.dt
        numadd = 0
        while dt >= self.dt:
            numadd += 1
            if self.world is not None:
                transforms = json.loads(
                    robotsim.ThreeJSGetTransforms(self.world))
            else:
                transforms = {'object': []}
            for update in transforms['object']:
                n = update['name']
                mat = make_fixed_precision(update['matrix'], 4)
                matpath = self.transforms.setdefault(n, [])
                assert len(matpath) == len(self.rpc)
                lastmat = None
                for m in matpath[::-1]:
                    if m != None:
                        lastmat = m
                        break
                if lastmat != mat:
                    matpath.append(mat)
                else:
                    matpath.append(None)
            if numadd == 1:
                if rpc is not None:
                    assert isinstance(
                        rpc, (list,
                              tuple)), "rpc argument must be a list or a tuple"
                    self.rpc.append(rpc)
                else:
                    self.rpc.append(None)
            else:
                self.rpc.append(None)
            dt -= self.dt
            self.last_t += self.dt
        if numadd > 1:
            print(
                "HTMLSharePath: Note, uneven time spacing, duplicating frame",
                numadd, "times")
Ejemplo n.º 2
0
Archivo: html.py Proyecto: xyyeh/Klampt
 def animate(self,time=None):
     """Updates the path from the world.  If the world wasn't a simulator, the time
     argument needs to be provided"""
     if self.sim != None and time == None:
         time = self.sim.getTime()
         self.sim.updateWorld()
     dt = time - self.last_t
     if self.dt == 0:
         self.dt = dt
     if self.dt == 0:
         return
     if abs(dt - self.dt) <= 1e-6:
         dt = self.dt
     numadd = 0
     while dt >= self.dt:
         numadd += 1
         transforms = json.loads(robotsim.ThreeJSGetTransforms(self.world))
         for update in transforms['object']:
             n = update['name']
             mat = make_fixed_precision(update['matrix'],4)
             matpath = self.transforms.setdefault(n,[])
             assert len(matpath) == len(self.rpc)
             lastmat = None
             for m in matpath[::-1]:
                 if m != None:
                     lastmat = m
                     break
             if lastmat != mat:
                 matpath.append(mat)
             else:
                 matpath.append(None)
         self.rpc.append('null')
         dt -= self.dt
         self.last_t += self.dt
     if numadd > 1:
         print("Uneven time spacing, duplicating frame",numadd,"times")