-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
478 additions
and
202 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# v-rotate | ||
|
||
## Problem | ||
|
||
When you want to simply add rotation to your mesh, you have to use the template reference, [useRenderLoop](/api/composables#userenderloop) and then assign the axis and the speed, but before check if you mesh is already available: | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import { shallowRef, watch } from 'vue' | ||
import { useRenderLoop } from '@tresjs/core' | ||
const boxRef = shallowRef() | ||
const { onLoop } = useRenderLoop() | ||
onLoop(({ elapsed }) => { | ||
if (boxRef.value) { | ||
boxRef.value.rotation.x = elapsed | ||
} | ||
}) | ||
</script> | ||
<template> | ||
<TresCanvas> | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<TresMesh | ||
ref="boxRef" | ||
:scale="0.5" | ||
> | ||
<TresBoxGeometry /> | ||
<TresMesh> | ||
<OrbitControls /> | ||
</TresMesh> | ||
</TresMesh> | ||
</TresCanvas> | ||
</template> | ||
``` | ||
|
||
And is A LOT of code just for a simple rotation right? Normally we need something fast to see if something is working | ||
|
||
## Usage | ||
|
||
With the new directive v-rotate provided by **TresJS**, you can do this by just adding `v-rotate` to the instance. | ||
|
||
```vue{2,8} | ||
<script setup lang="ts"> | ||
import { vRotate } from '@tresjs/core' | ||
</script> | ||
<template> | ||
<TresCanvas > | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<TresMesh | ||
v-rotate // 😍 | ||
> | ||
<TresBoxGeometry /> | ||
</TresMesh> | ||
</TresCanvas> | ||
</template> | ||
``` | ||
By default `v-rotate` uses [Quaternions](https://threejs.org/docs/index.html?q=quater#api/en/math/Quaternion) so you don't have to worry by [Gimbal Lock](https://en.wikipedia.org/wiki/Gimbal_lock), or check if you mesh is available in the first frames. | ||
|
||
## Modifiers | ||
|
||
You can control the axis and the rotation speed by adding modifiers | ||
|
||
```vue{2,8} | ||
<script setup lang="ts"> | ||
import { vRotate } from '@tresjs/core' | ||
</script> | ||
<template> | ||
<TresCanvas > | ||
<TresPerspectiveCamera :position="[0, 2, 5]" /> | ||
<TresMesh | ||
v-rotate:x.y="0.1" // the axis will be x and y with a speed of 0.1 | ||
> | ||
<TresBoxGeometry /> | ||
</TresMesh> | ||
</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
Oops, something went wrong.