@octanejs/three 0.1.52 → 0.1.54
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/package.json +7 -7
- 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.
|
|
3
|
+
"version": "0.1.54",
|
|
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.
|
|
53
|
+
"octane": "^0.10.0",
|
|
54
54
|
"three": ">=0.156.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
@@ -59,23 +59,23 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
+
"@octanejs/rsbuild-plugin": "0.1.60",
|
|
63
|
+
"@octanejs/rspack-plugin": "0.1.58",
|
|
64
|
+
"@octanejs/vite-plugin": "0.3.0",
|
|
62
65
|
"@react-three/fiber": "9.6.1",
|
|
63
66
|
"@rsbuild/core": "^2.1.6",
|
|
64
67
|
"@rspack/core": "^2.1.4",
|
|
65
68
|
"@tsrx/react": "^0.3.7",
|
|
66
69
|
"@types/three": "0.172.0",
|
|
67
70
|
"esbuild": "^0.28.1",
|
|
71
|
+
"octane": "0.10.0",
|
|
68
72
|
"playwright": "^1.61.1",
|
|
69
73
|
"react": "19.2.7",
|
|
70
74
|
"react-dom": "19.2.7",
|
|
71
75
|
"three": "0.172.0",
|
|
72
76
|
"typescript": "^5.9.3",
|
|
73
77
|
"vite": "^8.1.5",
|
|
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"
|
|
78
|
+
"vitest": "^4.1.10"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"test": "pnpm upstream:check && vitest run --root ../.. --project three",
|
package/src/core/driver.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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 <
|
|
560
|
-
|
|
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 <
|
|
618
|
+
for (let index = 0; index < count; index++) {
|
|
593
619
|
try {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
)
|
|
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;
|