Skip to content

Commit 2b23e55

Browse files
committed
SceneCacheSource loads the full path for each shape based on the fullPathName parm.
1 parent e9a3354 commit 2b23e55

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

include/IECoreHoudini/SOP_SceneCacheSource.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2012-2014, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2012-2015, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
@@ -79,6 +79,7 @@ class SOP_SceneCacheSource : public SceneCacheNode<SOP_Node>
7979
GeometryType geometryType;
8080
std::string attributeFilter;
8181
std::string attributeCopy;
82+
std::string fullPathName;
8283
UT_StringMMPattern shapeFilter;
8384
UT_StringMMPattern tagFilter;
8485

@@ -94,7 +95,7 @@ class SOP_SceneCacheSource : public SceneCacheNode<SOP_Node>
9495
// Groups, and CoordinateSystems. Updates animatedTopology and animatedPrimVars if appropriate.
9596
IECore::ConstObjectPtr transformObject( const IECore::Object *object, const Imath::M44d &transform, Parameters &params );
9697
// Convert the object to Houdini, optimizing for animated primitive variables if possible.
97-
bool convertObject( const IECore::Object *object, const std::string &name, Parameters &params );
98+
bool convertObject( const IECore::Object *object, const std::string &name, const IECore::SceneInterface *scene, Parameters &params );
9899

99100
void loadObjects( const IECore::SceneInterface *scene, Imath::M44d transform, double time, Space space, Parameters &params, size_t rootSize );
100101
IECore::MatrixTransformPtr matrixTransform( Imath::M44d t );

src/IECoreHoudini/SOP_SceneCacheSource.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2012-2014, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2012-2015, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
@@ -194,6 +194,9 @@ OP_ERROR SOP_SceneCacheSource::cookMySop( OP_Context &context )
194194
UT_String attributeCopy;
195195
getAttributeCopy( attributeCopy );
196196

