[SOLVED] Transforming a custom tracker's geometry (coin issue)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

[SOLVED] Transforming a custom tracker's geometry (coin issue)

Post by Joel_graff »

I'm trying to sort out how to apply transformations to a custom wire tracker I'm creating. I can generate / regenerate the wire by supplying coordinates, but I cannot apply transforms...

The class I've created thus far:

Code: Select all

class DragTracker(Tracker):
    """
    Customized wire tracker
    """

    def __init__(self, points):
        """
        Constructor
        """

        self.line = coin.SoLineSet()
        self.line.numVertices.setValue(len(points))

        self.coords = coin.SoCoordinate3()

        self.transform = coin.SoTransform()

        self.update(points)

        Tracker.__init__(
            self, children=[self.coords, self.line, self.transform], name="DragTracker"
        )

        self.node = self.switch.getChild(0)
        self.draw_style = self.node.getChild(0)
        self.color = self.node.getChild(1)

        self.color.rgb = (0.0, 0.0, 0.0)

        self.on()

    def update(self, points):
        """
        Update
        """

        if not points:
            return

        self.line.numVertices.setValue(len(points))

        for _i, _pt in enumerate(points):
            self.coords.point.set1Value(_i, list(_pt))

    def set_placement(self, placement):
        """
        Transform the tracker by the passed placement
        """

        vec = placement.Base

        self.transform.translation.setValue(tuple(vec))
The idea is simply to call the tracker's set_placement() method and apply the base vector to the transform node of the tracker. Unfortunately, nothing happens...
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: [SOLVED] Transforming a custom tracker's geometry (coin issue)

Post by Joel_graff »

Solved by re-ordering the nodes that are added for the tracker. Specifically, transformation and coordinate nodes need to precede the geometry node which they define.

Thus:

Code: Select all

 Tracker.__init__(
            self, children=[self.coords, self.line, self.transform], name="DragTracker"
        )
becomes:

Code: Select all

 Tracker.__init__(
            self, children=[self.coords, self.transform, self.Line], name="DragTracker"
        )
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Post Reply