aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs81
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs1
2 files changed, 49 insertions, 33 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs
index 390c2f9..c113a43 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs
@@ -50,10 +50,11 @@ public struct MaterialAttributes
50 Avatar, 50 Avatar,
51 NumberOfTypes // the count of types in the enum. 51 NumberOfTypes // the count of types in the enum.
52 } 52 }
53
53 // Names must be in the order of the above enum. 54 // Names must be in the order of the above enum.
54 public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", 55 // These names must coorespond to the lower case field names in the MaterialAttributes
55 "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; 56 // structure as reflection is used to select the field to put the value in.
56 public static string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; 57 public static readonly string[] MaterialAttribs = { "Density", "Friction", "Restitution"};
57 58
58 public MaterialAttributes(string t, float d, float f, float r) 59 public MaterialAttributes(string t, float d, float f, float r)
59 { 60 {
@@ -70,60 +71,74 @@ public struct MaterialAttributes
70 71
71public static class BSMaterials 72public static class BSMaterials
72{ 73{
73 public static MaterialAttributes[] Attributes; 74 // Attributes for each material type
75 private static readonly MaterialAttributes[] Attributes;
76
77 // Map of material name to material type code
78 public static readonly Dictionary<string, MaterialAttributes.Material> MaterialMap;
74 79
75 static BSMaterials() 80 static BSMaterials()
76 { 81 {
77 // Attribute sets for both the non-physical and physical instances of materials. 82 // Attribute sets for both the non-physical and physical instances of materials.
78 Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; 83 Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2];
84
85 // Map of name to type code.
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);
79 } 96 }
80 97
81 // This is where all the default material attributes are defined. 98 // This is where all the default material attributes are defined.
82 public static void InitializeFromDefaults(ConfigurationParameters parms) 99 public static void InitializeFromDefaults(ConfigurationParameters parms)
83 { 100 {
84 // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL 101 // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL
85 // public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", 102 float dDensity = parms.defaultDensity;
86 // "Flesh", "Plastic", "Rubber", "Light", "Avatar" };
87 float dFriction = parms.defaultFriction; 103 float dFriction = parms.defaultFriction;
88 float dRestitution = parms.defaultRestitution; 104 float dRestitution = parms.defaultRestitution;
89 float dDensity = parms.defaultDensity;
90 Attributes[(int)MaterialAttributes.Material.Stone] = 105 Attributes[(int)MaterialAttributes.Material.Stone] =
91 new MaterialAttributes("stone",dDensity, 0.8f, 0.4f); 106 new MaterialAttributes("stone",dDensity, 0.8f, 0.4f);
92 Attributes[(int)MaterialAttributes.Material.Metal] = 107 Attributes[(int)MaterialAttributes.Material.Metal] =
93 new MaterialAttributes("metal",dDensity, 0.3f, 0.4f); 108 new MaterialAttributes("metal",dDensity, 0.3f, 0.4f);
94 Attributes[(int)MaterialAttributes.Material.Glass] = 109 Attributes[(int)MaterialAttributes.Material.Glass] =
95 new MaterialAttributes("glass",dDensity, 0.2f, 0.7f); 110 new MaterialAttributes("glass",dDensity, 0.2f, 0.7f);
96 Attributes[(int)MaterialAttributes.Material.Wood] = 111 Attributes[(int)MaterialAttributes.Material.Wood] =
97 new MaterialAttributes("wood",dDensity, 0.6f, 0.5f); 112 new MaterialAttributes("wood",dDensity, 0.6f, 0.5f);
98 Attributes[(int)MaterialAttributes.Material.Flesh] = 113 Attributes[(int)MaterialAttributes.Material.Flesh] =
99 new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f); 114 new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f);
100 Attributes[(int)MaterialAttributes.Material.Plastic] = 115 Attributes[(int)MaterialAttributes.Material.Plastic] =
101 new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f); 116 new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f);
102 Attributes[(int)MaterialAttributes.Material.Rubber] = 117 Attributes[(int)MaterialAttributes.Material.Rubber] =
103 new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f); 118 new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f);
104 Attributes[(int)MaterialAttributes.Material.Light] = 119 Attributes[(int)MaterialAttributes.Material.Light] =
105 new MaterialAttributes("light",dDensity, dFriction, dRestitution); 120 new MaterialAttributes("light",dDensity, dFriction, dRestitution);
106 Attributes[(int)MaterialAttributes.Material.Avatar] = 121 Attributes[(int)MaterialAttributes.Material.Avatar] =
107 new MaterialAttributes("avatar",60f, 0.2f, 0f); 122 new MaterialAttributes("avatar",60f, 0.2f, 0f);
108 123
109 Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = 124 Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] =
110 new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); 125 new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f);
111 Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = 126 Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] =
112 new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f); 127 new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f);
113 Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = 128 Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] =
114 new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f); 129 new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f);
115 Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = 130 Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] =
116 new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f); 131 new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f);
117 Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = 132 Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] =
118 new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f); 133 new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f);
119 Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = 134 Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] =
120 new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f); 135 new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f);
121 Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = 136 Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] =
122 new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f); 137 new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f);
123 Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = 138 Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] =
124 new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); 139 new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution);
125 Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = 140 Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] =
126 new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f); 141 new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f);
127 } 142 }
128 143
129 // Under the [BulletSim] section, one can change the individual material 144 // Under the [BulletSim] section, one can change the individual material
@@ -139,34 +154,34 @@ public static class BSMaterials
139 // the physical value. 154 // the physical value.
140 public static void InitializefromParameters(IConfig pConfig) 155 public static void InitializefromParameters(IConfig pConfig)
141 { 156 {
142 int matType = 0; 157 foreach (KeyValuePair<string, MaterialAttributes.Material> kvp in MaterialMap)
143 foreach (string matName in MaterialAttributes.MaterialNames)
144 { 158 {
159 string matName = kvp.Key;
145 foreach (string attribName in MaterialAttributes.MaterialAttribs) 160 foreach (string attribName in MaterialAttributes.MaterialAttribs)
146 { 161 {
147 string paramName = matName + attribName; 162 string paramName = matName + attribName;
148 if (pConfig.Contains(paramName)) 163 if (pConfig.Contains(paramName))
149 { 164 {
150 float paramValue = pConfig.GetFloat(paramName); 165 float paramValue = pConfig.GetFloat(paramName);
151 SetAttributeValue(matType, attribName, paramValue); 166 SetAttributeValue((int)kvp.Value, attribName, paramValue);
152 // set the physical value also 167 // set the physical value also
153 SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); 168 SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
154 } 169 }
155 paramName += "Physical"; 170 paramName += "Physical";
156 if (pConfig.Contains(paramName)) 171 if (pConfig.Contains(paramName))
157 { 172 {
158 float paramValue = pConfig.GetFloat(paramName); 173 float paramValue = pConfig.GetFloat(paramName);
159 SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); 174 SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
160 } 175 }
161 } 176 }
162 matType++;
163 } 177 }
164 } 178 }
165 179
180 // Use reflection to set the value in the attribute structure.
166 private static void SetAttributeValue(int matType, string attribName, float val) 181 private static void SetAttributeValue(int matType, string attribName, float val)
167 { 182 {
168 MaterialAttributes thisAttrib = Attributes[matType]; 183 MaterialAttributes thisAttrib = Attributes[matType];
169 FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName); 184 FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName.ToLower());
170 if (fieldInfo != null) 185 if (fieldInfo != null)
171 { 186 {
172 fieldInfo.SetValue(thisAttrib, val); 187 fieldInfo.SetValue(thisAttrib, val);
@@ -174,12 +189,12 @@ public static class BSMaterials
174 } 189 }
175 } 190 }
176 191
192 // Given a material type, return a structure of attributes.
177 public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical) 193 public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical)
178 { 194 {
179 int ind = (int)type; 195 int ind = (int)type;
180 if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes; 196 if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes;
181 return Attributes[ind]; 197 return Attributes[ind];
182 } 198 }
183
184} 199}
185} 200}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index f4f2801..cf5bb57 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -309,6 +309,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
309 BSMaterials.InitializeFromDefaults(Params); 309 BSMaterials.InitializeFromDefaults(Params);
310 if (pConfig != null) 310 if (pConfig != null)
311 { 311 {
312 // Let the user add new and interesting material property values.
312 BSMaterials.InitializefromParameters(pConfig); 313 BSMaterials.InitializefromParameters(pConfig);
313 } 314 }
314 } 315 }