コード例 #1
0
void ofxNDCircularGradient(float radius, const ofColor & start, const ofColor & end)
{
    int n = 32; // circular gradient resolution
    static ofMesh _nd_cg_mesh;

    _nd_cg_mesh.clear();
    _nd_cg_mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
    
    ofVec2f center(0,0);
    _nd_cg_mesh.addVertex(center);

    float angleBisector = TWO_PI / (n * 2);
    float smallRadius = radius;
    float bigRadius = smallRadius / cos(angleBisector);
    for(int i = 0; i <= n; i++) {
        float theta = i * TWO_PI / n;
        _nd_cg_mesh.addVertex(center + ofVec2f(sin(theta), cos(theta)) * bigRadius);
    }
    
    _nd_cg_mesh.clearColors();
    _nd_cg_mesh.addColor(start);
    for(int i = 0; i <= n; i++) {
        _nd_cg_mesh.addColor(end);
    }
    
    _nd_cg_mesh.draw();
}
コード例 #2
0
ファイル: ofApp.cpp プロジェクト: satoruhiga/ofws20014
	void update()
	{
		mesh.clear();
		
		float t = ofGetElapsedTimef() * 0.3;
		float noise_scale = 0.05;
		
		float size = 300;
		float shape_size = 200;
		
		int num = 100;
		for (int i = 0; i < num; i++)
		{
			ofVec3f base(ofSignedNoise(10, 0, 0, i * noise_scale + t),
						 ofSignedNoise(0, 10, 0, i * noise_scale + t),
						 ofSignedNoise(0, 0, 10, i * noise_scale + t));
			
			ofVec3f v0(ofSignedNoise(1, 0, 0, i * noise_scale + t),
					   ofSignedNoise(0, 1, 0, i * noise_scale + t),
					   ofSignedNoise(0, 0, 1, i * noise_scale + t));
			
			ofVec3f v1(ofSignedNoise(2, 0, 0, i * noise_scale + t),
					   ofSignedNoise(0, 2, 0, i * noise_scale + t),
					   ofSignedNoise(0, 0, 2, i * noise_scale + t));

			ofVec3f v2(ofSignedNoise(3, 0, 0, i * noise_scale + t),
					   ofSignedNoise(0, 3, 0, i * noise_scale + t),
					   ofSignedNoise(0, 0, 3, i * noise_scale + t));
			
			float hue = ofMap(i, 0, num, 0, 1);
			ofFloatColor c = ofFloatColor::fromHsb(hue, 1, 1);
			
			float s = fabs(sin(i * 0.1 + t)) + 0.1;
			
			mesh.addColor(c);
			mesh.addColor(c);
			mesh.addColor(c);
			
			mesh.addVertex(base * size + v0 * shape_size * s);
			mesh.addVertex(base * size + v1 * shape_size * s);
			mesh.addVertex(base * size + v2 * shape_size * s);
		}
		
		IndexColor::convertColorToTexCoord(mesh);
		
		// export to abc
		abc_out.addPolyMesh("/mesh", mesh);
	}
