#Meshlet Preprocessor not working ?

87 messages · Page 1 of 1 (latest)

autumn crystal
#

I'm using bevy skien and I am having issues with the meshlet processor.

I have and Observe that i use to convert meshes to meshlets :

fn mesh_to_meshlet(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
    let debug_material = world
        .resource_mut::<Assets<MeshletDebugMaterial>>()
        .add(MeshletDebugMaterial::default());
    let mesh_id = world.get::<Mesh3d>(entity).unwrap().id();

    let mesh = match world.resource::<Assets<Mesh>>().get(mesh_id) {
        Some(mesh) => mesh,
        None => {
            error!("Mesh not found for mesh_id: {:?}", mesh_id);
            return;
        }
    };

    info!(
        "vertex_count: {}, primitives: {:?}, nb of indicies {}",
        mesh.count_vertices(),
        mesh.primitive_topology(),
        mesh.indices().unwrap().len()
    );

    let meshlet = match MeshletMesh::from_mesh(mesh, 22) {
        Ok(meshlet) => meshlet,
        Err(err) => {
            error!("Failed to create meshlet: {err}");
            return;
        }
    };

    let meshlet_handle = world.resource_mut::<Assets<MeshletMesh>>().add(meshlet);

    let mut commands = world.commands();
    entity! {
        <commands|entity>
        MeshletMesh3d(meshlet_handle);
        MeshMaterial3d(debug_material);
        Transform::from_xyz(0.,4.,0.);
        .remove::<Mesh3d>()
        .remove::<GltfMeshExtras>()
        .remove::<MeshletFromMesh>()
        .remove::<MeshMaterial3d<StandardMaterial>>();
    }
}

The issue is that the meshlet processor is able to make a meshlet but doesnt seem to update the clusters no matter where i move the camera.
I have other meshlets in my scene that i loaded from the bevy repo which where already preprocessed and they work fine.
Am i missing something ?

also here is the entity to wich i applied the MeshFromMeshlet Struct:

old hull
#

trying to figure out exactly what's going on such that the clusters aren't being updated...might not be here, however.

#

could you provide a few screenshots?

autumn crystal
#

no matter what the clusters dont change

old hull
#

What happens if you do

    entity! {
        <commands|entity>
        MeshletMesh3d(meshlet_handle);
        MeshMaterial3d(debug_material);
        Transform::from_xyz(0.,4.,0.);
        .remove::<Mesh3d>()
        .remove::<GltfMeshExtras>()
        .remove::<MeshletFromMesh>()
        .remove::<MeshMaterial3d<StandardMaterial>>()
        .remove::<GlobalTransform>()
    }

I'm not as familiar with bevy hooks as I am with observers...but it's possible that because this entity has a global transform and other components prior to inserting, that those components are interfering with the meshlet transform processing

#

If you're using bevy_skein, then I'm guessing that since this component is a child of a scene, that may have something to do with it...
so let me see if this works...(writing some code)

#
fn mesh_to_meshlet(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
    let debug_material = world
        .resource_mut::<Assets<MeshletDebugMaterial>>()
        .add(MeshletDebugMaterial::default());
    let mesh_id = world.get::<Mesh3d>(entity).unwrap().id();

    let mesh = match world.resource::<Assets<Mesh>>().get(mesh_id) {
        Some(mesh) => mesh,
        None => {
            error!("Mesh not found for mesh_id: {:?}", mesh_id);
            return;
        }
    };

    info!(
        "vertex_count: {}, primitives: {:?}, nb of indicies {}",
        mesh.count_vertices(),
        mesh.primitive_topology(),
        mesh.indices().unwrap().len()
    );

    let meshlet = match MeshletMesh::from_mesh(mesh, 22) {
        Ok(meshlet) => meshlet,
        Err(err) => {
            error!("Failed to create meshlet: {err}");
            return;
        }
    };

    let meshlet_handle = world.resource_mut::<Assets<MeshletMesh>>().add(meshlet);

    let meshlet_handle = world.resource_mut::<Assets<MeshletMesh>>().add(meshlet);

    let mut commands = world.commands();
    commands.entity(entity).despawn();
    commands.spawn((
        MeshletMesh3d(meshlet_handle),
        MeshMaterial3d(debug_material),
        Transform::from_xyz(0., 4., 0.),
    ));
}

edit: just realized I added something extra which was getting the transform for the entity. this is probably not a great idea if the scene root is offset. could get globaltransform or just replace with your original transform

