Browse Source

feat(cientos): sphere abstraction

astanusic 2 years ago
parent
commit
e2a6fff864

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

+ 13 - 1
packages/cientos/src/index.ts

@@ -7,8 +7,20 @@ import { FBXModel } from './core/useFBX/component'
 import Text3D from './core/Text3D.vue'
 import Plane from './core/Plane.vue'
 import Box from './core/Box.vue'
+import Sphere from './core/Sphere.vue'
 
 export * from './core/useGLTF'
 export * from './core/useFBX'
 export * from './types'
-export { OrbitControls, TransformControls, useTweakPane, GLTFModel, FBXModel, Text3D, Plane, Box, useAnimations }
+export {
+  OrbitControls,
+  TransformControls,
+  useTweakPane,
+  GLTFModel,
+  FBXModel,
+  Text3D,
+  Plane,
+  Box,
+  Sphere,
+  useAnimations,
+}

+ 5 - 2
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, OrbitControls } from '../../../cientos/src/'
+import { Plane, Box, Sphere, OrbitControls } from '../../../cientos/src/'
 
 const state = reactive({
   clearColor: '#82DBC5',
@@ -29,9 +29,12 @@ watch(planeRef, plane => {
       <Plane ref="planeRef" :args="[8, 8]" :position="[0, 4, 0]" receive-shadow>
         <TresMeshToonMaterial color="teal" />
       </Plane>
-      <Box ref="boxRef" :args="[1, 1, 1]" :position="[0, 6, 0]" cast-shadow>
+      <Box ref="boxRef" :arg0s="[1, 1, 1]" :position="[0, 6, 0]" cast-shadow>
         <TresMeshToonMaterial color="orange" />
       </Box>
+      <Sphere ref="sphereRef" :args="[1, 32, 16]" :position="[2, 6, 0]" cast-shadow>
+        <TresMeshToonMaterial color="pink" />
+      </Sphere>
     </TresScene>
   </TresCanvas>
 </template>