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

Scene doesn't update after dragging egui::Window #235

Closed
YueChuCheng opened this issue Apr 25, 2022 · 3 comments
Closed

Scene doesn't update after dragging egui::Window #235

YueChuCheng opened this issue Apr 25, 2022 · 3 comments

Comments

@YueChuCheng
Copy link

YueChuCheng commented Apr 25, 2022

Hello, recently, I found that after I dragged egui::Window, part of the object stop rendering, how can I fix this issue?

Below is the video of this issue:
https://youtu.be/zVsFo0imEVQ

As for main.rs in examples/volume, I just change the gui from the side panel to the window

// Entry point for non-wasm
#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
async fn main() {
    run().await;
}

use three_d::*;

pub async fn run() {
    let window = Window::new(WindowSettings {
        title: "Volume!".to_string(),
        max_size: Some((1280, 720)),
        ..Default::default()
    })
    .unwrap();
    let context = window.gl().unwrap();

    let mut camera = Camera::new_perspective(
        &context,
        window.viewport().unwrap(),
        vec3(0.25, -0.5, -2.0),
        vec3(0.0, 0.0, 0.0),
        vec3(0.0, 1.0, 0.0),
        degrees(45.0),
        0.1,
        1000.0,
    )
    .unwrap();
    let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);

    // Source: https://web.cs.ucdavis.edu/~okreylos/PhDStudies/Spring2000/ECS277/DataSets.html
    let cpu_volume = Loader::load_async(&["examples/assets/Skull.vol"])
        .await
        .unwrap()
        .vol("")
        .unwrap();
    let mut volume = Model::new_with_material(
        &context,
        &CpuMesh::cube(),
        IsourfaceMaterial {
            voxels: std::rc::Rc::new(Texture3D::new(&context, &cpu_volume.voxels).unwrap()),
            lighting_model: LightingModel::Blinn,
            size: cpu_volume.size,
            threshold: 0.15,
            color: Color::WHITE,
            roughness: 1.0,
            metallic: 0.0,
        },
    )
    .unwrap();
    volume.set_transformation(Mat4::from_nonuniform_scale(
        0.5 * cpu_volume.size.x,
        0.5 * cpu_volume.size.y,
        0.5 * cpu_volume.size.z,
    ));

    let ambient = AmbientLight::new(&context, 0.4, Color::WHITE).unwrap();
    let directional1 =
        DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(-1.0, -1.0, -1.0)).unwrap();
    let directional2 =
        DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(1.0, 1.0, 1.0)).unwrap();

    // main loop
    let mut gui = three_d::GUI::new(&context).unwrap();
    let mut color = [1.0; 4];
    window
        .render_loop(move |mut frame_input| {
            let mut panel_width = 0;
            gui.update(&mut frame_input, |gui_context| {
                use three_d::egui::*;
                Window::new("My Window").show(gui_context, |ui| {
                    ui.label("Hello World!");
                });
                panel_width = gui_context.used_size().x as u32;
            })
            .unwrap();
            volume.material.color = Color::from_rgba_slice(&color);

            let viewport = Viewport {
                x: panel_width as i32,
                y: 0,
                width: frame_input.viewport.width - panel_width,
                height: frame_input.viewport.height,
            };
            camera.set_viewport(viewport).unwrap();
            control
                .handle_events(&mut camera, &mut frame_input.events)
                .unwrap();

            // draw
            Screen::write(
                &context,
                ClearState::color_and_depth(0.5, 0.5, 0.5, 1.0, 1.0),
                || {
                    render_pass(
                        &camera,
                        &[&volume],
                        &[&ambient, &directional1, &directional2],
                    )?;
                    gui.render()?;
                    Ok(())
                },
            )
            .unwrap();

            FrameOutput::default()
        })
        .unwrap();
}
asny added a commit that referenced this issue Apr 25, 2022
asny added a commit that referenced this issue Apr 25, 2022
@asny
Copy link
Owner

asny commented Apr 25, 2022

Hi, thanks for reporting 👍

I have made a fix in both the 0.11 and master branch and released in 0.11.2.

For your example to work properly you will have to use the frame_input.viewport instead of adjusting it based on the side panel size since there is no side panel 🙂

Also, related to #195.

@YueChuCheng
Copy link
Author

Thank you for fixing it so fast, now it works exactly what I want! 🥳🥳🥳

@asny
Copy link
Owner

asny commented Apr 25, 2022

No problem 🙂

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

No branches or pull requests

2 participants