From bfe43edefc58391f70727317f9c08182e3ca4f5b Mon Sep 17 00:00:00 2001 From: Daniel Dresser Date: Thu, 26 Oct 2023 19:30:11 -0700 Subject: [PATCH] Instancer : Initial hacking with omitting capsules --- src/GafferScene/Instancer.cpp | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/GafferScene/Instancer.cpp b/src/GafferScene/Instancer.cpp index 777ea8c11d8..367e054eb45 100644 --- a/src/GafferScene/Instancer.cpp +++ b/src/GafferScene/Instancer.cpp @@ -2636,7 +2636,7 @@ void addPrototypeToVectors( const ScenePlug *prototypesPlug, const ScenePlug::ScenePath *prototypeRoot, Context::EditableScope &scope, const std::vector &sampleTimes, const IECore::MurmurHash &hash, int index, GafferScene::Private::RendererAlgo::RenderOptions &renderOptions, - std::vector &objects, std::vector &transforms, std::vector &attributes + std::vector &objects, std::vector &transforms, std::vector &attributes ) { float onFrameTime = scope.context()->getFrame(); @@ -2655,7 +2655,6 @@ void addPrototypeToVectors( transforms.push_back( prototypesPlug->transformPlug()->getValue() ); } - scope.remove( ScenePlug::scenePathContextName ); IECore::MurmurHash h = hash; h.append( index ); @@ -2664,20 +2663,26 @@ void addPrototypeToVectors( // must be the on-frame time, since the capsules will add their own shutter scope.setFrame( onFrameTime ); + if( prototypesPlug->childNamesPlug()->getValue()->readable().size() == 0 ) + { + objects.push_back( prototypesPlug->objectPlug()->getValue() ); + } + else + { + scope.remove( ScenePlug::scenePathContextName ); - CapsulePtr newCapsule = new Capsule( - prototypesPlug, - *prototypeRoot, - *scope.context(), - h, - bound - ); - - // Pass through our render options to the sub-capsules - newCapsule->setRenderOptions( renderOptions ); - - objects.push_back( std::move( newCapsule ) ); + CapsulePtr newCapsule = new Capsule( + prototypesPlug, + *prototypeRoot, + *scope.context(), + h, + bound + ); + // Pass through our render options to the sub-capsules + newCapsule->setRenderOptions( renderOptions ); + objects.push_back( std::move( newCapsule ) ); + } } // \todo - this can be omitted once we add a specialization of std::hash for MurmurHash to Cortex @@ -2736,16 +2741,10 @@ void Instancer::InstancerCapsule::render( IECoreScenePreview::Renderer *renderer const ScenePlug *prototypesPlug = m_instancer->prototypesPlug(); - ObjectVectorPtr prototypesData = new ObjectVector(); - auto &prototypes = prototypesData->members(); - - ObjectVectorPtr prototypeAttributesData = new ObjectVector(); - auto &prototypeAttributes = prototypeAttributesData->members(); - + std::vector< ConstObjectPtr > prototypes; + std::vector< ConstObjectPtr > prototypeAttributes; vector prototypeTransforms; - - UIntVectorDataPtr prototypeIndicesData = new UIntVectorData(); - std::vector< unsigned int > &prototypeIndices = prototypeIndicesData->writable(); + std::vector< unsigned int > prototypeIndices; IECore::MurmurHash capsuleHash; @@ -2794,6 +2793,7 @@ void Instancer::InstancerCapsule::render( IECoreScenePreview::Renderer *renderer ); } + bool hasAttributes = engines[0]->numInstanceAttributes() > 0; // If we don't have per-instance attributes, we can pre-prepare renderer attributes ready to go that @@ -2801,9 +2801,9 @@ void Instancer::InstancerCapsule::render( IECoreScenePreview::Renderer *renderer std::vector< IECoreScenePreview::Renderer::AttributesInterfacePtr > prototypeRendererAttribs; if( !hasAttributes ) { - for( IECore::ObjectPtr &a : prototypeAttributes ) + for( IECore::ConstObjectPtr &a : prototypeAttributes ) { - CompoundObject* typedA = static_cast< CompoundObject* >( a.get() ); + const CompoundObject* typedA = static_cast< const CompoundObject* >( a.get() ); prototypeRendererAttribs.push_back( renderer->attributes( typedA ) ); } } @@ -2833,7 +2833,7 @@ void Instancer::InstancerCapsule::render( IECoreScenePreview::Renderer *renderer { CompoundObjectPtr currentAttributes = new CompoundObject(); engines[0]->instanceAttributes( pointIndex, *currentAttributes ); - for( auto &i : static_cast< CompoundObject* >( prototypeAttributes[prototypeIndex].get() )->members() ) + for( auto &i : static_cast< const CompoundObject* >( prototypeAttributes[prototypeIndex].get() )->members() ) { currentAttributes->members()[i.first] = i.second; }