Skip to content

Commit

Permalink
Merge branch 'atc-h20-673' into atc-h20-675b
Browse files Browse the repository at this point in the history
  • Loading branch information
atcarter714 committed Apr 18, 2024
2 parents 3499980 + 657a9ca commit 9feda3b
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 130 deletions.
8 changes: 4 additions & 4 deletions Plugins/HoudiniEngineUnity/Editor/UI/HEU_HoudiniAssetUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) <2020> Side Effects Software Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -285,8 +285,8 @@ public override void OnInspectorGUI( ) {
else if ( HEU_PluginSettings.CookingEnabled && _houdiniAsset.AutoCookOnParameterChange &&
_houdiniAsset.DoesAssetRequireRecook( ) ) {
// Often times, cooking while dragging mouse results in poor UX
bool isDragging = ( EditorGUIUtility.hotControl != 0 ) ;
bool blockAutoCook = _houdiniAsset.PendingAutoCookOnMouseRelease ||
bool isDragging = ( GUIUtility.hotControl is not 0 ) ;
bool blockAutoCook = _houdiniAsset.PendingAutoCookOnMouseRelease == true ||
( isDragging && Event.current != null &&
_delayAutoCookStrings.Contains( Event.current.commandName ) ) ;

Expand Down Expand Up @@ -1303,7 +1303,7 @@ void DrawTerrainSection( HEU_HoudiniAsset asset, SerializedObject assetObject )
bool bStrengthChanged = false ;

SerializedProperty layersProperty = cacheObjectSerialized.FindProperty( "_layers" ) ;
if ( layersProperty == null || layersProperty.arraySize == 0 ) {
if ( layersProperty == null || layersProperty.arraySize is 0 ) {
continue ;
}

Expand Down
11 changes: 7 additions & 4 deletions Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_GeoNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) <2020> Side Effects Software Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -422,6 +422,9 @@ internal void UpdateGeo( HEU_SessionBase session ) {
/// <summary>Process custom attribute with Unity script name, and attach any scripts found.</summary>
/// <param name="session">Session to use</param>
internal void ProcessUnityScriptAttribute( HEU_SessionBase session ) {
HEU_Logger.Log( "Processing Unity Script Attribute" ) ;
if ( _parts is not { Count: > 0 } ) return ;

if ( _parts is not { Count: > 0 } ) return ;

foreach ( HEU_PartData part in _parts ) {
Expand All @@ -430,9 +433,9 @@ internal void ProcessUnityScriptAttribute( HEU_SessionBase session ) {

string scriptValue =
HEU_GeneralUtility.GetUnityScriptAttributeValue( session, GeoID, part.PartID ) ;
if ( !string.IsNullOrEmpty( scriptValue ) ) {
HEU_GeneralUtility.AttachScriptWithInvokeFunction( scriptValue, outputGo ) ;
}
HEU_Logger.Log( $"Target Script: {scriptValue ?? string.Empty} ..." ) ;
if ( string.IsNullOrEmpty( scriptValue ) ) continue ;
HEU_GeneralUtility.AttachScriptWithInvokeFunction( scriptValue, outputGo ) ;
}
}

Expand Down
90 changes: 42 additions & 48 deletions Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_HoudiniAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ namespace HoudiniEngineUnity
[ExecuteInEditMode] // OnEnable/OnDisable for registering for tick
public sealed class HEU_HoudiniAsset: MonoBehaviour,
IHEU_HoudiniAsset,
IEquivable< HEU_HoudiniAsset >
{
IEquivable< HEU_HoudiniAsset > {
// ASSET DATA ------------------------------------------------------------------------------------------------

internal enum HEU_AssetType
Expand Down Expand Up @@ -1599,15 +1598,14 @@ void Awake( ) {
#if HOUDINIENGINEUNITY_ENABLED
//HEU_Logger.Log("HEU_HoudiniAsset::Awake - " + AssetName);

if ( _serializedMetaData == null ) {
if ( !_serializedMetaData )
_serializedMetaData = ScriptableObject.CreateInstance< HEU_AssetSerializedMetaData >( ) ;
}


// We want to support Object.Instantiate, but ScriptableObjects cannot copy by value by
// default. So we simulate the "duplicate" function when we detect that this occurs
// This would be a lot easier if Unity provided some sort of Instantiate() callback...
AssetInstantiationMethod instantiationMethod = GetInstantiationMethod( ) ;
if ( instantiationMethod == AssetInstantiationMethod.DUPLICATED ) {
if ( instantiationMethod is AssetInstantiationMethod.DUPLICATED ) {
HEU_HoudiniAsset instantiatedAsset = GetInstantiatedObject( ) ;
ResetAndCopyInstantiatedProperties( instantiatedAsset ) ;
}
Expand All @@ -1620,27 +1618,27 @@ void Awake( ) {
// to this asset if Unity had destroyed the asset during a play mode change
// or script compilation refresh.
HEU_SessionBase session = GetAssetSession( false ) ;
if ( session != null && HEU_HAPIUtility.IsNodeValidInHoudini( session, _assetID ) ) {
if ( session is not null && HEU_HAPIUtility.IsNodeValidInHoudini( session, _assetID ) )
session.ReregisterOnAwake( this ) ;
}

// Clear out the delegate because receiver might not exist on code refresh
_refreshUIDelegate = null ;

if ( _assetID is not HEU_Defines.HEU_INVALID_NODE_ID && instantiationMethod == AssetInstantiationMethod.UNDO ) {
Transform[] gos = _rootGameObject.GetComponentsInChildren< Transform >( ) ;
foreach ( Transform trans in gos ) {
if ( trans != null && trans.gameObject != null && trans.gameObject != _rootGameObject &&
trans.gameObject != gameObject ) {
DestroyImmediate( trans.gameObject ) ;
}
if ( _assetID is HEU_Defines.HEU_INVALID_NODE_ID ||
instantiationMethod is not AssetInstantiationMethod.UNDO ) return ;

Transform[ ] gos = _rootGameObject.GetComponentsInChildren< Transform >( ) ;
foreach ( Transform trans in gos ) {
if ( trans != null && trans.gameObject != null
&& trans.gameObject != _rootGameObject
&& trans.gameObject != gameObject ) {
DestroyImmediate( trans.gameObject ) ;
}

_serializedMetaData.SoftDeleted = false ;

HEU_Logger.LogWarning( "Undoing a deleted HDA may also remove its parameter undo stack." ) ;
RequestReload( ) ;
}

_serializedMetaData.SoftDeleted = false ;
HEU_Logger.LogWarning( "Undoing a deleted HDA may also remove its parameter undo stack." ) ;
RequestReload( ) ;
#endif
}

Expand All @@ -1649,10 +1647,8 @@ void Awake( ) {
/// in a Houdini session on the next recook, rebuild, or parameter change.
/// This should be done in asset is not found to be valid in an existing session.
/// </summary>
internal void InvalidateAsset( ) {
_assetID = HEU_Defines.HEU_INVALID_NODE_ID ;
}

internal void InvalidateAsset( ) => _assetID = HEU_Defines.HEU_INVALID_NODE_ID ;

void OnEnable( ) {
#if HOUDINIENGINEUNITY_ENABLED
// Adding in OnEnable as its called after a code recompile (Awake is not).
Expand Down Expand Up @@ -1853,7 +1849,7 @@ void ProcessRebuild( bool bPromptForSubasset, int desiredSubassetIndex ) {
SetCookStatus( AssetCookStatus.POSTLOAD, AssetCookResult.ERRORED ) ;

if ( _reloadDataEvent is null ) return ;

// Do callbacks regardless of success or failure as listeners might need to know
List< GameObject > outputObjects = new( ) ;
GetOutputGameObjects( outputObjects ) ;
InvokeReloadEvent( bResult, outputObjects ) ;
Expand Down Expand Up @@ -1926,9 +1922,7 @@ bool StartRebuild( bool bPromptForSubasset, int desiredSubassetIndex ) {
/// <returns>True if successfully completed building the asset</returns>
bool FinishRebuild( ) {
HEU_SessionBase session = GetAssetSession( true ) ;
if ( session == null ) {
return false ;
}
if ( session is null ) return false ;

// Load and cook the HDA
HAPI_NodeId newAssetID = HEU_Defines.HEU_INVALID_NODE_ID ;
Expand All @@ -1949,12 +1943,13 @@ bool FinishRebuild( ) {
}
}
else if ( _assetType is HEU_AssetType.TYPE_CURVE ) {
if ( _assetName == null ) {
if ( _assetName is null )
_assetName = "curve" ;
}

bool bResult =
HEU_HAPIUtility.CreateAndCookCurveAsset( session, _assetName, HEU_PluginSettings.CookTemplatedGeos,
HEU_HAPIUtility.CreateAndCookCurveAsset( session,
_assetName,
HEU_PluginSettings.CookTemplatedGeos,
out newAssetID ) ;
if ( !bResult ) {
if ( newAssetID is not HEU_Defines.HEU_INVALID_NODE_ID ) {
Expand All @@ -1965,12 +1960,11 @@ bool FinishRebuild( ) {
}
}
else if ( _assetType is HEU_AssetType.TYPE_INPUT ) {
if ( _assetName == null ) {
_assetName = "" ;
}

_assetName ??= string.Empty ;
bool bResult =
HEU_HAPIUtility.CreateAndCookInputAsset( session, _assetName, HEU_PluginSettings.CookTemplatedGeos,
HEU_HAPIUtility.CreateAndCookInputAsset( session,
_assetName,
HEU_PluginSettings.CookTemplatedGeos,
out newAssetID ) ;
if ( !bResult ) {
if ( newAssetID is not HEU_Defines.HEU_INVALID_NODE_ID ) {
Expand All @@ -1981,7 +1975,7 @@ bool FinishRebuild( ) {
}
}
else {
HEU_Logger.LogErrorFormat( HEU_Defines.HEU_NAME + ": Unsupported asset type {0}!", _assetType ) ;
HEU_Logger.LogErrorFormat( $"{HEU_Defines.HEU_NAME}: Unsupported asset type {{0}}!", _assetType ) ;
return false ;
}

Expand All @@ -2000,7 +1994,7 @@ bool FinishRebuild( ) {
_assetName = realName ;
}
else {
_assetName = realName.Substring( 0, 3 ) + GetHashCode( ) ;
_assetName = realName[ ..3 ] + GetHashCode( ) ;
}

_assetOpName = HEU_SessionManager.GetString( _assetInfo.fullOpNameSH, session ) ;
Expand All @@ -2024,14 +2018,14 @@ bool FinishRebuild( ) {
GenerateParameters( session ) ;

// Save the default preset
if ( _parameters != null ) {
if ( _parameters ) {
_parameters.DownloadAsDefaultPresetData( session ) ;
}

// Create objects in this asset. It will create object nodes, geometry, and anything else required.
if ( !CreateObjects( session ) ) {
// Failed to create objects means that this asset is not valid
HEU_Logger.LogErrorFormat( HEU_Defines.HEU_NAME + ": Failed to create objects for asset {0}",
HEU_Logger.LogErrorFormat( $"{HEU_Defines.HEU_NAME}: Failed to create objects for asset {{0}}",
_assetName ) ;
DeleteAllGeneratedData( ) ;
return false ;
Expand All @@ -2058,17 +2052,17 @@ bool FinishRebuild( ) {
SetCookStatus( AssetCookStatus.POSTLOAD, AssetCookResult.SUCCESS ) ;

// Finally load the saved preset and request another cook.
if ( _savedAssetPreset != null ) {
if ( _savedAssetPreset is not null ) {
LoadAssetPresetAndCook( _savedAssetPreset ) ;
_savedAssetPreset = null ;
}

if ( HEU_PDGSession.IsPDGAsset( session, newAssetID ) &&
RootGameObject.GetComponent< HEU_PDGAssetLink >( ) == null ) {
HEU_PDGAssetLink assetLink = RootGameObject.AddComponent< HEU_PDGAssetLink >( ) ;
assetLink.Setup( this ) ;
}

if ( !HEU_PDGSession.IsPDGAsset( session, newAssetID )
|| RootGameObject.GetComponent< HEU_PDGAssetLink >( ) )
return true ;

HEU_PDGAssetLink assetLink = RootGameObject.AddComponent< HEU_PDGAssetLink >( ) ;
assetLink.Setup( this ) ;
return true ;
}

Expand Down Expand Up @@ -3736,7 +3730,7 @@ void UpdateHoudiniMaterials( HEU_SessionBase session ) {
foreach ( HEU_MaterialData materialData in _materialCache ) {
// Non-Houdini material so no need to update it.
if ( materialData == null || materialData._materialSource != HEU_MaterialData.Source.HOUDINI ||
materialData._materialKey == HEU_Defines.HEU_INVALID_MATERIAL
materialData._materialKey is HEU_Defines.HEU_INVALID_MATERIAL
|| materialData._materialKey == HEU_Defines.EDITABLE_MATERIAL_KEY ) {
continue ;
}
Expand Down
4 changes: 2 additions & 2 deletions Plugins/HoudiniEngineUnity/Scripts/HEU_HoudiniVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class HEU_HoudiniVersion
{
public const int HOUDINI_MAJOR = 20;
public const int HOUDINI_MINOR = 0;
public const int HOUDINI_BUILD = 666;
public const int HOUDINI_BUILD = 673;
public const int HOUDINI_PATCH = 0;

public const string HOUDINI_VERSION_STRING = "20.0.666";
public const string HOUDINI_VERSION_STRING = "20.0.673";

public const int HOUDINI_ENGINE_MAJOR = 6;
public const int HOUDINI_ENGINE_MINOR = 2;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 10 additions & 16 deletions Plugins/HoudiniEngineUnity/Scripts/Sessions/HEU_SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public static class HEU_SessionManager {
/// </summary>
/// <returns>A new session object</returns>
public static HEU_SessionBase CreateSessionObject( ) {
HEU_SessionBase sessionBase = null ;
#if HOUDINIENGINEUNITY_ENABLED
sessionBase = new HEU_SessionHAPI( ) ;
HEU_SessionHAPI sessionBase = new( ) ;
#else
sessionBase = new HEU_SessionBase();

HEU_SessionBase sessionBase = new( ) ;
#endif
return sessionBase ;
}
Expand Down Expand Up @@ -206,11 +206,12 @@ static void InternalValidateSceneAssets( ) {
// Go through each asset, and validate in session
_assets = Object.FindObjectsByType< HEU_HoudiniAsset >( FindObjectsSortMode.None ) ;
foreach ( HEU_HoudiniAsset asset in _assets ) {
if ( !asset || asset.SessionID == HEU_Defines.HEU_INVALID_NODE_ID ) continue ;
if ( asset is not { SessionID: not HEU_Defines.HEU_INVALID_NODE_ID } )
continue ;

if ( _sessionMap.TryGetValue( asset.SessionID, out HEU_SessionBase session ) )
session.RegisterAsset( asset ) ;
else
else
asset.InvalidateAsset( ) ;
}
}
Expand Down Expand Up @@ -442,15 +443,8 @@ public static bool RestartSession( ) {
/// </summary>
/// <returns>True if plugin is installed and session is valid.</returns>
public static bool ValidatePluginSession( HEU_SessionBase session = null ) {
if ( session is null ) {
session = GetOrCreateDefaultSession( ) ;
}

if ( session is null || !session.IsSessionValid( ) ) {
return false ;
}

return true ;
session ??= GetOrCreateDefaultSession( ) ;
return session?.IsSessionValid( ) is true ;
}

/// <summary>Returns last session error.</summary>
Expand Down Expand Up @@ -504,14 +498,14 @@ public static string GetConnectionError( bool clear ) {
}

public static bool IsHARSProcessRunning( int processID ) {
if ( processID <= 0 ) return false ;
if ( processID < 1 ) return false ;
try {
System.Diagnostics.Process serverProcess =
System.Diagnostics.Process.GetProcessById( processID ) ;
return serverProcess is { HasExited: false, ProcessName: "HARS" } ;
//!serverProcess.HasExited && serverProcess.ProcessName.Equals( "HARS" ) ;
}
catch ( System.Exception ) { return false ; }
catch ( Exception ) { return false ; }
}

// SESSION DEBUG ----------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 9feda3b

Please sign in to comment.