New to Amethyst, trying to display a generated mesh, would like some help

(Martin) #1

I am trying to display a mesh that I have generated myself. I have half written the code for the mesh, but I’m not sure what I need to do to make it build and run.

First, I have written two functions, which create a mesh and a PNG that will be UV mapped onto the mesh.

pub fn make_mesh() -> ( // returns (mesh_points, mesh_triangles, uvs)
    Vec<na::Point3<f32>>,
    Vec<na::Point3<u16>>,
    Vec<na::Point2<f32>>,
) 

and

pub fn make_image() -> image::DynamicImage

Now I call these functions, and then try to use them in some simple code, which is basically the standard Amethyst example code.

        let (mesh_points, mesh_triangles, uvs) = make_data::make_mesh();
        let image = make_data::make_image();
        let (mesh, albedo) = {
            let mesh = world.exec(|loader: AssetLoaderSystemData<'_, Mesh>| {
                loader.load_from_data(
                    MeshBuilder::new()
                        .with_vertices(mesh_points)
                        .build()
                        .unwrap()
                        .into(),
                    (),
                )
            });
            let image_data = load_from_image(
                image,
                ImageTextureConfig {
                    format: Some(ImageFormat::PNG),
                    sampler_info: SamplerInfo::new(Filter::Linear, WrapMode::Border),
                    ..ImageTextureConfig::default()
                },
            )
            .unwrap()
            .build()
            .unwrap();
            let albedo = world.exec(|loader: AssetLoaderSystemData<'_, Texture>| {
                loader.load_from_data(image_data, ())
            });

            (mesh, albedo)
        };

This is not building at all. I just have no idea at this stage which types and methods I should be using.

The Amethyst documentation is a bit light on at this point, so I would welcome any advice on how to proceed.

(Chris Burnor) #2

What are the build errors that code above is generating? Or is it ‘building’ but not actually rendering to screen?