Inherit from of3DPrimitive

I’ve written a class that generates a mesh, and I would like to inherit from of3dPrimitive but I’ve got an error: “drawNormals(): mesh normals are disabled”
I’ve done the following:

#pragma once

#include "ofMain.h"
#include "of3dPrimitives.h"

class ofxMyClass : public of3dPrimitive {
    void setup(); //
    void build();
    void draw();
    // ...

    // ...
    void              setMeshMode(string geometry);
    ofVboMesh         mesh;
    mutable ofMesh    normalsMesh;
    bool thetaValueIsinRange(float theta);
    bool isAxiomInRules(string _axiom, vector<string> _strRules);
    void validateInput(string _axiom, vector<string> _strRules, float theta);

I was expecting to be able to call drawNormals and to see the normal, but I’ve received this warning "“drawNormals(): mesh normals are disabled”.
I’ve called mesh.enableNormals in my setup method, as I’ve read here but without any success.

I think that I’m missing something in the correct setup of this class in order to be able to inherit from of3dPrimitive, it is also not clear to me how I would be able to call method like move if I haven’t declared an ofNode in this class.
Any suggestion is more than appreciated!

I’ve partially solved my problem. The trick was to use getMesh

#pragma once

#include "ofMain.h"
#include "of3dPrimitives.h"

class FunnyPrimitive : public of3dPrimitive {
    void setup();

    const float side = 200.f;

#include "FunnyPrimitive.h"


void FunnyPrimitive::setup(){
    ofMesh mesh;
    static GLfloat vdata[8][3] = {
        // front square vertices
        {0.0, 0.0, 0.0}, {side, 0.0, 0.0}, {side, side, 0.0}, {0.0, side, 0.0},
        //back square vertices of the cube
        {0.0, 0.0, -side}, {side, 0.0, -side}, {side, side, -side}, {0.0, side, -side},

    // these are the data for the indexes
    static GLint indices[12][3] = {
        {0, 1, 2}, {0, 2, 3},
        {1, 5, 6}, {1, 2, 6},
        {5, 4, 7}, {5, 7, 6},
        {4, 0, 3}, {4, 3, 7},
        {0, 1, 5}, {0, 4, 5},
        {3, 2, 6}, {3, 6, 7}

    ofColor color(255, 0, 0);
    float hue = 254.f;

    for(int i = 0; i<8; ++i){
        mesh.addVertex(ofVec3f(vdata[i][0], vdata[i][1], vdata[i][2]));
        hue -= 20.f;

    for(int i = 0; i<12; ++i){
    cout << mesh.getNumVertices() << endl;
    getMesh() = mesh;

Now if in my app I declare FunnyPrimitive cube, and I use it as follow:

void ofApp::setup(){

void ofApp::update(){

void ofApp::draw(){

I can see a rolling cube. Everything looks fine except the position of the cube. The cube is rotating on the bottom left corner, but i would like to make it rotating from its center. How is it possible to define the position of the cube?

if not mistaken of3Dprimitive inherits ofNode.
maybe you can do with a setPosition ?

Yes, I’ve tried using setPosition (also setGlobalPosition) and it does not work. Or, better explained, I can set the position of the cube on the screen using setGlobalPosition, but it does not work because that position node is always the top left corner, as visible in this image. (the ofNode is the small black box)

I’ve found some advices here:

this one says that I should add the position of the vertices taking as reference the vector (0,0,0).

And one here:

The first solution works only for cubes. I’ve a generative mesh that starts from an origin point, and it’s not possible to calculate the position of all the vertices relative to the origin point

The second solution is ugly, it involves PushMatrix and PopMatrix and I don’t know the eventual dimension of the matrix.
Any suggestion?

I’ve found the solution here

Basically, all the vertices have to be referred to 0,0,0, like the gamedev link

1 Like