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

Modifying shapes after creation #11

Closed
Bauxitedev opened this issue Oct 13, 2020 · 1 comment · Fixed by #113
Closed

Modifying shapes after creation #11

Bauxitedev opened this issue Oct 13, 2020 · 1 comment · Fixed by #113

Comments

@Bauxitedev
Copy link

Bauxitedev commented Oct 13, 2020

Not sure if I'm doing it incorrectly, but right now it seems difficult if not impossible to modify the shapes at runtime after they've been created.

E.g. if I have a simple path shape like this...

    let points = vec![point(0.0, 0.0), point(100.0, 100.0), point(500.0, 000.0)];

    let shape = ShapeType::Polyline {
        points,
        closed: false,
    };
    let mut stroke_options = StrokeOptions::default();
    stroke_options.line_width = 1.0;

    cmd.spawn(primitive(
        material,
        &mut meshes,
        shape,
        TessellationMode::Stroke(&stroke_options),
        Vec3::zero(),
    ))

It seems if I want to change the shape afterwards, I need to use its Mesh component...

fn update(mut meshes: ResMut<Assets<Mesh>>, h: &Handle<Mesh>) {
    let mesh = meshes.get_mut(h).unwrap();
    let attributes = &mut mesh.attributes;

    for att in &mut attributes.iter_mut() {
        //TODO do something with attr
    }
}

But it seems the points it returns are the ones after tessellating the shape, which is not very useful if you want to move the original points before tessellation. E.g. it seems to return 6 points instead of the expected 3.

I assume the only way to do this right now is to create a new primitive every frame and delete the old one?

@CrabBucket
Copy link

CrabBucket commented Oct 14, 2020

Yeah, What I have been doing is creating a new primitive SpriteBundle every time I want to change shape then just setting the specific entities mesh (and shape but not sure its needed) to the newly created ones. so like if the handle was mutable h= primitive(... options).mesh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants