Skip to content

Commit

Permalink
feat: Add cylinder component
Browse files Browse the repository at this point in the history
* add cylinder component + docs
  • Loading branch information
schplitt authored Jun 9, 2024
1 parent 77b2220 commit 9e17559
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/component-list/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default [
{ text: 'CatmullRomCurve3', link: '/guide/shapes/catmullromcurve3' },
{ text: 'Circle', link: '/guide/shapes/circle' },
{ text: 'Cone', link: '/guide/shapes/cone' },
{ text: 'Cylinder', link: '/guide/shapes/cylinder' },

Check failure on line 71 in docs/component-list/components.ts

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected tab character

Check failure on line 71 in docs/component-list/components.ts

View workflow job for this annotation

GitHub Actions / Lint (18)

Mixed spaces and tabs
{ text: 'Dodecahedron', link: '/guide/shapes/dodecahedron' },
{ text: 'Icosahedron', link: '/guide/shapes/icosahedron' },
{ text: 'Line2', link: '/guide/shapes/line2' },
Expand Down
31 changes: 31 additions & 0 deletions docs/guide/shapes/cylinder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Cylinder <Badge type="warning" text="^4.0.0" />

![](/cientos/cylinder.png)

The `cientos` package provides a `<Cylinder />` component that serves as a short-cut for a `CylinderGeometry` and a `MeshBasicMaterial` with a `Mesh` object.

```

Check failure on line 7 in docs/guide/shapes/cylinder.md

View workflow job for this annotation

GitHub Actions / Lint (18)

Trailing spaces not allowed
args: [
radiusTop: number,
radiusBottom: number,
height: number,
radialSegments: number,
heightSegments: number,
openEnded: boolean,
thetaStart: number,
thetaLength: number
]
```

Reference: [CylinderGeometry](https://threejs.org/docs/?q=cylinder#api/en/geometries/CylinderGeometry)

## Usage

```vue
<Cylinder :args="[1, 1, 1, 32, 1, false, 0, Math.PI * 2]" color="orange" />
// Cylinder with a custom material transformations
<Cylinder ref="cylinderRef" :args="[1, 1, 1, 32, 1, false, 0, Math.PI * 2]" :position="[0, 4, 0]">
<TresMeshToonMaterial color="orange" />
</Cylinder>
```

Check failure on line 31 in docs/guide/shapes/cylinder.md

View workflow job for this annotation

GitHub Actions / Lint (18)

Newline required at end of file but not found
Binary file added docs/public/cientos/cylinder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions src/core/shapes/Cylinder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script setup lang="ts">
import type { TresColor } from '@tresjs/core'

Check failure on line 2 in src/core/shapes/Cylinder.vue

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected tab character

Check failure on line 2 in src/core/shapes/Cylinder.vue

View workflow job for this annotation

GitHub Actions / Lint (18)

Expected indentation of 0 spaces but found 1 tab
import type { CylinderGeometry } from 'three'

Check failure on line 3 in src/core/shapes/Cylinder.vue

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected tab character

Check failure on line 3 in src/core/shapes/Cylinder.vue

View workflow job for this annotation

GitHub Actions / Lint (18)

Expected indentation of 0 spaces but found 1 tab
import { shallowRef, toRefs } from 'vue'

Check failure on line 4 in src/core/shapes/Cylinder.vue

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected tab character

Check failure on line 4 in src/core/shapes/Cylinder.vue

View workflow job for this annotation

GitHub Actions / Lint (18)

Expected indentation of 0 spaces but found 1 tab
export interface CylinderProps {
/**
* The radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength of the cylinder.
* @default [1, 1, 1, 32, 1, false, 0, Math.PI * 2]
* @type {any[]}
* @memberof CylinderProps
* @see https://threejs.org/docs/#api/en/geometries/CylinderGeometry
*/
args?: ConstructorParameters<typeof CylinderGeometry>
/**
* The color of the cylinder.
* @default 0xffffff
* @type {TresColor}
* @memberof CylinderProps
* @see https://threejs.org/docs/#api/en/materials/MeshBasicMaterial
*/
color?: TresColor
}
const props = withDefaults(defineProps<CylinderProps>(), {
args: () => [1, 1, 1, 32, 1, false, 0, Math.PI * 2],
color: '#ffffff',
})
const { args, color } = toRefs(props)
const cylinderRef = shallowRef()
defineExpose({
value: cylinderRef,
})
</script>

<template>
<TresMesh ref="cylinderRef" v-bind="$attrs">
<TresCylinderGeometry :args="args" />
<slot>
<TresMeshBasicMaterial :color="color" />
</slot>
</TresMesh>
</template>
2 changes: 2 additions & 0 deletions src/core/shapes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Box from './Box.vue'
import CatmullRomCurve3 from './CatmullRomCurve3.vue'
import Circle from './Circle.vue'
import Cone from './Cone.vue'
import Cylinder from './Cylinder.vue'
import Dodecahedron from './Dodecahedron.vue'
import Icosahedron from './Icosahedron.vue'
import Line2 from './Line2.vue'
Expand All @@ -20,6 +21,7 @@ export {
Box,
CatmullRomCurve3,
Circle,
Cylinder,
Cone,
Dodecahedron,
Icosahedron,
Expand Down

0 comments on commit 9e17559

Please sign in to comment.