3d-spinner 0.9.2 → 0.9.3
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/README.md +66 -4
- package/dist/animation-label.d.ts +8 -0
- package/dist/animation-label.js +47 -0
- package/dist/animation.d.ts +2 -0
- package/dist/animations/charged-orb.d.ts +55 -0
- package/dist/animations/charged-orb.js +229 -0
- package/dist/animations/grid-assembly.d.ts +67 -0
- package/dist/animations/grid-assembly.js +268 -0
- package/dist/animations/object-motion.d.ts +19 -7
- package/dist/animations/object-motion.js +38 -32
- package/dist/animations/particles.d.ts +110 -0
- package/dist/animations/particles.js +209 -0
- package/dist/cjs/animations/charged-orb.cjs +1334 -0
- package/dist/cjs/animations/grid-assembly.cjs +1498 -0
- package/dist/cjs/animations/object-motion.cjs +124 -43
- package/dist/cjs/animations/particles.cjs +1940 -0
- package/dist/cjs/animations/spin.cjs +4 -3
- package/dist/cjs/composite-animation.cjs +58 -0
- package/dist/cjs/engines/little-3d-engine/little-3d-engine.cjs +131 -22
- package/dist/cjs/engines/little-3d-engine/loaders/obj.cjs +30 -1
- package/dist/cjs/engines/little-3d-engine/renderers/canvas2d-textured.cjs +345 -0
- package/dist/cjs/engines/little-3d-engine/renderers/webgl-textured.cjs +528 -0
- package/dist/cjs/engines/little-3d-engine/renderers/webgpu-textured.cjs +712 -0
- package/dist/cjs/prefabs/prefabs.cjs +3450 -0
- package/dist/composite-animation.d.ts +18 -0
- package/dist/composite-animation.js +39 -0
- package/dist/engines/little-3d-engine/little-3d-engine.d.ts +17 -12
- package/dist/engines/little-3d-engine/little-3d-engine.js +13 -8
- package/dist/engines/little-3d-engine/loaders/obj.d.ts +12 -4
- package/dist/engines/little-3d-engine/loaders/obj.js +44 -5
- package/dist/engines/little-3d-engine/renderer.d.ts +7 -1
- package/dist/engines/little-3d-engine/renderer.js +2 -0
- package/dist/engines/little-3d-engine/renderers/canvas2d-textured.d.ts +20 -0
- package/dist/engines/little-3d-engine/renderers/canvas2d-textured.js +135 -0
- package/dist/engines/little-3d-engine/renderers/textured-helpers.d.ts +9 -0
- package/dist/engines/little-3d-engine/renderers/textured-helpers.js +35 -0
- package/dist/engines/little-3d-engine/renderers/webgl-textured.d.ts +43 -0
- package/dist/engines/little-3d-engine/renderers/webgl-textured.js +211 -0
- package/dist/engines/little-3d-engine/renderers/webgpu-textured.d.ts +45 -0
- package/dist/engines/little-3d-engine/renderers/webgpu-textured.js +300 -0
- package/dist/engines/little-3d-engine/renderers/webgpu.d.ts +11 -6
- package/dist/engines/little-3d-engine/shapes/complex/plane.d.ts +3 -0
- package/dist/engines/little-3d-engine/shapes/complex/plane.js +33 -0
- package/dist/engines/little-3d-engine/shapes/{cube.d.ts → primitives/cube.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/{octahedron.d.ts → primitives/octahedron.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/{pyramid.d.ts → primitives/pyramid.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/primitives/quad.d.ts +9 -0
- package/dist/engines/little-3d-engine/shapes/primitives/quad.js +18 -0
- package/dist/engines/little-3d-engine/shapes/{cube-sphere.d.ts → primitives/spheres/cube-sphere.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/{icosphere.d.ts → primitives/spheres/icosphere.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/{icosphere.js → primitives/spheres/icosphere.js} +1 -1
- package/dist/engines/little-3d-engine/shapes/{octa-sphere.d.ts → primitives/spheres/octa-sphere.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/{octa-sphere.js → primitives/spheres/octa-sphere.js} +1 -1
- package/dist/engines/little-3d-engine/shapes/{uv-sphere.d.ts → primitives/spheres/uv-sphere.d.ts} +1 -1
- package/dist/engines/little-3d-engine/shapes/{tetrahedron.d.ts → primitives/tetrahedron.d.ts} +1 -1
- package/dist/engines/little-3d-engine/textures/dynamic/canvas-texture.d.ts +1 -0
- package/dist/engines/little-3d-engine/textures/dynamic/canvas-texture.js +8 -0
- package/dist/engines/little-3d-engine/textures/dynamic/shine.d.ts +2 -0
- package/dist/engines/little-3d-engine/textures/dynamic/shine.js +14 -0
- package/dist/engines/little-3d-engine/textures/dynamic/star.d.ts +2 -0
- package/dist/engines/little-3d-engine/textures/dynamic/star.js +16 -0
- package/dist/engines/little-3d-engine/textures/dynamic/streak.d.ts +5 -0
- package/dist/engines/little-3d-engine/textures/dynamic/streak.js +20 -0
- package/dist/index.d.ts +2 -1
- package/dist/prefabs/charged-orb.d.ts +17 -0
- package/dist/prefabs/charged-orb.js +37 -0
- package/dist/prefabs/crystal-comet.d.ts +4 -0
- package/dist/prefabs/crystal-comet.js +41 -0
- package/dist/prefabs/ghost-train.d.ts +9 -0
- package/dist/prefabs/ghost-train.js +44 -0
- package/dist/prefabs/grid-assembly.d.ts +13 -0
- package/dist/prefabs/grid-assembly.js +15 -0
- package/dist/prefabs/monochrome-streak.d.ts +4 -0
- package/dist/prefabs/monochrome-streak.js +25 -0
- package/dist/prefabs/plane-star-trail.d.ts +4 -0
- package/dist/prefabs/plane-star-trail.js +40 -0
- package/dist/prefabs/prefabs.d.ts +10 -0
- package/dist/prefabs/prefabs.js +9 -0
- package/dist/prefabs/pulsing-starfield.d.ts +4 -0
- package/dist/prefabs/pulsing-starfield.js +27 -0
- package/dist/prefabs/rocket-launch.d.ts +8 -0
- package/dist/prefabs/rocket-launch.js +59 -0
- package/dist/prefabs/spinner.d.ts +7 -0
- package/dist/prefabs/spinner.js +17 -0
- package/dist/prefabs/star-swarm.d.ts +4 -0
- package/dist/prefabs/star-swarm.js +27 -0
- package/dist/prefabs/types.d.ts +46 -0
- package/dist/prefabs/types.js +1 -0
- package/dist/umd/spinner.global.js +3055 -1251
- package/dist/umd/spinner.global.min.js +60 -5
- package/package.json +42 -1
- /package/dist/engines/little-3d-engine/shapes/{cube.js → primitives/cube.js} +0 -0
- /package/dist/engines/little-3d-engine/shapes/{octahedron.js → primitives/octahedron.js} +0 -0
- /package/dist/engines/little-3d-engine/shapes/{pyramid.js → primitives/pyramid.js} +0 -0
- /package/dist/engines/little-3d-engine/shapes/{cube-sphere.js → primitives/spheres/cube-sphere.js} +0 -0
- /package/dist/engines/little-3d-engine/shapes/{uv-sphere.js → primitives/spheres/uv-sphere.js} +0 -0
- /package/dist/engines/little-3d-engine/shapes/{tetrahedron.js → primitives/tetrahedron.js} +0 -0
|
@@ -797,6 +797,7 @@ function orderRenderItems(items, eye) {
|
|
|
797
797
|
return opaque.concat(transparent);
|
|
798
798
|
}
|
|
799
799
|
async function createRenderer(backend, options = {}) {
|
|
800
|
+
if (typeof backend === "function") return backend(options);
|
|
800
801
|
switch (backend) {
|
|
801
802
|
case "webgl":
|
|
802
803
|
return new (await Promise.resolve().then(() => (init_webgl(), webgl_exports))).WebGLRenderer(options);
|
|
@@ -874,7 +875,7 @@ function transform(init) {
|
|
|
874
875
|
init_renderer();
|
|
875
876
|
init_light();
|
|
876
877
|
|
|
877
|
-
// src/engines/little-3d-engine/shapes/cube.ts
|
|
878
|
+
// src/engines/little-3d-engine/shapes/primitives/cube.ts
|
|
878
879
|
var DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
879
880
|
function cube(size = 1, colors = DEFAULT_COLORS) {
|
|
880
881
|
const h = size / 2;
|
|
@@ -899,7 +900,7 @@ function cube(size = 1, colors = DEFAULT_COLORS) {
|
|
|
899
900
|
return { vertices, faces };
|
|
900
901
|
}
|
|
901
902
|
|
|
902
|
-
// src/engines/little-3d-engine/shapes/icosphere.ts
|
|
903
|
+
// src/engines/little-3d-engine/shapes/primitives/spheres/icosphere.ts
|
|
903
904
|
init_geometry();
|
|
904
905
|
var T = (1 + Math.sqrt(5)) / 2;
|
|
905
906
|
var SEED_VERTICES = [
|
|
@@ -917,7 +918,7 @@ var SEED_VERTICES = [
|
|
|
917
918
|
{ x: -T, y: 0, z: 1 }
|
|
918
919
|
];
|
|
919
920
|
|
|
920
|
-
// src/engines/little-3d-engine/shapes/octa-sphere.ts
|
|
921
|
+
// src/engines/little-3d-engine/shapes/primitives/spheres/octa-sphere.ts
|
|
921
922
|
init_geometry();
|
|
922
923
|
|
|
923
924
|
// src/engines/little-3d-engine/little-3d-engine.ts
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/composite-animation.ts
|
|
21
|
+
var composite_animation_exports = {};
|
|
22
|
+
__export(composite_animation_exports, {
|
|
23
|
+
CompositeAnimation: () => CompositeAnimation
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(composite_animation_exports);
|
|
26
|
+
var CompositeAnimation = class {
|
|
27
|
+
constructor(layers) {
|
|
28
|
+
this.elements = [];
|
|
29
|
+
this.layers = layers.map((layer) => "animation" in layer ? layer : { animation: layer });
|
|
30
|
+
}
|
|
31
|
+
mount(target) {
|
|
32
|
+
target.style.position = "relative";
|
|
33
|
+
for (const [index, layer] of this.layers.entries()) {
|
|
34
|
+
const element = document.createElement("div");
|
|
35
|
+
element.style.cssText = `position:absolute;inset:0;z-index:${layer.zIndex ?? index}`;
|
|
36
|
+
target.appendChild(element);
|
|
37
|
+
this.elements.push(element);
|
|
38
|
+
layer.animation.mount(element);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
enter(now) {
|
|
42
|
+
for (const layer of this.layers) layer.animation.enter(now);
|
|
43
|
+
}
|
|
44
|
+
exit(now) {
|
|
45
|
+
for (const layer of this.layers) layer.animation.exit(now);
|
|
46
|
+
}
|
|
47
|
+
render(now, frame) {
|
|
48
|
+
for (const layer of this.layers) layer.animation.render(now, frame);
|
|
49
|
+
}
|
|
50
|
+
isFinished() {
|
|
51
|
+
return this.layers.every((layer) => layer.animation.isFinished());
|
|
52
|
+
}
|
|
53
|
+
destroy() {
|
|
54
|
+
for (const layer of this.layers) layer.animation.destroy();
|
|
55
|
+
for (const element of this.elements) element.remove();
|
|
56
|
+
this.elements.length = 0;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -825,6 +825,7 @@ function orderRenderItems(items, eye) {
|
|
|
825
825
|
return opaque.concat(transparent);
|
|
826
826
|
}
|
|
827
827
|
async function createRenderer(backend, options = {}) {
|
|
828
|
+
if (typeof backend === "function") return backend(options);
|
|
828
829
|
switch (backend) {
|
|
829
830
|
case "webgl":
|
|
830
831
|
return new (await Promise.resolve().then(() => (init_webgl(), webgl_exports))).WebGLRenderer(options);
|
|
@@ -861,8 +862,13 @@ __export(little_3d_engine_exports, {
|
|
|
861
862
|
octaSphere: () => octaSphere,
|
|
862
863
|
octahedron: () => octahedron,
|
|
863
864
|
orderRenderItems: () => orderRenderItems,
|
|
865
|
+
planeMesh: () => planeMesh,
|
|
864
866
|
pyramid: () => pyramid,
|
|
867
|
+
quad: () => quad,
|
|
865
868
|
scale: () => scale,
|
|
869
|
+
shineTexture: () => shineTexture,
|
|
870
|
+
starTexture: () => starTexture,
|
|
871
|
+
streakTexture: () => streakTexture,
|
|
866
872
|
subtract: () => subtract,
|
|
867
873
|
tetrahedron: () => tetrahedron,
|
|
868
874
|
transform: () => transform,
|
|
@@ -921,7 +927,7 @@ function transform(init) {
|
|
|
921
927
|
init_renderer();
|
|
922
928
|
init_light();
|
|
923
929
|
|
|
924
|
-
// src/engines/little-3d-engine/shapes/cube.ts
|
|
930
|
+
// src/engines/little-3d-engine/shapes/primitives/cube.ts
|
|
925
931
|
var DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
926
932
|
function cube(size = 1, colors = DEFAULT_COLORS) {
|
|
927
933
|
const h = size / 2;
|
|
@@ -946,9 +952,22 @@ function cube(size = 1, colors = DEFAULT_COLORS) {
|
|
|
946
952
|
return { vertices, faces };
|
|
947
953
|
}
|
|
948
954
|
|
|
949
|
-
// src/engines/little-3d-engine/shapes/
|
|
950
|
-
var DEFAULT_COLORS2 = ["#3b82f6"
|
|
951
|
-
function
|
|
955
|
+
// src/engines/little-3d-engine/shapes/primitives/quad.ts
|
|
956
|
+
var DEFAULT_COLORS2 = ["#3b82f6"];
|
|
957
|
+
function quad(size = 1, colors = DEFAULT_COLORS2) {
|
|
958
|
+
const s = size / 2;
|
|
959
|
+
const vertices = [
|
|
960
|
+
{ x: -s, y: -s, z: 0 },
|
|
961
|
+
{ x: s, y: -s, z: 0 },
|
|
962
|
+
{ x: s, y: s, z: 0 },
|
|
963
|
+
{ x: -s, y: s, z: 0 }
|
|
964
|
+
];
|
|
965
|
+
return { vertices, faces: [{ indices: [0, 1, 2, 3], color: colors[0] }] };
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// src/engines/little-3d-engine/shapes/primitives/tetrahedron.ts
|
|
969
|
+
var DEFAULT_COLORS3 = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b"];
|
|
970
|
+
function tetrahedron(size = 1, colors = DEFAULT_COLORS3) {
|
|
952
971
|
const s = size / 2;
|
|
953
972
|
const vertices = [
|
|
954
973
|
{ x: s, y: s, z: s },
|
|
@@ -965,8 +984,8 @@ function tetrahedron(size = 1, colors = DEFAULT_COLORS2) {
|
|
|
965
984
|
return { vertices, faces };
|
|
966
985
|
}
|
|
967
986
|
|
|
968
|
-
// src/engines/little-3d-engine/shapes/octahedron.ts
|
|
969
|
-
var
|
|
987
|
+
// src/engines/little-3d-engine/shapes/primitives/octahedron.ts
|
|
988
|
+
var DEFAULT_COLORS4 = [
|
|
970
989
|
"#3b82f6",
|
|
971
990
|
"#8b5cf6",
|
|
972
991
|
"#ec4899",
|
|
@@ -976,7 +995,7 @@ var DEFAULT_COLORS3 = [
|
|
|
976
995
|
"#06b6d4",
|
|
977
996
|
"#eab308"
|
|
978
997
|
];
|
|
979
|
-
function octahedron(size = 1, colors =
|
|
998
|
+
function octahedron(size = 1, colors = DEFAULT_COLORS4) {
|
|
980
999
|
const r = size / 2;
|
|
981
1000
|
const vertices = [
|
|
982
1001
|
{ x: r, y: 0, z: 0 },
|
|
@@ -999,9 +1018,9 @@ function octahedron(size = 1, colors = DEFAULT_COLORS3) {
|
|
|
999
1018
|
return { vertices, faces };
|
|
1000
1019
|
}
|
|
1001
1020
|
|
|
1002
|
-
// src/engines/little-3d-engine/shapes/pyramid.ts
|
|
1003
|
-
var
|
|
1004
|
-
function pyramid(size = 1, colors =
|
|
1021
|
+
// src/engines/little-3d-engine/shapes/primitives/pyramid.ts
|
|
1022
|
+
var DEFAULT_COLORS5 = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981"];
|
|
1023
|
+
function pyramid(size = 1, colors = DEFAULT_COLORS5) {
|
|
1005
1024
|
const h = size / 2;
|
|
1006
1025
|
const vertices = [
|
|
1007
1026
|
{ x: -h, y: -h, z: h },
|
|
@@ -1020,9 +1039,9 @@ function pyramid(size = 1, colors = DEFAULT_COLORS4) {
|
|
|
1020
1039
|
return { vertices, faces };
|
|
1021
1040
|
}
|
|
1022
1041
|
|
|
1023
|
-
// src/engines/little-3d-engine/shapes/uv-sphere.ts
|
|
1024
|
-
var
|
|
1025
|
-
function uvSphere(size = 1, detail = 1, colors =
|
|
1042
|
+
// src/engines/little-3d-engine/shapes/primitives/spheres/uv-sphere.ts
|
|
1043
|
+
var DEFAULT_COLORS6 = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
1044
|
+
function uvSphere(size = 1, detail = 1, colors = DEFAULT_COLORS6) {
|
|
1026
1045
|
const r = size / 2;
|
|
1027
1046
|
const d = Math.max(1, Math.floor(detail));
|
|
1028
1047
|
const slices = Math.max(4, d * 4);
|
|
@@ -1064,9 +1083,9 @@ function uvSphere(size = 1, detail = 1, colors = DEFAULT_COLORS5) {
|
|
|
1064
1083
|
return { vertices, faces };
|
|
1065
1084
|
}
|
|
1066
1085
|
|
|
1067
|
-
// src/engines/little-3d-engine/shapes/icosphere.ts
|
|
1086
|
+
// src/engines/little-3d-engine/shapes/primitives/spheres/icosphere.ts
|
|
1068
1087
|
init_geometry();
|
|
1069
|
-
var
|
|
1088
|
+
var DEFAULT_COLORS7 = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
1070
1089
|
var T = (1 + Math.sqrt(5)) / 2;
|
|
1071
1090
|
var SEED_VERTICES = [
|
|
1072
1091
|
{ x: -1, y: T, z: 0 },
|
|
@@ -1104,13 +1123,13 @@ var SEED_FACES = [
|
|
|
1104
1123
|
[8, 6, 7],
|
|
1105
1124
|
[9, 8, 1]
|
|
1106
1125
|
];
|
|
1107
|
-
function icosphere(size = 1, detail = 1, colors =
|
|
1126
|
+
function icosphere(size = 1, detail = 1, colors = DEFAULT_COLORS7) {
|
|
1108
1127
|
return sphereFromTriangles(SEED_VERTICES, SEED_FACES, size, detail, colors);
|
|
1109
1128
|
}
|
|
1110
1129
|
|
|
1111
|
-
// src/engines/little-3d-engine/shapes/octa-sphere.ts
|
|
1130
|
+
// src/engines/little-3d-engine/shapes/primitives/spheres/octa-sphere.ts
|
|
1112
1131
|
init_geometry();
|
|
1113
|
-
var
|
|
1132
|
+
var DEFAULT_COLORS8 = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
1114
1133
|
var SEED_VERTICES2 = [
|
|
1115
1134
|
{ x: 1, y: 0, z: 0 },
|
|
1116
1135
|
{ x: -1, y: 0, z: 0 },
|
|
@@ -1129,12 +1148,12 @@ var SEED_FACES2 = [
|
|
|
1129
1148
|
[5, 3, 1],
|
|
1130
1149
|
[5, 0, 3]
|
|
1131
1150
|
];
|
|
1132
|
-
function octaSphere(size = 1, detail = 1, colors =
|
|
1151
|
+
function octaSphere(size = 1, detail = 1, colors = DEFAULT_COLORS8) {
|
|
1133
1152
|
return sphereFromTriangles(SEED_VERTICES2, SEED_FACES2, size, detail, colors);
|
|
1134
1153
|
}
|
|
1135
1154
|
|
|
1136
|
-
// src/engines/little-3d-engine/shapes/cube-sphere.ts
|
|
1137
|
-
var
|
|
1155
|
+
// src/engines/little-3d-engine/shapes/primitives/spheres/cube-sphere.ts
|
|
1156
|
+
var DEFAULT_COLORS9 = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
1138
1157
|
var CUBE_FACES = [
|
|
1139
1158
|
{ normal: [0, 0, 1], right: [1, 0, 0], up: [0, 1, 0] },
|
|
1140
1159
|
{ normal: [0, 0, -1], right: [-1, 0, 0], up: [0, 1, 0] },
|
|
@@ -1143,7 +1162,7 @@ var CUBE_FACES = [
|
|
|
1143
1162
|
{ normal: [0, 1, 0], right: [1, 0, 0], up: [0, 0, -1] },
|
|
1144
1163
|
{ normal: [0, -1, 0], right: [1, 0, 0], up: [0, 0, 1] }
|
|
1145
1164
|
];
|
|
1146
|
-
function cubeSphere(size = 1, detail = 1, colors =
|
|
1165
|
+
function cubeSphere(size = 1, detail = 1, colors = DEFAULT_COLORS9) {
|
|
1147
1166
|
const r = size / 2;
|
|
1148
1167
|
const n = Math.max(1, Math.floor(detail));
|
|
1149
1168
|
const vertices = [];
|
|
@@ -1175,6 +1194,96 @@ function cubeSphere(size = 1, detail = 1, colors = DEFAULT_COLORS8) {
|
|
|
1175
1194
|
return { vertices, faces };
|
|
1176
1195
|
}
|
|
1177
1196
|
|
|
1197
|
+
// src/engines/little-3d-engine/shapes/complex/plane.ts
|
|
1198
|
+
var DEFAULT_COLORS10 = ["#e0f2fe", "#7dd3fc", "#38bdf8", "#f8fafc"];
|
|
1199
|
+
function planeMesh(colors = DEFAULT_COLORS10) {
|
|
1200
|
+
return {
|
|
1201
|
+
vertices: [
|
|
1202
|
+
{ x: 0.9, y: 0, z: 0 },
|
|
1203
|
+
{ x: -0.2, y: 0, z: 0.82 },
|
|
1204
|
+
{ x: -0.55, y: 0, z: 0.16 },
|
|
1205
|
+
{ x: -0.72, y: 0, z: 0 },
|
|
1206
|
+
{ x: -0.55, y: 0, z: -0.16 },
|
|
1207
|
+
{ x: -0.2, y: 0, z: -0.82 },
|
|
1208
|
+
{ x: -0.08, y: 0.12, z: 0 },
|
|
1209
|
+
{ x: -0.08, y: -0.1, z: 0 },
|
|
1210
|
+
{ x: -0.52, y: 0.38, z: 0 }
|
|
1211
|
+
],
|
|
1212
|
+
faces: [
|
|
1213
|
+
{ indices: [6, 1, 0], color: colors[0] ?? DEFAULT_COLORS10[0] },
|
|
1214
|
+
{ indices: [6, 2, 1], color: colors[3] ?? DEFAULT_COLORS10[3] },
|
|
1215
|
+
{ indices: [6, 3, 2], color: colors[1] ?? DEFAULT_COLORS10[1] },
|
|
1216
|
+
{ indices: [6, 4, 3], color: colors[2] ?? DEFAULT_COLORS10[2] },
|
|
1217
|
+
{ indices: [6, 5, 4], color: colors[3] ?? DEFAULT_COLORS10[3] },
|
|
1218
|
+
{ indices: [6, 0, 5], color: colors[0] ?? DEFAULT_COLORS10[0] },
|
|
1219
|
+
{ indices: [7, 0, 1], color: colors[1] ?? DEFAULT_COLORS10[1] },
|
|
1220
|
+
{ indices: [7, 1, 2], color: colors[2] ?? DEFAULT_COLORS10[2] },
|
|
1221
|
+
{ indices: [7, 2, 3], color: colors[1] ?? DEFAULT_COLORS10[1] },
|
|
1222
|
+
{ indices: [7, 3, 4], color: colors[2] ?? DEFAULT_COLORS10[2] },
|
|
1223
|
+
{ indices: [7, 4, 5], color: colors[1] ?? DEFAULT_COLORS10[1] },
|
|
1224
|
+
{ indices: [7, 5, 0], color: colors[2] ?? DEFAULT_COLORS10[2] },
|
|
1225
|
+
{ indices: [3, 6, 8], color: colors[0] ?? DEFAULT_COLORS10[0] },
|
|
1226
|
+
{ indices: [3, 8, 6], color: colors[1] ?? DEFAULT_COLORS10[1] }
|
|
1227
|
+
]
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// src/engines/little-3d-engine/textures/dynamic/canvas-texture.ts
|
|
1232
|
+
function canvasTexture(draw, size = 96) {
|
|
1233
|
+
const canvas = document.createElement("canvas");
|
|
1234
|
+
canvas.width = canvas.height = size;
|
|
1235
|
+
const ctx = canvas.getContext("2d");
|
|
1236
|
+
if (ctx) draw(ctx);
|
|
1237
|
+
return canvas;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// src/engines/little-3d-engine/textures/dynamic/star.ts
|
|
1241
|
+
function starTexture() {
|
|
1242
|
+
return canvasTexture((ctx) => {
|
|
1243
|
+
ctx.translate(48, 48);
|
|
1244
|
+
ctx.fillStyle = "#fff";
|
|
1245
|
+
ctx.beginPath();
|
|
1246
|
+
for (let index = 0; index < 10; index++) {
|
|
1247
|
+
const radius = index % 2 === 0 ? 43 : 16;
|
|
1248
|
+
const angle = index * Math.PI / 5 - Math.PI / 2;
|
|
1249
|
+
ctx.lineTo(radius * Math.cos(angle), radius * Math.sin(angle));
|
|
1250
|
+
}
|
|
1251
|
+
ctx.closePath();
|
|
1252
|
+
ctx.fill();
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// src/engines/little-3d-engine/textures/dynamic/shine.ts
|
|
1257
|
+
function shineTexture() {
|
|
1258
|
+
return canvasTexture((ctx) => {
|
|
1259
|
+
const halo = ctx.createRadialGradient(48, 48, 1, 48, 48, 46);
|
|
1260
|
+
halo.addColorStop(0, "rgba(255,255,255,1)");
|
|
1261
|
+
halo.addColorStop(0.08, "rgba(255,255,255,1)");
|
|
1262
|
+
halo.addColorStop(0.22, "rgba(210,240,255,0.7)");
|
|
1263
|
+
halo.addColorStop(0.55, "rgba(120,200,255,0.22)");
|
|
1264
|
+
halo.addColorStop(1, "rgba(80,160,255,0)");
|
|
1265
|
+
ctx.fillStyle = halo;
|
|
1266
|
+
ctx.fillRect(0, 0, 96, 96);
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// src/engines/little-3d-engine/textures/dynamic/streak.ts
|
|
1271
|
+
function streakTexture() {
|
|
1272
|
+
return canvasTexture((ctx) => {
|
|
1273
|
+
const gradient = ctx.createLinearGradient(5, 0, 91, 0);
|
|
1274
|
+
gradient.addColorStop(0, "rgba(255,255,255,0)");
|
|
1275
|
+
gradient.addColorStop(0.7, "rgba(255,255,255,0.4)");
|
|
1276
|
+
gradient.addColorStop(1, "rgba(255,255,255,1)");
|
|
1277
|
+
ctx.strokeStyle = gradient;
|
|
1278
|
+
ctx.lineWidth = 3.5;
|
|
1279
|
+
ctx.lineCap = "round";
|
|
1280
|
+
ctx.beginPath();
|
|
1281
|
+
ctx.moveTo(5, 48);
|
|
1282
|
+
ctx.lineTo(91, 48);
|
|
1283
|
+
ctx.stroke();
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1178
1287
|
// src/engines/little-3d-engine/little-3d-engine.ts
|
|
1179
1288
|
init_geometry();
|
|
1180
1289
|
init_renderer();
|
|
@@ -24,14 +24,39 @@ __export(obj_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(obj_exports);
|
|
26
26
|
var DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
|
|
27
|
+
function channelToHex(value) {
|
|
28
|
+
const channel = Number.parseFloat(value);
|
|
29
|
+
if (!Number.isFinite(channel)) return void 0;
|
|
30
|
+
return Math.round(Math.min(1, Math.max(0, channel)) * 255).toString(16).padStart(2, "0");
|
|
31
|
+
}
|
|
32
|
+
function parseMtlColors(text) {
|
|
33
|
+
const colors = /* @__PURE__ */ new Map();
|
|
34
|
+
let material;
|
|
35
|
+
for (const line of text.split("\n")) {
|
|
36
|
+
const trimmed = line.trim();
|
|
37
|
+
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
38
|
+
const parts = trimmed.split(/\s+/);
|
|
39
|
+
if (parts[0] === "newmtl") {
|
|
40
|
+
material = parts.slice(1).join(" ");
|
|
41
|
+
} else if (parts[0] === "Kd" && material) {
|
|
42
|
+
const channels = parts.slice(1, 4).map(channelToHex);
|
|
43
|
+
if (channels.length === 3 && channels.every((channel) => channel !== void 0)) {
|
|
44
|
+
colors.set(material, `#${channels.join("")}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return colors;
|
|
49
|
+
}
|
|
27
50
|
function resolveIndex(token, vertexCount) {
|
|
28
51
|
const n = parseInt(token, 10);
|
|
29
52
|
return n < 0 ? vertexCount + n : n - 1;
|
|
30
53
|
}
|
|
31
54
|
function parseObj(text, options = {}) {
|
|
32
55
|
const colors = options.colors ?? DEFAULT_COLORS;
|
|
56
|
+
const materialColors = options.useMtlColors && options.mtl ? parseMtlColors(options.mtl) : void 0;
|
|
33
57
|
const vertices = [];
|
|
34
58
|
const faces = [];
|
|
59
|
+
let material;
|
|
35
60
|
for (const line of text.split("\n")) {
|
|
36
61
|
const trimmed = line.trim();
|
|
37
62
|
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
@@ -43,6 +68,8 @@ function parseObj(text, options = {}) {
|
|
|
43
68
|
y: parseFloat(parts[2]),
|
|
44
69
|
z: parseFloat(parts[3])
|
|
45
70
|
});
|
|
71
|
+
} else if (keyword === "usemtl") {
|
|
72
|
+
material = parts.slice(1).join(" ");
|
|
46
73
|
} else if (keyword === "f") {
|
|
47
74
|
const indices = [];
|
|
48
75
|
for (let i = 1; i < parts.length; i++) {
|
|
@@ -50,7 +77,9 @@ function parseObj(text, options = {}) {
|
|
|
50
77
|
indices.push(resolveIndex(vertexToken, vertices.length));
|
|
51
78
|
}
|
|
52
79
|
if (indices.length >= 3) {
|
|
53
|
-
|
|
80
|
+
const mtlColor = material ? materialColors?.get(material) : void 0;
|
|
81
|
+
const color = mtlColor ?? (materialColors ? colors[0] ?? "#888888" : colors[faces.length % colors.length]);
|
|
82
|
+
faces.push({ indices, color });
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
85
|
}
|