Esempio n. 1
0
    def createGizmo(self, angleDegrees=360, numSteps=16, axis=0, scale=10):
        data = EggData()

        vp = EggVertexPool('fan')
        data.addChild(vp)

        poly = EggPolygon()
        data.addChild(poly)

        v = EggVertex()
        v.setPos(Point3D(0, 0, 0))
        poly.addVertex(vp.addVertex(v))

        angleRadians = deg2Rad(angleDegrees)

        for i in range(numSteps + 1):
            a = angleRadians * i / numSteps
            y = math.sin(a) * scale
            x = math.cos(a) * scale
            v = EggVertex()
            if axis is 0:
                v.setPos(Point3D(x, 0, y))
            elif axis is 1:
                v.setPos(Point3D(x, y, 0))
            else:
                v.setPos(Point3D(0, x, y))
            poly.addVertex(vp.addVertex(v))
        node = loadEggData(data)
        return NodePath(node)
Esempio n. 2
0
    def update(self, state: MachineState):
        """Update this state.

        Parameters
        ----------
        state : MachineState
            The new state to update this state with.
        """
        self.position = Point3D(state.position)
        self.offset_position = Point3D(state.offset_position)
        self.extruder = state.extruder
        self.offset_extruder = state.offset_extruder
        self.feedrate = state.feedrate
        self.temp_extruder = state.feedrate
        self.is_rel_positioning = state.is_rel_positioning
        self.is_rel_extruder = state.is_rel_extruder
        self.is_imperial = state.is_imperial
Esempio n. 3
0
    def __init__(
        self,
        position: Point3D = Point3D(0, 0, 0),
        offset_position: Point3D = Point3D(0, 0, 0),
        extruder: float = 0,
        offset_extruder: float = 0,
        feedrate: float = 40,
        temp_extruder: float = 0,
        is_positioning_rel: bool = False,
        is_extruder_rel: bool = False,
        is_imperial: bool = False,
    ):
        """
        Parameters
        ----------
        position : Point3D, optional
            Absolute effector position, relative to origin.
        offset_position : Point3D, optional
            Offset from origin.
        extruder : float, optional
            Extruder value (E axis position).
        offset_extruder : float, optional
            Extruder value (E axis position) offset.
        feedrate : float, optional
            Effector translation feedrate in mm/s.
        temp_extruder : float, optional
            Extruder temperature (degrees C).
        is_positioning_rel : bool, optional
            Defines whether relative effector positioning is enabled.
        is_extruder_rel : bool, optional
            Defines whether relative extruder value is enabled.
        is_imperial : bool, optional
            Defines whether the used unit system is imperial (inches).

        Default values are based on RepRapFirmware defaults.
        """
        self.position = position
        self.offset_position = offset_position
        self.extruder = extruder
        self.offset_extruder = offset_extruder
        self.feedrate = feedrate
        self.temp_extruder = temp_extruder
        self.is_rel_positioning = is_positioning_rel
        self.is_rel_extruder = is_extruder_rel
        self.is_imperial = is_imperial
Esempio n. 4
0
    def vertex(self,commande,Nb_Param):
        if (Nb_Param==4):
            x,y,z = float(commande[1]),float(commande[2]),float(commande[3])
            if (self.poly != None):
                #Creating a new vertex with coords :
                v = EggVertex()
                v.setPos(Point3D(x,y,z))

                #Adding the new Vertex to the polygon :
                self.poly.addVertex(self.vertexPool.addVertex(v))
Esempio n. 5
0
    def createCuttingPlanes(self):
        self.planes = self.render.attachNewNode("planes")
        pl = self.planes.attachNewNode("pl")
        data = EggData()
        self.planedata = []

        vp = EggVertexPool('plane')
        data.addChild(vp)

        fac = 1.0
        expanse = 10.0
        rng = 4
        for i in range(-rng, rng):
            poly = EggPolygon()
            data.addChild(poly)

            self.planedata.append(i * fac)

            v = EggVertex()
            v.setPos(Point3D(i * fac, -expanse, -expanse))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(i * fac, -expanse, +expanse))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(i * fac, +expanse, +expanse))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(i * fac, +expanse, -expanse))
            poly.addVertex(vp.addVertex(v))

        node = loadEggData(data)
        np = NodePath(node)
        np.reparentTo(pl)
        np.setColor(0, 1, 0, 1)
        np.setTwoSided(True)
        np.setTransparency(TransparencyAttrib.MAlpha)
        np.setAlphaScale(0.1)
        np.setCollideMask(BitMask32(0x0))
        return self.planes
