Example #1
0
		/// <summary>
		/// Destroy all data.
		/// </summary>
		public void DestroyAllData()
		{
			if(_geoNodes != null)
			{
				for(int i = 0; i < _geoNodes.Count; ++i)
				{
					_geoNodes[i].DestroyAllData();
					HEU_GeneralUtility.DestroyImmediate(_geoNodes[i]);
				}
				_geoNodes.Clear();
			}
		}
		private bool LoadLayerFloatFromAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_NodeId partID, string attrName, ref float floatValue)
		{
			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			float[] attrValues = new float[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, attrName, ref attrInfo, ref attrValues, session.GetAttributeFloatData);
			if (attrValues != null && attrValues.Length > 0)
			{
				floatValue = attrValues[0];
				return true;
			}
			return false;
		}
		private bool LoadLayerTextureFromAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_NodeId partID, string attrName, out Texture2D outTexture)
		{
			outTexture = null;
			// The texture path is stored as string primitive attribute. Only 1 string path per layer.
			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			string[] texturePath = HEU_GeneralUtility.GetAttributeStringData(session, geoID, partID, attrName, ref attrInfo);
			if (texturePath != null && texturePath.Length > 0 && !string.IsNullOrEmpty(texturePath[0]))
			{
				outTexture = LoadAssetTexture(texturePath[0]);
			}
			return outTexture != null;
		}
		public static void DestroyGeneratedOutputData(HEU_GeneratedOutputData generatedOutputData, bool bDontDeletePersistantResources)
		{
			ClearGeneratedMaterialReferences(generatedOutputData);

			// Colliders
			HEU_GeneratedOutput.DestroyAllGeneratedColliders(generatedOutputData);

			// Components
			HEU_GeneralUtility.DestroyGeneratedMeshMaterialsLODGroups(generatedOutputData._gameObject, bDontDeletePersistantResources);

			// Gameobject
			HEU_GeneralUtility.DestroyImmediate(generatedOutputData._gameObject);
		}
Example #5
0
	private void SetupUIElements()
	{
	    if (_helpGridBoxStyle == null)
	    {
		_helpGridBoxStyle = new GUIStyle(GUI.skin.box);
		Color bgColor = HEU_EditorUI.IsEditorDarkSkin() ? new Color(0.8f, 0.8f, 0.8f, 0.2f) : new Color(0.6f, 0.6f, 0.6f, 0.6f);
		_helpGridBoxStyle.normal.background = HEU_GeneralUtility.MakeTexture(1, 1, bgColor);
		_helpGridBoxStyle.normal.textColor = HEU_EditorUI.IsEditorDarkSkin() ? Color.white : Color.black;
		_helpGridBoxStyle.fontStyle = FontStyle.Normal;
		_helpGridBoxStyle.fontSize = 11;
		_helpGridBoxStyle.alignment = TextAnchor.MiddleLeft;
	    }
	}
		public static string GetTerrainDataExportPathFromHeightfieldAttribute(HEU_SessionBase session, HAPI_NodeId geoID, 
			HAPI_PartId partID)
		{
			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			string[] attrValue = HEU_GeneralUtility.GetAttributeStringData(session, geoID, partID, 
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TERRAINDATA_EXPORT_PATH,
				ref attrInfo);
			if (attrInfo.exists && attrValue.Length > 0 && string.IsNullOrEmpty(attrValue[0]))
			{
				return attrValue[0];
			}
			return "";
		}
        /// <summary>
        /// Set attribute-based modifiers such as tag, layer, and scripts on
        /// the part outputs.
        /// </summary>
        /// <param name="session"></param>
        internal void SetAttributeModifiersOnPartOutputs(HEU_SessionBase session)
        {
            int numParts = _parts.Count;

            for (int i = 0; i < numParts; ++i)
            {
                if (_parts[i].OutputGameObject != null)
                {
                    HEU_GeneralUtility.AssignUnityTag(session, GeoID, _parts[i].PartID, _parts[i].OutputGameObject);
                    HEU_GeneralUtility.AssignUnityLayer(session, GeoID, _parts[i].PartID, _parts[i].OutputGameObject);
                    HEU_GeneralUtility.MakeStaticIfHasAttribute(session, GeoID, _parts[i].PartID, _parts[i].OutputGameObject);
                }
            }
        }
