Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unindexed meshes in Collider::from_bevy_mesh #491

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rlidwka
Copy link

@rlidwka rlidwka commented Apr 2, 2024

fixes #490

implementation was somewhat inspired by assimp/assimp#2049, you can see the explanation of "why" there

Here's how you can test it visually. The glTF file being checked here is this one.

use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, attach_collider)
        .add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
        .add_plugins(RapierDebugRenderPlugin::default())
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(DirectionalLightBundle::default());
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
        ..default()
    });
    commands.spawn(SceneBundle {
        scene: asset_server.load("TriangleWithoutIndices.gltf#Scene0"),
        ..default()
    });
}

fn attach_collider(
    mut commands: Commands,
    meshes: Res<Assets<Mesh>>,
    query: Query<(Entity, &Handle<Mesh>), Without<Collider>>,
) {
    for (entity, mesh) in query.iter() {
        let mesh = meshes.get(mesh).unwrap();
        commands
            .entity(entity)
            .insert(Collider::from_bevy_mesh(mesh, &ComputedColliderShape::TriMesh).unwrap());
    }
}

@Vrixyz Vrixyz added D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Medium A-Geometry C-Enhancement New feature or request labels May 20, 2024
@rlidwka rlidwka force-pushed the issue-490 branch 2 times, most recently from bf3cbe6 to 73fa110 Compare July 15, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Geometry C-Enhancement New feature or request D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

from_bevy_mesh doesn't support unindexed glTF
2 participants