@react-three/fiber 8.11.9 → 8.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.11.11
4
+
5
+ ### Patch Changes
6
+
7
+ - f03c6ef8: feat: `scene` render prop for custom THREE.Scene
8
+
9
+ ## 8.11.10
10
+
11
+ ### Patch Changes
12
+
13
+ - 12907836: fix onpointerlostcapture which fired before pointerup
14
+
3
15
  ## 8.11.9
4
16
 
5
17
  ### Patch Changes
@@ -27,6 +27,7 @@ export declare type RenderProps<TCanvas extends Canvas> = {
27
27
  performance?: Partial<Omit<Performance, 'regress'>>;
28
28
  dpr?: Dpr;
29
29
  raycaster?: Partial<THREE.Raycaster>;
30
+ scene?: THREE.Scene | Partial<ReactThreeFiber.Object3DNode<THREE.Scene, typeof THREE.Scene>>;
30
31
  camera?: (Camera | Partial<ReactThreeFiber.Object3DNode<THREE.Camera, typeof THREE.Camera> & ReactThreeFiber.Object3DNode<THREE.PerspectiveCamera, typeof THREE.PerspectiveCamera> & ReactThreeFiber.Object3DNode<THREE.OrthographicCamera, typeof THREE.OrthographicCamera>>) & {
31
32
  manual?: boolean;
32
33
  };
@@ -1093,9 +1093,16 @@ function createEvents(store) {
1093
1093
  } = store.getState();
1094
1094
  if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1095
1095
  // If the object event interface had onLostPointerCapture, we'd call it here on every
1096
- // object that's getting removed.
1097
- internal.capturedMap.delete(event.pointerId);
1098
- cancelPointer([]);
1096
+ // object that's getting removed. We call it on the next frame because onLostPointerCapture
1097
+ // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1098
+ // happen in the object it originated from, leaving components in a in-between state.
1099
+ requestAnimationFrame(() => {
1100
+ // Only release if pointer-up didn't do it already
1101
+ if (internal.capturedMap.has(event.pointerId)) {
1102
+ internal.capturedMap.delete(event.pointerId);
1103
+ cancelPointer([]);
1104
+ }
1105
+ });
1099
1106
  }
1100
1107
  };
1101
1108
  }
@@ -1140,6 +1147,22 @@ function createEvents(store) {
1140
1147
 
1141
1148
  // Check presence of handlers
1142
1149
  if (!(instance != null && instance.eventCount)) return;
1150
+
1151
+ /*
1152
+ MAYBE TODO, DELETE IF NOT:
1153
+ Check if the object is captured, captured events should not have intersects running in parallel
1154
+ But wouldn't it be better to just replace capturedMap with a single entry?
1155
+ Also, are we OK with straight up making picking up multiple objects impossible?
1156
+
1157
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1158
+ if (pointerId !== undefined) {
1159
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1160
+ if (capturedMeshSet) {
1161
+ const captured = capturedMeshSet.get(eventObject)
1162
+ if (captured && captured.localState.stopped) return
1163
+ }
1164
+ }*/
1165
+
1143
1166
  if (isPointerMove) {
1144
1167
  // Move event ...
1145
1168
  if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
@@ -1251,12 +1274,12 @@ const createStore = (invalidate, advance) => {
1251
1274
  connected: false
1252
1275
  },
1253
1276
  xr: null,
1277
+ scene: null,
1254
1278
  invalidate: (frames = 1) => invalidate(get(), frames),
1255
1279
  advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1256
1280
  legacy: false,
1257
1281
  linear: false,
1258
1282
  flat: false,
1259
- scene: prepare(new THREE__namespace.Scene()),
1260
1283
  controls: null,
1261
1284
  clock: new THREE__namespace.Clock(),
1262
1285
  pointer,
@@ -1749,6 +1772,7 @@ function createRoot(canvas) {
1749
1772
  let {
1750
1773
  gl: glConfig,
1751
1774
  size: propsSize,
1775
+ scene: sceneOptions,
1752
1776
  events,
1753
1777
  onCreated: onCreatedCallback,
1754
1778
  shadows = false,
@@ -1808,6 +1832,20 @@ function createRoot(canvas) {
1808
1832
  });
1809
1833
  }
1810
1834
 
1835
+ // Set up scene (one time only!)
1836
+ if (!state.scene) {
1837
+ let scene;
1838
+ if (sceneOptions instanceof THREE__namespace.Scene) {
1839
+ scene = sceneOptions;
1840
+ } else {
1841
+ scene = new THREE__namespace.Scene();
1842
+ if (sceneOptions) applyProps(scene, sceneOptions);
1843
+ }
1844
+ state.set({
1845
+ scene: prepare(scene)
1846
+ });
1847
+ }
1848
+
1811
1849
  // Set up XR (one time only!)
1812
1850
  if (!state.xr) {
1813
1851
  // Handle frame behavior in WebXR
@@ -1093,9 +1093,16 @@ function createEvents(store) {
1093
1093
  } = store.getState();
1094
1094
  if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1095
1095
  // If the object event interface had onLostPointerCapture, we'd call it here on every
1096
- // object that's getting removed.
1097
- internal.capturedMap.delete(event.pointerId);
1098
- cancelPointer([]);
1096
+ // object that's getting removed. We call it on the next frame because onLostPointerCapture
1097
+ // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1098
+ // happen in the object it originated from, leaving components in a in-between state.
1099
+ requestAnimationFrame(() => {
1100
+ // Only release if pointer-up didn't do it already
1101
+ if (internal.capturedMap.has(event.pointerId)) {
1102
+ internal.capturedMap.delete(event.pointerId);
1103
+ cancelPointer([]);
1104
+ }
1105
+ });
1099
1106
  }
1100
1107
  };
1101
1108
  }
