ofNode and ofParameter

It seems that ofNode is storing its properties with ofParameters:

    ofParameter<glm::vec3> position;
    ofParameter<glm::quat> orientation;
    ofParameter<glm::vec3> scale;

Now, how can I add these to a parameter group to easily store them into a JSON/XML file? I don’t find a way to do so…

you can’t yet :slight_smile: i did that as a way to ensure that setting and removing a parent was safe since ofParameter handles all the listener stuff but not completely sure is the best way to go because of performance reasons so until it’s better tested and nobody complains that it’s slow it’s a private property and there’s no way to access it. if you want to change it in your code you can add some getters but be adviced that ofNode might change in the future and not use parameters.

Thank you Arturo.
I suspected there was a good reason for it to be like that.

So far i fixed it extending ofNode in a class where there is another ofParameter. I don-t like the idea of having two times the same thing and having to update back and forth… but it works…
So the new class looks like this:

class InteractiveNode : public ofNode {

void setup(glm::vec3 vector, float w, float h)
{
    getPositionParameter().setName(name);
    setPosition(vector);
    // add a listener so that we update things when parameters are loaded from file
    position.addListener(this, &InteractiveNode::_setPosition);
}

void _setPosition(glm::vec3 & vector)
{
    setPosition(vector);
}

    void customDraw();

    void onPositionChanged(){
        position.setWithoutEventNotifications(getPosition());
    };

    const string& getName() const;
    ofParameter<glm::vec3>& getPositionParameter() {
        return position;
    }

private:
    ofParameter<glm::vec3> position;
    string        name;
};

I also tried hacking ofNode class by adding a couple of public methods:

        ofParameter<glm::vec3>& getPositionParameter() {
            return position;
        }
        void updateMatrix() {
            createMatrix();
        }

This also worked and probably is better and faster… but i didn-t want to touch ofNode so far. Otherwise I would have to add get/setName() methods…

1 Like