Преглед изворни кода

feat(cientos): circle abstraction

astanusic пре 2 година
родитељ
комит
978eb2da60

+ 29 - 0
packages/cientos/src/core/Circle.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, 32],
+    color: '0xffffff',
+  },
+)
+
+const circleRef = shallowRef()
+
+defineExpose({
+  value: circleRef,
+})
+</script>
+<template>
+  <TresMesh ref="circleRef" v-bind="$attrs">
+    <TresCircleGeometry :args="args" />
+    <slot>
+      <TresMeshBasicMaterial :color="color" />
+    </slot>
+  </TresMesh>
+</template>

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

@@ -10,6 +10,7 @@ import Box from './core/Box.vue'
 import Sphere from './core/Sphere.vue'
 import Torus from './core/Torus.vue'
 import TorusKnot from './core/TorusKnot.vue'
+import Circle from './core/Circle.vue'
 
 export * from './core/useGLTF'
 export * from './core/useFBX'
@@ -26,5 +27,6 @@ export {
   Sphere,
   Torus,
   TorusKnot,
+  Circle,
   useAnimations,
 }

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

@@ -1,7 +1,7 @@
 <script setup lang="ts">
-import { BasicShadowMap, NoToneMapping, sRGBEncoding } from 'three'
+import { BasicShadowMap, DoubleSide, NoToneMapping, sRGBEncoding } from 'three'
 import { reactive, shallowRef, watch } from 'vue'
-import { Plane, Box, Sphere, Torus, TorusKnot, OrbitControls } from '../../../cientos/src/'
+import { Plane, Box, Sphere, Torus, TorusKnot, Circle, OrbitControls } from '../../../cientos/src/'
 
 const state = reactive({
   clearColor: '#82DBC5',
@@ -17,6 +17,7 @@ const planeRef = shallowRef()
 const boxRef = shallowRef()
 const torusRef = shallowRef()
 const torusKnotRef = shallowRef()
+const circleRef = shallowRef()
 
 watch(planeRef, plane => {
   console.log('plane', plane.value.position)
@@ -30,6 +31,9 @@ watch(torusRef, torus => {
 watch(torusKnotRef, torusKnot => {
   console.log('torusKnot', torusKnot.value.position)
 })
+watch(circleRef, circle => {
+  console.log('circle', circle.value.position)
+})
 </script>
 <template>
   <TresCanvas v-bind="state">
@@ -53,6 +57,9 @@ watch(torusKnotRef, torusKnot => {
       <TorusKnot ref="torusKnotRef" :args="[0.6, 0.2, 64, 8]" :position="[-2, 6, 2]" cast-shadow>
         <TresMeshToonMaterial color="lime" />
       </TorusKnot>
+      <Circle ref="circleRef" :args="[0.9, 32]" :position="[0, 6, 2]" :rotation="[Math.PI, 0, 0]" cast-shadow>
+        <TresMeshToonMaterial color="lightsalmon" :side="DoubleSide" />
+      </Circle>
     </TresScene>
   </TresCanvas>
 </template>