Terrain with multiple materials
Terrain with multiple materials
I'm writing a racing game, and I need to assign different materials to different terrain parts. Texture splatting is used for rendering terrain, and physical materials should match to textures. Or, in other words, physics engine must take material returned from my function based on x, y coordinates of wheel. Is it possible? And if it is, how can I achieve this behavior?
Re: Terrain with multiple materials
It's possible- but let me make a bit easier real quick. I'm going to make a modification to the material management system to accept a delegate for the material relationships. I'll post again when it's up on the development fork.
Then, all that would be necessary is to add a delegate to the MaterialManager.MaterialInteractions between the material of the terrain and the material of an object moving around on the terrain. Materials have a Tag property that can hold a reference to the associated game logic object. (Technically, you could avoid the dictionary and use the general purpose MaterialManager.MaterialBlender catch-all delegate if you wanted.)
So, if the owner is the terrain game logic object and the other material's owner is a vehicle, you can grab the position of the vehicle body and ask the terrain game logic object what the friction is at that point.
Basing it solely on the vehicle body position will have the limitation of having only one material configuration for all wheels. Doing the evaluation per-wheel would get more precise results since one wheel could be on ice, another on grass.
Materials can technically be shared among multiple objects, but since this system relies on tags for information, it's probably best if object has its own material so the Tag points to it specifically.
Then, all that would be necessary is to add a delegate to the MaterialManager.MaterialInteractions between the material of the terrain and the material of an object moving around on the terrain. Materials have a Tag property that can hold a reference to the associated game logic object. (Technically, you could avoid the dictionary and use the general purpose MaterialManager.MaterialBlender catch-all delegate if you wanted.)
So, if the owner is the terrain game logic object and the other material's owner is a vehicle, you can grab the position of the vehicle body and ask the terrain game logic object what the friction is at that point.
Basing it solely on the vehicle body position will have the limitation of having only one material configuration for all wheels. Doing the evaluation per-wheel would get more precise results since one wheel could be on ice, another on grass.
Materials can technically be shared among multiple objects, but since this system relies on tags for information, it's probably best if object has its own material so the Tag points to it specifically.
Re: Terrain with multiple materials
The development fork now includes the changes: http://bepuphysics.codeplex.com/SourceC ... evelopment
In addition to the general MaterialManager changes made above, the friction blending systems used by the Vehicle have been changed to match. The Wheel.SlidingFriction.FrictionBlender, Wheel.Brake.FrictionBlender, and Wheel.DrivingMotor.FrictionBlender are all now WheelFrictionBlender delegates. This delegate type takes the values to blend, whether or not it's using kinetic or static friction, and the wheel being blended. The Wheel exposes the SupportMaterial, SupportingCollidable, and SupportEntity if they exist.
Between the wheel-exposed information and any data contained in the Tags of those objects, a blender which takes into account terrain friction can be created.
In addition to the general MaterialManager changes made above, the friction blending systems used by the Vehicle have been changed to match. The Wheel.SlidingFriction.FrictionBlender, Wheel.Brake.FrictionBlender, and Wheel.DrivingMotor.FrictionBlender are all now WheelFrictionBlender delegates. This delegate type takes the values to blend, whether or not it's using kinetic or static friction, and the wheel being blended. The Wheel exposes the SupportMaterial, SupportingCollidable, and SupportEntity if they exist.
Between the wheel-exposed information and any data contained in the Tags of those objects, a blender which takes into account terrain friction can be created.
Re: Terrain with multiple materials
Thank you. I didn't expect such good support for free 
