|
@@ -1,12 +1,42 @@
|
|
import { Raycaster, Vector2 } from 'three'
|
|
import { Raycaster, Vector2 } from 'three'
|
|
-import { onUnmounted, provide, ref, shallowRef } from 'vue'
|
|
|
|
|
|
+import { onUnmounted, provide, Ref, ref, ShallowRef, shallowRef } from 'vue'
|
|
import { useTres } from '/@/core'
|
|
import { useTres } from '/@/core'
|
|
|
|
|
|
const raycaster = shallowRef(new Raycaster())
|
|
const raycaster = shallowRef(new Raycaster())
|
|
const pointer = ref(new Vector2())
|
|
const pointer = ref(new Vector2())
|
|
const currentInstance = ref(null)
|
|
const currentInstance = ref(null)
|
|
|
|
|
|
-export function useRaycaster() {
|
|
|
|
|
|
+/**
|
|
|
|
+ * Raycaster composable return type
|
|
|
|
+ *
|
|
|
|
+ * @export
|
|
|
|
+ * @interface UseRaycasterReturn
|
|
|
|
+ */
|
|
|
|
+export interface UseRaycasterReturn {
|
|
|
|
+ /**
|
|
|
|
+ * Raycaster instance
|
|
|
|
+ *
|
|
|
|
+ * @type {ShallowRef<Raycaster>}
|
|
|
|
+ * @memberof UseRaycasterReturn
|
|
|
|
+ */
|
|
|
|
+ raycaster: ShallowRef<Raycaster>
|
|
|
|
+ /**
|
|
|
|
+ * Pointer position
|
|
|
|
+ *
|
|
|
|
+ * @type {Ref<Vector2>}
|
|
|
|
+ * @memberof UseRaycasterReturn
|
|
|
|
+ */
|
|
|
|
+ pointer: Ref<Vector2>
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Composable to provide raycaster support and pointer information
|
|
|
|
+ *
|
|
|
|
+ * @see https://threejs.org/docs/index.html?q=raycas#api/en/core/Raycaster
|
|
|
|
+ * @export
|
|
|
|
+ * @return {*} {UseRaycasterReturn}
|
|
|
|
+ */
|
|
|
|
+export function useRaycaster(): UseRaycasterReturn {
|
|
const { setState } = useTres()
|
|
const { setState } = useTres()
|
|
setState('raycaster', raycaster.value)
|
|
setState('raycaster', raycaster.value)
|
|
setState('pointer', pointer)
|
|
setState('pointer', pointer)
|