Model scale in ofxAssimpModelLoader

I’m trying to load and scale a .stl file with ofxAssimpModelLoader.

In my 3d modelling program, I generate the object with a fixed size – say, 10 x 10 x 20 mm.

Then I export the stl and load it in with ofxAssimpModelLoader.

I would expect my model to load at 100 x 100 x 200 pixels, but it seems to be much larger than that. It looks to be about 500 x 500 x 1000 pixels, but I’m not sure of the exact size.

I can’t find anyway in the model loader’s interface to scale it to a fixed size – the only forum post I could find is from last year and had a rather unsatisfying solution:

Is there anyway to either:

  1. scale a model from ofxAssimpModelLoader to a fixed size? or,
  2. load it without any sort of scaling?

Even stranger – I wrote a function to get the boundingBox in order to rescale the object –

ofVec3f ofApp::getMeshBoundingBoxDimension(const ofMesh &mesh) {

	auto xExtremes = minmax_element(mesh.getVertices().begin(), mesh.getVertices().end(),
		[](const ofPoint& lhs, const ofPoint& rhs) {
		return lhs.x < rhs.x;
	});
	auto yExtremes = minmax_element(mesh.getVertices().begin(), mesh.getVertices().end(),
		[](const ofPoint& lhs, const ofPoint& rhs) {
		return lhs.y < rhs.y;
	});
	auto zExtremes = minmax_element(mesh.getVertices().begin(), mesh.getVertices().end(),
		[](const ofPoint& lhs, const ofPoint& rhs) {
		return lhs.z < rhs.z;
	});
	return ofVec3f(xExtremes.second->x - xExtremes.first->x,
		yExtremes.second->y - yExtremes.first->y,
		zExtremes.second->z - zExtremes.first->z);
}

and it returns the original value in millimeters! Some more digging shows that it has its own model matrix; so it contains the original model at its original scale, but when it draws it, it has its own “normalized” scale:

void ofxAssimpModelLoader::updateModelMatrix() {
    modelMatrix.makeIdentityMatrix();
    modelMatrix.glTranslate(pos);
    modelMatrix.glRotate(180, 0, 0, 1);
    if(normalizeScale) {
        modelMatrix.glScale(normalizedScale , normalizedScale, normalizedScale);
    }
    for(int i = 0; i < (int)rotAngle.size(); i++){ // @julapy - not sure why rotAngle isn't a ofVec4f.
        modelMatrix.glRotate(rotAngle[i], rotAxis[i].x, rotAxis[i].y, rotAxis[i].z);
    }
    modelMatrix.glScale(scale.x, scale.y, scale.z);
}

So what you need to do is call setScaleNormalization(false); to prevent the scaling from occuring!

The issue is resolved!