@remotion/svg-3d-engine 4.0.364 → 4.0.365

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.
@@ -0,0 +1,22 @@
1
+ import type { Vector4D } from './matrix';
2
+ export type ThreeDReducedInstruction = {
3
+ type: 'M';
4
+ point: Vector4D;
5
+ } | {
6
+ type: 'L';
7
+ point: Vector4D;
8
+ } | {
9
+ type: 'C';
10
+ cp1: Vector4D;
11
+ cp2: Vector4D;
12
+ point: Vector4D;
13
+ } | {
14
+ type: 'Q';
15
+ cp: Vector4D;
16
+ point: Vector4D;
17
+ } | {
18
+ type: 'Z';
19
+ point: Vector4D;
20
+ };
21
+ export declare const serializeThreeDReducedInstruction: (instruction: ThreeDReducedInstruction) => string;
22
+ export declare const threeDIntoSvgPath: (instructions: ThreeDReducedInstruction[]) => string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.threeDIntoSvgPath = exports.serializeThreeDReducedInstruction = void 0;
4
+ const serializeThreeDReducedInstruction = (instruction) => {
5
+ if (instruction.type === 'M') {
6
+ return `M ${instruction.point[0]} ${instruction.point[1]}`;
7
+ }
8
+ if (instruction.type === 'L') {
9
+ return `L ${instruction.point[0]} ${instruction.point[1]}`;
10
+ }
11
+ if (instruction.type === 'C') {
12
+ return `C ${instruction.cp1[0]} ${instruction.cp1[1]} ${instruction.cp2[0]} ${instruction.cp2[1]} ${instruction.point[0]} ${instruction.point[1]}`;
13
+ }
14
+ if (instruction.type === 'Q') {
15
+ return `Q ${instruction.cp[0]} ${instruction.cp[1]} ${instruction.point[0]} ${instruction.point[1]}`;
16
+ }
17
+ if (instruction.type === 'Z') {
18
+ return 'Z';
19
+ }
20
+ throw new Error('Unknown instruction type');
21
+ };
22
+ exports.serializeThreeDReducedInstruction = serializeThreeDReducedInstruction;
23
+ const threeDIntoSvgPath = (instructions) => instructions
24
+ .map((instruction) => (0, exports.serializeThreeDReducedInstruction)(instruction))
25
+ .join(' ');
26
+ exports.threeDIntoSvgPath = threeDIntoSvgPath;
@@ -0,0 +1,8 @@
1
+ import type { FaceType } from './map-face';
2
+ import type { MatrixTransform4D } from './matrix';
3
+ export type ThreeDElement = {
4
+ faces: FaceType[];
5
+ id: string;
6
+ description: string;
7
+ };
8
+ export declare const transformFaces: (faces: FaceType[], transformations: MatrixTransform4D[]) => FaceType[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformFaces = void 0;
4
+ const map_face_1 = require("./map-face");
5
+ const transformFaces = (faces, transformations) => {
6
+ return faces.map((face) => {
7
+ return (0, map_face_1.transformFace)(face, transformations);
8
+ });
9
+ };
10
+ exports.transformFaces = transformFaces;
@@ -0,0 +1,15 @@
1
+ import type { Instruction } from '@remotion/paths';
2
+ import type { FaceType } from './map-face';
3
+ import type { MatrixTransform4D } from './matrix';
4
+ type ExtrudeElementOptions = {
5
+ depth: number;
6
+ sideColor: string;
7
+ points: Instruction[];
8
+ description?: string;
9
+ crispEdges: boolean;
10
+ };
11
+ export declare const extrudeElement: ({ depth, sideColor, points, crispEdges, }: ExtrudeElementOptions) => FaceType[];
12
+ export declare const extrudeAndTransformElement: (options: ExtrudeElementOptions & {
13
+ transformations: MatrixTransform4D;
14
+ }) => FaceType[];
15
+ export {};
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extrudeAndTransformElement = exports.extrudeElement = void 0;
4
+ const fix_z_1 = require("./fix-z");
5
+ const map_face_1 = require("./map-face");
6
+ const matrix_1 = require("./matrix");
7
+ const subdivide_instructions_1 = require("./subdivide-instructions");
8
+ const truthy_1 = require("./truthy");
9
+ const inverseInstruction = (instruction, comingFrom) => {
10
+ if (instruction.type === 'M') {
11
+ return {
12
+ type: 'M',
13
+ point: comingFrom,
14
+ };
15
+ }
16
+ if (instruction.type === 'L') {
17
+ return {
18
+ type: 'L',
19
+ point: comingFrom,
20
+ };
21
+ }
22
+ if (instruction.type === 'C') {
23
+ return {
24
+ type: 'C',
25
+ point: comingFrom,
26
+ cp1: instruction.cp2,
27
+ cp2: instruction.cp1,
28
+ };
29
+ }
30
+ if (instruction.type === 'Q') {
31
+ return {
32
+ type: 'Q',
33
+ point: comingFrom,
34
+ cp: instruction.cp,
35
+ };
36
+ }
37
+ if (instruction.type === 'Z') {
38
+ return {
39
+ type: 'L',
40
+ point: comingFrom,
41
+ };
42
+ }
43
+ throw new Error('Unknown instruction type');
44
+ };
45
+ const extrudeElement = ({ depth, sideColor, points, crispEdges, }) => {
46
+ const threeD = (0, fix_z_1.turnInto3D)(points);
47
+ const instructions = {
48
+ centerPoint: [0, 0, 0, 1],
49
+ points: (0, subdivide_instructions_1.subdivideInstructions)((0, subdivide_instructions_1.subdivideInstructions)((0, subdivide_instructions_1.subdivideInstructions)(threeD))),
50
+ color: 'black',
51
+ crispEdges,
52
+ };
53
+ const unscaledBackFace = (0, map_face_1.transformFace)(instructions, [(0, matrix_1.translateZ)(depth / 2)]);
54
+ const inbetween = unscaledBackFace.points.map((t, i) => {
55
+ const nextInstruction = i === unscaledBackFace.points.length - 1
56
+ ? unscaledBackFace.points[0]
57
+ : unscaledBackFace.points[i + 1];
58
+ const currentPoint = t.point;
59
+ const nextPoint = nextInstruction.point;
60
+ const movingOver = [
61
+ nextPoint[0],
62
+ nextPoint[1],
63
+ nextPoint[2] - depth,
64
+ nextPoint[3],
65
+ ];
66
+ const translatedInstruction = (0, map_face_1.translateSvgInstruction)(inverseInstruction(nextInstruction, currentPoint), 0, 0, -depth);
67
+ const newInstructions = [
68
+ {
69
+ type: 'M',
70
+ point: currentPoint,
71
+ },
72
+ nextInstruction,
73
+ nextInstruction.type === 'Z'
74
+ ? {
75
+ type: 'M',
76
+ point: nextInstruction.point,
77
+ }
78
+ : null,
79
+ {
80
+ type: 'L',
81
+ point: movingOver,
82
+ },
83
+ translatedInstruction,
84
+ {
85
+ type: 'L',
86
+ point: currentPoint,
87
+ },
88
+ ].filter(truthy_1.truthy);
89
+ return {
90
+ points: newInstructions,
91
+ color: sideColor,
92
+ centerPoint: [0, 0, 0, 1],
93
+ crispEdges: true,
94
+ };
95
+ });
96
+ return inbetween;
97
+ };
98
+ exports.extrudeElement = extrudeElement;
99
+ const extrudeAndTransformElement = (options) => {
100
+ const inbetween = (0, exports.extrudeElement)(options);
101
+ return inbetween.map((face) => ({
102
+ ...(0, map_face_1.transformFace)(face, [options.transformations]),
103
+ }));
104
+ };
105
+ exports.extrudeAndTransformElement = extrudeAndTransformElement;
@@ -0,0 +1,3 @@
1
+ import type { Instruction } from '@remotion/paths';
2
+ import type { ThreeDReducedInstruction } from './3d-svg';
3
+ export declare const turnInto3D: (instructions: Instruction[]) => ThreeDReducedInstruction[];
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.turnInto3D = void 0;
4
+ const paths_1 = require("@remotion/paths");
5
+ const turnInto3D = (instructions) => {
6
+ let lastMove = [0, 0, 0, 1];
7
+ const newInstructions = [];
8
+ const reduced = (0, paths_1.reduceInstructions)(instructions);
9
+ for (let i = 0; i < reduced.length; i++) {
10
+ const instruction = reduced[i];
11
+ if (instruction.type === 'Z') {
12
+ newInstructions.push({
13
+ type: 'Z',
14
+ point: lastMove,
15
+ });
16
+ }
17
+ else if (instruction.type === 'M') {
18
+ lastMove = [instruction.x, instruction.y, 0, 1];
19
+ newInstructions.push({
20
+ point: [instruction.x, instruction.y, 0, 1],
21
+ type: 'M',
22
+ });
23
+ }
24
+ else if (instruction.type === 'L') {
25
+ newInstructions.push({
26
+ type: 'L',
27
+ point: [instruction.x, instruction.y, 0, 1],
28
+ });
29
+ }
30
+ else if (instruction.type === 'C') {
31
+ newInstructions.push({
32
+ type: 'C',
33
+ point: [instruction.x, instruction.y, 0, 1],
34
+ cp1: [instruction.cp1x, instruction.cp1y, 0, 1],
35
+ cp2: [instruction.cp2x, instruction.cp2y, 0, 1],
36
+ });
37
+ }
38
+ else {
39
+ throw new Error('unknown');
40
+ }
41
+ }
42
+ return newInstructions;
43
+ };
44
+ exports.turnInto3D = turnInto3D;
@@ -0,0 +1,6 @@
1
+ export { MatrixTransform4D, Vector4D } from './matrix';
2
+ export type { ThreeDReducedInstruction } from './3d-svg';
3
+ export { threeDIntoSvgPath } from './3d-svg';
4
+ export { extrudeAndTransformElement, extrudeElement } from './extrude-element';
5
+ export { transformPath, type FaceType } from './map-face';
6
+ export { aroundCenterPoint, interpolateMatrix4d, makeMatrix3dTransform, reduceMatrices, rotateX, rotateY, rotateZ, scaleX, scaleY, scaled, translateX, translateY, translateZ, } from './matrix';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translateZ = exports.translateY = exports.translateX = exports.scaled = exports.scaleY = exports.scaleX = exports.rotateZ = exports.rotateY = exports.rotateX = exports.reduceMatrices = exports.makeMatrix3dTransform = exports.interpolateMatrix4d = exports.aroundCenterPoint = exports.transformPath = exports.extrudeElement = exports.extrudeAndTransformElement = exports.threeDIntoSvgPath = void 0;
4
+ var _3d_svg_1 = require("./3d-svg");
5
+ Object.defineProperty(exports, "threeDIntoSvgPath", { enumerable: true, get: function () { return _3d_svg_1.threeDIntoSvgPath; } });
6
+ var extrude_element_1 = require("./extrude-element");
7
+ Object.defineProperty(exports, "extrudeAndTransformElement", { enumerable: true, get: function () { return extrude_element_1.extrudeAndTransformElement; } });
8
+ Object.defineProperty(exports, "extrudeElement", { enumerable: true, get: function () { return extrude_element_1.extrudeElement; } });
9
+ var map_face_1 = require("./map-face");
10
+ Object.defineProperty(exports, "transformPath", { enumerable: true, get: function () { return map_face_1.transformPath; } });
11
+ var matrix_1 = require("./matrix");
12
+ Object.defineProperty(exports, "aroundCenterPoint", { enumerable: true, get: function () { return matrix_1.aroundCenterPoint; } });
13
+ Object.defineProperty(exports, "interpolateMatrix4d", { enumerable: true, get: function () { return matrix_1.interpolateMatrix4d; } });
14
+ Object.defineProperty(exports, "makeMatrix3dTransform", { enumerable: true, get: function () { return matrix_1.makeMatrix3dTransform; } });
15
+ Object.defineProperty(exports, "reduceMatrices", { enumerable: true, get: function () { return matrix_1.reduceMatrices; } });
16
+ Object.defineProperty(exports, "rotateX", { enumerable: true, get: function () { return matrix_1.rotateX; } });
17
+ Object.defineProperty(exports, "rotateY", { enumerable: true, get: function () { return matrix_1.rotateY; } });
18
+ Object.defineProperty(exports, "rotateZ", { enumerable: true, get: function () { return matrix_1.rotateZ; } });
19
+ Object.defineProperty(exports, "scaleX", { enumerable: true, get: function () { return matrix_1.scaleX; } });
20
+ Object.defineProperty(exports, "scaleY", { enumerable: true, get: function () { return matrix_1.scaleY; } });
21
+ Object.defineProperty(exports, "scaled", { enumerable: true, get: function () { return matrix_1.scaled; } });
22
+ Object.defineProperty(exports, "translateX", { enumerable: true, get: function () { return matrix_1.translateX; } });
23
+ Object.defineProperty(exports, "translateY", { enumerable: true, get: function () { return matrix_1.translateY; } });
24
+ Object.defineProperty(exports, "translateZ", { enumerable: true, get: function () { return matrix_1.translateZ; } });
@@ -0,0 +1 @@
1
+ export declare const makeId: () => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeId = void 0;
4
+ const makeId = () => {
5
+ return Math.random().toString().replace('.', '');
6
+ };
7
+ exports.makeId = makeId;
@@ -0,0 +1,25 @@
1
+ import { type ThreeDReducedInstruction } from './3d-svg';
2
+ import type { MatrixTransform4D, Vector4D } from './matrix';
3
+ export type FaceType = {
4
+ color: string;
5
+ points: ThreeDReducedInstruction[];
6
+ centerPoint: Vector4D;
7
+ crispEdges: boolean;
8
+ };
9
+ export declare const translateSvgInstruction: (instruction: ThreeDReducedInstruction, x: number, y: number, z: number) => ThreeDReducedInstruction;
10
+ export declare const transformPath: ({ path, transformation, }: {
11
+ path: string;
12
+ transformation: MatrixTransform4D;
13
+ }) => string;
14
+ export declare const transformFace: (face: FaceType, transformations: MatrixTransform4D[]) => FaceType;
15
+ export declare const transformFaces: ({ faces, transformations, }: {
16
+ faces: FaceType[];
17
+ transformations: MatrixTransform4D[];
18
+ }) => FaceType[];
19
+ export declare const makeFace: ({ points, fill, crispEdges, }: {
20
+ points: string | ThreeDReducedInstruction[];
21
+ strokeWidth: number;
22
+ strokeColor: string;
23
+ fill: string;
24
+ crispEdges: boolean;
25
+ }) => FaceType;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeFace = exports.transformFaces = exports.transformFace = exports.transformPath = exports.translateSvgInstruction = void 0;
4
+ const paths_1 = require("@remotion/paths");
5
+ const _3d_svg_1 = require("./3d-svg");
6
+ const fix_z_1 = require("./fix-z");
7
+ const matrix_1 = require("./matrix");
8
+ const translateSvgInstruction = (instruction, x, y, z) => {
9
+ if (instruction.type === 'M') {
10
+ return {
11
+ type: 'M',
12
+ point: [
13
+ instruction.point[0] + x,
14
+ instruction.point[1] + y,
15
+ instruction.point[2] + z,
16
+ instruction.point[3],
17
+ ],
18
+ };
19
+ }
20
+ if (instruction.type === 'L') {
21
+ return {
22
+ type: 'L',
23
+ point: [
24
+ instruction.point[0] + x,
25
+ instruction.point[1] + y,
26
+ instruction.point[2] + z,
27
+ instruction.point[3],
28
+ ],
29
+ };
30
+ }
31
+ if (instruction.type === 'C') {
32
+ return {
33
+ type: 'C',
34
+ point: [
35
+ instruction.point[0] + x,
36
+ instruction.point[1] + y,
37
+ instruction.point[2] + z,
38
+ instruction.point[3],
39
+ ],
40
+ cp1: [
41
+ instruction.cp1[0] + x,
42
+ instruction.cp1[1] + y,
43
+ instruction.cp1[2] + z,
44
+ instruction.cp1[3],
45
+ ],
46
+ cp2: [
47
+ instruction.cp2[0] + x,
48
+ instruction.cp2[1] + y,
49
+ instruction.cp2[2] + z,
50
+ instruction.cp2[3],
51
+ ],
52
+ };
53
+ }
54
+ if (instruction.type === 'Q') {
55
+ return {
56
+ type: 'Q',
57
+ point: [
58
+ instruction.point[0] + x,
59
+ instruction.point[1] + y,
60
+ instruction.point[2] + z,
61
+ instruction.point[3],
62
+ ],
63
+ cp: [
64
+ instruction.cp[0] + x,
65
+ instruction.cp[1] + y,
66
+ instruction.cp[2] + z,
67
+ instruction.cp[3],
68
+ ],
69
+ };
70
+ }
71
+ if (instruction.type === 'Z') {
72
+ return {
73
+ type: 'Z',
74
+ point: [
75
+ instruction.point[0] + x,
76
+ instruction.point[1] + y,
77
+ instruction.point[2] + z,
78
+ instruction.point[3],
79
+ ],
80
+ };
81
+ }
82
+ throw new Error('Unknown instruction type: ' + JSON.stringify(instruction));
83
+ };
84
+ exports.translateSvgInstruction = translateSvgInstruction;
85
+ const transformPath = ({ path, transformation, }) => {
86
+ const parsed = (0, paths_1.parsePath)(path);
87
+ const reduced = (0, paths_1.reduceInstructions)(parsed);
88
+ const threeD = (0, fix_z_1.turnInto3D)(reduced);
89
+ return (0, _3d_svg_1.threeDIntoSvgPath)(threeD.map((p) => {
90
+ return (0, matrix_1.multiplyMatrixAndSvgInstruction)(transformation, p);
91
+ }));
92
+ };
93
+ exports.transformPath = transformPath;
94
+ const transformFace = (face, transformations) => {
95
+ return {
96
+ ...face,
97
+ points: face.points.map((p) => {
98
+ return transformations.reduce((acc, t) => {
99
+ return (0, matrix_1.multiplyMatrixAndSvgInstruction)(t, acc);
100
+ }, p);
101
+ }),
102
+ centerPoint: transformations.reduce((acc, t) => {
103
+ const result = (0, matrix_1.multiplyMatrix)(t, acc);
104
+ return result;
105
+ }, face.centerPoint),
106
+ };
107
+ };
108
+ exports.transformFace = transformFace;
109
+ const transformFaces = ({ faces, transformations, }) => {
110
+ return faces.map((face) => {
111
+ return (0, exports.transformFace)(face, transformations);
112
+ });
113
+ };
114
+ exports.transformFaces = transformFaces;
115
+ const makeFace = ({ points, fill, crispEdges, }) => {
116
+ const centerPoint = [0, 0, 0, 1];
117
+ return {
118
+ centerPoint,
119
+ color: fill,
120
+ points: typeof points === 'string' ? (0, fix_z_1.turnInto3D)((0, paths_1.parsePath)(points)) : points,
121
+ crispEdges,
122
+ };
123
+ };
124
+ exports.makeFace = makeFace;
@@ -0,0 +1,66 @@
1
+ import type { ThreeDReducedInstruction } from './3d-svg';
2
+ export declare const stride: ({ v, m, width, offset, colStride, }: {
3
+ v: Vector;
4
+ m: MatrixTransform4D;
5
+ width: number;
6
+ offset: number;
7
+ colStride: number;
8
+ }) => MatrixTransform4D;
9
+ export declare const identity4: () => MatrixTransform4D;
10
+ export declare const m44multiply: (...matrices: MatrixTransform4D[]) => MatrixTransform4D;
11
+ export type Vector2D = [number, number];
12
+ export type Vector = [number, number, number];
13
+ export type Vector4D = [number, number, number, number];
14
+ export declare const rotateX: (radians: number) => MatrixTransform4D;
15
+ export declare const rotateY: (radians: number) => MatrixTransform4D;
16
+ export declare const translated4d: (vec: Vector) => MatrixTransform4D;
17
+ export declare const rotateZ: (radians: number) => MatrixTransform4D;
18
+ export type MatrixTransform4D = [
19
+ number,
20
+ number,
21
+ number,
22
+ number,
23
+ number,
24
+ number,
25
+ number,
26
+ number,
27
+ number,
28
+ number,
29
+ number,
30
+ number,
31
+ number,
32
+ number,
33
+ number,
34
+ number
35
+ ];
36
+ export declare const multiplyMatrices: (matrix1: MatrixTransform4D, matrix2: MatrixTransform4D) => MatrixTransform4D;
37
+ export declare const reduceMatrices: (matrices: (MatrixTransform4D | null)[]) => MatrixTransform4D;
38
+ export declare const aroundCenterPoint: ({ matrix, x, y, z, }: {
39
+ matrix: MatrixTransform4D;
40
+ x: number;
41
+ y: number;
42
+ z: number;
43
+ }) => MatrixTransform4D;
44
+ export declare const makeMatrix3dTransform: (matrix: MatrixTransform4D) => string;
45
+ export declare const interpolateMatrix4d: (input: number, matrix1: MatrixTransform4D, matrix2: MatrixTransform4D) => MatrixTransform4D;
46
+ export declare const scaled: (value: number | Vector) => MatrixTransform4D;
47
+ export declare const scaleX: (x: number) => MatrixTransform4D;
48
+ export declare const scaleY: (y: number) => MatrixTransform4D;
49
+ export declare const normalize: (v: Vector) => Vector;
50
+ export declare const normalize4d: (v: Vector4D) => Vector4D;
51
+ export declare const dot: (a: number[], b: number[]) => number;
52
+ export declare const translateX: (x: number) => MatrixTransform4D;
53
+ export declare const translateY: (y: number) => MatrixTransform4D;
54
+ export declare const translateZ: (z: number) => MatrixTransform4D;
55
+ export type Camera = {
56
+ near: number;
57
+ far: number;
58
+ angle: number;
59
+ eye: Vector;
60
+ coa: Vector;
61
+ up: Vector;
62
+ };
63
+ export declare const mulScalar: <T extends number[]>(v: T, s: number) => T;
64
+ export declare function multiplyMatrixAndSvgInstruction(matrix: MatrixTransform4D, point: ThreeDReducedInstruction): ThreeDReducedInstruction;
65
+ export declare const multiplyMatrix: (matrix: MatrixTransform4D, point: Vector4D) => Vector4D;
66
+ export declare const sub4d: (a: Vector4D, b: Vector4D) => Vector4D;