Example #8
0
		public static void DestroyBakedGameObjectsWithEndName(List<GameObject> gameObjectsToDestroy, string endName)
		{
			int numLeft = gameObjectsToDestroy.Count;
			for (int i = 0; i < numLeft; ++i)
			{
				GameObject deleteGO = gameObjectsToDestroy[i];
				if (string.IsNullOrEmpty(endName) || deleteGO.name.EndsWith(endName))
				{
					gameObjectsToDestroy[i] = null;
					HEU_PartData.DestroyExistingGeneratedComponentsMeshData(deleteGO, true);
					HEU_GeneralUtility.DestroyImmediate(deleteGO);
				}
			}
		}
	public static void ClearTOPNodeWorkItemResults(HEU_TOPNodeData topNode)
	{
	    int numResults = topNode._workResults.Count;
	    for (int i = 0; i < numResults; ++i)
	    {
		DestroyWorkItemResultData(topNode, topNode._workResults[i]);
	    }
	    topNode._workResults.Clear();

	    if (topNode._workResultParentGO != null)
	    {
		HEU_GeneralUtility.DestroyImmediate(topNode._workResultParentGO);
	    }
	}
Example #10
0
		private void LoadLayerVector2FromAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_NodeId partID, string attrName, ref Vector2 vectorValue)
		{
			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			float[] attrValues = new float[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, attrName, ref attrInfo, ref attrValues, session.GetAttributeFloatData);
			if (attrValues != null && attrValues.Length == 2)
			{
				if (attrInfo.tupleSize == 2)
				{
					vectorValue[0] = attrValues[0];
					vectorValue[1] = attrValues[1];
				}
			}
		}
		public static void DestroyGeneratedOutputChildren(HEU_GeneratedOutput generatedOutput)
		{
			// LOD Group component
			HEU_GeneralUtility.DestroyComponent<LODGroup>(generatedOutput._outputData._gameObject);

			int numChildren = generatedOutput._childOutputs != null ? generatedOutput._childOutputs.Count : 0;
			for (int i = 0; i < numChildren; ++i)
			{
				if (generatedOutput._childOutputs[i] != null && generatedOutput._childOutputs[i]._gameObject != null)
				{
					DestroyGeneratedOutputData(generatedOutput._childOutputs[i], true);
				}
			}
			generatedOutput._childOutputs.Clear();
		}
		/// <summary>
		/// Given relative path to an asset (with Assets/ in the path), this returns the full path to it.
		/// </summary>
		/// <param name="inAssetRelativePath">Relative path to parse</param>
		/// <returns>Returns full path to asset, or null if invalid input path</returns>
		public static string GetAssetFullPath(string inAssetRelativePath)
		{
			string replaceOld = GetAssetRelativePathStart();
			string replaceNew = Application.dataPath + HEU_Platform.DirectorySeparatorStr;
			//Debug.LogFormat("Replacing relative {0} with full {1}", inAssetRelativePath, inAssetRelativePath.Replace(replaceOld, replaceNew));
			if (IsPathRelativeToAssets(inAssetRelativePath))
			{
				return HEU_GeneralUtility.ReplaceFirstOccurrence(inAssetRelativePath, replaceOld, replaceNew);
			}
			else
			{
				Debug.LogWarningFormat("Given relative path {0} does not start with {1}. Unable to create full path!", inAssetRelativePath, replaceOld);
				return null;
			}
		}
