ofPrimitive and getMesh not drawing


#1

I am creating a class that inherits from of of3dPrimitive.

it is like this:

Stairs.h


class Stairs : public of3dPrimitive{
public:
    Stairs();
    void drawDebug();
private:
    void load();
    ofxAssimpModelLoader model;
    ofMesh myMesh;
};

Stairs.cpp

#include "Stairs.h"

Stairs::Stairs(){
    load();
}


void Stairs::load(){
    model.setScaleNormalization(false);
    model.loadModel("stair.obj");

    getMesh().clear();
    getMesh().append(model.getMesh(0));
    getMesh().enableNormals();
    getMesh().enableColors();

    myMesh.clear();
    myMesh.append(model.getMesh(0));
}

void Stairs::drawDebug(){
    // model.drawFaces(); Works
    //  myMesh.drawFaces(); Works
    getMesh().drawFaces();  //Does not work
}

I would like to inherits from of3DPrimitive in order to be able to use all the methods that come with it. I wonder why I can see on the screen the mesh that I draw with model.drawFaces() or myMesh.drawFaces() but not that one in getMesh().drawFaces(). I have already logged:

    ofLog() << getMesh().getVertices().size();
    ofLog() << getMesh().getIndices().size();
    ofLog() << getMesh().getTexCoords().size();
    ofLog() << getMesh().getNormals().size();

and they are all set.

I am drawing my mesh applying a texture to it (I have tried with a material, but same result).

void ofApp::draw(){
  tex.bind();
  stairs.drawDebug();
  tex.undind();
}

Am I missing something trivial?


#2

Also, if I draw a an assimp model using model.drawFaces(); and that model has a material, the texture gets ignored.


#3

not sure what’s going on but don’t use inheritance, it’s terrible and will only give you headaches in the long term


#4

But it is really handy to have a primitive object with a mesh created in blender. At the moment I am using this pattern as a workaround and it works:

draw(ofNode node){ // a node containing the position and the rotation
        node.transformGL();
        stairs.drawFaces();
        node.restoreTransformGL();
}