Skip to content

Commit

Permalink
Instancer : Initial hacking with omitting capsules
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldresser-ie committed Oct 27, 2023
1 parent 12eb9a6 commit bfe43ed
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/GafferScene/Instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,7 @@ void addPrototypeToVectors(
const ScenePlug *prototypesPlug, const ScenePlug::ScenePath *prototypeRoot, Context::EditableScope &scope,
const std::vector<float> &sampleTimes, const IECore::MurmurHash &hash, int index,
GafferScene::Private::RendererAlgo::RenderOptions &renderOptions,
std::vector<ObjectPtr> &objects, std::vector<M44f> &transforms, std::vector<ObjectPtr> &attributes
std::vector<ConstObjectPtr> &objects, std::vector<M44f> &transforms, std::vector<ConstObjectPtr> &attributes
)
{
float onFrameTime = scope.context()->getFrame();
Expand All @@ -2655,7 +2655,6 @@ void addPrototypeToVectors(
transforms.push_back( prototypesPlug->transformPlug()->getValue() );
}

scope.remove( ScenePlug::scenePathContextName );

IECore::MurmurHash h = hash;
h.append( index );
Expand All @@ -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
Expand Down Expand Up @@ -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<M44f> prototypeTransforms;

UIntVectorDataPtr prototypeIndicesData = new UIntVectorData();
std::vector< unsigned int > &prototypeIndices = prototypeIndicesData->writable();
std::vector< unsigned int > prototypeIndices;


IECore::MurmurHash capsuleHash;
Expand Down Expand Up @@ -2794,16 +2793,17 @@ 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
// depend only on the prototype
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 ) );
}
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bfe43ed

Please sign in to comment.