ソースを参照

feat(cientos): torus abstraction

astanusic 2 年 前
コミット
d85eb4091e

+ 29 - 0
packages/cientos/src/core/Torus.vue

@@ -0,0 +1,29 @@
+<script setup lang="ts">
+import { TresColor } from '@tresjs/core/dist/types'
+import { shallowRef } from 'vue'
+
+withDefaults(
+  defineProps<{
+    args?: number[]
+    color?: TresColor
+  }>(),
+  {
+    args: () => [1, 1, 16, 80],
+    color: '0xffffff',
+  },
+)
+
+const torusRef = shallowRef()
+
+defineExpose({
+  value: torusRef,
+})
+</script>
+<template>
+  <TresMesh ref="torusRef" v-bind="$attrs">
+    <TresTorusGeometry :args="args" />
+    <slot>
+      <TresMeshBasicMaterial :color="color" />
+    </slot>
+  </TresMesh>
+</template>

+ 2 - 0
packages/cientos/src/index.ts

@@ -8,6 +8,7 @@ import Text3D from './core/Text3D.vue'
 import Plane from './core/Plane.vue'
 import Box from './core/Box.vue'
 import Sphere from './core/Sphere.vue'
+import Torus from './core/Torus.vue'
 
 export * from './core/useGLTF'
 export * from './core/useFBX'
@@ -22,5 +23,6 @@ export {
   Plane,
   Box,
   Sphere,
+  Torus,
   useAnimations,
 }

+ 12 - 1
packages/tres/src/components/Shapes.vue

@@ -1,7 +1,7 @@
 <script setup lang="ts">
 import { BasicShadowMap, NoToneMapping, sRGBEncoding } from 'three'
 import { reactive, shallowRef, watch } from 'vue'
-import { Plane, Box, Sphere, OrbitControls } from '../../../cientos/src/'
+import { Plane, Box, Sphere, Torus, OrbitControls } from '../../../cientos/src/'
 
 const state = reactive({
   clearColor: '#82DBC5',
@@ -14,10 +14,18 @@ const state = reactive({
 })
 
 const planeRef = shallowRef()
+const boxRef = shallowRef()
+const torusRef = shallowRef()
 
 watch(planeRef, plane => {
   console.log('plane', plane.value.position)
 })
+watch(boxRef, box => {
+  console.log('box', box.value.position)
+})
+watch(torusRef, torus => {
+  console.log('torus', torus.value.position)
+})
 </script>
 <template>
   <TresCanvas v-bind="state">
@@ -35,6 +43,9 @@ watch(planeRef, plane => {
       <Sphere ref="sphereRef" :args="[1, 32, 16]" :position="[2, 6, 0]" cast-shadow>
         <TresMeshToonMaterial color="pink" />
       </Sphere>
+      <Torus ref="torusRef" :args="[0.75, 0.4, 16, 80]" :position="[-2, 6, 0]" cast-shadow>
+        <TresMeshToonMaterial color="cyan" />
+      </Torus>
     </TresScene>
   </TresCanvas>
 </template>