@@ -1140,6 +1147,22 @@ function createEvents(store) {
1140
1147
 
1141
1148
  // Check presence of handlers
1142
1149
  if (!(instance != null && instance.eventCount)) return;
1150
+
1151
+ /*
1152
+ MAYBE TODO, DELETE IF NOT:
1153
+ Check if the object is captured, captured events should not have intersects running in parallel
1154
+ But wouldn't it be better to just replace capturedMap with a single entry?
1155
+ Also, are we OK with straight up making picking up multiple objects impossible?
1156
+
1157
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1158
+ if (pointerId !== undefined) {
1159
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1160
+ if (capturedMeshSet) {
1161
+ const captured = capturedMeshSet.get(eventObject)
1162
+ if (captured && captured.localState.stopped) return
1163
+ }
1164
+ }*/
1165
+
1143
1166
  if (isPointerMove) {
1144
1167
  // Move event ...
1145
1168
  if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
@@ -1251,12 +1274,12 @@ const createStore = (invalidate, advance) => {
1251
1274
  connected: false
1252
1275
  },
1253
1276
  xr: null,
1277
+ scene: null,
1254
1278
  invalidate: (frames = 1) => invalidate(get(), frames),
1255
1279
  advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1256
1280
  legacy: false,
1257
1281
  linear: false,
1258
1282
  flat: false,
1259
- scene: prepare(new THREE__namespace.Scene()),
1260
1283
  controls: null,
1261
1284
  clock: new THREE__namespace.Clock(),
1262
1285
  pointer,
@@ -1749,6 +1772,7 @@ function createRoot(canvas) {
1749
1772
  let {
1750
1773
  gl: glConfig,
1751
1774
  size: propsSize,
1775
+ scene: sceneOptions,
1752
1776
  events,
1753
1777
  onCreated: onCreatedCallback,
1754
1778
  shadows = false,
@@ -1808,6 +1832,20 @@ function createRoot(canvas) {
1808
1832
  });
1809
1833
  }
1810
1834
 
1835
+ // Set up scene (one time only!)
1836
+ if (!state.scene) {
1837
+ let scene;
1838
+ if (sceneOptions instanceof THREE__namespace.Scene) {
1839
+ scene = sceneOptions;
1840
+ } else {
1841
+ scene = new THREE__namespace.Scene();
1842
+ if (sceneOptions) applyProps(scene, sceneOptions);
1843
+ }
1844
+ state.set({
1845
+ scene: prepare(scene)
1846
+ });
1847
+ }
1848
+
1811
1849
  // Set up XR (one time only!)
1812
1850
  if (!state.xr) {
1813
1851
  // Handle frame behavior in WebXR
@@ -1066,9 +1066,16 @@ function createEvents(store) {
1066
1066
  } = store.getState();
1067
1067
  if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1068
1068
  // If the object event interface had onLostPointerCapture, we'd call it here on every
1069
- // object that's getting removed.
1070
- internal.capturedMap.delete(event.pointerId);
1071
- cancelPointer([]);
1069
+ // object that's getting removed. We call it on the next frame because onLostPointerCapture
1070
+ // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1071
+ // happen in the object it originated from, leaving components in a in-between state.
1072
+ requestAnimationFrame(() => {
1073
+ // Only release if pointer-up didn't do it already
1074
+ if (internal.capturedMap.has(event.pointerId)) {
1075
+ internal.capturedMap.delete(event.pointerId);
1076
+ cancelPointer([]);
1077
+ }
1078
+ });
1072
1079
  }
1073
1080
  };
1074
1081
  }
