@remotion/svg-3d-engine 4.0.249
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/.turbo/turbo-make.log +5 -0
- package/LICENSE.md +49 -0
- package/README.md +7 -0
- package/bundle.ts +22 -0
- package/dist/cjs/3d-svg.d.ts +22 -0
- package/dist/cjs/3d-svg.js +26 -0
- package/dist/cjs/elements.d.ts +14 -0
- package/dist/cjs/elements.js +26 -0
- package/dist/cjs/extrude-element.d.ts +19 -0
- package/dist/cjs/extrude-element.js +128 -0
- package/dist/cjs/fix-z.d.ts +3 -0
- package/dist/cjs/fix-z.js +44 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/make-id.d.ts +1 -0
- package/dist/cjs/make-id.js +7 -0
- package/dist/cjs/map-face.d.ts +31 -0
- package/dist/cjs/map-face.js +134 -0
- package/dist/cjs/matrix.d.ts +58 -0
- package/dist/cjs/matrix.js +286 -0
- package/dist/cjs/subdivide-instructions.d.ts +4 -0
- package/dist/cjs/subdivide-instructions.js +180 -0
- package/dist/cjs/truthy.d.ts +3 -0
- package/dist/cjs/truthy.js +6 -0
- package/dist/esm/index.mjs +2694 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/eslint.config.mjs +7 -0
- package/package.json +34 -0
- package/src/3d-svg.ts +59 -0
- package/src/elements.ts +46 -0
- package/src/extrude-element.ts +184 -0
- package/src/fix-z.ts +45 -0
- package/src/index.ts +20 -0
- package/src/make-id.ts +3 -0
- package/src/map-face.ts +188 -0
- package/src/matrix.ts +393 -0
- package/src/subdivide-instructions.ts +238 -0
- package/src/truthy.ts +4 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import type {Instruction} from '@remotion/paths';
|
|
2
|
+
import type {ThreeDReducedInstruction} from './3d-svg';
|
|
3
|
+
import type {Vector2D, Vector4D} from './matrix';
|
|
4
|
+
|
|
5
|
+
const subdivideLOrMInstruction = (
|
|
6
|
+
from: Vector4D,
|
|
7
|
+
instruction: ThreeDReducedInstruction,
|
|
8
|
+
) => {
|
|
9
|
+
if (instruction.type !== 'L' && instruction.type !== 'M') {
|
|
10
|
+
throw new Error('Expected L or M instruction');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const t = 0.5;
|
|
14
|
+
const q0: Vector4D = [
|
|
15
|
+
(1 - t) * from[0] + t * instruction.point[0],
|
|
16
|
+
(1 - t) * from[1] + t * instruction.point[1],
|
|
17
|
+
(1 - t) * from[2] + t * instruction.point[2],
|
|
18
|
+
(1 - t) * from[3] + t * instruction.point[3],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const curves: [ThreeDReducedInstruction, ThreeDReducedInstruction] = [
|
|
22
|
+
{type: instruction.type, point: q0},
|
|
23
|
+
{type: instruction.type, point: instruction.point},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
return curves;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const subdivide2DCInstruction = (
|
|
30
|
+
fromX: number,
|
|
31
|
+
fromY: number,
|
|
32
|
+
instruction: Instruction,
|
|
33
|
+
t: number,
|
|
34
|
+
) => {
|
|
35
|
+
if (instruction.type !== 'C') {
|
|
36
|
+
throw new Error('Expected C instruction');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const q0: Vector2D = [
|
|
40
|
+
(1 - t) * fromX + t * instruction.cp1x,
|
|
41
|
+
(1 - t) * fromY + t * instruction.cp1y,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const q1: Vector2D = [
|
|
45
|
+
(1 - t) * instruction.cp1x + t * instruction.cp2x,
|
|
46
|
+
(1 - t) * instruction.cp1y + t * instruction.cp2y,
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const q2: Vector2D = [
|
|
50
|
+
(1 - t) * instruction.cp2x + t * instruction.x,
|
|
51
|
+
(1 - t) * instruction.cp2y + t * instruction.y,
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const r0: Vector2D = [
|
|
55
|
+
(1 - t) * q0[0] + t * q1[0],
|
|
56
|
+
(1 - t) * q0[1] + t * q1[1],
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const r1: Vector2D = [
|
|
60
|
+
(1 - t) * q1[0] + t * q2[0],
|
|
61
|
+
(1 - t) * q1[1] + t * q2[1],
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const s0: Vector2D = [
|
|
65
|
+
(1 - t) * r0[0] + t * r1[0],
|
|
66
|
+
(1 - t) * r0[1] + t * r1[1],
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const curves: [Instruction, Instruction] = [
|
|
70
|
+
{
|
|
71
|
+
type: 'C',
|
|
72
|
+
x: s0[0],
|
|
73
|
+
y: s0[1],
|
|
74
|
+
cp1x: q0[0],
|
|
75
|
+
cp1y: q0[1],
|
|
76
|
+
cp2x: r0[0],
|
|
77
|
+
cp2y: r0[1],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'C',
|
|
81
|
+
x: instruction.x,
|
|
82
|
+
y: instruction.y,
|
|
83
|
+
cp1x: r1[0],
|
|
84
|
+
cp1y: r1[1],
|
|
85
|
+
cp2x: q2[0],
|
|
86
|
+
cp2y: q2[1],
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
return curves;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const subdivide3DCInstruction = (
|
|
94
|
+
from: Vector4D,
|
|
95
|
+
instruction: ThreeDReducedInstruction,
|
|
96
|
+
) => {
|
|
97
|
+
if (instruction.type !== 'C') {
|
|
98
|
+
throw new Error('Expected C instruction');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const t = 0.5;
|
|
102
|
+
|
|
103
|
+
const q0: Vector4D = [
|
|
104
|
+
(1 - t) * from[0] + t * instruction.cp1[0],
|
|
105
|
+
(1 - t) * from[1] + t * instruction.cp1[1],
|
|
106
|
+
(1 - t) * from[2] + t * instruction.cp1[2],
|
|
107
|
+
(1 - t) * from[3] + t * instruction.cp1[3],
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
const q1: Vector4D = [
|
|
111
|
+
(1 - t) * instruction.cp1[0] + t * instruction.cp2[0],
|
|
112
|
+
(1 - t) * instruction.cp1[1] + t * instruction.cp2[1],
|
|
113
|
+
(1 - t) * instruction.cp1[2] + t * instruction.cp2[2],
|
|
114
|
+
(1 - t) * instruction.cp1[3] + t * instruction.cp2[3],
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
const q2: Vector4D = [
|
|
118
|
+
(1 - t) * instruction.cp2[0] + t * instruction.point[0],
|
|
119
|
+
(1 - t) * instruction.cp2[1] + t * instruction.point[1],
|
|
120
|
+
(1 - t) * instruction.cp2[2] + t * instruction.point[2],
|
|
121
|
+
(1 - t) * instruction.cp2[3] + t * instruction.point[3],
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
const r0: Vector4D = [
|
|
125
|
+
(1 - t) * q0[0] + t * q1[0],
|
|
126
|
+
(1 - t) * q0[1] + t * q1[1],
|
|
127
|
+
(1 - t) * q0[2] + t * q1[2],
|
|
128
|
+
(1 - t) * q0[3] + t * q1[3],
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const r1: Vector4D = [
|
|
132
|
+
(1 - t) * q1[0] + t * q2[0],
|
|
133
|
+
(1 - t) * q1[1] + t * q2[1],
|
|
134
|
+
(1 - t) * q1[2] + t * q2[2],
|
|
135
|
+
(1 - t) * q1[3] + t * q2[3],
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
const s0: Vector4D = [
|
|
139
|
+
(1 - t) * r0[0] + t * r1[0],
|
|
140
|
+
(1 - t) * r0[1] + t * r1[1],
|
|
141
|
+
(1 - t) * r0[2] + t * r1[2],
|
|
142
|
+
(1 - t) * r0[3] + t * r1[3],
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const curves: [ThreeDReducedInstruction, ThreeDReducedInstruction] = [
|
|
146
|
+
{type: 'C', point: s0, cp1: q0, cp2: r0},
|
|
147
|
+
{type: 'C', point: instruction.point, cp1: r1, cp2: q2},
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
return curves;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const subdivideQInstruction = (
|
|
154
|
+
from: Vector4D,
|
|
155
|
+
instruction: ThreeDReducedInstruction,
|
|
156
|
+
) => {
|
|
157
|
+
if (instruction.type !== 'Q') {
|
|
158
|
+
throw new Error('Expected Q instruction');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const t = 0.5;
|
|
162
|
+
const q0: Vector4D = [
|
|
163
|
+
(1 - t) * from[0] + t * instruction.cp[0],
|
|
164
|
+
(1 - t) * from[1] + t * instruction.cp[1],
|
|
165
|
+
(1 - t) * from[2] + t * instruction.cp[2],
|
|
166
|
+
(1 - t) * from[3] + t * instruction.cp[3],
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
const q1: Vector4D = [
|
|
170
|
+
(1 - t) * instruction.cp[0] + t * instruction.point[0],
|
|
171
|
+
(1 - t) * instruction.cp[1] + t * instruction.point[1],
|
|
172
|
+
(1 - t) * instruction.cp[2] + t * instruction.point[2],
|
|
173
|
+
(1 - t) * instruction.cp[3] + t * instruction.point[3],
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
const r0: Vector4D = [
|
|
177
|
+
(1 - t) * q0[0] + t * q1[0],
|
|
178
|
+
(1 - t) * q0[1] + t * q1[1],
|
|
179
|
+
(1 - t) * q0[2] + t * q1[2],
|
|
180
|
+
(1 - t) * q0[3] + t * q1[3],
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
const newInstructions: [ThreeDReducedInstruction, ThreeDReducedInstruction] =
|
|
184
|
+
[
|
|
185
|
+
{type: 'Q', point: r0, cp: q0},
|
|
186
|
+
{type: 'Q', point: instruction.point, cp: q1},
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
return newInstructions;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const subdivideInstruction = (
|
|
193
|
+
from: Vector4D,
|
|
194
|
+
instruction: ThreeDReducedInstruction,
|
|
195
|
+
): ThreeDReducedInstruction[] => {
|
|
196
|
+
if (instruction.type === 'C') {
|
|
197
|
+
return subdivide3DCInstruction(from, instruction);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (instruction.type === 'L' || instruction.type === 'M') {
|
|
201
|
+
return subdivideLOrMInstruction(from, instruction);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (instruction.type === 'Q') {
|
|
205
|
+
return subdivideQInstruction(from, instruction);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (instruction.type === 'Z') {
|
|
209
|
+
return [instruction];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
throw new Error('Cannot subdivide instruction');
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export const subdivideInstructions = (
|
|
216
|
+
instructions: ThreeDReducedInstruction[],
|
|
217
|
+
): ThreeDReducedInstruction[] => {
|
|
218
|
+
const newInstructions: ThreeDReducedInstruction[] = [];
|
|
219
|
+
instructions.forEach((instruction, i) => {
|
|
220
|
+
if (instruction.type === 'M') {
|
|
221
|
+
newInstructions.push(instruction);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (instruction.type === 'Z') {
|
|
226
|
+
newInstructions.push(instruction);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const previousInstruction = instructions[i - 1];
|
|
231
|
+
const subdivided = subdivideInstruction(
|
|
232
|
+
previousInstruction.point,
|
|
233
|
+
instruction,
|
|
234
|
+
);
|
|
235
|
+
newInstructions.push(...subdivided);
|
|
236
|
+
});
|
|
237
|
+
return newInstructions;
|
|
238
|
+
};
|
package/src/truthy.ts
ADDED