-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathHEU_HoudiniAsset.cs
More file actions
5683 lines (4740 loc) · 224 KB
/
HEU_HoudiniAsset.cs
File metadata and controls
5683 lines (4740 loc) · 224 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) <2020> Side Effects Software Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if (UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_LINUX)
#define HOUDINIENGINEUNITY_ENABLED
#endif
// Uncomment to profile
//#define HEU_PROFILER_ON
using System.Text;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
// Expose internal classes/functions
#if UNITY_EDITOR
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("HoudiniEngineUnityEditor")]
[assembly: InternalsVisibleTo("HoudiniEngineUnityEditorTests")]
[assembly: InternalsVisibleTo("HoudiniEngineUnityPlayModeTests")]
#endif
namespace HoudiniEngineUnity
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Typedefs (copy these from HEU_Common.cs)
using HAPI_NodeId = System.Int32;
using HAPI_AssetLibraryId = System.Int32;
using HAPI_StringHandle = System.Int32;
using HAPI_ErrorCodeBits = System.Int32;
using HAPI_NodeTypeBits = System.Int32;
using HAPI_NodeFlagsBits = System.Int32;
using HAPI_ParmId = System.Int32;
using HAPI_PartId = System.Int32;
/// <summary>
/// Represents a Houdini Digital Asset in Unity.
/// Contains object nodes, geo nodes, and parts for an HDA.
/// Contains HDA's parameters.
/// Load, (re)cook, and bake out asset.
/// Can (and should) be excluded from builds & runtime.
/// </summary>
[ExecuteInEditMode] // OnEnable/OnDisable for registering for tick
public sealed class HEU_HoudiniAsset : MonoBehaviour, IHEU_HoudiniAsset, IEquivable<HEU_HoudiniAsset>
{
// ASSET DATA ------------------------------------------------------------------------------------------------
internal enum HEU_AssetType
{
TYPE_INVALID = 0,
TYPE_HDA,
TYPE_CURVE,
TYPE_INPUT
}
// PUBLIC FIELDS ==============================================================
// Get/Set options
/// <inheritdoc />
public bool LoadAssetFromMemory
{
get { return _loadAssetFromMemory; }
set { _loadAssetFromMemory = value; }
}
/// <inheritdoc />
public bool AlwaysOverwriteOnLoad
{
get { return _alwaysOverwriteOnLoad; }
set { _alwaysOverwriteOnLoad = value; }
}
/// <inheritdoc />
public bool GenerateUVs
{
get { return _generateUVs; }
set { _generateUVs = value; }
}
/// <inheritdoc />
public bool GenerateTangents
{
get { return _generateTangents; }
set { _generateTangents = value; }
}
/// <inheritdoc />
public bool GenerateNormals
{
get { return _generateNormals; }
set { _generateNormals = value; }
}
/// <inheritdoc />
public bool PushTransformToHoudini
{
get { return _pushTransformToHoudini; }
set { _pushTransformToHoudini = value; }
}
/// <inheritdoc />
public bool TransformChangeTriggersCooks
{
get { return _transformChangeTriggersCooks; }
set { _transformChangeTriggersCooks = value; }
}
/// <inheritdoc />
public bool CookingTriggersDownCooks
{
get { return _cookingTriggersDownCooks; }
set { _cookingTriggersDownCooks = value; }
}
/// <inheritdoc />
public bool AutoCookOnParameterChange
{
get { return _autoCookOnParameterChange; }
set { _autoCookOnParameterChange = value; }
}
/// <inheritdoc />
public bool IgnoreNonDisplayNodes
{
get { return _ignoreNonDisplayNodes; }
set { _ignoreNonDisplayNodes = value; }
}
/// <inheritdoc />
public bool UseOutputNodes
{
get { return _useOutputNodes; }
set { _useOutputNodes = value; }
}
/// <inheritdoc />
public bool GenerateMeshUsingPoints
{
get { return _generateMeshUsingPoints; }
set { _generateMeshUsingPoints = value; }
}
/// <inheritdoc />
public bool UseLODGroups
{
get { return _useLODGroups; }
set { _useLODGroups = value; }
}
/// <inheritdoc />
public bool SplitGeosByGroup
{
get { return _splitGeosByGroup; }
set { _splitGeosByGroup = value; }
}
/// <inheritdoc />
public bool SessionSyncAutoCook
{
get { return _sessionSyncAutoCook; }
set { _sessionSyncAutoCook = value; }
}
/// <inheritdoc />
public bool BakeUpdateKeepPreviousTransformValues
{
get { return _bakeUpdateKeepPreviousTransformValues; }
set { _bakeUpdateKeepPreviousTransformValues = value; }
}
/// <inheritdoc />
public bool PauseCooking
{
get { return _pauseCooking; }
set { _pauseCooking = value; }
}
/// <inheritdoc />
public bool CurveEditorEnabled
{
get { return _curveEditorEnabled; }
set { _curveEditorEnabled = value; }
}
/// <inheritdoc />
public HEU_CurveDrawCollisionWrapper CurveDrawCollision
{
get { return CurveDrawCollision_InternalToWrapper(_curveDrawCollision); }
set { _curveDrawCollision = CurveDrawCollision_WrapperToInternal(value); }
}
/// <inheritdoc />
public LayerMask CurveDrawLayerMask
{
get { return _curveDrawLayerMask; }
set { _curveDrawLayerMask = value; }
}
/// <inheritdoc />
public float CurveProjectMaxDistance
{
get { return _curveProjectMaxDistance; }
set { _curveProjectMaxDistance = value; }
}
/// <inheritdoc />
public Vector3 CurveProjectDirection
{
get { return _curveProjectDirection; }
set { _curveProjectDirection = value; }
}
/// <inheritdoc />
public bool CurveProjectDirectionToView
{
get { return _curveProjectDirectionToView; }
set { _curveProjectDirectionToView = value; }
}
/// <inheritdoc />
public bool CurveDisableScaleRotation
{
get { return _curveDisableScaleRotation; }
set { _curveDisableScaleRotation = value; }
}
/// <inheritdoc />
public bool CurveFrameSelectedNodes
{
get { return _curveFrameSelectedNodes; }
set { _curveFrameSelectedNodes = value; }
}
/// <inheritdoc />
public float CurveFrameSelectedNodeDistance
{
get { return _curveFrameSelectedNodeDistance; }
set { _curveFrameSelectedNodeDistance = value; }
}
/// <inheritdoc />
public bool HandlesEnabled
{
get { return _handlesEnabled; }
set { _handlesEnabled = value; }
}
/// <inheritdoc />
public bool EditableNodesToolsEnabled
{
get { return _editableNodesToolsEnabled; }
set { _editableNodesToolsEnabled = value; }
}
// Read only ====
/// <inheritdoc />
public HEU_AssetTypeWrapper AssetType
{
get { return AssetType_InternalToWrapper(_assetType); }
}
/// <inheritdoc />
public HAPI_AssetInfo AssetInfo
{
get { return _assetInfo; }
}
/// <inheritdoc />
public HAPI_NodeInfo NodeInfo
{
get { return _nodeInfo; }
}
/// <inheritdoc />
public string AssetName
{
get { return _assetName; }
}
/// <inheritdoc />
public string AssetOpName
{
get { return _assetOpName; }
}
/// <inheritdoc />
public string AssetHelp
{
get { return _assetHelp; }
}
/// <inheritdoc />
public HAPI_NodeId AssetID
{
get { return _assetID; }
}
/// <inheritdoc />
public string AssetPath
{
get { return _assetPath; }
}
/// <inheritdoc />
public GameObject OwnerGameObject
{
get { return this.gameObject; }
}
/// <inheritdoc />
public GameObject RootGameObject
{
get { return _rootGameObject; }
}
/// <inheritdoc />
public List<HEU_MaterialData> MaterialCache
{
get { return _materialCache; }
}
/// <inheritdoc />
public HEU_Parameters Parameters
{
get { return _parameters; }
}
/// <inheritdoc />
public string AssetCacheFolder
{
get { return _assetCacheFolderPath; }
}
/// <inheritdoc />
public string[] SubassetNames
{
get { return _subassetNames; }
}
/// <inheritdoc />
public int SelectedSubassetIndex
{
get { return _selectedSubassetIndex; }
}
/// <inheritdoc />
public HEU_AssetCookStatusWrapper CookStatus
{
get { return AssetCookStatus_InternalToWrappper(_cookStatus); }
}
public HEU_AssetCookResultWrapper LastCookResult
{
get { return AssetCookResult_InternalToWrapper(_lastCookResult); }
}
/// <inheritdoc />
public long SessionID
{
get { return _sessionID; }
}
/// <inheritdoc />
public List<HEU_Curve> Curves
{
get { return _curves; }
}
/// <inheritdoc />
public List<HEU_InputNode> InputNodes
{
get { return _inputNodes; }
}
/// <inheritdoc />
public List<HEU_VolumeCache> VolumeCaches
{
get { return _volumeCaches; }
}
// ASSET EVENTS ----
/// <inheritdoc />
public HEU_ReloadDataEvent ReloadDataEvent
{
get { return _reloadDataEvent; }
}
/// <inheritdoc />
public HEU_CookedDataEvent CookedDataEvent
{
get { return _cookedDataEvent; }
}
/// <inheritdoc />
public HEU_BakedDataEvent BakedDataEvent
{
get { return _bakedDataEvent; }
}
/// <inheritdoc />
public HEU_PreAssetEvent PreAssetEvent
{
get { return _preAssetEvent; }
}
// =====================================================================
// PRIVATE MEMBERS ===================================================
[SerializeField] private HEU_AssetType _assetType;
internal HEU_AssetType AssetTypeInternal
{
get { return _assetType; }
}
[SerializeField] private HAPI_AssetInfo _assetInfo;
[SerializeField] private HAPI_NodeInfo _nodeInfo;
[SerializeField] private string _assetName;
[SerializeField] private string _assetOpName;
[SerializeField] private string _assetHelp;
[System.NonSerialized] private HAPI_NodeId _assetID = HEU_Defines.HEU_INVALID_NODE_ID;
[SerializeField] private string _assetPath;
// If true, this asset file will be loaded into memory first
// in Unity, then HARS will load it from memory buffer.
[SerializeField] private bool _loadAssetFromMemory;
// If true, always overwrite the existing HDA file in a call to LoadAssetLibraryFromFile (Without showing dialog)
[SerializeField] private bool _alwaysOverwriteOnLoad;
#pragma warning disable 0414
[SerializeField] private UnityEngine.Object _assetFileObject;
#pragma warning restore 0414
[SerializeField] private List<HEU_ObjectNode> _objectNodes;
[SerializeField] private GameObject _rootGameObject;
[SerializeField] private List<HEU_MaterialData> _materialCache;
[SerializeField] private HEU_Parameters _parameters;
[SerializeField] private Matrix4x4 _lastSyncedTransformMatrix;
[SerializeField] private List<Matrix4x4> _lastSyncedChildTransformMatrices;
// Location of this asset's cache folder for storing persistant data
[SerializeField] private string _assetCacheFolderPath;
[SerializeField] private string[] _subassetNames;
[SerializeField] private int _selectedSubassetIndex;
// Unserialized asset preset used when re-building asset to reapply parameter values
private HEU_AssetPreset _savedAssetPreset;
// Pending presets to apply after a Recook, which is invoked after a Rebuild
private HEU_RecookPreset _recookPreset;
// Keeps track of total cooks for this asset in order to check if need to update from Houdini
[SerializeField] private int _totalCookCount;
// BUILD & COOK -----------------------------------------------------------------------------------------------
internal enum AssetBuildAction
{
NONE,
RELOAD,
COOK,
INVALID,
STRIP_HEDATA,
DUPLICATE,
RESET_PARAMS
}
[SerializeField] private AssetBuildAction _requestBuildAction;
#pragma warning disable 0414
[SerializeField] private bool _checkParameterChangeForCook;
[SerializeField] private bool _skipCookCheck;
[SerializeField] private bool _uploadParameters;
[SerializeField] private bool _forceUploadInputs;
[SerializeField] private bool _upstreamCookChanged;
internal enum AssetCookStatus
{
NONE,
COOKING,
POSTCOOK,
LOADING,
POSTLOAD,
PRELOAD,
SELECT_SUBASSET
}
[SerializeField] private AssetCookStatus _cookStatus;
internal AssetCookStatus GetCookStatus()
{
return _cookStatus;
}
#pragma warning restore 0414
internal enum AssetCookResult
{
NONE,
SUCCESS,
ERRORED
}
[SerializeField] private AssetCookResult _lastCookResult;
internal AssetCookResult GetLastCookResult()
{
return _lastCookResult;
}
[SerializeField] private bool _isCookingAssetReloaded;
// Force everything to be updated without checking if changed
private bool _bForceUpdate;
[SerializeField] private long _sessionID = HEU_SessionData.INVALID_SESSION_ID;
[field: SerializeField] internal bool WarnedPrefabNotSupported { get; set; }
// UI TOGGLES -------------------------------------------------------------------------------------------------
// Disable the warning for unused variables. We're accessing these as SerializedProperty.
#pragma warning disable 0414
// By default, this component's serialized properties on custom inspector is locked out
// to reduce user tampering.
[SerializeField] private bool _uiLocked = true;
[SerializeField] private bool _showHDAOptions = false;
[SerializeField] private bool _showGenerateSection = true;
[SerializeField] private bool _showBakeSection = false;
[SerializeField] private bool _showEventsSection = false;
[SerializeField] private bool _showCurvesSection = false;
[SerializeField] private bool _showInputNodesSection = false;
[SerializeField] private bool _showToolsSection = false;
[SerializeField] private bool _showTerrainSection = false;
[SerializeField] private HEU_InstanceInputUIState _instanceInputUIState;
//! No attribute needed here (explicit field already serialized above)
internal HEU_InstanceInputUIState InstanceInputUIState
{
get { return _instanceInputUIState; }
set { _instanceInputUIState = value; }
}
#pragma warning restore 0414
// ASSET EVENTS -----------------------------------------------------------------------------------------------
[SerializeField] private HEU_ReloadDataEvent _reloadDataEvent = new HEU_ReloadDataEvent();
[SerializeField] private HEU_CookedDataEvent _cookedDataEvent = new HEU_CookedDataEvent();
[SerializeField] private HEU_BakedDataEvent _bakedDataEvent = new HEU_BakedDataEvent();
[SerializeField] private HEU_PreAssetEvent _preAssetEvent = new HEU_PreAssetEvent();
// Delegate for Editor window to hook into for callback when needing updating
public delegate void UpdateUIDelegate();
[SerializeField] private UpdateUIDelegate _refreshUIDelegate;
internal UpdateUIDelegate RefreshUIDelegate
{
get { return _refreshUIDelegate; }
set { _refreshUIDelegate = value; }
}
// CONNECTIONS ------------------------------------------------------------------------------------------------
private HEU_CookedDataEvent _downstreamConnectionCookedEvent = new HEU_CookedDataEvent();
// HDA OPTIONS ------------------------------------------------------------------------------------------------
[SerializeField] private bool _generateUVs = false;
[SerializeField] private bool _generateTangents = true;
[SerializeField] private bool _generateNormals = true;
[SerializeField] private bool _pushTransformToHoudini = true;
[SerializeField] private bool _transformChangeTriggersCooks = false;
[SerializeField] private bool _cookingTriggersDownCooks = true;
[SerializeField] private bool _autoCookOnParameterChange = true;
[SerializeField] private bool _ignoreNonDisplayNodes = false;
[SerializeField] private bool _useOutputNodes = true;
[SerializeField] private bool _generateMeshUsingPoints = false;
[SerializeField] private bool _useLODGroups = true;
[SerializeField] private bool _splitGeosByGroup = false;
[SerializeField] private bool _sessionSyncAutoCook = true;
[SerializeField] private bool _bakeUpdateKeepPreviousTransformValues = false;
// If false, pauses all cooking on this HDA until set back to true. Meant for unit testing use.
private bool _pauseCooking = false;
// CURVES -----------------------------------------------------------------------------------------------------
// Toggle curve editing tool in Scene view
[SerializeField] private bool _curveEditorEnabled = true;
[SerializeField] private List<HEU_Curve> _curves;
[SerializeField] private HEU_Curve.CurveDrawCollision _curveDrawCollision;
internal HEU_Curve.CurveDrawCollision CurveDrawCollisionInternal
{
get { return _curveDrawCollision; }
}
[SerializeField] private List<Collider> _curveDrawColliders = new List<Collider>();
internal List<Collider> GetCurveDrawColliders()
{
return _curveDrawColliders;
}
[SerializeField] private LayerMask _curveDrawLayerMask;
internal LayerMask GetCurveDrawLayerMask()
{
return _curveDrawLayerMask;
}
internal void SetCurveDrawLayerMask(LayerMask mask)
{
_curveDrawLayerMask = mask;
}
[SerializeField] private float _curveProjectMaxDistance = 1000f;
[SerializeField] private Vector3 _curveProjectDirection = Vector3.down;
[SerializeField] private bool _curveProjectDirectionToView = true;
[SerializeField] private bool _curveDisableScaleRotation = true;
[SerializeField] private bool _curveFrameSelectedNodes = true;
[SerializeField] private float _curveFrameSelectedNodeDistance = 20f;
// INPUT NODES ------------------------------------------------------------------------------------------------
[SerializeField] private List<HEU_InputNode> _inputNodes;
// HANDLES ----------------------------------------------------------------------------------------------------
[SerializeField] private List<HEU_Handle> _handles;
internal List<HEU_Handle> Handles
{
get { return _handles; }
}
[SerializeField] private bool _handlesEnabled = true;
// TERRAIN ----------------------------------------------------------------------------------------------------
[SerializeField] private List<HEU_VolumeCache> _volumeCaches;
// TOOLS ------------------------------------------------------------------------------------------------------
[SerializeField] private List<HEU_AttributesStore> _attributeStores;
internal List<HEU_AttributesStore> AttributeStores
{
get { return _attributeStores; }
}
[SerializeField] private bool _editableNodesToolsEnabled = false;
[SerializeField] private HEU_ToolsInfo _toolsInfo;
internal HEU_ToolsInfo ToolsInfo
{
get { return _toolsInfo; }
}
[SerializeField, HideInInspector] private HEU_AssetSerializedMetaData _serializedMetaData;
internal HEU_AssetSerializedMetaData SerializedMetaData
{
get { return _serializedMetaData; }
}
private bool _pendingAutoCookOnMouseRelease;
internal bool PendingAutoCookOnMouseRelease
{
get { return _pendingAutoCookOnMouseRelease; }
set
{
if (_autoCookOnParameterChange)
_pendingAutoCookOnMouseRelease = value;
else
_pendingAutoCookOnMouseRelease = false;
}
}
// Enum to guess how Unity instantiated this object (because Unity doesn't provide instantiation callbacks)
private enum AssetInstantiationMethod
{
DEFAULT,
DUPLICATED,
UNDO
};
// PROFILE ----------------------------------------------------------------------------------------------------
#if HEU_PROFILER_ON
private float _cookStartTime;
private float _hapiCookEndTime;
private float _postCookStartTime;
#endif
// PUBLIC FUNCTIONS ================================================================
/// <inheritdoc />
public bool RequestCook(bool bCheckParametersChanged = true, bool bAsync = false, bool bSkipCookCheck = true, bool bUploadParameters = true)
{
#if HOUDINIENGINEUNITY_ENABLED
//HEU_Logger.Log(HEU_Defines.HEU_NAME + ": Requesting Cook");
if (!HEU_PluginSettings.CookDisabledGameObjects && !this.gameObject.activeInHierarchy)
{
HEU_Logger.LogWarning("Houdini Asset: " + this.RootGameObject.name +
" Skipped cooking due to being disabled. Enable and recook manually to resync!");
return false;
}
if (bAsync)
{
// We don't want to override Reload or Invalid actions, so
// for now, only set request if no other pending build actions.
if (_requestBuildAction == AssetBuildAction.NONE)
{
_requestBuildAction = AssetBuildAction.COOK;
}
// This could be an update on the cook settings
if (_requestBuildAction == AssetBuildAction.COOK)
{
_checkParameterChangeForCook = bCheckParametersChanged;
_skipCookCheck = bSkipCookCheck;
_uploadParameters = bUploadParameters;
}
else
{
HEU_Logger.LogWarning(HEU_Defines.HEU_NAME + ": Asset busy. Unable to start cooking!");
}
}
else
{
if (_cookStatus == AssetCookStatus.NONE || _cookStatus == AssetCookStatus.POSTLOAD)
{
RecookBlocking(bCheckParametersChanged, bSkipCookCheck,
bUploadParameters, bUploadParameterPreset: false,
bForceUploadInputs: false, bCookingSessionSync: false);
}
else
{
HEU_Logger.LogWarningFormat(HEU_Defines.HEU_NAME + ": Houdini Engine: Asset busy (cook status: {0}). Unable to start cooking!",
_cookStatus);
}
}
#endif
return true;
}
/// <inheritdoc />
public bool RequestReload(bool bAsync = false)
{
#if HOUDINIENGINEUNITY_ENABLED
if (!HEU_PluginSettings.CookDisabledGameObjects && !this.gameObject.activeInHierarchy)
{
HEU_Logger.LogWarning("Houdini Asset: " + this.RootGameObject.name +
" Skipped cooking due to being disabled. Enable and recook manually to resync!");
return false;
}
if (bAsync)
{
_requestBuildAction = AssetBuildAction.RELOAD;
}
else
{
ClearBuildRequest();
SetCookStatus(AssetCookStatus.PRELOAD, AssetCookResult.NONE);
ProcessRebuild(true, -1);
}
#endif
return true;
}
/// <inheritdoc />
public bool RequestResetParameters(bool bAsync = false)
{
#if HOUDINIENGINEUNITY_ENABLED
if (bAsync)
{
_requestBuildAction = AssetBuildAction.RESET_PARAMS;
}
else
{
ClearBuildRequest();
SetCookStatus(AssetCookStatus.PRELOAD, AssetCookResult.NONE);
ResetParametersToDefault();
ProcessRebuild(true, -1);
}
#endif
return true;
}
/// <inheritdoc />
public GameObject DuplicateAsset(GameObject newRootGameObject = null)
{
string goName = _rootGameObject.name + "_copy";
bool bBuildAsync = false;
HEU_SessionBase session = GetAssetSession(true);
Transform thisParentTransform = _rootGameObject.transform.parent;
if (_assetType == HEU_AssetType.TYPE_HDA)
{
newRootGameObject = HEU_HAPIUtility.InstantiateHDA(_assetPath, _rootGameObject.transform.position, session, bBuildAsync,
bAlwaysOverwriteOnLoad: false, rootGO: newRootGameObject);
}
else if (_assetType == HEU_AssetType.TYPE_CURVE)
{
newRootGameObject = HEU_HAPIUtility.CreateNewCurveAsset(parentTransform: thisParentTransform, session: session,
bBuildAsync: bBuildAsync, rootGO: newRootGameObject);
}
else if (_assetType == HEU_AssetType.TYPE_INPUT)
{
newRootGameObject = HEU_HAPIUtility.CreateNewInputAsset(parentTransform: thisParentTransform, session: session,
bBuildAsync: bBuildAsync, rootGO: newRootGameObject);
}
else
{
HEU_Logger.LogErrorFormat("Unsupported asset type {0} for duplication.", _assetType);
return null;
}
HEU_HoudiniAssetRoot newRoot = newRootGameObject.GetComponent<HEU_HoudiniAssetRoot>();
HEU_HoudiniAsset newAsset = newRoot._houdiniAsset;
Transform newRootTransform = newRootGameObject.transform;
newRootTransform.parent = thisParentTransform;
newRootTransform.localPosition = _rootGameObject.transform.localPosition;
newRootTransform.localRotation = _rootGameObject.transform.localRotation;
newRootTransform.localScale = _rootGameObject.transform.localScale;
this.CopyPropertiesTo(newAsset);
// Select it
HEU_EditorUtility.SelectObject(newRootGameObject);
return newRootGameObject;
}
/// <inheritdoc />
public bool DeleteAllGeneratedData(bool bIsRebuild = false)
{
if (_assetID != HEU_Defines.HEU_INVALID_NODE_ID)
{
DeleteSessionDataOnly();
_assetID = HEU_Defines.HEU_INVALID_NODE_ID;
}
// Clean up object nodes which in turns cleans up meshes.
if (_objectNodes != null)
{
for (int i = 0; i < _objectNodes.Count; ++i)
{
if (_objectNodes[i] != null)
{
_objectNodes[i].DestroyAllData(bIsRebuild);
HEU_GeneralUtility.DestroyImmediate(_objectNodes[i]);
}
}
_objectNodes.Clear();
}
// The materials for this asset will be deleted when we delete the asset cache.
// So we'll just clear the material cache without actually deleting them.
ClearMaterialCache();
// Clear out connection callbacks using parameter input nodes
ClearAllUpstreamConnections();
if (_parameters != null)
{
_parameters.CleanUp();
_parameters = null;
}
CleanUpInputNodes();
CleanUpHandles();
// Delete children objects just in case.
// Don't delete children if part of a prefab.
bool isPrefab = HEU_EditorUtility.IsPrefabAsset(gameObject);
if (!isPrefab)
{
Transform[] transforms = this.GetComponentsInChildren<Transform>();
foreach (Transform trans in transforms)
{
if (trans != this.transform)
{
DestroyImmediate(trans.gameObject);
}
}
}
return true;
}
/// <inheritdoc />
public GameObject BakeToNewPrefab(string destinationPrefabPath = null)
{
if (_preAssetEvent != null)
{