internal bool CreateInputNodeForCollider(HEU_SessionBase session, out HAPI_NodeId outNodeID, HAPI_NodeId parentNodeId, int colliderIndex, string colliderName, float[] colliderVertices, int[] colliderIndices)
	{
	    outNodeID = HEU_Defines.HEU_INVALID_NODE_ID;

	    HAPI_NodeId colliderNodeId = HEU_Defines.HEU_INVALID_NODE_ID;

	    if (!session.CreateNode(parentNodeId, "null", colliderName, false, out colliderNodeId))
		return false;

	    HAPI_PartInfo partInfo = new HAPI_PartInfo();
	    partInfo.init();
	    partInfo.id = 0;
	    partInfo.nameSH = 0;
	    partInfo.attributeCounts[(int)HAPI_AttributeOwner.HAPI_ATTROWNER_POINT] = 0;
	    partInfo.attributeCounts[(int)HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM] = 0;
	    partInfo.attributeCounts[(int)HAPI_AttributeOwner.HAPI_ATTROWNER_VERTEX] = 0;
	    partInfo.attributeCounts[(int)HAPI_AttributeOwner.HAPI_ATTROWNER_DETAIL] = 0;
	    partInfo.vertexCount = colliderIndices.Length;
	    partInfo.faceCount = colliderIndices.Length / 3;
	    partInfo.pointCount = colliderVertices.Length / 3;
	    partInfo.type = HAPI_PartType.HAPI_PARTTYPE_MESH;

	    if (!session.SetPartInfo(colliderNodeId, 0, ref partInfo)) return false;

	    HAPI_AttributeInfo attributeInfoPoint = new HAPI_AttributeInfo();
	    attributeInfoPoint.count = colliderVertices.Length / 3;
	    attributeInfoPoint.tupleSize = 3;
	    attributeInfoPoint.exists = true;
	    attributeInfoPoint.owner = HAPI_AttributeOwner.HAPI_ATTROWNER_POINT;
	    attributeInfoPoint.storage = HAPI_StorageType.HAPI_STORAGETYPE_FLOAT;
	    attributeInfoPoint.originalOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_INVALID;

	    if (!session.AddAttribute(colliderNodeId, 0, HEU_HAPIConstants.HAPI_ATTRIB_POSITION, ref attributeInfoPoint))
		return false;

	    if (!session.SetAttributeFloatData(colliderNodeId, 0, HEU_HAPIConstants.HAPI_ATTRIB_POSITION, ref attributeInfoPoint, colliderVertices, 0, attributeInfoPoint.count))
		return false;

	    if (!session.SetVertexList(colliderNodeId, 0, colliderIndices, 0, colliderIndices.Length))
		return false;

	    int[] faceCounts = new int[partInfo.faceCount];
	    for (int i = 0; i < faceCounts.Length; i++)
	    {
		faceCounts[i] = 3;
	    }

	    if (!session.SetFaceCount(colliderNodeId, 0, faceCounts, 0, faceCounts.Length))
		return false;

	    if (!session.CommitGeo(colliderNodeId))
		return false;

	    outNodeID = colliderNodeId;

	    return true;
	}
Example #2
0
        public static bool CreateAndCookInputAsset(HEU_SessionBase session, string assetName, bool bCookTemplatedGeos, out HAPI_NodeId newAssetID)
        {
            newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;
            if (!session.CreateInputNode(out newAssetID, null))
            {
                return(false);
            }

            // Make sure cooking is successfull before proceeding. Any licensing or file data issues will be caught here.
            if (!HEU_HAPIUtility.ProcessHoudiniCookStatus(session, assetName))
            {
                return(false);
            }

            // In case the cooking wasn't done previously, force it now.
            bool bResult = HEU_HAPIUtility.CookNodeInHoudini(session, newAssetID, bCookTemplatedGeos, assetName);

            if (!bResult)
            {
                // When cook failed, deleted the node created earlier
                session.DeleteNode(newAssetID);
                newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;
                return(false);
            }

            // After cooking, set an empty partinfo
            HAPI_GeoInfo inputGeoInfo = new HAPI_GeoInfo();

            if (!session.GetDisplayGeoInfo(newAssetID, ref inputGeoInfo))
            {
                return(false);
            }

            HAPI_PartInfo newPart = new HAPI_PartInfo();

            newPart.init();
            newPart.id          = 0;
            newPart.vertexCount = 0;
            newPart.faceCount   = 0;
            newPart.pointCount  = 0;
            // TODO: always set to mesh type?
            newPart.type = HAPI_PartType.HAPI_PARTTYPE_MESH;

            if (!session.SetPartInfo(inputGeoInfo.nodeId, 0, ref newPart))
            {
                Debug.LogErrorFormat(HEU_Defines.HEU_NAME + ": Failed to set partinfo for input node!");
                return(false);
            }

            return(true);
        }