@react-three/fiber 8.3.1 → 8.5.0

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,11 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - edc8252: feat: handle primitive children, auto-attach via instanceof
8
+
3
9
  ## 8.3.1
4
10
 
5
11
  ### Patch Changes
@@ -869,11 +869,7 @@ function createRenderer(_roots, _getEventPriority) {
869
869
  ...props
870
870
  }, root) {
871
871
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
872
- let instance; // Auto-attach geometries and materials
873
-
874
- if (attach === undefined) {
875
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
876
- }
872
+ let instance;
877
873
 
878
874
  if (type === 'primitive') {
879
875
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -904,6 +900,11 @@ function createRenderer(_roots, _getEventPriority) {
904
900
  args
905
901
  }
906
902
  });
903
+ } // Auto-attach geometries and materials
904
+
905
+
906
+ if (instance.__r3f.attach === undefined) {
907
+ if (instance instanceof THREE__namespace.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE__namespace.Material) instance.__r3f.attach = 'material';
907
908
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
908
909
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
909
910
  // why it passes "true" here
@@ -1043,13 +1044,13 @@ function createRenderer(_roots, _getEventPriority) {
1043
1044
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1044
1045
  // When args change the instance has to be re-constructed, which then
1045
1046
  // forces r3f to re-parent the children and non-scene objects
1046
- // This can not include primitives, which should not have declarative children
1047
1047
 
1048
- if (type !== 'primitive' && instance.children) {
1049
- instance.children.forEach(child => appendChild(newInstance, child));
1050
- instance.children = [];
1048
+ for (const child of instance.children) {
1049
+ if (child.__r3f) appendChild(newInstance, child);
1051
1050
  }
1052
1051
 
1052
+ instance.children = instance.children.filter(child => !child.__r3f);
1053
+
1053
1054
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1054
1055
 
1055
1056
  instance.__r3f.objects = [];
@@ -1169,11 +1170,11 @@ function createRenderer(_roots, _getEventPriority) {
1169
1170
  hideInstance(instance) {
1170
1171
  var _instance$__r3f4;
1171
1172
 
1172
- // Deatch while the instance is hidden
1173
+ // Detach while the instance is hidden
1173
1174
  const {
1174
1175
  attach: type,
1175
1176
  parent
1176
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1177
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1177
1178
  if (type && parent) detach(parent, instance, type);
1178
1179
  if (instance.isObject3D) instance.visible = false;
1179
1180
  invalidateInstance(instance);
@@ -1186,7 +1187,7 @@ function createRenderer(_roots, _getEventPriority) {
1186
1187
  const {
1187
1188
  attach: type,
1188
1189
  parent
1189
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1190
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1190
1191
  if (type && parent) attach(parent, instance, type);
1191
1192
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1192
1193
  invalidateInstance(instance);
@@ -869,11 +869,7 @@ function createRenderer(_roots, _getEventPriority) {
869
869
  ...props
870
870
  }, root) {
871
871
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
872
- let instance; // Auto-attach geometries and materials
873
-
874
- if (attach === undefined) {
875
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
876
- }
872
+ let instance;
877
873
 
878
874
  if (type === 'primitive') {
879
875
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -904,6 +900,11 @@ function createRenderer(_roots, _getEventPriority) {
904
900
  args
905
901
  }
906
902
  });
903
+ } // Auto-attach geometries and materials
904
+
905
+
906
+ if (instance.__r3f.attach === undefined) {
907
+ if (instance instanceof THREE__namespace.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE__namespace.Material) instance.__r3f.attach = 'material';
907
908
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
908
909
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
909
910
  // why it passes "true" here
@@ -1043,13 +1044,13 @@ function createRenderer(_roots, _getEventPriority) {
1043
1044
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1044
1045
  // When args change the instance has to be re-constructed, which then
1045
1046
  // forces r3f to re-parent the children and non-scene objects
1046
- // This can not include primitives, which should not have declarative children
1047
1047
 
1048
- if (type !== 'primitive' && instance.children) {
1049
- instance.children.forEach(child => appendChild(newInstance, child));
1050
- instance.children = [];
1048
+ for (const child of instance.children) {
1049
+ if (child.__r3f) appendChild(newInstance, child);
1051
1050
  }
1052
1051
 
1052
+ instance.children = instance.children.filter(child => !child.__r3f);
1053
+
1053
1054
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1054
1055
 
1055
1056
  instance.__r3f.objects = [];
@@ -1169,11 +1170,11 @@ function createRenderer(_roots, _getEventPriority) {
1169
1170
  hideInstance(instance) {
1170
1171
  var _instance$__r3f4;
1171
1172
 
1172
- // Deatch while the instance is hidden
1173
+ // Detach while the instance is hidden
1173
1174
  const {
1174
1175
  attach: type,
1175
1176
  parent
1176
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1177
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1177
1178
  if (type && parent) detach(parent, instance, type);
1178
1179
  if (instance.isObject3D) instance.visible = false;
1179
1180
  invalidateInstance(instance);
@@ -1186,7 +1187,7 @@ function createRenderer(_roots, _getEventPriority) {
1186
1187
  const {
1187
1188
  attach: type,
1188
1189
  parent
1189
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1190
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1190
1191
  if (type && parent) attach(parent, instance, type);
1191
1192
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1192
1193
  invalidateInstance(instance);
@@ -842,11 +842,7 @@ function createRenderer(_roots, _getEventPriority) {
842
842
  ...props
843
843
  }, root) {
844
844
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
845
- let instance; // Auto-attach geometries and materials
846
-
847
- if (attach === undefined) {
848
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
849
- }
845
+ let instance;
850
846
 
851
847
  if (type === 'primitive') {
852
848
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -877,6 +873,11 @@ function createRenderer(_roots, _getEventPriority) {
877
873
  args
878
874
  }
879
875
  });
876
+ } // Auto-attach geometries and materials
877
+
878
+
879
+ if (instance.__r3f.attach === undefined) {
880
+ if (instance instanceof THREE.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE.Material) instance.__r3f.attach = 'material';
880
881
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
881
882
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
882
883
  // why it passes "true" here
@@ -1016,13 +1017,13 @@ function createRenderer(_roots, _getEventPriority) {
1016
1017
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1017
1018
  // When args change the instance has to be re-constructed, which then
1018
1019
  // forces r3f to re-parent the children and non-scene objects
1019
- // This can not include primitives, which should not have declarative children
1020
1020
 
1021
- if (type !== 'primitive' && instance.children) {
1022
- instance.children.forEach(child => appendChild(newInstance, child));
1023
- instance.children = [];
1021
+ for (const child of instance.children) {
1022
+ if (child.__r3f) appendChild(newInstance, child);
1024
1023
  }
1025
1024
 
1025
+ instance.children = instance.children.filter(child => !child.__r3f);
1026
+
1026
1027
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1027
1028
 
1028
1029
  instance.__r3f.objects = [];
@@ -1142,11 +1143,11 @@ function createRenderer(_roots, _getEventPriority) {
1142
1143
  hideInstance(instance) {
1143
1144
  var _instance$__r3f4;
1144
1145
 
1145
- // Deatch while the instance is hidden
1146
+ // Detach while the instance is hidden
1146
1147
  const {
1147
1148
  attach: type,
1148
1149
  parent
1149
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1150
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1150
1151
  if (type && parent) detach(parent, instance, type);
1151
1152
  if (instance.isObject3D) instance.visible = false;
1152
1153
  invalidateInstance(instance);
@@ -1159,7 +1160,7 @@ function createRenderer(_roots, _getEventPriority) {
1159
1160
  const {
1160
1161
  attach: type,
1161
1162
  parent
1162
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1163
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1163
1164
  if (type && parent) attach(parent, instance, type);
1164
1165
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1165
1166
  invalidateInstance(instance);
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-bcd3e47c.cjs.dev.js');
5
+ var index = require('./index-2bf2b90e.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-e086bd20.cjs.prod.js');
5
+ var index = require('./index-aea5c5ce.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 createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-212b30d8.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-212b30d8.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-ea463076.esm.js';
2
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-ea463076.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-bcd3e47c.cjs.dev.js');
5
+ var index = require('../../dist/index-2bf2b90e.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-e086bd20.cjs.prod.js');
5
+ var index = require('../../dist/index-aea5c5ce.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 createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-212b30d8.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-212b30d8.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-ea463076.esm.js';
2
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-ea463076.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.3.1",
3
+ "version": "8.5.0",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",
package/readme.md CHANGED
@@ -164,7 +164,7 @@ Some reading material:
164
164
 
165
165
  - [Threejs-docs](https://threejs.org/docs)
166
166
  - [Threejs-examples](https://threejs.org/examples)
167
- - [Threejs-fundamentals](https://threejsfundamentals.org)
167
+ - [Threejs-fundamentals](https://threejs.org/manual/#en/fundamentals)
168
168
  - [Discover Threejs](https://discoverthreejs.com)
169
169
  - [Do's and don'ts](https://discoverthreejs.com/tips-and-tricks) for performance and best practices
170
170
  - [react-three-fiber alligator.io tutorial](https://alligator.io/react/react-with-threejs) by [@dghez\_](https://twitter.com/dghez_)