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

Add: sample for postprocessing #4

Closed
marwie opened this issue Mar 27, 2023 · 3 comments
Closed

Add: sample for postprocessing #4

marwie opened this issue Mar 27, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@marwie
Copy link
Member

marwie commented Mar 27, 2023

No description provided.

@marwie marwie added the enhancement New feature or request label Mar 27, 2023
@marwie
Copy link
Member Author

marwie commented Mar 28, 2023

import { Behaviour, DepthOfField, serializable, Volume } from "@needle-tools/engine";


export class FocusDistancer extends Behaviour {

    @serializable(Volume)
    post !: Volume;

    update(): void {
        if (this.context.input.getPointerClicked(0)) {
            const profile = this.post?.sharedProfile;
            if(!profile) return;
            for (const ef of profile!.components!) {
                if (ef instanceof DepthOfField) {
                    const hits = this.context.physics.raycast();
                    if (hits.length) {
                        const hitInCam = this.context.mainCamera?.worldToLocal(hits[0].point);
                        ef.focusDistance.value = -hitInCam!.z;
                    }
                }
            }
        }
    }
}

@marwie
Copy link
Member Author

marwie commented Mar 30, 2023

Sample test: https://ethereal-rumbling-clam.glitch.me/

@marwie
Copy link
Member Author

marwie commented Mar 30, 2023

@marwie marwie closed this as completed Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant