Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Update Mesh slow-down

$
0
0

OMG thank you arturo!

it's working very nice now (not really for the ofxIntSlider, but never mind). Say me, if you have the time, if my code it's correct for you.

#include "ofApp.h"

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

	mesh.setMode(OF_PRIMITIVE_LINES);

	image.load("test.jpg");
	image.resize(100, 100);

	myPanel.setup("COLOR");
	myPanel.add(drawMyMesh.setup("drawMyMesh", 20, 0, 255));
	myPanel.add(actionRadius.setup("Action Radius", 30, 0, 100));

}

//--------------------------------------------------------------
void ofApp::update() {
	drawMyMesh.addListener(this, &ofApp::parametersChanged);
	actionRadius.addListener(this, &ofApp::parametersChanged);
	

}

//--------------------------------------------------------------
void ofApp::draw() {
	ofColor centerColor = ofColor(255, 255, 255);
	ofColor edgeColor = ofColor(125, 125, 125);
	ofBackgroundGradient(centerColor, edgeColor, OF_GRADIENT_CIRCULAR);

	easyCam.begin();
		ofPushMatrix();
			ofTranslate(-ofGetWidth() / 2, -ofGetHeight() / 2);
			mesh.draw();
		ofPopMatrix();
	easyCam.end();

	myPanel.draw();
}

void ofApp::parametersChanged(int & drawMyMesh) {
	mesh.clear();

	float intensityThreshold = drawMyMesh;
	for (auto line : image.getPixels().getLines()) {
		auto x = 0;
		for (auto pixel : line.getPixels()) {
			ofColor c = pixel.getColor();
			float intensity = c.getLightness();
			if (intensity <= intensityThreshold) {
				float saturation = c.getSaturation();
				float z = ofMap(saturation, 0, 255, -100, 100);
				ofVec3f pos(x * 5, line.getLineNum() * 5, z);
				mesh.addVertex(pos);
				mesh.addColor(c);
			}
			++x;
		}
	}

	float connectionDistance = actionRadius;
	int numVerts = mesh.getNumVertices();
	for (int a = 0; a < numVerts; a += 4) {
		ofVec3f verta = mesh.getVertex(a);
		for (int b = a + 1; b < numVerts; b += 4) {
			ofVec3f vertb = mesh.getVertex(b);
			float distance = verta.distance(vertb);
			if (distance <= connectionDistance) {
				mesh.addIndex(a);
				mesh.addIndex(b);
			}
		}
	}
}

Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>