Esempio n. 1
0
 public void run(object o)
 {
     for (int i = 0; i < arrassets.Length; i++)
     {
         AssetBase ab = sn.CommsManager.AssetCache.GetAsset(arrassets[i], AssetRequestInfo.InternalRequest());
         if (ab != null && ab.Data != null)
         {
             j2kdecode.Decode(arrassets[i], ab.Data);
         }
     }
     ThreadTracker.Remove(thisthread);
 }
        void HandleDecode(string module, string[] args)
        {
            if (args.Length < 3)
            {
                MainConsole.Instance.Output("Usage is j2k decode <ID>");
                return;
            }

            UUID   assetId;
            string rawAssetId = args[2];

            if (!UUID.TryParse(rawAssetId, out assetId))
            {
                MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId);
                return;
            }

            AssetBase asset = m_scene.AssetService.Get(assetId.ToString());

            if (asset == null)
            {
                MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId);
                return;
            }

            if (asset.Type != (sbyte)AssetType.Texture)
            {
                MainConsole.Instance.OutputFormat("ERROR: Asset {0} is not a texture type", assetId);
                return;
            }

            IJ2KDecoder decoder = m_scene.RequestModuleInterface <IJ2KDecoder>();

            if (decoder == null)
            {
                MainConsole.Instance.OutputFormat("ERROR: No IJ2KDecoder module available");
                return;
            }

            OpenJPEG.J2KLayerInfo[] layers;
            int components;

            if (decoder.Decode(assetId, asset.Data, out layers, out components))
            {
                MainConsole.Instance.OutputFormat(
                    "Successfully decoded asset {0} with {1} layers and {2} components",
                    assetId, layers.Length, components);
            }
            else
            {
                MainConsole.Instance.OutputFormat("Decode of asset {0} failed", assetId);
            }
        }
                /// <summary>
                /// Handle raw uploaded baked texture data.
                /// </summary>
                /// <param name="data"></param>
                /// <param name="path"></param>
                /// <param name="param"></param>
                /// <returns></returns>
                public string BakedTextureUploaded(byte[] data, string path, string param)
                {
                    String result;
                    bool   decodeFailed = false;
                    UUID   newAssetID   = UUID.Random();

                    if (data.Length <= 0)
                    {
                        m_log.ErrorFormat("[CAPS]: Invalid length {0} on UploadBakeRequestPut for {1}", data.Length, path);
                        decodeFailed = true;
                    }
                    else if (m_layerDecoder != null)
                    {
                        decodeFailed = (m_layerDecoder.Decode(newAssetID, data) == false);
                    }

                    if (decodeFailed)
                    {
                        Hashtable badReply = new Hashtable();
                        badReply["state"]     = "error";
                        badReply["new_asset"] = UUID.Zero;
                        result = LLSDHelpers.SerializeLLSDReply(badReply);
                    }
                    else
                    {
                        AssetBase asset = new AssetBase(newAssetID, "Baked Texture", (sbyte)AssetType.Texture, m_Caps.AgentID.ToString());
                        asset.Data = data;
                        //Persist baked textures as we will use them in the baked texture cache
                        //asset.Temporary = true;
                        asset.Local = true;
                        m_assetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());

                        LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                        uploadComplete.new_asset          = newAssetID.ToString();
                        uploadComplete.new_inventory_item = UUID.Zero;
                        uploadComplete.state = "complete";

                        result = LLSDHelpers.SerializeLLSDReply(uploadComplete);
                        // m_log.DebugFormat("[BAKED TEXTURE UPLOADER]: baked texture upload completed for {0}", newAssetID);
                    }

                    m_Caps.HttpListener.RemoveStreamHandler("POST", m_uploaderPath);
                    return(result);
                }
            /// <summary>
            ///     Called once new texture data has been received for this updater.
            /// </summary>
            public void DataReceived(byte [] data, IScene scene)
            {
                ISceneChildEntity part = scene.GetSceneObjectPart(PrimID);

                if (part == null || data == null || data.Length <= 1)
                {
                    IChatModule chatModule = scene.RequestModuleInterface <IChatModule> ();
                    if (chatModule != null)
                    {
                        string msg =
                            string.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
                        if (part != null)
                        {
                            chatModule.SimChat(msg, ChatTypeEnum.Say, 0,
                                               part.ParentEntity.AbsolutePosition, part.Name, part.UUID, false, scene);
                        }
                        else
                        {
                            chatModule.SimChat(msg, ChatTypeEnum.Say, 0,
                                               new Vector3(), "Unknown", UUID.Zero, false, scene);
                        }
                    }
                    return;
                }

                byte []   assetData = null;
                AssetBase oldAsset  = null;

                if (BlendWithOldTexture)
                {
                    Primitive.TextureEntryFace defaultFace = part.Shape.Textures.DefaultTexture;
                    if (defaultFace != null)
                    {
                        oldAsset = scene.AssetService.Get(defaultFace.TextureID.ToString());

                        if (oldAsset != null)
                        {
                            assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha, scene);
                        }
                    }
                }

                if (assetData == null)
                {
                    assetData = new byte [data.Length];
                    Array.Copy(data, assetData, data.Length);
                }

                AssetBase asset = null;

                if (LastAssetID != UUID.Zero)
                {
                    asset = scene.AssetService.Get(LastAssetID.ToString());
                    if (asset != null)
                    {
                        asset.Description = string.Format("URL image : {0}", Url);
                        asset.Data        = assetData;
                        if ((asset.Flags & AssetFlags.Local) == AssetFlags.Local)
                        {
                            asset.Flags = asset.Flags & ~AssetFlags.Local;
                        }
                        if (((asset.Flags & AssetFlags.Temporary) == AssetFlags.Temporary) != ((Disp & DISP_TEMP) != 0))
                        {
                            if ((Disp & DISP_TEMP) != 0)
                            {
                                asset.Flags |= AssetFlags.Temporary;
                            }
                            else
                            {
                                asset.Flags = asset.Flags & ~AssetFlags.Temporary;
                            }
                        }
                        asset.ID = scene.AssetService.Store(asset);
                    }
                }

                // either we have no LastAssetID or the above failed to retrieve the asset...so...
                if (asset == null)
                {
                    // Create a new asset for user
                    asset = new AssetBase(UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000),
                                          AssetType.Texture,
                                          scene.RegionInfo.RegionID)
                    {
                        Data = assetData, Description = string.Format("URL image : {0}", Url)
                    };
                    if ((Disp & DISP_TEMP) != 0)
                    {
                        asset.Flags = AssetFlags.Temporary;
                    }
                    asset.ID = scene.AssetService.Store(asset);
                }

                IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface <IJ2KDecoder> ();

                if (cacheLayerDecode != null)
                {
                    cacheLayerDecode.Decode(asset.ID, asset.Data);
                    cacheLayerDecode = null;
                    LastAssetID      = asset.ID;
                }

                UUID oldID = UUID.Zero;

                lock (part) {
                    // mostly keep the values from before
                    Primitive.TextureEntry tmptex = part.Shape.Textures;

                    // remove the old asset from the cache
                    oldID = tmptex.DefaultTexture.TextureID;

                    if (Face == ALL_SIDES)
                    {
                        tmptex.DefaultTexture.TextureID = asset.ID;
                    }
                    else
                    {
                        try {
                            Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face);
                            texface.TextureID          = asset.ID;
                            tmptex.FaceTextures [Face] = texface;
                        } catch (Exception) {
                            tmptex.DefaultTexture.TextureID = asset.ID;
                        }
                    }

                    // I'm pretty sure we always want to force this to true
                    // I'm pretty sure no one wants to set fullbright true if it wasn't true before.
                    // tmptex.DefaultTexture.Fullbright = true;

                    part.UpdateTexture(tmptex, true);
                }

                if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0))
                {
                    if (oldAsset == null)
                    {
                        oldAsset = scene.AssetService.Get(oldID.ToString());
                    }
                    if (oldAsset != null)
                    {
                        if ((oldAsset.Flags & AssetFlags.Temporary) == AssetFlags.Temporary)
                        {
                            scene.AssetService.Delete(oldID);
                        }
                    }
                }

                if (oldAsset != null)
                {
                    oldAsset.Dispose();
                }
                asset.Dispose();
            }
