void CloudsVisualSystem3DModelLoader::loadCameraLineModel( ofVbo& vbo, string loc ){ ofBuffer buffer = ofBufferFromFile( loc ); vbo.clear(); vector<ofVec3f> points; if(buffer.size()) { while (buffer.isLastLine() == false) { string line = buffer.getNextLine(); vector<string> vals = ofSplitString( line, ","); for (int i=0; i<vals.size(); i+=3) { points.push_back( ofVec3f( ofToFloat(vals[i]), ofToFloat(vals[i+1]), ofToFloat(vals[i+2]) ) ); } } } vbo.setVertexData( &points[0], points.size(), GL_STATIC_DRAW ); cameraLinesNumVertices = points.size(); points.clear(); buffer.clear(); }
int CloudsVisualSystemLaplacianTunnel::loadMesh(ofVbo &vbo, string path) { char* buffer; long size; //cout << "path is " << path << endl; ifstream data( ofToDataPath(path, true).c_str(), ios::in | ios::binary); data.seekg(0, ios::end); size = data.tellg(); data.seekg(0, ios::beg); buffer = new char[size]; data.read(buffer, size); data.close(); unsigned int *ints = (unsigned int *) buffer; int numPts = ints[0]; int numTriangles = ints[1]; float *pts = (float *) (ints+2); for(int i = 0; i < numPts; i++){ ofVec3f p(pts[i*3+0],pts[i*3+1],pts[i*3+2]); center += p; min = ofVec3f(MIN(min.x,p.x), MIN(min.y,p.y), MIN(min.z,p.z)); max = ofVec3f(MAX(max.x,p.x), MAX(max.y,p.y), MAX(max.z,p.z)); } center /= numPts; unsigned int * indices = ints + 2 + numPts*6; //not sure what is enable or disable by default vbo.enableIndices(); vbo.enableNormals(); vbo.disableColors(); vbo.disableTexCoords(); vbo.setVertexData(pts,3,numPts,GL_STATIC_DRAW,sizeof(float)*3); vbo.setNormalData(pts+numPts*3,numPts,GL_STATIC_DRAW,sizeof(float)*3); vbo.setIndexData(indices,numTriangles*3,GL_STATIC_DRAW); //cout << "File " << path << " has " << numTriangles << " triangles " << endl; return numTriangles*3; }
/** * Add a quad to the mesh with clockwise front face vertex order */ void addQuad(ofVec3f const & bottomLeft, ofVec3f const & topLeft, ofVec3f const & topRight, ofVec3f const & bottomRight) { mesh.enableNormals(); vbo.enableNormals(); ofVec3f v1 = topLeft; ofVec3f v2 = topRight; ofVec3f v3 = bottomRight; ofVec3f v4 = bottomLeft; ofVec3f v1N, v2N, v3N, v4N; v1N = crossProd(v1,v2,v3); v3N = crossProd(v3,v4,v1); v2N = crossProd(v2,v1,v4); v4N = crossProd(v4,v3,v2); mesh.addVertex(v4); mesh.addNormal(v4N); mesh.addVertex(v1); mesh.addNormal(v1N); mesh.addVertex(v2); mesh.addNormal(v2N); mesh.addVertex(v3); mesh.addNormal(v3N); }
void ofApp::drawRectangle(float x, float y, float w, float h) { static ofVbo vbo; vector<ofVec3f> vertices = { ofVec3f(x, y, 0), ofVec3f(x + w, y, 0), ofVec3f(x + w, y + h, 0) , ofVec3f(x, y + h, 0) }; vector<ofFloatColor> colors(4, ofGetStyle().color); if (!vbo.getIsAllocated()) { vector<ofVec2f> texCoords = { ofVec2f(0, 0), ofVec2f(1, 0), ofVec2f(1, 1), ofVec2f(0, 1) }; vector<ofVec3f> normals(4, ofVec3f(0, 0, 1)); vector<ofIndexType> indices = { 0, 2, 1, 0, 3, 2 }; vbo.setVertexData(&vertices[0].x, 3, vertices.size(), GL_DYNAMIC_DRAW); vbo.setColorData(&colors[0].r, colors.size(), GL_DYNAMIC_DRAW); vbo.setTexCoordData(&texCoords[0].x, texCoords.size(), GL_STATIC_DRAW); vbo.setNormalData(&normals[0].x, normals.size(), GL_STATIC_DRAW); vbo.setIndexData(&indices[0], indices.size(), GL_STATIC_DRAW); } else { vbo.updateVertexData(&vertices[0].x, vertices.size()); vbo.updateColorData(&colors[0].r, colors.size()); } vbo.drawElements(GL_TRIANGLES, vbo.getNumIndices()); }
int ofxKinectV2::getVbo(ofVbo& vbo) { auto& vertices = pcVertices[indexFront]; auto& colors = pcColors[indexFront]; if (!vbo.getIsAllocated()) { vector<ofVec2f> texCoords; for (int y = 0; y < DEPTH_HEIGHT; y++) { float coord_y = (float)y / DEPTH_HEIGHT; for (int x = 0; x < DEPTH_WIDTH; x++) { float coord_x = (float)x / DEPTH_HEIGHT; texCoords.emplace_back(coord_x, coord_y); } } vbo.setTexCoordData(&texCoords[0], texCoords.size(), GL_STATIC_DRAW); vbo.setVertexData(&vertices[0].x, 4, vertices.size(), GL_DYNAMIC_DRAW); vbo.setColorData(&colors[0], colors.size(), GL_DYNAMIC_DRAW); vbo.setIndexBuffer(indicesBuffer); } else { vbo.updateVertexData(&vertices[0].x, vertices.size()); vbo.updateColorData(&colors[0].r, colors.size()); } auto& depth = frameRawDepth[indexFront]; if (depth.getWidth() && depth.getHeight()) { { std::lock_guard<std::mutex> guard(mutex); depthTexture.loadData(&depth[0], DEPTH_WIDTH, DEPTH_HEIGHT, GL_RED); //vector<float> dd(512 * 424); //memcpy(&dd[0], depth.getData(), sizeof(float) * dd.size()); } depthTexture.bindAsImage(0, GL_READ_ONLY); indicesBuffer.bindBase(GL_SHADER_STORAGE_BUFFER, 0); atomicCounter.bindBase(GL_ATOMIC_COUNTER_BUFFER, 0); computeIndices.begin(); computeIndices.setUniform1i("bUseUserMap", 0); computeIndices.dispatchCompute(DEPTH_WIDTH / 32, DEPTH_HEIGHT / 8, 1); computeIndices.end(); indicesBuffer.unbindBase(GL_SHADER_STORAGE_BUFFER, 0); atomicCounter.unbindBase(GL_ATOMIC_COUNTER_BUFFER, 0); #if 0 auto atomic = atomicCounter.map<int>(GL_READ_ONLY); int num = atomic[0]; atomicCounter.unmap(); cout << "atomic: " << num << endl; #endif int data = 0; atomicCounter.updateData(0, sizeof(int), &data); } return indicesBuffer.size() / sizeof(int); }