Adding a texture to a simple 3d model

Hello,

I’m trying to load a simple 3d model and texture map the various surfaces of it.

I’ve created a simple model of a square surface in Rhino, and exported it as a .stl.

I have a simple test image in bin/data called test.jpg

My code is:

ofApp.h

#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofxAssimpModelLoader.h"
#include "ofVboMesh.h"
#include "atlasSyphonClient.h"

class ofApp : public ofBaseApp{

 public:
		void setup();
		void update();
		void draw();
		
		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);		

 private:
		//general stuff
		float width, height;
		//model-related stuff
		ofxAssimpModelLoader model;
		//Syphon / texture-related stuff
		//atlasSyphonClient syphonClient;
};

#endif

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
  ofEnableSmoothing();
  ofEnableAlphaBlending();
  ofSetFrameRate(60);
  ofSetVerticalSync(true);
  width = ofGetWidth();
  height = ofGetHeight();

  ofSetWindowTitle("Atlas");
 
  ofEnableDepthTest();
  model.loadModel("single_screen.stl");
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
    ofBackground(50, 50, 50, 0);
    ofSetColor(255, 255, 255, 255);

    ofPushMatrix();
    ofTranslate(width/2, height/2, 0);
    ofRotateY(-mouseX);
    model.setScale(0.5, 0.5, 0.5);
    model.setPosition(0, 0, 0);
    model.draw(OF_MESH_WIREFRAME);
    ofPopMatrix();
    ofImage img;
    img.loadImage("test.jpg");

    //the command to load the selected texture    
    *model.getMeshHelper(0).getTexturePtr() = img.getTextureReference();
}

and this compiles just fine and dandy – but when I run it, my program crashes every time. All I get is:

black-rainbows:atlas scottnla$ make run
/bin/sh: line 1: 10086 Bus error: 10           ./atlas
make: *** [run] Error 138

which, well, isn’t very helpful. So my questions are:

  1. Is this the correct way to texture map the object, or is my code causing the crash somehow?
  2. If this should be the correct method; what am I doing to cause my program to crash?

thanks!

I’ve also tried using:

img.getTextureReference().bind();
model.draw(OF_MESH_POINTS);
img.getTextureReference().unbind();

but that doesn’t seem to work either :confused:

did you try to export the model in dae format?