Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/IECoreNuke/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "DDImage/Box.h"
#include "DDImage/Box3.h"
#include "DDImage/Matrix3.h"
#include "DDImage/Matrix4.h"
#include "DDImage/Vector2.h"
#include "DDImage/Vector3.h"
Expand Down Expand Up @@ -119,6 +120,12 @@ IECORENUKE_API Imath::Color4f convert( const DD::Image::Vector4 &from );
template<>
IECORENUKE_API Imath::V3d convert( const DD::Image::Vector4 &from );

template<>
IECORENUKE_API Imath::M33f convert( const DD::Image::Matrix3 &from );

template<>
IECORENUKE_API Imath::M33d convert( const DD::Image::Matrix3 &from );

template<>
IECORENUKE_API Imath::M44f convert( const DD::Image::Matrix4 &from );

Expand Down
3 changes: 3 additions & 0 deletions include/IECoreNuke/ToNukeGeometryConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@

#include "IECoreNuke/ToNukeConverter.h"

#include "IECore/CompoundObject.h"
#include "IECore/NumericParameter.h"
#include "IECore/Object.h"
#include "IECore/SimpleTypedParameter.h"
#include "IECore/TypedObjectParameter.h"

#include "DDImage/GeometryList.h"

Expand Down Expand Up @@ -99,6 +101,7 @@ class IECORENUKE_API ToNukeGeometryConverter : public ToNukeConverter

IECore::IntParameterPtr m_objIndexParameter;
IECore::StringParameterPtr m_pathParameter;
IECore::CompoundObjectParameterPtr m_attributesParameter;

};

Expand Down
28 changes: 28 additions & 0 deletions src/IECoreNuke/Convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,34 @@ Imath::Color4f convert( const DD::Image::Vector4 &from )
return Imath::Color4f( from.x, from.y, from.z, from.w );
}

template<>
Imath::M33f convert( const DD::Image::Matrix3 &from )
{
Imath::M33f result;
for( unsigned int i=0; i<3; i++ )
{
for( unsigned int j=0; j<3; j++ )
{
result[j][i] = from[j][i];
}
}
return result;
}

template<>
Imath::M33d convert( const DD::Image::Matrix3 &from )
{
Imath::M33d result;
for( unsigned int i=0; i<3; i++ )
{
for( unsigned int j=0; j<3; j++ )
{
result[j][i] = from[j][i];
}
}
return result;
}

