-
Notifications
You must be signed in to change notification settings - Fork 5
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
Clarify documentation and examples for relations #10
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d3e4a8
fix: invalid archetype for a transitive archetype connection
ten3roberts 1ca2428
fix: clarify associated values for relations
ten3roberts cf664d7
fix: clarify value uniqueness
ten3roberts c2a15bb
feat: document exclusive relations
ten3roberts 47534e2
chore: wording
ten3roberts 9558776
fix!: clear up naming with relation target
ten3roberts 2ee705b
feat: nth_relation
ten3roberts 0c136d9
fix: nth_relation access granularity
ten3roberts 53184f2
fix: clarify target terms
ten3roberts 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 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 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 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,68 @@ | ||
use flax::{component, components::name, entity_ids, Dfs, Entity, FetchExt, Query, World}; | ||
use glam::{vec2, Vec2}; | ||
use tracing_subscriber::{prelude::*, registry}; | ||
use tracing_tree::HierarchicalLayer; | ||
|
||
fn main() { | ||
registry().with(HierarchicalLayer::default()).init(); | ||
|
||
let mut world = World::new(); | ||
|
||
// ANCHOR: main | ||
struct Spring { | ||
strength: f32, | ||
length: f32, | ||
} | ||
|
||
impl Spring { | ||
fn new(strength: f32, length: f32) -> Self { | ||
Self { strength, length } | ||
} | ||
} | ||
component! { | ||
spring_joint(id): Spring, | ||
position: Vec2, | ||
} | ||
|
||
let id1 = Entity::builder() | ||
.set(name(), "a".into()) | ||
.set(position(), vec2(1.0, 4.0)) | ||
.spawn(&mut world); | ||
|
||
// Connect id2 to id1 with a spring of strength 2.0 | ||
let id2 = Entity::builder() | ||
.set(name(), "b".into()) | ||
.set(spring_joint(id1), Spring::new(2.0, 1.0)) | ||
.set(position(), vec2(2.0, 0.0)) | ||
.spawn(&mut world); | ||
|
||
let _id3 = Entity::builder() | ||
.set(name(), "c".into()) | ||
.set(spring_joint(id1), Spring::new(2.0, 3.0)) | ||
.set(position(), vec2(2.0, 3.0)) | ||
.spawn(&mut world); | ||
|
||
let _id4 = Entity::builder() | ||
.set(name(), "d".into()) | ||
.set(spring_joint(id2), Spring::new(5.0, 0.5)) | ||
.set(position(), vec2(1.0, 0.0)) | ||
.spawn(&mut world); | ||
|
||
let mut query = Query::new((entity_ids(), name().cloned(), position())) | ||
.with_strategy(Dfs::new(spring_joint)); | ||
|
||
query | ||
.borrow(&world) | ||
.traverse(&None, |(id, name, &pos), strength, parent| { | ||
if let (Some(spring), Some((parent_name, parent_pos))) = (strength, parent) { | ||
let distance = pos.distance(*parent_pos) - spring.length; | ||
let force = distance * spring.strength; | ||
tracing::info!("spring acting with {force:.1}N between {parent_name} and {name}"); | ||
} else { | ||
tracing::info!(%id, name, "root"); | ||
} | ||
|
||
Some((name, pos)) | ||
}); | ||
// ANCHOR_END: main | ||
} |
This file contains 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 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 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 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
Maybe here would be a good place to reinforce the target-subject terms after parent-child? Not sure.
Example:
This allows forming hierarchies such as *parent-child* (target-subject) relations for transforms and UI...
Not really sure because the relation can have any arbitrary direction, maybe this only applies to the
child_of
type of relation.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.
Thank you, I've clarified it a bit more :)