Esempio n. 6
0
    def _move_to_origin(self, command: commands.G28):
        """Perform effector homing.

        Parameters
        ----------
        command: commands.G28
            G28 command.
        """
        if not any([command.x, command.y, command.z]):
            # No axes specified, home all axes
            self.state_current.offset_position = Point3D(0, 0, 0)
            self.state_current.position = Point3D(0, 0, 0)
            return

        # Selective axis homing
        if command.x:
            self.state_current.offset_position.x = 0
            self.state_current.position.x = 0
        if command.y:
            self.state_current.offset_position.y = 0
            self.state_current.position.y = 0
        if command.z:
            self.state_current.offset_position.z = 0
            self.state_current.position.z = 0
Esempio n. 7
0
    def _handle_move(self, command: Move):
        """Handle Move commands.

        Parameters
        ----------
        command : Move
            The Move command to handle.
        """
        # Handle feedrate
        if command.f is not None:
            self.state_current.feedrate = command.f

        # Handle extruder
        if command.e is not None:
            if self.state_previous.is_rel_extruder:
                # Relative
                self.state_current.extruder = self.state_previous.extruder + command.e
            else:
                # Absolute
                self.state_current.extruder = command.e

        # Handle position change
        if self.state_previous.is_rel_positioning:
            # Relative
            position_delta = Point3D(
                *[val or 0 for val in get_xyz_from_command(command)])
            self.state_current.position = self.state_previous.position + position_delta
            # Round to 3 decimal places, to compensate for computation errors
            self.state_current.position.x = round(
                self.state_current.position.x, 3)
            self.state_current.position.y = round(
                self.state_current.position.y, 3)
            self.state_current.position.z = round(
                self.state_current.position.z, 3)

        else:
            # Absolute
            if command.x is not None:
                self.state_current.position.x = (
                    command.x * self.state_previous.unit_multiplier)
            if command.y is not None:
                self.state_current.position.y = (
                    command.y * self.state_previous.unit_multiplier)
            if isinstance(command, LineMove) and command.z is not None:
                self.state_current.position.z = (
                    command.z * self.state_previous.unit_multiplier)
Esempio n. 8
0
 def __eggifyverts(self, eprim, evpool, vlist):
     for vertex in vlist:
         ixyz = vertex['v']
         vinfo = self.points[ixyz - 1]
         vxyz, _ = vinfo
         ev = EggVertex()
         ev.setPos(Point3D(vxyz[0], vxyz[1], vxyz[2]))
         iuv = vertex['vt']
         if iuv is not None:
             vuv = self.uvs[iuv - 1]
             ev.setUv(Point2D(vuv[0], vuv[1]))
         inormal = vertex['vn']
         if inormal is not None:
             vn = self.normals[inormal - 1]
             ev.setNormal(Vec3D(vn[0], vn[1], vn[2]))
         evpool.addVertex(ev)
         eprim.addVertex(ev)
     return self
Esempio n. 9
0
    def make_circle(self, num_steps):
        data = EggData()

        vertex_pool = EggVertexPool('fan')
        data.addChild(vertex_pool)

        poly = EggPolygon()
        data.addChild(poly)

        for i in range(num_steps + 1):
            angle = 2 * math.pi * i / num_steps
            y = math.sin(angle) * config.minimap.size / 2
            x = math.cos(angle) * config.minimap.size / 2

            vertex = EggVertex()
            vertex.setPos(Point3D(x, 0, y))
            poly.addVertex(vertex_pool.addVertex(vertex))

        node = loadEggData(data)
        return node
Esempio n. 10
0
 def readVecteur(self, data):
     v = EggVertex()
     x,y,z = struct.unpack('fff', data)        
     v.setPos(Point3D(x,y,z))
     return v 
Esempio n. 11
0
def makeVertex(vp, x, y, z):
    v = EggVertex()
    v.setPos(Point3D(x, y, z))
    vp.addVertex(v)
    return v