Example #13
0
	private bool FindAddToInputHDA(string gameObjectName)
	{
	    HEU_HoudiniAssetRoot inputAssetRoot = HEU_GeneralUtility.GetHDAByGameObjectNameInScene(gameObjectName);
	    if (inputAssetRoot != null && inputAssetRoot._houdiniAsset != null)
	    {
		// Adding to list will take care of reconnecting
		InternalAddInputHDAAtEnd(inputAssetRoot.gameObject);
		return true;
	    }
	    else
	    {
		Debug.LogWarningFormat("HDA with gameobject name {0} not found. Unable to set input asset.", gameObjectName);
	    }

	    return false;
	}
		public static void DestroyGeneratedOutput(HEU_GeneratedOutput generatedOutput)
		{
			int numChildren = generatedOutput._childOutputs != null ? generatedOutput._childOutputs.Count : 0;
			for (int i = 0; i < numChildren; ++i)
			{
				if (generatedOutput._childOutputs[i] != null && generatedOutput._childOutputs[i]._gameObject != null)
				{
					HEU_GeneralUtility.DestroyImmediate(generatedOutput._childOutputs[i]._gameObject);
				}
			}
			generatedOutput._childOutputs.Clear();

			HEU_GeneralUtility.DestroyImmediate(generatedOutput._outputData._gameObject);
			generatedOutput._outputData._gameObject = null;
			generatedOutput._outputData._renderMaterials = null;
		}
		/// <summary>
		/// Retrieve and set the detail properties from the specified heightfield.
		/// This includes detail distance, density, and resolution per patch.
		/// </summary>
		/// <param name="session">Current Houdini Engine session</param>
		/// <param name="geoID">Heightfield object</param>
		/// <param name="partID">Heightfield layer</param>
		/// <param name="detailProperties">Reference to a HEU_DetailProperties which will
		/// be populated.</param>
		public static void PopulateDetailProperties(HEU_SessionBase session, HAPI_NodeId geoID,
			HAPI_PartId partID, ref HEU_DetailProperties detailProperties)
		{
			// Detail distance
			HAPI_AttributeInfo detailDistanceAttrInfo = new HAPI_AttributeInfo();
			int[] detailDistances = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID,
				HEU_Defines.HEIGHTFIELD_DETAIL_DISTANCE, ref detailDistanceAttrInfo, ref detailDistances,
				session.GetAttributeIntData);

			// Detail density
			HAPI_AttributeInfo detailDensityAttrInfo = new HAPI_AttributeInfo();
			float[] detailDensity = new float[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID,
				HEU_Defines.HEIGHTFIELD_DETAIL_DENSITY, ref detailDensityAttrInfo, ref detailDensity,
				session.GetAttributeFloatData);

			// Scatter Detail Resolution Per Patch (note that Detail Resolution comes from HF layer size)
			HAPI_AttributeInfo resolutionPatchAttrInfo = new HAPI_AttributeInfo();
			int[] resolutionPatches = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID,
				HEU_Defines.HEIGHTFIELD_DETAIL_RESOLUTION_PER_PATCH, ref resolutionPatchAttrInfo,
				ref resolutionPatches, session.GetAttributeIntData);

			if (detailProperties == null)
			{
				detailProperties = new HEU_DetailProperties();
			}

			// Unity only supports 1 set of detail resolution properties per terrain
			int arraySize = 1;

			if (detailDistanceAttrInfo.exists && detailDistances.Length >= arraySize)
			{
				detailProperties._detailDistance = detailDistances[0];
			}

			if (detailDensityAttrInfo.exists && detailDensity.Length >= arraySize)
			{
				detailProperties._detailDensity = detailDensity[0];
			}

			if (resolutionPatchAttrInfo.exists && resolutionPatches.Length >= arraySize)
			{
				detailProperties._detailResolutionPerPatch = resolutionPatches[0];
			}
		}
	/// <summary>
	/// Returns HEU_UploadMeshData with mesh data found on meshGameObject.
	/// </summary>
	/// <param name="meshGameObject">The GameObject to query mesh data from</param>
	/// <returns>A valid HEU_UploadMeshData if mesh data found or null</returns>
	public static HEU_InputDataMesh CreateSingleMeshData(GameObject meshGameObject)
	{
	    HEU_InputDataMesh meshData = new HEU_InputDataMesh();

	    if (meshGameObject == null)
	    {
		return null;
	    }

	    Mesh sharedMesh = GetMeshFromObject(meshGameObject);

	    if (sharedMesh == null)
	    {
		return null;
	    }

	    meshData._mesh = sharedMesh;
	    meshData._numVertices = meshData._mesh.vertexCount;
	    meshData._numSubMeshes = meshData._mesh.subMeshCount;

	    meshData._meshName = meshGameObject.name;

	    // Use project path is not saved in scene, otherwise just use name
	    if (HEU_GeneralUtility.IsGameObjectInProject(meshGameObject))
	    {
		meshData._meshPath = HEU_AssetDatabase.GetAssetOrScenePath(meshGameObject);
		if (string.IsNullOrEmpty(meshData._meshPath))
		{
		    meshData._meshPath = meshGameObject.name;
		}
	    }
	    else
	    {
		meshData._meshPath = meshGameObject.name;
	    }
	    //Debug.Log("Mesh Path: " + meshData._meshPath);

	    MeshRenderer meshRenderer = meshGameObject.GetComponent<MeshRenderer>();
	    if (meshRenderer != null)
	    {
		meshData._materials = meshRenderer.sharedMaterials;
	    }

	    meshData._transform = meshGameObject.transform;

	    return meshData;
	}
		/// <summary>
		/// Returns list of HEU_TreePrototypeInfo formed by querying data from given part.
		/// </summary>
		/// <param name="session">Houdini Engine session</param>
		/// <param name="geoID">Geometry object</param>
		/// <param name="partID">Part ID</param>
		/// <returns>Returns list of HEU_TreePrototypeInfo or null if none found.</returns>
		public static List<HEU_TreePrototypeInfo> GetTreePrototypeInfosFromPart(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID)
		{
			List<HEU_TreePrototypeInfo> treePrototypes = new List<HEU_TreePrototypeInfo>();

			// Each TreePrototype data is stored as a string attribute, under the 'HEU_Defines.HEIGHTFIELD_TREEPROTOTYPE + index'
			// name. So check and parse until no more valid attributes found.
			int index = 0;
			while (true)
			{
				// Does this attribute exist?
				string attrName = HEU_Defines.HEIGHTFIELD_TREEPROTOTYPE + index.ToString();
				if (!HEU_GeneralUtility.HasAttribute(session, geoID, partID, attrName, HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM))
				{
					break;
				}

				index++;

				// Get the string value
				HAPI_AttributeInfo treeAttrInfo = new HAPI_AttributeInfo();
				string[] protoAttrString = HEU_GeneralUtility.GetAttributeStringData(session, geoID, partID,
					attrName, ref treeAttrInfo);
				if (protoAttrString == null || protoAttrString.Length == 0 || string.IsNullOrEmpty(protoAttrString[0]))
				{
					break;
				}

				// Parse the attribute string value:
				// Only expecting a single element here, comma-separated for the asset path and bend factor:
				// => asset_path,bend_factor
				string[] properties = protoAttrString[0].Split(',');
				if (properties.Length > 0 && !string.IsNullOrEmpty(properties[0]))
				{
					HEU_TreePrototypeInfo prototype = new HEU_TreePrototypeInfo();
					prototype._prefabPath = properties[0];
					if (properties.Length >= 2)
					{
						float.TryParse(properties[1], out prototype._bendfactor);
					}

					treePrototypes.Add(prototype);
				}
			}

			return treePrototypes.Count > 0 ? treePrototypes : null;
		}
        public void SetupUI()
        {
            _backgroundStyle = new GUIStyle(GUI.skin.box);
            RectOffset br = _backgroundStyle.margin;

            br.top    = 10;
            br.bottom = 6;
            br.left   = 4;
            br.right  = 4;
            _backgroundStyle.margin = br;

            _eventMessageStyle          = new GUIStyle(EditorStyles.textArea);
            _eventMessageStyle.richText = true;

            _eventMessageStyle.normal.textColor  = new Color(1f, 1f, 1f, 1f);
            _eventMessageStyle.normal.background = HEU_GeneralUtility.MakeTexture(1, 1, new Color(0, 0, 0, 1f));
        }
Example #19
0
		/// <summary>
		/// Returns the Unity script attribute value, if found, on the specified geo's part.
		/// The attribute must be of string type, and owned by detail.
		/// </summary>
		/// <param name="session">Session that the asset resides in</param>
		/// <param name="geoID">The geo node's ID</param>
		/// <param name="partID">The part's ID</param>
		/// <returns>The name of the Unity script, or null if not found</returns>
		public static string GetUnityScriptAttributeValue(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID)
		{
			HAPI_AttributeInfo scriptAttributeInfo = new HAPI_AttributeInfo();
			int[] scriptAttr = new int[0];
			string scriptString = null;

			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_PluginSettings.UnityScriptAttributeName, ref scriptAttributeInfo, ref scriptAttr, session.GetAttributeStringData);
			if (scriptAttributeInfo.exists)
			{
				if (scriptAttr.Length > 0)
				{
					scriptString = HEU_SessionManager.GetString(scriptAttr[0]);
				}
			}

			return scriptString;
		}
Example #20
0
        //Set string detail attribute
        public static bool SetMeshDetailAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attrName,
                                                  string data, ref HAPI_PartInfo partInfo)
        {
            HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();

            attrInfo.exists        = true;
            attrInfo.owner         = HAPI_AttributeOwner.HAPI_ATTROWNER_DETAIL;
            attrInfo.storage       = HAPI_StorageType.HAPI_STORAGETYPE_STRING;
            attrInfo.count         = 1;
            attrInfo.tupleSize     = 1;
            attrInfo.originalOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_INVALID;

            string[] values = new string[1];
            values[0] = data;

            return(HEU_GeneralUtility.SetAttributeArray(geoID, partID, attrName, ref attrInfo, values, session.SetAttributeStringData, 1));
        }
