From d9ba4b8709307b449692289a4dffdeac5f9930c6 Mon Sep 17 00:00:00 2001
From: Michael Dougall <6801309+itsdouges@users.noreply.github.com>
Date: Sun, 18 Jun 2023 14:30:33 +1000
Subject: [PATCH] Add helper icon box for raycasting
adeira-source-id: a3bf847cf06925d4f75d3b57c9bee945998c0fb9
---
examples/faze/src/scenes/camera-testing.tsx | 8 ++--
packages/scene/src/components/helper.tsx | 50 ++++++++++++---------
2 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/examples/faze/src/scenes/camera-testing.tsx b/examples/faze/src/scenes/camera-testing.tsx
index 4ef5e3da..e34852c0 100644
--- a/examples/faze/src/scenes/camera-testing.tsx
+++ b/examples/faze/src/scenes/camera-testing.tsx
@@ -18,7 +18,7 @@ export function Scene() {
@@ -30,12 +30,14 @@ export function Scene() {
-
+
>
);
}
diff --git a/packages/scene/src/components/helper.tsx b/packages/scene/src/components/helper.tsx
index b037dc96..b95f7fe5 100644
--- a/packages/scene/src/components/helper.tsx
+++ b/packages/scene/src/components/helper.tsx
@@ -1,7 +1,6 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
import { ThreeEvent, useFrame } from "@react-three/fiber";
import { useLayoutEffect, useRef, useState } from "react";
-import { Object3D } from "three";
+import { Mesh, Object3D } from "three";
import "./camera-helper";
type Helper =
@@ -13,8 +12,7 @@ type Helper =
type HelperInstance = Object3D & { update: () => void; dispose: () => void };
-const LIGHT_HELPER_SIZE = 0.2;
-const HELPER_EXCLUSIONS = ["directionalLightHelper", "spotLightHelper"];
+const HELPER_SIZE = 0.2;
export const getHelperForElement = (
name: string
@@ -25,10 +23,10 @@ export const getHelperForElement = (
case "rectAreaLight":
case "pointLight":
case "ambientLight":
- return ["pointLightHelper", [LIGHT_HELPER_SIZE]];
+ return ["pointLightHelper", [HELPER_SIZE]];
case "hemisphereLight":
- return ["hemisphereLightHelper", [LIGHT_HELPER_SIZE]];
+ return ["hemisphereLightHelper", [HELPER_SIZE]];
case "spotLight":
return ["spotLightHelper", []];
@@ -47,20 +45,40 @@ export const getHelperForElement = (
}
};
+function HelperIcon({
+ target,
+ onClick,
+}: {
+ target: Object3D;
+ onClick: (e: ThreeEvent) => void;
+}) {
+ const ref = useRef(null!);
+
+ useFrame(() => {
+ ref.current.position.copy(target.position);
+ });
+
+ return (
+
+
+
+
+ );
+}
+
export function Helper({
args = [],
parentObject,
helperName: HelperElement,
onClick,
}: {
- args?: any[];
+ args?: unknown[];
parentObject: React.MutableRefObject;
helperName: Helper;
onClick: (e: ThreeEvent) => void;
}) {
- const [target, setTarget] = useState(null);
+ const [target, setTarget] = useState(null);
const helperRef = useRef(null);
- const altHelperRef = useRef(null);
useLayoutEffect(() => {
if (parentObject && parentObject?.current) {
@@ -70,25 +88,15 @@ export function Helper({
useFrame(() => {
helperRef.current?.update();
- altHelperRef.current?.update();
});
if (target) {
- const isExcluded = HELPER_EXCLUSIONS.includes(HelperElement);
-
return (
<>
- {isExcluded && (
-
- )}
-
+