| 66 | } |
| 67 | |
| 68 | IECore::RunTimeTypedPtr ToGLMeshConverter::doConversion( IECore::ConstObjectPtr src, IECore::ConstCompoundObjectPtr operands ) const |
| 69 | { |
| 70 | IECoreScene::MeshPrimitivePtr mesh = boost::static_pointer_cast<IECoreScene::MeshPrimitive>( src->copy() ); // safe because the parameter validated it for us |
| 71 | |
| 72 | if( !mesh->variableData<IECore::V3fVectorData>( "P", IECoreScene::PrimitiveVariable::Vertex ) ) |
| 73 | { |
| 74 | throw IECore::Exception( "Must specify primitive variable \"P\", of type V3fVectorData and interpolation type Vertex." ); |
| 75 | } |
| 76 | |
| 77 | if( mesh->variables.find( "N" )==mesh->variables.end() ) |
| 78 | { |
| 79 | // the mesh has no normals - we need to explicitly add some. if it's a polygon |
| 80 | // mesh (interpolation==linear) then we add per-face normals for a faceted look |
| 81 | // and if it's a subdivision mesh we add smooth per-vertex normals. |
| 82 | IECoreScene::MeshNormalsOpPtr normalOp = new IECoreScene::MeshNormalsOp(); |
| 83 | normalOp->inputParameter()->setValue( mesh ); |
| 84 | normalOp->copyParameter()->setTypedValue( false ); |
| 85 | normalOp->interpolationParameter()->setNumericValue( |
| 86 | mesh->interpolation() == "linear" ? IECoreScene::PrimitiveVariable::Uniform : IECoreScene::PrimitiveVariable::Vertex |
| 87 | ); |
| 88 | normalOp->operate(); |
| 89 | } |
| 90 | |
| 91 | mesh = IECoreScene::MeshAlgo::triangulate( mesh.get() ); |
| 92 | |
| 93 | IECoreScene::FaceVaryingPromotionOpPtr faceVaryingOp = new IECoreScene::FaceVaryingPromotionOp; |
| 94 | faceVaryingOp->inputParameter()->setValue( mesh ); |
| 95 | faceVaryingOp->copyParameter()->setTypedValue( false ); |
| 96 | faceVaryingOp->operate(); |
| 97 | |
| 98 | MeshPrimitivePtr glMesh = new MeshPrimitive( mesh->numFaces() ); |
| 99 | |
| 100 | for ( IECoreScene::PrimitiveVariableMap::iterator pIt = mesh->variables.begin(); pIt != mesh->variables.end(); ++pIt ) |
| 101 | { |
| 102 | if( pIt->second.data ) |
| 103 | { |
| 104 | glMesh->addPrimitiveVariable( pIt->first, pIt->second ); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | IECore::msg( IECore::Msg::Warning, "ToGLMeshConverter", boost::format( "No data given for primvar \"%s\"" ) % pIt->first ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return glMesh; |
| 113 | } |
nothing calls this directly
no test coverage detected