Пример #1
0
void SOP_SceneCacheSource::loadObjects( const IECore::SceneInterface *scene, Imath::M44d transform, double time, Space space, Parameters &params, size_t rootSize )
{
	UT_Interrupt *progress = UTgetInterrupt();
	progress->setLongOpText( ( "Loading " + scene->name().string() ).c_str() );
	if ( progress->opInterrupt() )
	{
		return;
	}
	
	if ( scene->hasObject() && UT_String( scene->name() ).multiMatch( params.shapeFilter ) && tagged( scene, params.tagFilter ) )
	{
		std::string name = relativePath( scene, rootSize );
		
		Imath::M44d currentTransform;
		if ( space == Local )
		{
			currentTransform = scene->readTransformAsMatrix( time );
		}
		else if ( space != Object )
		{
			currentTransform = transform;
		}
		
		ConstObjectPtr object = 0;
		if ( params.geometryType == BoundingBox )
		{
			Imath::Box3d bound = scene->readBound( time );
			object = MeshPrimitive::createBox( Imath::Box3f( bound.min, bound.max ) );
			
			params.hasAnimatedTopology = false;
			params.hasAnimatedPrimVars = true;
			params.animatedPrimVars.clear();
			params.animatedPrimVars.push_back( "P" );
		}
		else if ( params.geometryType == PointCloud )
		{
			std::vector<Imath::V3f> point( 1, scene->readBound( time ).center() );
			PointsPrimitivePtr points = new PointsPrimitive( new V3fVectorData( point ) );
			std::vector<Imath::V3f> basis1( 1, Imath::V3f( currentTransform[0][0], currentTransform[0][1], currentTransform[0][2] ) );
			std::vector<Imath::V3f> basis2( 1, Imath::V3f( currentTransform[1][0], currentTransform[1][1], currentTransform[1][2] ) );
			std::vector<Imath::V3f> basis3( 1, Imath::V3f( currentTransform[2][0], currentTransform[2][1], currentTransform[2][2] ) );
			points->variables["basis1"] = PrimitiveVariable( PrimitiveVariable::Vertex, new V3fVectorData( basis1 ) );
			points->variables["basis2"] = PrimitiveVariable( PrimitiveVariable::Vertex, new V3fVectorData( basis2 ) );
			points->variables["basis3"] = PrimitiveVariable( PrimitiveVariable::Vertex, new V3fVectorData( basis3 ) );
			
			params.hasAnimatedTopology = false;
			params.hasAnimatedPrimVars = true;
			params.animatedPrimVars.clear();
			params.animatedPrimVars.push_back( "P" );
			params.animatedPrimVars.push_back( "basis1" );
			params.animatedPrimVars.push_back( "basis2" );
			params.animatedPrimVars.push_back( "basis3" );
			
			object = points;
		}
		else
		{
			object = scene->readObject( time );
			
			params.hasAnimatedTopology = scene->hasAttribute( SceneCache::animatedObjectTopologyAttribute );
			params.hasAnimatedPrimVars = scene->hasAttribute( SceneCache::animatedObjectPrimVarsAttribute );
			if ( params.hasAnimatedPrimVars )
			{
				const ConstObjectPtr animatedPrimVarObj = scene->readAttribute( SceneCache::animatedObjectPrimVarsAttribute, 0 );
				const InternedStringVectorData *animatedPrimVarData = IECore::runTimeCast<const InternedStringVectorData>( animatedPrimVarObj.get() );
				if ( animatedPrimVarData )
				{
					const std::vector<InternedString> &values = animatedPrimVarData->readable();
					params.animatedPrimVars.clear();
					params.animatedPrimVars.resize( values.size() );
					std::copy( values.begin(), values.end(), params.animatedPrimVars.begin() );
				}
			}
		}
		
		// modify the object if necessary
		object = modifyObject( object.get(), params );
		
		// transform the object unless its an identity
		if ( currentTransform != Imath::M44d() )
		{
			object = transformObject( object.get(), currentTransform, params );
		}
		
		// convert the object to Houdini
		if ( !convertObject( object.get(), name, scene, params ) )
		{
			std::string fullName;
			SceneInterface::Path path;
			scene->path( path );
			SceneInterface::pathToString( path, fullName );
			addWarning( SOP_MESSAGE, ( "Could not convert " + fullName + " to Houdini" ).c_str() );
		}
	}
	
	if ( evalInt( pObjectOnly.getToken(), 0, 0 ) )
	{
		return;
	}
	
	SceneInterface::NameList children;
	scene->childNames( children );
	std::sort( children.begin(), children.end(), InternedStringSort() );
	for ( SceneInterface::NameList::const_iterator it=children.begin(); it != children.end(); ++it )
	{
		ConstSceneInterfacePtr child = scene->child( *it );
		if ( tagged( child.get(), params.tagFilter ) )
		{
			loadObjects( child.get(), child->readTransformAsMatrix( time ) * transform, time, space, params, rootSize );
		}
	}
}
void SOP_SceneCacheSource::loadObjects( const IECore::SceneInterface *scene, Imath::M44d transform, double time, Space space, const UT_StringMMPattern &shapeFilter, const std::string &attributeFilter, GeometryType geometryType, size_t rootSize )
{
	UT_Interrupt *progress = UTgetInterrupt();
	progress->setLongOpText( ( "Loading " + scene->name().string() ).c_str() );
	if ( progress->opInterrupt() )
	{
		return;
	}
	
	if ( scene->hasObject() && UT_String( scene->name() ).multiMatch( shapeFilter ) )
	{
		// \todo See if there are ways to avoid the Object copy below.
		ObjectPtr object = scene->readObject( time )->copy();
		std::string name = relativePath( scene, rootSize );
		
		bool hasAnimatedTopology = scene->hasAttribute( SceneCache::animatedObjectTopologyAttribute );
		bool hasAnimatedPrimVars = scene->hasAttribute( SceneCache::animatedObjectPrimVarsAttribute );
		std::vector<InternedString> animatedPrimVars;
		if ( hasAnimatedPrimVars )
		{
			const ConstObjectPtr animatedPrimVarObj = scene->readAttribute( SceneCache::animatedObjectPrimVarsAttribute, 0 );
			const InternedStringVectorData *animatedPrimVarData = IECore::runTimeCast<const InternedStringVectorData>( animatedPrimVarObj );
			if ( animatedPrimVarData )
			{
				const std::vector<InternedString> &values = animatedPrimVarData->readable();
				animatedPrimVars.resize( values.size() );
				std::copy( values.begin(), values.end(), animatedPrimVars.begin() );
			}
		}
		
		modifyObject( object, name, attributeFilter, hasAnimatedTopology, hasAnimatedPrimVars, animatedPrimVars );
		
		Imath::M44d currentTransform;
		if ( space == Local )
		{
			currentTransform = scene->readTransformAsMatrix( time );
		}
		else if ( space != Object )
		{
			currentTransform = transform;
		}
		
		// transform the object unless its an identity
		if ( currentTransform != Imath::M44d() )
		{
			transformObject( object, currentTransform, hasAnimatedTopology, hasAnimatedPrimVars, animatedPrimVars );
		}
		
		// load the Cortex object directly
		if ( geometryType == Cortex )
		{
			holdObject( object, name, hasAnimatedTopology, hasAnimatedPrimVars, animatedPrimVars );
		}
		else
		{
			// convert the object to Houdini
			if ( !convertObject( object, name, attributeFilter, geometryType, hasAnimatedTopology, hasAnimatedPrimVars, animatedPrimVars ) )
			{
				std::string fullName;
				SceneInterface::Path path;
				scene->path( path );
				SceneInterface::pathToString( path, fullName );
				addWarning( SOP_MESSAGE, ( "Could not convert " + fullName + " to houdini" ).c_str() );
			}
		}
	}
	
	if ( evalInt( pObjectOnly.getToken(), 0, 0 ) )
	{
		return;
	}
	
	SceneInterface::NameList children;
	scene->childNames( children );
	for ( SceneInterface::NameList::const_iterator it=children.begin(); it != children.end(); ++it )
	{
		ConstSceneInterfacePtr child = scene->child( *it );
		loadObjects( child, child->readTransformAsMatrix( time ) * transform, time, space, shapeFilter, attributeFilter, geometryType, rootSize );
	}
}
void OBJ_SceneCacheTransform::doExpandChildren( const SceneInterface *scene, OP_Network *parent, const Parameters &params )
{
	UT_Interrupt *progress = UTgetInterrupt();
	progress->setLongOpText( ( "Expanding " + scene->name().string() ).c_str() );
	if ( progress->opInterrupt() )
	{
		return;
	}

	OP_Network *inputNode = parent;
	if ( params.hierarchy == Parenting )
	{
		parent = parent->getParent();
	}

	SceneInterface::NameList children;
	scene->childNames( children );
	for ( SceneInterface::NameList::const_iterator it=children.begin(); it != children.end(); ++it )
	{
		ConstSceneInterfacePtr child = scene->child( *it );

		OBJ_Node *childNode = 0;
		if ( params.hierarchy == SubNetworks )
		{
			childNode = doExpandChild( child.get(), parent, params );
			if ( params.depth == AllDescendants && child->hasObject() && tagged( child.get(), params.tagFilter ) )
			{
				Parameters childParams( params );
				childParams.depth = Children;
				doExpandObject( child.get(), childNode, childParams );
			}
		}
		else if ( params.hierarchy == Parenting )
		{
			if ( child->hasObject() )
			{
				Parameters childParams( params );
				childParams.depth = Children;
				childNode = doExpandObject( child.get(), parent, childParams );
			}
			else
			{
				childNode = doExpandChild( child.get(), parent, params );
			}

			childNode->setInput( 0, inputNode );
		}

		if ( params.depth == AllDescendants )
		{
			if ( params.hierarchy == SubNetworks && !tagged( child.get(), params.tagFilter ) )
			{
				// we don't expand non-tagged children for SubNetwork mode, but we
				// do for Parenting mode, because otherwise the hierarchy would be
				// stuck in an un-expandable state.
				continue;
			}

			doExpandChildren( child.get(), childNode, params );
			childNode->setInt( pExpanded.getToken(), 0, 0, 1 );
		}
	}

	OP_Layout layout( parent );

#if UT_MAJOR_VERSION_INT >= 16

	OP_SubnetIndirectInput *parentInput = parent->getParentInput( 0 );
	layout.addLayoutItem( parentInput->getInputItem() );
	for ( int i=0; i < parent->getNchildren(); ++i )
	{
		layout.addLayoutItem( parent->getChild( i ) );
	}

#else

	layout.addLayoutOp( parent->getParentInput( 0 ) );
	for ( int i=0; i < parent->getNchildren(); ++i )
	{
		layout.addLayoutOp( parent->getChild( i ) );
	}

#endif

	layout.layoutOps( OP_LAYOUT_TOP_TO_BOT, parent, parent->getParentInput( 0 ) );
}