@keyframe-engine/three 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 InitialXKO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,45 @@
1
+ export interface RegisterSceneOptions {
2
+ defaultFastDirty?: boolean;
3
+ }
4
+ export interface RegisterObjectOptions {
5
+ fastDirty?: boolean;
6
+ }
7
+ export interface ApplyOptions {
8
+ fastDirty?: boolean;
9
+ }
10
+ export interface AdapterObjectOptions {
11
+ fastDirty?: boolean;
12
+ }
13
+ export declare class AdapterContext {
14
+ readonly scene: any;
15
+ readonly engine: any;
16
+ readonly defaultFastDirty: boolean;
17
+ readonly registeredObjects: Set<any>;
18
+ readonly objectOptions: Map<any, AdapterObjectOptions>;
19
+ constructor(scene: any, engine: any, options?: RegisterSceneOptions);
20
+ registerObject(object: any, options?: RegisterObjectOptions): void;
21
+ unregisterObject(object: any, restoreControl?: boolean): void;
22
+ }
23
+ export declare class ThreeAdapter {
24
+ /**
25
+ * Register scene and get unique AdapterContext credential handle.
26
+ */
27
+ registerScene(scene: any, engine: any, options?: RegisterSceneOptions): AdapterContext;
28
+ /**
29
+ * Unbind scene context.
30
+ * @param ctx AdapterContext handle
31
+ * @param restoreControl true (default): restore matrixAutoUpdate=true and updateMatrix().
32
+ * false: clear internal references directly, skip matrix restore.
33
+ * WARNING: If false is used on non-disposed scene, objects remain locked.
34
+ */
35
+ unregisterScene(ctx: AdapterContext, restoreControl?: boolean): void;
36
+ /**
37
+ * Apply matrices to all registered objects in Context credential.
38
+ * Atomic execution order:
39
+ * 1. object.matrixAutoUpdate = false
40
+ * 2. object.matrix.copy(rawMatrix) / elements assignment
41
+ * 3. if (!fastDirty) matrix.decompose(position, quaternion, scale)
42
+ */
43
+ applyToScene(ctx: AdapterContext, time: number, options?: ApplyOptions): void;
44
+ }
45
+ export declare const threeAdapter: ThreeAdapter;
package/dist/index.js ADDED
@@ -0,0 +1,117 @@
1
+ export class AdapterContext {
2
+ scene;
3
+ engine;
4
+ defaultFastDirty;
5
+ registeredObjects = new Set();
6
+ objectOptions = new Map();
7
+ constructor(scene, engine, options) {
8
+ this.scene = scene;
9
+ this.engine = engine;
10
+ this.defaultFastDirty = options?.defaultFastDirty ?? false;
11
+ }
12
+ registerObject(object, options) {
13
+ if (!object)
14
+ return;
15
+ this.registeredObjects.add(object);
16
+ if (options) {
17
+ this.objectOptions.set(object, { fastDirty: options.fastDirty });
18
+ }
19
+ object.matrixAutoUpdate = false;
20
+ }
21
+ unregisterObject(object, restoreControl = true) {
22
+ if (!object)
23
+ return;
24
+ this.registeredObjects.delete(object);
25
+ this.objectOptions.delete(object);
26
+ if (restoreControl) {
27
+ object.matrixAutoUpdate = true;
28
+ if (typeof object.updateMatrix === "function") {
29
+ object.updateMatrix();
30
+ }
31
+ }
32
+ }
33
+ }
34
+ export class ThreeAdapter {
35
+ /**
36
+ * Register scene and get unique AdapterContext credential handle.
37
+ */
38
+ registerScene(scene, engine, options) {
39
+ return new AdapterContext(scene, engine, options);
40
+ }
41
+ /**
42
+ * Unbind scene context.
43
+ * @param ctx AdapterContext handle
44
+ * @param restoreControl true (default): restore matrixAutoUpdate=true and updateMatrix().
45
+ * false: clear internal references directly, skip matrix restore.
46
+ * WARNING: If false is used on non-disposed scene, objects remain locked.
47
+ */
48
+ unregisterScene(ctx, restoreControl = true) {
49
+ if (!ctx)
50
+ return;
51
+ if (restoreControl) {
52
+ for (const obj of ctx.registeredObjects) {
53
+ obj.matrixAutoUpdate = true;
54
+ if (typeof obj.updateMatrix === "function") {
55
+ obj.updateMatrix();
56
+ }
57
+ }
58
+ }
59
+ ctx.registeredObjects.clear();
60
+ ctx.objectOptions.clear();
61
+ }
62
+ /**
63
+ * Apply matrices to all registered objects in Context credential.
64
+ * Atomic execution order:
65
+ * 1. object.matrixAutoUpdate = false
66
+ * 2. object.matrix.copy(rawMatrix) / elements assignment
67
+ * 3. if (!fastDirty) matrix.decompose(position, quaternion, scale)
68
+ */
69
+ applyToScene(ctx, time, options) {
70
+ if (!ctx || !ctx.engine)
71
+ return;
72
+ const evaluated = ctx.engine.getEvaluatedInstances(time);
73
+ const objectsArray = Array.from(ctx.registeredObjects);
74
+ const sceneDefaultFastDirty = ctx.defaultFastDirty;
75
+ const globalFastDirty = options?.fastDirty;
76
+ for (let i = 0; i < objectsArray.length; i++) {
77
+ const obj = objectsArray[i];
78
+ const instData = evaluated[i];
79
+ if (!obj || !instData)
80
+ continue;
81
+ // 1. Lock control
82
+ obj.matrixAutoUpdate = false;
83
+ // 2. Write native column-major matrix
84
+ const rawMatrix = instData.transformMatrix;
85
+ if (obj.matrix) {
86
+ if (typeof obj.matrix.fromArray === "function") {
87
+ obj.matrix.fromArray(rawMatrix);
88
+ }
89
+ else if (typeof obj.matrix.copy === "function" && rawMatrix.elements) {
90
+ obj.matrix.copy(rawMatrix);
91
+ }
92
+ else if (obj.matrix.elements) {
93
+ obj.matrix.elements.set(rawMatrix);
94
+ }
95
+ else {
96
+ obj.matrix.elements = new Float32Array(rawMatrix);
97
+ }
98
+ }
99
+ // Determine fastDirty strategy
100
+ const objSpecificFastDirty = ctx.objectOptions.get(obj)?.fastDirty;
101
+ const isFastDirty = globalFastDirty ?? objSpecificFastDirty ?? sceneDefaultFastDirty;
102
+ // 3. Decompose if fastDirty is false
103
+ if (!isFastDirty && obj.matrix) {
104
+ if (typeof obj.matrix.decompose === "function") {
105
+ if (!obj.position)
106
+ obj.position = { x: 0, y: 0, z: 0 };
107
+ if (!obj.quaternion)
108
+ obj.quaternion = { x: 0, y: 0, z: 0, w: 1 };
109
+ if (!obj.scale)
110
+ obj.scale = { x: 1, y: 1, z: 1 };
111
+ obj.matrix.decompose(obj.position, obj.quaternion, obj.scale);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ export const threeAdapter = new ThreeAdapter();
@@ -0,0 +1,31 @@
1
+ export interface RegisterSceneOptions {
2
+ defaultRasterized?: boolean;
3
+ }
4
+ export interface RegisterObjectOptions {
5
+ rasterized?: boolean;
6
+ }
7
+ export interface ApplyOptions {
8
+ rasterized?: boolean;
9
+ }
10
+ export interface UnregisterSceneOptions {
11
+ abandoned?: boolean;
12
+ }
13
+ export interface AdapterObjectOptions {
14
+ rasterized?: boolean;
15
+ }
16
+ export declare class AdapterContext {
17
+ readonly scene: any;
18
+ readonly engine: any;
19
+ readonly defaultRasterized: boolean;
20
+ readonly registeredObjects: Set<any>;
21
+ readonly objectOptions: Map<any, AdapterObjectOptions>;
22
+ constructor(scene: any, engine: any, options?: RegisterSceneOptions);
23
+ registerObject(object: any, options?: RegisterObjectOptions): void;
24
+ unregisterObject(object: any, options?: UnregisterSceneOptions): void;
25
+ }
26
+ export declare class ThreeAdapter {
27
+ registerScene(scene: any, engine: any, options?: RegisterSceneOptions): AdapterContext;
28
+ unregisterScene(ctx: AdapterContext, options?: UnregisterSceneOptions): void;
29
+ applyToScene(ctx: AdapterContext, time: number, options?: ApplyOptions): void;
30
+ }
31
+ export declare const threeAdapter: ThreeAdapter;
@@ -0,0 +1,98 @@
1
+ export class AdapterContext {
2
+ scene;
3
+ engine;
4
+ defaultRasterized;
5
+ registeredObjects = new Set();
6
+ objectOptions = new Map();
7
+ constructor(scene, engine, options) {
8
+ this.scene = scene;
9
+ this.engine = engine;
10
+ this.defaultRasterized = options?.defaultRasterized ?? false;
11
+ }
12
+ registerObject(object, options) {
13
+ if (!object)
14
+ return;
15
+ this.registeredObjects.add(object);
16
+ if (options?.rasterized !== undefined) {
17
+ this.objectOptions.set(object, { rasterized: options.rasterized });
18
+ }
19
+ object.matrixAutoUpdate = false;
20
+ }
21
+ unregisterObject(object, options) {
22
+ if (!object)
23
+ return;
24
+ this.registeredObjects.delete(object);
25
+ this.objectOptions.delete(object);
26
+ const isAbandoned = options?.abandoned ?? false;
27
+ if (!isAbandoned) {
28
+ object.matrixAutoUpdate = true;
29
+ if (typeof object.updateMatrix === "function") {
30
+ object.updateMatrix();
31
+ }
32
+ }
33
+ }
34
+ }
35
+ export class ThreeAdapter {
36
+ registerScene(scene, engine, options) {
37
+ return new AdapterContext(scene, engine, options);
38
+ }
39
+ unregisterScene(ctx, options) {
40
+ if (!ctx)
41
+ return;
42
+ const isAbandoned = options?.abandoned ?? false;
43
+ if (!isAbandoned) {
44
+ for (const obj of ctx.registeredObjects) {
45
+ obj.matrixAutoUpdate = true;
46
+ if (typeof obj.updateMatrix === "function") {
47
+ obj.updateMatrix();
48
+ }
49
+ }
50
+ }
51
+ ctx.registeredObjects.clear();
52
+ ctx.objectOptions.clear();
53
+ }
54
+ applyToScene(ctx, time, options) {
55
+ if (!ctx || !ctx.engine)
56
+ return;
57
+ const evaluated = ctx.engine.getEvaluatedInstances(time);
58
+ const objectsArray = Array.from(ctx.registeredObjects);
59
+ const sceneDefaultRasterized = ctx.defaultRasterized;
60
+ const globalRasterized = options?.rasterized;
61
+ for (let i = 0; i < objectsArray.length; i++) {
62
+ const obj = objectsArray[i];
63
+ const instData = evaluated[i];
64
+ if (!obj || !instData)
65
+ continue;
66
+ obj.matrixAutoUpdate = false;
67
+ const rawMatrix = instData.transformMatrix;
68
+ if (obj.matrix) {
69
+ if (typeof obj.matrix.fromArray === "function") {
70
+ obj.matrix.fromArray(rawMatrix);
71
+ }
72
+ else if (typeof obj.matrix.copy === "function" && rawMatrix.elements) {
73
+ obj.matrix.copy(rawMatrix);
74
+ }
75
+ else if (obj.matrix.elements) {
76
+ obj.matrix.elements.set(rawMatrix);
77
+ }
78
+ else {
79
+ obj.matrix.elements = new Float32Array(rawMatrix);
80
+ }
81
+ }
82
+ const objSpecificRasterized = ctx.objectOptions.get(obj)?.rasterized;
83
+ const isRasterized = globalRasterized ?? objSpecificRasterized ?? sceneDefaultRasterized;
84
+ if (!isRasterized && obj.matrix) {
85
+ if (typeof obj.matrix.decompose === "function") {
86
+ if (!obj.position)
87
+ obj.position = { x: 0, y: 0, z: 0 };
88
+ if (!obj.quaternion)
89
+ obj.quaternion = { x: 0, y: 0, z: 0, w: 1 };
90
+ if (!obj.scale)
91
+ obj.scale = { x: 1, y: 1, z: 1 };
92
+ obj.matrix.decompose(obj.position, obj.quaternion, obj.scale);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ export const threeAdapter = new ThreeAdapter();
@@ -0,0 +1 @@
1
+ export * from "../../../js/adapters/three_adapter.js";
@@ -0,0 +1 @@
1
+ export * from "../../../js/adapters/three_adapter.js";
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@keyframe-engine/three",
3
+ "version": "1.0.0",
4
+ "description": "@keyframe-engine/three — Three.js Binding Adapter",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "peerDependencies": {
10
+ "three": "^0.150.0",
11
+ "@keyframe-engine/core": "1.0.0"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc"
18
+ }
19
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ export interface RegisterSceneOptions {
2
+ defaultFastDirty?: boolean;
3
+ }
4
+ export interface RegisterObjectOptions {
5
+ fastDirty?: boolean;
6
+ }
7
+ export interface ApplyOptions {
8
+ fastDirty?: boolean;
9
+ }
10
+ export interface AdapterObjectOptions {
11
+ fastDirty?: boolean;
12
+ }
13
+ export declare class AdapterContext {
14
+ readonly scene: any;
15
+ readonly engine: any;
16
+ readonly defaultFastDirty: boolean;
17
+ readonly registeredObjects: Set<any>;
18
+ readonly objectOptions: Map<any, AdapterObjectOptions>;
19
+ constructor(scene: any, engine: any, options?: RegisterSceneOptions);
20
+ registerObject(object: any, options?: RegisterObjectOptions): void;
21
+ unregisterObject(object: any, restoreControl?: boolean): void;
22
+ }
23
+ export declare class ThreeAdapter {
24
+ /**
25
+ * Register scene and get unique AdapterContext credential handle.
26
+ */
27
+ registerScene(scene: any, engine: any, options?: RegisterSceneOptions): AdapterContext;
28
+ /**
29
+ * Unbind scene context.
30
+ * @param ctx AdapterContext handle
31
+ * @param restoreControl true (default): restore matrixAutoUpdate=true and updateMatrix().
32
+ * false: clear internal references directly, skip matrix restore.
33
+ * WARNING: If false is used on non-disposed scene, objects remain locked.
34
+ */
35
+ unregisterScene(ctx: AdapterContext, restoreControl?: boolean): void;
36
+ /**
37
+ * Apply matrices to all registered objects in Context credential.
38
+ * Atomic execution order:
39
+ * 1. object.matrixAutoUpdate = false
40
+ * 2. object.matrix.copy(rawMatrix) / elements assignment
41
+ * 3. if (!fastDirty) matrix.decompose(position, quaternion, scale)
42
+ */
43
+ applyToScene(ctx: AdapterContext, time: number, options?: ApplyOptions): void;
44
+ }
45
+ export declare const threeAdapter: ThreeAdapter;
package/src/index.js ADDED
@@ -0,0 +1,117 @@
1
+ export class AdapterContext {
2
+ scene;
3
+ engine;
4
+ defaultFastDirty;
5
+ registeredObjects = new Set();
6
+ objectOptions = new Map();
7
+ constructor(scene, engine, options) {
8
+ this.scene = scene;
9
+ this.engine = engine;
10
+ this.defaultFastDirty = options?.defaultFastDirty ?? false;
11
+ }
12
+ registerObject(object, options) {
13
+ if (!object)
14
+ return;
15
+ this.registeredObjects.add(object);
16
+ if (options) {
17
+ this.objectOptions.set(object, { fastDirty: options.fastDirty });
18
+ }
19
+ object.matrixAutoUpdate = false;
20
+ }
21
+ unregisterObject(object, restoreControl = true) {
22
+ if (!object)
23
+ return;
24
+ this.registeredObjects.delete(object);
25
+ this.objectOptions.delete(object);
26
+ if (restoreControl) {
27
+ object.matrixAutoUpdate = true;
28
+ if (typeof object.updateMatrix === "function") {
29
+ object.updateMatrix();
30
+ }
31
+ }
32
+ }
33
+ }
34
+ export class ThreeAdapter {
35
+ /**
36
+ * Register scene and get unique AdapterContext credential handle.
37
+ */
38
+ registerScene(scene, engine, options) {
39
+ return new AdapterContext(scene, engine, options);
40
+ }
41
+ /**
42
+ * Unbind scene context.
43
+ * @param ctx AdapterContext handle
44
+ * @param restoreControl true (default): restore matrixAutoUpdate=true and updateMatrix().
45
+ * false: clear internal references directly, skip matrix restore.
46
+ * WARNING: If false is used on non-disposed scene, objects remain locked.
47
+ */
48
+ unregisterScene(ctx, restoreControl = true) {
49
+ if (!ctx)
50
+ return;
51
+ if (restoreControl) {
52
+ for (const obj of ctx.registeredObjects) {
53
+ obj.matrixAutoUpdate = true;
54
+ if (typeof obj.updateMatrix === "function") {
55
+ obj.updateMatrix();
56
+ }
57
+ }
58
+ }
59
+ ctx.registeredObjects.clear();
60
+ ctx.objectOptions.clear();
61
+ }
62
+ /**
63
+ * Apply matrices to all registered objects in Context credential.
64
+ * Atomic execution order:
65
+ * 1. object.matrixAutoUpdate = false
66
+ * 2. object.matrix.copy(rawMatrix) / elements assignment
67
+ * 3. if (!fastDirty) matrix.decompose(position, quaternion, scale)
68
+ */
69
+ applyToScene(ctx, time, options) {
70
+ if (!ctx || !ctx.engine)
71
+ return;
72
+ const evaluated = ctx.engine.getEvaluatedInstances(time);
73
+ const objectsArray = Array.from(ctx.registeredObjects);
74
+ const sceneDefaultFastDirty = ctx.defaultFastDirty;
75
+ const globalFastDirty = options?.fastDirty;
76
+ for (let i = 0; i < objectsArray.length; i++) {
77
+ const obj = objectsArray[i];
78
+ const instData = evaluated[i];
79
+ if (!obj || !instData)
80
+ continue;
81
+ // 1. Lock control
82
+ obj.matrixAutoUpdate = false;
83
+ // 2. Write native column-major matrix
84
+ const rawMatrix = instData.transformMatrix;
85
+ if (obj.matrix) {
86
+ if (typeof obj.matrix.fromArray === "function") {
87
+ obj.matrix.fromArray(rawMatrix);
88
+ }
89
+ else if (typeof obj.matrix.copy === "function" && rawMatrix.elements) {
90
+ obj.matrix.copy(rawMatrix);
91
+ }
92
+ else if (obj.matrix.elements) {
93
+ obj.matrix.elements.set(rawMatrix);
94
+ }
95
+ else {
96
+ obj.matrix.elements = new Float32Array(rawMatrix);
97
+ }
98
+ }
99
+ // Determine fastDirty strategy
100
+ const objSpecificFastDirty = ctx.objectOptions.get(obj)?.fastDirty;
101
+ const isFastDirty = globalFastDirty ?? objSpecificFastDirty ?? sceneDefaultFastDirty;
102
+ // 3. Decompose if fastDirty is false
103
+ if (!isFastDirty && obj.matrix) {
104
+ if (typeof obj.matrix.decompose === "function") {
105
+ if (!obj.position)
106
+ obj.position = { x: 0, y: 0, z: 0 };
107
+ if (!obj.quaternion)
108
+ obj.quaternion = { x: 0, y: 0, z: 0, w: 1 };
109
+ if (!obj.scale)
110
+ obj.scale = { x: 1, y: 1, z: 1 };
111
+ obj.matrix.decompose(obj.position, obj.quaternion, obj.scale);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ export const threeAdapter = new ThreeAdapter();
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "../../../js/adapters/three_adapter.js";
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true
12
+ },
13
+ "include": ["src/**/*"]
14
+ }