From 60c200d19d7f82781632576c22e3b15ea118ac5c Mon Sep 17 00:00:00 2001 From: Damien Montastier Date: Wed, 4 Dec 2024 07:47:29 +0100 Subject: [PATCH] feat: edges (#390) * feat: add edges component * feat(cientos/edges): rework code and playground demo * feat(cientos/edges): rework code and playground demo - fix lint * feat(cientos/edges): wip doc * feat(cientos/edges): wip documentation and demo * update edge component * update merge main * review fix --------- Co-authored-by: Alvaro Saburido --- docs/.vitepress/config.ts | 2 + .../.vitepress/theme/components/EdgesDemo.vue | 55 +++++++++++++++ docs/guide/abstractions/edges.md | 62 +++++++++++++++++ .../vue/src/pages/abstractions/EdgesDemo.vue | 69 +++++++++++++++++++ .../vue/src/router/routes/abstractions.ts | 5 ++ src/core/abstractions/Edges.vue | 61 ++++++++++++++++ src/core/abstractions/index.ts | 2 + 7 files changed, 256 insertions(+) create mode 100644 docs/.vitepress/theme/components/EdgesDemo.vue create mode 100644 docs/guide/abstractions/edges.md create mode 100644 playground/vue/src/pages/abstractions/EdgesDemo.vue create mode 100644 src/core/abstractions/Edges.vue diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 38cd2a1d..ffe24e8d 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -75,6 +75,8 @@ export default defineConfig({ { text: 'useFBO', link: '/guide/abstractions/use-fbo' }, { text: 'useSurfaceSampler', link: '/guide/abstractions/use-surface-sampler' }, { text: 'Sampler', link: '/guide/abstractions/sampler' }, + { text: 'Edges', link: '/guide/abstractions/edges' }, + { text: 'PositionalAudio', link: '/guide/abstractions/positional-audio' }, { text: 'AnimatedSprite', link: '/guide/abstractions/animated-sprite' }, { text: 'Billboard', link: '/guide/abstractions/billboard' }, ], diff --git a/docs/.vitepress/theme/components/EdgesDemo.vue b/docs/.vitepress/theme/components/EdgesDemo.vue new file mode 100644 index 00000000..7e436ced --- /dev/null +++ b/docs/.vitepress/theme/components/EdgesDemo.vue @@ -0,0 +1,55 @@ + + + diff --git a/docs/guide/abstractions/edges.md b/docs/guide/abstractions/edges.md new file mode 100644 index 00000000..b0e75c41 --- /dev/null +++ b/docs/guide/abstractions/edges.md @@ -0,0 +1,62 @@ +# Edges + + + + + +The `cientos` package provides an abstraction of [EdgesGeometry](https://threejs.org/docs/#api/en/geometries/EdgesGeometry) from Three.js, `` is specifically designed for rendering visible edges of objects in a scene graph. This enhances the visual quality by highlighting contours and providing a stylized appearance which contributes to the artistic aspect of 3D visualizations. + +## Usage + +<<< @/.vitepress/theme/components/EdgesDemo.vue + +The `` component is easy to set up as it automatically derives geometry from its parent. You can simply wrap it around any [Object3D](https://threejs.org/docs/#api/en/core/Object3D), [Mesh](https://threejs.org/docs/#api/en/objects/Mesh), or [primitive](https://docs.tresjs.org/advanced/primitive.html) to automatically apply edge rendering. You can provide a custom material to ``. When a custom material is used, the color prop has no effect. *(see code bellow)* + +```vue + + + +``` + +## Props + +`` is based on [LineSegments](https://threejs.org/docs/#api/en/objects/LineSegments) & [Line](https://threejs.org/docs/#api/en/objects/Line) and supports all of its props. + +| Prop | Description | Default | +| :---------------- | :--------------------------------------------------- | ------------------------- | +| **color** | `THREE.Color` — Color of the edges.
More informations : [TresColor](https://docs.tresjs.org/api/instances-arguments-and-props.html#colors) — [THREE.Color](https://threejs.org/docs/#api/en/math/Color) | `#ff0000` | +| **threshold** | `number` — An edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value | `1` | + +## Exposed properties + +| Event | Description | +| :---------- | :--------------------------------------------------------------- | +| `instance` | Instance reference — Inheritance of [LineSegments](https://threejs.org/docs/#api/en/objects/LineSegments).| + +```typescript{1} +const edgesRef = shallowRef(null) + +console.log(edgesRef.value.instance) // instance properties +``` + +```vue{2} + +``` diff --git a/playground/vue/src/pages/abstractions/EdgesDemo.vue b/playground/vue/src/pages/abstractions/EdgesDemo.vue new file mode 100644 index 00000000..c64d2746 --- /dev/null +++ b/playground/vue/src/pages/abstractions/EdgesDemo.vue @@ -0,0 +1,69 @@ + + + diff --git a/playground/vue/src/router/routes/abstractions.ts b/playground/vue/src/router/routes/abstractions.ts index 574fbdbe..b03dafe3 100644 --- a/playground/vue/src/router/routes/abstractions.ts +++ b/playground/vue/src/router/routes/abstractions.ts @@ -49,6 +49,11 @@ export const abstractionsRoutes = [ name: 'Sampler', component: () => import('../../pages/abstractions/Sampler.vue'), }, + { + path: '/abstractions/edges', + name: 'Edges', + component: () => import('../../pages/abstractions/EdgesDemo.vue'), + }, { path: '/abstractions/positional-audio', name: 'PositionalAudio', diff --git a/src/core/abstractions/Edges.vue b/src/core/abstractions/Edges.vue new file mode 100644 index 00000000..84bd30ff --- /dev/null +++ b/src/core/abstractions/Edges.vue @@ -0,0 +1,61 @@ + + + diff --git a/src/core/abstractions/index.ts b/src/core/abstractions/index.ts index 61379fb9..7eb9797d 100644 --- a/src/core/abstractions/index.ts +++ b/src/core/abstractions/index.ts @@ -10,12 +10,14 @@ import Text3D from './Text3D.vue' import { useAnimations } from './useAnimations' import Fbo from './useFBO/component.vue' import Sampler from './useSurfaceSampler/component.vue' +import Edges from './Edges.vue' export * from '../staging/useEnvironment' export * from './useFBO/' export * from './useSurfaceSampler' export { AnimatedSprite, + Edges, Billboard, Fbo, GlobalAudio,