-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Tresjs/feature/25-extend-catalog-in-cientos
feat: extend catalog in cientos
- Loading branch information
Showing
9 changed files
with
134 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
<script setup lang="ts"> | ||
import { useRenderLoop } from '@tresjs/core' | ||
import { Camera, WebGLRenderer } from 'three' | ||
import { OrbitControls as OrbitControlsImp } from 'three-stdlib' | ||
import { inject, type Ref, unref, watch } from 'vue' | ||
<script lang="ts" setup> | ||
import { Camera, Vector3, WebGLRenderer } from 'three' | ||
import { OrbitControls } from 'three-stdlib' | ||
import { inject, ref, type Ref } from 'vue' | ||
let controls: OrbitControlsImp | ||
import { useCientos } from './useCientos' | ||
const camera = inject<Ref<Camera>>('camera') | ||
const renderer = inject<Ref<WebGLRenderer>>('renderer') | ||
watch( | ||
[camera, renderer], | ||
() => { | ||
if (camera?.value && renderer?.value) { | ||
if (controls) controls.reset() | ||
controls = new OrbitControlsImp(camera.value, unref(renderer).domElement) | ||
controls.enableDamping = true | ||
const { onLoop } = useRenderLoop() | ||
onLoop(() => { | ||
if (controls) { | ||
controls.update() | ||
} | ||
}) | ||
} | ||
}, | ||
const props = withDefaults( | ||
defineProps<{ | ||
makeDefault?: boolean | ||
camera?: Camera | ||
domElement?: HTMLElement | ||
target?: Ref<Vector3> | ||
enableDamping?: boolean | ||
}>(), | ||
{ | ||
deep: true, | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { inject } from 'vue' | ||
|
||
export function useCientos() { | ||
const extend = | ||
inject<(objects: any) => void>('extend') || | ||
(() => { | ||
console.warn('No extend function provided') | ||
}) | ||
return { | ||
extend, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import { createApp } from 'vue' | ||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' | ||
import App from './App.vue' | ||
import plugin from '.' | ||
import './style.css' | ||
|
||
export const app = createApp(App) | ||
|
||
app.use(plugin, { | ||
extends: { | ||
OrbitControls, | ||
}, | ||
}) | ||
app.use(plugin) | ||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters