/// <summary> /// Creates a new PhysX.RigidDynamic using our defaults /// </summary> /// <param name="shape"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <returns></returns> public static PhysX.RigidDynamic CreateRigidDynamic(PhysxScene scene, PhysicsShape shape, OpenMetaverse.Vector3 position, OpenMetaverse.Quaternion rotation, bool physical, bool kinematic, Material material) { PhysX.RigidDynamic physActor = scene.SceneImpl.Physics.CreateRigidDynamic(); if (kinematic) physActor.Flags |= PhysX.RigidDynamicFlags.Kinematic; SetCommonProperties(scene, shape, position, rotation, physActor, physical, material); if (physical) { physActor.UpdateMassAndInertia(material.Density); physActor.MaxAngularVelocity *= 4; physActor.AngularDamping = DEFAULT_ANGULAR_DAMPING; physActor.LinearDamping = DEFAULT_LINEAR_DAMPING; } physActor.SleepThreshold = SLEEP_THRESHOLD; return physActor; }
private void ReplaceMaterialOnShapes(Material material, PhysxPrim affectedPrim, IEnumerable<PhysX.Shape> shapes) { Material oldMaterial = affectedPrim.PhysxProperties.PhysxMaterial; affectedPrim.PhysxProperties.PhysxMaterial = material; PhysX.Material[] materialArr = new PhysX.Material[] { material.PhyMaterial }; foreach (PhysX.Shape shape in shapes) { shape.SetMaterials(materialArr); } if (oldMaterial.Density != material.Density) UpdateMassAndInertia(); oldMaterial.CheckedDispose(); }
private void ReplaceMaterialOnAllShapes(Material material) { //place the primary copy of this material on the root prim ReplaceMaterialOnShapes(material, this, _primaryShapes); //duplicate the material for each child prim shape foreach (var childShape in _childShapes) { ReplaceMaterialOnShapes(material.Duplicate(_scene.SceneImpl.Physics), childShape.Key, childShape.Value.PhyShapes); } }
/// <summary> /// Sets the given prim in our linkset to the given material /// </summary> /// <param name="material"></param> /// <param name="affectedPrim"></param> private void SetMaterialSync(Material material, PhysxPrim affectedPrim, bool applyToObject) { IEnumerable<PhysX.Shape> shapes; if (applyToObject) { ReplaceMaterialOnAllShapes(material); return; } if (affectedPrim == this) { shapes = _actor.Shapes; } else { RelatedShapes childShapes; if (_childShapes.TryGetValue(affectedPrim, out childShapes)) { shapes = childShapes.PhyShapes; } else { m_log.ErrorFormat("[InWorldz.PhysxPhysics] Asked to set material for unknown child shape"); return; } } ReplaceMaterialOnShapes(material, affectedPrim, shapes); }
/// <summary> /// Sets our root prim or one of our children to the given material /// </summary> /// <param name="material">The material to set</param> /// <param name="applyToObject">Whether the material applies to the entire object or just this prim</param> internal void SetMaterialSync(Material material, bool applyToObject) { if (HasActor) { SetMaterialSync(material, this, applyToObject); } else { _parentPrim.SetMaterialSync(material, this, applyToObject); } }
public static void BuiltinMaterialInit(PhysX.Physics physics) { // PhysX collision forces are very strong, so the ground restitution needs to be lowered significantly. GROUND = new Material(physics.CreateMaterial(0.4f, 0.35f, 0.05f), 1200.0f); GROUND.IsShared = true; // For navigable roads, people need a preset that acts mostly like ground. STONE = new Material(physics.CreateMaterial(0.5f, 0.35f, 0.05f), 2400.0f, (int)OpenMetaverse.Material.Stone); STONE.IsShared = true; METAL = new Material(physics.CreateMaterial(0.3f, 0.25f, 0.4f), 2700.0f, (int)OpenMetaverse.Material.Metal); METAL.IsShared = true; GLASS = new Material(physics.CreateMaterial(0.2f, 0.15f, 0.7f), 2500.0f, (int)OpenMetaverse.Material.Glass); GLASS.IsShared = true; WOOD = new Material(physics.CreateMaterial(0.6f, 0.55f, 0.5f), 1000.0f, (int)OpenMetaverse.Material.Wood); WOOD.IsShared = true; FLESH = new Material(physics.CreateMaterial(0.9f, 0.8f, 0.3f), 1400.0f, (int)OpenMetaverse.Material.Flesh); FLESH.IsShared = true; PLASTIC = new Material(physics.CreateMaterial(0.4f, 0.35f, 0.7f), 900.0f, (int)OpenMetaverse.Material.Plastic); PLASTIC.IsShared = true; RUBBER = new Material(physics.CreateMaterial(0.9f, 0.87f, 0.9f), 1100.0f, (int)OpenMetaverse.Material.Rubber); RUBBER.IsShared = true; MaterialsByOMVEnum = new Material[] { STONE, //0... METAL, GLASS, WOOD, FLESH, PLASTIC, RUBBER, WOOD //light.. which makes no sense is remapped to wood }; }
private static void SetCommonProperties(PhysxScene scene, PhysicsShape shape, OpenMetaverse.Vector3 position, OpenMetaverse.Quaternion rotation, PhysX.RigidActor physActor, bool physical, Material material) { shape.AssignToActor(physActor, material.PhyMaterial, physical); physActor.GlobalPose = PhysX.Math.Matrix.RotationQuaternion(new PhysX.Math.Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W)) * PhysX.Math.Matrix.Translation(position.X, position.Y, position.Z); }
/// <summary> /// Creates a new PhysX.RigidStatic using our defaults /// </summary> /// <param name="shape"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <returns></returns> public static PhysX.RigidStatic CreateRigidStatic(PhysxScene scene, PhysicsShape shape, OpenMetaverse.Vector3 position, OpenMetaverse.Quaternion rotation, Material material) { PhysX.RigidStatic physActor = scene.SceneImpl.Physics.CreateRigidStatic(); SetCommonProperties(scene, shape, position, rotation, physActor, false, material); return physActor; }
public static PhysX.RigidActor CreateProperInitialActor(PhysicsShape meshedShape, PhysxScene scene, OpenMetaverse.Vector3 pos, OpenMetaverse.Quaternion rotation, PhysicsScene.AddPrimShapeFlags flags, out bool kinematicStatic, Material material) { bool isPhysical = (flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0; kinematicStatic = false; PhysX.RigidActor actor; if (isPhysical) { actor = PhysxActorFactory.CreateRigidDynamic(scene, meshedShape, pos, rotation, isPhysical, kinematicStatic, material); } else { if ((flags & PhysicsScene.AddPrimShapeFlags.FromSceneStartup) != 0) { actor = PhysxActorFactory.CreateRigidStatic(scene, meshedShape, pos, rotation, material); } else { kinematicStatic = true; actor = PhysxActorFactory.CreateRigidDynamic(scene, meshedShape, pos, rotation, isPhysical, kinematicStatic, material); } } return actor; }