197+
UT_String fullPathName;
198+
getFullPathName( fullPathName );
199+
197200
ConstSceneInterfacePtr scene = this->scene( file, path );
198201
if ( !scene )
199202
{
@@ -210,6 +213,7 @@ OP_ERROR SOP_SceneCacheSource::cookMySop( OP_Context &context )
210213
hash.append( shapeFilterStr );
211214
hash.append( attributeFilter );
212215
hash.append( attributeCopy );
216+
hash.append( fullPathName );
213217
hash.append( geometryType );
214218
hash.append( getObjectOnly() );
215219

@@ -237,6 +241,7 @@ OP_ERROR SOP_SceneCacheSource::cookMySop( OP_Context &context )
237241
getAttributeFilter( attribFilter );
238242
params.attributeFilter = attribFilter.toStdString();
239243
params.attributeCopy = attributeCopy.toStdString();
244+
params.fullPathName = fullPathName.toStdString();
240245
params.geometryType = getGeometryType();
241246
getShapeFilter( params.shapeFilter );
242247
getTagFilter( params.tagFilter );
@@ -380,7 +385,7 @@ void SOP_SceneCacheSource::loadObjects( const IECore::SceneInterface *scene, Ima
380385
}
381386

382387
// convert the object to Houdini
383-
if ( !convertObject( object.get(), name, params ) )
388+
if ( !convertObject( object.get(), name, scene, params ) )
384389
{
385390
std::string fullName;
386391
SceneInterface::Path path;
@@ -525,7 +530,7 @@ ConstObjectPtr SOP_SceneCacheSource::transformObject( const IECore::Object *obje
525530
return object;
526531
}
527532

528-
bool SOP_SceneCacheSource::convertObject( const IECore::Object *object, const std::string &name, Parameters &params )
533+
bool SOP_SceneCacheSource::convertObject( const IECore::Object *object, const std::string &name, const SceneInterface *scene, Parameters &params )
529534
{
530535
ToHoudiniGeometryConverterPtr converter = 0;
531536
if ( params.geometryType == Cortex )
@@ -602,7 +607,28 @@ bool SOP_SceneCacheSource::convertObject( const IECore::Object *object, const st
602607

603608
try
604609
{
605-
return converter->convert( myGdpHandle );
610+
GA_Offset firstNewPrim = gdp->getPrimitiveMap().lastOffset() + 1;
611+
612+
bool status = converter->convert( myGdpHandle );
613+
614+
if ( params.fullPathName != "" )
615+
{
616+
// adds the full path in addition to the relative name
617+
const GA_IndexMap &primMap = gdp->getPrimitiveMap();
618+
GA_Range newPrims( primMap, firstNewPrim, primMap.lastOffset() + 1 );
619+
if ( newPrims.isValid() )
620+
{
621+
std::string fullName;
622+
SceneInterface::Path path;
623+
scene->path( path );
624+
SceneInterface::pathToString( path, fullName );
625+
626+
GA_RWAttributeRef pathAttribRef = ToHoudiniStringVectorAttribConverter::convertString( params.fullPathName, fullName, gdp, newPrims );
627+
status = status && pathAttribRef.isValid();
628+
}
629+
}
630+
631+
return status;
606632
}
607633
catch ( std::exception &e )
608634
{

test/IECoreHoudini/SceneCacheTest.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,77 @@ def testLiveAttributes( self ) :
15031503
self.assertEqual( c.readAttribute( "animColor", 0.5 ), IECore.Color3dData( IECore.Color3d( 0.5 ) ) )
15041504
self.assertEqual( c.readAttribute( "animColor", 1 ), IECore.Color3dData( IECore.Color3d( 1 ) ) )
15051505

1506+
def testFullPathName( self ) :
1507+
1508+
self.writeSCC()
1509+
node = self.sop()
1510+
node.parm( "geometryType" ).set( IECoreHoudini.SceneCacheNode.GeometryType.Houdini )
1511+
1512+
# make sure the full path doesn't load until the parm has a value
1513+
self.assertEqual( node.parm( "fullPathName" ).eval(), "" )
1514+
self.assertEqual( node.geometry().findPrimAttrib( "path" ), None )
1515+
self.assertEqual( sorted( [ x.name() for x in node.geometry().primAttribs() ] ), ["Cd", "ieMeshInterpolation", "name"] )
1516+
1517+
# now lets load it an validate the paths
1518+
node.parm( "fullPathName" ).set( "path" )
1519+
self.assertEqual( sorted( [ x.name() for x in node.geometry().primAttribs() ] ), ["Cd", "ieMeshInterpolation", "name", "path"] )
1520+
1521+
prims = node.geometry().prims()
1522+
self.assertEqual( len(prims), 18 )
1523+
nameAttr = node.geometry().findPrimAttrib( "name" )
1524+
pathAttr = node.geometry().findPrimAttrib( "path" )
1525+
self.assertEqual( nameAttr.strings(), tuple( [ '/1', '/1/2', '/1/2/3' ] ) )
1526+
self.assertEqual( pathAttr.strings(), tuple( [ '/1', '/1/2', '/1/2/3' ] ) )
1527+
for name in nameAttr.strings() :
1528+
self.assertEqual( len([ x for x in prims if x.attribValue( "name" ) == name ]), 6 )
1529+
for path in pathAttr.strings() :
1530+
self.assertEqual( len([ x for x in prims if x.attribValue( "path" ) == path ]), 6 )
1531+
self.assertEqual( prims[0].vertex( 0 ).point().position(), hou.Vector3( 1, 0, 0 ) )
1532+
self.assertEqual( prims[6].vertex( 0 ).point().position(), hou.Vector3( 3, 0, 0 ) )
1533+
self.assertEqual( prims[12].vertex( 0 ).point().position(), hou.Vector3( 6, 0, 0 ) )
1534+
1535+
node.parm( "root" ).set( "/1" )
1536+
prims = node.geometry().prims()
1537+
self.assertEqual( len(prims), 18 )
1538+
nameAttr = node.geometry().findPrimAttrib( "name" )
1539+
pathAttr = node.geometry().findPrimAttrib( "path" )
1540+
self.assertEqual( nameAttr.strings(), tuple( [ '/', '/2', '/2/3' ] ) )
1541+
self.assertEqual( pathAttr.strings(), tuple( [ '/1', '/1/2', '/1/2/3' ] ) )
1542+
for name in nameAttr.strings() :
1543+
self.assertEqual( len([ x for x in prims if x.attribValue( "name" ) == name ]), 6 )
1544+
for path in pathAttr.strings() :
1545+
self.assertEqual( len([ x for x in prims if x.attribValue( "path" ) == path ]), 6 )
1546+
self.assertEqual( prims[0].vertex( 0 ).point().position(), hou.Vector3( 1, 0, 0 ) )
1547+
self.assertEqual( prims[6].vertex( 0 ).point().position(), hou.Vector3( 3, 0, 0 ) )
1548+
self.assertEqual( prims[12].vertex( 0 ).point().position(), hou.Vector3( 6, 0, 0 ) )
1549+
1550+
node.parm( "root" ).set( "/1/2" )
1551+
prims = node.geometry().prims()
1552+
self.assertEqual( len(prims), 12 )
1553+
nameAttr = node.geometry().findPrimAttrib( "name" )
1554+
pathAttr = node.geometry().findPrimAttrib( "path" )
1555+
self.assertEqual( nameAttr.strings(), tuple( [ '/', '/3' ] ) )
1556+
self.assertEqual( pathAttr.strings(), tuple( [ '/1/2', '/1/2/3' ] ) )
1557+
for name in nameAttr.strings() :
1558+
self.assertEqual( len([ x for x in prims if x.attribValue( "name" ) == name ]), 6 )
1559+
for path in pathAttr.strings() :
1560+
self.assertEqual( len([ x for x in prims if x.attribValue( "path" ) == path ]), 6 )
1561+
self.assertEqual( prims[0].vertex( 0 ).point().position(), hou.Vector3( 3, 0, 0 ) )
1562+
self.assertEqual( prims[6].vertex( 0 ).point().position(), hou.Vector3( 6, 0, 0 ) )
1563+
1564+
node.parm( "root" ).set( "/1/2/3" )
1565+
prims = node.geometry().prims()
1566+
self.assertEqual( len(prims), 6 )
1567+
nameAttr = node.geometry().findPrimAttrib( "name" )
1568+
pathAttr = node.geometry().findPrimAttrib( "path" )
1569+
self.assertEqual( nameAttr.strings(), tuple( [ '/' ] ) )
1570+
self.assertEqual( pathAttr.strings(), tuple( [ '/1/2/3' ] ) )
1571+
for name in nameAttr.strings() :
1572+
self.assertEqual( len([ x for x in prims if x.attribValue( "name" ) == name ]), 6 )
1573+
for path in pathAttr.strings() :
1574+
self.assertEqual( len([ x for x in prims if x.attribValue( "path" ) == path ]), 6 )
1575+
self.assertEqual( prims[0].vertex( 0 ).point().position(), hou.Vector3( 6, 0, 0 ) )
1576+
15061577
def testReloadButton( self ) :
15071578

15081579
def testNode( node ) :

0 commit comments

Comments
 (0)