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

docs: add tresjs (vue) to docs #46

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ function Cube() {
}
```

</details>
<details>
<summary>Show Vue (Tresjs) example</summary>
FarazzShaikh marked this conversation as resolved.
Show resolved Hide resolved

*You need to have installed [Cientos](https://cientos.tresjs.org/) pkg to use this component.*

```vue
<script setup>
import { CustomShaderMaterial } from '@tresjs/cientos'

</script>
<template>
<TresMesh>
<TresTorusKnotGeometry :args="[1, 0.3, 512, 32]" />
<CustomShaderMaterial
:baseMaterial="THREE.MeshPhysicalMaterial"
:vertexShader="yourGLSLVertex"
:fragmentShader="yourGLSLFragment"
:uniforms="yourUniforms"
silent
/>
</TresMesh>
</template>
```

</details>

## Installation
Expand Down Expand Up @@ -222,6 +247,43 @@ function Cube() {

</details>

<details >
<summary>Show Vue (Tresjs) example</summary>

```vue
<script setup>
import {ref } from 'vue'
import { CustomShaderMaterial } from '@tresjs/cientos'

const materialBase = ref()
</script>

<template>
<TresMesh>
<TresTorusKnotGeometry :args="[1, 0.3, 512, 32]" />
<CustomShaderMaterial
ref="materialBase"
:baseMaterial="THREE.MeshPhysicalMaterial"
:vertexShader="yourGLSLVertex"
:fragmentShader="yourGLSLFragment"
:uniforms="yourUniforms"
silent
/>
</TresMesh>

<TresMesh v-if="materialBase">
<TresSphereGeometry :args="[0.5, 16, 16]" />
<CustomShaderMaterial
:base-material="new CustomShaderMaterialImpl({
baseMaterial: materialBase.value,
})"
/>
</TresMesh>
</template>
```

</details>

### Gotchas

- When extending already extended material, variables, uniforms, attributes, varyings and functions are **NOT** scoped to the material they are defined in. Thus, you **WILL** get redefinition errors if you do not manually scope these identifiers.
Expand Down Expand Up @@ -260,6 +322,10 @@ CSM has a non-negligible startup cost, i.e it does take more milliseconds than a

You can provide your own cache key function via the `cacheKey` prop.

> Note: CSM will only rebuild if the **reference** to the above props change, for example, in React, doing `uniforms={{...}}` means that the uniforms object is unstable, i.e. it is re-created, with a **new** reference every render. Instead, condsider memoizing the uniforms prop `const uniforms = useMemo(() -> ({...}));`. The uniforms object will then have the same refrence on every render.

> If the uniforms are memoized, changing their value by doing `uniforms.foo.value = ...` will not cause CSM to rebuild, as the refrence of `uniforms` does not change.

## Development

```sh
Expand Down
Loading