コード例 #3
0
ファイル: ofApp.cpp プロジェクト: fishkingsin/ribbonTunnel
//http://www.packtpub.com/sites/default/files/9781849518048_Chapter_07.pdf
//knotExample
void ofApp::addCircle( ofVec3f nextPoint, ofMesh &mesh ){
    float time = ofGetElapsedTimef();    //Time
    //Parameters – twisting and rotating angles and color

    ofFloatColor color( ofNoise( time * 0.05 ),
                       ofNoise( time * 0.1 ),
                       ofNoise( time * 0.15 ));
    color.setSaturation( 1.0 );  //Make the color maximally
    
    //Add vertices
    for (int i=0; i<circleN; i++) {
        float angle = float(i) / circleN * TWO_PI+(PI*0.25);
        float x = Rad * cos( angle );
        float y = Rad * sin( angle );
        ofPoint p =    nextPoint+ofVec3f(x ,y , 0);
        mesh.addVertex( p );
        mesh.addColor( color );
    }
    //Add the triangles
    int base = mesh.getNumVertices() - 2 * circleN;
    if ( base >= 0 ) {  //Check if it is not the first step
        //and we really need to add the triangles
        for (int i=0; i<circleN; i++) {
            int a = base + i;
            int b = base + (i + 1) % circleN;
            int c = circleN  + a;
            int d = circleN  + b;
            mesh.addTriangle(a,b,d);
            mesh.addTriangle(a, d, c);
        }
        //Update the normals
        setNormals( mesh );
    }
}
コード例 #4
0
//--------------------------------------------------------------
void ofApp::colorFaces(ofMesh & mesh){
	for(int i = 0; i < mesh.getVertices().size(); i++){
		const ofVec3f & v = mesh.getVertices()[i];
		ofColor col;
		col.setHsb(ofMap(v.x + v.y, -1000, 1000, 0, 255), 255, 255);
		mesh.addColor(col);
	}
}
コード例 #5
0
ファイル: testApp.cpp プロジェクト: pixlpa/pxPAPI
//--------------------------------------------------------------
void testApp::draw(){
    fbo.begin();
        ofSetTextureWrap(GL_REPEAT,GL_REPEAT);
        fbfbo.draw(0,2);
    //cam.draw(0,0);
        fbfbo.getTextureReference().bind();
        trik2.draw();
        fbfbo.getTextureReference().unbind();
        
        ofSetColor(255,255,255);
    if(tritimer>tritimerlimit){
        float xpt, ypt,xtoff,ytoff;
        //draw gradient splashes
        ofMesh trik;
        for(int b = 0;b<5;b++){
            xtoff = ofRandomf()*0.5;
            ytoff = ofRandomf()*0.5;
            for(int i=0;i<3;i++){
                xpt = ofRandomuf()*2+xtoff;
                ypt = ofRandomuf()*2+ytoff;
                trik.addVertex(ofVec3f(xpt*w,ypt*h,0));
                trik.addColor(ofFloatColor(float(ofRandomuf()>0.5)*0.6+0.4,float(ofRandomuf()>0.5)*0.5+0.5,float(ofRandomuf()>0.5)*0.7+0.3));
            }
        }
        trik.draw();
        tritimer = 0;
        tritimerlimit= ofRandom(20,200);
    }
    
    if(tritimer2>45){
        //re-generate the feedback triangles
        float xpt, ypt,xoff,yoff,xtoff,ytoff;
        trik2.clear();
        //ofEnableNormalizedTexCoords();
        for(int b = 0;b<5;b++){
            xoff = ofRandomf()*0.1;
            yoff = ofRandomf()*0.1;
            xtoff = ofRandomf()*0.5;
            ytoff = ofRandomf()*0.5;
            for(int i=0;i<3;i++){
                xpt = ofRandomuf()+xtoff;
                ypt = ofRandomuf()+ytoff;
                trik2.addVertex(ofVec3f((xpt+xoff)*w,(ypt+yoff)*h,0));
                trik2.addTexCoord(ofVec2f(xpt*w,ypt*h));
                trik2.addColor(ofFloatColor(1,1,1));
            }
        }
        tritimer2=0;
        tritimer2limit= ofRandom(20,200);
        //ofDisableNormalizedTexCoords();
    }
    fbo.end();
    fbfbo.begin();
    fbo.draw(0,0);
    fbfbo.end();
    fbo.draw(0,0);
}
コード例 #6
0
ファイル: Particle.cpp プロジェクト: julenka/hciiCommons
void Particle::addToMesh(ofMesh & mesh, unsigned long long systemTime) {
    float pct;
    switch(state) {
        case INACTIVE:
            break;
        case BORN:
            mesh.addColor(ofColor(baseColor));
            mesh.addVertex(location);
            break;
        case FALLING:
            pct = 1 - ofMap(systemTime - bornTime, BORN_TIMEOUT_MS, FALL_TIMEOUT_MS, 0,1,true);
            curColor = baseColor * pct;
            mesh.addColor(curColor);
            mesh.addVertex(location);
            break;
        default:
            break;
    }
}
コード例 #7
0
//--------------------------------------------------------------
void addFace(ofMesh& mesh,
             ofVec3f a, ofFloatColor aC,
             ofVec3f b, ofFloatColor bC,
             ofVec3f c, ofFloatColor cC) {
    
	ofVec3f normal = ((b - a).cross(c - a)).normalize() * -1.0;
    
	mesh.addNormal(normal);
    mesh.addColor(aC);
	mesh.addVertex(a);
    
	mesh.addNormal(normal);
    mesh.addColor(bC);
	mesh.addVertex(b);
    
	mesh.addNormal(normal);
	mesh.addColor(cC);
    mesh.addVertex(c);
}
コード例 #8
0
OFX_OBJLOADER_BEGIN_NAMESPACE

