GithubHelp home page GithubHelp logo

Comments (3)

sdfgeoff avatar sdfgeoff commented on June 12, 2024

Currently all components must be structs - which I think is generically true in bevy.

While the interface can display an enum, the backing storage is still an integer. For example for bevy-rapier (whatever old version is in this repo), I had the struct:

The struct that the blender plugin creates

pub struct RigidBodyDescription {
    /// Because we can't export enums yet, this is encoded as a u8
    ///  0 => dynamic
    ///  1 => static
    ///  2 => kinematic
    pub body_status: u8,

<< snip >>

With definition:

{
    "name": "RigidBody",
    "description": "Makes this object obey physics",
    "id": "rapier_rigid_body",
    "struct": "blender_bevy_toolkit::rapier_physics::RigidBodyDescription",
    "fields": [
        {
            "field": "body_status", 
            "type": "u8enum", 
            "default": ["dynamic", "static", "kinematic"],
            "description": "Dynamic bodies respond to forces. Static bodies do not move. Kinematic bodies must be moved manually but internally track velocity so they push other dynamic bodies properly"
        },
<< snip >>

And then at runtime:

/// Converts a RigidBodyDescription into a rapier::dynamics::RigidBodyBuilder. This allows
/// RigidBodyBuilders to be created from a file using bevies Reflection system and scene format
pub fn body_description_to_builder(
    mut commands: Commands,
    body_desc_query: Query<(&RigidBodyDescription, Entity, &Transform)>,
) {
    for (body_desc, entity, transform) in body_desc_query.iter() {
        commands.entity(entity).remove::<RigidBodyDescription>();
        
        << snip >>
        let body_status = match body_desc.body_status {
            0 => BodyStatus::Dynamic,
            1 => BodyStatus::Static,
            2 => BodyStatus::Kinematic,
            _ => panic!("Unknown body status"),
        };

        << snip >>

        let rigid_body_builder = RigidBodyBuilder::new(body_status)
            .position(position)
            .linear_damping(body_desc.damping_linear)
            .angular_damping(body_desc.damping_angular)
            .ccd_enabled(body_desc.ccd_enable)
            .can_sleep(body_desc.sleep_allow)
            .additional_mass(body_desc.mass_extra)
            .additional_principal_angular_inertia(inertia_vec);

        commands.entity(entity).insert(rigid_body_builder);

It was done this way because at the time, Bevy didn't support Reflect on enums. That's probably changed now.

When you do an integration with the new bevy-rapier, I'm super interested in including it into this repo, so please ping back when you've got something working.

from blender_bevy_toolkit.

piedoom avatar piedoom commented on June 12, 2024

thank you for the detailed response, it's much appreciated! Closing as the original issue is solved but if I happen to run into any more info about Reflect on enums I'll ping back - and likewise if I have any success with new rapier.

from blender_bevy_toolkit.

piedoom avatar piedoom commented on June 12, 2024

Got some progress done which I published to my fork, unsure if it is of any use. I think the components work but I got the positions wrong as it glitches for non-zero transforms. Looking into that tomorrow (seems to work OK now) but in the meantime it appears to properly add colliders at least

from blender_bevy_toolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.