Hi I would like to know how to access the vertex position and indices using
VBOMesh
TriMesh
ObjLoader.
PS Reply ASAP
Hi I would like to know how to access the vertex position and indices using
VBOMesh
TriMesh
ObjLoader.
PS Reply ASAP
Here’s a snippet from a project I’m working on that pulls out some vertex data and indices from a TriMesh, to use them in a compute shader:
void MeshVolumizerApp::makeVertexBuffers()
{
	if( ! mMesh ) {
		CI_LOG_E( "no mesh loaded" );
		return;
	}
	if( ! mMesh->hasTexCoords() ) {
		CI_LOG_E( "mesh has no tex coords" );
		// will still process but texCoords will all be (0, 0)
	}
	// upload vertex data
	size_t numVertices = mMesh->getNumVertices();
	const auto &positions = mMesh->getPositions<3>();
	const auto &normals = mMesh->getNormals();
	vector<VertexData> vertData;
	for( size_t i = 0; i < numVertices; i++ ) {
		VertexData v;
		v.pos = vec4( positions[i], 0 );
		if( mMesh->hasTexCoords() ) {
			v.texCoord = vec4( mMesh->getTexCoords0<2>()[i], 0, 0 );
		}
		v.normal = vec4( normals[i], 0 );
		vertData.push_back( v );
	}
	mSsboVertexData = gl::Ssbo::create( vertData.size() * sizeof( VertexData ), vertData.data(), GL_STATIC_DRAW );
	// upload indices
	const auto &indices = mMesh->getIndices();
	vector<TriangleData> facesData;
	for( size_t i = 0; i < indices.size(); /* */ ) {
		TriangleData face;
		face.indices.x = indices[i++];
		face.indices.y = indices[i++];
		face.indices.z = indices[i++];
		face.indices.w = 0;
		facesData.push_back( face );
	}
	mSsboIndexData = gl::Ssbo::create( facesData.size() * sizeof( TriangleData ), facesData.data(), GL_STATIC_DRAW );
}
If you have more specific questions feel free to ask.
Cheers,
Rich