create-definedmotion 0.2.0 → 0.3.1

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.
Files changed (65) hide show
  1. package/package.json +2 -2
  2. package/template/src/assets/audio/testing_shadow_glow_song.mp3 +0 -0
  3. package/template/src/assets/for_tests/svg/gravity_text.svg +38 -0
  4. package/template/src/assets/for_tests/svg/grip_figure.svg +28 -0
  5. package/template/src/entry.ts +1 -1
  6. package/template/src/example_scenes/dependencyScene.ts +2 -4
  7. package/template/src/example_scenes/fourierSeriesScene.ts +7 -8
  8. package/template/src/example_scenes/keyboardScene.ts +3 -5
  9. package/template/src/example_scenes/latex_text_transitions_scene.ts +146 -0
  10. package/template/src/example_scenes/tests/animations/camera_movements/test_2d_camera_centers_labels.ts +53 -0
  11. package/template/src/example_scenes/tests/animations/camera_movements/test_2d_camera_hits_markers.ts +40 -0
  12. package/template/src/example_scenes/tests/animations/camera_movements/test_camera_rotate_quaternion.ts +17 -0
  13. package/template/src/example_scenes/tests/animations/camera_movements/test_camera_waypoints_sequential.ts +29 -0
  14. package/template/src/example_scenes/tests/animations/camera_movements/test_fly_camera_waypoints_verifiable.ts +87 -0
  15. package/template/src/example_scenes/tests/animations/camera_movements/test_zoom_perspective_sequential.ts +17 -0
  16. package/template/src/example_scenes/tests/animations/latex/test_latex_blue_particle_transition.ts +82 -0
  17. package/template/src/example_scenes/tests/animations/latex/test_latex_highlight_animation.ts +64 -0
  18. package/template/src/example_scenes/tests/animations/latex/test_latex_mark_animation.ts +42 -0
  19. package/template/src/example_scenes/tests/animations/latex/test_latex_particle_transition.ts +48 -0
  20. package/template/src/example_scenes/tests/animations/latex/test_latex_particle_transition_complex.ts +65 -0
  21. package/template/src/example_scenes/tests/animations/latex/test_latex_particle_transition_super_complex.ts +86 -0
  22. package/template/src/example_scenes/tests/animations/latex/test_with_environment_latex_particle_transition.ts +80 -0
  23. package/template/src/example_scenes/tests/animations/latex/test_write_latex_animation.ts +28 -0
  24. package/template/src/example_scenes/tests/animations/latex/test_write_latex_animation_2.ts +34 -0
  25. package/template/src/example_scenes/tests/animations/latex/test_write_latex_animation_3.ts +34 -0
  26. package/template/src/example_scenes/tests/audio/test_long_audio.ts +11 -0
  27. package/template/src/example_scenes/tests/audio/test_many_short_sounds.ts +50 -0
  28. package/template/src/example_scenes/tests/environment/test_hdri_performance.ts +14 -0
  29. package/template/src/example_scenes/tests/svg/test_basic_latex_query.ts +59 -0
  30. package/template/src/example_scenes/tests/svg/test_basic_svg.ts +11 -0
  31. package/template/src/example_scenes/tests/svg/test_colored_latex_to_svg.ts +42 -0
  32. package/template/src/example_scenes/tests/svg/test_complex_latex_to_svg.ts +22 -0
  33. package/template/src/example_scenes/tests/svg/test_latex_to_svg.ts +17 -0
  34. package/template/src/example_scenes/tests/svg/test_material_on_latex.ts +43 -0
  35. package/template/src/example_scenes/tests/svg/test_query_latex_variables.ts +66 -0
  36. package/template/src/example_scenes/tests/svg/test_regular_text_latex.ts +21 -0
  37. package/template/src/example_scenes/tests/svg/test_super_complex_latex_to_svg.ts +98 -0
  38. package/template/src/example_scenes/tests/svg/test_transition_svgs.ts +33 -0
  39. package/template/src/example_scenes/tests/svg/test_update_svg_object.ts +19 -0
  40. package/template/src/example_scenes/tests/svg/test_yellow_grip_symbol_svg.ts +11 -0
  41. package/template/src/example_scenes/tutorials/medium1.ts +3 -5
  42. package/template/src/example_scenes/vectorField.ts +2 -4
  43. package/template/src/example_scenes/visulizingFunctions.ts +3 -5
  44. package/template/src/main/rendering.ts +38 -21
  45. package/template/src/renderer/src/App.svelte +40 -12
  46. package/template/src/renderer/src/lib/animation/animations.ts +141 -88
  47. package/template/src/renderer/src/lib/animation/captureCanvas.ts +1 -15
  48. package/template/src/renderer/src/lib/animation/latexMarkAndHighlight.ts +349 -0
  49. package/template/src/renderer/src/lib/animation/latexTransitionsAndWrite.ts +558 -0
  50. package/template/src/renderer/src/lib/audio/manager.ts +185 -0
  51. package/template/src/renderer/src/lib/rendering/hdri.ts +273 -0
  52. package/template/src/renderer/src/lib/rendering/lighting3d.ts +0 -105
  53. package/template/src/renderer/src/lib/rendering/setup.ts +7 -1
  54. package/template/src/renderer/src/lib/rendering/svg/latexSVGQueries.ts +44 -0
  55. package/template/src/renderer/src/lib/rendering/svg/latexToSVG.ts +132 -0
  56. package/template/src/renderer/src/lib/rendering/svg/svgObjectHelpers.ts +59 -0
  57. package/template/src/renderer/src/lib/rendering/svg/svgRendering.ts +120 -0
  58. package/template/src/renderer/src/lib/scene/sceneClass.ts +93 -31
  59. package/template/src/renderer/src/lib/audio/loader.ts +0 -104
  60. package/template/src/renderer/src/lib/rendering/materials.ts +0 -6
  61. package/template/src/renderer/src/lib/rendering/protocols.ts +0 -21
  62. package/template/src/renderer/src/lib/rendering/svg/drawing.ts +0 -213
  63. package/template/src/renderer/src/lib/rendering/svg/parsing.ts +0 -717
  64. package/template/src/renderer/src/lib/rendering/svg/rastered.ts +0 -42
  65. package/template/src/renderer/src/lib/rendering/svgObjects.ts +0 -1137
