From 4a2e09682e54f314386e91bf1d930a260634a50b Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 3 Nov 2024 15:58:35 +0100 Subject: [PATCH] docs(attach): add documentation for attach prop --- docs/.vitepress/config/en.ts | 1 + docs/advanced/attach.md | 190 +++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 docs/advanced/attach.md diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index 007ee1852..3ce52eaa3 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -45,6 +45,7 @@ export const enConfig: LocaleSpecificConfig = { { text: 'Extending', link: '/advanced/extending' }, { text: 'Primitives', link: '/advanced/primitive' }, { text: 'Scaling Performance 🚀', link: '/advanced/performance' }, + { text: 'Attach', link: '/advanced/attach' }, { text: 'Caveats', link: '/advanced/caveats', diff --git a/docs/advanced/attach.md b/docs/advanced/attach.md new file mode 100644 index 000000000..d16bcb599 --- /dev/null +++ b/docs/advanced/attach.md @@ -0,0 +1,190 @@ +# `attach` 🖇 + +Using the `attach` prop, you can tell Tres exactly where you want to insert a child into its parent. + +:::info + +The `attach` prop is not required for many common cases. For instance: + +* adding a single `` to a `` +* adding a `` to a `` +* adding one or more ``s to a parent `` + +::: + +## Background + +Tres tries to automatically determine where to insert child tag into its parent. For example, in this code, Tres will: + +* automatically insert the geometry into `parent.geometry` +* automatically insert the material into `parent.material` + +```vue + +``` + +## Problem + +Tres covers common cases, like above. But it doesn't cover every possible case. + +When Tres doesn't automatically choose the proper insertion location for a child, one solution is to fall back to procedural code in ` + + +``` + +But this workaround means: + +* your materials aren't managed by Tres +* your code is imperative, not declarative +* your code is non-reactive by default + +## Solution + +The `attach` prop lets you specify where an object will be added to the parent object using declarative code. + +## Usage + +Here's the example above, rewritten declaratively using `attach`: + +```vue + +``` + +## "Pierced" `attach` + +You can deeply attach a child to a parent by "piercing" – i.e., using a kebab-case string. + +### Pseudocode + +First, here are a few simple pseudocode examples. This will attach `bar` at `foo.ab.cd`: + +```html + + + +``` + +This will attach `bar` at `foo.ab.cd.ef`: + +```html + + + +``` + +### Usage + +As a concrete example, you can used "pierced" `attach` to add custom `BufferAttribute`s: + +```vue + + + +``` + +## Arrays + +You can attach within arrays by using array indices in the `attach` string. + +### Usage + +For example, you can use array indices to attach `THREE` post-processing passes to the `THREE.EffectComposer.passes` array: + +```vue + + + +```