Exemplo n.º 1
0
        private void UpdateAppearanceFromWearables(bool bake)
        {
            lock (AgentTextures)
            {
                for (int i = 0; i < AgentTextures.Length; i++)
                    AgentTextures[i] = UUID.Zero;
            }

            // Register an asset download callback to get wearable data
            AssetManager.AssetReceivedCallback assetCallback = new AssetManager.AssetReceivedCallback(Assets_OnAssetReceived);
            
            AssetManager.AssetUploadedCallback uploadCallback = new AssetManager.AssetUploadedCallback(Assets_OnAssetUploaded);
            Assets.OnAssetReceived += assetCallback;
            
            Assets.OnAssetUploaded += uploadCallback;

            // Download assets for what we are wearing and fill in AgentTextures
            DownloadWearableAssets();
            WearablesDownloadedEvent.WaitOne();

            // Unregister the asset download callback
            Assets.OnAssetReceived -= assetCallback;

            // Check if anything needs to be rebaked
            if (bake) RequestCachedBakes();

            // Tell the sim what we are wearing
            SendAgentIsNowWearing();

            // Wait for cached layer check to finish
            if (bake) CachedResponseEvent.WaitOne();

            // Unregister the image download and asset upload callbacks
            //Assets.OnImageReceived -= imageCallback;
            Assets.OnAssetUploaded -= uploadCallback;

            Log.DebugLog("CachedResponseEvent completed");

            #region Send Appearance

            Primitive.TextureEntry te = null;

            ObjectManager.NewAvatarCallback updateCallback =
                delegate(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation)
                {
                    if (avatar.LocalID == Self.LocalID)
                    {
                        if (avatar.Textures.FaceTextures != null)
                        {
                            bool match = true;

                            for (uint i = 0; i < AgentTextures.Length; i++)
                            {
                                Primitive.TextureEntryFace face = avatar.Textures.FaceTextures[i];

                                if (face == null)
                                {
                                    // If the texture is UUID.Zero the face should be null
                                    if (AgentTextures[i] != UUID.Zero)
                                    {
                                        match = false;
                                        break;
                                    }
                                }
                                else if (face.TextureID != AgentTextures[i] && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE)
                                {
                                    Log.DebugLog("*** FACE is " + ((TextureIndex)i).ToString() + " " + face.TextureID.ToString() + " Agent Texture is " + AgentTextures[i].ToString());
                                    match = false;
                                    //break;
                                }
                            }

                            if (!match)
                                Log.Log("TextureEntry mismatch after updating our appearance", Helpers.LogLevel.Warning);

                            te = avatar.Textures;
                            UpdateEvent.Set();
                        }
                        else
                        {
                            Log.Log("Received an update for our avatar with a null FaceTextures array",
                                Helpers.LogLevel.Warning);
                        }
                    }
                };
            Objects.OnNewAvatar += updateCallback;

            // Send all of the visual params and textures for our agent
            SendAgentSetAppearance();

            // Wait for the ObjectUpdate to come in for our avatar after changing appearance
            if (UpdateEvent.WaitOne(1000 * 60, false))
            {
                if (OnAppearanceUpdated != null)
                {
                    try { OnAppearanceUpdated(te); }
                    catch (Exception e) { Log.Log(e.Message, Helpers.LogLevel.Error, e); }
                }
            }
            else
            {
                Log.Log("Timed out waiting for our appearance to update on the simulator", Helpers.LogLevel.Warning);
            }

            Objects.OnNewAvatar -= updateCallback;
            Log.Log("Appearance update completed",Helpers.LogLevel.Info);

            #endregion Send Appearance
        }
Exemplo n.º 2
0
        private void UpdateAppearanceFromWearables(bool bake)
        {
            lock (AgentTextures)
            {
                for (int i = 0; i < AgentTextures.Length; i++)
                    AgentTextures[i] = LLUUID.Zero;
            }

            // Register an asset download callback to get wearable data
            AssetManager.AssetReceivedCallback assetCallback = new AssetManager.AssetReceivedCallback(Assets_OnAssetReceived);
            AssetManager.ImageReceivedCallback imageCallback = new AssetManager.ImageReceivedCallback(Assets_OnImageReceived);
            AssetManager.AssetUploadedCallback uploadCallback = new AssetManager.AssetUploadedCallback(Assets_OnAssetUploaded);
            Assets.OnAssetReceived += assetCallback;
            Assets.OnImageReceived += imageCallback;
            Assets.OnAssetUploaded += uploadCallback;

            // Download assets for what we are wearing and fill in AgentTextures
            DownloadWearableAssets();
            WearablesDownloadedEvent.WaitOne();

            // Unregister the asset download callback
            Assets.OnAssetReceived -= assetCallback;

            if (Client.Settings.DEBUG)
            {
                StringBuilder tex = new StringBuilder();

                for (int i = 0; i < AgentTextures.Length; i++)
                    if (AgentTextures[i] != LLUUID.Zero)
                        tex.AppendFormat("{0} = {1}\n", (TextureIndex)i, AgentTextures[i]);

                Client.DebugLog("AgentTextures:" + Environment.NewLine + tex.ToString());
            }

            // Check if anything needs to be rebaked
            if (bake) RequestCachedBakes();

            // Tell the sim what we are wearing
            SendAgentIsNowWearing();

            // Wait for cached layer check to finish
            if (bake) CachedResponseEvent.WaitOne();

            // Unregister the image download and asset upload callbacks
            Assets.OnImageReceived -= imageCallback;
            Assets.OnAssetUploaded -= uploadCallback;

            Client.DebugLog("CachedResponseEvent completed");

            #region Send Appearance

            LLObject.TextureEntry te = null;

            ObjectManager.NewAvatarCallback updateCallback =
                delegate(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation)
                {
                    if (avatar.LocalID == Client.Self.LocalID)
                    {
                        if (avatar.Textures.FaceTextures != null)
                        {
                            bool match = true;

                            for (uint i = 0; i < AgentTextures.Length; i++)
                            {
                                LLObject.TextureEntryFace face = avatar.Textures.FaceTextures[i];

                                if (face == null)
                                {
                                    // If the texture is LLUUID.Zero the face should be null
                                    if (AgentTextures[i] != LLUUID.Zero)
                                    {
                                        match = false;
                                        break;
                                    }
                                }
                                else if (face.TextureID != AgentTextures[i])
                                {
                                    match = false;
                                    break;
                                }
                            }

                            if (!match)
                                Client.Log("TextureEntry mismatch after updating our appearance", Helpers.LogLevel.Warning);

                            te = avatar.Textures;
                            UpdateEvent.Set();
                        }
                        else
                        {
                            Client.Log("Received an update for our avatar with a null FaceTextures array",
                                Helpers.LogLevel.Warning);
                        }
                    }
                };
            Client.Objects.OnNewAvatar += updateCallback;

            // Send all of the visual params and textures for our agent
            SendAgentSetAppearance();

            // Wait for the ObjectUpdate to come in for our avatar after changing appearance
            if (UpdateEvent.WaitOne(1000 * 60, false))
            {
                if (OnAppearanceUpdated != null)
                {
                    try { OnAppearanceUpdated(te); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }
            else
            {
                Client.Log("Timed out waiting for our appearance to update on the simulator", Helpers.LogLevel.Warning);
            }

            Client.Objects.OnNewAvatar -= updateCallback;

            #endregion Send Appearance
        }