Example #21
0
        //Set string point attributes
        public static bool SetMeshPointAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attrName, string[] data, ref HAPI_PartInfo partInfo)
        {
            HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
            attrInfo.exists = true;
            attrInfo.owner = HAPI_AttributeOwner.HAPI_ATTROWNER_POINT;
            attrInfo.storage = HAPI_StorageType.HAPI_STORAGETYPE_STRING;
            attrInfo.count = partInfo.pointCount;
            attrInfo.tupleSize = 1;
            attrInfo.originalOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_INVALID;

            if (!session.AddAttribute(geoID, 0, attrName, ref attrInfo))
            {
                Debug.Log("Could not create attribute named: " + attrName);
                return false;
            }
            return HEU_GeneralUtility.SetAttributeArray(geoID, partID, attrName, ref attrInfo, data, session.SetAttributeStringData, partInfo.pointCount);
        }
Example #22
0
		public void DisablePaintCollider()
		{
			if (_localMeshCollider != null && _outputGameObject != null)
			{
				HEU_GeneralUtility.DestroyComponent<MeshCollider>(_outputGameObject);
				_localMeshCollider = null;
			}

			if (_outputCollider != null)
			{
				_outputCollider.sharedMesh = _outputColliderMesh;
				_outputCollider.enabled = _outputMeshColliderInitiallyEnabled;

				_outputCollider = null;
				_outputColliderMesh = null;
			}
		}
        public void DestroyVolumeCache()
        {
            if (_volumeCaches != null)
            {
                int numCaches = _volumeCaches.Count;
                for (int i = 0; i < numCaches; ++i)
                {
                    if (_volumeCaches[i] != null)
                    {
                        ParentAsset.RemoveVolumeCache(_volumeCaches[i]);
                        HEU_GeneralUtility.DestroyImmediate(_volumeCaches[i]);
                        _volumeCaches[i] = null;
                    }
                }

                _volumeCaches = null;
            }
        }
