public void PopulateDetailPrototype(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID,
			HEU_VolumeLayer layer)
		{
			HEU_TerrainUtility.PopulateDetailPrototype(session, geoID, partID, ref layer._detailPrototype);
		}
		public virtual bool GetHeightFieldData(HAPI_NodeId nodeID, HAPI_PartId partID, float[] valuesArray, int start, int length)
		{
			return false;
		}
		public virtual bool SetVolumeTileFloatData(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_VolumeTileInfo tileInfo, float[] valuesArray, int length)
		{
			valuesArray = new float[0];
			return false;
		}
示例#4
0
		public virtual bool AddGroup(HAPI_NodeId nodeID, HAPI_PartId partID, HAPI_GroupType groupType, string groupName)
		{
			return false;
		}
		// MATERIALS --------------------------------------------------------------------------------------------------

		/// <summary>
		/// Get the Material on the specified Part
		/// </summary>
		/// <param name="nodeID">The node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="materialInfo">A valid material info to populate</param>
		/// <returns>True if successfully queried the material info</returns>
		public virtual bool GetMaterialOnPart(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_MaterialInfo materialInfo)
		{
			return false;
		}
示例#6
0
		public virtual bool SetFaceCount(HAPI_NodeId nodeID, HAPI_PartId partID, int[] faceCounts, int start, int length)
		{
			return false;
		}
示例#7
0
		public virtual bool SetAttributeStringData(HAPI_NodeId nodeID, HAPI_PartId partID, string name, ref HAPI_AttributeInfo attrInfo,
			string[] data, int start, int length)
		{
			return false;
		}
示例#8
0
		/// <summary>
		/// Get the main geometry info struct.
		/// </summary>
		/// <param name="nodeID">The SOP node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="name">Attribute name</param>
		/// <param name="owner">Attribute owner</param>
		/// <param name="attributeInfo">Info to populate</param>
		/// <returns>True if successfully queried the attribute info</returns>
		public virtual bool GetAttributeInfo(HAPI_NodeId nodeID, HAPI_PartId partID, string name, HAPI_AttributeOwner owner, ref HAPI_AttributeInfo attributeInfo)
		{
			return false;
		}
示例#9
0
		/// <summary>
		/// Get the attribute names of all attributes having owner of the given part.
		/// </summary>
		/// <param name="nodeID">The SOP node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="owner">Attributes must have this owner type</param>
		/// <param name="attributeNames">Result array of name strings. Must be atleast count size.</param>
		/// <param name="count">Expected number of attributes. Should be from HAPI_PartInfo.attributeCounts[owner].</param>
		/// <returns>True if successfully retrieved the names</returns>
		public virtual bool GetAttributeNames(HAPI_NodeId nodeID, HAPI_PartId partID, HAPI_AttributeOwner owner, ref string[] attributeNames, int count)
		{
			return false;
		}
	public static HEU_MaterialData CreateHoudiniMaterialData(HEU_SessionBase session, HAPI_NodeId assetID, HAPI_NodeId materialID, HAPI_NodeId geoID, HAPI_PartId partID, List<HEU_MaterialData> materialCache, string assetCacheFolderPath)
	{
	    string materialName = "";

	    if (materialID == HEU_Defines.HEU_INVALID_NODE_ID)
	    {
		return GetOrCreateDefaultMaterialInCache(session, geoID, partID, false, materialCache, assetCacheFolderPath);
	    }
	    else
	    {
		materialName = HEU_SessionManager.GetUniqueMaterialShopName(assetID, materialID);
	    }

	    HEU_MaterialData materialData = ScriptableObject.CreateInstance<HEU_MaterialData>();
	    materialData._materialSource = HEU_MaterialData.Source.HOUDINI;
	    materialData._materialKey = materialID;

	    materialData._material = HEU_MaterialFactory.CreateNewHoudiniStandardMaterial(assetCacheFolderPath, materialName, true);
	    materialData._material.name = materialName;

	    //HEU_Logger.LogFormat("New Material ID: {0} - {1}", materialID, materialName);

	    if (materialID != HEU_Defines.HEU_INVALID_NODE_ID)
	    {
		// Get material info from Houdini to populate the Unity material values

		HAPI_MaterialInfo materialInfo = new HAPI_MaterialInfo();
		if (session.GetMaterialInfo(materialID, ref materialInfo))
		{
		    if (materialInfo.exists)
		    {
			materialData.UpdateMaterialFromHoudini(materialInfo, assetCacheFolderPath);
		    }
		}
	    }

	    //HEU_Logger.LogFormat("Created new material with id={0} and name={1}", materialID, materialName);

	    materialCache.Add(materialData);
	    return materialData;
	}
