private Material GetMaterial(EntityComponent component, BepuColliderShape shape) { var componentType = ComponentType.Trigger; var rigidbodyComponent = component as BepuRigidbodyComponent; if (rigidbodyComponent != null) { componentType = rigidbodyComponent.IsTrigger ? ComponentType.Trigger : rigidbodyComponent.IsKinematic ? ComponentType.Kinematic : ComponentType.Dynamic; } //else if (component is BepuCharacterComponent) //{ // componentType = ComponentType.Character; //} else if (component is BepuStaticColliderComponent staticCollider) { componentType = staticCollider.IsTrigger ? ComponentType.Trigger : ComponentType.Static; } if (shape is BepuStaticPlaneColliderShape) { return(componentTypeStaticPlaneMaterial[componentType]); } //else if (shape is BepuHeightfieldColliderShape) //{ // return componentTypeHeightfieldMaterial[componentType]; //} else { return(componentTypeDefaultMaterial[componentType]); } }
public PhysicsElementInfo(BepuPhysicsComponent component, SkeletonUpdater skeleton) { shape = component.ColliderShape; var rigidbodyComponent = component as BepuRigidbodyComponent; isKinematic = rigidbodyComponent != null && rigidbodyComponent.IsKinematic; colliderShapes = component.ColliderShapes != null?CloneDescs(component.ColliderShapes) : null; var componentBase = component as BepuPhysicsSkinnedComponentBase; boneName = componentBase?.NodeName; this.skeleton = skeleton; boneIndex = componentBase?.BoneIndex ?? -1; var triggerBase = component as BepuPhysicsTriggerComponentBase; isTrigger = triggerBase != null && triggerBase.IsTrigger; }
private Entity CreateChildEntity(BepuPhysicsComponent component, BepuColliderShape shape, RenderGroup renderGroup, bool addOffset) { if (shape == null) { return(null); } switch (shape.Type) { case ColliderShapeTypes.Compound: { var entity = new Entity(); //We got to recurse var compound = (BepuCompoundColliderShape)shape; for (int i = 0; i < compound.Count; i++) { var subShape = compound[i]; var subEntity = CreateChildEntity(component, subShape, renderGroup, true); //always add offsets to compounds if (subEntity != null) { entity.AddChild(subEntity); } } entity.Transform.LocalMatrix = Matrix.Identity; entity.Transform.UseTRS = false; compound.DebugEntity = entity; return(entity); } case ColliderShapeTypes.Box: case ColliderShapeTypes.Capsule: case ColliderShapeTypes.ConvexHull: case ColliderShapeTypes.Cylinder: case ColliderShapeTypes.Sphere: case ColliderShapeTypes.Cone: case ColliderShapeTypes.StaticPlane: case ColliderShapeTypes.StaticMesh: case ColliderShapeTypes.Heightfield: { IDebugPrimitive debugPrimitive; var type = shape.GetType(); //if (type == typeof(BepuHeightfieldColliderShape)) //{ // if (!updatableDebugMeshCache.TryGetValue(shape, out debugPrimitive)) // { // debugPrimitive = shape.CreateUpdatableDebugPrimitive(graphicsDevice); // updatableDebugMeshCache[shape] = debugPrimitive; // } // if (!updatableDebugMeshes.ContainsKey(shape)) // { // updatableDebugMeshes.Add(shape, debugPrimitive); // } //} //else if (type == typeof(BepuCapsuleColliderShape) || type == typeof(BepuConvexHullColliderShape) //|| type == typeof(BepuStaticMeshColliderShape) ) { if (!debugMeshCache2.TryGetValue(shape, out debugPrimitive)) { debugPrimitive = new DebugPrimitive { shape.CreateDebugPrimitive(graphicsDevice) }; debugMeshCache2[shape] = debugPrimitive; } } else { if (!debugMeshCache.TryGetValue(shape.GetType(), out debugPrimitive)) { debugPrimitive = new DebugPrimitive { shape.CreateDebugPrimitive(graphicsDevice) }; debugMeshCache[shape.GetType()] = debugPrimitive; } } var model = new Model { GetMaterial(component, shape), }; foreach (var meshDraw in debugPrimitive.GetMeshDraws()) { model.Add(new Mesh { Draw = meshDraw }); } var entity = new Entity { new ModelComponent { Model = model, RenderGroup = renderGroup, }, }; var offset = addOffset ? Matrix.RotationQuaternion(shape.LocalRotation) * Matrix.Translation(shape.LocalOffset) : Matrix.Identity; entity.Transform.LocalMatrix = shape.DebugPrimitiveMatrix * offset * Matrix.Scaling(shape.Scaling); entity.Transform.UseTRS = false; shape.DebugEntity = entity; return(entity); } default: return(null); } }