-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add v-distance-to directive proposal * chore: change life cycle from update to mounted in v-log directive * chore: update console.table show information * chore: add console.table, add new utils for extract position on binding * docs: apply review changes * chore: apply review changes, handle error null ref * chore: handle error null ref for vAlwaysLookAt * chore: fix log message for directives
- Loading branch information
1 parent
6efc076
commit d2e2521
Showing
9 changed files
with
143 additions
and
10 deletions.
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,36 @@ | ||
# v-distance-to | ||
|
||
Have you tried to calculate the distance between two Object3Ds? | ||
|
||
With the new directive `v-distance-to` it's easier than ever, you should only indicate the target object to perform the measure and the result will appear in your console. | ||
|
||
In addition, an arrow will be created to indicate which objects you're measuring. | ||
|
||
```vue{2,8,13} | ||
<script setup lang="ts"> | ||
import { OrbitControls, Sphere, vLog } from '@tresjs/cientos' | ||
</script> | ||
<template> | ||
<TresCanvas v-bind="gl"> | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<Sphere | ||
ref="sphere1Ref" | ||
:position="[-2, slider, 0]" | ||
:scale="0.5" | ||
/> | ||
<Sphere | ||
v-distance-to="sphere1Ref" | ||
:position="[2, 0, 0]" | ||
:scale="0.5" | ||
/> | ||
<TresGridHelper :args="[10, 10]" /> | ||
<OrbitControls /> | ||
</TresCanvas> | ||
</template> | ||
``` | ||
|
||
The use of `v-distance-to` is reactive, so it works perfectly with @tres/leches 🍰. | ||
|
||
::: warning | ||
`v-distance-to` will not measure an object in movement within the renderLoop. | ||
::: |
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,44 @@ | ||
<script setup lang="ts"> | ||
import { shallowRef } from 'vue' | ||
import { TresCanvas } from '@tresjs/core' | ||
import { OrbitControls, Sphere, vDistanceTo } from '@tresjs/cientos' | ||
import { SRGBColorSpace, NoToneMapping } from 'three' | ||
import { useControls, TresLeches } from '@tresjs/leches' | ||
import '@tresjs/leches/styles' | ||
const gl = { | ||
clearColor: '#333', | ||
outputColorSpace: SRGBColorSpace, | ||
toneMapping: NoToneMapping, | ||
} | ||
const sphere1Ref = shallowRef() | ||
const { value: slider } = useControls({ | ||
slider: { | ||
value: -2, | ||
min: -4, | ||
max: 2, | ||
step: 0.1, | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<TresLeches class="top-0 important-left-4" /> | ||
<TresCanvas v-bind="gl"> | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<Sphere | ||
ref="sphere1Ref" | ||
:position="[-2, slider, 0]" | ||
:scale="0.5" | ||
/> | ||
<Sphere | ||
v-distance-to="sphere1Ref" | ||
:position="[2, 0, 0]" | ||
:scale="0.5" | ||
/> | ||
<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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { vLog } from './vLog' | ||
import { vLightHelper } from './vLightHelper' | ||
import { vAlwaysLookAt } from './vAlwaysLookAt' | ||
import { vDistanceTo } from './vDistanceTo' | ||
|
||
export { vLog, vLightHelper, vAlwaysLookAt } | ||
export { vLog, vLightHelper, vAlwaysLookAt, vDistanceTo } |
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,35 @@ | ||
import { useLogger } from '@tresjs/core' | ||
import { ArrowHelper } from 'three' | ||
import { extractBindingPosition } from '../../utils/index' | ||
|
||
const { logWarning } = useLogger() | ||
|
||
export const vDistanceTo = { | ||
updated: (el: any, binding: any) => { | ||
const observer = extractBindingPosition(binding) | ||
if (!observer) { | ||
logWarning(`v-distance-to: problem with binding value: ${binding.value}`) | ||
return | ||
} | ||
if (arrowHelper) { | ||
arrowHelper.dispose() | ||
el.parent.remove(arrowHelper) | ||
} | ||
const dir = observer.clone().sub(el.position) | ||
dir.normalize() | ||
arrowHelper = new ArrowHelper( dir, el.position, el.position.distanceTo(observer) / 1.5, 0xffff00 ) | ||
el.parent.add( arrowHelper ) | ||
// eslint-disable-next-line no-console | ||
console.table([ | ||
['Distance:', el.position.distanceTo(observer)], | ||
[`origin: ${el.name || el.type}`, `x:${el.position.x}, y:${el.position.y}, z:${el.position?.z}`], | ||
[`Destiny: ${el.name || el.type}`, `x:${observer.x}, y:${observer.y}, z:${observer?.z}`], | ||
], | ||
) | ||
}, | ||
unmounted: (el: any) => { | ||
arrowHelper?.dispose() | ||
el.parent.remove(arrowHelper) | ||
}, | ||
} | ||
let arrowHelper: ArrowHelper | null = null |
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