예제 #1
0
 def call(self, model, tree):
     args = tree.value[1:]
     ret = None
     while interp.isTrue(interp.getv(interp.interpret(model, args[0]))):
         for arg in args[1:]:
             ret = interp.interpret(model, arg)
     return ret
예제 #2
0
    def call(self, model, sprocket_list, continuous = interp.lcad_t):

        # Keywords
        continuous = True if interp.isTrue(continuous) else False

        # Get list of sprockets.
        if (len(sprocket_list) < 2):
            raise NumberSprocketsException(len(sprocket_list))

        # Create sprockets.
        chain = belt.Belt(continuous)
        for sprocket in sprocket_list:
        
            if not isinstance(sprocket, list):
                raise lcadExceptions.WrongTypeException("list", type(sprocket))

            if (len(sprocket) != 4):
                raise SprocketException(len(sprocket))

            for elt in sprocket:
                if not isinstance(elt, numbers.Number):
                    raise lcadExceptions.WrongTypeException("number", type(elt))

            chain.addSprocket(belt.Sprocket([sprocket[0], sprocket[1], 0], [0, 0, 1],
                                            sprocket[2], sprocket[3]))

        chain.finalize()

        # Return chain function.
        return curveFunctions.CurveFunction(chain, "user created chain function.")
예제 #3
0
    def call(self, model, m1, v1, m2, v2, ccw):
        group = model.curGroup()
        matrix = group.matrix()

        m1 = numpy.dot(matrix, m1)
        m2 = numpy.dot(matrix, m2)

        p1 = numpy.dot(m1, v1)
        p2 = numpy.dot(m2, v2)
        if interpreter.isTrue(ccw):
            for mz in self.matrices:            
                p3 = numpy.dot(m1, numpy.dot(mz, v1))
                p4 = numpy.dot(m2, numpy.dot(mz, v2))
                group.addPart(parts.Triangle(None, numpy.append(p1[0:3], [p2[0:3], p3[:3]]), 16), True)
                group.addPart(parts.Triangle(None, numpy.append(p3[0:3], [p2[0:3], p4[:3]]), 16), True)
                p1 = p3
                p2 = p4
        else:
            for mz in self.matrices:            
                p3 = numpy.dot(m1, numpy.dot(mz, v1))
                p4 = numpy.dot(m2, numpy.dot(mz, v2))
                group.addPart(parts.Triangle(None, numpy.append(p2[:3], [p1[:3], p3[:3]]), 16), True)
                group.addPart(parts.Triangle(None, numpy.append(p2[:3], [p3[:3], p4[:3]]), 16), True)
                p1 = p3
                p2 = p4
예제 #4
0
 def call(self, model, tree):
     args = tree.value[1:]
     if interp.isTrue(interp.getv(interp.interpret(model, args[0]))):
         return interp.interpret(model, args[1])
     else:
         if (len(args)==3):
             return interp.interpret(model, args[2])
         else:
             return interp.lcad_nil
예제 #5
0
 def call(self, model, tree):
     args = tree.value[1:]
     ret = interp.lcad_nil
     for arg in args:
         nodes = arg.value
         if interp.isTrue(interp.getv(interp.interpret(model, nodes[0]))):
             for node in nodes[1:]:
                 ret = interp.interpret(model, node)
             return ret
     return ret
예제 #6
0
    def call(self, model, arg):

        # If arg is t return the curve length.
        if not isinstance(arg, numbers.Number):
            if interp.isTrue(arg):
                return self.curve.getLength()
            else:
                return interp.lcad_nil

        # Return transform matrix.
        return self.curve.getMatrix(arg)
예제 #7
0
    def call(self, model, pulley_list, continuous = interp.lcad_t):

        # Keywords
        continuous = True if interp.isTrue(continuous) else False

        # Get list of pulleys.
        if (len(pulley_list) < 2):
            raise NumberPulleysException(len(pulley_list))

        # Create belt.
        belt = Belt(continuous)
        for pulley in pulley_list:
            belt.addSprocket(Sprocket(*parsePulley(pulley)))
            
        belt.finalize()

        # Return belt function.
        return curveFunctions.CurveFunction(belt, "user created belt function.")
예제 #8
0
    def call(self, model, controlp_list, **kwargs):

        # Keyword defaults.
        auto_scale = True if interp.isTrue(kwargs["auto-scale"]) else False
        extrapolate = True if interp.isTrue(kwargs["extrapolate"]) else False
        scale = kwargs["scale"]
        twist = kwargs["twist"]

        # Process control points.
        if (len(controlp_list) < 2):
            raise NumberControlPointsException(len(controlp_list))

        control_points = []
        for i in range(len(controlp_list)):

            # Get list of control point vectors.
            control_point = controlp_list[i]

            if not isinstance(control_point, list):
                raise lcadExceptions.WrongTypeException(
                    "list", type(control_point))

            if (i == 0):
                if (len(control_point) != 3):
                    raise ControlPointException(
                        "First control point must include a perpendicular vector."
                    )
            else:
                if (len(control_point) != 2):
                    raise ControlPointException(
                        "Control point must have a location and a derivative (tangent) vector."
                    )

            # Process control point vectors.
            vals = []
            for j in range(len(control_point)):
                vec = control_point[j]

                if (len(vec) != 3):
                    raise ControlPointException(
                        "Control point vector must have 3 elements")

                if isinstance(vec, list):
                    for k in range(3):
                        if not isinstance(vec[k], numbers.Number):
                            raise lcadExceptions.WrongTypeException(
                                "number", type(vec[k]))
                        vals.append(vec[k])

                elif isinstance(vec, numpy.ndarray):
                    for k in range(3):
                        vals.append(vec[k])

                else:
                    raise lcadExceptions.WrongTypeException(
                        "list, numpy.ndarray", type(vec))

            # Check that tangent is not zero.
            tx = vals[3]
            ty = vals[4]
            tz = vals[5]
            if ((tx * tx + ty * ty + tz * tz) < 1.0e-3):
                raise TangentException()

            # Create control point.
            control_points.append(ControlPoint(*vals))

        # Create curve.
        curve = Curve(auto_scale, extrapolate, scale, twist)
        for i in range(len(control_points) - 1):
            curve.addSegment(control_points[i], control_points[i + 1])

        # Return curve function.
        return curveFunctions.CurveFunction(curve,
                                            "user created curve function.")
예제 #9
0
 def call(self, model, val):
     if interp.isTrue(val):
         return interp.lcad_nil
     else:
         return interp.lcad_t
예제 #10
0
 def call(self, model, tree):
     for i in range(self.numberArgs(tree)):
         if interp.isTrue(self.getArg(model, tree, i)):
             return interp.lcad_t
     return interp.lcad_nil
예제 #11
0
    def call(self, model, controlp_list, **kwargs):

        # Keyword defaults.
        auto_scale = True if interp.isTrue(kwargs["auto-scale"]) else False
        extrapolate = True if interp.isTrue(kwargs["extrapolate"]) else False
        scale = kwargs["scale"]
        twist = kwargs["twist"]

        # Process control points.
        if (len(controlp_list) < 2):
            raise NumberControlPointsException(len(controlp_list))

        control_points = []
        for i in range(len(controlp_list)):

            # Get list of control point vectors.
            control_point = controlp_list[i]

            if not isinstance(control_point, list):
                raise lcadExceptions.WrongTypeException("list", type(control_point))

            if (i == 0):
                if (len(control_point) != 3):
                    raise ControlPointException("First control point must include a perpendicular vector.")
            else:
                if (len(control_point) != 2):
                    raise ControlPointException("Control point must have a location and a derivative (tangent) vector.")

            # Process control point vectors.
            vals = []
            for j in range(len(control_point)):
                vec = control_point[j]
                
                if (len(vec) != 3):
                    raise ControlPointException("Control point vector must have 3 elements")
            
                if isinstance(vec, list):
                    for k in range(3):
                        if not isinstance(vec[k], numbers.Number):
                            raise lcadExceptions.WrongTypeException("number", type(vec[k]))
                        vals.append(vec[k])

                elif isinstance(vec, numpy.ndarray):
                    for k in range(3):
                        vals.append(vec[k])

                else:
                    raise lcadExceptions.WrongTypeException("list, numpy.ndarray", type(vec))

            # Check that tangent is not zero.
            tx = vals[3]
            ty = vals[4]
            tz = vals[5]
            if ((tx*tx + ty*ty + tz*tz) < 1.0e-3):
                raise TangentException()

            # Create control point.
            control_points.append(ControlPoint(*vals))

        # Create curve.
        curve = Curve(auto_scale, extrapolate, scale, twist)
        for i in range(len(control_points)-1):
            curve.addSegment(control_points[i], control_points[i+1])

        # Return curve function.
        return curveFunctions.CurveFunction(curve, "user created curve function.")
예제 #12
0
 def call(self, model, val):
     if interp.isTrue(val):
         return interp.lcad_nil
     else:
         return interp.lcad_t
예제 #13
0
 def call(self, model, tree):
     for i in range(self.numberArgs(tree)):
         if interp.isTrue(self.getArg(model, tree, i)):
             return interp.lcad_t
     return interp.lcad_nil