@react-three/fiber 9.0.4 → 9.1.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
+ ## 9.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cbc79507600b81f6a39de9f3f0ecb3aaf811233f: feat: add meshes to loader graph, misc internal fixes
8
+
3
9
  ## 9.0.4
4
10
 
5
11
  ### Patch Changes
@@ -138,6 +138,9 @@ export interface ObjectMap {
138
138
  materials: {
139
139
  [name: string]: THREE.Material;
140
140
  };
141
+ meshes: {
142
+ [name: string]: THREE.Mesh;
143
+ };
141
144
  }
142
145
  export declare function calculateDpr(dpr: Dpr): number;
143
146
  /**
@@ -184,12 +184,14 @@ const is = {
184
184
  function buildGraph(object) {
185
185
  const data = {
186
186
  nodes: {},
187
- materials: {}
187
+ materials: {},
188
+ meshes: {}
188
189
  };
189
190
  if (object) {
190
191
  object.traverse(obj => {
191
192
  if (obj.name) data.nodes[obj.name] = obj;
192
193
  if (obj.material && !data.materials[obj.material.name]) data.materials[obj.material.name] = obj.material;
194
+ if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
193
195
  });
194
196
  }
195
197
  return data;
@@ -236,7 +238,6 @@ function prepare(target, root, type, props) {
236
238
  return instance;
237
239
  }
238
240
  function resolve(root, key) {
239
- var _target;
240
241
  let target = root[key];
241
242
  if (!key.includes('-')) return {
242
243
  root,
@@ -245,12 +246,16 @@ function resolve(root, key) {
245
246
  };
246
247
 
247
248
  // Resolve pierced target
248
- const chain = key.split('-');
249
- target = chain.reduce((acc, key) => acc[key], root);
250
- key = chain.pop();
249
+ target = root;
250
+ for (const part of key.split('-')) {
251
+ var _target;
252
+ key = part;
253
+ root = target;
254
+ target = (_target = target) == null ? void 0 : _target[key];
255
+ }
256
+
257
+ // TODO: change key to 'foo-bar' if target is undefined?
251
258
 
252
- // Switch root if atomic
253
- if (!((_target = target) != null && _target.set)) root = chain.reduce((acc, key) => acc[key], root);
254
259
  return {
255
260
  root,
256
261
  key,
@@ -1357,15 +1362,24 @@ function handleContainerEffects(parent, child, beforeChild) {
1357
1362
  } else if (isObject3D(child.object) && isObject3D(parent.object)) {
1358
1363
  const childIndex = parent.object.children.indexOf(beforeChild == null ? void 0 : beforeChild.object);
1359
1364
  if (beforeChild && childIndex !== -1) {
1360
- child.object.parent = parent.object;
1361
- parent.object.children.splice(childIndex, 0, child.object);
1362
- child.object.dispatchEvent({
1363
- type: 'added'
1364
- });
1365
- parent.object.dispatchEvent({
1366
- type: 'childadded',
1367
- child: child.object
1368
- });
1365
+ // If the child is already in the parent's children array, move it to the new position
1366
+ // Otherwise, just insert it at the target position
1367
+ const existingIndex = parent.object.children.indexOf(child.object);
1368
+ if (existingIndex !== -1) {
1369
+ parent.object.children.splice(existingIndex, 1);
1370
+ const adjustedIndex = existingIndex < childIndex ? childIndex - 1 : childIndex;
1371
+ parent.object.children.splice(adjustedIndex, 0, child.object);
1372
+ } else {
1373
+ child.object.parent = parent.object;
1374
+ parent.object.children.splice(childIndex, 0, child.object);
1375
+ child.object.dispatchEvent({
1376
+ type: 'added'
1377
+ });
1378
+ parent.object.dispatchEvent({
1379
+ type: 'childadded',
1380
+ child: child.object
1381
+ });
1382
+ }
1369
1383
  } else {
1370
1384
  parent.object.add(child.object);
1371
1385
  }
@@ -184,12 +184,14 @@ const is = {
184
184
  function buildGraph(object) {
185
185
  const data = {
186
186
  nodes: {},
187
- materials: {}
187
+ materials: {},
188
+ meshes: {}
188
189
  };
189
190
  if (object) {
190
191
  object.traverse(obj => {
191
192
  if (obj.name) data.nodes[obj.name] = obj;
192
193
  if (obj.material && !data.materials[obj.material.name]) data.materials[obj.material.name] = obj.material;
194
+ if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
193
195
  });
194
196
  }
195
197
  return data;
@@ -236,7 +238,6 @@ function prepare(target, root, type, props) {
236
238
  return instance;
237
239
  }
238
240
  function resolve(root, key) {
239
- var _target;
240
241
  let target = root[key];
241
242
  if (!key.includes('-')) return {
242
243
  root,
@@ -245,12 +246,16 @@ function resolve(root, key) {
245
246
  };
246
247
 
247
248
  // Resolve pierced target
248
- const chain = key.split('-');
249
- target = chain.reduce((acc, key) => acc[key], root);
250
- key = chain.pop();
249
+ target = root;
250
+ for (const part of key.split('-')) {
251
+ var _target;
252
+ key = part;
253
+ root = target;
254
+ target = (_target = target) == null ? void 0 : _target[key];
255
+ }
256
+
257
+ // TODO: change key to 'foo-bar' if target is undefined?
251
258
 
252
- // Switch root if atomic
253
- if (!((_target = target) != null && _target.set)) root = chain.reduce((acc, key) => acc[key], root);
254
259
  return {
255
260
  root,
256
261
  key,
@@ -1357,15 +1362,24 @@ function handleContainerEffects(parent, child, beforeChild) {
1357
1362
  } else if (isObject3D(child.object) && isObject3D(parent.object)) {
1358
1363
  const childIndex = parent.object.children.indexOf(beforeChild == null ? void 0 : beforeChild.object);
1359
1364
  if (beforeChild && childIndex !== -1) {
1360
- child.object.parent = parent.object;
1361
- parent.object.children.splice(childIndex, 0, child.object);
1362
- child.object.dispatchEvent({
1363
- type: 'added'
1364
- });
1365
- parent.object.dispatchEvent({
1366
- type: 'childadded',
1367
- child: child.object
1368
- });
1365
+ // If the child is already in the parent's children array, move it to the new position
1366
+ // Otherwise, just insert it at the target position
1367
+ const existingIndex = parent.object.children.indexOf(child.object);
1368
+ if (existingIndex !== -1) {
1369
+ parent.object.children.splice(existingIndex, 1);
1370
+ const adjustedIndex = existingIndex < childIndex ? childIndex - 1 : childIndex;
1371
+ parent.object.children.splice(adjustedIndex, 0, child.object);
1372
+ } else {
1373
+ child.object.parent = parent.object;
1374
+ parent.object.children.splice(childIndex, 0, child.object);
1375
+ child.object.dispatchEvent({
1376
+ type: 'added'
1377
+ });
1378
+ parent.object.dispatchEvent({
1379
+ type: 'childadded',
1380
+ child: child.object
1381
+ });
1382
+ }
1369
1383
  } else {
1370
1384
  parent.object.add(child.object);
1371
1385
  }
@@ -158,12 +158,14 @@ const is = {
158
158
  function buildGraph(object) {
159
159
  const data = {
160
160
  nodes: {},
161
- materials: {}
161
+ materials: {},
162
+ meshes: {}
162
163
  };
163
164
  if (object) {
164
165
  object.traverse(obj => {
165
166
  if (obj.name) data.nodes[obj.name] = obj;
166
167
  if (obj.material && !data.materials[obj.material.name]) data.materials[obj.material.name] = obj.material;
168
+ if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
167
169
  });
168
170
  }
169
171
  return data;
@@ -210,7 +212,6 @@ function prepare(target, root, type, props) {
210
212
  return instance;
211
213
  }
212
214
  function resolve(root, key) {
213
- var _target;
214
215
  let target = root[key];
215
216
  if (!key.includes('-')) return {
216
217
  root,
@@ -219,12 +220,16 @@ function resolve(root, key) {
219
220
  };
220
221
 
221
222
  // Resolve pierced target
222
- const chain = key.split('-');
223
- target = chain.reduce((acc, key) => acc[key], root);
224
- key = chain.pop();
223
+ target = root;
224
+ for (const part of key.split('-')) {
225
+ var _target;
226
+ key = part;
227
+ root = target;
228
+ target = (_target = target) == null ? void 0 : _target[key];
229
+ }
230
+
231
+ // TODO: change key to 'foo-bar' if target is undefined?
225
232
 
226
- // Switch root if atomic
227
- if (!((_target = target) != null && _target.set)) root = chain.reduce((acc, key) => acc[key], root);
228
233
  return {
229
234
  root,
230
235
  key,
@@ -1331,15 +1336,24 @@ function handleContainerEffects(parent, child, beforeChild) {
1331
1336
  } else if (isObject3D(child.object) && isObject3D(parent.object)) {
1332
1337
  const childIndex = parent.object.children.indexOf(beforeChild == null ? void 0 : beforeChild.object);
1333
1338
  if (beforeChild && childIndex !== -1) {
1334
- child.object.parent = parent.object;
1335
- parent.object.children.splice(childIndex, 0, child.object);
1336
- child.object.dispatchEvent({
1337
- type: 'added'
1338
- });
1339
- parent.object.dispatchEvent({
1340
- type: 'childadded',
1341
- child: child.object
1342
- });
1339
+ // If the child is already in the parent's children array, move it to the new position
1340
+ // Otherwise, just insert it at the target position
1341
+ const existingIndex = parent.object.children.indexOf(child.object);
1342
+ if (existingIndex !== -1) {
1343
+ parent.object.children.splice(existingIndex, 1);
1344
+ const adjustedIndex = existingIndex < childIndex ? childIndex - 1 : childIndex;
1345
+ parent.object.children.splice(adjustedIndex, 0, child.object);
1346
+ } else {
1347
+ child.object.parent = parent.object;
1348
+ parent.object.children.splice(childIndex, 0, child.object);
1349
+ child.object.dispatchEvent({
1350
+ type: 'added'
1351
+ });
1352
+ parent.object.dispatchEvent({
1353
+ type: 'childadded',
1354
+ child: child.object
1355
+ });
1356
+ }
1343
1357
  } else {
1344
1358
  parent.object.add(child.object);
1345
1359
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var events = require('./events-cee74b95.cjs.dev.js');
5
+ var events = require('./events-d47554c5.cjs.dev.js');
6
6
  var React = require('react');
7
7
  var THREE = require('three');
8
8
  var useMeasure = require('react-use-measure');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var events = require('./events-ff8de4d2.cjs.prod.js');
5
+ var events = require('./events-9e217aef.cjs.prod.js');
6
6
  var React = require('react');
7
7
  var THREE = require('three');
8
8
  var useMeasure = require('react-use-measure');
@@ -1,5 +1,5 @@
1
- import { e as extend, u as useBridge, a as useMutableCallback, b as useIsomorphicLayoutEffect, c as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode, f as createPointerEvents } from './events-2895749c.esm.js';
2
- export { t as ReactThreeFiber, _ as _roots, w as act, k as addAfterEffect, j as addEffect, l as addTail, n as advance, q as applyProps, x as buildGraph, p as context, g as createEvents, o as createPortal, c as createRoot, v as dispose, f as events, e as extend, h as flushGlobalEffects, s as getRootState, m as invalidate, r as reconciler, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './events-2895749c.esm.js';
1
+ import { e as extend, u as useBridge, a as useMutableCallback, b as useIsomorphicLayoutEffect, c as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode, f as createPointerEvents } from './events-f80b1519.esm.js';
2
+ export { t as ReactThreeFiber, _ as _roots, w as act, k as addAfterEffect, j as addEffect, l as addTail, n as advance, q as applyProps, x as buildGraph, p as context, g as createEvents, o as createPortal, c as createRoot, v as dispose, f as events, e as extend, h as flushGlobalEffects, s as getRootState, m as invalidate, r as reconciler, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './events-f80b1519.esm.js';
3
3
  import * as React from 'react';
4
4
  import * as THREE from 'three';
5
5
  import useMeasure from 'react-use-measure';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var events = require('../../dist/events-cee74b95.cjs.dev.js');
5
+ var events = require('../../dist/events-d47554c5.cjs.dev.js');
6
6
  var React = require('react');
7
7
  var THREE = require('three');
8
8
  var reactNative = require('react-native');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var events = require('../../dist/events-ff8de4d2.cjs.prod.js');
5
+ var events = require('../../dist/events-9e217aef.cjs.prod.js');
6
6
  var React = require('react');
7
7
  var THREE = require('three');
8
8
  var reactNative = require('react-native');
@@ -1,5 +1,5 @@
1
- import { e as extend, u as useBridge, a as useMutableCallback, c as createRoot, b as useIsomorphicLayoutEffect, E as ErrorBoundary, B as Block, d as unmountComponentAtNode, f as createPointerEvents, g as createEvents } from '../../dist/events-2895749c.esm.js';
2
- export { t as ReactThreeFiber, _ as _roots, w as act, k as addAfterEffect, j as addEffect, l as addTail, n as advance, q as applyProps, x as buildGraph, p as context, g as createEvents, o as createPortal, c as createRoot, v as dispose, e as extend, h as flushGlobalEffects, s as getRootState, m as invalidate, r as reconciler, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from '../../dist/events-2895749c.esm.js';
1
+ import { e as extend, u as useBridge, a as useMutableCallback, c as createRoot, b as useIsomorphicLayoutEffect, E as ErrorBoundary, B as Block, d as unmountComponentAtNode, f as createPointerEvents, g as createEvents } from '../../dist/events-f80b1519.esm.js';
2
+ export { t as ReactThreeFiber, _ as _roots, w as act, k as addAfterEffect, j as addEffect, l as addTail, n as advance, q as applyProps, x as buildGraph, p as context, g as createEvents, o as createPortal, c as createRoot, v as dispose, e as extend, h as flushGlobalEffects, s as getRootState, m as invalidate, r as reconciler, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from '../../dist/events-f80b1519.esm.js';
3
3
  import * as React from 'react';
4
4
  import * as THREE from 'three';
5
5
  import { PanResponder, PixelRatio, StyleSheet, View, Platform, Image, NativeModules } from 'react-native';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "9.0.4",
3
+ "version": "9.1.0",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",