Skip to content

Commit

Permalink
Merge pull request #234 from Tresjs/docs/expand-precipitation-docs
Browse files Browse the repository at this point in the history
docs: add more examples of the precipitation component
  • Loading branch information
JaimeTorrealba authored Sep 25, 2023
2 parents 630f381 + b3fe3e9 commit 11e0413
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 27 deletions.
31 changes: 31 additions & 0 deletions docs/.vitepress/theme/components/PrecipitationBeamDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { shallowRef, reactive } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
import { SRGBColorSpace, NoToneMapping } from 'three'
const gl = {
clearColor: '#333',
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
const precipitationRef = shallowRef()
</script>

<template>
<TresCanvas
v-bind="gl"
>
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
ref="precipitationRef"
:position="[0, 3, 7.5]"
:randomness="0"
:speed="0.5"
:count="2000"
:area="[1, 10, 1]"
/>
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
20 changes: 2 additions & 18 deletions docs/.vitepress/theme/components/PrecipitationDemo.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { shallowRef, reactive } from 'vue'
import { shallowRef } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls, Precipitation } from '@tresjs/cientos'
import { Precipitation } from '@tresjs/cientos'
import { SRGBColorSpace, NoToneMapping } from 'three'
const gl = {
Expand All @@ -11,16 +11,6 @@ const gl = {
}
const precipitationRef = shallowRef()
const options = reactive({
speed: 1,
randomness: 0,
count: 1000,
size: 0.1,
areaX: 25,
areaY: 25,
areaZ: 25,
})
</script>

<template>
Expand All @@ -30,13 +20,7 @@ const options = reactive({
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
ref="precipitationRef"
:speed="options.speed"
:area="[options.areaX, options.areaY, options.areaZ]"
:count="options.count"
:randomness="options.randomness"
:size="options.size"
/>
<TresGridHelper :args="[10, 10]" />
<OrbitControls />
</TresCanvas>
</template>
29 changes: 29 additions & 0 deletions docs/.vitepress/theme/components/PrecipitationRainDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
import { shallowRef, reactive } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
import { SRGBColorSpace, NoToneMapping } from 'three'
const gl = {
clearColor: '#333',
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
const precipitationRef = shallowRef()
</script>

<template>
<TresCanvas
v-bind="gl"
>
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
ref="precipitationRef"
:randomness="0"
:speed="1"
:count="2500"
/>
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
29 changes: 29 additions & 0 deletions docs/.vitepress/theme/components/PrecipitationStormDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
import { shallowRef, reactive } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
import { SRGBColorSpace, NoToneMapping } from 'three'
const gl = {
clearColor: '#333',
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
const precipitationRef = shallowRef()
</script>

<template>
<TresCanvas
v-bind="gl"
>
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
ref="precipitationRef"
:randomness="3"
:speed="1"
:count="2500"
/>
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
82 changes: 73 additions & 9 deletions docs/guide/staging/precipitation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,97 @@

## Usage

You can use `<Precipitation />` component without passing any props.
You can use `<Precipitation />` component without passing any props, this will achieve a snowy effect, like the before example.

```vue
```vue{8}
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
</script>
<template>
<TresCanvas>
...
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation />
...
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
```

To create uniques effects play around with the different props available
By setting the randomness to 0, increase the speed and reduce the count. You can easily achieve a more rainy effect.

```vue
<DocsDemo>
<PrecipitationRainDemo />
</DocsDemo>


```vue{9,10,11}
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
</script>
<template>
<TresCanvas>
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
:speed="1"
:randomness="0"
:count="2500"
/>
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
```
A storm effect? Easy just increase the randomness.

<DocsDemo>
<PrecipitationStormDemo />
</DocsDemo>

```vue{9,10,11}
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
</script>
<template>
<TresCanvas>
...
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
:speed="1"
:randomness="3"
:count="2500"
:map="myTexture"
/>
...
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
```

What about an infinite beam?.

<DocsDemo>
<PrecipitationBeamDemo />
</DocsDemo>

Just set the area, to the axis that you need constrain.

```vue{9,10,11,12}
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { Precipitation } from '@tresjs/cientos'
</script>
<template>
<TresCanvas>
<TresPerspectiveCamera :position="[0, 2, 15]" />
<Precipitation
:randomness="0"
:speed="0.5"
:count="2000"
:area="[1, 10, 1]"
/>
<TresGridHelper :args="[10, 10]" />
</TresCanvas>
</template>
```
You can create much more! ☔

::: warning
Be careful with the performance this components render infinite particles in movement
Expand Down

0 comments on commit 11e0413

Please sign in to comment.