Color loss on saving/loading ofMesh

Hi all,

I am using a kinect to get a point cloud with real colors:

(in ofApp.h: ofMesh pointCloud1, pointCloud2, pointCloudTransformed;)

for(int y = 0; y < h; y += density) {
    for(int x = 0; x < w; x += density) {
        if(..[distance stuff..])
        {
            pointCloud1.addColor(kinect.getColorAt(x,y));
            pointCloud1.addVertex(kinect.getWorldCoordinateAt(x, y));
        }
    }
}

If I draw the point cloud, all is as expected. Then I save it:

pointCloud1.save("meshes/pointCloud1.ply");

When later loading the point Cloud and drawing it, all is good on OS X OF 0.8.4., while on Ubuntu OF 0.9.8 the point cloud draws without colors (all dots grey). The .ply-file look good to me on both machines.
When switching back to live (getting the point cloud from kinect and drawing it directly) all is expected (with colors) on both systems again.

Any idea what could be causing this?

Thanks for any hint!
oe

Hi all,

I prepared a small App to show my problem and did some tries. I tested on 3 Machines running Windows and ubuntu each. All machines show colorless version of a pre-saved mesh (point cloud mesh consists of grey dots) no matter which system.
Same code / same mesh on OS X shows the colors (point cloud mesh consists of colored dots).

So it is obviously not a problem of one system or graphics card. I assume, I am just missing a setting maybe?
If anyone could try and help, I’d be happy. Find the app (with mesh) here:

tryShowSavedMesh.tar.gz (579.7 KB)

Thanks for any hint!
oe


The code is basically just
(in ofApp.h)

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

    ofMesh pointCloud;
    ofEasyCam easyCam;
};

(in ofApp.cpp)

//--------------------------------------------------------------
void ofApp::setup(){
    pointCloud.load("meshes/pointCloud1.ply");
    pointCloud.setMode(OF_PRIMITIVE_POINTS);
    glPointSize(3);
}

//--------------------------------------------------------------
void ofApp::draw(){
    easyCam.begin();
    ofScale(1, -1, -1);
    ofTranslate(0, 0, -1000);
	pointCloud.drawVertices();
    easyCam.end();
}

as a test I also added some tries for GL setting (just to be sure there is no different default on OS X) - but no success:

    ofEnableDepthTest();
    ofDisableLighting();
    ofEnableAlphaBlending();
    ofEnableAntiAliasing();
    //ofEnableBlendMode();
    ofEnableDepthTest();
    ofEnablePointSprites();
    ofEnableSmoothing();
    ofEnableSeparateSpecularLight();
    ofEnableArbTex();
    ofEnableNormalizedTexCoords();
    ofEnableTextureEdgeHack();

I’m facing same issue on v0.9.8 / Linux Mint, any update?

Hello,

I think I’m having this same issue as well.

My code:

#include "ofApp.h"
#include <iostream>
#include <string>
using namespace std;

//--------------------------------------------------------------
void ofApp::setup(){
    setupGui();
    
    cam.enableMouseInput();

    
    sphere.setRadius(200);
    sphere.setResolution(100);

    ofLoadImage(texture,"specs/image.png");

    float w = texture.getWidth();
    float h = texture.getHeight();
    sphere.mapTexCoords(0, h, w, 0);
    sphere.rotate(180, 0, 1, 0);
    
     vector<glm::vec<3, float, glm::packed_highp>>& vertices = sphere.getMesh().getVertices();
    
     ofPixels pixels;
     texture.readToPixels(pixels);
     for (int i=0; i<vertices.size(); i++) {
         ofVec2f t = sphere.getMesh().getTexCoords()[i];
         t.x = ofClamp( t.x, 0, pixels.getWidth()-1 );
         t.y = ofClamp( t.y, 0, pixels.getHeight()-1 );
         float br = pixels.getColor(t.x, t.y).getBrightness();
         vertices[i] *= 1 + br / 255.0 ; // * some_extrude_factor
     }

    texture.bind();
    sphere.getMesh().save("specs/model.ply");
    
    
}

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

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


    ofBackground(22, 22, 29);
    
    cam.begin();
    draw3d();
    cam.end();
}

void ofApp::draw3d(){
    ofScale(1, -1, 1);
    texture.bind();
    //light.setPosition(ofGetWidth() / 2, ofGetHeight()/2, 600);
    //light.enable();
    material.begin();
    ofEnableDepthTest();
    
    ofSetColor(ofColor::white);
    sphere.draw();
    sphere.drawWireframe();
 
    ofDisableDepthTest();
    material.end();
    //light.disable();
    //ofDisableLighting();
    texture.unbind();

}


I’m essentially taking a sphere, applying the color from an image to the vertices of a sphere and extruding it out based on brightness. It’s based on work I did in this post (just about a year ago!)

I’m able to save my model as a .ply file but none of the color comes with it if I try to load it in another 3D modeling/viewing application (in my case, Blender and A-Frame)

Is there something else I should be doing to save my mesh with the pixel colors I’ve set?

Thank you for any help and please let me know if there is more information I can provide!

Hi, what happens if you run the following?
ofApp.h

#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();
		void keyReleased(int key);
		
	ofMesh sphere, saved;
	
	bool bShowSphere = true;
	
};

ofApp.cpp

#include "ofApp.h"

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

	ofSpherePrimitive _sphere(200, 20);

	sphere= _sphere.getMesh();
	auto &verts = sphere.getVertices();
	for(auto&v: verts){
		sphere.addColor(ofFloatColor(ofRandom(0.4, 1.0),ofRandom(0.4, 1.0),ofRandom(0.4, 1.0)));
	}
	sphere.save("sphere.ply");
	
	saved.load("sphere.ply");
	
	
}

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

}

//--------------------------------------------------------------
void ofApp::draw(){
	ofPushMatrix();
	ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
	if(bShowSphere){
		sphere.draw();
	}else{
		saved.draw();
	}
	ofPopMatrix();
	ofDrawBitmapStringHighlight("Drawing Sphere: " + ofToString(bShowSphere), 20,20);
	
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){

	if(key == ' ' )bShowSphere ^= true;
}

Thanks @roymacdonald. I get this (sorry for the funky resolution):

Drawing Sphere: 1

Drawing Sphere: 0

I’m running on Linux by the way, and could test on OSX if that helps.

I am on OSX and thats what I get.
So now, if these saved sphere.ply file is opened in one of the other softwares you use, is it the same thing you are seeing? does it have colors?