public void init( int asset_id, int node_id, HoudiniAsset asset, int object_id, string object_name, bool object_visible) { prAssetId = asset_id; prNodeId = node_id; prAsset = asset; prObjectId = object_id; prObjectName = object_name; prObjectVisible = object_visible; }
public static HoudiniAssetAccessor getAssetAccessor(GameObject gameObject) { HoudiniAsset asset = gameObject.GetComponent <HoudiniAsset>(); if (asset) { return(new HoudiniAssetAccessor(asset)); } return(null); }
public void init( int asset_id, int node_id, HoudiniAsset asset, int object_id, string object_name, bool object_visible ) { prAssetId = asset_id; prNodeId = node_id; prAsset = asset; prObjectNodeId = node_id; prObjectId = object_id; prObjectName = object_name; prObjectVisible = object_visible; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Public public virtual void OnEnable() { myAsset = target as HoudiniAsset; myUndoInfo = myAsset.prAssetUndoInfo; myParmChanges = true; myUnbuiltChanges = false; myFocusChanged = true; myHelpScrollPosition = new Vector2( 0.0f, 0.0f ); HoudiniHost.myRepaintDelegate += this.refresh; HoudiniHost.myDeselectionDelegate += this.deselect; HoudiniHost.mySelectionTarget = myAsset.gameObject; // If selection is a prefab build it ( parameters only ) to allow // editing of parameters. Only need to build once, the first time // it is selected. if ( myAsset.isPrefab() ) { // Reloading prefab after play mode change since OnEnable // never gets called for prefab. This only needs to be done // if prefab has already been built. if ( myAsset.prReloadPrefabOnPlaymodeChange && HoudiniHost.isAssetValid( myAsset.prAssetId, myAsset.prAssetValidationId ) ) { myAsset.prReloadPrefabOnPlaymodeChange = false; myAsset.build( false, // reload_asset false, // unload_asset_first true, // serializatin_recovery_only false, // force_reconnect false, // is_duplication false, // cook_downstream_assets false // use_delay_for_progress_bar ); } else if ( myAsset.prAssetId != myAsset.prBackupAssetId || !HoudiniHost.isAssetValid( myAsset.prAssetId, myAsset.prAssetValidationId ) ) { myAsset.prAssetId = -1; myAsset.build( true, // reload_asset true, // unload_asset_first true, // serializatin_recovery_only false, // force_reconnect false, // is_duplication false, // cook_downstream_assets false // use_delay_for_progress_bar ); EditorUtility.SetDirty( myAsset ); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Public Methods public HoudiniProgressBar() { prCurrentValue = 0; prCurrentDuration = new System.TimeSpan(0); prTotal = 0; prTitle = "Building Houdini Asset"; prMessage = "Doing stuff."; prStartTime = System.DateTime.Now; #if UNITY_EDITOR myLastValue = -1; myLastMsg = ""; #endif // UNITY_EDITOR prUseDelay = true; prAsset = null; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Public Methods public HoudiniProgressBar() { prCurrentValue = 0; prCurrentDuration = new System.TimeSpan( 0 ); prTotal = 0; prTitle = "Building Houdini Asset"; prMessage = "Doing stuff."; prStartTime = System.DateTime.Now; #if UNITY_EDITOR myLastValue = -1; myLastMsg = ""; #endif // UNITY_EDITOR prUseDelay = true; prAsset = null; }
protected bool setTransformInput(int index) { if (myAsset.prUpStreamTransformObjects == null || myAsset.prUpStreamTransformObjects.Count <= 0) { return(false); } bool join_last = false; bool no_label_toggle_last = true; GameObject temp_obj = null; HoudiniGUIParm trans_input = new HoudiniGUIParm("trans_input_" + index, myAsset.prTransInputNames[index]); Object obj = (Object)myAsset.prUpStreamTransformObjects[index]; bool changed = HoudiniGUI.objectField(ref trans_input, ref obj, typeof(GameObject), ref join_last, ref no_label_toggle_last, null, ref temp_obj); if (changed) { if (!obj) { myAsset.prUpStreamTransformObjects[index] = null; myAsset.removeTransformInput(index); } else { GameObject game_obj = (GameObject)obj; myAsset.prUpStreamTransformObjects[index] = game_obj; HoudiniAsset input_asset = game_obj.GetComponent <HoudiniAsset>(); if (input_asset) { myAsset.addAssetAsTransformInput(input_asset, index); } else { myAsset.removeTransformInput(index); } myAsset.buildClientSide(); } } return(changed); }
// Initialization public void initialize(HoudiniAsset asset) { isGeoVisible = asset.prIsGeoVisible; showPinnedInstances = asset.prShowPinnedInstances; showOnlyVertexColours = asset.prShowOnlyVertexColours; generateUVs = asset.prGenerateUVs; generateLightmapUV2s = asset.prGenerateLightmapUV2s; generateTangents = asset.prGenerateTangents; enableCooking = asset.prEnableCooking; cookingTriggersDownCooks = asset.prCookingTriggersDownCooks; playmodePerFrameCooking = asset.prPlaymodePerFrameCooking; pushUnityTransformToHoudini = asset.prPushUnityTransformToHoudini; transformChangeTriggersCooks = asset.prTransformChangeTriggersCooks; importTemplatedGeos = asset.prImportTemplatedGeos; splitGeosByGroupOverride = asset.prSplitGeosByGroupOverride; splitGeosByGroup = asset.prSplitGeosByGroup; omitPartNameEnumeration = asset.prOmitPartNameEnumeration; bakeStartTime = asset.prBakeStartTime; bakeEndTime = asset.prBakeEndTime; bakeSamplesPerSecond = asset.prBakeSamplesPerSecond; }
// Initialization public void initialize(HoudiniAsset asset) { isGeoVisible = asset.prIsGeoVisible; showPinnedInstances = asset.prShowPinnedInstances; autoSelectAssetRootNode = asset.prAutoSelectAssetRootNode; materialShaderType = asset.prMaterialShaderType; renderResolution = asset.prRenderResolution; showOnlyVertexColours = asset.prShowOnlyVertexColours; generateTangents = asset.prGenerateTangents; enableCooking = asset.prEnableCooking; cookingTriggersDownCooks = asset.prCookingTriggersDownCooks; playmodePerFrameCooking = asset.prPlaymodePerFrameCooking; pushUnityTransformToHoudini = asset.prPushUnityTransformToHoudini; transformChangeTriggersCooks = asset.prTransformChangeTriggersCooks; importTemplatedGeos = asset.prImportTemplatedGeos; splitGeosByGroupOverride = asset.prSplitGeosByGroupOverride; splitGeosByGroup = asset.prSplitGeosByGroup; bakeStartTime = asset.prBakeStartTime; bakeEndTime = asset.prBakeEndTime; bakeSamplesPerSecond = asset.prBakeSamplesPerSecond; }
// Initialization public void initialize( HoudiniAsset asset ) { isGeoVisible = asset.prIsGeoVisible; showPinnedInstances = asset.prShowPinnedInstances; autoSelectAssetRootNode = asset.prAutoSelectAssetRootNode; showOnlyVertexColours = asset.prShowOnlyVertexColours; generateUVs = asset.prGenerateUVs; generateLightmapUV2s = asset.prGenerateLightmapUV2s; generateTangents = asset.prGenerateTangents; enableCooking = asset.prEnableCooking; cookingTriggersDownCooks = asset.prCookingTriggersDownCooks; playmodePerFrameCooking = asset.prPlaymodePerFrameCooking; pushUnityTransformToHoudini = asset.prPushUnityTransformToHoudini; transformChangeTriggersCooks = asset.prTransformChangeTriggersCooks; importTemplatedGeos = asset.prImportTemplatedGeos; splitGeosByGroupOverride = asset.prSplitGeosByGroupOverride; splitGeosByGroup = asset.prSplitGeosByGroup; bakeStartTime = asset.prBakeStartTime; bakeEndTime = asset.prBakeEndTime; bakeSamplesPerSecond = asset.prBakeSamplesPerSecond; }
static void OnPostprocessAllAssets(String[] importedAssets, String[] deletedAssets, String[] movedAssets, String[] movedFromAssetPaths) { foreach (string asset_path in deletedAssets) { if (HoudiniHost.myCleanUpPrefabAssets.ContainsKey(asset_path)) { int asset_id = HoudiniHost.myCleanUpPrefabAssets[asset_path]; HoudiniHost.destroyAsset(asset_id); HoudiniHost.myCleanUpPrefabAssets.Remove(asset_path); } } foreach (string asset_path in importedAssets) { if (asset_path.EndsWith(".prefab")) { GameObject prefab = AssetDatabase.LoadAssetAtPath(asset_path, typeof(GameObject)) as GameObject; if (prefab) { HoudiniAsset prefab_asset = prefab.GetComponent <HoudiniAsset>(); if (prPrefabToReplace && asset_path.Equals(AssetDatabase.GetAssetPath(prPrefabToReplace))) { prPrefabToReplace = null; } else if (prefab_asset && prefab_asset.isApplyingChangesToPrefab()) { prPrefabToReplace = prefab; // TODO: Used to be (why?): // EditorApplication.delayCall += ReplacePrefab; ReplacePrefab(); } } } } }
// Called before the asset cooks. virtual public void preCook(HoudiniAsset asset) { Debug.Log(asset.name + " is about to cook."); }
public void addDownstreamGeoAsset( HoudiniAsset asset ) { foreach ( HoudiniAsset downstream_asset in prDownStreamGeoAssets ) if ( downstream_asset == asset ) return; prDownStreamGeoAssets.Add( asset ); }
public void removeDownstreamGeoAsset( HoudiniAsset asset ) { prDownStreamGeoAssets.Remove( asset ); }
// Geometry related connection methods ------------------------------------------------------- public void addAssetAsGeoInput( HoudiniAsset asset, int object_index, int index ) { prUpStreamGeoAssets[ index ] = asset; HoudiniHost.connectAssetGeometry( asset.prAssetId, object_index, prAssetId, index ); asset.addDownstreamGeoAsset( this ); // We have to save the presets here because this connection might change a parm // and we want to save it. #if UNITY_EDITOR if ( !EditorApplication.isPlaying ) savePreset(); #endif // UNITY_EDITOR }
// Called after a *successful* cook. virtual public void postCook( HoudiniAsset asset ) { Debug.Log( asset.name + " just cooked." ); }
// Called before the asset cooks. virtual public void preCook( HoudiniAsset asset ) { Debug.Log( asset.name + " is about to cook." ); }
public void instanceObjects(HoudiniProgressBar progress_bar) { try { destroyChildren(); HAPI_ObjectInfo object_info = HoudiniHost.getObjectInfo(prObjectId); // Get Detail info. HAPI_GeoInfo geo_info = HoudiniHost.getDisplayGeoInfo(prObjectId); if (geo_info.partCount == 0) { return; } cacheNumInstances(); HAPI_Transform[] instance_transforms = new HAPI_Transform[myNumInstances]; Utility.getArray2Id( geo_info.nodeId, HAPI_RSTOrder.HAPI_SRT, HoudiniHost.getInstanceTransforms, instance_transforms, myNumInstances); // Get scale point attributes. HAPI_AttributeInfo scale_attr_info = new HAPI_AttributeInfo("scale"); float[] scale_attr = new float[0]; Utility.getAttribute( geo_info.nodeId, 0, "scale", ref scale_attr_info, ref scale_attr, HoudiniHost.getAttributeFloatData); if (scale_attr_info.exists && scale_attr_info.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT) { throw new HoudiniErrorIgnorable("I only understand scale as point attributes!"); } if (scale_attr_info.exists && scale_attr.Length != myNumInstances * 3) { throw new HoudiniError( "Unexpected scale array length found for asset: " + prAsset.prAssetId + "!\n" + "Expected length of: " + myNumInstances * 3 + " but given: " + scale_attr.Length); } HAPI_AttributeInfo script_attr_info = new HAPI_AttributeInfo("Unity_Script"); int[] script_attr = new int[0]; Utility.getAttribute( geo_info.nodeId, 0, "Unity_Script", ref script_attr_info, ref script_attr, HoudiniHost.getAttributeStringData); if (script_attr_info.exists && script_attr_info.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT) { throw new HoudiniErrorIgnorable("I only understand Unity_Script as point attributes!"); } if (script_attr_info.exists && script_attr.Length != myNumInstances) { throw new HoudiniError("Unexpected Unity_Script array length found for asset: " + prAsset.prAssetId + "!"); } int[] instance_attr = null; int[] name_attr = null; getInstanceAndNameAttrs(out instance_attr, out name_attr); progress_bar.prTotal = myNumInstances; List <int> exclusion_list = new List <int>(); instanceOverriddenObjects(myNumInstances, exclusion_list); List <string> unique_instantiated_names = new List <string>(); HoudiniInstancerPersistentData persistent_data = prPersistentData; if (persistent_data.variationChoice.Count != myNumInstances) { if (myNumInstances > persistent_data.variationChoice.Count) { int difference = myNumInstances - persistent_data.variationChoice.Count; for (int ii = 0; ii < difference; ii++) { persistent_data.variationChoice.Add(-1); } } else { int difference = persistent_data.variationChoice.Count - myNumInstances; persistent_data.variationChoice.RemoveRange( persistent_data.variationChoice.Count - difference, difference); } } bool liveTransformPropagationSetting = false; bool syncAssetTransformSetting = false; bool enableCooking = true; for (int i = 0; i < myNumInstances; ++i) { if (exclusion_list.Contains(i)) { continue; } GameObject obj_to_instance = null; if (instance_attr.Length > 0 || name_attr.Length > 0) { if (name_attr.Length > 0) { string obj_name = HoudiniHost.getString(name_attr[i]); int object_index = prAsset.findObjectByName(obj_name); if (object_index >= 0) { obj_to_instance = prAsset.prGameObjects[object_index]; } else { obj_to_instance = prAsset.findPartByName(obj_name, true); } if (obj_to_instance == null) { obj_to_instance = GameObject.Find(obj_name); } } else { string instanceObjectPath = HoudiniHost.getString(instance_attr[i]); string [] pathItems = instanceObjectPath.Split('/'); string instanceObjectName = pathItems[pathItems.Length - 1]; int objectIndex = prAsset.findObjectByName(instanceObjectName); if (objectIndex >= 0) { obj_to_instance = prAsset.prGameObjects[objectIndex]; } else { obj_to_instance = GameObject.Find(instanceObjectName); } } if (obj_to_instance != null) { HoudiniAsset hapi_asset = obj_to_instance.GetComponent <HoudiniAsset>(); if (hapi_asset != null) { liveTransformPropagationSetting = hapi_asset.prTransformChangeTriggersCooks; syncAssetTransformSetting = hapi_asset.prPushUnityTransformToHoudini; enableCooking = hapi_asset.prEnableCooking; hapi_asset.prTransformChangeTriggersCooks = false; hapi_asset.prPushUnityTransformToHoudini = false; hapi_asset.prEnableCooking = false; } } } else if (object_info.objectToInstanceId >= 0) { int object_to_instance_idx = prAsset.findObjectByNodeId(object_info.objectToInstanceId); if (object_to_instance_idx >= 0) { obj_to_instance = prAsset.prGameObjects[object_to_instance_idx]; } } if (obj_to_instance != null) { // Set progress bar information. progress_bar.prCurrentValue = i; progress_bar.prMessage = "Instancing: " + obj_to_instance.name + " (" + i + " of " + myNumInstances + ")"; progress_bar.displayProgressBar(); if (!unique_instantiated_names.Contains(obj_to_instance.name)) { unique_instantiated_names.Add(obj_to_instance.name); } Vector3 pos = new Vector3(); // Apply object transforms. // // Axis and Rotation conversions: // Note that Houdini's X axis points in the opposite direction that Unity's does. Also, Houdini's // rotation is right handed, whereas Unity is left handed. To account for this, we need to invert // the x coordinate of the translation, and do the same for the rotations (except for the x rotation, // which doesn't need to be flipped because the change in handedness AND direction of the left x axis // causes a double negative - yeah, I know). pos[0] = -instance_transforms[i].position[0]; pos[1] = instance_transforms[i].position[1]; pos[2] = instance_transforms[i].position[2]; Quaternion quat = new Quaternion(instance_transforms[i].rotationQuaternion[0], instance_transforms[i].rotationQuaternion[1], instance_transforms[i].rotationQuaternion[2], instance_transforms[i].rotationQuaternion[3]); Vector3 euler = quat.eulerAngles; euler.y = -euler.y; euler.z = -euler.z; Vector3 scale = new Vector3(instance_transforms[i].scale[0], instance_transforms[i].scale[1], instance_transforms[i].scale[2]); Matrix4x4 local_mat = new Matrix4x4(); local_mat.SetTRS(pos, Quaternion.Euler(euler), scale); // TODO: Now this *should* be the transform.localToWorldMatrix // but for some reason, after a scene load, we pick up compensating // factors in the local transform that cancel out the transform on the // asset. For now just use the asset's transform as the parent matrix. Matrix4x4 parent_mat = prAsset.transform.localToWorldMatrix; Matrix4x4 global_mat = parent_mat * local_mat; euler = HoudiniAssetUtility.getQuaternion(global_mat).eulerAngles; pos = HoudiniAssetUtility.getPosition(global_mat); scale = HoudiniAssetUtility.getScale(global_mat); //mat.SetTRS( pos, string script_to_attach = ""; if (script_attr_info.exists) { script_to_attach = HoudiniHost.getString(script_attr[i]); } instanceObject(obj_to_instance, pos, euler, i, scale_attr_info.exists, scale, script_attr_info.exists, script_to_attach); HoudiniAsset hapi_asset = obj_to_instance.GetComponent <HoudiniAsset>(); if (hapi_asset != null) { hapi_asset.prTransformChangeTriggersCooks = liveTransformPropagationSetting; hapi_asset.prPushUnityTransformToHoudini = syncAssetTransformSetting; hapi_asset.prEnableCooking = enableCooking; } } } updateUniqueInstantiatedNames(unique_instantiated_names); } catch (HoudiniError error) { Debug.LogWarning(error.ToString()); return; } }
public override void OnInspectorGUI() { bool gui_enable = GUI.enabled; // We can only build or do anything if we can link to our libraries. #if !( HAPI_ENABLE_RUNTIME ) HoudiniGUI.help(HoudiniConstants.HAPI_UNSUPPORTED_PLATFORM_MSG, MessageType.Info); GUI.enabled = false; #else if (!HoudiniHost.isInstallationOk()) { HoudiniGUI.help(HoudiniHost.getMissingEngineInstallHelpString(), MessageType.Info); GUI.enabled = false; } #endif // !( HAPI_ENABLE_RUNTIME ) try { myDelayBuild = false; myParmChanges = false; /////////////////////////////////////////////////////////////////////// // Draw License/Logo Thingy #if ( HAPI_ENABLE_RUNTIME ) drawLicenseLogo(); #endif /////////////////////////////////////////////////////////////////////// // Draw Game Object Controls if (HoudiniHost.isNodeValid(myAsset.prAssetId, myAsset.prNodeInfo.uniqueHoudiniNodeId) && (myAsset.prTransformInputCount > 0 || myAsset.prGeoInputCount > 0) && myAsset.prAssetType != HoudiniAsset.AssetType.TYPE_CURVE) { myAsset.prShowInputControls = HoudiniGUI.foldout("Inputs", myAsset.prShowInputControls, true); if (myAsset.prShowInputControls) { if (myAsset.prNodeInfo.type == HAPI_NodeType.HAPI_NODETYPE_OBJ) { for (int ii = 0; ii < myAsset.prTransformInputCount; ++ii) { myParmChanges |= setTransformInput(ii); } } if (myAsset.prUpStreamGeoObjects == null || myAsset.prUpStreamGeoAssets == null || myAsset.prUpStreamGeoObjects.Count <= 0 || myAsset.prUpStreamGeoAssets.Count <= 0) { myAsset.prGeoInputCount = 0; } for (int input_index = 0; input_index < myAsset.prGeoInputCount; ++input_index) { bool join_last = false; bool no_label_toggle_last = true; GameObject temp_obj = null; HoudiniGUIParm geo_input = new HoudiniGUIParm( "geo_input_" + input_index, myAsset.prGeoInputNames[input_index]); Object obj = (Object)myAsset.prUpStreamGeoObjects[input_index]; myParmChanges |= HoudiniGUI.objectField( ref geo_input, ref obj, typeof(GameObject), ref join_last, ref no_label_toggle_last, null, ref temp_obj); HoudiniGUIParm geo_input_transform_type = new HoudiniGUIParm( "geo_input_transform_type_" + input_index, "Keep world transform"); bool transform_type = myAsset.prGeoInputsTransformTypes[input_index] != 0; bool TransformTypeUpdate = HoudiniGUI.toggle(ref geo_input_transform_type, ref transform_type); bool need_build_client_side = false; if (myParmChanges || !myAsset.isGeoInputValid(input_index)) { if (!obj) { myAsset.removeGeoInput(input_index); //myAsset.buildClientSide(); need_build_client_side = true; } else { GameObject new_obj = (GameObject)obj; myAsset.prUpStreamGeoObjects[input_index] = new_obj; // Select the asset component (if it exists). HoudiniAsset asset = new_obj.GetComponent <HoudiniAsset>(); // If we're selecting a specific object to input than try and // get the object id. Note that by getting the HAPI_ObjectControl // component we also cover the geo and part controls because // they all inherit from HAPI_ObjectControl. The user can therefore // drag any gameObject under the asset into another asset's // input and have it all work. int object_index = 0; HoudiniObjectControl obj_control = new_obj.GetComponent <HoudiniObjectControl>(); if (obj_control) { object_index = obj_control.prObjectId; asset = obj_control.prAsset; } if (asset == null) { // Connecting a new game object myAsset.addGeoAsGeoInput(new_obj, input_index); myAsset.updateGeoInputTransformType(input_index, transform_type ? 1 : 0); need_build_client_side = true; //myAsset.buildClientSide(); } else if (myAsset.prUpStreamGeoAssets[input_index] != asset) { // Connecting a new asset if (myAsset == asset) { Debug.LogError("Can't connect an asset to itself!"); } else { myAsset.addAssetAsGeoInput(asset, object_index, input_index); myAsset.updateGeoInputTransformType(input_index, transform_type ? 1 : 0); need_build_client_side = true; //myAsset.buildClientSide(); } } } } if (TransformTypeUpdate) { myAsset.updateGeoInputTransformType(input_index, transform_type ? 1 : 0); need_build_client_side = true; } if (need_build_client_side) { myAsset.buildClientSide(); } } // for } // if } // if // Draw Cook Log Pane myAsset.prShowCookLog = HoudiniGUI.foldout("Asset Cook Log", myAsset.prShowCookLog, true); if (myAsset.prShowCookLog) { drawCookLog(); } } catch (HoudiniError e) { Debug.LogError(e.ToString()); } GUI.enabled = gui_enable; }
// Called after a *successful* cook. virtual public void postCook(HoudiniAsset asset) { Debug.Log(asset.name + " just cooked."); }
private HoudiniAssetAccessor(HoudiniAsset asset) { myAsset = asset; myAssetParms = asset.prParms; }
private HoudiniAssetAccessor( HoudiniAsset asset ) { myAsset = asset; myAssetParms = asset.prParms; }
private void instanceObject(GameObject objToInstantiate, Vector3 pos, Vector3 euler, int point_index, bool scale_exists, Vector3 scale, bool attach_script_exists, string attach_script) { if (objToInstantiate == null) { Debug.LogError("No object to instantiate for instancer '" + this.name + "' and point index " + point_index + "!"); return; } GameObject obj = null; #if UNITY_EDITOR GameObject user_instance = prPersistentData.getUserObjToInstantiateFromName(objToInstantiate.name, point_index); // See if object is a prefab instance. var prefab_parent = PrefabUtility.GetPrefabParent(user_instance) as GameObject; if (prefab_parent != null) { user_instance = prefab_parent; } if (user_instance != null) { obj = PrefabUtility.InstantiatePrefab(user_instance) as GameObject; if (obj == null) { bool liveTransformPropagationSetting = false; bool syncAssetTransformSetting = false; bool enableCooking = true; HoudiniAsset hapi_asset = user_instance.GetComponent <HoudiniAsset>(); if (hapi_asset != null) { liveTransformPropagationSetting = hapi_asset.prTransformChangeTriggersCooks; syncAssetTransformSetting = hapi_asset.prPushUnityTransformToHoudini; enableCooking = hapi_asset.prEnableCooking; hapi_asset.prTransformChangeTriggersCooks = false; hapi_asset.prPushUnityTransformToHoudini = false; hapi_asset.prEnableCooking = false; } obj = Instantiate(user_instance, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; HoudiniAsset hapi_asset_on_clone = obj.GetComponent <HoudiniAsset>(); if (hapi_asset_on_clone != null) { Destroy(hapi_asset_on_clone); } if (hapi_asset != null) { hapi_asset.prTransformChangeTriggersCooks = liveTransformPropagationSetting; hapi_asset.prPushUnityTransformToHoudini = syncAssetTransformSetting; hapi_asset.prEnableCooking = enableCooking; } } HoudiniInstance instance = obj.AddComponent <HoudiniInstance>(); instance.prInstancePointNumber = point_index; instance.prObjectToInstantiate = user_instance; instance.prInstancer = this; obj.transform.localPosition = pos; // Rotation order is important here. Bug: #63304 Quaternion user_angle_rot = user_instance.transform.localRotation; Quaternion offset_rot = Quaternion.Euler(prPersistentData.rotationalOffset); Quaternion instance_rot = Quaternion.Euler(euler); obj.transform.localRotation = instance_rot * offset_rot * user_angle_rot; if (scale_exists) { obj.transform.localScale = new Vector3( prPersistentData.scaleOffset.x * user_instance.transform.localScale.x * scale.x, prPersistentData.scaleOffset.y * user_instance.transform.localScale.y * scale.y, prPersistentData.scaleOffset.z * user_instance.transform.localScale.z * scale.z); } else { obj.transform.localScale = new Vector3( prPersistentData.scaleOffset.x * user_instance.transform.localScale.x, prPersistentData.scaleOffset.y * user_instance.transform.localScale.y, prPersistentData.scaleOffset.z * user_instance.transform.localScale.z); } } else #endif // UNITY_EDITOR { obj = Instantiate(objToInstantiate, pos, Quaternion.Euler(euler)) as GameObject; HoudiniInstance instance = obj.AddComponent <HoudiniInstance>(); instance.prInstancePointNumber = point_index; instance.prObjectToInstantiate = objToInstantiate; instance.prInstancer = this; if (scale_exists) { if (Mathf.Approximately(0.0f, scale.x) || Mathf.Approximately(0.0f, scale.y) || Mathf.Approximately(0.0f, scale.z)) { Debug.LogWarning("Instance " + point_index + ": Scale has a zero component!"); } obj.transform.localScale = scale; } // The original object is probably set to be invisible because it just contains // the raw geometry with no transforms applied. We need to set the newly instanced // object's childrens' mesh renderers to be enabled otherwise the instanced // objects will also be invisible. :) MeshCollider[] mesh_colliders = obj.GetComponentsInChildren <MeshCollider>(); foreach (MeshCollider mesh_collider in mesh_colliders) { mesh_collider.enabled = true; } MeshRenderer[] mesh_renderers = obj.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mesh_renderer in mesh_renderers) { mesh_renderer.enabled = true; } } obj.transform.parent = transform; if (attach_script_exists) { HoudiniAssetUtility.attachScript(obj, attach_script); } }
// Transform related connection methods ------------------------------------------------------- public void addAssetAsTransformInput( HoudiniAsset asset, int index ) { if ( prUpStreamTransformAssets[ index ] == asset ) return; prUpStreamTransformAssets[ index ] = asset; HoudiniHost.connectAssetTransform( asset.prAssetId, prAssetId, index ); asset.addDownstreamTransformAsset( this ); }
static void ReplacePrefab() { HoudiniAsset prefab_asset = prPrefabToReplace.GetComponent <HoudiniAsset>(); if (prPrefabToReplace && prefab_asset) { foreach (GameObject obj in GameObject.FindObjectsOfType(typeof(GameObject))) { HoudiniAsset asset = obj.GetComponent <HoudiniAsset>(); GameObject prefab_parent = PrefabUtility.GetPrefabParent(obj) as GameObject; if (asset && PrefabUtility.Equals(prefab_parent, prPrefabToReplace)) { // this is the asset the prefab is being created/changed from if (asset.prAssetId == prefab_asset.prAssetId) { // If the prefab's backup id refers to a valid asset then this signifies the // prefab is being changed due to an "Apply" from a prefab instance. We need // to delete the prefab asset since we are re-creating the prefab. bool is_applying_changes = HoudiniHost.isAssetValid( prefab_asset.prBackupAssetId, prefab_asset.prBackupAssetValidationId); if (is_applying_changes) { try { HoudiniHost.destroyAsset(prefab_asset.prBackupAssetId); } catch (HoudiniError error) { Debug.LogError("Asset failed to unload: " + error.ToString()); } prefab_asset.reset(); prefab_asset.prParms.reset(); } // replace prefab with original asset with all children game objects removed HoudiniControl.destroyChildren(asset.transform); GameObject new_prefab = PrefabUtility.ReplacePrefab(asset.gameObject, prPrefabToReplace, ReplacePrefabOptions.ConnectToPrefab) as GameObject; HoudiniAsset new_prefab_asset = new_prefab.GetComponent <HoudiniAsset>(); // If applying changes to prefab from prefab instance we also need to retrieve // all the overriden parameters on the prefab instance so that we can apply // these changes properly to all the other instances. This must be done after // prefab has been replaced. if (is_applying_changes) { foreach (HAPI_ParmInfo parm_info in asset.prParms.prParms) { if (asset.prParms.isParmOverridden(parm_info.id)) { new_prefab_asset.prUpdatePrefabInstanceParmNames.Add(parm_info.name); } } } // Set asset id of prefab to -1 since it has not been built yet. // Call SetDirty so changes to prefab will be saved to disk and // OnEnable will be called on original asset so that it can be // rebuilt in order to re-create its game objects. new_prefab_asset.prAssetId = -1; new_prefab_asset.prAssetValidationId = -1; EditorUtility.SetDirty(new_prefab_asset); break; } } } } }
public void removeAssetAsTransformInput( HoudiniAsset asset ) { for ( int ii = 0; ii < prUpStreamTransformAssets.Count; ++ii ) { if ( prUpStreamTransformAssets[ii] == asset ) { prUpStreamTransformAssets[ ii ] = null; HoudiniHost.disconnectAssetTransform( prAssetId, ii ); asset.removeDownstreamTransformAsset( this ); } } }
public override void OnInspectorGUI() { bool gui_enable = GUI.enabled; // We can only build or do anything if we can link to our libraries. #if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_METRO && UNITY_EDITOR)) HoudiniGUI.help(HoudiniConstants.HAPI_UNSUPPORTED_PLATFORM_MSG, MessageType.Info); GUI.enabled = false; #else if (!HoudiniHost.isInstallationOk()) { HoudiniGUI.help(HoudiniHost.getMissingEngineInstallHelpString(), MessageType.Info); GUI.enabled = false; } #endif // !( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) ) try { myDelayBuild = false; myParmChanges = false; /////////////////////////////////////////////////////////////////////// // Draw Game Object Controls if (HoudiniHost.isAssetValid(myAsset.prAssetId, myAsset.prAssetValidationId) && (myAsset.prTransformInputCount > 0 || myAsset.prGeoInputCount > 0) && myAsset.prAssetSubType != HAPI_AssetSubType.HAPI_ASSETSUBTYPE_CURVE && !myAsset.isPrefab()) { myAsset.prShowInputControls = HoudiniGUI.foldout("Inputs", myAsset.prShowInputControls, true); if (myAsset.prShowInputControls) { if (myAsset.prHAPIAssetType == HAPI_AssetType.HAPI_ASSETTYPE_OBJ) { for (int ii = 0; ii < myAsset.prTransformInputCount; ++ii) { myParmChanges |= setTransformInput(ii); } } if (myAsset.prUpStreamGeoObjects == null || myAsset.prUpStreamGeoAssets == null || myAsset.prUpStreamGeoObjects.Count <= 0 || myAsset.prUpStreamGeoAssets.Count <= 0) { return; } for (int input_index = 0; input_index < myAsset.prGeoInputCount; ++input_index) { bool join_last = false; bool no_label_toggle_last = true; HoudiniGUIParm geo_input = new HoudiniGUIParm( "geo_input_" + input_index, myAsset.prGeoInputNames[input_index]); Object obj = (Object)myAsset.prUpStreamGeoObjects[input_index]; myParmChanges |= HoudiniGUI.objectField( ref geo_input, ref obj, typeof(GameObject), ref join_last, ref no_label_toggle_last); if (myParmChanges || !myAsset.isGeoInputValid(input_index)) { if (!obj) { myAsset.removeGeoInput(input_index); myAsset.buildClientSide(); } else { GameObject new_obj = (GameObject)obj; myAsset.prUpStreamGeoObjects[input_index] = new_obj; // Select the asset component (if it exists). HoudiniAsset asset = new_obj.GetComponent <HoudiniAsset>(); // If we're selecting a specific object to input than try and // get the object id. Note that by getting the HAPI_ObjectControl // component we also cover the geo and part controls because // they all inherit from HAPI_ObjectControl. The user can therefore // drag any gameObject under the asset into another asset's // input and have it all work. int object_index = 0; HoudiniObjectControl obj_control = new_obj.GetComponent <HoudiniObjectControl>(); if (obj_control) { object_index = obj_control.prObjectId; asset = obj_control.prAsset; } if (asset == null) { myAsset.addGeoAsGeoInput(new_obj, input_index); myAsset.buildClientSide(); } else if (myAsset.prUpStreamGeoAssets[input_index] != asset) { if (myAsset == asset) { Debug.LogError("Can't connect an asset to itself!"); } else { myAsset.addAssetAsGeoInput(asset, object_index, input_index); myAsset.buildClientSide(); } } } } } // for } // if } // if // Draw Cook Log Pane myAsset.prShowCookLog = HoudiniGUI.foldout("Asset Cook Log", myAsset.prShowCookLog, true); if (myAsset.prShowCookLog) { drawCookLog(); } } catch (HoudiniError e) { Debug.LogError(e.ToString()); } GUI.enabled = gui_enable; }
public int getAssetTransformConnectionIndex( HoudiniAsset asset ) { for ( int ii = 0; ii < prUpStreamTransformAssets.Count; ii++ ) if ( prUpStreamTransformAssets[ii] == asset ) return ii; return -1; }
public void getParameterValues() { if (prControl == null) { return; } if (prControl.prAsset == null) { return; } if (prControl.prAssetId < 0) { return; } if (myPostSerialization) { myValuesEqualToHoudini = areValuesEqualToHoudini(); } else { myValuesEqualToHoudini = true; } // Create undo info if it hasn't been created already if (myParmsUndoInfo == null) { myParmsUndoInfo = ScriptableObject.CreateInstance <HoudiniParmsUndoInfo>(); } // Get the node info again HAPI_NodeInfo node_info = HoudiniHost.getNodeInfo(prControl.prNodeId); prParmCount = node_info.parmCount; prParmIntValueCount = node_info.parmIntValueCount; prParmFloatValueCount = node_info.parmFloatValueCount; prParmStringValueCount = node_info.parmStringValueCount; prParmChoiceCount = node_info.parmChoiceCount; // Get all parameters. prParms = new HAPI_ParmInfo[prParmCount]; HoudiniAssetUtility.getArray1Id(prControl.prNodeId, HoudiniHost.getParameters, prParms, prParmCount); // Get parameter int values. prParmIntValues = new int[prParmIntValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmIntValues, prParmIntValues, prParmIntValueCount); myParmsUndoInfo.parmIntValues = new int[prParmIntValueCount]; Array.Copy(prParmIntValues, myParmsUndoInfo.parmIntValues, prParmIntValueCount); // Get parameter float values. prParmFloatValues = new float[prParmFloatValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmFloatValues, prParmFloatValues, prParmFloatValueCount); myParmsUndoInfo.parmFloatValues = new float[prParmFloatValueCount]; Array.Copy(prParmFloatValues, myParmsUndoInfo.parmFloatValues, prParmFloatValueCount); // Get parameter string (handle) values. prParmStringValues = new int[prParmStringValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmStringValues, prParmStringValues, prParmStringValueCount); // Get parameter choice lists. prParmChoiceLists = new HAPI_ParmChoiceInfo[prParmChoiceCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmChoiceLists, prParmChoiceLists, prParmChoiceCount); // Build the map of parm id -> parm for (int i = 0; i < prParms.Length; ++i) { myParmMap[prParms[i].id] = prParms[i]; } cacheStringsFromHost(); // Go through parameters and set index map and multiparm map for undo info myParmsUndoInfo.parmNames.Clear(); myParmsUndoInfo.parmIndices.Clear(); foreach (HAPI_ParmInfo parm in prParms) { // Need to check the index values are greater or equal to 0 // for now because there is a bug where some parameters are // being set to have an integer parameter type, a size of // zero, and an index value of -1 if (parm.isInt() && parm.intValuesIndex >= 0) { myParmsUndoInfo.parmIndices.Add(parm.intValuesIndex); } else if (parm.isFloat() && parm.floatValuesIndex >= 0) { myParmsUndoInfo.parmIndices.Add(parm.floatValuesIndex); } else if (parm.isString() && parm.stringValuesIndex >= 0) { myParmsUndoInfo.parmIndices.Add(parm.stringValuesIndex); } else { continue; } myParmsUndoInfo.parmNames.Add(parm.name); } #if UNITY_EDITOR // Set which parameter values have been overridden (only needed for a prefab instance) if (prControl && prControl.isPrefabInstance() && gameObject.GetComponent <HoudiniAsset>() != null) { HoudiniAsset prefab_asset = prControl.prAsset.getParentPrefabAsset(); if (prefab_asset && prefab_asset.prParms != null && prefab_asset.prParms.prParms != null && !prefab_asset.isApplyingChangesToPrefab()) { // loop through parameter values and determine which ones have been // overridden (ie. changed from corresponding parameter value on prefab) for (int i = 0; i < prParms.Length; ++i) { myOverriddenParmsMap[prParms[i].id] = !isParmSameInPrefab(prParms[i].id, prefab_asset.prParms); } } // This tells Unity that parameter values have been overridden for this prefab instance PrefabUtility.RecordPrefabInstancePropertyModifications(this); } #endif // UNITY_EDITOR }
public void removeDownstreamTransformAsset( HoudiniAsset asset ) { prDownStreamTransformAssets.Remove( asset ); }