void load(string path, ofMesh& mesh, bool generateNormals, bool flipFace)
{
	path = ofToDataPath(path);

	mesh.clear();

	GLMmodel* m;

	m = glmReadOBJ((char*)path.c_str());

	if (generateNormals)
	{
		glmFacetNormals(m);
		glmVertexNormals(m, 90);
	}

	if (flipFace)
	{
		glmReverseWinding(m);
	}

	for (int j = 0; j < m->numtriangles; j++)
	{
		const GLMtriangle &tri = m->triangles[j];

		for (int k = 0; k < 3; k++)
		{
			GLfloat *v = m->vertices + (tri.vindices[k] * 3);
			mesh.addVertex(ofVec3f(v[0], v[1], v[2]));

			if (m->colors)
			{
				GLfloat *c = m->colors + (tri.vindices[k] * 3);
				mesh.addColor(ofFloatColor(c[0], c[1], c[2]));
			}

			if (m->normals && ofInRange(tri.nindices[k], 0, m->numnormals))
			{
				GLfloat *n = m->normals + (tri.nindices[k] * 3);
				mesh.addNormal(ofVec3f(n[0], n[1], n[2]));
			}

			if (m->texcoords && ofInRange(tri.tindices[k], 0, m->numtexcoords))
			{
				GLfloat *c = m->texcoords + (tri.tindices[k] * 2);
				mesh.addTexCoord(ofVec2f(c[0], c[1]));
			}
		}
	}

	glmDelete(m);
}
コード例 #9
0
//--------------------------------------------------------------
ofMesh testApp::pixelManipulate(ofImage imageA, ofMesh meshA, float intensityThreshold, float sketchDepth){
    
    
    imageA.resize(200, 200);
    
    //create mesh with points as the primitive
    //meshA.setMode(OF_PRIMITIVE_POINTS);
    
    //create a mesh with lines
      meshA.setMode(OF_PRIMITIVE_LINE_LOOP);
    
    //meshA.setMode(OF_PRIMITIVE_LINE_STRIP);
    
    
    int w = imageA.getWidth();
    
    int h = imageA.getHeight();
    
    //loop through each pixel in the image using image width & height
    for (int x=0; x<w; x++){
        for(int y=0; y<h; y++){
            
            //create the color object at that pixel
            //ofColor c = imageA.getColor(x, y);
            
            ofColor c = imageA.getColor(x, y);

            
            //check the intensity of the pixel's color
            float intensity = c.getLightness();
            
            //if the intensity exceeds the threshold, create a vertex at the location of the pixel
            //& color it with the pixel's color
            if (intensity >= intensityThreshold){
                
                //pushes brighter colors in the positive z direction
                //pushes whiter colors in the negative z direction
                float saturation = c.getSaturation();
                float z = ofMap(saturation, 0, 255, -sketchDepth, sketchDepth);
                
                //the image is now 1/4 the size of the OF window, so multiply
                //the pixel location by 4 so that the mesh covers the OF window
                ofVec3f pos(5*x, 4*y, z);
                meshA.addVertex(pos);
                meshA.addColor(c);
            }
        }
    }
    
    return meshA;
}
void CloudsVisualSystemTunnelDrawing::drawRibbonTrail(const RibbonTrail& trail, ofMesh& geo){
	
	for(int i = 1; i < trail.points.size(); i++){
        
		//find this point and the next point
		ofVec3f thisPoint = trail.points[i-1];
		ofVec3f nextPoint = trail.points[i];
        
		//get the direction from one to the next.
		//the ribbon should fan out from this direction
		ofVec3f direction = (nextPoint - thisPoint);
        //direction.z = 0;
		
		//get the distance from one point to the next
		float distance = direction.length();
        
		//get the normalized direction. normalized vectors always have a length of one
		//and are really useful for representing directions as opposed to something with length
		ofVec3f unitDirection = direction.normalized();
        
		//find both directions to the left and to the right
		ofVec3f toTheLeft  = unitDirection.getRotated(-90, ofVec3f(0,0,1));
		ofVec3f toTheRight = unitDirection.getRotated(90, ofVec3f(0,0,1));
        
		//use the map function to determine the distance.
		//the longer the distance, the narrower the line.
		//this makes it look a bit like brush strokes
		float thickness = ofMap(distance,
								distanceRange.min, distanceRange.max,
								thicknessRange.max, thicknessRange.min, true);
		
		//calculate the points to the left and to the right
		//by extending the current point in the direction of left/right by the length
		ofVec3f leftPoint  = thisPoint + toTheLeft  * thickness;
		ofVec3f rightPoint = thisPoint + toTheRight * thickness;
        
		if(i == 1){
			geo.addColor(ofFloatColor(0,0,0,0));
			geo.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));
			geo.addColor(ofFloatColor(0,0,0,0));
			geo.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));
		}
		
		//add these points to the triangle strip
		geo.addColor(ofFloatColor::white);
		geo.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));
		geo.addColor(ofFloatColor::white);
		geo.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));
		
		if( i == trail.points.size()-1 ){
			geo.addColor(ofFloatColor(0,0,0,0));
			geo.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));
			geo.addColor(ofFloatColor(0,0,0,0));
			geo.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));
		}
	}
}
//--------------------------------------------------------------
static void aiMeshToOfMesh(const aiMesh* aim, ofMesh& ofm, ofxAssimpMeshHelper * helper = NULL){

	// default to triangle mode
	ofm.setMode(OF_PRIMITIVE_TRIANGLES);

	// copy vertices
	for (int i=0; i < (int)aim->mNumVertices;i++){
		ofm.addVertex(ofVec3f(aim->mVertices[i].x,aim->mVertices[i].y,aim->mVertices[i].z));
	}

	if(aim->HasNormals()){
		for (int i=0; i < (int)aim->mNumVertices;i++){
			ofm.addNormal(ofVec3f(aim->mNormals[i].x,aim->mNormals[i].y,aim->mNormals[i].z));
		}
	}

	// aiVector3D * 	mTextureCoords [AI_MAX_NUMBER_OF_TEXTURECOORDS]
	// just one for now
	if(aim->GetNumUVChannels()>0){
		for (int i=0; i < (int)aim->mNumVertices;i++){
			if( helper != NULL && helper->texture.getWidth() > 0.0 ){
				ofVec2f texCoord = helper->texture.getCoordFromPercent(aim->mTextureCoords[0][i].x ,aim->mTextureCoords[0][i].y);
				ofm.addTexCoord(texCoord);
			}else{
				ofm.addTexCoord(ofVec2f(aim->mTextureCoords[0][i].x ,aim->mTextureCoords[0][i].y));			
			}
		}
	}

	//aiColor4D * 	mColors [AI_MAX_NUMBER_OF_COLOR_SETS]
	// just one for now
	if(aim->GetNumColorChannels()>0){
		for (int i=0; i < (int)aim->mNumVertices;i++){
			ofm.addColor(aiColorToOfColor(aim->mColors[0][i]));
		}
	}

	for (int i=0; i <(int) aim->mNumFaces;i++){
		if(aim->mFaces[i].mNumIndices>3){
			ofLog(OF_LOG_WARNING,"non-triangular face found: model face # " + ofToString(i));
		}
		for (int j=0; j<(int)aim->mFaces[i].mNumIndices; j++){
			ofm.addIndex(aim->mFaces[i].mIndices[j]);
		}
	}

	ofm.setName(string(aim->mName.data));
	//	ofm.materialId = aim->mMaterialIndex;
}
コード例 #12
0
ファイル: TextWriter.cpp プロジェクト: imclab/LaserShow
void TextWriter::addGlyphToMesh(Letter &letter, ofRectangle box, ofMesh& mesh) {
	
	//float randomness = 0.05;
	
    for( int i = 0; i < letter.points.size(); i++ ) {
		
		ofVec3f v; 
		v.x = box.x + ofMap(letter.points[i].x + ofRandom(-lineRandomness, lineRandomness), 0, glyphWidth, 0, box.width);
		v.y = box.y + ofMap(letter.points[i].y + ofRandom(-lineRandomness, lineRandomness), 0, glyphHeight, 0, box.height);
       
        mesh.addVertex(v);
		
		ofColor vcolor(colour);
		vcolor.setBrightness(vcolor.getBrightness() * ofRandom(colourFlickerMin, 1));
		mesh.addColor(vcolor); 
       
    }

}
コード例 #13
0
ファイル: ofxExtras.cpp プロジェクト: Bicicletorama/Game
void ofxAutoColorMesh(ofMesh &mesh) {
    for (int i=0; i<mesh.getNumVertices(); i++) {
        ofVec3f v = mesh.getVertex(i).normalized();
        mesh.addColor(ofFloatColor(v.x,v.y,v.z));
    }
}
コード例 #14
0
ファイル: ofxPolyvox.cpp プロジェクト: kalwalt/ofxPolyvox
void ofxPolyvox::polyvoxToOfMesh(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh, ofMesh& polyvxToOfMesh, bool setColor){

    //Convienient access to the vertices and indices
	const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
	const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();//surfaceMesh.getRawVertexData();

	ofIndexType ofVecIndices;
	const void* pIndices = static_cast<const void*>(&(vecIndices[0]));

	int* indices = (int*)pIndices;

    vector<int> indx;


     for (int i = 0; i < surfaceMesh.getNoOfIndices(); i++ ){

     indx.push_back(indices[i]);
     //cout << "indices:" << indices[i] << endl;
    polyvxToOfMesh.addIndex(indx[i]);
     }

	ofLog(OF_LOG_NOTICE, "ofMesh: number of indices is %d", polyvxToOfMesh.getNumIndices());

    ofVec3f ofVecVertices;


     for (int i = 0; i < surfaceMesh.getNoOfVertices(); i++ ){


    PositionMaterialNormal vert0 = vecVertices[i];


    ofVecVertices = ofVec3f(vert0.getPosition().getX(),vert0.getPosition().getY(),vert0.getPosition().getZ());

    polyvxToOfMesh.addVertex(ofVecVertices);

    }

	 ofLog(OF_LOG_NOTICE, "ofMesh: number of vertices is %d", polyvxToOfMesh.getNumVertices());

    ofVec3f ofVecNormals;

    for (int i = 0; i < surfaceMesh.getNoOfVertices(); i++ ){


    PositionMaterialNormal vert0 = vecVertices[i];


    ofVecNormals = ofVec3f(vert0.getNormal().getX(),vert0.getNormal().getY(),vert0.getNormal().getZ());

    polyvxToOfMesh.addNormal(ofVecNormals);

    }

	ofLog(OF_LOG_NOTICE, "ofMesh: number of normals is %d", polyvxToOfMesh.getNumNormals());


    if(setColor){

        for (int i = 0; i < surfaceMesh.getNoOfVertices(); i++ ){

        PositionMaterialNormal vert0 = vecVertices[i];

        uint8_t material = static_cast<uint8_t>(vert0.getMaterial() + 0.5);

        //cout << "material:" << int(material) << endl;

        ofFloatColor colour = convertMaterialIDToColour(material);

        //cout << colour << endl;

        polyvxToOfMesh.addColor(colour);

        bool col = polyvxToOfMesh.hasColors();

        //cout << "hasColors:" << col << endl;
        }

    }

}
コード例 #15
0
ファイル: FlockMember.cpp プロジェクト: armadillu/Sardine
void FlockMember::draw(ofMesh & pointsMesh, ofMesh &forcesMesh){

	if (!enabled)
		return;
	if (false){ //3d model orientation

		glPushMatrix();
			glTranslatef( pos.x, pos.y, pos.z );

			ofQuaternion rot;
			rot.makeRotate(vel.normalized(), ofVec3f(1,0,0) );
			ofVec3f r = rot.getEuler();
			glRotatef( -r.y, 0, 1, 0);
			glRotatef( -r.x, 0, 0, 1);
			//glRotatef( -r.z, 1, 0, 0);

			ofSetColor(c);
			//model->draw();

		glPopMatrix();
	}else{
		ofSetColor(c);
		//ofSphere(pos, 0.1);
		pointsMesh.addColor(c);
		pointsMesh.addVertex(pos);
	}
	//ofSetColor(c);

	float gain = 30;

	if (params->debugShowDirection){
		ofColor cc = ofColor::yellow;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos);
		cc.a = 0;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos + vel);
	}

	if (params->debugShowCollisions){
		ofColor cc = ofColor::red;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos);
		cc.a = 0;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos + avoidNeigbhors * gain);
	}

	if (params->debugShowCohesion){
		ofColor cc = ofColor::blue;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos);
		cc.a = 0;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos + groupCohesion * gain);
	}

	if (params->debugShowSchooling){
		ofColor cc = ofColor::magenta;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos);
		cc.a = 0;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos + schoolSameColor * gain);

		cc = ofColor::cyan;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos);
		cc.a = 0;
		forcesMesh.addColor(cc);
		forcesMesh.addVertex(pos + schoolDifferentColor * gain);
	}

	float ballAlpha = 128;
	if (params->debugCohesionDist){
		ofNoFill();
		ofSetColor(0,0,255,ballAlpha );
		ofSphere(pos, params->cohesionDist * 0.5f);
		ofFill();
	}

	if (params->debugCollisionDist){
		ofNoFill();
		ofSetColor(255,0,0,ballAlpha );
		ofSphere(pos, params->collisionDist * 0.5f);
		ofFill();
	}

	if (params->debugSchoolingFriendsDist){
		ofNoFill();
		ofSetColor(255,0,255,ballAlpha );
		ofSphere(pos, params->schoolFriendsDist * 0.5f);
		ofFill();
	}

	if (params->debugSchoolingOthersDist){
		ofNoFill();
		ofSetColor(0,255,255,ballAlpha );
		ofSphere(pos, params->schoolOthersDist * 0.5f);
		ofFill();
	}
//	ofSetColor(255);
//	ofDrawBitmapString(ofToString(vel), pos);
}
コード例 #16
0
void BGGraphics::pushVertex(ofMesh & mesh, float x, float y, float z, float nx, float ny, float nz, float offsetX, float offsetY) {
    mesh.addVertex(ofVec3f(x, y, z));
    mesh.addNormal(ofVec3f(nx, ny, nz));
    mesh.addTexCoord(ofVec2f(offsetX, offsetY));
    mesh.addColor(ofFloatColor(255, 255, 255));
}