samcan 0.0.2 → 0.1.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 → LICENSE} +3 -1
- package/README.md +3 -0
- package/dist/camera/index.cjs +370 -0
- package/dist/camera/index.d.cts +54 -0
- package/dist/camera/index.d.ts +54 -0
- package/dist/camera/index.js +70 -0
- package/dist/document/index.cjs +735 -0
- package/dist/document/index.d.cts +174 -0
- package/dist/document/index.d.ts +174 -0
- package/dist/document/index.js +161 -0
- package/dist/editor/index.cjs +5007 -0
- package/dist/editor/index.d.cts +374 -0
- package/dist/editor/index.d.ts +374 -0
- package/dist/editor/index.js +2401 -0
- package/dist/engine/index.cjs +3752 -0
- package/dist/engine/index.d.cts +183 -0
- package/dist/engine/index.d.ts +183 -0
- package/dist/engine/index.js +111 -0
- package/dist/index.cjs +8899 -0
- package/dist/index.d.cts +962 -0
- package/dist/index.d.ts +962 -46
- package/dist/index.js +1008 -49
- package/dist/math/index.cjs +2230 -0
- package/dist/math/index.d.cts +302 -0
- package/dist/math/index.d.ts +302 -0
- package/dist/math/index.js +1109 -0
- package/dist/renderer/index.cjs +1865 -0
- package/dist/renderer/index.d.cts +91 -0
- package/dist/renderer/index.d.ts +91 -0
- package/dist/renderer/index.js +89 -0
- package/dist/shared/chunk-35pkr0zs.js +110 -0
- package/dist/shared/chunk-7sr7q84y.js +80 -0
- package/dist/shared/chunk-87399bz7.js +89 -0
- package/dist/shared/chunk-8ynnz57m.js +129 -0
- package/dist/shared/chunk-d6gxvapt.js +500 -0
- package/dist/shared/chunk-hewznwbd.js +305 -0
- package/dist/shared/chunk-jdvrd5tv.js +623 -0
- package/dist/shared/chunk-rvag1j46.js +461 -0
- package/dist/shared/chunk-rzxyjwk8.js +397 -0
- package/dist/shared/chunk-s3qdcmcq.js +1392 -0
- package/dist/shared/chunk-v53jprrn.js +68 -0
- package/dist/shared/chunk-wa3772hp.js +117 -0
- package/dist/spatial/index.cjs +954 -0
- package/dist/spatial/index.d.cts +136 -0
- package/dist/spatial/index.d.ts +136 -0
- package/dist/spatial/index.js +301 -0
- package/dist/stroke/index.cjs +1010 -0
- package/dist/stroke/index.d.cts +143 -0
- package/dist/stroke/index.d.ts +143 -0
- package/dist/stroke/index.js +343 -0
- package/package.json +122 -58
- package/dist/bundle.js +0 -5888
- package/dist/core/animation/animationruntime.d.ts +0 -238
- package/dist/core/animation/animationruntime.d.ts.map +0 -1
- package/dist/core/animation/animationruntime.js +0 -530
- package/dist/core/animation/animationruntime.js.map +0 -1
- package/dist/core/animation/animationstate.d.ts +0 -85
- package/dist/core/animation/animationstate.d.ts.map +0 -1
- package/dist/core/animation/animationstate.js +0 -119
- package/dist/core/animation/animationstate.js.map +0 -1
- package/dist/core/animation/animationtrack.d.ts +0 -55
- package/dist/core/animation/animationtrack.d.ts.map +0 -1
- package/dist/core/animation/animationtrack.js +0 -185
- package/dist/core/animation/animationtrack.js.map +0 -1
- package/dist/core/animation/easing.d.ts +0 -80
- package/dist/core/animation/easing.d.ts.map +0 -1
- package/dist/core/animation/easing.js +0 -126
- package/dist/core/animation/easing.js.map +0 -1
- package/dist/core/animation/index.d.ts +0 -11
- package/dist/core/animation/index.d.ts.map +0 -1
- package/dist/core/animation/index.js +0 -10
- package/dist/core/animation/index.js.map +0 -1
- package/dist/core/animation/interpolator.d.ts +0 -82
- package/dist/core/animation/interpolator.d.ts.map +0 -1
- package/dist/core/animation/interpolator.js +0 -108
- package/dist/core/animation/interpolator.js.map +0 -1
- package/dist/core/animation/keyframe.d.ts +0 -52
- package/dist/core/animation/keyframe.d.ts.map +0 -1
- package/dist/core/animation/keyframe.js +0 -65
- package/dist/core/animation/keyframe.js.map +0 -1
- package/dist/core/animation/logger.d.ts +0 -8
- package/dist/core/animation/logger.d.ts.map +0 -1
- package/dist/core/animation/logger.js +0 -20
- package/dist/core/animation/logger.js.map +0 -1
- package/dist/core/animation/statemachine.d.ts +0 -178
- package/dist/core/animation/statemachine.d.ts.map +0 -1
- package/dist/core/animation/statemachine.js +0 -378
- package/dist/core/animation/statemachine.js.map +0 -1
- package/dist/core/animation/statetransition.d.ts +0 -142
- package/dist/core/animation/statetransition.d.ts.map +0 -1
- package/dist/core/animation/statetransition.js +0 -189
- package/dist/core/animation/statetransition.js.map +0 -1
- package/dist/core/animation/timeline.d.ts +0 -62
- package/dist/core/animation/timeline.d.ts.map +0 -1
- package/dist/core/animation/timeline.js +0 -102
- package/dist/core/animation/timeline.js.map +0 -1
- package/dist/core/api.d.ts +0 -245
- package/dist/core/api.d.ts.map +0 -1
- package/dist/core/api.js +0 -369
- package/dist/core/api.js.map +0 -1
- package/dist/core/asset/assetmanager.d.ts +0 -196
- package/dist/core/asset/assetmanager.d.ts.map +0 -1
- package/dist/core/asset/assetmanager.js +0 -502
- package/dist/core/asset/assetmanager.js.map +0 -1
- package/dist/core/asset/index.d.ts +0 -3
- package/dist/core/asset/index.d.ts.map +0 -1
- package/dist/core/asset/index.js +0 -3
- package/dist/core/asset/index.js.map +0 -1
- package/dist/core/asset/types.d.ts +0 -36
- package/dist/core/asset/types.d.ts.map +0 -1
- package/dist/core/asset/types.js +0 -1
- package/dist/core/asset/types.js.map +0 -1
- package/dist/core/command/basecommand.d.ts +0 -29
- package/dist/core/command/basecommand.d.ts.map +0 -1
- package/dist/core/command/basecommand.js +0 -36
- package/dist/core/command/basecommand.js.map +0 -1
- package/dist/core/command/command.d.ts +0 -55
- package/dist/core/command/command.d.ts.map +0 -1
- package/dist/core/command/command.js +0 -1
- package/dist/core/command/command.js.map +0 -1
- package/dist/core/command/commandhistory.d.ts +0 -76
- package/dist/core/command/commandhistory.d.ts.map +0 -1
- package/dist/core/command/commandhistory.js +0 -122
- package/dist/core/command/commandhistory.js.map +0 -1
- package/dist/core/command/editorcommands.d.ts +0 -108
- package/dist/core/command/editorcommands.d.ts.map +0 -1
- package/dist/core/command/editorcommands.js +0 -274
- package/dist/core/command/editorcommands.js.map +0 -1
- package/dist/core/command/index.d.ts +0 -5
- package/dist/core/command/index.d.ts.map +0 -1
- package/dist/core/command/index.js +0 -5
- package/dist/core/command/index.js.map +0 -1
- package/dist/core/editor/events/emitter.d.ts +0 -45
- package/dist/core/editor/events/emitter.d.ts.map +0 -1
- package/dist/core/editor/events/emitter.js +0 -88
- package/dist/core/editor/events/emitter.js.map +0 -1
- package/dist/core/error/animationerror.d.ts +0 -27
- package/dist/core/error/animationerror.d.ts.map +0 -1
- package/dist/core/error/animationerror.js +0 -41
- package/dist/core/error/animationerror.js.map +0 -1
- package/dist/core/error/asseterror.d.ts +0 -32
- package/dist/core/error/asseterror.d.ts.map +0 -1
- package/dist/core/error/asseterror.js +0 -48
- package/dist/core/error/asseterror.js.map +0 -1
- package/dist/core/error/index.d.ts +0 -7
- package/dist/core/error/index.d.ts.map +0 -1
- package/dist/core/error/index.js +0 -7
- package/dist/core/error/index.js.map +0 -1
- package/dist/core/error/pluginerror.d.ts +0 -22
- package/dist/core/error/pluginerror.d.ts.map +0 -1
- package/dist/core/error/pluginerror.js +0 -33
- package/dist/core/error/pluginerror.js.map +0 -1
- package/dist/core/error/renderererror.d.ts +0 -26
- package/dist/core/error/renderererror.d.ts.map +0 -1
- package/dist/core/error/renderererror.js +0 -40
- package/dist/core/error/renderererror.js.map +0 -1
- package/dist/core/error/samcanerror.d.ts +0 -72
- package/dist/core/error/samcanerror.d.ts.map +0 -1
- package/dist/core/error/samcanerror.js +0 -108
- package/dist/core/error/samcanerror.js.map +0 -1
- package/dist/core/error/serializationerror.d.ts +0 -31
- package/dist/core/error/serializationerror.d.ts.map +0 -1
- package/dist/core/error/serializationerror.js +0 -46
- package/dist/core/error/serializationerror.js.map +0 -1
- package/dist/core/index.d.ts +0 -12
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -12
- package/dist/core/index.js.map +0 -1
- package/dist/core/math/color.d.ts +0 -56
- package/dist/core/math/color.d.ts.map +0 -1
- package/dist/core/math/color.js +0 -125
- package/dist/core/math/color.js.map +0 -1
- package/dist/core/math/index.d.ts +0 -14
- package/dist/core/math/index.d.ts.map +0 -1
- package/dist/core/math/index.js +0 -14
- package/dist/core/math/index.js.map +0 -1
- package/dist/core/math/matrix.d.ts +0 -101
- package/dist/core/math/matrix.d.ts.map +0 -1
- package/dist/core/math/matrix.js +0 -177
- package/dist/core/math/matrix.js.map +0 -1
- package/dist/core/math/paint.d.ts +0 -104
- package/dist/core/math/paint.d.ts.map +0 -1
- package/dist/core/math/paint.js +0 -204
- package/dist/core/math/paint.js.map +0 -1
- package/dist/core/math/path/index.d.ts +0 -94
- package/dist/core/math/path/index.d.ts.map +0 -1
- package/dist/core/math/path/index.js +0 -180
- package/dist/core/math/path/index.js.map +0 -1
- package/dist/core/math/path/operations.d.ts +0 -38
- package/dist/core/math/path/operations.d.ts.map +0 -1
- package/dist/core/math/path/operations.js +0 -149
- package/dist/core/math/path/operations.js.map +0 -1
- package/dist/core/math/pool.d.ts +0 -54
- package/dist/core/math/pool.d.ts.map +0 -1
- package/dist/core/math/pool.js +0 -97
- package/dist/core/math/pool.js.map +0 -1
- package/dist/core/math/pools.d.ts +0 -29
- package/dist/core/math/pools.d.ts.map +0 -1
- package/dist/core/math/pools.js +0 -50
- package/dist/core/math/pools.js.map +0 -1
- package/dist/core/math/rectangle.d.ts +0 -68
- package/dist/core/math/rectangle.d.ts.map +0 -1
- package/dist/core/math/rectangle.js +0 -124
- package/dist/core/math/rectangle.js.map +0 -1
- package/dist/core/math/utils.d.ts +0 -68
- package/dist/core/math/utils.d.ts.map +0 -1
- package/dist/core/math/utils.js +0 -110
- package/dist/core/math/utils.js.map +0 -1
- package/dist/core/math/vector2.d.ts +0 -85
- package/dist/core/math/vector2.d.ts.map +0 -1
- package/dist/core/math/vector2.js +0 -134
- package/dist/core/math/vector2.js.map +0 -1
- package/dist/core/plugin/animationcontroller.d.ts +0 -43
- package/dist/core/plugin/animationcontroller.d.ts.map +0 -1
- package/dist/core/plugin/animationcontroller.js +0 -11
- package/dist/core/plugin/animationcontroller.js.map +0 -1
- package/dist/core/plugin/index.d.ts +0 -6
- package/dist/core/plugin/index.d.ts.map +0 -1
- package/dist/core/plugin/index.js +0 -4
- package/dist/core/plugin/index.js.map +0 -1
- package/dist/core/plugin/plugin.d.ts +0 -53
- package/dist/core/plugin/plugin.d.ts.map +0 -1
- package/dist/core/plugin/plugin.js +0 -29
- package/dist/core/plugin/plugin.js.map +0 -1
- package/dist/core/plugin/pluginregistry.d.ts +0 -71
- package/dist/core/plugin/pluginregistry.d.ts.map +0 -1
- package/dist/core/plugin/pluginregistry.js +0 -143
- package/dist/core/plugin/pluginregistry.js.map +0 -1
- package/dist/core/renderer/batchmanager.d.ts +0 -68
- package/dist/core/renderer/batchmanager.d.ts.map +0 -1
- package/dist/core/renderer/batchmanager.js +0 -82
- package/dist/core/renderer/batchmanager.js.map +0 -1
- package/dist/core/renderer/canvas2drenderer.d.ts +0 -139
- package/dist/core/renderer/canvas2drenderer.d.ts.map +0 -1
- package/dist/core/renderer/canvas2drenderer.js +0 -499
- package/dist/core/renderer/canvas2drenderer.js.map +0 -1
- package/dist/core/renderer/dirtyregionmanager.d.ts +0 -54
- package/dist/core/renderer/dirtyregionmanager.d.ts.map +0 -1
- package/dist/core/renderer/dirtyregionmanager.js +0 -129
- package/dist/core/renderer/dirtyregionmanager.js.map +0 -1
- package/dist/core/renderer/index.d.ts +0 -8
- package/dist/core/renderer/index.d.ts.map +0 -1
- package/dist/core/renderer/index.js +0 -6
- package/dist/core/renderer/index.js.map +0 -1
- package/dist/core/renderer/renderer.d.ts +0 -154
- package/dist/core/renderer/renderer.d.ts.map +0 -1
- package/dist/core/renderer/renderer.js +0 -1
- package/dist/core/renderer/renderer.js.map +0 -1
- package/dist/core/renderer/rendererfactory.d.ts +0 -66
- package/dist/core/renderer/rendererfactory.d.ts.map +0 -1
- package/dist/core/renderer/rendererfactory.js +0 -219
- package/dist/core/renderer/rendererfactory.js.map +0 -1
- package/dist/core/renderer/webglrenderer.d.ts +0 -185
- package/dist/core/renderer/webglrenderer.d.ts.map +0 -1
- package/dist/core/renderer/webglrenderer.js +0 -1007
- package/dist/core/renderer/webglrenderer.js.map +0 -1
- package/dist/core/scene/index.d.ts +0 -4
- package/dist/core/scene/index.d.ts.map +0 -1
- package/dist/core/scene/index.js +0 -4
- package/dist/core/scene/index.js.map +0 -1
- package/dist/core/scene/node.d.ts +0 -162
- package/dist/core/scene/node.d.ts.map +0 -1
- package/dist/core/scene/node.js +0 -402
- package/dist/core/scene/node.js.map +0 -1
- package/dist/core/scene/nodes/artboard.d.ts +0 -42
- package/dist/core/scene/nodes/artboard.d.ts.map +0 -1
- package/dist/core/scene/nodes/artboard.js +0 -64
- package/dist/core/scene/nodes/artboard.js.map +0 -1
- package/dist/core/scene/nodes/groupnode.d.ts +0 -10
- package/dist/core/scene/nodes/groupnode.d.ts.map +0 -1
- package/dist/core/scene/nodes/groupnode.js +0 -12
- package/dist/core/scene/nodes/groupnode.js.map +0 -1
- package/dist/core/scene/nodes/imagenode.d.ts +0 -38
- package/dist/core/scene/nodes/imagenode.d.ts.map +0 -1
- package/dist/core/scene/nodes/imagenode.js +0 -77
- package/dist/core/scene/nodes/imagenode.js.map +0 -1
- package/dist/core/scene/nodes/index.d.ts +0 -5
- package/dist/core/scene/nodes/index.d.ts.map +0 -1
- package/dist/core/scene/nodes/index.js +0 -5
- package/dist/core/scene/nodes/index.js.map +0 -1
- package/dist/core/scene/nodes/shapenode.d.ts +0 -76
- package/dist/core/scene/nodes/shapenode.d.ts.map +0 -1
- package/dist/core/scene/nodes/shapenode.js +0 -212
- package/dist/core/scene/nodes/shapenode.js.map +0 -1
- package/dist/core/scene/transform.d.ts +0 -27
- package/dist/core/scene/transform.d.ts.map +0 -1
- package/dist/core/scene/transform.js +0 -52
- package/dist/core/scene/transform.js.map +0 -1
- package/dist/core/serialization/index.d.ts +0 -3
- package/dist/core/serialization/index.d.ts.map +0 -1
- package/dist/core/serialization/index.js +0 -2
- package/dist/core/serialization/index.js.map +0 -1
- package/dist/core/serialization/serializer.d.ts +0 -323
- package/dist/core/serialization/serializer.d.ts.map +0 -1
- package/dist/core/serialization/serializer.js +0 -1173
- package/dist/core/serialization/serializer.js.map +0 -1
- package/dist/core/serialization/types.d.ts +0 -242
- package/dist/core/serialization/types.d.ts.map +0 -1
- package/dist/core/serialization/types.js +0 -1
- package/dist/core/serialization/types.js.map +0 -1
- package/dist/core/timing/clock.d.ts +0 -43
- package/dist/core/timing/clock.d.ts.map +0 -1
- package/dist/core/timing/clock.js +0 -78
- package/dist/core/timing/clock.js.map +0 -1
- package/dist/core/timing/index.d.ts +0 -3
- package/dist/core/timing/index.d.ts.map +0 -1
- package/dist/core/timing/index.js +0 -3
- package/dist/core/timing/index.js.map +0 -1
- package/dist/core/timing/scheduler.d.ts +0 -72
- package/dist/core/timing/scheduler.d.ts.map +0 -1
- package/dist/core/timing/scheduler.js +0 -163
- package/dist/core/timing/scheduler.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/wrapper/react/index.d.ts +0 -5
- package/dist/wrapper/react/index.d.ts.map +0 -1
- package/dist/wrapper/react/index.js +0 -3
- package/dist/wrapper/react/index.js.map +0 -1
- package/dist/wrapper/react/samcan-player.d.ts +0 -26
- package/dist/wrapper/react/samcan-player.d.ts.map +0 -1
- package/dist/wrapper/react/samcan-player.js +0 -19
- package/dist/wrapper/react/samcan-player.js.map +0 -1
- package/dist/wrapper/react/use-samcan-player.d.ts +0 -33
- package/dist/wrapper/react/use-samcan-player.d.ts.map +0 -1
- package/dist/wrapper/react/use-samcan-player.js +0 -65
- package/dist/wrapper/react/use-samcan-player.js.map +0 -1
- package/readme.md +0 -96
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// camera/camera.ts
|
|
2
|
+
function create_camera(x = 0, y = 0, zoom = 1, rotation = 0) {
|
|
3
|
+
return [x, y, zoom, rotation];
|
|
4
|
+
}
|
|
5
|
+
function clone_camera(c) {
|
|
6
|
+
return [c[0], c[1], c[2], c[3]];
|
|
7
|
+
}
|
|
8
|
+
function copy_camera(c, out) {
|
|
9
|
+
out[0] = c[0];
|
|
10
|
+
out[1] = c[1];
|
|
11
|
+
out[2] = c[2];
|
|
12
|
+
out[3] = c[3];
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function set_camera(x, y, zoom, rotation, out) {
|
|
16
|
+
out[0] = x;
|
|
17
|
+
out[1] = y;
|
|
18
|
+
out[2] = zoom;
|
|
19
|
+
out[3] = rotation;
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
function x_of_camera(c) {
|
|
23
|
+
return c[0];
|
|
24
|
+
}
|
|
25
|
+
function y_of_camera(c) {
|
|
26
|
+
return c[1];
|
|
27
|
+
}
|
|
28
|
+
function zoom_of_camera(c) {
|
|
29
|
+
return c[2];
|
|
30
|
+
}
|
|
31
|
+
function rotation_of_camera(c) {
|
|
32
|
+
return c[3];
|
|
33
|
+
}
|
|
34
|
+
function position_of_camera(c, out) {
|
|
35
|
+
out[0] = c[0];
|
|
36
|
+
out[1] = c[1];
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function pan_camera(c, dx, dy, out) {
|
|
40
|
+
out[0] = c[0] + dx;
|
|
41
|
+
out[1] = c[1] + dy;
|
|
42
|
+
out[2] = c[2];
|
|
43
|
+
out[3] = c[3];
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function zoom_camera(c, factor, out) {
|
|
47
|
+
out[0] = c[0];
|
|
48
|
+
out[1] = c[1];
|
|
49
|
+
out[2] = c[2] * factor;
|
|
50
|
+
out[3] = c[3];
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function zoom_at_camera(c, factor, anchor, out) {
|
|
54
|
+
const world_dx = anchor.world_x - c[0];
|
|
55
|
+
const world_dy = anchor.world_y - c[1];
|
|
56
|
+
const new_zoom = c[2] * factor;
|
|
57
|
+
const new_world_x = anchor.world_x - world_dx / factor;
|
|
58
|
+
const new_world_y = anchor.world_y - world_dy / factor;
|
|
59
|
+
out[0] = new_world_x;
|
|
60
|
+
out[1] = new_world_y;
|
|
61
|
+
out[2] = new_zoom;
|
|
62
|
+
out[3] = c[3];
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
function rotate_camera(c, angle, out) {
|
|
66
|
+
out[0] = c[0];
|
|
67
|
+
out[1] = c[1];
|
|
68
|
+
out[2] = c[2];
|
|
69
|
+
out[3] = c[3] + angle;
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function clamp_camera(c, limits, out) {
|
|
73
|
+
const clamped_zoom = Math.max(limits.min_zoom, Math.min(limits.max_zoom, c[2]));
|
|
74
|
+
const clamped_x = Math.max(limits.min_x, Math.min(limits.max_x, c[0]));
|
|
75
|
+
const clamped_y = Math.max(limits.min_y, Math.min(limits.max_y, c[1]));
|
|
76
|
+
out[0] = clamped_x;
|
|
77
|
+
out[1] = clamped_y;
|
|
78
|
+
out[2] = clamped_zoom;
|
|
79
|
+
out[3] = c[3];
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
function lerp_camera(a, b, t, out) {
|
|
83
|
+
const clamped_t = Math.max(0, Math.min(1, t));
|
|
84
|
+
out[0] = a[0] + clamped_t * (b[0] - a[0]);
|
|
85
|
+
out[1] = a[1] + clamped_t * (b[1] - a[1]);
|
|
86
|
+
out[2] = a[2] + clamped_t * (b[2] - a[2]);
|
|
87
|
+
let rotation_diff = b[3] - a[3];
|
|
88
|
+
while (rotation_diff > Math.PI) {
|
|
89
|
+
rotation_diff = rotation_diff - 2 * Math.PI;
|
|
90
|
+
}
|
|
91
|
+
while (rotation_diff < -Math.PI) {
|
|
92
|
+
rotation_diff = rotation_diff + 2 * Math.PI;
|
|
93
|
+
}
|
|
94
|
+
out[3] = a[3] + clamped_t * rotation_diff;
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
function smooth_damp_camera(current, target, velocity, smooth_time, delta_time, out) {
|
|
98
|
+
const omega = 2 / Math.max(0.0001, smooth_time);
|
|
99
|
+
const x = omega * delta_time;
|
|
100
|
+
const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x);
|
|
101
|
+
const delta_x = current[0] - target[0];
|
|
102
|
+
const delta_y = current[1] - target[1];
|
|
103
|
+
const delta_zoom = current[2] - target[2];
|
|
104
|
+
let rotation_diff = target[3] - current[3];
|
|
105
|
+
while (rotation_diff > Math.PI) {
|
|
106
|
+
rotation_diff = rotation_diff - 2 * Math.PI;
|
|
107
|
+
}
|
|
108
|
+
while (rotation_diff < -Math.PI) {
|
|
109
|
+
rotation_diff = rotation_diff + 2 * Math.PI;
|
|
110
|
+
}
|
|
111
|
+
const delta_rotation = -rotation_diff;
|
|
112
|
+
const temp_x = (velocity[0] + omega * delta_x) * delta_time;
|
|
113
|
+
const temp_y = (velocity[1] + omega * delta_y) * delta_time;
|
|
114
|
+
const temp_zoom = (velocity[2] + omega * delta_zoom) * delta_time;
|
|
115
|
+
const temp_rotation = (velocity[3] + omega * delta_rotation) * delta_time;
|
|
116
|
+
const new_velocity_x = (velocity[0] - omega * temp_x) * exp;
|
|
117
|
+
const new_velocity_y = (velocity[1] - omega * temp_y) * exp;
|
|
118
|
+
const new_velocity_zoom = (velocity[2] - omega * temp_zoom) * exp;
|
|
119
|
+
const new_velocity_rotation = (velocity[3] - omega * temp_rotation) * exp;
|
|
120
|
+
velocity[0] = new_velocity_x;
|
|
121
|
+
velocity[1] = new_velocity_y;
|
|
122
|
+
velocity[2] = new_velocity_zoom;
|
|
123
|
+
velocity[3] = new_velocity_rotation;
|
|
124
|
+
const result_x = target[0] + (delta_x + temp_x) * exp;
|
|
125
|
+
const result_y = target[1] + (delta_y + temp_y) * exp;
|
|
126
|
+
const result_zoom = target[2] + (delta_zoom + temp_zoom) * exp;
|
|
127
|
+
const result_rotation = target[3] + (delta_rotation + temp_rotation) * exp;
|
|
128
|
+
out[0] = result_x;
|
|
129
|
+
out[1] = result_y;
|
|
130
|
+
out[2] = result_zoom;
|
|
131
|
+
out[3] = result_rotation;
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
function equals_camera(c1, c2, epsilon = 0.0001) {
|
|
135
|
+
return Math.abs(c1[0] - c2[0]) < epsilon && Math.abs(c1[1] - c2[1]) < epsilon && Math.abs(c1[2] - c2[2]) < epsilon && Math.abs(c1[3] - c2[3]) < epsilon;
|
|
136
|
+
}
|
|
137
|
+
function is_identity_camera(c) {
|
|
138
|
+
return c[0] === 0 && c[1] === 0 && c[2] === 1 && c[3] === 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// camera/projection.ts
|
|
142
|
+
function world_to_screen_camera(c, v, world_pos, out) {
|
|
143
|
+
const dx = world_pos[0] - c[0];
|
|
144
|
+
const dy = world_pos[1] - c[1];
|
|
145
|
+
const cos_r = Math.cos(c[3]);
|
|
146
|
+
const sin_r = Math.sin(c[3]);
|
|
147
|
+
const rotated_x = dx * cos_r - dy * sin_r;
|
|
148
|
+
const rotated_y = dx * sin_r + dy * cos_r;
|
|
149
|
+
const screen_x = rotated_x * c[2] + v[0] / 2;
|
|
150
|
+
const screen_y = rotated_y * c[2] + v[1] / 2;
|
|
151
|
+
out[0] = screen_x;
|
|
152
|
+
out[1] = screen_y;
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
function screen_to_world_camera(c, v, screen_pos, out) {
|
|
156
|
+
if (c[2] <= 0) {
|
|
157
|
+
out[0] = c[0];
|
|
158
|
+
out[1] = c[1];
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
const dx = screen_pos[0] - v[0] / 2;
|
|
162
|
+
const dy = screen_pos[1] - v[1] / 2;
|
|
163
|
+
const cos_r = Math.cos(-c[3]);
|
|
164
|
+
const sin_r = Math.sin(-c[3]);
|
|
165
|
+
const scaled_x = dx / c[2];
|
|
166
|
+
const scaled_y = dy / c[2];
|
|
167
|
+
const rotated_x = scaled_x * cos_r - scaled_y * sin_r;
|
|
168
|
+
const rotated_y = scaled_x * sin_r + scaled_y * cos_r;
|
|
169
|
+
out[0] = rotated_x + c[0];
|
|
170
|
+
out[1] = rotated_y + c[1];
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
function view_transform_camera(c, out) {
|
|
174
|
+
const cos_r = Math.cos(c[3]);
|
|
175
|
+
const sin_r = Math.sin(c[3]);
|
|
176
|
+
out[0] = cos_r * c[2];
|
|
177
|
+
out[1] = sin_r * c[2];
|
|
178
|
+
out[2] = -sin_r * c[2];
|
|
179
|
+
out[3] = cos_r * c[2];
|
|
180
|
+
out[4] = -c[0] * cos_r * c[2] + c[1] * sin_r * c[2];
|
|
181
|
+
out[5] = -c[0] * sin_r * c[2] - c[1] * cos_r * c[2];
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function inverse_view_transform_camera(c, out) {
|
|
185
|
+
const cos_r = Math.cos(c[3]);
|
|
186
|
+
const sin_r = Math.sin(c[3]);
|
|
187
|
+
const safe_zoom = c[2] <= 0 ? 0.0001 : c[2];
|
|
188
|
+
const inverse_zoom = 1 / safe_zoom;
|
|
189
|
+
out[0] = cos_r * inverse_zoom;
|
|
190
|
+
out[1] = -sin_r * inverse_zoom;
|
|
191
|
+
out[2] = sin_r * inverse_zoom;
|
|
192
|
+
out[3] = cos_r * inverse_zoom;
|
|
193
|
+
out[4] = c[0];
|
|
194
|
+
out[5] = c[1];
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
function camera_frustum(c, v, out) {
|
|
198
|
+
if (c[2] <= 0) {
|
|
199
|
+
out[0] = c[0];
|
|
200
|
+
out[1] = c[0];
|
|
201
|
+
out[2] = c[1];
|
|
202
|
+
out[3] = c[1];
|
|
203
|
+
out[4] = 0;
|
|
204
|
+
out[5] = Number.MAX_VALUE;
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
const half_width = v[0] / (2 * c[2]);
|
|
208
|
+
const half_height = v[1] / (2 * c[2]);
|
|
209
|
+
if (c[3] === 0) {
|
|
210
|
+
out[0] = c[0] - half_width;
|
|
211
|
+
out[1] = c[0] + half_width;
|
|
212
|
+
out[2] = c[1] + half_height;
|
|
213
|
+
out[3] = c[1] - half_height;
|
|
214
|
+
out[4] = 0;
|
|
215
|
+
out[5] = Number.MAX_VALUE;
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
const cos_r = Math.abs(Math.cos(c[3]));
|
|
219
|
+
const sin_r = Math.abs(Math.sin(c[3]));
|
|
220
|
+
const x_extent = half_width * cos_r + half_height * sin_r;
|
|
221
|
+
const y_extent = half_width * sin_r + half_height * cos_r;
|
|
222
|
+
out[0] = c[0] - x_extent;
|
|
223
|
+
out[1] = c[0] + x_extent;
|
|
224
|
+
out[2] = c[1] + y_extent;
|
|
225
|
+
out[3] = c[1] - y_extent;
|
|
226
|
+
out[4] = 0;
|
|
227
|
+
out[5] = Number.MAX_VALUE;
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
function fit_camera_to_bounds(bounds, v, margin = 0.1, out) {
|
|
231
|
+
const bounds_width = bounds[2];
|
|
232
|
+
const bounds_height = bounds[3];
|
|
233
|
+
if (bounds_width <= 0 || bounds_height <= 0) {
|
|
234
|
+
out[0] = bounds[0];
|
|
235
|
+
out[1] = bounds[1];
|
|
236
|
+
out[2] = 1;
|
|
237
|
+
out[3] = 0;
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
const viewport_width = v[0] * (1 - margin * 2);
|
|
241
|
+
const viewport_height = v[1] * (1 - margin * 2);
|
|
242
|
+
if (viewport_width <= 0 || viewport_height <= 0) {
|
|
243
|
+
out[0] = bounds[0] + bounds_width / 2;
|
|
244
|
+
out[1] = bounds[1] + bounds_height / 2;
|
|
245
|
+
out[2] = 1;
|
|
246
|
+
out[3] = 0;
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
const zoom_x = viewport_width / bounds_width;
|
|
250
|
+
const zoom_y = viewport_height / bounds_height;
|
|
251
|
+
const zoom = Math.min(zoom_x, zoom_y);
|
|
252
|
+
const center_x = bounds[0] + bounds_width / 2;
|
|
253
|
+
const center_y = bounds[1] + bounds_height / 2;
|
|
254
|
+
out[0] = center_x;
|
|
255
|
+
out[1] = center_y;
|
|
256
|
+
out[2] = zoom;
|
|
257
|
+
out[3] = 0;
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
function contains_point_camera_frustum(c, v, world_x, world_y) {
|
|
261
|
+
const dx = world_x - c[0];
|
|
262
|
+
const dy = world_y - c[1];
|
|
263
|
+
const cos_r = Math.cos(-c[3]);
|
|
264
|
+
const sin_r = Math.sin(-c[3]);
|
|
265
|
+
const rotated_x = dx * cos_r - dy * sin_r;
|
|
266
|
+
const rotated_y = dx * sin_r + dy * cos_r;
|
|
267
|
+
const scaled_x = rotated_x * c[2];
|
|
268
|
+
const scaled_y = rotated_y * c[2];
|
|
269
|
+
const half_width = v[0] / 2;
|
|
270
|
+
const half_height = v[1] / 2;
|
|
271
|
+
return scaled_x >= -half_width && scaled_x <= half_width && scaled_y >= -half_height && scaled_y <= half_height;
|
|
272
|
+
}
|
|
273
|
+
function width_of_camera_world(c, v) {
|
|
274
|
+
const safe_zoom = c[2] <= 0 ? 0.0001 : c[2];
|
|
275
|
+
return v[0] / safe_zoom;
|
|
276
|
+
}
|
|
277
|
+
function height_of_camera_world(c, v) {
|
|
278
|
+
const safe_zoom = c[2] <= 0 ? 0.0001 : c[2];
|
|
279
|
+
return v[1] / safe_zoom;
|
|
280
|
+
}
|
|
281
|
+
function pixel_size_of_camera(c) {
|
|
282
|
+
const safe_zoom = c[2] <= 0 ? 0.0001 : c[2];
|
|
283
|
+
return 1 / safe_zoom;
|
|
284
|
+
}
|
|
285
|
+
function pixel_ratio_of_viewport(v) {
|
|
286
|
+
return v[2];
|
|
287
|
+
}
|
|
288
|
+
function device_width_of_viewport(v) {
|
|
289
|
+
return v[0] * v[2];
|
|
290
|
+
}
|
|
291
|
+
function device_height_of_viewport(v) {
|
|
292
|
+
return v[1] * v[2];
|
|
293
|
+
}
|
|
294
|
+
function world_to_device_camera(c, v, world_pos, out) {
|
|
295
|
+
world_to_screen_camera(c, v, world_pos, out);
|
|
296
|
+
out[0] = out[0] * v[2];
|
|
297
|
+
out[1] = out[1] * v[2];
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
function device_to_world_camera(c, v, device_pos, out) {
|
|
301
|
+
const screen_pos = [device_pos[0] / v[2], device_pos[1] / v[2]];
|
|
302
|
+
return screen_to_world_camera(c, v, screen_pos, out);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { create_camera, clone_camera, copy_camera, set_camera, x_of_camera, y_of_camera, zoom_of_camera, rotation_of_camera, position_of_camera, pan_camera, zoom_camera, zoom_at_camera, rotate_camera, clamp_camera, lerp_camera, smooth_damp_camera, equals_camera, is_identity_camera, world_to_screen_camera, screen_to_world_camera, view_transform_camera, inverse_view_transform_camera, camera_frustum, fit_camera_to_bounds, contains_point_camera_frustum, width_of_camera_world, height_of_camera_world, pixel_size_of_camera, pixel_ratio_of_viewport, device_width_of_viewport, device_height_of_viewport, world_to_device_camera, device_to_world_camera };
|