Esempio n. 5
0
            /// <summary>
            /// Called once new texture data has been received for this updater.
            /// </summary>
            /// <param name="data"></param>
            /// <param name="scene"></param>
            /// <param name="isReuseable">True if the data given is reuseable.</param>
            /// <returns>The asset UUID given to the incoming data.</returns>
            public UUID DataReceived(byte[] data, Scene scene)
            {
                SceneObjectPart part = scene.GetSceneObjectPart(PrimID);

                if (part == null || data == null || data.Length <= 1)
                {
                    string msg =
                        String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
                    scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say,
                                  0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false);

                    return(UUID.Zero);
                }

                byte[]    assetData = null;
                AssetBase oldAsset  = null;

                if (BlendWithOldTexture)
                {
                    Primitive.TextureEntryFace curFace;
                    if (Face == ALL_SIDES)
                    {
                        curFace = part.Shape.Textures.DefaultTexture;
                    }
                    else
                    {
                        try
                        {
                            curFace = part.Shape.Textures.GetFace((uint)Face);
                        }
                        catch
                        {
                            curFace = null;
                        }
                    }
                    if (curFace != null)
                    {
                        oldAsset = scene.AssetService.Get(curFace.TextureID.ToString());

                        if (oldAsset != null)
                        {
                            assetData = BlendTextures(data, oldAsset.Data, FrontAlpha);
                        }
                    }
                }
                else if (FrontAlpha < 255)
                {
                    assetData = BlendTextures(data, null, FrontAlpha);
                }


                if (assetData == null)
                {
                    assetData = new byte[data.Length];
                    Array.Copy(data, assetData, data.Length);
                }

                // Create a new asset for user
                AssetBase asset
                    = new AssetBase(
                          UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000), (sbyte)AssetType.Texture,
                          scene.RegionInfo.RegionID.ToString());

                asset.Data        = assetData;
                asset.Description = String.Format("URL image : {0}", Url);
                if (asset.Description.Length > 128)
                {
                    asset.Description = asset.Description.Substring(0, 128);
                }
                asset.Local     = true;          // dynamic images aren't saved in the assets server
                asset.Temporary = ((Disp & DISP_TEMP) != 0);
                scene.AssetService.Store(asset); // this will only save the asset in the local asset cache

                IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface <IJ2KDecoder>();

                if (cacheLayerDecode != null)
                {
                    if (!cacheLayerDecode.Decode(asset.FullID, asset.Data))
                    {
                        m_log.WarnFormat(
                            "[DYNAMIC TEXTURE MODULE]: Decoding of dynamically generated asset {0} for {1} in {2} failed",
                            asset.ID, part.Name, part.ParentGroup.Scene.Name);
                    }
                }

                UUID oldID = UpdatePart(part, asset.FullID);

                if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0))
                {
                    if (oldAsset == null)
                    {
                        oldAsset = scene.AssetService.Get(oldID.ToString());
                    }

                    if (oldAsset != null)
                    {
                        if (oldAsset.Temporary)
                        {
                            scene.AssetService.Delete(oldID.ToString());
                        }
                    }
                }

                return(asset.FullID);
            }
            /// <summary>
            /// Called once new texture data has been received for this updater.
            /// </summary>
            public void DataReceived(byte[] data, Scene scene)
            {
                SceneObjectPart part = scene.GetSceneObjectPart(PrimID);

                if (part == null || data == null || data.Length <= 1)
                {
                    string msg =
                        String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
                    scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say,
                                  0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false);
                    return;
                }

                byte[]    assetData = null;
                AssetBase oldAsset  = null;

                if (BlendWithOldTexture)
                {
                    Primitive.TextureEntryFace defaultFace = part.Shape.Textures.DefaultTexture;
                    if (defaultFace != null)
                    {
                        oldAsset = scene.AssetService.Get(defaultFace.TextureID.ToString());

                        if (oldAsset != null)
                        {
                            assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
                        }
                    }
                }

                if (assetData == null)
                {
                    assetData = new byte[data.Length];
                    Array.Copy(data, assetData, data.Length);
                }

                // Create a new asset for user
                AssetBase asset = new AssetBase(UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000), (sbyte)AssetType.Texture,
                                                scene.RegionInfo.RegionID.ToString());

                asset.Data        = assetData;
                asset.Description = String.Format("URL image : {0}", Url);
                asset.Local       = false;
                asset.Temporary   = ((Disp & DISP_TEMP) != 0);
                scene.AssetService.Store(asset);
