-
Notifications
You must be signed in to change notification settings - Fork 3
WIP Lights #67
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
Open
catilac
wants to merge
4
commits into
processing:main
Choose a base branch
from
catilac:lights
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WIP Lights #67
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| //! A light in Processing | ||
| //! | ||
|
|
||
| use bevy::prelude::*; | ||
|
|
||
| pub struct LightPlugin; | ||
|
|
||
| impl Plugin for LightPlugin { | ||
| fn build(&self, _app: &mut App) {} | ||
| } | ||
|
|
||
| #[derive(Component)] | ||
| pub struct Light { | ||
| pub light_type: LightType, | ||
| pub pos: Vec3, | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| pub enum LightType { | ||
| Ambient, | ||
| Directional, | ||
| Point, | ||
| Spot, | ||
| } | ||
|
|
||
| pub fn create( | ||
| In((light_type, x, y, z)): In<(LightType, f32, f32, f32)>, | ||
| mut commands: Commands, | ||
| ) -> Entity { | ||
| // let light = Light { | ||
| // light_type: light_type, | ||
| // pos: Vec3::new(x, y, z), | ||
| // }; | ||
| // commands.spawn(light).id() | ||
|
|
||
| match light_type { | ||
| LightType::Directional => commands | ||
| .spawn((DirectionalLight::default(), Transform::from_xyz(x, y, z))) | ||
| .id(), | ||
| _ => commands.spawn(AmbientLight::default()).id(), | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| mod glfw; | ||
|
|
||
| use glfw::GlfwContext; | ||
| use processing::prelude::*; | ||
| use processing_render::light::LightType; | ||
| use processing_render::render::command::DrawCommand; | ||
|
|
||
| fn main() { | ||
| match sketch() { | ||
| Ok(_) => { | ||
| eprintln!("Sketch completed successfully"); | ||
| exit(0).unwrap(); | ||
| } | ||
| Err(e) => { | ||
| eprintln!("Sketch error: {:?}", e); | ||
| exit(1).unwrap(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn sketch() -> error::Result<()> { | ||
| let mut glfw_ctx = GlfwContext::new(400, 400)?; | ||
| init(Config::default())?; | ||
|
|
||
| let width = 400; | ||
| let height = 400; | ||
| let scale_factor = 1.0; | ||
|
|
||
| let surface = glfw_ctx.create_surface(width, height, scale_factor)?; | ||
| let graphics = graphics_create(surface, width, height)?; | ||
| let box_geo = geometry_box(10.0, 10.0, 10.0)?; | ||
|
|
||
| // We will only declare lights in `setup` | ||
| // rather than calling some sort of `light()` method inside of `draw` | ||
| let _point_light = light_create(LightType::Point, 0.0, 0.0, 0.0)?; | ||
|
Comment on lines
+33
to
+35
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not totally sure, but I think we may want to consider including color as a required constructor arg since all three types share that. |
||
|
|
||
| graphics_mode_3d(graphics)?; | ||
| graphics_camera_position(graphics, 100.0, 100.0, 300.0)?; | ||
| graphics_camera_look_at(graphics, 0.0, 0.0, 0.0)?; | ||
|
|
||
| let mut angle = 0.0; | ||
|
|
||
| while glfw_ctx.poll_events() { | ||
| graphics_begin_draw(graphics)?; | ||
|
|
||
| graphics_record_command( | ||
| graphics, | ||
| DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.18, 0.20, 0.15)), | ||
| )?; | ||
|
|
||
| graphics_record_command(graphics, DrawCommand::PushMatrix)?; | ||
| graphics_record_command(graphics, DrawCommand::Translate { x: 25.0, y: 25.0 })?; | ||
| graphics_record_command(graphics, DrawCommand::Rotate { angle })?; | ||
| graphics_record_command(graphics, DrawCommand::Geometry(box_geo))?; | ||
| graphics_record_command(graphics, DrawCommand::PopMatrix)?; | ||
|
|
||
| graphics_record_command(graphics, DrawCommand::PushMatrix)?; | ||
| graphics_record_command(graphics, DrawCommand::Translate { x: -25.0, y: 20.0 })?; | ||
| graphics_record_command(graphics, DrawCommand::Scale { x: 1.5, y: 2.0 })?; | ||
| graphics_record_command(graphics, DrawCommand::Rotate { angle })?; | ||
| graphics_record_command(graphics, DrawCommand::Geometry(box_geo))?; | ||
| graphics_record_command(graphics, DrawCommand::PopMatrix)?; | ||
|
|
||
| graphics_end_draw(graphics)?; | ||
|
|
||
| angle += 0.02; | ||
| } | ||
| Ok(()) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ambient lights are a bit weird in that they are added to the camera rather than spawned independently in the world. In that sense, they're more like a global graphics setting. I think we should punt on ambient light for now or add it as a setting for
Graphics.