private void DispatchAvatarSpecificationRequest(AvatarSpecRequestParams avatarSpecRequest)
    {
        textureCopyManager.CheckFallbackTextureSet(avatarSpecRequest._lod);
        CAPI.ovrAvatar_SetForceASTCTextures(avatarSpecRequest._forceMobileTextureFormat);

        HashSet<specificationCallback> callbackSet;
        if (!specificationCallbacks.TryGetValue(avatarSpecRequest._userId, out callbackSet))
        {
            callbackSet = new HashSet<specificationCallback>();
            specificationCallbacks.Add(avatarSpecRequest._userId, callbackSet);

            IntPtr specRequest = CAPI.ovrAvatarSpecificationRequest_Create(avatarSpecRequest._userId);
            CAPI.ovrAvatarSpecificationRequest_SetLookAndFeelVersion(specRequest, avatarSpecRequest._lookVersion);
            CAPI.ovrAvatarSpecificationRequest_SetFallbackLookAndFeelVersion(specRequest, avatarSpecRequest._fallbackVersion);
            CAPI.ovrAvatarSpecificationRequest_SetLevelOfDetail(specRequest, avatarSpecRequest._lod);
            CAPI.ovrAvatarSpecificationRequest_SetCombineMeshes(specRequest, avatarSpecRequest._useCombinedMesh);
            CAPI.ovrAvatarSpecificationRequest_SetExpressiveFlag(specRequest, avatarSpecRequest._enableExpressive);
            CAPI.ovrAvatar_RequestAvatarSpecificationFromSpecRequest(specRequest);
            CAPI.ovrAvatarSpecificationRequest_Destroy(specRequest);
        }

        callbackSet.Add(avatarSpecRequest._callback);
    }
Example #2
0
 // Request an avatar specification to be loaded by adding to the queue.
 // Requests are dispatched in Update().
 public void RequestAvatarSpecification(AvatarSpecRequestParams avatarSpecRequest)
 {
     avatarSpecificationQueue.Enqueue(avatarSpecRequest);
     AvatarLogger.Log("Avatar spec request queued: " + avatarSpecRequest._userId.ToString());
 }
Example #3
0
    void Update()
    {
        if (Instance == null)
        {
            return;
        }
#if AVATAR_DEBUG
        // Call before ovrAvatarMessage_Pop which flushes the state
        CAPI.ovrAvatar_DrawDebugLines();
#endif

        // Dispatch waiting avatar spec request
        if (avatarSpecificationQueue.Count > 0 &&
            (avatarSpecRequestAvailable ||
             Time.time - lastDispatchedAvatarSpecRequestTime >= AVATAR_SPEC_REQUEST_TIMEOUT))
        {
            avatarSpecRequestAvailable = false;
            AvatarSpecRequestParams avatarSpec = avatarSpecificationQueue.Dequeue();
            DispatchAvatarSpecificationRequest(avatarSpec);
            lastDispatchedAvatarSpecRequestTime = Time.time;
            AvatarLogger.Log("Avatar spec request dispatched: " + avatarSpec._userId);
        }

        IntPtr message = CAPI.ovrAvatarMessage_Pop();
        if (message == IntPtr.Zero)
        {
            return;
        }

        ovrAvatarMessageType messageType = CAPI.ovrAvatarMessage_GetType(message);
        switch (messageType)
        {
        case ovrAvatarMessageType.AssetLoaded:
        {
            ovrAvatarMessage_AssetLoaded assetMessage = CAPI.ovrAvatarMessage_GetAssetLoaded(message);
            IntPtr             asset       = assetMessage.asset;
            UInt64             assetID     = assetMessage.assetID;
            ovrAvatarAssetType assetType   = CAPI.ovrAvatarAsset_GetType(asset);
            OvrAvatarAsset     assetData   = null;
            IntPtr             avatarOwner = IntPtr.Zero;

            switch (assetType)
            {
            case ovrAvatarAssetType.Mesh:
                assetData = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.Mesh);
                break;

            case ovrAvatarAssetType.Texture:
                assetData = new OvrAvatarAssetTexture(assetID, asset);
                break;

            case ovrAvatarAssetType.Material:
                assetData = new OvrAvatarAssetMaterial(assetID, asset);
                break;

            case ovrAvatarAssetType.CombinedMesh:
                avatarOwner = CAPI.ovrAvatarAsset_GetAvatar(asset);
                assetData   = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.CombinedMesh);
                break;

            case ovrAvatarAssetType.FailedLoad:
                AvatarLogger.LogWarning("Asset failed to load from SDK " + assetID);
                break;

            default:
                throw new NotImplementedException(string.Format("Unsupported asset type format {0}", assetType.ToString()));
            }

            HashSet <assetLoadedCallback> callbackSet;
            if (assetType == ovrAvatarAssetType.CombinedMesh)
            {
                if (!assetCache.ContainsKey(assetID))
                {
                    assetCache.Add(assetID, assetData);
                }

                combinedMeshLoadedCallback callback;
                if (combinedMeshLoadedCallbacks.TryGetValue(avatarOwner, out callback))
                {
                    callback(asset);
                    combinedMeshLoadedCallbacks.Remove(avatarOwner);
                }
                else
                {
                    AvatarLogger.LogWarning("Loaded a combined mesh with no owner: " + assetMessage.assetID);
                }
            }
            else
            {
                if (assetData != null && assetLoadedCallbacks.TryGetValue(assetMessage.assetID, out callbackSet))
                {
                    assetCache.Add(assetID, assetData);

                    foreach (var callback in callbackSet)
                    {
                        callback(assetData);
                    }

                    assetLoadedCallbacks.Remove(assetMessage.assetID);
                }
            }
            break;
        }

        case ovrAvatarMessageType.AvatarSpecification:
        {
            avatarSpecRequestAvailable = true;
            ovrAvatarMessage_AvatarSpecification spec = CAPI.ovrAvatarMessage_GetAvatarSpecification(message);
            HashSet <specificationCallback>      callbackSet;
            if (specificationCallbacks.TryGetValue(spec.oculusUserID, out callbackSet))
            {
                foreach (var callback in callbackSet)
                {
                    callback(spec.avatarSpec);
                }

                specificationCallbacks.Remove(spec.oculusUserID);
            }
            else
            {
                AvatarLogger.LogWarning("Error, got an avatar specification callback from a user id we don't have a record for: " + spec.oculusUserID);
            }
            break;
        }

        default:
            throw new NotImplementedException("Unhandled ovrAvatarMessageType: " + messageType);
        }
        CAPI.ovrAvatarMessage_Free(message);
    }