示例#11
0
		private float[] GetHeightfield(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string partName, int terrainSize)
		{
			HAPI_VolumeInfo volumeInfo = new HAPI_VolumeInfo();
			bool bResult = session.GetVolumeInfo(geoID, partID, ref volumeInfo);
			if (!bResult)
			{
				return null;
			}

			int volumeXLength = volumeInfo.xLength;
			int volumeYLength = volumeInfo.yLength;

			// Number of heightfield values
			int totalHeightValues = volumeXLength * volumeYLength;

			float[] heightValues = new float[totalHeightValues];
			bResult = HEU_GeneralUtility.GetArray2Arg(geoID, partID, session.GetHeightFieldData, heightValues, 0, totalHeightValues);
			if (!bResult)
			{
				Debug.LogErrorFormat("Unable to get heightfield data from part {0}", partName);
				return null;
			}

			float minHeight = heightValues[0];
			float maxHeight = minHeight;
			for (int i = 0; i < totalHeightValues; ++i)
			{
				float f = heightValues[i];
				if (f > maxHeight)
				{
					maxHeight = f;
				}
				else if (f < minHeight)
				{
					minHeight = f;
				}
			}

			float heightRange = (maxHeight - minHeight);
			if(heightRange == 0f)
			{
				heightRange = 1f;
			}
			//Debug.LogFormat("{0} : {1}", HEU_SessionManager.GetString(volumeInfo.nameSH, session), heightRange);

			// Remap height values to fit terrain size
			int paddingWidth = terrainSize - volumeXLength;
			int paddingLeft = Mathf.CeilToInt(paddingWidth * 0.5f);
			int paddingRight = terrainSize - paddingLeft;
			//Debug.LogFormat("Padding: Width={0}, Left={1}, Right={2}", paddingWidth, paddingLeft, paddingRight);

			int paddingHeight = terrainSize - volumeYLength;
			int paddingTop = Mathf.CeilToInt(paddingHeight * 0.5f);
			int paddingBottom = terrainSize - paddingTop;
			//Debug.LogFormat("Padding: Height={0}, Top={1}, Bottom={2}", paddingHeight, paddingTop, paddingBottom);

			// Set height values at centre of the terrain, with padding on the sides if we resized
			float[] resizedHeightValues = new float[terrainSize * terrainSize];
			for (int y = 0; y < terrainSize; ++y)
			{
				for (int x = 0; x < terrainSize; ++x)
				{
					if (y >= paddingTop && y < (paddingBottom) && x >= paddingLeft && x < (paddingRight))
					{
						int ay = x - paddingLeft;
						int ax = y - paddingTop;

						float f = heightValues[ay + ax * volumeXLength] - minHeight;
						f /= heightRange;

						// Flip for right-hand to left-handed coordinate system
						int ix = x;
						int iy = terrainSize - (y + 1);

						// Unity expects height array indexing to be [y, x].
						resizedHeightValues[iy + ix * terrainSize] = f;
					}
				}
			}

			return resizedHeightValues;
		}
	public static string GenerateDefaultMaterialName(HAPI_NodeId geoID, HAPI_PartId partID)
	{
	    return string.Format("{0}_{1}_{2}", HEU_Defines.DEFAULT_MATERIAL, geoID, partID);
	}
	public static HEU_MaterialData GetOrCreateDefaultMaterialInCache(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, bool bWriteToFile, List<HEU_MaterialData> materialCache,
		string assetCacheFolderPath)
	{
	    string materialName = GenerateDefaultMaterialName(geoID, partID);
	    int materialKey = HEU_MaterialFactory.MaterialNameToKey(materialName);
	    HEU_MaterialData materialData = GetMaterialDataFromCache(materialKey, materialCache);
	    if (materialData == null)
	    {
		materialData = CreateMaterialInCache(materialKey, materialName, HEU_MaterialData.Source.DEFAULT, bWriteToFile, materialCache, assetCacheFolderPath);
	    }
	    return materialData;
	}
		public void LoadLayerPropertiesFromAttributes(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, TerrainLayer terrainLayer,
			bool bNewTerrainLayer, Texture2D defaultTexture)
		{
			Texture2D diffuseTexture = null;
			if (LoadLayerTextureFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_DIFFUSE_ATTR, out diffuseTexture))
			{
				terrainLayer.diffuseTexture = diffuseTexture;
			}

			if (terrainLayer.diffuseTexture == null && bNewTerrainLayer)
			{
				// Applying default texture if this layer was created newly and no texture was specified.
				// Unity always seems to require a default texture when creating a new layer normally.
				terrainLayer.diffuseTexture = defaultTexture;
			}

			Texture2D maskTexture = null;
			if (LoadLayerTextureFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_MASK_ATTR, out maskTexture))
			{
				terrainLayer.maskMapTexture = maskTexture;
			}

			Texture2D normalTexture = null;
			if (LoadLayerTextureFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_NORMAL_ATTR, out normalTexture))
			{
				terrainLayer.normalMapTexture = normalTexture;
			}

			float normalScale = 0f;
			if (LoadLayerFloatFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_NORMAL_SCALE_ATTR, ref normalScale))
			{
				terrainLayer.normalScale = normalScale;
			}

			float metallic = 0f;
			if (LoadLayerFloatFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_METALLIC_ATTR, ref metallic))
			{
				terrainLayer.metallic = metallic;
			}

			float smoothness = 0f;
			if (LoadLayerFloatFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SMOOTHNESS_ATTR, ref smoothness))
			{
				terrainLayer.smoothness = smoothness;
			}

			Color specularColor = new Color();
			if (LoadLayerColorFromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SPECULAR_ATTR, ref specularColor))
			{
				terrainLayer.specular = specularColor;
			}

			Vector2 tileOffset = new Vector2();
			if (LoadLayerVector2FromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_OFFSET_ATTR, ref tileOffset))
			{
				terrainLayer.tileOffset = tileOffset;
			}

			Vector2 tileSize = new Vector2();
			if (LoadLayerVector2FromAttribute(session, geoID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_SIZE_ATTR, ref tileSize))
			{
				terrainLayer.tileSize = tileSize;
			}

			if (terrainLayer.tileSize.magnitude == 0f)
			{
				// Use texture size if tile size is 0
				terrainLayer.tileSize = new Vector2(terrainLayer.diffuseTexture.width, terrainLayer.diffuseTexture.height);
			}
		}
示例#15
0
		public virtual bool GetCurveCounts(HAPI_NodeId nodeID, HAPI_PartId partID, [Out] int[] counts, int start, int length)
		{
			return false;
		}
示例#16
0
		/// <summary>
		/// Get the attribute string data.
		/// </summary>
		/// <param name="nodeID">The node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="name">Attribute name</param>
		/// <param name="attributeInfo">Atttribute info</param>
		/// <param name="dataArray">Array to populate. Must be at least the size of length * HAPI_AttributeInfo::tupleSize</param>
		/// <param name="start">First index of range. Must be at least 0 and at most HAPI_AttributeInfo::count - 1</param>
		/// <param name="length">Must be at least 0 and at most HAPI_AttributeInfo::count - start</param>
		/// <returns>True if successfully queried the atttribute string data</returns>
		public virtual bool GetAttributeStringData(HAPI_NodeId nodeID, HAPI_PartId partID, string name, ref HAPI_AttributeInfo attributeInfo, [Out] HAPI_StringHandle[] dataArray, int start, int length)
		{
			return false;
		}
示例#17
0
		// GEOMETRY SETTERS -------------------------------------------------------------------------------------------

		public virtual bool SetPartInfo(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_PartInfo partInfo)
		{
			return false;
		}
示例#18
0
		/// <summary>
		/// Get the attribute float data.
		/// </summary>
		/// <param name="nodeID">The node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="name">Attribut ename</param>
		/// <param name="attributeInfo">Should be same struct returned by HAPI_GetAttributeInfo</param>
		/// <param name="data">A float array at least the size of length * HAPI_AttributeInfo::tupleSize</param>
		/// <param name="start">First index of range. Must be at least 0 and at most HAPI_AttributeInfo::count - 1</param>
		/// <param name="length">Must be at least 0 and at most HAPI_AttributeInfo::count - start.</param>
		/// <returns>True if successfully queried the atttribute float data</returns>
		public virtual bool GetAttributeFloatData(HAPI_NodeId nodeID, HAPI_PartId partID, string name, ref HAPI_AttributeInfo attributeInfo, [Out] float[] data, int start, int length)
		{
			return false;
		}
