ObjectPtr BGEOParticleReader::doOperation( const CompoundObject *operands ) { vector<string> attributes; particleAttributes( attributes ); size_t nParticles = numParticles(); PointsPrimitivePtr result = new PointsPrimitive( nParticles ); CompoundDataPtr attributeData = readAttributes( attributes ); if ( !attributeData ) { throw Exception( ( format( "Failed to load \"%s\"." ) % fileName() ).str() ); } bool haveNumPoints = false; for( vector<string>::const_iterator it = attributes.begin(); it!=attributes.end(); it++ ) { CompoundDataMap::const_iterator itData = attributeData->readable().find( *it ); if ( itData == attributeData->readable().end() ) { msg( Msg::Warning, "ParticleReader::doOperation", format( "Attribute %s expected but not found." ) % *it ); continue; } DataPtr d = itData->second; if ( testTypedData<TypeTraits::IsVectorTypedData>( d ) ) { size_t s = despatchTypedData< TypedDataSize, TypeTraits::IsVectorTypedData >( d ); if( !haveNumPoints ) { result->setNumPoints( s ); haveNumPoints = true; } if( s==result->getNumPoints() ) { result->variables.insert( PrimitiveVariableMap::value_type( *it, PrimitiveVariable( PrimitiveVariable::Vertex, d ) ) ); } else { msg( Msg::Warning, "ParticleReader::doOperation", format( "Ignoring attribute \"%s\" due to insufficient elements (expected %d but found %d)." ) % *it % result->getNumPoints() % s ); } } else if ( testTypedData<TypeTraits::IsSimpleTypedData>( d ) ) { result->variables.insert( PrimitiveVariableMap::value_type( *it, PrimitiveVariable( PrimitiveVariable::Constant, d ) ) ); } } return result; }
DataPtr BGEOParticleReader::readAttribute( const std::string &name ) { std::vector< std::string > names; names.push_back( name ); CompoundDataPtr result = readAttributes( names ); if (!result) { return 0; } CompoundDataMap::const_iterator it = result->readable().find( name ); if ( it == result->readable().end() ) { return 0; } return it->second; }
IECore::ConstObjectPtr OSLObject::computeProcessedObject( const ScenePath &path, const Gaffer::Context *context, IECore::ConstObjectPtr inputObject ) const { const Primitive *inputPrimitive = runTimeCast<const Primitive>( inputObject.get() ); if( !inputPrimitive ) { return inputObject; } const OSLShader *shader = runTimeCast<const OSLShader>( shaderPlug()->source()->node() ); ConstShadingEnginePtr shadingEngine = shader ? shader->shadingEngine() : nullptr; if( !shadingEngine ) { return inputObject; } PrimitiveVariable::Interpolation interpolation = static_cast<PrimitiveVariable::Interpolation>( interpolationPlug()->getValue() ); IECoreScene::ConstPrimitivePtr resampledObject = IECore::runTimeCast<const IECoreScene::Primitive>( resampledInPlug()->objectPlug()->getValue() ); CompoundDataPtr shadingPoints = prepareShadingPoints( resampledObject.get(), shadingEngine.get() ); PrimitivePtr outputPrimitive = inputPrimitive->copy(); ShadingEngine::Transforms transforms; transforms[ g_world ] = ShadingEngine::Transform( inPlug()->fullTransform( path )); CompoundDataPtr shadedPoints = shadingEngine->shade( shadingPoints.get(), transforms ); for( CompoundDataMap::const_iterator it = shadedPoints->readable().begin(), eIt = shadedPoints->readable().end(); it != eIt; ++it ) { // Ignore the output color closure as the debug closures are used to define what is 'exported' from the shader if( it->first != "Ci" ) { outputPrimitive->variables[it->first] = PrimitiveVariable( interpolation, it->second ); } } return outputPrimitive; }
IECore::ConstObjectPtr OSLObject::computeProcessedObject( const ScenePath &path, const Gaffer::Context *context, IECore::ConstObjectPtr inputObject ) const { const Primitive *inputPrimitive = runTimeCast<const Primitive>( inputObject.get() ); if( !inputPrimitive ) { return inputObject; } if( !inputPrimitive->variableData<V3fVectorData>( "P", PrimitiveVariable::Vertex ) ) { return inputObject; } ConstOSLShaderPtr shader = runTimeCast<const OSLShader>( shaderPlug()->source<Plug>()->node() ); ConstShadingEnginePtr shadingEngine = shader ? shader->shadingEngine() : NULL; if( !shadingEngine ) { return inputObject; } CompoundDataPtr shadingPoints = new CompoundData; for( PrimitiveVariableMap::const_iterator it = inputPrimitive->variables.begin(), eIt = inputPrimitive->variables.end(); it != eIt; ++it ) { if( it->second.interpolation == PrimitiveVariable::Vertex ) { // cast is ok - we're only using it to be able to reference the data from the shadingPoints, // but nothing will modify the data itself. shadingPoints->writable()[it->first] = boost::const_pointer_cast<Data>( it->second.data ); } } PrimitivePtr outputPrimitive = inputPrimitive->copy(); ShadingEngine::Transforms transforms; transforms[ g_world ] = ShadingEngine::Transform( inPlug()->fullTransform( path )); CompoundDataPtr shadedPoints = shadingEngine->shade( shadingPoints.get(), transforms ); for( CompoundDataMap::const_iterator it = shadedPoints->readable().begin(), eIt = shadedPoints->readable().end(); it != eIt; ++it ) { if( it->first != "Ci" ) { outputPrimitive->variables[it->first] = PrimitiveVariable( PrimitiveVariable::Vertex, it->second ); } } return outputPrimitive; }
static ShaderPtr construct( const std::string &name="defaultsurface", const std::string &type="surface", CompoundDataPtr parameters = 0 ) { return new Shader( name, type, parameters ? parameters->readable() : CompoundDataMap() ); }
static LightPtr construct( const std::string &name="distantlight", const std::string &handle="", CompoundDataPtr parameters = nullptr ) { return new Light( name, handle, parameters ? parameters->readable() : CompoundDataMap() ); }