@octanejs/three 0.1.52 → 0.1.53

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/core/driver.ts +62 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/three",
3
- "version": "0.1.52",
3
+ "version": "0.1.53",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@types/three": ">=0.156.0",
53
- "octane": "^0.8.0",
53
+ "octane": "^0.9.0",
54
54
  "three": ">=0.156.0"
55
55
  },
56
56
  "peerDependenciesMeta": {
@@ -72,10 +72,10 @@
72
72
  "typescript": "^5.9.3",
73
73
  "vite": "^8.1.5",
74
74
  "vitest": "^4.1.10",
75
- "@octanejs/rsbuild-plugin": "0.1.58",
76
- "@octanejs/rspack-plugin": "0.1.56",
77
- "@octanejs/vite-plugin": "0.2.0",
78
- "octane": "0.8.0"
75
+ "@octanejs/rsbuild-plugin": "0.1.59",
76
+ "@octanejs/vite-plugin": "0.2.1",
77
+ "octane": "0.9.0",
78
+ "@octanejs/rspack-plugin": "0.1.57"
79
79
  },
80
80
  "scripts": {
81
81
  "test": "pnpm upstream:check && vitest run --root ../.. --project three",
@@ -538,48 +538,74 @@ function prepareDirectLeafMountBatch(
538
538
  };
539
539
  }
540
540
 
541
+ /**
542
+ * Per-command checks for the update-only fast path. Each update runs the
543
+ * enclosing loop once, so keeping its body in a function called per command
544
+ * lets the engine optimize it as the hot code it is.
545
+ */
546
+ function isDirectMeshUpdate(
547
+ command: UniversalHostCommand,
548
+ instance: ThreeHostInstance,
549
+ scene: THREE.Scene,
550
+ index: number,
551
+ ): boolean {
552
+ if (command.op !== 'update' || command.id !== instance.id) return false;
553
+ const object = instance.object;
554
+ const props = command.props;
555
+ if (
556
+ object.parent !== scene ||
557
+ scene.children[index] !== object ||
558
+ object.visible !== true ||
559
+ object.position.fromArray !== THREE_VECTOR3_FROM_ARRAY ||
560
+ !isDirectMeshProps(props)
561
+ ) {
562
+ return false;
563
+ }
564
+ if ((instance.props as DirectMeshProps).name === props.name) return true;
565
+ const nameDescriptor = Object.getOwnPropertyDescriptor(object, 'name');
566
+ return (
567
+ nameDescriptor !== undefined && 'value' in nameDescriptor && nameDescriptor.writable === true
568
+ );
569
+ }
570
+
571
+ function applyDirectMeshUpdate(instance: ThreeHostInstance, next: DirectMeshProps): void {
572
+ const previous = instance.props as DirectMeshProps;
573
+ instance.props = next;
574
+ if (previous.name !== next.name) instance.object.name = next.name;
575
+ const previousPosition = previous.position;
576
+ const nextPosition = next.position;
577
+ if (
578
+ previousPosition[0] !== nextPosition[0] ||
579
+ previousPosition[1] !== nextPosition[1] ||
580
+ previousPosition[2] !== nextPosition[2]
581
+ ) {
582
+ instance.object.position.fromArray(nextPosition);
583
+ }
584
+ }
585
+
541
586
  function prepareUpdateOnlyBatch(
542
587
  container: ThreeHostContainer,
543
588
  batch: UniversalHostBatch,
544
589
  ): UniversalPreparedHostBatch | null {
545
- if (batch.commands.length === 0) return null;
590
+ const commands = batch.commands;
591
+ const count = commands.length;
592
+ if (count === 0) return null;
546
593
 
547
594
  const state = container[THREE_DRIVER_STATE];
548
595
  const instances = state.directInstances;
596
+ const scene = container.scene;
549
597
  if (
550
598
  instances === null ||
551
- batch.commands.length !== state.rootChildren.length ||
552
- batch.commands.length !== instances.length ||
553
- state.rootChildren.length !== state.instances.size ||
554
- container.scene.children.length !== state.rootChildren.length ||
555
- container.scene.parent !== null
599
+ count !== state.rootChildren.length ||
600
+ count !== instances.length ||
601
+ count !== state.instances.size ||
602
+ scene.children.length !== count ||
603
+ scene.parent !== null
556
604
  ) {
557
605
  return null;
558
606
  }
559
- for (let index = 0; index < batch.commands.length; index++) {
560
- const command = batch.commands[index];
561
- if (command.op !== 'update') return null;
562
- const instance = instances[index];
563
- if (command.id !== instance.id) return null;
564
- if (
565
- instance.object.parent !== container.scene ||
566
- container.scene.children[index] !== instance.object ||
567
- instance.object.visible !== true ||
568
- instance.object.position.fromArray !== THREE_VECTOR3_FROM_ARRAY
569
- ) {
570
- return null;
571
- }
572
- if (!isDirectMeshProps(command.props)) return null;
573
- if ((instance.props as DirectMeshProps).name !== command.props.name) {
574
- const nameDescriptor = Object.getOwnPropertyDescriptor(instance.object, 'name');
575
- if (
576
- nameDescriptor === undefined ||
577
- !('value' in nameDescriptor) ||
578
- nameDescriptor.writable !== true
579
- ) {
580
- return null;
581
- }
582
- }
607
+ for (let index = 0; index < count; index++) {
608
+ if (!isDirectMeshUpdate(commands[index], instances[index], scene, index)) return null;
583
609
  }
584
610
 
585
611
  let status: 'prepared' | 'applied' | 'aborted' = 'prepared';
@@ -589,24 +615,13 @@ function prepareUpdateOnlyBatch(
589
615
  status = 'applied';
590
616
  let failed = false;
591
617
  let firstError: unknown;
592
- for (let index = 0; index < instances.length; index++) {
618
+ for (let index = 0; index < count; index++) {
593
619
  try {
594
- const instance = instances[index];
595
- const previous = instance.props as DirectMeshProps;
596
- const next = (
597
- batch.commands[index] as Extract<UniversalHostCommand, { readonly op: 'update' }>
598
- ).props as DirectMeshProps;
599
- instance.props = next;
600
- if (previous.name !== next.name) instance.object.name = next.name;
601
- const previousPosition = previous.position;
602
- const nextPosition = next.position;
603
- if (
604
- previousPosition[0] !== nextPosition[0] ||
605
- previousPosition[1] !== nextPosition[1] ||
606
- previousPosition[2] !== nextPosition[2]
607
- ) {
608
- instance.object.position.fromArray(nextPosition);
609
- }
620
+ applyDirectMeshUpdate(
621
+ instances[index],
622
+ (commands[index] as Extract<UniversalHostCommand, { readonly op: 'update' }>)
623
+ .props as DirectMeshProps,
624
+ );
610
625
  } catch (error) {
611
626
  if (!failed) {
612
627
  failed = true;