//                scene.CommsManager.AssetCache.AddAsset(asset);

                IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface <IJ2KDecoder>();

                if (cacheLayerDecode != null)
                {
                    cacheLayerDecode.Decode(asset.FullID, asset.Data);
                    cacheLayerDecode = null;
                    LastAssetID      = asset.FullID;
                }

                UUID oldID = UUID.Zero;

                lock (part)
                {
                    // mostly keep the values from before
                    Primitive.TextureEntry tmptex = part.Shape.Textures;

                    // remove the old asset from the cache
                    oldID = tmptex.DefaultTexture.TextureID;

                    if (Face == ALL_SIDES)
                    {
                        tmptex.DefaultTexture.TextureID = asset.FullID;
                    }
                    else
                    {
                        try
                        {
                            Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face);
                            texface.TextureID         = asset.FullID;
                            tmptex.FaceTextures[Face] = texface;
                        }
                        catch (Exception)
                        {
                            tmptex.DefaultTexture.TextureID = asset.FullID;
                        }
                    }

                    // I'm pretty sure we always want to force this to true
                    // I'm pretty sure noone whats to set fullbright true if it wasn't true before.
                    // tmptex.DefaultTexture.Fullbright = true;

                    part.UpdateTexture(tmptex);
                }

                if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0))
                {
                    if (oldAsset == null)
                    {
                        oldAsset = scene.AssetService.Get(oldID.ToString());
                    }
                    if (oldAsset != null)
                    {
                        if (oldAsset.Temporary == true)
                        {
                            scene.AssetService.Delete(oldID.ToString());
                        }
                    }
                }
            }