@@ -1,213 +0,0 @@
1
- import { COLORS } from '../helpers'
2
- import { isApproximatelyEqual2D, isApproximatelyEqual2d3d, VectorizedElementNode } from './parsing'
3
- import * as THREE from 'three'
4
-
5
- export const drawVectorizedNodes = (
6
- vectorizedNodes: VectorizedElementNode[],
7
- width: number,
8
- options?: {
9
- defaultFillColor?: number
10
- defaultStrokeColor?: number
11
- }
12
- ): THREE.Group => {
13
- const { defaultFillColor = 0xff9900, defaultStrokeColor = 0x0099ff } = options ?? {}
14
-
15
- const rootGroup = new THREE.Group()
16
-
17
- const drawNode = (node: VectorizedElementNode): THREE.Object3D => {
18
- const nodeGroup = new THREE.Group()
19
-
20
- const props = node.properties ?? {}
21
- const hasFill = 'fill' in props && props.fill !== 'none'
22
- const hasStroke = 'stroke' in props && props.stroke !== 'none'
23
-
24
- if (node.points.length >= 2 && node.tagName !== 'path' && (hasFill || hasStroke)) {
25
- // ✅ Fill if applicable
26
- if (node.isClosed && node.points.length >= 3 && hasFill) {
27
- const shape = new THREE.Shape(node.points.map(([x, y]) => new THREE.Vector2(x, y)))
28
- const fillColor = new THREE.Color()
29
-
30
- const mesh = new THREE.Mesh(
31
- new THREE.ShapeGeometry(shape),
32
- new THREE.MeshBasicMaterial({ color: fillColor, side: THREE.DoubleSide })
33
- )
34
- nodeGroup.add(mesh)
35
- }
36
-
37
- // ✅ Stroke if applicable
38
- if (hasStroke) {
39
- const vertices: [number, number, number][] = node.points.map(([x, y]) => [x, y, 0])
40
- const geometry = pointsToStroke(vertices, props['stroke-width'] || 1)
41
-
42
- const strokeColor = new THREE.Color(
43
- typeof props.stroke === 'string' ? props.stroke : defaultStrokeColor
44
- )
45
-
46
- const material = new THREE.MeshBasicMaterial({
47
- color: strokeColor,
48
- side: THREE.DoubleSide,
49
- depthWrite: false,
50
- depthTest: false
51
- })
52
- const strokeMesh = new THREE.Mesh(geometry, material)
53
- nodeGroup.add(strokeMesh)
54
- }
55
- }
56
-
57
- if (node.tagName === 'path') {
58
- const vertices: [number, number, number][] = node.points.map(([x, y]) => [x, y, 0])
59
- let previousStart = 0
60
- node.subpathIndices.forEach((index) => {
61
- if (previousStart !== index) {
62
- const subpathIsClosed = isApproximatelyEqual2d3d(
63
- vertices[previousStart],
64
- vertices[index - 1]
65
- )
66
-
67
- if (subpathIsClosed && hasFill) {
68
- const shape = new THREE.Shape(
69
- node.points.slice(previousStart, index).map(([x, y]) => new THREE.Vector2(x, y))
70
- )
71
- const fillColor = COLORS.black
72
-
73
- const mesh = new THREE.Mesh(
74
- new THREE.ShapeGeometry(shape),
75
- new THREE.MeshBasicMaterial({ color: fillColor, side: THREE.DoubleSide })
76
- )
77
-
78
- nodeGroup.add(mesh)
79
- } else {
80
- const geometry = pointsToStroke(
81
- vertices.slice(previousStart, index),
82
- (props['stroke-width'] as number) || 1
83
- )
84
-
85
- const strokeColor = COLORS.black
86
-
87
- const material = new THREE.MeshBasicMaterial({
88
- color: strokeColor,
89
- side: THREE.DoubleSide,
90
- depthWrite: false,
91
- depthTest: false
92
- })
93
- const strokeMesh = new THREE.Mesh(geometry, material)
94
- nodeGroup.add(strokeMesh)
95
- }
96
-
97
- previousStart = index
98
- }
99
- })
100
- }
101
-
102
- for (const child of node.children) {
103
- if (typeof child === 'string') continue
104
- const childGroup = drawNode(child)
105
- nodeGroup.add(childGroup)
106
- }
107
-
108
- return nodeGroup
109
- }
110
-
111
- for (const node of vectorizedNodes) {
112
- const group = drawNode(node)
113
- rootGroup.add(group)
114
- }
115
-
116
- const originalBox = new THREE.Box3().setFromObject(rootGroup)
117
- const originalWidth = originalBox.max.x - originalBox.min.x
118
- if (originalWidth <= 0) return rootGroup
119
-
120
- const scaleFactor = width / originalWidth
121
- rootGroup.scale.set(scaleFactor, -scaleFactor, 1) // Single Y flip here
122
-
123
- // Center the scaled group
124
- const scaledBox = new THREE.Box3().setFromObject(rootGroup)
125
- const center = scaledBox.getCenter(new THREE.Vector3())
126
- rootGroup.position.sub(center)
127
-
128
- return rootGroup
129
- }
130
-
131
- function pointsToStroke(points: [number, number, number][], width: number): THREE.BufferGeometry {
132
- const halfWidth = width / 2
133
- const leftOffsets: [number, number][] = []
134
- const rightOffsets: [number, number][] = []
135
-
136
- // Helper: compute a unit normal (perpendicular) from point A to B.
137
- function computeNormal(
138
- A: [number, number, number],
139
- B: [number, number, number]
140
- ): [number, number, number] {
141
- const dx = B[0] - A[0]
142
- const dy = B[1] - A[1]
143
- const len = Math.sqrt(dx * dx + dy * dy)
144
- if (len === 0) return [0, 0, 0]
145
- // Rotate by 90° counterclockwise: (-dy, dx)
146
- return [-dy / len, dx / len, 0]
147
- }
148
-
149
- // Use the normal of the first segment for the first point.
150
- const nStart = computeNormal(points[0], points[1])
151
- leftOffsets.push([points[0][0] + nStart[0] * halfWidth, points[0][1] + nStart[1] * halfWidth])
152
- rightOffsets.push([points[0][0] - nStart[0] * halfWidth, points[0][1] - nStart[1] * halfWidth])
153
-
154
- // For internal points, average the normals of adjacent segments.
155
- for (let i = 1; i < points.length - 1; i++) {
156
- const n1 = computeNormal(points[i - 1], points[i])
157
- const n2 = computeNormal(points[i], points[i + 1])
158
- // Average the two normals.
159
- const avg: [number, number, number] = [n1[0] + n2[0], n1[1] + n2[1], 0]
160
- const len = Math.sqrt(avg[0] * avg[0] + avg[1] * avg[1])
161
- const normal: [number, number, number] = len === 0 ? n2 : [avg[0] / len, avg[1] / len, 0]
162
- leftOffsets.push([points[i][0] + normal[0] * halfWidth, points[i][1] + normal[1] * halfWidth])
163
- rightOffsets.push([points[i][0] - normal[0] * halfWidth, points[i][1] - normal[1] * halfWidth])
164
- }
165
-
166
- // Use the normal of the last segment for the last point.
167
- const nEnd = computeNormal(points[points.length - 2], points[points.length - 1])
168
- leftOffsets.push([
169
- points[points.length - 1][0] + nEnd[0] * halfWidth,
170
- points[points.length - 1][1] + nEnd[1] * halfWidth
171
- ])
172
- rightOffsets.push([
173
- points[points.length - 1][0] - nEnd[0] * halfWidth,
174
- points[points.length - 1][1] - nEnd[1] * halfWidth
175
- ])
176
-
177
- // Build triangles for each segment between consecutive points.
178
- const positions: number[] = []
179
- const normals: number[] = []
180
- // All normals face +Z for a flat XY-plane.
181
- const nz = [0, 0, 1]
182
-
183
- for (let i = 0; i < points.length - 1; i++) {
184
- // Create vertices for the quad:
185
- // leftOffsets[i], rightOffsets[i], rightOffsets[i+1], leftOffsets[i+1]
186
- const v0 = leftOffsets[i]
187
- const v1 = rightOffsets[i]
188
- const v2 = rightOffsets[i + 1]
189
- const v3 = leftOffsets[i + 1]
190
-
191
- // Triangle 1: v0, v1, v2
192
- positions.push(v0[0], v0[1], 0)
193
- positions.push(v1[0], v1[1], 0)
194
- positions.push(v2[0], v2[1], 0)
195
-
196
- // Triangle 2: v0, v2, v3
197
- positions.push(v0[0], v0[1], 0)
198
- positions.push(v2[0], v2[1], 0)
199
- positions.push(v3[0], v3[1], 0)
200
-
201
- // Each triangle has 3 vertices, add normals for each (pointing up)
202
- for (let j = 0; j < 6; j++) {
203
- normals.push(...nz)
204
- }
205
- }
206
-
207
- const geometry = new THREE.BufferGeometry()
208
- geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3))
209
- geometry.setAttribute('normal', new THREE.Float32BufferAttribute(normals, 3))
210
- geometry.computeBoundingSphere()
211
-
212
- return geometry
213
- }