void SceneGadget::setSelection( const IECore::PathMatcher &selection ) { m_selection = selection; ConstDataPtr d = new IECore::PathMatcherData( selection ); m_renderer->option( "gl:selection", d.get() ); requestRender(); }
DataPtr readTransformAtSample( SampledSceneInterface &m, size_t sampleIndex ) { ConstDataPtr d = m.readTransformAtSample(sampleIndex); if ( d ) { return d->copy(); } return 0; }
static DataPtr getAttribute( Group &g, const std::string &name ) { ConstDataPtr d = g.getAttribute( name ); if( d ) { return d->copy(); } return 0; }
static object get( Context &c, const IECore::InternedString &name ) { ConstDataPtr d = c.get<Data>( name ); try { return despatchTypedData<SimpleTypedDataGetter, TypeTraits::IsSimpleTypedData>( constPointerCast<Data>( d ) ); } catch( const InvalidArgumentException &e ) { return object( DataPtr( d->copy() ) ); } }
void IECoreAppleseed::BatchPrimitiveConverter::setOption( const string &name, ConstDataPtr value ) { if( name == "as:mesh_file_format" ) { if( const StringData *f = runTimeCast<const StringData>( value.get() ) ) { if( f->readable() == "binarymesh" ) { m_meshGeomExtension = ".binarymesh"; } else if( f->readable() == "obj" ) { m_meshGeomExtension = ".obj"; } else { msg( Msg::Warning, "IECoreAppleseed::RendererImplementation::setOption", format( "as:mesh_file_format, unknown mesh file format \"%s\"." ) % f->readable() ); } } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "as:mesh_file_format option expects a StringData value." ); } } else PrimitiveConverter::setOption( name, value ); }
void IECoreAppleseed::AttributeState::setAttribute( const string &name, ConstDataPtr value ) { m_attributes->writable()[name] = value->copy(); if( 0 == name.compare( 0, 14, "as:visibility:" ) ) { // visibility flags are not implemented yet in appleseed. return; } if( name == "name" ) { if( ConstStringDataPtr f = runTimeCast<const StringData>( value ) ) { m_name = f->readable(); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setAttribute", "name attribute expects a StringData value." ); } } else if( name == "as:alpha_map" ) { if( ConstStringDataPtr f = runTimeCast<const StringData>( value ) ) { m_shadingState.setAlphaMap( f->readable() ); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setAttribute", "as:alpha_map attribute expects a StringData value." ); } } else if( name == "as:shading_samples" ) { if( ConstIntDataPtr f = runTimeCast<const IntData>( value ) ) { m_shadingState.setShadingSamples( f->readable() ); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setAttribute", "as:shading_samples attribute expects an IntData value." ); } } else if( name == "gaffer:deformationBlurSegments" ) { if( ConstIntDataPtr f = runTimeCast<const IntData>( value ) ) { // round samples to the next power of 2 as // appleseed only supports power of 2 number of deformation segments. int samples = asf::next_pow2( f->readable() ); m_attributes->writable()[name] = new IntData( samples ); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setAttribute", "as:shading_samples attribute expects an IntData value." ); } } }
string IECoreAppleseed::dataToString( ConstDataPtr value ) { stringstream ss; switch( value->typeId() ) { case IntDataTypeId : { int x = static_cast<const IntData*>( value.get() )->readable(); ss << x; } break; case FloatDataTypeId : { float x = static_cast<const FloatData*>( value.get() )->readable(); ss << x; } break; case StringDataTypeId : { const string &x = static_cast<const StringData*>( value.get() )->readable(); ss << x; } break; case V2iDataTypeId : { const Imath::V2i &x = static_cast<const V2iData*>( value.get() )->readable(); ss << x.x << ", " << x.y; } break; case Color3fDataTypeId : { const Imath::Color3f &x = static_cast<const Color3fData*>( value.get() )->readable(); ss << x.x << ", " << x.y << ", " << x.z; } break; case BoolDataTypeId : { bool x = static_cast<const BoolData*>( value.get() )->readable(); ss << x; } break; default: break; } return ss.str(); }
void IECoreAppleseed::PrimitiveConverter::setOption( const string &name, ConstDataPtr value ) { if( name == "as:automatic_instancing" ) { if( const BoolData *f = runTimeCast<const BoolData>( value.get() ) ) { m_autoInstancing = f->readable(); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "as:automatic_instancing option expects a BoolData value." ); } } }
void RenderManShader::loadShaderParameters( const IECore::Shader *shader, Gaffer::CompoundPlug *parametersPlug, bool keepExistingValues ) { const CompoundData *typeHints = shader->blindData()->member<CompoundData>( "ri:parameterTypeHints", true ); const StringVectorData *orderedParameterNamesData = shader->blindData()->member<StringVectorData>( "ri:orderedParameterNames", true ); const vector<string> &orderedParameterNames = orderedParameterNamesData->readable(); const StringVectorData *outputParameterNamesData = shader->blindData()->member<StringVectorData>( "ri:outputParameterNames", true ); const vector<string> &outputParameterNames = outputParameterNamesData->readable(); const CompoundData *annotations = shader->blindData()->member<CompoundData>( "ri:annotations", true ); // if we're not preserving existing values then remove all existing parameter plugs - the various // plug creators above know that if a plug exists then they should preserve its values. if( !keepExistingValues ) { for( int i = parametersPlug->children().size() - 1; i >= 0; --i ) { parametersPlug->removeChild( parametersPlug->getChild<GraphComponent>( i ) ); } } // make sure we have a plug to represent each parameter, reusing plugs wherever possible. set<string> validPlugNames; for( vector<string>::const_iterator it = orderedParameterNames.begin(), eIt = orderedParameterNames.end(); it != eIt; it++ ) { if( std::find( outputParameterNames.begin(), outputParameterNames.end(), *it ) != outputParameterNames.end() ) { continue; } // splines are represented by two parameters matched by a naming convention, and we map // those two parameters to a single SplinePlug. const bool endsWithValues = ends_with( *it, "Values" ); const bool endsWithPositions = ends_with( *it, "Positions" ); if( endsWithPositions || endsWithValues ) { string plugName( *it, 0, it->size() - ( endsWithValues ? 6 : 9 ) ); if( validPlugNames.find( plugName ) != validPlugNames.end() ) { continue; } // must use a smart pointers here because we may assign the data the parser creates (and which we therefore own) ConstFloatVectorDataPtr positions = shader->parametersData()->member<FloatVectorData>( plugName + "Positions" ); ConstDataPtr values = shader->parametersData()->member<Data>( plugName + "Values" ); if( positions && values ) { const StringData *defaultValuesAnnotation = annotations->member<StringData>( plugName + "Values.defaultValue" ); const StringData *defaultPositionsAnnotation = annotations->member<StringData>( plugName + "Positions.defaultValue" ); if( defaultValuesAnnotation ) { DataPtr parsedValues; if( values->isInstanceOf( Color3fVectorData::staticTypeId() ) ) { parsedValues = parseColors( defaultValuesAnnotation->readable() ); } else { parsedValues = parseFloats( defaultValuesAnnotation->readable() ); } if( parsedValues ) { values = parsedValues; } else { msg( Msg::Warning, "RenderManShader::loadShaderParameters", boost::format( "Unable to parse default value \"%s\" for parameter \"%s\"" ) % defaultValuesAnnotation->readable() % ( plugName + "Values" ) ); } } if( defaultPositionsAnnotation ) { FloatVectorDataPtr parsedPositions = parseFloats( defaultPositionsAnnotation->readable() ); if( parsedPositions ) { positions = parsedPositions; } else { msg( Msg::Warning, "RenderManShader::loadShaderParameters", boost::format( "Unable to parse default value \"%s\" for parameter \"%s\"" ) % defaultPositionsAnnotation->readable() % ( plugName + "Positions" ) ); } } switch( values->typeId() ) { case FloatVectorDataTypeId : loadSplineParameter<SplineffPlug>( parametersPlug, plugName, positions, values ); break; case Color3fVectorDataTypeId : loadSplineParameter<SplinefColor3fPlug>( parametersPlug, plugName, positions, values ); break; default : msg( Msg::Warning, "RenderManShader::loadShaderParameters", boost::format( "Spline \"%s\" has unsupported value type \"%s\"" ) % plugName % values->typeName() ); } validPlugNames.insert( plugName ); continue; } } // the other parameter types map more simply to a single plug each. const StringData *typeHint = typeHints->member<StringData>( *it, false ); const Data *defaultValue = shader->parametersData()->member<Data>( *it ); switch( defaultValue->typeId() ) { case StringDataTypeId : if( typeHint && typeHint->readable() == "shader" ) { loadCoshaderParameter( parametersPlug, *it ); } else { loadParameter<StringPlug>( parametersPlug, *it, static_cast<const StringData *>( defaultValue )->readable() ); } break; case FloatDataTypeId : loadNumericParameter( parametersPlug, *it, static_cast<const FloatData *>( defaultValue )->readable(), annotations ); break; case Color3fDataTypeId : loadCompoundNumericParameter<Color3fPlug>( parametersPlug, *it, static_cast<const Color3fData *>( defaultValue )->readable(), annotations ); break; case V3fDataTypeId : loadCompoundNumericParameter<V3fPlug>( parametersPlug, *it, static_cast<const V3fData *>( defaultValue )->readable(), annotations ); break; case StringVectorDataTypeId : if( typeHint && typeHint->readable() == "shader" ) { loadCoshaderArrayParameter( parametersPlug, *it, static_cast<const StringVectorData *>( defaultValue ) ); } else { loadArrayParameter<StringVectorDataPlug>( parametersPlug, *it, defaultValue, annotations ); } break; case FloatVectorDataTypeId : loadArrayParameter<FloatVectorDataPlug>( parametersPlug, *it, defaultValue, annotations ); break; case Color3fVectorDataTypeId : loadArrayParameter<Color3fVectorDataPlug>( parametersPlug, *it, defaultValue, annotations ); break; case V3fVectorDataTypeId : loadArrayParameter<V3fVectorDataPlug>( parametersPlug, *it, defaultValue, annotations ); break; default : msg( Msg::Warning, "RenderManShader::loadShaderParameters", boost::format( "Parameter \"%s\" has unsupported type \"%s\"" ) % *it % defaultValue->typeName() ); } validPlugNames.insert( *it ); } // remove any old plugs which it turned out we didn't need if( keepExistingValues ) { for( int i = parametersPlug->children().size() - 1; i >= 0; --i ) { GraphComponent *child = parametersPlug->getChild<GraphComponent>( i ); if( validPlugNames.find( child->getName().string() ) == validPlugNames.end() ) { parametersPlug->removeChild( child ); } } } }
void IECoreAppleseed::RendererImplementation::setOption( const string &name, ConstDataPtr value ) { m_optionsMap[name] = value; if( 0 == name.compare( 0, 7, "as:cfg:" ) ) { // appleseed render settings. string optName( name, 7, string::npos ); replace( optName.begin(), optName.end(), ':', '.' ); string valueStr = dataToString( value ); if( !valueStr.empty() ) { if( optName == "rendering_threads" ) { if( const IntData *numThreadsData = runTimeCast<const IntData>( value.get() ) ) { // if numThreads is 0, we want to use all the CPU cores. // We can remove any previous "rendering_threads" param and // let appleseed choose the number of threads to use. if( numThreadsData->readable() == 0 ) { m_project->configurations().get_by_name( "final" )->get_parameters().remove_path( optName.c_str() ); m_project->configurations().get_by_name( "interactive" )->get_parameters().remove_path( optName.c_str() ); return; } } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "as:cfg:rendering_threads option expects an IntData value." ); } } else if( algorithm::ends_with( optName, "max_path_length" ) ) { if( const IntData *maxPathLengthData = runTimeCast<const IntData>( value.get() ) ) { // if maxPathLength is 0, we want to use and unlimited number of bounces and let // russian roulette terminate paths when their contribution is too low. // We can disable max path lengths by remove any previous param. if( maxPathLengthData->readable() == 0 ) { m_project->configurations().get_by_name( "final" )->get_parameters().remove_path( optName.c_str() ); m_project->configurations().get_by_name( "interactive" )->get_parameters().remove_path( optName.c_str() ); return; } } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", format( "%s option expects an IntData value." ) % optName ); } } else if( optName == "pt.max_ray_intensity" ) { if( const FloatData *maxIntensityData = runTimeCast<const FloatData>( value.get() ) ) { // if maxIntensity is 0 disable it. if( maxIntensityData->readable() == 0.0f ) { m_project->configurations().get_by_name( "final" )->get_parameters().remove_path( optName.c_str() ); m_project->configurations().get_by_name( "interactive" )->get_parameters().remove_path( optName.c_str() ); return; } } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "as:cfg:pt:max_ray_intensity option expects a FloatData value." ); } } else if( optName == "generic_frame_renderer.passes" ) { if( const IntData *numPassesData = runTimeCast<const IntData>( value.get() ) ) { int numPasses = numPassesData->readable(); // if the number of passes is greater than one, we need to // switch the shading result framebuffer in the final rendering config. m_project->configurations().get_by_name( "final" )->get_parameters().insert( "shading_result_framebuffer", numPasses > 1 ? "permanent" : "ephemeral" ); // enable decorrelate pixels if the number of render passes is greater than one. m_project->configurations().get_by_name( "final" )->get_parameters().insert_path( "uniform_pixel_renderer.decorrelate_pixels", numPasses > 1 ? "true" : "false" ); m_project->configurations().get_by_name( "interactive" )->get_parameters().insert_path( "uniform_pixel_renderer.decorrelate_pixels", numPasses > 1 ? "true" : "false" ); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "as:cfg:generic_frame_renderer:passes option expects an IntData value." ); } } m_project->configurations().get_by_name( "final" )->get_parameters().insert_path( optName.c_str(), valueStr.c_str() ); m_project->configurations().get_by_name( "interactive" )->get_parameters().insert_path( optName.c_str(), valueStr.c_str() ); } } else if( 0 == name.compare( 0, 3, "as:" ) ) { // other appleseed options. string optName( name, 3, string::npos ); if( optName == "searchpath" ) { if( const StringData *searchPathData = runTimeCast<const StringData>( value.get() ) ) { m_project->search_paths().push_back( searchPathData->readable().c_str() ); } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "as:searchpath option expects a StringData value." ); } } else if( optName == "mesh_file_format" ) { m_primitiveConverter->setOption( name, value ); } else if( optName == "automatic_instancing" ) { m_primitiveConverter->setOption( name, value ); } } else if( name.find_first_of( ":" )!=string::npos ) { // ignore options prefixed for some other renderer } else if( name == "editable" ) { if( const BoolData *editableData = runTimeCast<const BoolData>( value.get() ) ) { if( editableData->readable() ) { m_editHandler.reset( new EditBlockHandler( *m_project ) ); } else { m_editHandler.reset(); } } else { msg( Msg::Error, "IECoreAppleseed::RendererImplementation::setOption", "editable option expects an BoolData value." ); } } else { msg( Msg::Warning, "IECoreAppleseed::RendererImplementation::setOption", format( "Unknown option \"%s\"." ) % name ); } }