@octanejs/three 0.1.51 → 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.
- package/package.json +6 -6
- package/src/core/driver.ts +67 -48
- package/src/core/root.ts +3 -0
- package/src/intrinsics.ts +3 -0
- package/src/web/Canvas.tsrx +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/three",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
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/
|
|
76
|
-
"@octanejs/
|
|
77
|
-
"
|
|
78
|
-
"
|
|
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",
|
package/src/core/driver.ts
CHANGED
|
@@ -208,7 +208,11 @@ export function createThreePortalTarget(
|
|
|
208
208
|
export interface ThreeHostEnvironment {
|
|
209
209
|
/** Called once after an accepted host batch, without requiring WebGL. */
|
|
210
210
|
invalidate?(): void;
|
|
211
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Set false to omit accepted batches from the public diagnostic history.
|
|
213
|
+
* Roots created by `createRoot` (and therefore `Canvas` and the testing
|
|
214
|
+
* harness) set it false so a long-lived scene does not retain every batch.
|
|
215
|
+
*/
|
|
212
216
|
recordCommits?: boolean;
|
|
213
217
|
/** Root state associated with a configured managed scene. */
|
|
214
218
|
readonly store?: RootStore;
|
|
@@ -534,48 +538,74 @@ function prepareDirectLeafMountBatch(
|
|
|
534
538
|
};
|
|
535
539
|
}
|
|
536
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
|
+
|
|
537
586
|
function prepareUpdateOnlyBatch(
|
|
538
587
|
container: ThreeHostContainer,
|
|
539
588
|
batch: UniversalHostBatch,
|
|
540
589
|
): UniversalPreparedHostBatch | null {
|
|
541
|
-
|
|
590
|
+
const commands = batch.commands;
|
|
591
|
+
const count = commands.length;
|
|
592
|
+
if (count === 0) return null;
|
|
542
593
|
|
|
543
594
|
const state = container[THREE_DRIVER_STATE];
|
|
544
595
|
const instances = state.directInstances;
|
|
596
|
+
const scene = container.scene;
|
|
545
597
|
if (
|
|
546
598
|
instances === null ||
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
599
|
+
count !== state.rootChildren.length ||
|
|
600
|
+
count !== instances.length ||
|
|
601
|
+
count !== state.instances.size ||
|
|
602
|
+
scene.children.length !== count ||
|
|
603
|
+
scene.parent !== null
|
|
552
604
|
) {
|
|
553
605
|
return null;
|
|
554
606
|
}
|
|
555
|
-
for (let index = 0; index <
|
|
556
|
-
|
|
557
|
-
if (command.op !== 'update') return null;
|
|
558
|
-
const instance = instances[index];
|
|
559
|
-
if (command.id !== instance.id) return null;
|
|
560
|
-
if (
|
|
561
|
-
instance.object.parent !== container.scene ||
|
|
562
|
-
container.scene.children[index] !== instance.object ||
|
|
563
|
-
instance.object.visible !== true ||
|
|
564
|
-
instance.object.position.fromArray !== THREE_VECTOR3_FROM_ARRAY
|
|
565
|
-
) {
|
|
566
|
-
return null;
|
|
567
|
-
}
|
|
568
|
-
if (!isDirectMeshProps(command.props)) return null;
|
|
569
|
-
if ((instance.props as DirectMeshProps).name !== command.props.name) {
|
|
570
|
-
const nameDescriptor = Object.getOwnPropertyDescriptor(instance.object, 'name');
|
|
571
|
-
if (
|
|
572
|
-
nameDescriptor === undefined ||
|
|
573
|
-
!('value' in nameDescriptor) ||
|
|
574
|
-
nameDescriptor.writable !== true
|
|
575
|
-
) {
|
|
576
|
-
return null;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
607
|
+
for (let index = 0; index < count; index++) {
|
|
608
|
+
if (!isDirectMeshUpdate(commands[index], instances[index], scene, index)) return null;
|
|
579
609
|
}
|
|
580
610
|
|
|
581
611
|
let status: 'prepared' | 'applied' | 'aborted' = 'prepared';
|
|
@@ -585,24 +615,13 @@ function prepareUpdateOnlyBatch(
|
|
|
585
615
|
status = 'applied';
|
|
586
616
|
let failed = false;
|
|
587
617
|
let firstError: unknown;
|
|
588
|
-
for (let index = 0; index <
|
|
618
|
+
for (let index = 0; index < count; index++) {
|
|
589
619
|
try {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
)
|
|
595
|
-
instance.props = next;
|
|
596
|
-
if (previous.name !== next.name) instance.object.name = next.name;
|
|
597
|
-
const previousPosition = previous.position;
|
|
598
|
-
const nextPosition = next.position;
|
|
599
|
-
if (
|
|
600
|
-
previousPosition[0] !== nextPosition[0] ||
|
|
601
|
-
previousPosition[1] !== nextPosition[1] ||
|
|
602
|
-
previousPosition[2] !== nextPosition[2]
|
|
603
|
-
) {
|
|
604
|
-
instance.object.position.fromArray(nextPosition);
|
|
605
|
-
}
|
|
620
|
+
applyDirectMeshUpdate(
|
|
621
|
+
instances[index],
|
|
622
|
+
(commands[index] as Extract<UniversalHostCommand, { readonly op: 'update' }>)
|
|
623
|
+
.props as DirectMeshProps,
|
|
624
|
+
);
|
|
606
625
|
} catch (error) {
|
|
607
626
|
if (!failed) {
|
|
608
627
|
failed = true;
|
package/src/core/root.ts
CHANGED
|
@@ -469,6 +469,9 @@ function ensureHostRoot(internals: ThreeRootInternals<any>): void {
|
|
|
469
469
|
let hostRoot: UniversalRoot | null = null;
|
|
470
470
|
const environment: ThreeHostEnvironment = {
|
|
471
471
|
store: internals.store,
|
|
472
|
+
// An application root commits for its whole lifetime; keeping every accepted
|
|
473
|
+
// batch would retain each replaced props object and listener table forever.
|
|
474
|
+
recordCommits: false,
|
|
472
475
|
invalidate: () => internals.store.getState().invalidate(),
|
|
473
476
|
eventScope(priority, run) {
|
|
474
477
|
const root = hostRoot;
|
package/src/intrinsics.ts
CHANGED
|
@@ -35,4 +35,7 @@ export type {
|
|
|
35
35
|
/** TypeScript resolves this namespace through the intrinsic jsx-runtime export. */
|
|
36
36
|
export namespace JSX {
|
|
37
37
|
export interface IntrinsicElements extends ThreeIntrinsicElements {}
|
|
38
|
+
export interface ElementChildrenAttribute {
|
|
39
|
+
children: {};
|
|
40
|
+
}
|
|
38
41
|
}
|
package/src/web/Canvas.tsrx
CHANGED
|
@@ -291,7 +291,11 @@ export function Canvas({
|
|
|
291
291
|
...style,
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
-
return <div
|
|
294
|
+
return <div
|
|
295
|
+
ref={wrapperRef}
|
|
296
|
+
style={wrapperStyle}
|
|
297
|
+
{...domProps as typeof domProps & { ref?: undefined }}
|
|
298
|
+
>
|
|
295
299
|
<div style={{ width: '100%', height: '100%' }}>
|
|
296
300
|
<canvas ref={[canvasRef, ref]} style={{ display: 'block' }}>{fallback}</canvas>
|
|
297
301
|
</div>
|