| 104 | }; |
| 105 | |
| 106 | IECore::RunTimeTypedPtr ToGLCurvesConverter::doConversion( IECore::ConstObjectPtr src, IECore::ConstCompoundObjectPtr operands ) const |
| 107 | { |
| 108 | IECoreScene::CurvesPrimitive::ConstPtr curves = boost::static_pointer_cast<const IECoreScene::CurvesPrimitive>( src ); // safe because the parameter validated it for us |
| 109 | |
| 110 | IECore::V3fVectorData::ConstPtr points = curves->variableData<IECore::V3fVectorData>( "P", IECoreScene::PrimitiveVariable::Vertex ); |
| 111 | if( !points ) |
| 112 | { |
| 113 | throw IECore::Exception( "Must specify primitive variable \"P\", of type V3fVectorData and interpolation type Vertex." ); |
| 114 | } |
| 115 | |
| 116 | IECore::FloatData::ConstPtr widthData = curves->variableData<IECore::FloatData>( "width", IECoreScene::PrimitiveVariable::Constant ); |
| 117 | if( !widthData ) |
| 118 | { |
| 119 | widthData = curves->variableData<IECore::FloatData>( "constantwidth", IECoreScene::PrimitiveVariable::Constant ); |
| 120 | } |
| 121 | |
| 122 | float width = 1; |
| 123 | if( widthData ) |
| 124 | { |
| 125 | width = widthData->readable(); |
| 126 | } |
| 127 | |
| 128 | CurvesPrimitive::Ptr result = new CurvesPrimitive( curves->basis(), curves->periodic(), curves->verticesPerCurve(), width ); |
| 129 | |
| 130 | for ( IECoreScene::PrimitiveVariableMap::const_iterator pIt = curves->variables.begin(); pIt != curves->variables.end(); ++pIt ) |
| 131 | { |
| 132 | if( !pIt->second.data ) |
| 133 | { |
| 134 | IECore::msg( IECore::Msg::Warning, "ToGLCurvesConverter", boost::format( "No data given for primvar \"%s\"" ) % pIt->first ); |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | if( pIt->second.interpolation == IECoreScene::PrimitiveVariable::Vertex || pIt->second.interpolation == IECoreScene::PrimitiveVariable::Constant ) |
| 139 | { |
| 140 | result->addPrimitiveVariable( pIt->first, pIt->second ); |
| 141 | } |
| 142 | else if( pIt->second.interpolation == IECoreScene::PrimitiveVariable::Uniform ) |
| 143 | { |
| 144 | ToVertexConverter converter( curves->verticesPerCurve()->readable(), curves->variableSize( IECoreScene::PrimitiveVariable::Vertex ), 1 ); |
| 145 | // todo : convert to Vertex interpolation using indices if they exist. For now we just expand the data. |
| 146 | // todo : Note crash was discovered when converting a indexed uniform string primvar for viewport rendering - can we do anything with this data? |
| 147 | auto expandedData = pIt->second.expandedData(); |
| 148 | IECore::DataPtr newData = IECore::despatchTypedData<ToVertexConverter, IECore::TypeTraits::IsVectorTypedData>( expandedData.get(), converter ); |
| 149 | if( newData ) |
| 150 | { |
| 151 | result->addPrimitiveVariable( pIt->first, IECoreScene::PrimitiveVariable( IECoreScene::PrimitiveVariable::Vertex, newData ) ); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return result; |
| 157 | } |
nothing calls this directly
no test coverage detected