Skip to content

Feat: loading xyz files#17

Closed
GeigerJ2 wants to merge 0 commit intors4rse:mainfrom
GeigerJ2:feat/xyz-loading
Closed

Feat: loading xyz files#17
GeigerJ2 wants to merge 0 commit intors4rse:mainfrom
GeigerJ2:feat/xyz-loading

Conversation

@GeigerJ2
Copy link
Copy Markdown
Collaborator

@GeigerJ2 GeigerJ2 commented Nov 6, 2025

No description provided.

Copy link
Copy Markdown
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give my first go. This is actually the first time I review others rust code in github, thanks bro ;)

Two major requests:

  • can you check all pub keywords to see if all of them can be pub(crate) or even just private?
  • After adding this load_file functionality, I believe it is useless to have a default molecule stay there at beginning. I'd prefer to have an empty screen with the text you add and a button says "load the default structure". In the future, we can extend this button into some "example structure assets", but that is out of scope of this PR.

Comment thread src/io.rs Outdated
Comment thread src/parse.rs Outdated
@@ -1,9 +1,9 @@
// parse.rs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// parse.rs

Comment thread src/parse.rs Outdated
// Function to parse XYZ file format from string content
#[allow(dead_code)]
fn parse_xyz_content(contents: &str) -> Result<Crystal> {
pub fn parse_xyz_content(contents: &str) -> Result<Crystal> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn parse_xyz_content(contents: &str) -> Result<Crystal> {
pub(crate) fn parse_xyz_content(contents: &str) -> Result<Crystal> {

Comment thread src/parse.rs Outdated
Comment on lines +49 to +56

// Function to read XYZ file from path
#[allow(dead_code)]
pub fn read_xyz_file(path: &str) -> Result<Crystal> {
let contents =
std::fs::read_to_string(path).context(format!("Failed to read XYZ file: {}", path))?;
parse_xyz_content(&contents)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Function to read XYZ file from path
#[allow(dead_code)]
pub fn read_xyz_file(path: &str) -> Result<Crystal> {
let contents =
std::fs::read_to_string(path).context(format!("Failed to read XYZ file: {}", path))?;
parse_xyz_content(&contents)
}

not used anywhere, correct?

Comment thread src/ui.rs Outdated
pub(crate) struct FileUploadText;

// System to set up file upload UI
pub fn setup_file_ui(mut commands: Commands) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn setup_file_ui(mut commands: Commands) {
pub(crate) fn setup_file_ui(mut commands: Commands) {

Comment thread src/ui.rs Outdated
Comment on lines +48 to +49
#[allow(dead_code)]
pub fn clear_old_atoms(mut commands: Commands, atom_query: Query<Entity, With<AtomEntity>>) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is not called?

Comment thread src/ui.rs Outdated

// System to update file upload UI
pub fn update_file_ui(
file_drag_drop: Res<crate::io::FileDragDrop>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll put use crate::io::FileDragDrop in the beginning of the file.

Comment thread src/ui.rs Outdated
Comment on lines +125 to +126
Transform::from_xyz(atom.x, atom.y, atom.z)
.with_scale(Vec3::splat(get_element_size(&atom.element))),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, builder pattern.

Comment thread src/ui.rs Outdated
..default()
},
Transform::default(), // inherit camera rotation; light points along -Z in local space
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_4)),
Copy link
Copy Markdown
Member

@unkcpz unkcpz Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_4)),
Transform::from_rotation(Quat::from_rotation_x(-f32::consts::FRAC_PI_4)),

Actually, after play with other molecules, I think we should not change this in this PR. the rotation of the light is a bit too much and make the shadow looks very distract. I'll focus on functionality and leave the ui not change for the moment.

Comment thread src/lib.rs Outdated
Comment on lines +42 to +45
load_default_crystal,
setup_scene,
setup_camera,
setup_file_ui,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You remove the .chain() thus it can not guarantee the crystal exist before the setup_scene which need a crystal. My suggestion is not have any crystal loaded at the beginning but

  • put a text showing to user that they can upload a file by drag and drop as you did.
  • adding a button to click and load the default molecule (water). We can then extend this to a dropdown or "what is your lucky crystal today" just like google's "I'm feeling lucky".

Comment thread src/io.rs Outdated

if let Some(extension) = path_buf.extension() {
if extension == "xyz" {
file_drag_drop.dragged_file = Some(path_buf.clone());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .clone() needed here because you use it later in the HoveredFile match branch. However, I am not sure the println there actually print anything in the screen, it might be just print to console. But I'm fine with this, it is just prototype and a fun project, when it get more mature, we can go through all .clone() and audit with having performance under consideration.

Comment thread src/io.rs Outdated
Comment on lines +109 to +110
commands.insert_resource(crystal.clone());
println!("Crystal updated with {} atoms", crystal.atoms.len());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a critical design decision we need to think about soon, that is how we store the crystal and make it cross the bevy world and our back-end crystal operations.

  • we keep a single one?
  • we make clone every time when new crystal appears and make a clone of it to let it into bevy world.

For now, it is just inter-op with file, clone is a nice solution. Thanks for bring this up.

@unkcpz
Copy link
Copy Markdown
Member

unkcpz commented Nov 25, 2025

If it is hard to rebase, you can leave it to me, there are quite some conflict.

@unkcpz unkcpz closed this Nov 26, 2025
@unkcpz
Copy link
Copy Markdown
Member

unkcpz commented Nov 26, 2025

Okay, I think I screw it up, I push wrong branch to your branch, and since it has no change to main, it close this pr automatically. I cannot push more to this branch. Can you reopen? (maybe clone again because your fork have the old name "vizcrystal").

Sorry.. But I can open a new pr as well, with your commits, I'll do that.

@GeigerJ2
Copy link
Copy Markdown
Collaborator Author

GeigerJ2 commented Dec 3, 2025

Bru, I don't check here for a few days, and you are making this mess 💔 😆

@unkcpz
Copy link
Copy Markdown
Member

unkcpz commented Dec 4, 2025

yep, my skill issue, I am always not very good when rebase things with conflicts. Anyway, #28 start shaping, and I'll find time to polish it.

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 this pull request may close these issues.

2 participants