Added color and alpha blending/bump information to VisualParams (towards LIBOMV-658)

git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3047 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Latif Khalifa
2009-08-02 07:16:11 +00:00
parent 79684bd8eb
commit 4fbfbc83d6
3 changed files with 650 additions and 414 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
namespace VisualParamGenerator
@@ -75,6 +76,9 @@ namespace VisualParamGenerator
}
SortedList<int, string> IDs = new SortedList<int, string>();
Dictionary<int, string> Alphas = new Dictionary<int, string>();
Dictionary<int, string> Colors = new Dictionary<int, string>();
StringWriter output = new StringWriter();
// Make sure we end up with 218 Group-0 VisualParams as a sanity check
@@ -107,6 +111,81 @@ namespace VisualParamGenerator
{
int id = Int32.Parse(node.Attributes["id"].Value);
if (node.HasChildNodes)
{
for (int nodeNr = 0; nodeNr < node.ChildNodes.Count; nodeNr++)
{
#region Alpha mask and bumps
if (node.ChildNodes[nodeNr].Name == "param_alpha")
{
XmlNode anode = node.ChildNodes[nodeNr];
string tga_file = "string.Empty";
string skip_if_zero = "false";
string multiply_blend = "false";
string domain = "0";
if (anode.Attributes["domain"] != null)
domain = anode.Attributes["domain"].Value;
if (anode.Attributes["tga_file"] != null)
tga_file = string.Format("\"{0}\"", anode.Attributes["tga_file"].Value); ;
if (anode.Attributes["skip_if_zero"] != null && anode.Attributes["skip_if_zero"].Value == "true")
skip_if_zero = "true";
if (anode.Attributes["multiply_blend"] != null && anode.Attributes["multiply_blend"].Value == "true")
multiply_blend = "true";
Alphas.Add(id, string.Format("new VisualAlphaParam({0}f, {1}, {2}, {3})", domain, tga_file, skip_if_zero, multiply_blend));
}
#endregion
#region Colors
else if (node.ChildNodes[nodeNr].Name == "param_color" && node.ChildNodes[nodeNr].HasChildNodes)
{
XmlNode cnode = node.ChildNodes[nodeNr];
string operation = "VisualColorOperation.None";
List<string> colors = new List<string>();
if (cnode.Attributes["operation"] != null)
{
switch (cnode.Attributes["operation"].Value)
{
case "blend":
operation = "VisualColorOperation.Blend";
break;
case "multiply":
operation = "VisualColorOperation.Blend";
break;
}
}
foreach (XmlNode cvalue in cnode.ChildNodes)
{
if (cvalue.Name == "value" && cvalue.Attributes["color"] != null)
{
Match m = Regex.Match(cvalue.Attributes["color"].Value, @"((?<val>\d+)(?:, *)?){4}");
if (!m.Success)
{
continue;
}
CaptureCollection val = m.Groups["val"].Captures;
colors.Add(string.Format("System.Drawing.Color.FromArgb({0}, {1}, {2}, {3})", val[3], val[0], val[1], val[2]));
}
}
if (colors.Count > 0)
{
string colorsStr = string.Join(", ", colors.ToArray());
Colors.Add(id, string.Format("new VisualColorParam({0}, new System.Drawing.Color[] {{ {1} }})", operation, colorsStr));
}
}
#endregion
}
}
// Check for duplicates
if (IDs.ContainsKey(id))
continue;
@@ -143,8 +222,8 @@ namespace VisualParamGenerator
def = min;
IDs.Add(id,
String.Format(" Params[{0}] = new VisualParam({0}, \"{1}\", {2}, {3}, {4}, {5}, {6}, {7}f, {8}f, {9}f);{10}",
id, name, group, wearable, label, label_min, label_max, def, min, max, Environment.NewLine));
String.Format(" Params[{0}] = new VisualParam({0}, \"{1}\", {2}, {3}, {4}, {5}, {6}, {7}f, {8}f, {9}f, ",
id, name, group, wearable, label, label_min, label_max, def, min, max));
if (group == 0)
++count;
@@ -158,14 +237,35 @@ namespace VisualParamGenerator
if (count != 218)
{
Console.WriteLine("Ended up with the wrong number of Group-8 VisualParams! Exiting...");
Console.WriteLine("Ended up with the wrong number of Group-0 VisualParams! Exiting...");
return;
}
// Now that we've collected all the entries and sorted them, add them to our output buffer
foreach (string line in IDs.Values)
foreach (KeyValuePair<int, string> line in IDs)
{
output.Write(line);
output.Write(line.Value);
if (Alphas.ContainsKey(line.Key))
{
output.Write(Alphas[line.Key] + ", ");
}
else
{
output.Write("null, ");
}
if (Colors.ContainsKey(line.Key))
{
output.Write(Colors[line.Key]);
}
else
{
output.Write("null");
}
output.WriteLine(");");
}
output.Write(" }" + Environment.NewLine);

View File

@@ -1,8 +1,71 @@
using System;
using System.Collections.Generic;
namespace libsecondlife
namespace OpenMetaverse
{
/// <summary>
/// Operation to apply when applying color to texture
/// </summary>
public enum VisualColorOperation
{
None,
Blend,
Multiply
}
/// <summary>
/// Information needed to translate visual param value to RGBA color
/// </summary>
public struct VisualColorParam
{
public VisualColorOperation Operation;
public System.Drawing.Color[] Colors;
/// <summary>
/// Construct VisualColorParam
/// </summary>
/// <param name="operation">Operation to apply when applying color to texture</param>
/// <param name="colors">Colors</param>
public VisualColorParam(VisualColorOperation operation, System.Drawing.Color[] colors)
{
Operation = operation;
Colors = colors;
}
}
/// <summary>
/// Represents alpha blending and bump infor for a visual parameter
/// such as sleive length
/// </summary>
public struct VisualAlphaParam
{
/// <summary>Stregth of the alpha to apply</summary>
public float Domain;
/// <summary>File containing the alpha channel</summary>
public string TGAFile;
/// <summary>Skip blending if parameter value is 0</summary>
public bool SkipIfZero;
/// <summary>Use miltiply insted of alpha blending</summary>
public bool MultiplyBlend;
/// <summary>
/// Create new alhpa information for a visual param
/// </summary>
/// <param name="domain">Stregth of the alpha to apply</param>
/// <param name="tgaFile">File containing the alpha channel</param>
/// <param name="skipIfZero">Skip blending if parameter value is 0</param>
/// <param name="multiplyBlend">Use miltiply insted of alpha blending</param>
public VisualAlphaParam(float domain, string tgaFile, bool skipIfZero, bool multiplyBlend)
{
Domain = domain;
TGAFile = tgaFile;
SkipIfZero = skipIfZero;
MultiplyBlend = multiplyBlend;
}
}
/// <summary>
/// A single visual characteristic of an avatar mesh, such as eyebrow height
/// </summary>
@@ -28,7 +91,10 @@ namespace libsecondlife
public float MinValue;
/// <summary>Maximum value</summary>
public float MaxValue;
/// <summary>Alpha blending/bump info</summary>
public VisualAlphaParam? AlphaParams;
/// <summary>Color information</summary>
public VisualColorParam? ColorParams;
/// <summary>
/// Set all the values through the constructor
/// </summary>
@@ -42,7 +108,7 @@ namespace libsecondlife
/// <param name="def">Default value</param>
/// <param name="min">Minimum value</param>
/// <param name="max">Maximum value</param>
public VisualParam(int paramID, string name, int group, string wearable, string label, string labelMin, string labelMax, float def, float min, float max)
public VisualParam(int paramID, string name, int group, string wearable, string label, string labelMin, string labelMax, float def, float min, float max, VisualAlphaParam? alpha, VisualColorParam? colorParams)
{
ParamID = paramID;
Name = name;
@@ -54,6 +120,8 @@ namespace libsecondlife
DefaultValue = def;
MaxValue = max;
MinValue = min;
AlphaParams = alpha;
ColorParams = colorParams;
}
}
@@ -62,6 +130,8 @@ namespace libsecondlife
/// </summary>
public static class VisualParams
{
public static SortedList<int, VisualParam> Params = new SortedList<int, VisualParam>();
public static VisualParam Find(string name, string wearable)
{
foreach (KeyValuePair<int, VisualParam> param in Params)
@@ -71,7 +141,5 @@ namespace libsecondlife
return new VisualParam();
}
public static SortedList<int, VisualParam> Params = new SortedList<int, VisualParam>();
static VisualParams()
{