when adding asset as history to mesh with no history,
create intermediate copy of mesh for upstream history first
@@ -300,6 +300,27 @@ houdiniEngine_connectHistory(string $inputAttr, string $objects[], string $compo
print "This asset is already connected as history\n";
return 0;
}
+ // if there is no upstream mesh history, copy the mesh, insert as upstream history
+ // and make it intermediate so it doesn't mess up selection and other mesh UI
+ // yeah, keeping the name on the downstream node rather than the upstream node is bad for file referencing
+ // but it is consistent with the way that native maya construction history works
+
+ if($upstreamNode == "") {
+ string $copyForUpstream[] = `duplicate -n "polySurface#" $targetMesh`;
+ string $newUpstreamShape[] = `listRelatives -shapes $copyForUpstream[0]`;
+ string $targetXform[] = `listRelatives -parent $targetMesh`;
+ string $upstreamNodes[] = `parent -add -shape $newUpstreamShape[0] $targetXform[0]`;
+ // reparenting can change name and/or partial path, so we re-get node name here
+ $upstreamNode = $upstreamNodes[0];
+ setAttr ($upstreamNode + ".intermediateObject") 1;
+ delete $copyForUpstream[0];
+ $upstreamAttr = ($upstreamNode + ".outMesh");
+ connectAttr -f $upstreamAttr ($targetMesh + ".inMesh");
+ }
+ if($upstreamNode == "") {
+ print "Could not add history to this mesh\n";
+ return 0;
+ }
int $upstreamIsAsset = 0;
if($upstreamNode != "") {
if(`nodeType $upstreamNode` == "houdiniAsset") {
@@ -355,19 +376,10 @@ houdiniEngine_connectHistory(string $inputAttr, string $objects[], string $compo
eval $cmd;
}
- // if there is no upstream history
- // then we need a copy of the original mesh, so we sync
- int $copyShape = ($upstreamAttr == "");
-
- // if the selected mesh had history, connect the history rather than the shape
- if(!$copyShape) {
+ // connect the history rather than the shape
if(! $upstreamIsAsset) {
connectAttr -f $upstreamAttr ($finalUpstreamNode + ".inputGeometry");
}
- } else {
- print "needed an upstream copy of the mesh because there is no history\n";
- print "just syncing the asset to get a new output mesh for now\n";
- }
if(`isConnected $finalUpstreamAttr $inputAttr`)
{
@@ -380,24 +392,12 @@ houdiniEngine_connectHistory(string $inputAttr, string $objects[], string $compo
connectAttr $finalUpstreamAttr $inputAttr;
}
- if(!`exists houdiniEngine_syncSelectedAsset`)
- source houdiniEngineAssetSync;
-
- if($copyShape && `getAttr ($assetNode + ".assetConnectType")` != 1)
- houdiniEngine_syncAssetOutput $assetNode;
-
- // if the selected mesh had history, connect the asset output back to the shape
- if(!$copyShape){
- // NEED to disconnect it from the original output first
+ // connect the asset output back to the shape
connectAttr -f ($assetNode + ".outputObjects[0].outputGeos[0].outputParts[0].outputPartMeshData") ($targetMesh + ".inMesh");
- }
- // only want to sync output at most once for history node.
+ // flag this as a history asset so we know what to do with it later
setAttr ($assetNode + ".assetConnectType") 1;
- // if copyshape was true, need to parent copy next to input
- // and set the upstream shape to intermediate
-
return 1;
}
