void IECoreMantra::ProceduralPrimitive::applySettings() { // Shaders are hidden in the attribute stack with a ':' prefix. // The renderer method Shader() stores them as a full shader invocation string. CompoundDataMap::const_iterator s_it = m_renderer->m_attributeStack.top().attributes->readable().find(":surface"); if ( s_it != m_renderer->m_attributeStack.top().attributes->readable().end() ) { ConstStringDataPtr s = runTimeCast<const StringData>( s_it->second ); changeSetting("surface", s->readable().c_str(), "object"); } CompoundDataMap::const_iterator a_it; for (a_it = m_renderer->m_attributeStack.top().attributes->readable().begin(); a_it != m_renderer->m_attributeStack.top().attributes->readable().end(); a_it++) { std::string name = a_it->first; if ( name.compare(0, 1, ":") == 0 ) // skip internal attributes { continue; } std::string ifd, type; m_renderer->ifdString( a_it->second, ifd, type); /// \todo there are more efficient changeSetting methods that don't use string values changeSetting( name.c_str(), ifd.c_str() ); } }
ImageDisplayDriver::ImageDisplayDriver( const Box2i &displayWindow, const Box2i &dataWindow, const vector<string> &channelNames, ConstCompoundDataPtr parameters ) : DisplayDriver( displayWindow, dataWindow, channelNames, parameters ), m_image( new ImagePrimitive( dataWindow, displayWindow ) ) { for ( vector<string>::const_iterator it = channelNames.begin(); it != channelNames.end(); it++ ) { m_image->createChannel<float>( *it ); } if( parameters ) { CompoundDataMap &xData = m_image->blindData()->writable(); const CompoundDataMap &yData = parameters->readable(); CompoundDataMap::const_iterator iterY = yData.begin(); for ( ; iterY != yData.end(); iterY++ ) { xData[iterY->first] = iterY->second->copy(); } ConstStringDataPtr handle = parameters->member<StringData>( "handle" ); if( handle ) { tbb::mutex::scoped_lock lock( g_poolMutex ); g_pool[handle->readable()] = m_image; } } }
void DisplayIop::driverCreated( NukeDisplayDriver *driver ) { ConstStringDataPtr portNumber = driver->parameters()->member<StringData>( "displayPort" ); if( portNumber && boost::lexical_cast<int>( portNumber->readable() ) == m_portNumber ) { firstDisplayIop()->connectToDriver( driver ); } }
void Display::driverCreated( GafferDisplayDriver *driver ) { ConstStringDataPtr portNumber = driver->parameters()->member<StringData>( "displayPort" ); if( portNumber && boost::lexical_cast<int>( portNumber->readable() ) == portPlug()->getValue() ) { setupDriver( driver ); } }
bool PlugAdder::canCreateConnection( const Gaffer::Plug *endpoint ) const { ConstStringDataPtr noduleType = Gaffer::Metadata::value<StringData>( endpoint, IECore::InternedString( "nodule:type" ) ); if( noduleType ) { if( noduleType->readable() == "GafferUI::CompoundNodule" ) { return false; } } return true; }
void StandardLightVisualiser::addBasicLightVisualiser( ConstStringDataPtr type, GroupPtr &output, Color3f multiplier, float coneAngle, float penumbraAngle, const std::string *penumbraType, float lensRadius ) { bool indicatorFaceCamera = false; if( !type || type->readable() == "point" ) { output->addChild( const_pointer_cast<IECoreGL::Renderable>( pointRays() ) ); indicatorFaceCamera = true; } else if( type->readable() == "spot" ) { float innerAngle = 0; float outerAngle = 0; if( !penumbraType || *penumbraType == "inset" ) { outerAngle = coneAngle; innerAngle = coneAngle - 2.0f * penumbraAngle; } else if( *penumbraType == "outset" ) { outerAngle = coneAngle + 2.0f * penumbraAngle; innerAngle = coneAngle ; } else if( *penumbraType == "absolute" ) { outerAngle = coneAngle; innerAngle = penumbraAngle; } output->addChild( const_pointer_cast<IECoreGL::Renderable>( spotlightCone( innerAngle, outerAngle, lensRadius ) ) ); output->addChild( const_pointer_cast<IECoreGL::Renderable>( ray() ) ); } else if( type->readable() == "distant" ) { for ( int i = 0; i < 3; i++ ) { IECoreGL::GroupPtr rayGroup = new IECoreGL::Group(); Imath::M44f trans; trans.rotate( V3f( 0, 0, 2.0 * M_PI / 3.0 * i ) ); trans.translate( V3f( 0, 0.4, 0.5 ) ); rayGroup->addChild( const_pointer_cast<IECoreGL::Renderable>( ray() ) ); rayGroup->setTransform( trans ); output->addChild( rayGroup ); } } output->addChild( const_pointer_cast<IECoreGL::Renderable>( colorIndicator( multiplier, indicatorFaceCamera ) ) ); }
const std::string &SpherePrimitiveEvaluator::Result::stringPrimVar( const PrimitiveVariable &pv ) const { ConstStringDataPtr data = runTimeCast< const StringData >( pv.data ); if (data) { return data->readable(); } else { ConstStringVectorDataPtr data = runTimeCast< const StringVectorData >( pv.data ); if (data) { return data->readable()[0]; } } throw InvalidArgumentException( "Could not retrieve primvar data for SpherePrimitiveEvaluator" ); }
void Dot::setup( const Plug *plug ) { const Plug *originalPlug = plug; if( const Plug *inputPlug = plug->getInput() ) { // We'd prefer to set up based on an input plug if possible - see comments // in DotNodeGadgetTest.testCustomNoduleTangentsPreferInputIfAvailable(). plug = inputPlug; } Gaffer::PlugPtr in = plug->createCounterpart( g_inPlugName, Plug::In ); Gaffer::PlugPtr out = plug->createCounterpart( g_outPlugName, Plug::Out ); MetadataAlgo::copyColors( originalPlug , in.get() , /* overwrite = */ false ); MetadataAlgo::copyColors( originalPlug , out.get() , /* overwrite = */ false ); in->setFlags( Plug::Serialisable, true ); out->setFlags( Plug::Serialisable, true ); // Set up Metadata so our plugs appear in the right place. We must do this now rather // than later because the GraphEditor will add a Nodule for the plug as soon as the plug // is added as a child. ConstStringDataPtr sectionData; for( const Plug *metadataPlug = plug; metadataPlug; metadataPlug = metadataPlug->parent<Plug>() ) { if( ( sectionData = Metadata::value<StringData>( metadataPlug, g_sectionName ) ) ) { break; } } if( sectionData ) { const std::string §ion = sectionData->readable(); std::string oppositeSection; if( section == "left" ) { oppositeSection = "right"; } else if( section == "right" ) { oppositeSection = "left"; } else if( section == "bottom" ) { oppositeSection = "top"; } else { oppositeSection = "bottom"; } Metadata::registerValue( plug->direction() == Plug::In ? in.get() : out.get(), g_sectionName, sectionData ); Metadata::registerValue( plug->direction() == Plug::In ? out.get() : in.get(), g_sectionName, new StringData( oppositeSection ) ); } setChild( g_inPlugName, in ); setChild( g_outPlugName, out ); out->setInput( in ); }
IECoreGL::ConstRenderablePtr StandardLightVisualiser::visualise( const IECore::InternedString &attributeName, const IECore::ObjectVector *shaderVector, IECoreGL::ConstStatePtr &state ) const { if( !shaderVector || shaderVector->members().size() == 0 ) { return NULL; } IECore::InternedString metadataTarget; const IECore::CompoundData *shaderParameters = NULL; if( const IECore::Shader *shader = IECore::runTimeCast<const IECore::Shader>( shaderVector->members().back().get() ) ) { metadataTarget = attributeName.string() + ":" + shader->getName(); shaderParameters = shader->parametersData(); } else if( const IECore::Light *light = IECore::runTimeCast<const IECore::Light>( shaderVector->members().back().get() ) ) { /// \todo Remove once all Light node derived classes are /// creating only shaders. metadataTarget = attributeName.string() + ":" + light->getName(); shaderParameters = light->parametersData().get(); } if( !shaderParameters ) { return NULL; } ConstStringDataPtr type = Metadata::value<StringData>( metadataTarget, "type" ); ConstM44fDataPtr orientation = Metadata::value<M44fData>( metadataTarget, "visualiserOrientation" ); const Color3f color = parameter<Color3f>( metadataTarget, shaderParameters, "colorParameter", Color3f( 1.0f ) ); const float intensity = parameter<float>( metadataTarget, shaderParameters, "intensityParameter", 1 ); const float exposure = parameter<float>( metadataTarget, shaderParameters, "exposureParameter", 0 ); const Color3f finalColor = color * intensity * pow( 2.0f, exposure ); if( type && type->readable() == "area" ) { const std::string textureName = parameter<std::string>( metadataTarget, shaderParameters, "textureNameParameter", "" ); const bool flipNormal = parameter<bool>( metadataTarget, shaderParameters, "flipNormalParameter", 0 ); const bool doubleSided = parameter<bool>( metadataTarget, shaderParameters, "doubleSidedParameter", 0 ); const bool sphericalProjection = parameter<bool>( metadataTarget, shaderParameters, "sphericalProjectionParameter", 0 ); M44f projectionTransform = parameter<M44f>( metadataTarget, shaderParameters, "projectionTransformParameter", M44f() ); const std::vector<float> projectionTransformVector = parameter<std::vector<float> >( metadataTarget, shaderParameters, "projectionTransformParameter", std::vector<float>() ); if( projectionTransformVector.size() == 16 ) { projectionTransform = M44f( (float(*)[4])(&projectionTransformVector[0]) ); } addAreaLightVisualiser( state, finalColor, textureName, flipNormal, doubleSided, sphericalProjection, projectionTransform ); return NULL; } GroupPtr result = new Group; const float locatorScale = parameter<float>( metadataTarget, shaderParameters, "locatorScaleParameter", 1 ); Imath::M44f topTrans; if( orientation ) { topTrans = orientation->readable(); } topTrans.scale( V3f( locatorScale ) ); result->setTransform( topTrans ); if( type && type->readable() == "environment" ) { const std::string textureName = parameter<std::string>( metadataTarget, shaderParameters, "textureNameParameter", "" ); addEnvLightVisualiser( result, finalColor, textureName ); } else { float coneAngle = parameter<float>( metadataTarget, shaderParameters, "coneAngleParameter", 0.0f ); float penumbraAngle = parameter<float>( metadataTarget, shaderParameters, "penumbraAngleParameter", 0.0f ); if( ConstStringDataPtr angleUnit = Metadata::value<StringData>( metadataTarget, "angleUnit" ) ) { if( angleUnit->readable() == "radians" ) { coneAngle *= 180.0 / M_PI; penumbraAngle *= 180 / M_PI; } } const std::string *penumbraType = NULL; ConstStringDataPtr penumbraTypeData = Metadata::value<StringData>( metadataTarget, "penumbraType" ); if( penumbraTypeData ) { penumbraType = &penumbraTypeData->readable(); } float lensRadius = 0.0f; if( parameter<bool>( metadataTarget, shaderParameters, "lensRadiusEnableParameter", true ) ) { lensRadius = parameter<float>( metadataTarget, shaderParameters, "lensRadiusParameter", 0.0f ); } addBasicLightVisualiser( type, result, finalColor, coneAngle, penumbraAngle, penumbraType, lensRadius / locatorScale ); } return result; }
SceneInterfacePtr LinkedScene::scene( const Path &path, MissingBehaviour missingBehaviour ) { if ( missingBehaviour == SceneInterface::CreateIfMissing ) { throw Exception( "createIfMissing is not supported!" ); } SceneInterfacePtr s = m_mainScene->scene( SceneInterface::rootPath ); Path::const_iterator pIt; /// first try to get as close as possible using the m_mainScene... for ( pIt = path.begin(); pIt != path.end(); pIt++ ) { SceneInterfacePtr n = s->child( *pIt, SceneInterface::NullIfMissing ); if ( !n ) { break; } s = n; } ConstSceneInterfacePtr l = 0; int linkDepth = 0; bool atLink = false; bool timeRemapped = false; if ( s->hasAttribute( fileNameLinkAttribute ) && s->hasAttribute( rootLinkAttribute ) ) { atLink = true; timeRemapped = s->hasAttribute( timeLinkAttribute ); ConstStringDataPtr fileName = runTimeCast< const StringData >( s->readAttribute( fileNameLinkAttribute, 0 ) ); ConstInternedStringVectorDataPtr root = runTimeCast< const InternedStringVectorData >( s->readAttribute( rootLinkAttribute, 0 ) ); l = expandLink( fileName.get(), root.get(), linkDepth ); if (!l) { atLink = false; timeRemapped = false; } } else if( s->hasAttribute( linkAttribute ) ) { atLink = true; ConstCompoundDataPtr d = runTimeCast< const CompoundData >( s->readAttribute( linkAttribute, 0 ) ); l = expandLink( d->member< const StringData >( g_fileName ), d->member< const InternedStringVectorData >( g_root ), linkDepth ); if ( !l ) { atLink = false; } } if ( pIt != path.end() ) { if ( !atLink ) { if ( missingBehaviour == SceneInterface::NullIfMissing ) { return 0; } throw Exception( "Could not find child '" + pIt->value() + "'" ); } for ( ; pIt != path.end(); pIt++ ) { l = l->child( *pIt, missingBehaviour ); if ( !l ) { return 0; } } atLink = false; } return new LinkedScene( s, l, linkDepth, m_readOnly, atLink, timeRemapped ); }
SceneInterfacePtr LinkedScene::child( const Name &name, MissingBehaviour missingBehaviour ) { if ( missingBehaviour == SceneInterface::CreateIfMissing ) { if ( m_readOnly ) { throw Exception( "No write access to scene file!" ); } if ( m_atLink ) { throw Exception( "Locations with links to external scene cannot have child locations themselves!" ); } } if ( m_linkedScene ) { ConstSceneInterfacePtr c = m_linkedScene->child( name, missingBehaviour ); if ( !c ) { return 0; } return new LinkedScene( m_mainScene.get(), c.get(), m_rootLinkDepth, m_readOnly, false, m_timeRemapped ); } else { SceneInterfacePtr c = m_mainScene->child( name, missingBehaviour ); if ( !c ) { return 0; } if ( m_readOnly ) { if( c->hasAttribute( fileNameLinkAttribute ) && c->hasAttribute( rootLinkAttribute ) ) { ConstStringDataPtr fileName = runTimeCast< const StringData >( c->readAttribute( fileNameLinkAttribute, 0 ) ); ConstInternedStringVectorDataPtr root = runTimeCast< const InternedStringVectorData >( c->readAttribute( rootLinkAttribute, 0 ) ); /// we found the link attribute... int linkDepth; bool timeRemapped = c->hasAttribute( timeLinkAttribute ); ConstSceneInterfacePtr l = expandLink( fileName.get(), root.get(), linkDepth ); if ( l ) { return new LinkedScene( c.get(), l.get(), linkDepth, m_readOnly, true, timeRemapped ); } } else if( c->hasAttribute( linkAttribute ) ) { // read from old school link attribute. // \todo: remove this when it doesn't break everyone's stuff! ConstCompoundDataPtr d = runTimeCast< const CompoundData >( c->readAttribute( linkAttribute, 0 ) ); /// we found the link attribute... int linkDepth; bool timeRemapped = false; ConstSceneInterfacePtr l = expandLink( d->member< const StringData >( g_fileName ), d->member< const InternedStringVectorData >( g_root ), linkDepth ); if ( l ) { return new LinkedScene( c.get(), l.get(), linkDepth, m_readOnly, true, timeRemapped ); } } } return new LinkedScene( c.get(), 0, 0, m_readOnly, false, false ); } }