|
44 | 44 |
|
45 | 45 | #include "IECore/Exception.h" |
46 | 46 | #include "IECore/NullObject.h" |
| 47 | +#include "IECore/SimpleTypedData.h" |
47 | 48 | #include "IECore/TransformationMatrixData.h" |
48 | 49 |
|
49 | 50 | #include "OpenEXR/OpenEXRConfig.h" |
@@ -81,6 +82,38 @@ IECore::TransformationMatrixd convertTransformMatrix( DD::Image::Matrix4& from ) |
81 | 82 |
|
82 | 83 | tbb::recursive_mutex g_mutex; |
83 | 84 |
|
| 85 | +IECore::ConstObjectPtr convertAttribute( const DD::Image::Attribute *attribute ) |
| 86 | +{ |
| 87 | + switch( attribute->type() ) |
| 88 | + { |
| 89 | + case DD::Image::FLOAT_ATTRIB : |
| 90 | + return new IECore::FloatData( attribute->flt( 0 ) ); |
| 91 | + case DD::Image::INT_ATTRIB : |
| 92 | + return new IECore::IntData( attribute->integer( 0 ) ); |
| 93 | + case DD::Image::STD_STRING_ATTRIB : |
| 94 | + return new IECore::StringData( attribute->stdstring( 0 ) ); |
| 95 | + case DD::Image::STRING_ATTRIB : |
| 96 | + { |
| 97 | + const char *s = attribute->string( 0 ); |
| 98 | + return new IECore::StringData( s ? s : "" ); |
| 99 | + } |
| 100 | + case DD::Image::VECTOR2_ATTRIB : |
| 101 | + return new IECore::V2fData( IECore::convert<Imath::V2f>( attribute->vector2( 0 ) ) ); |
| 102 | + case DD::Image::VECTOR3_ATTRIB : |
| 103 | + return new IECore::V3fData( IECore::convert<Imath::V3f>( attribute->vector3( 0 ) ) ); |
| 104 | + case DD::Image::NORMAL_ATTRIB : |
| 105 | + return new IECore::V3fData( IECore::convert<Imath::V3f>( attribute->normal( 0 ) ) ); |
| 106 | + case DD::Image::VECTOR4_ATTRIB : |
| 107 | + return new IECore::Color4fData( IECore::convert<Imath::Color4f>( attribute->vector4( 0 ) ) ); |
| 108 | + case DD::Image::MATRIX3_ATTRIB : |
| 109 | + return new IECore::M33fData( IECore::convert<Imath::M33f>( attribute->matrix3( 0 ) ) ); |
| 110 | + case DD::Image::MATRIX4_ATTRIB : |
| 111 | + return new IECore::M44fData( IECore::convert<Imath::M44f>( attribute->matrix4( 0 ) ) ); |
| 112 | + default : |
| 113 | + return nullptr; |
| 114 | + } |
| 115 | +} |
| 116 | + |
84 | 117 | LiveScene::LiveSceneGeometryCache &cachedGeometryListMap() |
85 | 118 | { |
86 | 119 | static LiveScene::LiveSceneGeometryCache *cache = new LiveScene::LiveSceneGeometryCache(); |
@@ -424,15 +457,85 @@ void LiveScene::writeTransform( const Data *transform, double time ) |
424 | 457 |
|
425 | 458 | bool LiveScene::hasAttribute( const Name &name ) const |
426 | 459 | { |
| 460 | + const unsigned numObjects = objectNum(); |
| 461 | + for( unsigned i = 0; i < numObjects; ++i ) |
| 462 | + { |
| 463 | + if( m_pathMatcher.match( geoInfoPath( i ) ) != IECore::PathMatcher::ExactMatch ) |
| 464 | + { |
| 465 | + continue; |
| 466 | + } |
| 467 | + auto geoInfo = object( i ); |
| 468 | + if( !geoInfo ) |
| 469 | + { |
| 470 | + return false; |
| 471 | + } |
| 472 | + // we only support Group_Object because they are only one that makes sense to match to IECoreScene Attributes |
| 473 | + // other type of attributes are more akin to PrimitiveVariables |
| 474 | + // so we could consider adding support for Group_Primitive/Vertex and Point as such. |
| 475 | + auto attr = geoInfo->get_group_attribute( GroupType::Group_Object, name.c_str() ); |
| 476 | + return attr && attr->size() > 0; |
| 477 | + } |
427 | 478 | return false; |
428 | 479 | } |
429 | 480 |
|
430 | 481 | void LiveScene::attributeNames( NameList &attrs ) const |
431 | 482 | { |
| 483 | + attrs.clear(); |
| 484 | + const unsigned numObjects = objectNum(); |
| 485 | + for( unsigned i = 0; i < numObjects; ++i ) |
| 486 | + { |
| 487 | + if( m_pathMatcher.match( geoInfoPath( i ) ) != IECore::PathMatcher::ExactMatch ) |
| 488 | + { |
| 489 | + continue; |
| 490 | + } |
| 491 | + auto geoInfo = object( i ); |
| 492 | + if( !geoInfo ) |
| 493 | + { |
| 494 | + return; |
| 495 | + } |
| 496 | + const int count = geoInfo->get_attribcontext_count(); |
| 497 | + for( int j = 0; j < count; ++j ) |
| 498 | + { |
| 499 | + auto context = geoInfo->get_attribcontext( j ); |
| 500 | + // we only support Group_Object because they are only one that makes sense to match to IECoreScene Attributes |
| 501 | + // other type of attributes are more akin to PrimitiveVariables |
| 502 | + // so we could consider adding support for Group_Primitive/Vertex and Point as such. |
| 503 | + if( context && !context->empty() && context->group == GroupType::Group_Object && context->name ) |
| 504 | + { |
| 505 | + attrs.push_back( context->name ); |
| 506 | + } |
| 507 | + } |
| 508 | + return; |
| 509 | + } |
432 | 510 | } |
433 | 511 |
|
434 | 512 | ConstObjectPtr LiveScene::readAttribute( const Name &name, double time ) const |
435 | 513 | { |
| 514 | + const unsigned numObjects = objectNum( &time ); |
| 515 | + for( unsigned i = 0; i < numObjects; ++i ) |
| 516 | + { |
| 517 | + if( m_pathMatcher.match( geoInfoPath( i ) ) != IECore::PathMatcher::ExactMatch ) |
| 518 | + { |
| 519 | + continue; |
| 520 | + } |
| 521 | + auto geoInfo = object( i, &time ); |
| 522 | + if( !geoInfo ) |
| 523 | + { |
| 524 | + return IECore::NullObject::defaultNullObject(); |
| 525 | + } |
| 526 | + // we only support Group_Object because they are only one that makes sense to match to IECoreScene Attributes |
| 527 | + // other type of attributes are more akin to PrimitiveVariables |
| 528 | + // so we could consider adding support for Group_Primitive/Vertex and Point as such. |
| 529 | + auto attr = geoInfo->get_group_attribute( GroupType::Group_Object, name.c_str() ); |
| 530 | + if( attr && attr->size() > 0 ) |
| 531 | + { |
| 532 | + if( auto converted = convertAttribute( attr ) ) |
| 533 | + { |
| 534 | + return converted; |
| 535 | + } |
| 536 | + } |
| 537 | + return IECore::NullObject::defaultNullObject(); |
| 538 | + } |
436 | 539 | return IECore::NullObject::defaultNullObject(); |
437 | 540 | } |
438 | 541 |
|
|
0 commit comments