@@ -1113,6 +1120,22 @@ function createEvents(store) {
1113
1120
 
1114
1121
  // Check presence of handlers
1115
1122
  if (!(instance != null && instance.eventCount)) return;
1123
+
1124
+ /*
1125
+ MAYBE TODO, DELETE IF NOT:
1126
+ Check if the object is captured, captured events should not have intersects running in parallel
1127
+ But wouldn't it be better to just replace capturedMap with a single entry?
1128
+ Also, are we OK with straight up making picking up multiple objects impossible?
1129
+
1130
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1131
+ if (pointerId !== undefined) {
1132
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1133
+ if (capturedMeshSet) {
1134
+ const captured = capturedMeshSet.get(eventObject)
1135
+ if (captured && captured.localState.stopped) return
1136
+ }
1137
+ }*/
1138
+
1116
1139
  if (isPointerMove) {
1117
1140
  // Move event ...
1118
1141
  if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
@@ -1224,12 +1247,12 @@ const createStore = (invalidate, advance) => {
1224
1247
  connected: false
1225
1248
  },
1226
1249
  xr: null,
1250
+ scene: null,
1227
1251
  invalidate: (frames = 1) => invalidate(get(), frames),
1228
1252
  advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1229
1253
  legacy: false,
1230
1254
  linear: false,
1231
1255
  flat: false,
1232
- scene: prepare(new THREE.Scene()),
1233
1256
  controls: null,
1234
1257
  clock: new THREE.Clock(),
1235
1258
  pointer,
@@ -1722,6 +1745,7 @@ function createRoot(canvas) {
1722
1745
  let {
1723
1746
  gl: glConfig,
1724
1747
  size: propsSize,
1748
+ scene: sceneOptions,
1725
1749
  events,
1726
1750
  onCreated: onCreatedCallback,
1727
1751
  shadows = false,
@@ -1781,6 +1805,20 @@ function createRoot(canvas) {
1781
1805
  });
1782
1806
  }
1783
1807
 
1808
+ // Set up scene (one time only!)
1809
+ if (!state.scene) {
1810
+ let scene;
1811
+ if (sceneOptions instanceof THREE.Scene) {
1812
+ scene = sceneOptions;
1813
+ } else {
1814
+ scene = new THREE.Scene();
1815
+ if (sceneOptions) applyProps(scene, sceneOptions);
1816
+ }
1817
+ state.set({
1818
+ scene: prepare(scene)
1819
+ });
1820
+ }
1821
+
1784
1822
  // Set up XR (one time only!)
1785
1823
  if (!state.xr) {
1786
1824
  // Handle frame behavior in WebXR
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-4073a042.cjs.dev.js');
5
+ var index = require('./index-8e3d9f5f.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-a47b404f.cjs.prod.js');
5
+ var index = require('./index-7373fbbd.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-6b130504.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-6b130504.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-bb759d07.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-bb759d07.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-4073a042.cjs.dev.js');
5
+ var index = require('../../dist/index-8e3d9f5f.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-a47b404f.cjs.prod.js');
5
+ var index = require('../../dist/index-7373fbbd.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-6b130504.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-6b130504.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-bb759d07.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-bb759d07.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.11.9",
3
+ "version": "8.11.11",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",