#

You could alternatively despawn only the entity and attach any children to the new entity

autumn crystal
#

messing with the transform seems to make it not render

old hull
#

shoot

autumn crystal
#

it just becomes invisible

#

it rebecomes visible when i give it avian physics tho but still broken

old hull
#

wat

autumn crystal
#

I tried :

    entity! {
        <commands|entity>
        Transform::from_xyz(0.,4.,0.);
        MeshletMesh3d(meshlet_handle);
        MeshMaterial3d(debug_material);
        .remove::<Mesh3d>()
        .remove::<ChildOf>()
        .remove::<GlobalTransform>()
        .remove::<GltfMeshExtras>()
        .remove::<MeshletFromMesh>()
        .remove::<MeshMaterial3d<StandardMaterial>>();
    }

and it made the meshlet invisible

old hull
#

wow, one sec alice's talk is on at rustconf but I'll get back

autumn crystal
#

hmmm

#

I applied the blender scales to the mesh and exported it.

    entity! {
        <commands|entity>
        Transform::from_xyz(0.,4.,0.);
        MeshletMesh3d(meshlet_handle);
        MeshMaterial3d(debug_material);
        .remove::<Mesh3d>()
        // .remove::<ChildOf>()
        // .remove::<GlobalTransform>()
        .remove::<GltfMeshExtras>()
        .remove::<MeshletFromMesh>()
        .remove::<MeshMaterial3d<StandardMaterial>>();
    }
#

this is the mesh in blender :

autumn crystal
#

all transforms are fine :

#

it just looks like the meshlet processor is having a stroke

#

i created another mesh just to make sure its not just corrupted

#

let me cargo clean

#

that did not fix the issue

old hull
#

no, this is some funk for sure

#

something's off. do you have a larger example? I'm quite interested

old hull
#

like a fat cube

#

what happens if you give this a white mesh material?

#

being a child of a scene is my hunch

autumn crystal
#

i tried removing the childOf so that it apears without any parents

#

but it just becomes invisible

autumn crystal
#

AHHHHHH

#

theyre still children because of the hook

#

for some reason ````
commands.entity(entity).despawn();
commands.spawn((
MeshletMesh3d(meshlet_handle),
MeshMaterial3d(debug_material),
Transform::from_xyz(0., 4., 0.),
));

spawns it as a child
edit:my bad i just missread the world inspector
#

ill fix this later

#

yea still broken:

#

there not the child of anybody now and still behave the same

#

i spawned several other suzane heads with the MeshletFromMesh and they all seem to collapse at the same area

#

tldr the grey suzzane head does not had a MeshfromMeshlet struct

#

i replaced the head with a torrus

#

the preprocessed meshlets are fine tho :

old hull
#

Something's super suspicious. I'll look to reproduce with only the monkey head after work

cerulean crater
loud flint
#

huh interesting

#

should test something similar once building isn't utterly broken

old hull
loud flint
#

so i'm not sure if the bug will still be there

old hull
#

oh amazing!

#

You might be interested in something I've got to show in a few...once this file's done downloading...

loud flint
old hull
#

Check out this tree's meshlet

#

kinda fire huh

loud flint
#

ouch

#

yeah nanite is terrible at alpha cards

old hull
#

you're dropping some important words I need to look into hahaha

loud flint
#

nanite is the UE5's virtual geometry which is what sparked basically everyone's interest in it

old hull
#

I mean alpha cards 🤔

loud flint
#

alpha cards are a technique used for foliage where each leaf is a quad and you use alpha to basically cut the shape out

old hull
#

the weird part I don't understand is...where is the trunk??

loud flint
#

a quad can't really be shrimplified so nanite just fails on it

loud flint
#

dunno for sure

old hull
#

interesting...

loud flint
#

i'm trying to ensure the bvh builder will panic/error if it messes up so hopefully we don't have silent failures in the future

old hull
loud flint
#

cheers will take a look

autumn crystal
#

thanks to @old hull it turn out i put the vertex_position_quantization_factor in the MeshletMesh::from_mesh to a value that was too high

#

dsgallups fixed it by changing it from 22 to 1

#

putting this here for people that run in the same issue

loud flint
#

there's alsoMESHLET_DEFAULT_VERTEX_POSITION_QUANTIZATION_FACTOR which is 4

cerulean crater
#

Ideally in the future there will be an automatic adaptive default, but it's not been a priority to implement