template<>
Imath::M44f convert( const DD::Image::Matrix4 &from )
{
Expand Down
103 changes: 103 additions & 0 deletions src/IECoreNuke/LiveScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "IECore/Exception.h"
#include "IECore/NullObject.h"
#include "IECore/SimpleTypedData.h"
#include "IECore/TransformationMatrixData.h"

#include "OpenEXR/OpenEXRConfig.h"
Expand Down Expand Up @@ -81,6 +82,38 @@ IECore::TransformationMatrixd convertTransformMatrix( DD::Image::Matrix4& from )

tbb::recursive_mutex g_mutex;

IECore::ConstObjectPtr convertAttribute( const DD::Image::Attribute *attribute )
{
switch( attribute->type() )
{
case DD::Image::FLOAT_ATTRIB :
return new IECore::FloatData( attribute->flt( 0 ) );
case DD::Image::INT_ATTRIB :
return new IECore::IntData( attribute->integer( 0 ) );
case DD::Image::STD_STRING_ATTRIB :
return new IECore::StringData( attribute->stdstring( 0 ) );
case DD::Image::STRING_ATTRIB :
{
const char *s = attribute->string( 0 );
return new IECore::StringData( s ? s : "" );
}
case DD::Image::VECTOR2_ATTRIB :
return new IECore::V2fData( IECore::convert<Imath::V2f>( attribute->vector2( 0 ) ) );
case DD::Image::VECTOR3_ATTRIB :
return new IECore::V3fData( IECore::convert<Imath::V3f>( attribute->vector3( 0 ) ) );
case DD::Image::NORMAL_ATTRIB :
return new IECore::V3fData( IECore::convert<Imath::V3f>( attribute->normal( 0 ) ) );
case DD::Image::VECTOR4_ATTRIB :
return new IECore::Color4fData( IECore::convert<Imath::Color4f>( attribute->vector4( 0 ) ) );
case DD::Image::MATRIX3_ATTRIB :
return new IECore::M33fData( IECore::convert<Imath::M33f>( attribute->matrix3( 0 ) ) );
case DD::Image::MATRIX4_ATTRIB :
return new IECore::M44fData( IECore::convert<Imath::M44f>( attribute->matrix4( 0 ) ) );
default :
return nullptr;
}
}

LiveScene::LiveSceneGeometryCache &cachedGeometryListMap()
{
static LiveScene::LiveSceneGeometryCache *cache = new LiveScene::LiveSceneGeometryCache();
Expand Down Expand Up @@ -424,15 +457,85 @@ void LiveScene::writeTransform( const Data *transform, double time )

bool LiveScene::hasAttribute( const Name &name ) const
{
const unsigned numObjects = objectNum();
for( unsigned i = 0; i < numObjects; ++i )
{
if( m_pathMatcher.match( geoInfoPath( i ) ) != IECore::PathMatcher::ExactMatch )
{
continue;
}
auto geoInfo = object( i );
if( !geoInfo )
{
return false;
}
// we only support Group_Object because they are only one that makes sense to match to IECoreScene Attributes
// other type of attributes are more akin to PrimitiveVariables
// so we could consider adding support for Group_Primitive/Vertex and Point as such.
auto attr = geoInfo->get_group_attribute( GroupType::Group_Object, name.c_str() );
return attr && attr->size() > 0;
}
return false;
}

void LiveScene::attributeNames( NameList &attrs ) const
{
attrs.clear();
const unsigned numObjects = objectNum();
for( unsigned i = 0; i < numObjects; ++i )
{
if( m_pathMatcher.match( geoInfoPath( i ) ) != IECore::PathMatcher::ExactMatch )
{
continue;
}
auto geoInfo = object( i );
if( !geoInfo )
{
return;
}
const int count = geoInfo->get_attribcontext_count();
for( int j = 0; j < count; ++j )
{
auto context = geoInfo->get_attribcontext( j );
// we only support Group_Object because they are only one that makes sense to match to IECoreScene Attributes
// other type of attributes are more akin to PrimitiveVariables
// so we could consider adding support for Group_Primitive/Vertex and Point as such.
if( context && !context->empty() && context->group == GroupType::Group_Object && context->name )
{
attrs.push_back( context->name );
}
}
return;
}
}

ConstObjectPtr LiveScene::readAttribute( const Name &name, double time ) const
{
const unsigned numObjects = objectNum( &time );
for( unsigned i = 0; i < numObjects; ++i )
{
if( m_pathMatcher.match( geoInfoPath( i ) ) != IECore::PathMatcher::ExactMatch )
{
continue;
}
auto geoInfo = object( i, &time );
if( !geoInfo )
{
return IECore::NullObject::defaultNullObject();
}
// we only support Group_Object because they are only one that makes sense to match to IECoreScene Attributes
// other type of attributes are more akin to PrimitiveVariables
// so we could consider adding support for Group_Primitive/Vertex and Point as such.
auto attr = geoInfo->get_group_attribute( GroupType::Group_Object, name.c_str() );
if( attr && attr->size() > 0 )
{
if( auto converted = convertAttribute( attr ) )
{
return converted;
}
}
return IECore::NullObject::defaultNullObject();
}
return IECore::NullObject::defaultNullObject();
}

Expand Down
14 changes: 14 additions & 0 deletions src/IECoreNuke/SceneCacheReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "IECoreNuke/Hash.h"
#include "IECoreNuke/ToNukeGeometryConverter.h"

#include "IECore/CompoundObject.h"

#include "IECoreGL/BoxPrimitive.h"
#include "IECoreGL/Camera.h"
#include "IECoreGL/Exception.h"
Expand Down Expand Up @@ -1094,6 +1096,18 @@ void SceneCacheReader::loadPrimitive( DD::Image::GeometryList &out, const std::s
if (converter)
{
converter->parameters()->parameter<IECore::StringParameter>( "path" )->setValue( new IECore::StringData( itemPath ) );

IECore::CompoundObjectPtr sceneAttributes = new IECore::CompoundObject();
IECoreScene::SceneInterface::NameList attrNames;
sceneInterface->attributeNames( attrNames );
for( const auto &attrName : attrNames )
{
// Safe to cast away const as the CompoundObject is only used to pass
// attribute values through to the converter, which only reads them.
sceneAttributes->members()[attrName] = boost::const_pointer_cast<IECore::Object>( sceneInterface->readAttribute( attrName, time ) );
}
converter->parameters()->parameter<IECore::CompoundObjectParameter>( "attributes" )->setValue( sceneAttributes );

converter->convert( out );
// store the world matrix to apply in geometry_engine because
// somewhere after the create_geometry nuke reset the matrix in the SourceGeo base class.
Expand Down
117 changes: 117 additions & 0 deletions src/IECoreNuke/ToNukeGeometryConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,124 @@
//////////////////////////////////////////////////////////////////////////

#include "IECoreNuke/ToNukeGeometryConverter.h"
#include "IECoreNuke/Convert.h"
#include "IECoreNuke/LiveScene.h"

#include "IECore/CompoundData.h"
#include "IECore/MessageHandler.h"
#include "IECore/CompoundObject.h"
#include "IECore/CompoundParameter.h"
#include "IECore/SimpleTypedData.h"

#include <cassert>

#include "boost/format.hpp"

using namespace IECoreNuke;
using namespace IECore;
using namespace DD::Image;

namespace
{

void writeAttribute( DD::Image::GeometryList &geoList, int objIndex, const char *name, const IECore::Object *value )
{
switch( value->typeId() )
{
case IECore::FloatDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::FLOAT_ATTRIB );
attr->flt() = static_cast<const IECore::FloatData *>( value )->readable();
break;
}
case IECore::IntDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::INT_ATTRIB );
attr->integer() = static_cast<const IECore::IntData *>( value )->readable();
break;
}
case IECore::BoolDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::INT_ATTRIB );
attr->integer() = static_cast<const IECore::BoolData *>( value )->readable() ? 1 : 0;
break;
}
case IECore::StringDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::STD_STRING_ATTRIB );
attr->stdstring() = static_cast<const IECore::StringData *>( value )->readable();
break;
}
case IECore::V2fDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::VECTOR2_ATTRIB );
const auto &v = static_cast<const IECore::V2fData *>( value )->readable();
attr->vector2() = DD::Image::Vector2( v.x, v.y );
break;
}
case IECore::V3fDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::VECTOR3_ATTRIB );
attr->vector3() = IECore::convert<DD::Image::Vector3>( static_cast<const IECore::V3fData *>( value )->readable() );
break;
}
case IECore::Color4fDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::VECTOR4_ATTRIB );
const auto &c = static_cast<const IECore::Color4fData *>( value )->readable();
attr->vector4() = DD::Image::Vector4( c.r, c.g, c.b, c.a );
break;
}
case IECore::M33fDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::MATRIX3_ATTRIB );
const auto &m = static_cast<const IECore::M33fData *>( value )->readable();
DD::Image::Matrix3 result;
for( int i = 0; i < 3; i++ )
{
for( int j = 0; j < 3; j++ )
{
result[j][i] = m[j][i];
}
}
attr->matrix3() = result;
break;
}
case IECore::M44fDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::MATRIX4_ATTRIB );
attr->matrix4() = IECore::convert<DD::Image::Matrix4>( Imath::M44d( static_cast<const IECore::M44fData *>( value )->readable() ) );
break;
}
case IECore::M44dDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::MATRIX4_ATTRIB );
attr->matrix4() = IECore::convert<DD::Image::Matrix4>( static_cast<const IECore::M44dData *>( value )->readable() );
break;
}
case IECore::M33dDataTypeId :
{
auto attr = geoList.writable_attribute( objIndex, GroupType::Group_Object, name, AttribType::MATRIX3_ATTRIB );
const auto &m = static_cast<const IECore::M33dData *>( value )->readable();
DD::Image::Matrix3 result;
for( int i = 0; i < 3; i++ )
{
for( int j = 0; j < 3; j++ )
{
result[j][i] = m[j][i];
}
}
attr->matrix3() = result;
break;
}
default :
IECore::msg( IECore::Msg::Warning, "ToNukeGeometryConverter", boost::format( "Unsupported attribute type \"%s\" for \"%s\"" ) % value->typeName() % name );
break;
}
}

} // namespace

