|
|
@ -51,7 +51,7 @@ void ofApp::setup(){ |
|
|
|
map_depth.load("shaders/map_depth"); |
|
|
|
|
|
|
|
ORTCHAR_T* modelPath = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/image-to-mesh/bin/data/models/depth_anything_v2_vits.onnx"; |
|
|
|
ORTCHAR_T* modelPath_Small = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/image-to-mesh/bin/data/models/depth_anything_v2_vits.onnx"; |
|
|
|
ORTCHAR_T* modelPath_Small = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/image-to-mesh/bin/data/models/depth_anything_v2_vitb.onnx"; |
|
|
|
|
|
|
|
/* bullet setup */ |
|
|
|
bullet.setup(nodes); |
|
|
@ -63,7 +63,7 @@ void ofApp::setup(){ |
|
|
|
|
|
|
|
/* onnx setup */ |
|
|
|
depth_onnx.Setup(modelPath, false, true); |
|
|
|
depth_onnx_esp.Setup(modelPath_Small, false, true); |
|
|
|
depth_onnx_esp.Setup(modelPath, false, true); |
|
|
|
depth_onnx_portrait.Setup(modelPath_Small, false, true); |
|
|
|
|
|
|
|
/* multi-thread setup */ |
|
|
@ -115,9 +115,23 @@ void ofApp::update(){ |
|
|
|
server->update(esp_comp_fbo); |
|
|
|
|
|
|
|
float current_time = ofGetElapsedTimef(); |
|
|
|
|
|
|
|
Node n = server->getChosenNode(); |
|
|
|
|
|
|
|
// Check if node has changed
|
|
|
|
if(n.tsne_position != last_chosen_node.tsne_position) { |
|
|
|
portrait_needs_update = true; |
|
|
|
last_chosen_node = n; |
|
|
|
} else { |
|
|
|
portrait_needs_update = false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(current_time - last_updated_time >= 3){ |
|
|
|
buildKDTree(); |
|
|
|
getNearestImages(); |
|
|
|
depth_esp.update(); |
|
|
|
depth_onnx_esp.SetPixels(model_esp_out_fbo); |
|
|
|
last_updated_time = current_time; |
|
|
|
} |
|
|
|
|
|
|
@ -141,13 +155,11 @@ void ofApp::update(){ |
|
|
|
|
|
|
|
try{ |
|
|
|
depth_thread.update(); |
|
|
|
depth_esp.update(); |
|
|
|
depth_portrait.update(); |
|
|
|
|
|
|
|
|
|
|
|
/* set output to fbo's */ |
|
|
|
depth_onnx.SetPixels(model_outptut_fbo); |
|
|
|
depth_onnx_esp.SetPixels(model_esp_out_fbo); |
|
|
|
depth_onnx_portrait.SetPixels(model_portrait_out_fbo); |
|
|
|
|
|
|
|
|
|
|
|
} catch (exception e){ |
|
|
|
std::cout << "Model did not run" << std::endl; |
|
|
@ -156,7 +168,7 @@ void ofApp::update(){ |
|
|
|
//mapper.update();
|
|
|
|
bullet.update(server->is_active, server->getChosenNode()); |
|
|
|
|
|
|
|
std::cout << portrait_camera.getPosition() << " : " <<portrait_camera.getOrientationQuat()<< std::endl; |
|
|
|
//std::cout << portrait_camera.getPosition() << " : " <<portrait_camera.getOrientationQuat()<< std::endl;
|
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
@ -207,7 +219,6 @@ void ofApp::draw(){ |
|
|
|
comp_fbo.begin(); |
|
|
|
ofClear(ofColor::lightGrey); //uncommet when changing to map
|
|
|
|
ofBackgroundGradient(ofColor::darkGrey, ofColor::whiteSmoke, OF_GRADIENT_LINEAR); |
|
|
|
//ofClear(0);
|
|
|
|
shaders.begin(); |
|
|
|
portrait_fbo.draw(ofGetWindowWidth() / 2, 0); |
|
|
|
shaders.setUniformTexture("tex0", t, 0); |
|
|
@ -219,9 +230,7 @@ void ofApp::draw(){ |
|
|
|
/* actual map */ |
|
|
|
map_fbo_alpha.draw(0,0); |
|
|
|
//model_portrait_out_fbo.draw(0,0);
|
|
|
|
//portrait_fbo.draw(0, 0);
|
|
|
|
//portrait_fbo.draw(map_w * 0.333, 0);
|
|
|
|
//portrait_fbo.draw(map_w * 0.666, 0);
|
|
|
|
//portrait_pre_fbo_alpha.draw(model_portrait_out_fbo.getWidth(),0);
|
|
|
|
shaders.end(); |
|
|
|
comp_fbo.end(); |
|
|
|
|
|
|
@ -235,31 +244,29 @@ void ofApp::draw(){ |
|
|
|
|
|
|
|
void ofApp::drawPortrait(){ |
|
|
|
|
|
|
|
Node n = server->getChosenNode(); |
|
|
|
|
|
|
|
float p_scale = 1 + ( ((1 + ofNoise(ofGetElapsedTimef() / 5)) / 2) * 0.5); |
|
|
|
|
|
|
|
portrait_pre_fbo.begin(); |
|
|
|
ofClear(0, 0, 0, 0); |
|
|
|
|
|
|
|
float scale = min( |
|
|
|
(float)portrait_pre_fbo.getWidth() / n.img.getWidth(), |
|
|
|
(float)portrait_pre_fbo.getHeight() / n.img.getHeight() |
|
|
|
(float)portrait_pre_fbo.getWidth() / last_chosen_node.img.getWidth(), |
|
|
|
(float)portrait_pre_fbo.getHeight() / last_chosen_node.img.getHeight() |
|
|
|
); |
|
|
|
float scaledWidth = n.img.getWidth() * scale; |
|
|
|
float scaledHeight = n.img.getHeight() * scale; |
|
|
|
float scaledWidth = last_chosen_node.img.getWidth() * scale; |
|
|
|
float scaledHeight = last_chosen_node.img.getHeight() * scale; |
|
|
|
float xPos = (portrait_pre_fbo.getWidth() - scaledWidth) / 2; |
|
|
|
float yPos = (portrait_pre_fbo.getHeight() - scaledHeight) / 2; |
|
|
|
|
|
|
|
ofPushMatrix(); |
|
|
|
// Move to center of FBO
|
|
|
|
ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight() * 0.6); // 0.8
|
|
|
|
ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight()); // 0.8
|
|
|
|
// Apply scale
|
|
|
|
ofScale(1); |
|
|
|
// Move back by half the scaled image dimensions
|
|
|
|
ofTranslate(-scaledWidth/2, -scaledHeight/2); |
|
|
|
ofTranslate(-scaledWidth/2, -scaledHeight); |
|
|
|
// Draw at 0,0 since we've already translated
|
|
|
|
n.img.draw(0, 0, scaledWidth, scaledHeight); |
|
|
|
last_chosen_node.img.draw(0, 0, scaledWidth, scaledHeight); |
|
|
|
ofPopMatrix(); |
|
|
|
|
|
|
|
portrait_pre_fbo.end(); |
|
|
@ -267,19 +274,37 @@ void ofApp::drawPortrait(){ |
|
|
|
portrait_pre_fbo_alpha.begin(); |
|
|
|
ofPushMatrix(); |
|
|
|
ofClear(0, 0, 0, 0); |
|
|
|
ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight() * 0.6); |
|
|
|
ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight()); |
|
|
|
// Apply scale
|
|
|
|
ofScale(p_scale); |
|
|
|
ofScale(1); |
|
|
|
// Move back by half the scaled image dimensions
|
|
|
|
ofTranslate(-scaledWidth/2, -scaledHeight/2); |
|
|
|
n.img.draw(0, 0, scaledWidth, scaledHeight); |
|
|
|
ofTranslate(-scaledWidth/2, -scaledHeight); |
|
|
|
last_chosen_node.img.draw(0, 0, scaledWidth, scaledHeight); |
|
|
|
ofPopMatrix(); |
|
|
|
portrait_pre_fbo_alpha.end(); |
|
|
|
|
|
|
|
if(portrait_needs_update) { |
|
|
|
ofPixels pix; |
|
|
|
portrait_pre_fbo.readToPixels(pix); |
|
|
|
model_image_portrait.setFromPixels(pix); |
|
|
|
|
|
|
|
ofPixels pix; |
|
|
|
portrait_pre_fbo.readToPixels(pix); |
|
|
|
model_image_portrait.setFromPixels(pix); |
|
|
|
// Only run portrait model when needed
|
|
|
|
depth_portrait.update(); |
|
|
|
depth_onnx_portrait.SetPixels(model_portrait_out_fbo); |
|
|
|
|
|
|
|
/* create mesh */ |
|
|
|
float planeScale = 1.0; |
|
|
|
int planeWidth = portrait_pre_fbo_alpha.getWidth() * planeScale; |
|
|
|
int planeHeight = portrait_pre_fbo_alpha.getHeight() * planeScale; |
|
|
|
int planeGridSize = plane_size; |
|
|
|
int planeColumns = planeWidth / planeGridSize; |
|
|
|
int planeRows = planeHeight / planeGridSize; |
|
|
|
|
|
|
|
plane.set(planeWidth, planeHeight, planeColumns, planeRows, OF_PRIMITIVE_TRIANGLES); |
|
|
|
plane.mapTexCoords(0, 0, planeWidth, planeHeight); |
|
|
|
custom_mesh = createCustomPlane(planeWidth, planeHeight, planeColumns, planeRows); |
|
|
|
// ofLog() << "new mesh";
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ofApp::drawPortraitZ(){ |
|
|
@ -304,11 +329,6 @@ void ofApp::drawPortraitZ(){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* map bullet cam scale to portrait z-dist */ |
|
|
|
float map_camera_scale = bullet.camera.getScale().x; |
|
|
|
float pz = ofMap(map_camera_scale, 0.01, 0.03, 300, 550); |
|
|
|
//portrait_camera.setPosition(glm::vec3(portrait_camera.getPosition().x, portrait_camera.getPosition().y, pz));
|
|
|
|
|
|
|
|
portrait_camera.begin(); |
|
|
|
ofEnableDepthTest(); |
|
|
|
|
|
|
@ -317,16 +337,6 @@ void ofApp::drawPortraitZ(){ |
|
|
|
float p_noise_y = ofSignedNoise(time + 100, time + 100) * 20; |
|
|
|
|
|
|
|
ofPushMatrix(); |
|
|
|
|
|
|
|
float planeScale = 1.0; |
|
|
|
int planeWidth = portrait_pre_fbo_alpha.getWidth() * planeScale; |
|
|
|
int planeHeight = portrait_pre_fbo_alpha.getHeight() * planeScale; |
|
|
|
int planeGridSize = plane_size; |
|
|
|
int planeColumns = planeWidth / planeGridSize; |
|
|
|
int planeRows = planeHeight / planeGridSize; |
|
|
|
|
|
|
|
plane.set(planeWidth, planeHeight, planeColumns, planeRows, OF_PRIMITIVE_TRIANGLES); |
|
|
|
plane.mapTexCoords(0, 0, planeWidth, planeHeight); |
|
|
|
|
|
|
|
p_depth.begin(); |
|
|
|
p_depth.setUniform1f("gridSize", g_size); |
|
|
@ -335,9 +345,8 @@ void ofApp::drawPortraitZ(){ |
|
|
|
p_depth.setUniformTexture("tex0", tex_color, 0); |
|
|
|
p_depth.setUniformTexture("tex1", tex_depth, 1); |
|
|
|
ofFill(); |
|
|
|
//ofRotateDeg(90, 0, 1, 0);
|
|
|
|
ofTranslate(p_noise_x, p_noise_y, 0); |
|
|
|
plane.draw(); |
|
|
|
custom_mesh.draw(); |
|
|
|
p_depth.end(); |
|
|
|
ofPopMatrix(); |
|
|
|
ofDisableDepthTest(); |
|
|
@ -576,4 +585,59 @@ void ofApp::mousePressed(int x, int y, int button){ |
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mouseReleased(int x, int y, int button){ |
|
|
|
//mapper.mouseReleased(x, y, button);
|
|
|
|
} |
|
|
|
|
|
|
|
ofMesh ofApp::createCustomPlane(float width, float height, int numX, int numY) { |
|
|
|
ofMesh mesh; |
|
|
|
mesh.setMode(OF_PRIMITIVE_TRIANGLES); |
|
|
|
|
|
|
|
// Create vertices with non-uniform distribution
|
|
|
|
for(int y = 0; y <= numY; y++) { |
|
|
|
for(int x = 0; x <= numX; x++) { |
|
|
|
// Get base uniform position
|
|
|
|
float xPos = (float)x/numX * width; |
|
|
|
float yPos = (float)y/numY * height; |
|
|
|
|
|
|
|
float texX = (float)x/numX; |
|
|
|
float texY = 1.0 - (float)y/numY; |
|
|
|
|
|
|
|
// Add random offset but keep edges fixed
|
|
|
|
if(x != 0 && x != numX && y != 0 && y != numY) { |
|
|
|
// Random offset proportional to cell size
|
|
|
|
float cellWidth = width/numX; |
|
|
|
float cellHeight = height/numY; |
|
|
|
|
|
|
|
xPos += ofRandom(-cellWidth * 0.4, cellWidth * 0.4); |
|
|
|
yPos += ofRandom(-cellHeight * 0.4, cellHeight * 0.4); |
|
|
|
} |
|
|
|
|
|
|
|
mesh.addVertex(glm::vec3(xPos, yPos, 0)); |
|
|
|
|
|
|
|
// Add texture coordinates (normalized)
|
|
|
|
mesh.addTexCoord(glm::vec2(texX, texY)); |
|
|
|
mesh.addColor(ofColor(255, 255, 255, 255)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Create triangles
|
|
|
|
for(int y = 0; y < numY; y++) { |
|
|
|
for(int x = 0; x < numX; x++) { |
|
|
|
// Get indices for corners of quad
|
|
|
|
int nw = y * (numX + 1) + x; |
|
|
|
int ne = nw + 1; |
|
|
|
int sw = nw + (numX + 1); |
|
|
|
int se = sw + 1; |
|
|
|
|
|
|
|
// Add triangles
|
|
|
|
mesh.addIndex(nw); |
|
|
|
mesh.addIndex(ne); |
|
|
|
mesh.addIndex(se); |
|
|
|
|
|
|
|
mesh.addIndex(nw); |
|
|
|
mesh.addIndex(se); |
|
|
|
mesh.addIndex(sw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return mesh; |
|
|
|
} |