Skip to content

Commit

Permalink
feat(cientos): Refactor OrbitControls to use new extend API
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Dec 6, 2022
1 parent 815b839 commit 7251b60
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
55 changes: 52 additions & 3 deletions packages/cientos/src/core/OrbitControls.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
<script setup lang="ts">
<script lang="ts" setup>
import { Camera, Vector3, WebGLRenderer } from 'three'
import { OrbitControls } from 'three-stdlib'
import { inject, ref, type Ref } from 'vue'
import { useCientos } from './useCientos'
const props = withDefaults(
defineProps<{
makeDefault?: boolean
camera?: Camera
domElement?: HTMLElement
target?: Ref<Vector3>
enableDamping?: boolean
}>(),
{
makeDefault: false,
},
)
const controls = ref(null)
const camera = inject<Ref<Camera>>('camera')
const renderer = inject<Ref<WebGLRenderer>>('renderer')
const { extend } = useCientos()
extend({ OrbitControls })
</script>

<template>
<TresOrbitControls
v-if="camera && renderer"
ref="controls"
:args="[camera, renderer?.domElement]"
:enabling-dampling="enableDamping"
/>
</template>

<!-- <script setup lang="ts">
import { useRenderLoop } from '@tresjs/core'
import { Camera, WebGLRenderer } from 'three'
import { Camera, Vector3, WebGLRenderer } from 'three'
import { OrbitControls as OrbitControlsImp } from 'three-stdlib'
import { inject, type Ref, unref, watch } from 'vue'

const props = withDefaults(
defineProps<{
makeDefault?: boolean
camera?: Camera
domElement?: HTMLElement
target?: Ref<Vector3>
}>(),
{
makeDefault: false,
},
)
let controls: OrbitControlsImp

const camera = inject<Ref<Camera>>('camera')
Expand All @@ -19,7 +67,7 @@ watch(
const { onLoop } = useRenderLoop()

onLoop(() => {
if (controls) {
if (controls.enabled) {
controls.update()
}
})
Expand All @@ -30,3 +78,4 @@ watch(
},
)
</script>
-->
10 changes: 10 additions & 0 deletions packages/cientos/src/core/useCientos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useCatalogue } from '@tresjs/core'

export function useCientos() {
const { catalogue, extend } = useCatalogue(window.__TRES__.app)

return {
catalogue,
extend,
}
}
12 changes: 12 additions & 0 deletions packages/cientos/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { App } from 'vue'
/// <reference types="vite/client" />

declare module '*.vue' {
Expand All @@ -6,3 +7,14 @@ declare module '*.vue' {
const component: DefineComponent<{}, {}, any>
export default component
}

declare global {
// Define the window interface, with type annotations for the properties and methods of the window object
interface Window {
// Define the location property, with a type of Location
__TRES__: {
app: App
version: string
}
}
}

0 comments on commit 7251b60

Please sign in to comment.