2008-04-11 07:59:44 +00:00
/ *
2008-07-21 21:12:59 +00:00
* Copyright ( c ) 2007 - 2008 , openmetaverse . org
2008-04-11 07:59:44 +00:00
* All rights reserved .
*
* - Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
*
* - Redistributions of source code must retain the above copyright notice , this
* list of conditions and the following disclaimer .
2008-07-21 21:12:59 +00:00
* - Neither the name of the openmetaverse . org nor the names
2008-04-11 07:59:44 +00:00
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
* CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
* CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE .
* /
2007-07-15 22:03:59 +00:00
using System ;
using System.Text ;
2007-08-25 09:36:33 +00:00
using System.Collections.Generic ;
2008-07-21 21:12:59 +00:00
using OpenMetaverse.Imaging ;
2007-07-15 22:03:59 +00:00
2008-07-21 21:12:59 +00:00
namespace OpenMetaverse
2007-07-15 22:03:59 +00:00
{
2008-05-05 02:02:29 +00:00
/// <summary>
///
/// </summary>
[Flags]
2007-12-17 06:37:56 +00:00
public enum WearableType : byte
{
2008-05-05 02:02:29 +00:00
/// <summary>A shape</summary>
2007-12-17 06:37:56 +00:00
Shape = 0 ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Skin ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Hair ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Eyes ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Shirt ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Pants ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Shoes ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Socks ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Jacket ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Gloves ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Undershirt ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Underpants ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Skirt ,
2008-05-05 02:02:29 +00:00
/// <summary></summary>
2007-12-17 06:37:56 +00:00
Invalid = 255
} ;
2008-05-05 02:02:29 +00:00
/// <summary>
2009-03-19 01:25:28 +00:00
/// Base class for all Asset types
2008-05-05 02:02:29 +00:00
/// </summary>
2007-07-15 22:03:59 +00:00
public abstract class Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>A byte array containing the raw asset data</summary>
2007-08-04 16:46:37 +00:00
public byte [ ] AssetData ;
2009-03-19 01:25:28 +00:00
/// <summary>True if the asset it only stored on the server temporarily</summary>
2008-10-09 04:50:03 +00:00
public bool Temporary ;
2009-03-19 01:25:28 +00:00
/// <summary>A unique ID</summary>
2008-07-25 05:15:05 +00:00
private UUID _AssetID ;
2009-03-19 01:25:28 +00:00
/// <summary>The assets unique ID</summary>
2008-07-25 05:15:05 +00:00
public UUID AssetID
2007-07-15 22:03:59 +00:00
{
get { return _AssetID ; }
2007-07-16 18:31:53 +00:00
internal set { _AssetID = value ; }
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// The "type" of asset, Notecard, Animation, etc
/// </summary>
2007-08-04 16:46:37 +00:00
public abstract AssetType AssetType
2007-07-15 22:03:59 +00:00
{
2007-08-04 16:46:37 +00:00
get ;
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Construct a new Asset object
/// </summary>
2007-07-15 22:03:59 +00:00
public Asset ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// Construct a new Asset object
/// </summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public Asset ( UUID assetID , byte [ ] assetData )
2007-07-15 22:03:59 +00:00
{
2008-08-20 22:46:28 +00:00
_AssetID = assetID ;
2007-08-04 16:46:37 +00:00
AssetData = assetData ;
2007-07-15 22:03:59 +00:00
}
/// <summary>
/// Regenerates the <code>AssetData</code> byte array from the properties
/// of the derived class.
/// </summary>
2007-08-04 16:46:37 +00:00
public abstract void Encode ( ) ;
2007-07-15 22:03:59 +00:00
/// <summary>
/// Decodes the AssetData, placing it in appropriate properties of the derived
/// class.
/// </summary>
2007-12-17 06:37:56 +00:00
/// <returns>True if the asset decoding succeeded, otherwise false</returns>
public abstract bool Decode ( ) ;
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents an Animation
/// </summary>
2008-08-25 22:56:00 +00:00
public class AssetAnimation : Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2008-08-25 22:56:00 +00:00
public override AssetType AssetType { get { return AssetType . Animation ; } }
2009-03-19 01:25:28 +00:00
/// <summary>Default Constructor</summary>
2008-08-25 22:56:00 +00:00
public AssetAnimation ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// Construct an Asset object of type Animation
/// </summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-25 22:56:00 +00:00
public AssetAnimation ( UUID assetID , byte [ ] assetData )
: base ( assetID , assetData )
{
AssetData = assetData ;
}
public override void Encode ( ) { }
2008-09-09 00:35:24 +00:00
public override bool Decode ( ) { return true ; }
2008-08-25 22:56:00 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents a string of characters encoded with specific formatting properties
/// </summary>
2007-07-15 22:03:59 +00:00
public class AssetNotecard : Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2007-08-04 16:46:37 +00:00
public override AssetType AssetType { get { return AssetType . Notecard ; } }
2009-03-19 01:25:28 +00:00
/// <summary>A text string containing the raw contents of the notecard</summary>
2007-08-04 16:46:37 +00:00
public string Text = null ;
2009-03-19 01:25:28 +00:00
/// <summary>Construct an Asset of type Notecard</summary>
2007-08-04 16:46:37 +00:00
public AssetNotecard ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// Construct an Asset object of type Notecard
/// </summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetNotecard ( UUID assetID , byte [ ] assetData ) : base ( assetID , assetData )
2008-02-28 21:36:09 +00:00
{
Decode ( ) ;
}
2007-08-04 16:46:37 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Construct an Asset object of type Notecard
/// </summary>
/// <param name="text">A text string containing the raw contents of the notecard</param>
2007-08-04 16:46:37 +00:00
public AssetNotecard ( string text )
{
Text = text ;
2008-02-28 21:36:09 +00:00
Encode ( ) ;
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Encode the raw contents of a string with the specific Linden Text properties
/// </summary>
2007-08-04 16:46:37 +00:00
public override void Encode ( )
2007-07-15 22:03:59 +00:00
{
2008-02-28 21:36:09 +00:00
string temp = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " ;
temp + = Text . Length + "\n" ;
temp + = Text ;
temp + = "}" ;
2008-08-12 22:38:02 +00:00
AssetData = Utils . StringToBytes ( temp ) ;
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Decode the raw asset data including the Linden Text properties
/// </summary>
/// <returns>true if the AssetData was successfully decoded to a string</returns>
2007-12-17 06:37:56 +00:00
public override bool Decode ( )
2007-07-15 22:03:59 +00:00
{
2008-08-12 22:38:02 +00:00
Text = Utils . BytesToString ( AssetData ) ;
2007-12-17 06:37:56 +00:00
return true ;
2007-07-15 22:03:59 +00:00
}
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents an LSL Text object containing a string of UTF encoded characters
/// </summary>
2007-07-16 18:31:53 +00:00
public class AssetScriptText : Asset
2007-07-15 22:03:59 +00:00
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2007-08-04 16:46:37 +00:00
public override AssetType AssetType { get { return AssetType . LSLText ; } }
2009-03-19 01:25:28 +00:00
/// <summary>A string of characters represting the script contents</summary>
2007-08-04 16:46:37 +00:00
public string Source ;
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new AssetScriptText object</summary>
2007-08-04 16:46:37 +00:00
public AssetScriptText ( ) { }
2008-08-20 22:46:28 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Initializes a new AssetScriptText object with parameters
/// </summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetScriptText ( UUID assetID , byte [ ] assetData ) : base ( assetID , assetData ) { }
2007-08-04 16:46:37 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Initializes a new AssetScriptText object with parameters
/// </summary>
/// <param name="source">A string containing the scripts contents</param>
2007-08-04 16:46:37 +00:00
public AssetScriptText ( string source )
2007-07-15 22:03:59 +00:00
{
2007-08-04 16:46:37 +00:00
Source = source ;
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Encode a string containing the scripts contents into byte encoded AssetData
/// </summary>
2007-08-04 16:46:37 +00:00
public override void Encode ( )
2007-07-15 22:03:59 +00:00
{
2008-08-12 22:38:02 +00:00
AssetData = Utils . StringToBytes ( Source ) ;
2007-07-15 22:03:59 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Decode a byte array containing the scripts contents into a string
/// </summary>
/// <returns>true if decoding is successful</returns>
2007-12-17 06:37:56 +00:00
public override bool Decode ( )
2007-07-15 22:03:59 +00:00
{
2008-08-12 22:38:02 +00:00
Source = Utils . BytesToString ( AssetData ) ;
2007-12-17 06:37:56 +00:00
return true ;
2007-07-15 22:03:59 +00:00
}
}
2007-07-16 18:31:53 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents an AssetScriptBinary object containing the
/// LSO compiled bytecode of an LSL script
/// </summary>
2007-07-16 18:31:53 +00:00
public class AssetScriptBinary : Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2007-08-04 16:46:37 +00:00
public override AssetType AssetType { get { return AssetType . LSLBytecode ; } }
2007-07-16 18:31:53 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetScriptBinary object</summary>
2007-08-04 16:46:37 +00:00
public AssetScriptBinary ( ) { }
2008-08-20 22:46:28 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetScriptBinary object with parameters</summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetScriptBinary ( UUID assetID , byte [ ] assetData )
: base ( assetID , assetData )
2007-07-16 18:31:53 +00:00
{
2008-08-25 22:56:00 +00:00
AssetData = assetData ;
2007-07-16 18:31:53 +00:00
}
2007-08-04 16:46:37 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// TODO: Encodes a scripts contents into a LSO Bytecode file
/// </summary>
2008-08-25 22:56:00 +00:00
public override void Encode ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// TODO: Decode LSO Bytecode into a string
/// </summary>
/// <returns>true</returns>
2008-09-09 00:35:24 +00:00
public override bool Decode ( ) { return true ; }
2008-08-25 22:56:00 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents a Sound Asset
/// </summary>
2008-08-25 22:56:00 +00:00
public class AssetSound : Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2008-08-25 22:56:00 +00:00
public override AssetType AssetType { get { return AssetType . Sound ; } }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetSound object</summary>
2008-08-25 22:56:00 +00:00
public AssetSound ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetSound object with parameters</summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-25 22:56:00 +00:00
public AssetSound ( UUID assetID , byte [ ] assetData )
: base ( assetID , assetData )
{
AssetData = assetData ;
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// TODO: Encodes a sound file
/// </summary>
2008-08-25 22:56:00 +00:00
public override void Encode ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// TODO: Decode a sound file
/// </summary>
/// <returns>true</returns>
2008-09-09 00:35:24 +00:00
public override bool Decode ( ) { return true ; }
2007-07-16 18:31:53 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents a texture
/// </summary>
2007-07-16 18:31:53 +00:00
public class AssetTexture : Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2007-08-04 16:46:37 +00:00
public override AssetType AssetType { get { return AssetType . Texture ; } }
2009-03-19 01:25:28 +00:00
/// <summary>A <seealso cref="ManagedImage"/> object containing image data</summary>
2008-07-16 17:41:09 +00:00
public ManagedImage Image ;
2009-03-19 01:25:28 +00:00
/// <summary></summary>
2008-09-09 00:35:24 +00:00
public OpenJPEG . J2KLayerInfo [ ] LayerInfo ;
2009-03-19 01:25:28 +00:00
/// <summary></summary>
2008-10-09 04:50:03 +00:00
public int Components ;
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetTexture object</summary>
2007-07-16 18:31:53 +00:00
public AssetTexture ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// Initializes a new instance of an AssetTexture object
/// </summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetTexture ( UUID assetID , byte [ ] assetData ) : base ( assetID , assetData ) { }
2007-08-04 16:46:37 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Initializes a new instance of an AssetTexture object
/// </summary>
/// <param name="image">A <seealso cref="ManagedImage"/> object containing texture data</param>
2008-07-16 17:41:09 +00:00
public AssetTexture ( ManagedImage image )
2007-07-16 18:31:53 +00:00
{
2007-08-04 16:46:37 +00:00
Image = image ;
2008-10-09 04:50:03 +00:00
Components = 0 ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Color ) ! = 0 )
Components + = 3 ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Gray ) ! = 0 )
+ + Components ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Bump ) ! = 0 )
+ + Components ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Alpha ) ! = 0 )
+ + Components ;
2007-07-16 18:31:53 +00:00
}
2008-07-18 10:29:16 +00:00
/// <summary>
2008-09-09 00:35:24 +00:00
/// Populates the <seealso cref="AssetData"/> byte array with a JPEG2000
/// encoded image created from the data in <seealso cref="Image"/>
2008-07-18 10:29:16 +00:00
/// </summary>
2007-08-04 16:46:37 +00:00
public override void Encode ( )
2007-07-16 18:31:53 +00:00
{
2008-07-18 10:29:16 +00:00
AssetData = OpenJPEG . Encode ( Image ) ;
2007-07-16 18:31:53 +00:00
}
2007-08-04 16:46:37 +00:00
2008-07-18 10:29:16 +00:00
/// <summary>
/// Decodes the JPEG2000 data in <code>AssetData</code> to the
2008-09-09 00:35:24 +00:00
/// <seealso cref="ManagedImage"/> object <seealso cref="Image"/>
2008-07-18 10:29:16 +00:00
/// </summary>
/// <returns>True if the decoding was successful, otherwise false</returns>
2007-12-17 06:37:56 +00:00
public override bool Decode ( )
2007-07-16 18:31:53 +00:00
{
2008-10-09 04:50:03 +00:00
Components = 0 ;
if ( OpenJPEG . DecodeToImage ( AssetData , out Image ) )
{
if ( ( Image . Channels & ManagedImage . ImageChannels . Color ) ! = 0 )
Components + = 3 ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Gray ) ! = 0 )
+ + Components ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Bump ) ! = 0 )
+ + Components ;
if ( ( Image . Channels & ManagedImage . ImageChannels . Alpha ) ! = 0 )
+ + Components ;
return true ;
}
else
{
return false ;
}
2007-07-16 18:31:53 +00:00
}
2008-09-09 00:35:24 +00:00
/// <summary>
/// Decodes the begin and end byte positions for each quality layer in
/// the image
/// </summary>
/// <returns></returns>
public bool DecodeLayerBoundaries ( )
{
2008-10-09 04:50:03 +00:00
return OpenJPEG . DecodeLayerBoundaries ( AssetData , out LayerInfo , out Components ) ;
2008-09-09 00:35:24 +00:00
}
2007-07-16 18:31:53 +00:00
}
2007-08-04 16:46:37 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents a primitive asset
/// </summary>
2007-08-10 20:16:19 +00:00
public class AssetPrim : Asset
2007-08-04 16:46:37 +00:00
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2008-04-07 16:46:04 +00:00
public override AssetType AssetType { get { return AssetType . Object ; } }
2007-08-25 09:36:33 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetPrim object</summary>
2007-08-10 20:16:19 +00:00
public AssetPrim ( ) { }
2007-08-04 16:46:37 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// TODO:
/// </summary>
2007-08-04 16:46:37 +00:00
public override void Encode ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>
/// TODO:
/// </summary>
/// <returns>true</returns>
2008-09-09 00:35:24 +00:00
public override bool Decode ( ) { return true ; }
2007-08-04 16:46:37 +00:00
}
2007-08-10 20:16:19 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents a Wearable Asset, Clothing, Hair, Skin, Etc
/// </summary>
2007-08-25 09:36:33 +00:00
public abstract class AssetWearable : Asset
{
2009-03-19 01:25:28 +00:00
/// <summary>A string containing the name of the asset</summary>
2007-08-25 09:36:33 +00:00
public string Name = String . Empty ;
2009-03-19 01:25:28 +00:00
/// <summary>A string containing a short description of the asset</summary>
2007-08-25 09:36:33 +00:00
public string Description = String . Empty ;
2009-03-19 01:25:28 +00:00
/// <summary>The Assets WearableType</summary>
2007-08-25 09:36:33 +00:00
public WearableType WearableType = WearableType . Shape ;
2009-03-19 01:25:28 +00:00
/// <summary>The For-Sale status of the object</summary>
2007-11-06 09:26:10 +00:00
public SaleType ForSale ;
2009-03-19 01:25:28 +00:00
/// <summary>An Integer representing the purchase price of the asset</summary>
2007-11-06 09:26:10 +00:00
public int SalePrice ;
2009-03-19 01:25:28 +00:00
/// <summary>The <seealso cref="UUID"/> of the assets creator</summary>
2008-07-25 05:15:05 +00:00
public UUID Creator ;
2009-03-19 01:25:28 +00:00
/// <summary>The <seealso cref="UUID"/> of the assets current owner</summary>
2008-07-25 05:15:05 +00:00
public UUID Owner ;
2009-03-19 01:25:28 +00:00
/// <summary>The <seealso cref="UUID"/> of the assets prior owner</summary>
2008-07-25 05:15:05 +00:00
public UUID LastOwner ;
2009-03-19 01:25:28 +00:00
/// <summary>The <seealso cref="UUID"/> of the Group this asset is set to</summary>
2008-07-25 05:15:05 +00:00
public UUID Group ;
2009-03-19 01:25:28 +00:00
/// <summary>True if the asset is owned by a <seealso cref="Group"/></summary>
2007-11-06 09:26:10 +00:00
public bool GroupOwned ;
2009-03-19 01:25:28 +00:00
/// <summary>The Permissions mask of the asset</summary>
2007-08-25 09:36:33 +00:00
public Permissions Permissions ;
2009-03-19 01:25:28 +00:00
/// <summary>A Dictionary containing Key/Value pairs of the objects parameters</summary>
2007-08-25 09:36:33 +00:00
public Dictionary < int , float > Params = new Dictionary < int , float > ( ) ;
2009-03-19 01:25:28 +00:00
/// <summary>A Dictionary containing Key/Value pairs where the Key is the textures Index and the Value is the Textures <seealso cref="UUID"/></summary>
2008-07-25 05:15:05 +00:00
public Dictionary < AppearanceManager . TextureIndex , UUID > Textures = new Dictionary < AppearanceManager . TextureIndex , UUID > ( ) ;
2007-08-25 09:36:33 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetWearable object</summary>
2007-08-25 09:36:33 +00:00
public AssetWearable ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetWearable object with parameters</summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetWearable ( UUID assetID , byte [ ] assetData ) : base ( assetID , assetData ) { }
2007-08-25 09:36:33 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetWearable object with parameters</summary>
/// <param name="source">A string containing the asset parameters</param>
2007-08-25 09:36:33 +00:00
public AssetWearable ( string source )
2007-08-10 20:16:19 +00:00
{
2008-08-12 22:38:02 +00:00
AssetData = Utils . StringToBytes ( source ) ;
2007-08-10 20:16:19 +00:00
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Decode an assets byte encoded data to a string
/// </summary>
/// <returns>true if the asset data was decoded successfully</returns>
2007-12-17 06:37:56 +00:00
public override bool Decode ( )
2007-08-10 20:16:19 +00:00
{
2007-08-25 09:36:33 +00:00
int version = - 1 ;
Permissions = new Permissions ( ) ;
2008-08-12 22:38:02 +00:00
string data = Utils . BytesToString ( AssetData ) ;
2007-08-25 09:36:33 +00:00
2008-08-21 06:46:36 +00:00
data = data . Replace ( "\r" , String . Empty ) ;
2007-12-17 06:37:56 +00:00
string [ ] lines = data . Split ( '\n' ) ;
for ( int stri = 0 ; stri < lines . Length ; stri + + )
2007-08-25 09:36:33 +00:00
{
2007-12-17 06:37:56 +00:00
if ( stri = = 0 )
2007-08-25 09:36:33 +00:00
{
2007-12-17 06:37:56 +00:00
string versionstring = lines [ stri ] ;
version = Int32 . Parse ( versionstring . Split ( ' ' ) [ 2 ] ) ;
if ( version ! = 22 & & version ! = 18 )
return false ;
2007-08-25 09:36:33 +00:00
}
2007-12-17 06:37:56 +00:00
else if ( stri = = 1 )
2007-08-25 09:36:33 +00:00
{
2007-12-17 06:37:56 +00:00
Name = lines [ stri ] ;
2007-08-25 09:36:33 +00:00
}
2007-12-17 06:37:56 +00:00
else if ( stri = = 2 )
2007-08-25 09:36:33 +00:00
{
2007-12-17 06:37:56 +00:00
Description = lines [ stri ] ;
2007-08-25 09:36:33 +00:00
}
2007-12-17 06:37:56 +00:00
else
2007-08-25 09:36:33 +00:00
{
2007-12-17 06:37:56 +00:00
string line = lines [ stri ] . Trim ( ) ;
string [ ] fields = line . Split ( '\t' ) ;
2007-08-25 09:36:33 +00:00
2007-12-17 06:37:56 +00:00
if ( fields . Length = = 1 )
{
fields = line . Split ( ' ' ) ;
if ( fields [ 0 ] = = "parameters" )
{
int count = Int32 . Parse ( fields [ 1 ] ) + stri ;
for ( ; stri < count ; )
{
stri + + ;
line = lines [ stri ] . Trim ( ) ;
fields = line . Split ( ' ' ) ;
int id = Int32 . Parse ( fields [ 0 ] ) ;
2007-12-30 01:31:10 +00:00
if ( fields [ 1 ] = = "," )
fields [ 1 ] = "0" ;
else
fields [ 1 ] = fields [ 1 ] . Replace ( ',' , '.' ) ;
2008-06-06 18:37:22 +00:00
2007-12-17 06:37:56 +00:00
float weight = float . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . Float ,
2008-11-17 23:37:02 +00:00
Utils . EnUsCulture . NumberFormat ) ;
2007-12-17 06:37:56 +00:00
Params [ id ] = weight ;
}
}
else if ( fields [ 0 ] = = "textures" )
{
int count = Int32 . Parse ( fields [ 1 ] ) + stri ;
for ( ; stri < count ; )
{
stri + + ;
line = lines [ stri ] . Trim ( ) ;
fields = line . Split ( ' ' ) ;
AppearanceManager . TextureIndex id = ( AppearanceManager . TextureIndex ) Int32 . Parse ( fields [ 0 ] ) ;
2008-07-25 05:15:05 +00:00
UUID texture = new UUID ( fields [ 1 ] ) ;
2007-12-17 06:37:56 +00:00
Textures [ id ] = texture ;
}
}
else if ( fields [ 0 ] = = "type" )
{
WearableType = ( WearableType ) Int32 . Parse ( fields [ 1 ] ) ;
}
2007-08-25 09:36:33 +00:00
2007-12-17 06:37:56 +00:00
}
else if ( fields . Length = = 2 )
{
switch ( fields [ 0 ] )
{
case "creator_mask" :
// Deprecated, apply this as the base mask
Permissions . BaseMask = ( PermissionMask ) UInt32 . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
break ;
case "base_mask" :
Permissions . BaseMask = ( PermissionMask ) UInt32 . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
break ;
case "owner_mask" :
Permissions . OwnerMask = ( PermissionMask ) UInt32 . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
break ;
case "group_mask" :
Permissions . GroupMask = ( PermissionMask ) UInt32 . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
break ;
case "everyone_mask" :
Permissions . EveryoneMask = ( PermissionMask ) UInt32 . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
break ;
case "next_owner_mask" :
Permissions . NextOwnerMask = ( PermissionMask ) UInt32 . Parse ( fields [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
break ;
case "creator_id" :
2008-07-25 05:15:05 +00:00
Creator = new UUID ( fields [ 1 ] ) ;
2007-12-17 06:37:56 +00:00
break ;
case "owner_id" :
2008-07-25 05:15:05 +00:00
Owner = new UUID ( fields [ 1 ] ) ;
2007-12-17 06:37:56 +00:00
break ;
case "last_owner_id" :
2008-07-25 05:15:05 +00:00
LastOwner = new UUID ( fields [ 1 ] ) ;
2007-12-17 06:37:56 +00:00
break ;
case "group_id" :
2008-07-25 05:15:05 +00:00
Group = new UUID ( fields [ 1 ] ) ;
2007-12-17 06:37:56 +00:00
break ;
case "group_owned" :
GroupOwned = ( Int32 . Parse ( fields [ 1 ] ) ! = 0 ) ;
break ;
case "sale_type" :
ForSale = InventoryManager . StringToSaleType ( fields [ 1 ] ) ;
break ;
case "sale_price" :
SalePrice = Int32 . Parse ( fields [ 1 ] ) ;
break ;
2007-12-19 22:00:49 +00:00
case "sale_info" :
// Container for sale_type and sale_price, ignore
break ;
2007-12-17 06:37:56 +00:00
default :
return false ;
}
}
2007-08-25 09:36:33 +00:00
}
}
2007-12-17 06:37:56 +00:00
return true ;
2007-08-10 20:16:19 +00:00
}
2007-08-25 09:36:33 +00:00
2009-03-19 01:25:28 +00:00
/// <summary>
/// Encode the assets string represantion into a format consumable by the asset server
/// </summary>
2007-08-25 09:36:33 +00:00
public override void Encode ( )
{
2007-11-06 09:26:10 +00:00
const string NL = "\n" ;
2007-08-25 09:36:33 +00:00
StringBuilder data = new StringBuilder ( "LLWearable version 22\n" ) ;
2007-11-06 09:26:10 +00:00
data . Append ( Name ) ; data . Append ( NL ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
data . Append ( "\tpermissions 0\n\t{\n" ) ;
2008-10-06 22:34:38 +00:00
data . Append ( "\t\tbase_mask\t" ) ; data . Append ( Utils . UIntToHexString ( ( uint ) Permissions . BaseMask ) ) ; data . Append ( NL ) ;
data . Append ( "\t\towner_mask\t" ) ; data . Append ( Utils . UIntToHexString ( ( uint ) Permissions . OwnerMask ) ) ; data . Append ( NL ) ;
data . Append ( "\t\tgroup_mask\t" ) ; data . Append ( Utils . UIntToHexString ( ( uint ) Permissions . GroupMask ) ) ; data . Append ( NL ) ;
data . Append ( "\t\teveryone_mask\t" ) ; data . Append ( Utils . UIntToHexString ( ( uint ) Permissions . EveryoneMask ) ) ; data . Append ( NL ) ;
data . Append ( "\t\tnext_owner_mask\t" ) ; data . Append ( Utils . UIntToHexString ( ( uint ) Permissions . NextOwnerMask ) ) ; data . Append ( NL ) ;
2007-11-30 13:15:31 +00:00
data . Append ( "\t\tcreator_id\t" ) ; data . Append ( Creator . ToString ( ) ) ; data . Append ( NL ) ;
data . Append ( "\t\towner_id\t" ) ; data . Append ( Owner . ToString ( ) ) ; data . Append ( NL ) ;
data . Append ( "\t\tlast_owner_id\t" ) ; data . Append ( LastOwner . ToString ( ) ) ; data . Append ( NL ) ;
data . Append ( "\t\tgroup_id\t" ) ; data . Append ( Group . ToString ( ) ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
if ( GroupOwned ) data . Append ( "\t\tgroup_owned\t1\n" ) ;
data . Append ( "\t}\n" ) ;
data . Append ( "\tsale_info\t0\n" ) ;
data . Append ( "\t{\n" ) ;
2007-11-06 09:26:10 +00:00
data . Append ( "\t\tsale_type\t" ) ; data . Append ( InventoryManager . SaleTypeToString ( ForSale ) ) ; data . Append ( NL ) ;
data . Append ( "\t\tsale_price\t" ) ; data . Append ( SalePrice ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
data . Append ( "\t}\n" ) ;
2007-11-06 09:26:10 +00:00
data . Append ( "type " ) ; data . Append ( ( int ) WearableType ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
2007-11-06 09:26:10 +00:00
data . Append ( "parameters " ) ; data . Append ( Params . Count ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
foreach ( KeyValuePair < int , float > param in Params )
{
2007-11-06 09:26:10 +00:00
data . Append ( param . Key ) ; data . Append ( " " ) ; data . Append ( Helpers . FloatToTerseString ( param . Value ) ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
}
2007-11-06 09:26:10 +00:00
data . Append ( "textures " ) ; data . Append ( Textures . Count ) ; data . Append ( NL ) ;
2008-07-25 05:15:05 +00:00
foreach ( KeyValuePair < AppearanceManager . TextureIndex , UUID > texture in Textures )
2007-08-25 09:36:33 +00:00
{
2007-11-30 13:15:31 +00:00
data . Append ( texture . Key ) ; data . Append ( " " ) ; data . Append ( texture . Value . ToString ( ) ) ; data . Append ( NL ) ;
2007-08-25 09:36:33 +00:00
}
2008-08-12 22:38:02 +00:00
AssetData = Utils . StringToBytes ( data . ToString ( ) ) ;
2007-08-25 09:36:33 +00:00
}
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents an <seealso cref="AssetWearable"/> that can be worn on an avatar
/// such as a Shirt, Pants, etc.
/// </summary>
2007-08-25 09:36:33 +00:00
public class AssetClothing : AssetWearable
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2007-08-25 09:36:33 +00:00
public override AssetType AssetType { get { return AssetType . Clothing ; } }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetScriptBinary object</summary>
2007-08-25 09:36:33 +00:00
public AssetClothing ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetScriptBinary object with parameters</summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetClothing ( UUID assetID , byte [ ] assetData ) : base ( assetID , assetData ) { }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetScriptBinary object with parameters</summary>
/// <param name="source">A string containing the Clothings data</param>
2007-08-25 09:36:33 +00:00
public AssetClothing ( string source ) : base ( source ) { }
}
2009-03-19 01:25:28 +00:00
/// <summary>
/// Represents an <seealso cref="AssetWearable"/> that represents an avatars body ie: Hair, Etc.
/// </summary>
2007-08-25 09:36:33 +00:00
public class AssetBodypart : AssetWearable
{
2009-03-19 01:25:28 +00:00
/// <summary>Override the base classes AssetType</summary>
2007-08-25 09:36:33 +00:00
public override AssetType AssetType { get { return AssetType . Bodypart ; } }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetBodyPart object</summary>
2007-08-25 09:36:33 +00:00
public AssetBodypart ( ) { }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetBodyPart object with parameters</summary>
/// <param name="assetID">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
2008-08-20 22:46:28 +00:00
public AssetBodypart ( UUID assetID , byte [ ] assetData ) : base ( assetID , assetData ) { }
2009-03-19 01:25:28 +00:00
/// <summary>Initializes a new instance of an AssetBodyPart object with parameters</summary>
/// <param name="source">A string representing the values of the Bodypart</param>
2007-08-25 09:36:33 +00:00
public AssetBodypart ( string source ) : base ( source ) { }
2007-08-10 20:16:19 +00:00
}
2007-07-15 22:03:59 +00:00
}