//-------------------------------------------------------------- void testApp::setup(){ ofSetLogLevel(OF_LOG_VERBOSE); model.loadMeshes("astroBoy_walk.dae",meshes); tex.loadImage("boy_10.tga"); ofEnableNormalizedTexCoords(); for(int i =0; i < meshes.size();i++){ vboMeshes.push_back(ofVboMesh()); vboMeshes.back().meshElement = &meshes[i]; vboMeshes.back().drawType = GL_STREAM_DRAW_ARB; } // ofEnableBlendMode(OF_BLENDMODE_ALPHA); glEnable(GL_DEPTH_TEST); lightsOn = true; glEnable(GL_SMOOTH); glEnable(GL_POINT_SMOOTH); glPointSize(4); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_NORMALIZE); }
ofVboMesh getCellMesh(voro::voronoicell &_c, ofPoint _pos, bool bWireframe){ if( _c.p ) { ofVboMesh mesh; getCellMesh(_c, _pos, mesh, bWireframe); return mesh; } return ofVboMesh(); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); ofEnableDepthTest(); tempMesh = ofVboMesh(); tempMesh.setMode(OF_PRIMITIVE_POINTS); tempMesh.load("church-mesh.ply") ; // change for different data set imgCount = 0 ; cam.setFarClip(100000) ; cam.setNearClip(0.1) ; }
//---------------------------------------------------------- ofVboMesh ofTessellator::tessellate( const ofPolyline& polyline, bool bIs2D ){ mutex.lock(); clear(); resultMesh = ofVboMesh(); // resultMesh.clear(); // now get the tesselator object up and ready: GLUtesselator * ofShapeTobj = gluNewTess(); #if defined( TARGET_OSX) #ifndef MAC_OS_X_VERSION_10_5 #define OF_NEED_GLU_FIX #endif #endif // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // MAC - XCODE USERS PLEASE NOTE - some machines will not be able to compile the code below // if this happens uncomment the "OF_NEED_GLU_FIX" line below and it // should compile also please post to the forums with the error message, you OS X version, // Xcode verison and the CPU type - PPC or Intel. Thanks! // (note: this is known problem based on different version of glu.h, we are working on a fix) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //#define OF_NEED_GLU_FIX #ifdef OF_NEED_GLU_FIX #define OF_GLU_CALLBACK_HACK (void(CALLBACK*)(...)) #else #define OF_GLU_CALLBACK_HACK (void(CALLBACK*)()) #endif gluTessCallback( ofShapeTobj, GLU_TESS_BEGIN, OF_GLU_CALLBACK_HACK &ofTessellator::begin); gluTessCallback( ofShapeTobj, GLU_TESS_VERTEX, OF_GLU_CALLBACK_HACK &ofTessellator::vertex); gluTessCallback( ofShapeTobj, GLU_TESS_COMBINE, OF_GLU_CALLBACK_HACK &ofTessellator::combine); gluTessCallback( ofShapeTobj, GLU_TESS_END, OF_GLU_CALLBACK_HACK &ofTessellator::end); gluTessCallback( ofShapeTobj, GLU_TESS_ERROR, OF_GLU_CALLBACK_HACK &ofTessellator::error); gluTessProperty( ofShapeTobj, GLU_TESS_WINDING_RULE, ofGetStyle().polyMode); if (!ofGetStyle().bFill){ gluTessProperty( ofShapeTobj, GLU_TESS_BOUNDARY_ONLY, true); } else { gluTessProperty( ofShapeTobj, GLU_TESS_BOUNDARY_ONLY, false); } gluTessProperty( ofShapeTobj, GLU_TESS_TOLERANCE, 0); /* ------------------------------------------ for 2d, this next call (normal) likely helps speed up .... quote : The computation of the normal represents about 10% of the computation time. For example, if all polygons lie in the x-y plane, you can provide the normal by using the ------------------------------------------- */ if( bIs2D) gluTessNormal(ofShapeTobj, 0.0, 0.0, 1.0); gluTessBeginPolygon( ofShapeTobj, NULL); for ( int i=0; i<polyline.size(); i++ ) { double* point = new double[3]; point[0] = polyline[i].x; point[1] = polyline[i].y; point[2] = polyline[i].z; ofShapePolyVertexs.push_back(point); } gluTessBeginContour( ofShapeTobj ); for (int i=0; i<(int)ofShapePolyVertexs.size(); i++) { gluTessVertex( ofShapeTobj, ofShapePolyVertexs[i], ofShapePolyVertexs[i]); } gluTessEndContour( ofShapeTobj ); // no matter what we did / do, we need to delete the tesselator object gluTessEndPolygon( ofShapeTobj); gluDeleteTess( ofShapeTobj); ofShapeTobj = NULL; // now clear the vertices on the dynamically allocated data clear(); mutex.unlock(); return resultMesh; }
void CloudsSVGMesh::recurseSVGTag(ofxXmlSettings& xml, const string& parentId, float parentOpacity){ ofMesh strokeMesh; ofMesh fillMesh; //find geo on this layer //<line display="inline" opacity="0.49" fill="none" stroke="#FFFFFF" stroke-miterlimit="10" x1="87.313" y1="612.5" x2="749.313" y2="612.5"/> int numLineTags = xml.getNumTags("line"); for(int l = 0; l < numLineTags; l++){ strokeMesh.addVertex(ofVec3f(xml.getAttribute("line", "x1", 0., l), xml.getAttribute("line", "y1", 0., l), 0)); strokeMesh.addVertex(ofVec3f(xml.getAttribute("line", "x2", 0., l), xml.getAttribute("line", "y2", 0., l), 0)); string hexColor = xml.getAttribute("line", "stroke", "#FFFFFF", l); hexColor.erase(hexColor.begin());//kill the # ofColor color = ofColor::fromHex( ofHexToInt(hexColor) ); if(xml.attributeExists("line","opacity",l)){ color.a = xml.getAttribute("line", "opacity", 0., l)*255.; } color.a *= parentOpacity; strokeMesh.addColor(color); strokeMesh.addColor(color); } //sample rect tag //<rect x="519.813" y="144.5" display="inline" opacity="0.02" fill="none" stroke="#FFFFFF" stroke-miterlimit="10" width="29" height="18"/> int numRectTags = xml.getNumTags("rect"); for(int r = 0; r < numRectTags; r++){ ofRectangle rect(xml.getAttribute("rect", "x", 0., r), xml.getAttribute("rect", "y", 0., r), xml.getAttribute("rect", "width", 0., r), xml.getAttribute("rect", "height", 0., r)); //pull the vertices out as vec3s ofVec3f a = rect.getTopLeft(); ofVec3f b = rect.getTopRight(); ofVec3f c = rect.getBottomRight(); ofVec3f d = rect.getBottomLeft(); string fillProperty = xml.getAttribute("rect", "fill", "none",r); bool isLines = fillProperty == "none"; string hexColor = xml.getAttribute("rect", (isLines ? "stroke" : "fill"), "#FFFFFF", r); hexColor.erase(hexColor.begin());//kill the # ofColor color = ofColor::fromHex( ofHexToInt(hexColor)); if(xml.attributeExists("rect","opacity",r)){ color.a = xml.getAttribute("rect", "opacity", 0., r)*255.; } color.a *= parentOpacity; if(isLines){ //we may wish to make this a line loop.... //convert to line segments strokeMesh.addVertex(a); strokeMesh.addVertex(b); strokeMesh.addVertex(b); strokeMesh.addVertex(c); strokeMesh.addVertex(c); strokeMesh.addVertex(d); strokeMesh.addVertex(d); strokeMesh.addVertex(a); for(int i = 0; i < 8; i++){ strokeMesh.addColor(color); } } else{ fillMesh.addVertex(a); fillMesh.addVertex(b); fillMesh.addVertex(d); fillMesh.addVertex(b); fillMesh.addVertex(d); fillMesh.addVertex(c); for(int i = 0; i < 6; i++){ fillMesh.addColor(color); } } } //if we added go throw it in the group, and give it a name if(strokeMesh.getNumVertices() > 0){ SVGMesh m; m.visible = true; m.id = parentId; if(m.id != ""){ meshIdIndex[m.id] = meshes.size(); } m.mesh = ofVboMesh(strokeMesh); m.mesh.setMode(OF_PRIMITIVE_LINES); m.mesh.setUsage(GL_STATIC_DRAW); m.fill = false; meshes.push_back(m); } if(fillMesh.getNumVertices() > 0){ SVGMesh m; m.visible = true; m.id = parentId; if(m.id != ""){ meshIdIndex[m.id] = meshes.size(); } m.mesh = ofVboMesh(fillMesh); m.mesh.setMode(OF_PRIMITIVE_TRIANGLES); m.mesh.setUsage(GL_STATIC_DRAW); m.fill = true; meshes.push_back(m); } //search other g tags int numGTags = xml.getNumTags("g"); for(int i = 0; i < numGTags; i++){ //is g tag displayed? if(xml.attributeExists("g", "display", i) && xml.getAttribute("g", "display", "", i) == "none") { //skipit continue; } string nextParentId; //does g tag have id; if(xml.attributeExists("g", "id", i)){ nextParentId = xml.getAttribute("g", "id", "",i); } if(xml.attributeExists("g", "opacity", i)){ parentOpacity *= xml.getAttribute("g", "opacity", 1.0, i);; } xml.pushTag("g",i); recurseSVGTag(xml, nextParentId, parentOpacity); xml.popTag(); } }