Example #24
0
		private void SetOutputVisiblity(HEU_LoadBufferBase buffer)
		{
			bool bVisibility = !buffer._bInstanced;

			if (HEU_GeneratedOutput.HasLODGroup(buffer._generatedOutput))
			{
				foreach (HEU_GeneratedOutputData childOutput in buffer._generatedOutput._childOutputs)
				{
					HEU_GeneralUtility.SetGameObjectRenderVisiblity(childOutput._gameObject, bVisibility);
					HEU_GeneralUtility.SetGameObjectColliderState(childOutput._gameObject, bVisibility);
				}
			}
			else
			{
				HEU_GeneralUtility.SetGameObjectRenderVisiblity(buffer._generatedOutput._outputData._gameObject, bVisibility);
				HEU_GeneralUtility.SetGameObjectColliderState(buffer._generatedOutput._outputData._gameObject, bVisibility);
			}
		}
		private void GetPartLayerAttributes(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_NodeId partID, HEU_VolumeLayer layer)
		{
			// Get the tile index, if it exists, for this part
			HAPI_AttributeInfo tileAttrInfo = new HAPI_AttributeInfo();
			int[] tileAttrData = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_Defines.HAPI_HEIGHTFIELD_TILE_ATTR, ref tileAttrInfo, ref tileAttrData, session.GetAttributeIntData);
			if (tileAttrData != null && tileAttrData.Length > 0)
			{
				layer._tile = tileAttrData[0];
				//Debug.LogFormat("Tile: {0}", tileAttrData[0]);
			}
			else
			{
				layer._tile = 0;
			}

			layer._hasLayerAttributes = HEU_TerrainUtility.VolumeLayerHasAttributes(session, geoID, partID);
		}
		private void GetPartLayerAttributes(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_NodeId partID, HEU_VolumeLayer layer)
		{
			// Get the tile index, if it exists, for this part
			HAPI_AttributeInfo tileAttrInfo = new HAPI_AttributeInfo();
			int[] tileAttrData = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_Defines.HAPI_HEIGHTFIELD_TILE_ATTR, ref tileAttrInfo, ref tileAttrData, session.GetAttributeIntData);
			if (tileAttrData != null && tileAttrData.Length > 0)
			{
				layer._tile = tileAttrData[0];
				//Debug.LogFormat("Tile: {0}", tileAttrData[0]);
			}
			else
			{
				layer._tile = 0;
			}


			string[] layerAttrNames =
			{
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_DIFFUSE_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_MASK_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_NORMAL_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_NORMAL_SCALE_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_METALLIC_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SMOOTHNESS_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SPECULAR_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_OFFSET_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_SIZE_ATTR
			};

			// Check if any of the layer attribute names show up in the existing primitive attributes
			layer._hasLayerAttributes = false;
			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			bool bResult = false;
			foreach (string layerAttr in layerAttrNames)
			{
				bResult = session.GetAttributeInfo(geoID, partID, layerAttr, HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM, ref attrInfo);
				if (bResult && attrInfo.exists)
				{
					layer._hasLayerAttributes = true;
					break;
				}
			}
		}
Example #27
0
        /// <summary>
        /// Load and instantiate an HDA asset in Unity and Houdini, for the asset located at given path.
        /// </summary>
        /// <param name="filePath">Full path to the HDA in Unity project</param>
        /// <param name="initialPosition">Initial location to create the instance in Unity.</param>
        /// <returns>Returns the newly created gameobject for the asset in the scene, or null if creation failed.</returns>
        public static GameObject InstantiateHDA(string filePath, Vector3 initialPosition, HEU_SessionBase session, bool bBuildAsync)
        {
            if (filePath == null || !HEU_Platform.DoesFileExist(filePath))
            {
                return(null);
            }

            // This will be the root GameObject for the HDA. Adding HEU_HoudiniAssetRoot
            // allows to use a custom Inspector.
            GameObject           rootGO    = new GameObject(HEU_Defines.HEU_DEFAULT_ASSET_NAME);
            HEU_HoudiniAssetRoot assetRoot = rootGO.AddComponent <HEU_HoudiniAssetRoot>();

            // Under the root, we'll add the HEU_HoudiniAsset onto another GameObject
            // This will be marked as EditorOnly to strip out for builds
            GameObject hdaGEO = new GameObject(HEU_PluginSettings.HDAData_Name);

            hdaGEO.transform.parent = rootGO.transform;

            // This holds all Houdini Engine data
            HEU_HoudiniAsset asset = hdaGEO.AddComponent <HEU_HoudiniAsset>();

            // Marking as EditorOnly to be excluded from builds
            if (HEU_GeneralUtility.DoesUnityTagExist(HEU_PluginSettings.EditorOnly_Tag))
            {
                hdaGEO.tag = HEU_PluginSettings.EditorOnly_Tag;
            }

            // Bind the root to the asset
            assetRoot._houdiniAsset = asset;

            // Populate asset with what we know
            asset.SetupAsset(HEU_HoudiniAsset.HEU_AssetType.TYPE_HDA, filePath, rootGO, session);

            // Build it in Houdini Engine
            asset.RequestReload(bBuildAsync);

            // Apply Unity transform and possibly upload to Houdini Engine
            rootGO.transform.position = initialPosition;

            Debug.LogFormat("{0}: Created new HDA asset from {1} of type {2}.", HEU_Defines.HEU_NAME, filePath, asset.AssetType);

            return(rootGO);
        }
