예제 #1
0
void TriangulationApp::recalcMesh()
{
	TriMesh2d mesh = Triangulator( mShape, mPrecision ).calcMesh( Triangulator::WINDING_ODD );
	mNumPoints = mesh.getNumIndices();
	mVboMesh = gl::VboMesh( mesh ); 
	mOldPrecision = mPrecision;
}
예제 #2
0
void BasicSampleApp::triangulate()
{

    // Triangulate line
    TriMesh2d mesh = Triangulator( mLine ).calcMesh();

    // Rebuild list of triangles from mesh
    mTriangles.clear();
    Vec2f a, b, c;
    for ( uint32_t i = 0; i < mesh.getNumTriangles(); i++ ) {
        mesh.getTriangleVertices( i, &a, &b, &c );
        Trianglef triangle( c, b, a );
        mTriangles[ i ] = triangle;
    }

}
예제 #3
0
void FaceController::prepareFaceToSave(TriMesh2d mesh, gl::Texture surf, float headScale)
{
	genericName = "surf_"+to_string(facesStoreVector.size()) + ".png";	

	Rectf rect =	mesh.calcBoundingBox();	

	vector<ci::Vec2f> savecords;
	savecords.clear();
	for (int i = 0; i < mesh.getNumVertices(); i++)
		 savecords.push_back(Vec2f( ( mesh.getVertices()[i].x-rect.x1 )/surf.getWidth(), (mesh.getVertices()[i].y -rect.y1)/surf.getHeight())); 	
	
	FaceObject newface;
	newface.setPoints(savecords);
	newface.setTexName(genericName);
	newface.setTexture(surf);

	facesStoreVector.push_back(newface);
	writeImage( getAppPath() /FACE_STORAGE_FOLDER/genericName, surf);
}
예제 #4
0
void DelayFeedback::loadMesh()
{
	Rectf boundingBox( - MAX_RADIUS, - MAX_RADIUS, MAX_RADIUS, MAX_RADIUS );

	TriMesh2d mesh;

	mesh.appendVertex( boundingBox.getUpperLeft() );
	mesh.appendTexCoord( Vec2f( -1, -1 ) );

	mesh.appendVertex( boundingBox.getLowerLeft() );
	mesh.appendTexCoord( Vec2f( -1, 1 ) );

	mesh.appendVertex( boundingBox.getUpperRight() );
	mesh.appendTexCoord( Vec2f( 1, -1 ) );

	mesh.appendVertex( boundingBox.getLowerRight() );
	mesh.appendTexCoord( Vec2f( 1, 1 ) );

	mesh.appendTriangle( 0, 1, 2 );
	mesh.appendTriangle( 2, 1, 3 );

	mMesh = gl::VboMesh::create( mesh );
}
예제 #5
0
VboMesh::VboMesh( const TriMesh2d &triMesh, Layout layout )
	: mObj( shared_ptr<Obj>( new Obj ) )
{
	if( layout.isDefaults() ) { // we need to start by preparing our layout
		if( triMesh.hasColorsRgb() )
			mObj->mLayout.setStaticColorsRGB();
		if( triMesh.hasColorsRgba() )
			mObj->mLayout.setStaticColorsRGBA();
		if( triMesh.hasTexCoords() )
			mObj->mLayout.setStaticTexCoords2d();
		mObj->mLayout.setStaticIndices();
		mObj->mLayout.setStaticPositions();
	}
	else
		mObj->mLayout = layout;

	mObj->mPrimitiveType = GL_TRIANGLES;
	mObj->mNumIndices = triMesh.getNumIndices();
	mObj->mNumVertices = triMesh.getNumVertices();

	initializeBuffers( false );
			
	// upload the indices
	getIndexVbo().bufferData( sizeof(uint32_t) * triMesh.getNumIndices(), &(triMesh.getIndices()[0]), (mObj->mLayout.hasStaticIndices()) ? GL_STATIC_DRAW : GL_STREAM_DRAW );
	
	// upload the verts
	for( int buffer = STATIC_BUFFER; buffer <= DYNAMIC_BUFFER; ++buffer ) {
		if( ! mObj->mBuffers[buffer] )
			continue;
		
		uint8_t *ptr = mObj->mBuffers[buffer].map( GL_WRITE_ONLY );
		
		bool copyPosition = ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticPositions() : mObj->mLayout.hasDynamicPositions();
		bool copyColorRGB = ( ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticColorsRGB() : mObj->mLayout.hasDynamicColorsRGB() ) && triMesh.hasColorsRgb();
		bool copyColorRGBA = ( ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticColorsRGBA() : mObj->mLayout.hasDynamicColorsRGBA() ) && triMesh.hasColorsRgba();
		bool copyTexCoord2D = ( ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticTexCoords2d() : mObj->mLayout.hasDynamicTexCoords2d() ) && triMesh.hasTexCoords();
		
		for( size_t v = 0; v < mObj->mNumVertices; ++v ) {
			if( copyPosition ) {
				const Vec2f &p = triMesh.getVertices()[v];
				*(reinterpret_cast<Vec3f*>(ptr)) = Vec3f( p.x, p.y, 0 );
				ptr += sizeof( Vec3f );
			}
			if( copyColorRGB ) {
				*(reinterpret_cast<Color*>(ptr)) = triMesh.getColorsRGB()[v];
				ptr += sizeof( Color );
			}
			if( copyColorRGBA ) {
				*(reinterpret_cast<ColorA*>(ptr)) = triMesh.getColorsRGBA()[v];
				ptr += sizeof( Color );
			}
			if( copyTexCoord2D ) {
				*(reinterpret_cast<Vec2f*>(ptr)) = triMesh.getTexCoords()[v];
				ptr += sizeof( Vec2f );
			}
		}
		
		mObj->mBuffers[buffer].unmap();
	}

	unbindBuffers();	
}