Esempio n. 7
0
            /// <summary>
            /// Called once new texture data has been received for this updater.
            /// </summary>
            public void DataReceived(byte[] data, Scene scene)
            {
                SceneObjectPart part = scene.GetSceneObjectPart(PrimID);

                if (data == null)
                {
                    string msg =
                        String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
                    scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say,
                                  0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false);
                    return;
                }

                byte[]    assetData;
                AssetBase oldAsset = null;

                if (BlendWithOldTexture)
                {
                    UUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID;
                    oldAsset = scene.CommsManager.AssetCache.GetAsset(lastTextureID, AssetRequestInfo.InternalRequest());
                    if (oldAsset != null)
                    {
                        assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
                    }
                    else
                    {
                        assetData = new byte[data.Length];
                        Array.Copy(data, assetData, data.Length);
                    }
                }
                else
                {
                    assetData = new byte[data.Length];
                    Array.Copy(data, assetData, data.Length);
                }

                // Create a new asset for user
                AssetBase asset = new AssetBase();

                asset.FullID      = UUID.Random();
                asset.Data        = assetData;
                asset.Name        = "DynamicImage" + Util.RandomClass.Next(1, 10000);
                asset.Type        = 0;
                asset.Description = "dynamic image";
                asset.Local       = false;
                asset.Temporary   = true;
                scene.CommsManager.AssetCache.AddAsset(asset, AssetRequestInfo.InternalRequest());

                LastAssetID = asset.FullID;

                IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface <IJ2KDecoder>();

                if (cacheLayerDecode != null)
                {
                    cacheLayerDecode.Decode(asset.FullID, asset.Data);
                }
                cacheLayerDecode = null;

                // mostly keep the values from before
                Primitive.TextureEntry tmptex = part.Shape.Textures;

                // remove the old asset from the cache
                UUID oldID = tmptex.DefaultTexture.TextureID;

                tmptex.DefaultTexture.TextureID = asset.FullID;
                // I'm pretty sure we always want to force this to true
                // I'm pretty sure noone whats to set fullbright true if it wasn't true before.
                // tmptex.DefaultTexture.Fullbright = true;

                part.Shape.Textures = tmptex;
                part.ScheduleFullUpdate();
            }