Example #28
0
        private void SetupGeoCurveGameObjectAndTransform(HEU_Curve curve)
        {
            if (curve._targetGameObject == null)
            {
                curve._targetGameObject = new GameObject();
            }

            // For geo curve, the parent is the HDA_Data
            Transform curveTransform = curve._targetGameObject.transform;

            curveTransform.parent = ParentAsset.OwnerGameObject.transform;

            HEU_GeneralUtility.CopyFlags(curveTransform.parent.gameObject, curve._targetGameObject, true);

            // Reset to origin
            curveTransform.localPosition = Vector3.zero;
            curveTransform.localRotation = Quaternion.identity;
            curveTransform.localScale    = Vector3.one;
        }
Example #29
0
		public void PopulateInputPreset(HEU_InputPreset inputPreset)
		{
			inputPreset._inputObjectType = _inputObjectType;

			inputPreset._inputAssetName = _inputAsset != null ? _inputAsset.name : "";

			inputPreset._inputIndex = _inputIndex;
			inputPreset._inputName = _inputName;

			inputPreset._keepWorldTransform = _keepWorldTransform;
			inputPreset._packGeometryBeforeMerging = _packGeometryBeforeMerging;

			foreach (HEU_InputObjectInfo inputObject in _inputObjects)
			{
				HEU_InputObjectPreset inputObjectPreset = new HEU_InputObjectPreset();

				if (inputObject._gameObject != null)
				{
					inputObjectPreset._gameObjectName = inputObject._gameObject.name;

					// Tag whether scene or project input object
					inputObjectPreset._isSceneObject = !HEU_GeneralUtility.IsGameObjectInProject(inputObject._gameObject);
					if (!inputObjectPreset._isSceneObject)
					{
						// For inputs in project, use the project path as name
						inputObjectPreset._gameObjectName = HEU_AssetDatabase.GetAssetOrScenePath(inputObject._gameObject);
					}
				}
				else
				{
					inputObjectPreset._gameObjectName = "";
				}

				inputObjectPreset._useTransformOffset = inputObject._useTransformOffset;
				inputObjectPreset._translateOffset = inputObject._translateOffset;
				inputObjectPreset._rotateOffset = inputObject._rotateOffset;
				inputObjectPreset._scaleOffset = inputObject._scaleOffset;

				inputPreset._inputObjectPresets.Add(inputObjectPreset);
			}

		}
        /// <summary>
        /// Process custom attribute with Unity script name, and attach any scripts found.
        /// </summary>
        /// <param name="session">Session to use</param>
        public void ProcessUnityScriptAttribute(HEU_SessionBase session)
        {
            if (_parts == null || _parts.Count == 0)
            {
                return;
            }

            foreach (HEU_PartData part in _parts)
            {
                GameObject outputGO = part.OutputGameObject;
                if (outputGO != null)
                {
                    string scriptValue = HEU_GeneralUtility.GetUnityScriptAttributeValue(session, GeoID, part.PartID);
                    if (!string.IsNullOrEmpty(scriptValue))
                    {
                        HEU_GeneralUtility.AttachScriptWithInvokeFunction(scriptValue, outputGO);
                    }
                }
            }
        }