IE_CORE_DEFINERUNTIMETYPED( ToNukeGeometryConverter );

ToNukeGeometryConverter::ToNukeGeometryConverter( const std::string &description, IECore::TypeId fromType, ConstObjectPtr object )
Expand All @@ -57,6 +164,9 @@ ToNukeGeometryConverter::ToNukeGeometryConverter( const std::string &description
m_pathParameter = new StringParameter( "path", "The object path in the hierarchy.", new StringData() );
parameters()->addParameter( m_pathParameter );

m_attributesParameter = new CompoundObjectParameter( "attributes", "Scene attributes to write as Group_Object attributes.", new CompoundObject() );
parameters()->addParameter( m_attributesParameter );

}

void ToNukeGeometryConverter::convert( GeometryList &geoList ) const
Expand All @@ -72,6 +182,13 @@ void ToNukeGeometryConverter::convert( GeometryList &geoList ) const
auto nameAttribute = geoList.writable_attribute( objIndex, GroupType::Group_Object, IECoreNuke::LiveScene::nameAttribute.data(), AttribType::STD_STRING_ATTRIB);
nameAttribute->stdstring() = m_pathParameter->getTypedValue();

// add scene attributes as Group_Object attributes
ConstCompoundObjectPtr attributes = m_attributesParameter->getTypedValue<CompoundObject>();
for( const auto &attr : attributes->members() )
{
writeAttribute( geoList, objIndex, attr.first.c_str(), attr.second.get() );
}

ConstCompoundObjectPtr operands = parameters()->getTypedValidatedValue<CompoundObject>();
doConversion( srcParameter()->getValidatedValue(), geoList, objIndex, operands.get() );
}
Expand Down
Loading
Loading