-
-
Notifications
You must be signed in to change notification settings - Fork 43
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(cientos): 178 v-light-helper #214
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d3e79d7
feat: add v-light-helper component
JaimeTorrealba ac1ba0c
docs: add docs for v-light-helper
JaimeTorrealba 8646ec7
chore: remove the instance in unmounted
JaimeTorrealba 0c31f65
chore: adding dispose method to helper
JaimeTorrealba fff82fd
docs: remove copy/paste mistake
JaimeTorrealba 5254ac2
chore: add update method to helpers
JaimeTorrealba 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# v-light-helper 🔆 | ||
|
||
With the new directive v-light-helper provided by **TresJS**, you can add fast the respective helper to your lights with just one line of code 😍. | ||
|
||
```vue{3} | ||
<script setup lang="ts"> | ||
import { OrbitControls, Sphere, vLightHelper } from '@tresjs/cientos' | ||
</script> | ||
<template> | ||
<TresCanvas > | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<TresDirectionalLight | ||
v-light-helper | ||
/> | ||
<TresPointLight | ||
v-light-helper | ||
/> | ||
<TresSpotLight | ||
v-light-helper | ||
/> | ||
|
||
<TresHemisphereLight | ||
v-light-helper | ||
/> | ||
</TresCanvas> | ||
</template> | ||
``` | ||
|
||
Note that you can pass a modifier with the name of a property, for example `v-log:material`, and will log directly the `material` property | ||
|
||
::: 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 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,74 @@ | ||
<script setup lang="ts"> | ||
import { reactive, shallowRef } from 'vue' | ||
import { TresCanvas, useRenderLoop } from '@tresjs/core' | ||
import { OrbitControls, Sphere, vLightHelper } from '@tresjs/cientos' | ||
import { SRGBColorSpace, NoToneMapping } from 'three' | ||
|
||
const gl = { | ||
clearColor: '#333', | ||
outputColorSpace: SRGBColorSpace, | ||
toneMapping: NoToneMapping, | ||
} | ||
|
||
const directionalLightRef = shallowRef() | ||
const pointLightRef = shallowRef() | ||
const spotLightRef = shallowRef() | ||
|
||
const { onLoop } = useRenderLoop() | ||
|
||
onLoop(({ elapsed }) => { | ||
if (directionalLightRef.value ) { | ||
directionalLightRef.value.position.y = Math.sin(elapsed) * 1.5 + 2 | ||
|
||
} | ||
if (pointLightRef.value) { | ||
const lightAngle = elapsed * 0.5 | ||
pointLightRef.value.position.x = Math.cos(lightAngle) * 4 | ||
pointLightRef.value.position.z = Math.sin(lightAngle) * 4 | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<TresCanvas v-bind="gl"> | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<Sphere | ||
v-light-helper | ||
:scale="0.5" | ||
> | ||
<TresMeshStandardMaterial :color="0x222" /> | ||
</Sphere> | ||
<TresAmbientLight :color="0xffffff" /> | ||
<TresDirectionalLight | ||
ref="directionalLightRef" | ||
v-light-helper | ||
:color="0xffffff" | ||
:intensity="5" | ||
:position="[0, 2, 4]" | ||
/> | ||
<TresPointLight | ||
ref="pointLightRef" | ||
v-light-helper | ||
:color="0xff0000" | ||
:intensity="100" | ||
:position="[0, 1, 1]" | ||
/> | ||
<TresSpotLight | ||
ref="spotLightRef" | ||
v-light-helper | ||
:color="0x00ff00" | ||
:intensity="10" | ||
:position="[0, 1, 1]" | ||
/> | ||
|
||
<TresHemisphereLight | ||
v-light-helper | ||
:color="0x0000ff" | ||
:ground-color="0x00ffff" | ||
:intensity="50" | ||
/> | ||
|
||
<TresGridHelper :args="[10, 10]" /> | ||
<OrbitControls /> | ||
</TresCanvas> | ||
</template> |
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
<template> | ||
<Suspense> | ||
<DirectivesDemo /> | ||
<ModelsDemo /> | ||
</Suspense> | ||
</template> |
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,12 @@ | ||
export const directivesRoutes = [ | ||
{ | ||
path: '/directives/vlog', | ||
name: 'vLog', | ||
component: () => import('../../pages/directives/vLog.vue'), | ||
}, | ||
{ | ||
path: '/directives/v-light-helper', | ||
name: 'vLightHelper', | ||
component: () => import('../../pages/directives/vLightHelper.vue'), | ||
}, | ||
] |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { vLog } from './vLog' | ||
import { vLightHelper } from './vLightHelper' | ||
|
||
export { vLog } | ||
export { vLog, vLightHelper } |
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,22 @@ | ||
import { useLogger } from '@tresjs/core' | ||
import { DirectionalLightHelper, PointLightHelper, SpotLightHelper, HemisphereLightHelper } from 'three' | ||
|
||
const { logWarning } = useLogger() | ||
|
||
export const vLightHelper = { | ||
mounted: (el: any) => { | ||
if (!el.isLight) { | ||
logWarning(`${el.type} is not a light`) | ||
return | ||
} | ||
const currentHelper = helpers[el.type] | ||
JaimeTorrealba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
el.parent.add(new currentHelper(el)) | ||
}, | ||
} | ||
|
||
const helpers = { | ||
DirectionalLight: DirectionalLightHelper, | ||
PointLight: PointLightHelper, | ||
SpotLight: SpotLightHelper, | ||
HemisphereLight: HemisphereLightHelper, | ||
} |
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.
Copy paste ;) @JaimeTorrealba