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

feat(app): Add shadow camera helpers to v-light-helper #337

Closed
wants to merge 1 commit into from

Conversation

JaimeTorrealba
Copy link
Member

No description provided.

Copy link

stackblitz bot commented Jan 26, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Jan 26, 2024

Deploy Preview for cientos-tresjs ready!

Name Link
🔨 Latest commit af4f1d5
🔍 Latest deploy log https://app.netlify.com/sites/cientos-tresjs/deploys/65b401823bd75a000818ef36
😎 Deploy Preview https://deploy-preview-337--cientos-tresjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@andretchen0 andretchen0 left a comment

Choose a reason for hiding this comment

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

Hey @JaimeTorrealba !

I've found some bugs and made a few suggestions for getting rid of them.

There are also a few changes/suggestions for typos, etc.

😎


::: warning
This directive just work with the following lights:DirectionalLight,PointLight, SpotLight, HemisphereLight.
By this way you can't tweaks the props for the helper if you need to do that, please use the normal helper instance
This directive just work with the following lights:DirectionalLight,PointLight, SpotLight, HemisphereLight and RectAreaLight.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo and maybe wording(?)

This directive just work

"just works" is fine, but it's ambiguous in this particular context. It can mean either of these:

  • "It accomplishes the task without your intervention, if you use the following: ..."
  • "It only works with the following:"

I think it means the second option here, so:

This directive only works

Spacing

lights:DirectionalLight,PointLight,

lights: DirectionalLight, PointLight,

This directive just work with the following lights:DirectionalLight,PointLight, SpotLight, HemisphereLight.
By this way you can't tweaks the props for the helper if you need to do that, please use the normal helper instance
This directive just work with the following lights:DirectionalLight,PointLight, SpotLight, HemisphereLight and RectAreaLight.
By this way you can't tweaks the props of the helper, if you need to do that, please use the normal helper instance
Copy link
Contributor

Choose a reason for hiding this comment

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

In English, I think we don't normally say "by this way", though I found a few instances online. It's usually "in this way", at least for me. (Prepositions are tough and don't make logical sense!)

But I think we can just drop it here:

By this way you can't tweaks the props of

You can't tweaks the props of

Also, this is a "comma splice":

the helper, if you need to do that

the helper. If you need to do that

@@ -26,8 +26,29 @@ import { OrbitControls, Sphere, vLightHelper } from '@tresjs/cientos'
</TresCanvas>
</template>
```
### shadowCamera

Using the `shadowCamera` argument you can also instantiate the helper for the current `shadow-camera` this only works in lights that generate shadows.
Copy link
Contributor

Choose a reason for hiding this comment

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

shadow-camera this only works

shadow-camera. This only works

v-light-helper:shadowCamera
/>
<TresHemisphereLight
v-light-helper:shadowCamera // This won't work, hemisphereLight doesn't generate shadows
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work,

This won't work.

</script>

<template>
<TresLeches
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a bug related to removing the Light/Helper.

When any of these Leches boxes are unticked – removing the light helper – errors are being logged to the console for me:

Screenshot 2024-01-27 at 14 34 43

It shows up in the latest FF and Chrome on Mac, anyway.

import { RectAreaLightHelper } from 'three-stdlib'

const { logWarning } = useLogger()

export const vLightHelper = {
mounted: (el: any) => {
mounted: (el: any, binding: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like el could be typed as a Light, given the usage here. That will allow the type checker to highlight a few problems down below.

@@ -40,40 +52,45 @@ onLoop(({ elapsed }) => {
</Sphere>
<TresAmbientLight :color="0xffffff" />
<TresDirectionalLight
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is placed in a group, an error is thrown.

  <TresGroup>
    <TresDirectionalLight
      v-if="dirLight.value"
      ref="directionalLightRef"
      v-light-helper:shadowCamera
      :color="0xffffff"
      :intensity="5"
      :position="[0, 2, 4]"
    />
  </TresGroup>
Uncaught (in promise) TypeError: currentShadowCameraHelper is undefined
Screenshot 2024-01-27 at 15 41 41

const getHelperIntance = (el: any) =>
el.parent.children.find((child: any) => child instanceof currentHelper)
const getShadowCameraHelperIntance = (el: any) =>
el.parent.children.find((child: any) => child instanceof CameraHelper)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this approach is causing some problems. If you el.parent.children.find there might be multiple instances of a particular instanceof, if there are sibling lights.

Suggestion

LightHelpers and CameraHelpers store a reference to their targets. You could match on those.

},
}
let currentHelper: any
let currentInstance: any
let currentShadowCameraHelper: any
Copy link
Contributor

@andretchen0 andretchen0 Jan 27, 2024

Choose a reason for hiding this comment

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

I think these variables are out of sync when the code reaches line 29. If I understand correctly, the code could lead to this incorrect flow:

  • Create SpotLight 1, add helper
  • Create PointLight 2, add helper
  • updated() on SpotLight 1 <-- getHelperInstance will return the PointLight helper instance, but should return the SpotLight helper instance

Suggestion

If you want to store references, maybe something like this?

type LightHelper = DirectionalLightHelper | PointLightHelper | SpotLightHelper | HemisphereLightHelper | RectAreaLightHelper
const lightUuidToShadowCameraHelper: Record<string, CameraHelper> = {}
const lightUuidToLightHelper: Record<string, LightHelper> = {}

@JaimeTorrealba
Copy link
Member Author

@andretchen0 thanks for taking the time, I like your feedback. I'm going to put this in draw because we're moving the directive section to the core pkg. So I don't know yet what will happen with this one

@JaimeTorrealba JaimeTorrealba marked this pull request as draft January 29, 2024 10:19
@JaimeTorrealba
Copy link
Member Author

I'll close this one, since now the directives are in the core (I'll re-open there)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants