28 using System.Collections.Generic;
30 using System.Reflection;
33 namespace OpenSim.
Region.PhysicsModule.BulletS
57 public static readonly
string[] MaterialAttribs = {
"Density",
"Friction",
"Restitution"};
72 public static class BSMaterials
86 MaterialMap =
new Dictionary<string, MaterialAttributes.Material>();
87 MaterialMap.Add(
"Stone", MaterialAttributes.Material.Stone);
88 MaterialMap.Add(
"Metal", MaterialAttributes.Material.Metal);
89 MaterialMap.Add(
"Glass", MaterialAttributes.Material.Glass);
90 MaterialMap.Add(
"Wood", MaterialAttributes.Material.Wood);
91 MaterialMap.Add(
"Flesh", MaterialAttributes.Material.Flesh);
92 MaterialMap.Add(
"Plastic", MaterialAttributes.Material.Plastic);
93 MaterialMap.Add(
"Rubber", MaterialAttributes.Material.Rubber);
94 MaterialMap.Add(
"Light", MaterialAttributes.Material.Light);
95 MaterialMap.Add(
"Avatar", MaterialAttributes.Material.Avatar);
99 public static void InitializeFromDefaults(ConfigurationParameters parms)
102 float dDensity = parms.defaultDensity;
103 float dFriction = parms.defaultFriction;
104 float dRestitution = parms.defaultRestitution;
105 Attributes[(int)MaterialAttributes.Material.Stone] =
106 new MaterialAttributes(
"stone",dDensity, 0.8f, 0.4f);
107 Attributes[(int)MaterialAttributes.Material.Metal] =
108 new MaterialAttributes(
"metal",dDensity, 0.3f, 0.4f);
109 Attributes[(int)MaterialAttributes.Material.Glass] =
110 new MaterialAttributes(
"glass",dDensity, 0.2f, 0.7f);
111 Attributes[(int)MaterialAttributes.Material.Wood] =
112 new MaterialAttributes(
"wood",dDensity, 0.6f, 0.5f);
113 Attributes[(int)MaterialAttributes.Material.Flesh] =
114 new MaterialAttributes(
"flesh",dDensity, 0.9f, 0.3f);
115 Attributes[(int)MaterialAttributes.Material.Plastic] =
116 new MaterialAttributes(
"plastic",dDensity, 0.4f, 0.7f);
117 Attributes[(int)MaterialAttributes.Material.Rubber] =
118 new MaterialAttributes(
"rubber",dDensity, 0.9f, 0.9f);
119 Attributes[(int)MaterialAttributes.Material.Light] =
120 new MaterialAttributes(
"light",dDensity, dFriction, dRestitution);
121 Attributes[(int)MaterialAttributes.Material.Avatar] =
122 new MaterialAttributes(
"avatar",3.5f, 0.2f, 0f);
124 Attributes[(int)MaterialAttributes.Material.Stone + (
int)MaterialAttributes.Material.NumberOfTypes] =
125 new MaterialAttributes(
"stonePhysical",dDensity, 0.8f, 0.4f);
126 Attributes[(int)MaterialAttributes.Material.Metal + (
int)MaterialAttributes.Material.NumberOfTypes] =
127 new MaterialAttributes(
"metalPhysical",dDensity, 0.3f, 0.4f);
128 Attributes[(int)MaterialAttributes.Material.Glass + (
int)MaterialAttributes.Material.NumberOfTypes] =
129 new MaterialAttributes(
"glassPhysical",dDensity, 0.2f, 0.7f);
130 Attributes[(int)MaterialAttributes.Material.Wood + (
int)MaterialAttributes.Material.NumberOfTypes] =
131 new MaterialAttributes(
"woodPhysical",dDensity, 0.6f, 0.5f);
132 Attributes[(int)MaterialAttributes.Material.Flesh + (
int)MaterialAttributes.Material.NumberOfTypes] =
133 new MaterialAttributes(
"fleshPhysical",dDensity, 0.9f, 0.3f);
134 Attributes[(int)MaterialAttributes.Material.Plastic + (
int)MaterialAttributes.Material.NumberOfTypes] =
135 new MaterialAttributes(
"plasticPhysical",dDensity, 0.4f, 0.7f);
136 Attributes[(int)MaterialAttributes.Material.Rubber + (
int)MaterialAttributes.Material.NumberOfTypes] =
137 new MaterialAttributes(
"rubberPhysical",dDensity, 0.9f, 0.9f);
138 Attributes[(int)MaterialAttributes.Material.Light + (
int)MaterialAttributes.Material.NumberOfTypes] =
139 new MaterialAttributes(
"lightPhysical",dDensity, dFriction, dRestitution);
140 Attributes[(int)MaterialAttributes.Material.Avatar + (
int)MaterialAttributes.Material.NumberOfTypes] =
141 new MaterialAttributes(
"avatarPhysical",3.5f, 0.2f, 0f);
155 public static void InitializefromParameters(IConfig pConfig)
157 foreach (KeyValuePair<string, MaterialAttributes.Material> kvp
in MaterialMap)
159 string matName = kvp.Key;
160 foreach (
string attribName
in MaterialAttributes.MaterialAttribs)
162 string paramName = matName + attribName;
163 if (pConfig.Contains(paramName))
165 float paramValue = pConfig.GetFloat(paramName);
166 SetAttributeValue((
int)kvp.Value, attribName, paramValue);
168 SetAttributeValue((
int)kvp.Value + (
int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
170 paramName +=
"Physical";
171 if (pConfig.Contains(paramName))
173 float paramValue = pConfig.GetFloat(paramName);
174 SetAttributeValue((
int)kvp.Value + (
int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
181 private static void SetAttributeValue(
int matType,
string attribName,
float val)
184 MaterialAttributes thisAttrib = Attributes[matType];
186 FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName.ToLower());
187 if (fieldInfo != null)
189 fieldInfo.SetValue(thisAttrib, val);
191 Attributes[matType] = thisAttrib;
196 public static MaterialAttributes GetAttributes(MaterialAttributes.Material type,
bool isPhysical)
199 if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes;
200 return Attributes[ind];
MaterialAttributes(string t, float d, float f, float r)