void GeometryApp::loadGeomSource( const geom::Source &source, const geom::Source &sourceWire ) { // The purpose of the TriMesh is to capture a bounding box; without that need we could just instantiate the Batch directly using primitive TriMesh::Format fmt = TriMesh::Format().positions().normals().texCoords().tangents(); if( mShowColors && source.getAvailableAttribs().count( geom::COLOR ) > 0 ) fmt.colors(); TriMesh mesh( source, fmt ); AxisAlignedBox bbox = mesh.calcBoundingBox(); mCameraLerpTarget = mesh.calcBoundingBox().getCenter(); mCameraViewDirection = mCamera.getViewDirection(); mRecenterCamera = true; if( mPhongShader ) mPrimitive = gl::Batch::create( mesh, mPhongShader ); if( mWireShader ) mPrimitiveWire = gl::Batch::create( sourceWire, mWireShader ); if( mWireframeShader ) mPrimitiveWireframe = gl::Batch::create( mesh, mWireframeShader ); vec3 size = bbox.getMax() - bbox.getMin(); float scale = std::max( std::max( size.x, size.y ), size.z ) / 25.0f; mPrimitiveNormalLines = gl::Batch::create( mesh >> geom::VertexNormalLines( scale ), gl::getStockShader( gl::ShaderDef().color() ) ); if( mesh.hasTangents() ) mPrimitiveTangentLines = gl::Batch::create( mesh >> geom::VertexNormalLines( scale, geom::TANGENT ), gl::getStockShader( gl::ShaderDef().color() ) ); else
void GeometryApp::loadGeomSource( const geom::Source &source ) { // The purpose of the TriMesh is to capture a bounding box; without that need we could just instantiate the Batch directly using primitive TriMesh::Format fmt = TriMesh::Format().positions().normals().texCoords(); if( mShowColors && source.getAvailableAttribs().count( geom::COLOR ) > 0 ) fmt.colors(); TriMesh mesh( source, fmt ); AxisAlignedBox3f bbox = mesh.calcBoundingBox(); mCameraCOI = mesh.calcBoundingBox().getCenter(); mRecenterCamera = true; if( mSubdivision > 1 ) mesh.subdivide( mSubdivision ); if( mPhongShader ) mPrimitive = gl::Batch::create( mesh, mPhongShader ); if( mWireframeShader ) mPrimitiveWireframe = gl::Batch::create( mesh, mWireframeShader ); vec3 size = bbox.getMax() - bbox.getMin(); float scale = std::max( std::max( size.x, size.y ), size.z ) / 25.0f; mPrimitiveNormalLines = gl::Batch::create( geom::VertexNormalLines( mesh, scale ), gl::getStockShader( gl::ShaderDef().color() ) ); getWindow()->setTitle( "Geometry - " + to_string( mesh.getNumVertices() ) + " vertices" ); }
Batch::Batch( const geom::Source &source, const gl::GlslProgRef &glsl, const AttributeMapping &attributeMapping ) : mGlsl( glsl ) { geom::AttribSet attribs; // include all the attributes in the custom attributeMapping for( const auto &attrib : attributeMapping ) { if( source.getAttribDims( attrib.first ) ) attribs.insert( attrib.first ); } // and then the attributes references by the GLSL for( const auto &attrib : glsl->getActiveAttributes() ) { if( source.getAttribDims( attrib.getSemantic() ) ) attribs.insert( attrib.getSemantic() ); } mVboMesh = gl::VboMesh::create( source, attribs ); initVao( attributeMapping ); }