BulletSim: add values for material friction and restitution. Fix line endings in material definition file.

0.7.5-pf-bulletsim
Robert Adams 2012-12-06 06:45:51 -08:00
parent 6d7f66f781
commit 2ecd8e6720
1 changed files with 185 additions and 191 deletions

View File

@ -1,191 +1,185 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyrightD * * Redistributions in binary form must reproduce the above copyrightD
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the * * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Reflection; using System.Reflection;
using Nini.Config; using Nini.Config;
namespace OpenSim.Region.Physics.BulletSPlugin namespace OpenSim.Region.Physics.BulletSPlugin
{ {
public struct MaterialAttributes public struct MaterialAttributes
{ {
// Material type values that correspond with definitions for LSL // Material type values that correspond with definitions for LSL
public enum Material : int public enum Material : int
{ {
Stone = 0, Stone = 0,
Metal, Metal,
Glass, Glass,
Wood, Wood,
Flesh, Flesh,
Plastic, Plastic,
Rubber, Rubber,
Light, Light,
// Hereafter are BulletSim additions // Hereafter are BulletSim additions
Avatar, Avatar,
NumberOfTypes // the count of types in the enum. NumberOfTypes // the count of types in the enum.
} }
// Names must be in the order of the above enum. // Names must be in the order of the above enum.
public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood",
"Flesh", "Plastic", "Rubber", "Light", "Avatar" }; "Flesh", "Plastic", "Rubber", "Light", "Avatar" };
public static string[] MaterialAttribs = { "Density", "Friction", "Restitution", public static string[] MaterialAttribs = { "Density", "Friction", "Restitution"};
"ccdMotionThreshold", "ccdSweptSphereRadius" };
public MaterialAttributes(string t, float d, float f, float r)
public MaterialAttributes(string t, float d, float f, float r, float ccdM, float ccdS) {
{ type = t;
type = t; density = d;
density = d; friction = f;
friction = f; restitution = r;
restitution = r; }
ccdMotionThreshold = ccdM; public string type;
ccdSweptSphereRadius = ccdS; public float density;
} public float friction;
public string type; public float restitution;
public float density; }
public float friction;
public float restitution; public static class BSMaterials
public float ccdMotionThreshold; {
public float ccdSweptSphereRadius; public static MaterialAttributes[] Attributes;
}
static BSMaterials()
public static class BSMaterials {
{ // Attribute sets for both the non-physical and physical instances of materials.
public static MaterialAttributes[] Attributes; Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2];
}
static BSMaterials()
{ // This is where all the default material attributes are defined.
// Attribute sets for both the non-physical and physical instances of materials. public static void InitializeFromDefaults(ConfigurationParameters parms)
Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; {
} // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL
// public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood",
// This is where all the default material attributes are defined. // "Flesh", "Plastic", "Rubber", "Light", "Avatar" };
public static void InitializeFromDefaults(ConfigurationParameters parms) float dFriction = parms.defaultFriction;
{ float dRestitution = parms.defaultRestitution;
// public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", float dDensity = parms.defaultDensity;
// "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; Attributes[(int)MaterialAttributes.Material.Stone] =
float dFriction = parms.defaultFriction; new MaterialAttributes("stone",dDensity, 0.8f, 0.4f);
float dRestitution = parms.defaultRestitution; Attributes[(int)MaterialAttributes.Material.Metal] =
float dDensity = parms.defaultDensity; new MaterialAttributes("metal",dDensity, 0.3f, 0.4f);
float dCcdM = parms.ccdMotionThreshold; Attributes[(int)MaterialAttributes.Material.Glass] =
float dCcdS = parms.ccdSweptSphereRadius; new MaterialAttributes("glass",dDensity, 0.2f, 0.7f);
Attributes[(int)MaterialAttributes.Material.Stone] = Attributes[(int)MaterialAttributes.Material.Wood] =
new MaterialAttributes("stone",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("wood",dDensity, 0.6f, 0.5f);
Attributes[(int)MaterialAttributes.Material.Metal] = Attributes[(int)MaterialAttributes.Material.Flesh] =
new MaterialAttributes("metal",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f);
Attributes[(int)MaterialAttributes.Material.Glass] = Attributes[(int)MaterialAttributes.Material.Plastic] =
new MaterialAttributes("glass",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f);
Attributes[(int)MaterialAttributes.Material.Wood] = Attributes[(int)MaterialAttributes.Material.Rubber] =
new MaterialAttributes("wood",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f);
Attributes[(int)MaterialAttributes.Material.Flesh] = Attributes[(int)MaterialAttributes.Material.Light] =
new MaterialAttributes("flesh",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("light",dDensity, dFriction, dRestitution);
Attributes[(int)MaterialAttributes.Material.Plastic] = Attributes[(int)MaterialAttributes.Material.Avatar] =
new MaterialAttributes("plastic",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("avatar",60f, 0.2f, 0f);
Attributes[(int)MaterialAttributes.Material.Rubber] =
new MaterialAttributes("rubber",dDensity,dFriction,dRestitution, dCcdM, dCcdS); Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] =
Attributes[(int)MaterialAttributes.Material.Light] = new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f);
new MaterialAttributes("light",dDensity,dFriction,dRestitution, dCcdM, dCcdS); Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] =
Attributes[(int)MaterialAttributes.Material.Avatar] = new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f);
new MaterialAttributes("avatar",dDensity,dFriction,dRestitution, dCcdM, dCcdS); Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f);
Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("stonePhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f);
Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("metalPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f);
Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("glassPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f);
Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("woodPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f);
Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("fleshPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution);
Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("plasticPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f);
Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = }
new MaterialAttributes("rubberPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS);
Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = // Under the [BulletSim] section, one can change the individual material
new MaterialAttributes("lightPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); // attribute values. The format of the configuration parameter is:
Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = // <materialName><Attribute>["Physical"] = floatValue
new MaterialAttributes("avatarPhysical",dDensity,dFriction,dRestitution, dCcdM, dCcdS); // For instance:
} // [BulletSim]
// StoneFriction = 0.2
// Under the [BulletSim] section, one can change the individual material // FleshRestitutionPhysical = 0.8
// attribute values. The format of the configuration parameter is: // Materials can have different parameters for their static and
// <materialName><Attribute>["Physical"] = floatValue // physical instantiations. When setting the non-physical value,
// For instance: // both values are changed. Setting the physical value only changes
// [BulletSim] // the physical value.
// StoneFriction = 0.2 public static void InitializefromParameters(IConfig pConfig)
// FleshRestitutionPhysical = 0.8 {
// Materials can have different parameters for their static and int matType = 0;
// physical instantiations. When setting the non-physical value, foreach (string matName in MaterialAttributes.MaterialNames)
// both values are changed. Setting the physical value only changes {
// the physical value. foreach (string attribName in MaterialAttributes.MaterialAttribs)
public static void InitializefromParameters(IConfig pConfig) {
{ string paramName = matName + attribName;
int matType = 0; if (pConfig.Contains(paramName))
foreach (string matName in MaterialAttributes.MaterialNames) {
{ float paramValue = pConfig.GetFloat(paramName);
foreach (string attribName in MaterialAttributes.MaterialAttribs) SetAttributeValue(matType, attribName, paramValue);
{ // set the physical value also
string paramName = matName + attribName; SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
if (pConfig.Contains(paramName)) }
{ paramName += "Physical";
float paramValue = pConfig.GetFloat(paramName); if (pConfig.Contains(paramName))
SetAttributeValue(matType, attribName, paramValue); {
// set the physical value also float paramValue = pConfig.GetFloat(paramName);
SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
} }
paramName += "Physical"; }
if (pConfig.Contains(paramName)) matType++;
{ }
float paramValue = pConfig.GetFloat(paramName); }
SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
} private static void SetAttributeValue(int matType, string attribName, float val)
} {
matType++; MaterialAttributes thisAttrib = Attributes[matType];
} FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName);
} if (fieldInfo != null)
{
private static void SetAttributeValue(int matType, string attribName, float val) fieldInfo.SetValue(thisAttrib, val);
{ Attributes[matType] = thisAttrib;
MaterialAttributes thisAttrib = Attributes[matType]; }
FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName); }
if (fieldInfo != null)
{ public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical)
fieldInfo.SetValue(thisAttrib, val); {
Attributes[matType] = thisAttrib; int ind = (int)type;
} if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes;
} return Attributes[ind];
}
public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical)
{ }
int ind = (int)type; }
if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes;
return Attributes[ind];
}
}
}