示例#19
0
		public virtual bool SetVertexList(HAPI_NodeId nodeID, HAPI_PartId partID, int[] vertexList, int start, int length)
		{
			return false;
		}
示例#20
0
		public virtual bool GetInstancedPartIds(HAPI_NodeId nodeID, HAPI_PartId partID, [Out] HAPI_PartId[] instancedPartsArray, int start, int length)
		{
			return false;
		}
示例#21
0
		public virtual bool AddAttribute(HAPI_NodeId nodeID, HAPI_PartId partID, string name, ref HAPI_AttributeInfo attrInfo)
		{
			return false;
		}
示例#22
0
		public virtual bool GetInstancerPartTransforms(HAPI_NodeId nodeID, HAPI_PartId partID, HAPI_RSTOrder rstOrder, [Out] HAPI_Transform[] transformsArray, int start, int length)
		{
			return false;
		}
示例#23
0
		public virtual bool SetGroupMembership(HAPI_NodeId nodeID, HAPI_PartId partID, HAPI_GroupType groupType, string groupName, [Out] int[] membershipArray, int start, int length)
		{
			return false;
		}
示例#24
0
		/// <summary>
		/// Get the box info on a geo part.
		/// </summary>
		/// <param name="nodeID">The geo node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="boxInfo">The info to fill</param>
		/// <returns>True if successfully queried the box info</returns>
		public virtual bool GetBoxInfo(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_BoxInfo boxInfo)
		{
			return false;
		}
		/// <summary>
		/// Get the material node IDs on faces for specified part.
		/// </summary>
		/// <param name="nodeID">The node ID</param>
		/// <param name="partID">The part to query</param>
		/// <param name="bSingleFaceMaterial">Whether same material on all faces</param>
		/// <param name="materialNodeIDs">The array to fill in with material node IDs. Must be at least size of faceCount</param>
		/// <param name="faceCount">Number of material IDs to query</param>
		/// <returns>True if successfully queried the materials</returns>
		public virtual bool GetMaterialNodeIDsOnFaces(HAPI_NodeId nodeID, HAPI_PartId partID, ref bool bSingleFaceMaterial, [Out] HAPI_NodeId[] materialNodeIDs, int faceCount)
		{
			return false;
		}
示例#26
0
		/// <summary>
		/// Get the sphere info on a geo part.
		/// </summary>
		/// <param name="nodeID">The geo node ID</param>
		/// <param name="partID">The part ID</param>
		/// <param name="sphereInfo">The info to fill</param>
		/// <returns>True if successfully queried the sphere info</returns>
		public virtual bool GetSphereInfo(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_SphereInfo sphereInfo)
		{
			return false;
		}
		public virtual bool SetVolumeInfo(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_VolumeInfo volumeInfo)
		{
			return false;
		}
示例#28
0
		public virtual bool GetCurveInfo(HAPI_NodeId nodeID, HAPI_PartId partID, ref HAPI_CurveInfo curveInfo)
		{
			return false;
		}
		public virtual bool GetVolumeBounds(HAPI_NodeId nodeID, HAPI_PartId partID, out float x_min, out float y_min, out float z_min,
			out float x_max, out float y_max, out float z_max, out float x_center, out float y_center, out float z_center)
		{
			x_min = y_min = z_min = x_max = y_max = z_max = x_center = y_center = z_center = 0;
			return false;
		}
		public void PopulateScatterTrees(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, int pointCount)
		{
			HEU_TerrainUtility.PopulateScatterTrees(session, geoID, partID, pointCount, ref _scatterTrees);
		}