Skip to content

Commit

Permalink
Use out-of-band raycaster for scene selection
Browse files Browse the repository at this point in the history
adeira-source-id: f14b92b41a6f543e12c0e383b55ef37ba990ce1c
  • Loading branch information
itsdouges authored and triplex-bot committed Mar 30, 2024
1 parent 01197b4 commit 6ac049c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/fuzzy-ligers-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@triplex/renderer-r3f": minor
"@triplex/editor": minor
---

Scene selection is now powered by an out-of-band raycaster. By default scenes
no-longer receive events when in edit mode.
6 changes: 5 additions & 1 deletion examples/test-fixture/src/geometry/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the GPL-3.0 license found in the LICENSE
* file in the root directory of this source tree.
*/
import { useState } from "react";
import { type Vector3Tuple } from "three";

function Box({
Expand All @@ -25,19 +26,22 @@ function Box({
size?: number;
}) {
const ok = {};
const [hover, setHover] = useState(false);
return (
<group scale={scale} visible={true}>
<mesh
{...ok}
name="hello-world"
onClick={() => {}}
onPointerOut={() => setHover(false)}
onPointerOver={() => setHover(true)}
position={position}
rotation={rotation}
userData={{ hello: true }}
visible={true}
>
<boxGeometry args={[size, size, size]} />
<meshStandardMaterial color={color} key={color} />
<meshStandardMaterial color={hover ? "purple" : color} key={color} />
</mesh>
</group>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-three-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"typedef": "echo \"not implemented\""
},
"dependencies": {
"@react-three/test-renderer": "^8.2.0"
"@react-three/test-renderer": "^8.2.0",
"@testing-library/dom": "^9.3.4"
},
"peerDependencies": {
"@react-three/fiber": "^8.0.0",
Expand Down
13 changes: 12 additions & 1 deletion packages/react-three-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import renderer from "@react-three/test-renderer";
import { type TreeNode } from "@react-three/test-renderer/dist/declarations/src/types";
import { fireEvent as fireDOMEvent } from "@testing-library/dom";

// @ts-expect-error - Ignore global variable in test.
global.IS_REACT_ACT_ENVIRONMENT = true;
Expand All @@ -31,11 +32,21 @@ function find(
}

export async function render(jsx: JSX.Element) {
const controls = await renderer.create(jsx);
let canvas: HTMLCanvasElement;

const controls = await renderer.create(jsx, {
onCreated(state) {
canvas = state.gl.domElement;
},
});

return {
...controls,
act: renderer.act,
get canvas() {
return canvas;
},
fireDOMEvent,
tree: {
getByType(type: string) {
const tree = controls.toTree();
Expand Down

0 comments on commit 6ac049c

Please sign in to comment.