Преглед на файлове

feat(cientos) ring abstraction

astanusic преди 2 години
родител
ревизия
196edcaa54
променени са 3 файла, в които са добавени 40 реда и са изтрити 1 реда
  1. 29 0
      packages/cientos/src/core/Ring.vue
  2. 2 0
      packages/cientos/src/index.ts
  3. 9 1
      packages/tres/src/components/Shapes.vue

+ 29 - 0
packages/cientos/src/core/Ring.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: () => [0.5, 1, 32],
+    color: '0xffffff',
+  },
+)
+
+const ringRef = shallowRef()
+
+defineExpose({
+  value: ringRef,
+})
+</script>
+<template>
+  <TresMesh ref="ringRef" :rotation="[-Math.PI / 2, 0, 0]" v-bind="$attrs">
+    <TresRingGeometry :args="args" />
+    <slot>
+      <TresMeshBasicMaterial :color="color" />
+    </slot>
+  </TresMesh>
+</template>

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

@@ -13,6 +13,7 @@ import TorusKnot from './core/TorusKnot.vue'
 import Circle from './core/Circle.vue'
 import Circle from './core/Circle.vue'
 import Cone from './core/Cone.vue'
 import Cone from './core/Cone.vue'
 import Tube from './core/Tube.vue'
 import Tube from './core/Tube.vue'
+import Ring from './core/Ring.vue'
 
 
 export * from './core/useGLTF'
 export * from './core/useGLTF'
 export * from './core/useFBX'
 export * from './core/useFBX'
@@ -32,5 +33,6 @@ export {
   Circle,
   Circle,
   Cone,
   Cone,
   Tube,
   Tube,
+  Ring,
   useAnimations,
   useAnimations,
 }
 }

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

@@ -1,7 +1,7 @@
 <script setup lang="ts">
 <script setup lang="ts">
 import { BasicShadowMap, CubicBezierCurve3, DoubleSide, NoToneMapping, sRGBEncoding, Vector3 } from 'three'
 import { BasicShadowMap, CubicBezierCurve3, DoubleSide, NoToneMapping, sRGBEncoding, Vector3 } from 'three'
 import { reactive, ref, shallowRef, watch } from 'vue'
 import { reactive, ref, shallowRef, watch } from 'vue'
-import { Plane, Tube, Box, Sphere, Torus, TorusKnot, Circle, Cone, OrbitControls } from '../../../cientos/src/'
+import { Plane, Tube, Box, Sphere, Torus, Ring, TorusKnot, Circle, Cone, OrbitControls } from '../../../cientos/src/'
 
 
 const state = reactive({
 const state = reactive({
   clearColor: '#82DBC5',
   clearColor: '#82DBC5',
@@ -19,6 +19,7 @@ const torusRef = shallowRef()
 const torusKnotRef = shallowRef()
 const torusKnotRef = shallowRef()
 const circleRef = shallowRef()
 const circleRef = shallowRef()
 const tubeRef = shallowRef()
 const tubeRef = shallowRef()
+const ringRef = shallowRef()
 
 
 watch(planeRef, plane => {
 watch(planeRef, plane => {
   console.log('plane', plane.value.position)
   console.log('plane', plane.value.position)
@@ -38,6 +39,10 @@ watch(circleRef, circle => {
 watch(tubeRef, tube => {
 watch(tubeRef, tube => {
   console.log('tube', tube.value.position)
   console.log('tube', tube.value.position)
 })
 })
+watch(ringRef, ring => {
+  console.log('ring', ring.value.position)
+})
+
 const tubePath = new CubicBezierCurve3(
 const tubePath = new CubicBezierCurve3(
   new Vector3(-1, 0, 0),
   new Vector3(-1, 0, 0),
   new Vector3(-0.5, -1, 0),
   new Vector3(-0.5, -1, 0),
@@ -77,6 +82,9 @@ const tubePath = new CubicBezierCurve3(
       <Tube ref="tubeRef" :args="[tubePath, 20, 0.2, 8, false]" :position="[2, 6, -2]" cast-shadow>
       <Tube ref="tubeRef" :args="[tubePath, 20, 0.2, 8, false]" :position="[2, 6, -2]" cast-shadow>
         <TresMeshToonMaterial color="lightblue" />
         <TresMeshToonMaterial color="lightblue" />
       </Tube>
       </Tube>
+      <Ring ref="ringRef" :args="[0.5, 1, 32]" :position="[0, 6, -2]" :rotation="[Math.PI, 0, 0]" cast-shadow>
+        <TresMeshToonMaterial color="purple" :side="DoubleSide" />
+      </Ring>
     </TresScene>
     </TresScene>
   </TresCanvas>
   </TresCanvas>
 </template>
 </template>