@vib3code/sdk 2.0.1 → 2.0.3-canary.75a3290
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/CHANGELOG.md +36 -0
- package/DOCS/AGENT_HARNESS_ARCHITECTURE.md +243 -0
- package/DOCS/CLI_ONBOARDING.md +1 -1
- package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +117 -0
- package/DOCS/EPIC_SCROLL_EVENTS.md +773 -0
- package/DOCS/HANDOFF_LANDING_PAGE.md +154 -0
- package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +493 -0
- package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +937 -0
- package/DOCS/PRODUCT_STRATEGY.md +63 -0
- package/DOCS/README.md +103 -0
- package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +97 -0
- package/DOCS/ROADMAP.md +111 -0
- package/DOCS/SCROLL_TIMELINE_v3.md +269 -0
- package/DOCS/SITE_REFACTOR_PLAN.md +100 -0
- package/DOCS/STATUS.md +24 -0
- package/DOCS/SYSTEM_INVENTORY.md +33 -30
- package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +85 -0
- package/DOCS/VISUAL_ANALYSIS_FACETAD.md +133 -0
- package/DOCS/VISUAL_ANALYSIS_SIMONE.md +95 -0
- package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +86 -0
- package/DOCS/{BLUEPRINT_EXECUTION_PLAN_2026-01-07.md → archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md} +1 -1
- package/DOCS/{DEV_TRACK_ANALYSIS.md → archive/DEV_TRACK_ANALYSIS.md} +3 -0
- package/DOCS/{SYSTEM_AUDIT_2026-01-30.md → archive/SYSTEM_AUDIT_2026-01-30.md} +3 -0
- package/DOCS/{DEV_TRACK_SESSION_2026-01-31.md → dev-tracks/DEV_TRACK_SESSION_2026-01-31.md} +1 -1
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +231 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +127 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-15.md +142 -0
- package/DOCS/dev-tracks/README.md +10 -0
- package/README.md +26 -13
- package/cpp/CMakeLists.txt +236 -0
- package/cpp/bindings/embind.cpp +269 -0
- package/cpp/build.sh +129 -0
- package/cpp/geometry/Crystal.cpp +103 -0
- package/cpp/geometry/Fractal.cpp +136 -0
- package/cpp/geometry/GeometryGenerator.cpp +262 -0
- package/cpp/geometry/KleinBottle.cpp +71 -0
- package/cpp/geometry/Sphere.cpp +134 -0
- package/cpp/geometry/Tesseract.cpp +94 -0
- package/cpp/geometry/Tetrahedron.cpp +83 -0
- package/cpp/geometry/Torus.cpp +65 -0
- package/cpp/geometry/WarpFunctions.cpp +238 -0
- package/cpp/geometry/Wave.cpp +85 -0
- package/cpp/include/vib3_ffi.h +238 -0
- package/cpp/math/Mat4x4.cpp +409 -0
- package/cpp/math/Mat4x4.hpp +209 -0
- package/cpp/math/Projection.cpp +142 -0
- package/cpp/math/Projection.hpp +148 -0
- package/cpp/math/Rotor4D.cpp +322 -0
- package/cpp/math/Rotor4D.hpp +204 -0
- package/cpp/math/Vec4.cpp +303 -0
- package/cpp/math/Vec4.hpp +225 -0
- package/cpp/src/vib3_ffi.cpp +607 -0
- package/cpp/tests/Geometry_test.cpp +213 -0
- package/cpp/tests/Mat4x4_test.cpp +494 -0
- package/cpp/tests/Projection_test.cpp +298 -0
- package/cpp/tests/Rotor4D_test.cpp +423 -0
- package/cpp/tests/Vec4_test.cpp +489 -0
- package/package.json +40 -27
- package/src/agent/index.js +1 -3
- package/src/agent/mcp/MCPServer.js +918 -0
- package/src/agent/mcp/index.js +1 -1
- package/src/agent/mcp/stdio-server.js +264 -0
- package/src/agent/mcp/tools.js +454 -0
- package/src/cli/index.js +374 -44
- package/src/core/CanvasManager.js +97 -204
- package/src/core/ErrorReporter.js +1 -1
- package/src/core/Parameters.js +1 -1
- package/src/core/VIB3Engine.js +93 -4
- package/src/core/VitalitySystem.js +53 -0
- package/src/core/index.js +18 -0
- package/src/core/renderers/FacetedRendererAdapter.js +10 -9
- package/src/core/renderers/HolographicRendererAdapter.js +13 -9
- package/src/core/renderers/QuantumRendererAdapter.js +11 -7
- package/src/creative/AestheticMapper.js +628 -0
- package/src/creative/ChoreographyPlayer.js +481 -0
- package/src/creative/index.js +11 -0
- package/src/export/TradingCardManager.js +3 -4
- package/src/export/index.js +11 -1
- package/src/faceted/FacetedSystem.js +241 -388
- package/src/holograms/HolographicVisualizer.js +29 -12
- package/src/holograms/RealHolographicSystem.js +194 -43
- package/src/math/index.js +7 -7
- package/src/polychora/PolychoraSystem.js +77 -0
- package/src/quantum/QuantumEngine.js +103 -66
- package/src/quantum/QuantumVisualizer.js +7 -2
- package/src/reactivity/index.js +3 -5
- package/src/render/LayerPresetManager.js +372 -0
- package/src/render/LayerReactivityBridge.js +344 -0
- package/src/render/LayerRelationshipGraph.js +610 -0
- package/src/render/MultiCanvasBridge.js +148 -25
- package/src/render/UnifiedRenderBridge.js +3 -0
- package/src/render/index.js +27 -2
- package/src/scene/index.js +4 -4
- package/src/shaders/faceted/faceted.frag.glsl +220 -80
- package/src/shaders/faceted/faceted.frag.wgsl +138 -97
- package/src/shaders/holographic/holographic.frag.glsl +28 -9
- package/src/shaders/holographic/holographic.frag.wgsl +107 -38
- package/src/shaders/quantum/quantum.frag.glsl +1 -0
- package/src/shaders/quantum/quantum.frag.wgsl +1 -1
- package/src/testing/ParallelTestFramework.js +2 -2
- package/src/viewer/GalleryUI.js +17 -0
- package/src/viewer/ViewerPortal.js +2 -2
- package/src/viewer/index.js +1 -1
- package/tools/headless-renderer.js +258 -0
- package/tools/shader-sync-verify.js +8 -4
- package/tools/site-analysis/all-reports.json +32 -0
- package/tools/site-analysis/combined-analysis.md +50 -0
- package/tools/site-analyzer.mjs +779 -0
- package/tools/visual-catalog/capture.js +276 -0
- package/tools/visual-catalog/composite.js +138 -0
- package/types/adaptive-sdk.d.ts +204 -5
- package/types/agent/cli.d.ts +78 -0
- package/types/agent/index.d.ts +18 -0
- package/types/agent/mcp.d.ts +87 -0
- package/types/agent/telemetry.d.ts +190 -0
- package/types/core/VIB3Engine.d.ts +26 -0
- package/types/core/index.d.ts +261 -0
- package/types/creative/AestheticMapper.d.ts +72 -0
- package/types/creative/ChoreographyPlayer.d.ts +96 -0
- package/types/creative/index.d.ts +17 -0
- package/types/export/index.d.ts +243 -0
- package/types/geometry/index.d.ts +164 -0
- package/types/math/index.d.ts +214 -0
- package/types/render/LayerPresetManager.d.ts +78 -0
- package/types/render/LayerReactivityBridge.d.ts +85 -0
- package/types/render/LayerRelationshipGraph.d.ts +174 -0
- package/types/render/index.d.ts +3 -0
- package/types/scene/index.d.ts +204 -0
- package/types/systems/index.d.ts +244 -0
- package/types/variations/index.d.ts +62 -0
- package/types/viewer/index.d.ts +225 -0
- /package/DOCS/{DEV_TRACK_PLAN_2026-01-07.md → archive/DEV_TRACK_PLAN_2026-01-07.md} +0 -0
- /package/DOCS/{SESSION_014_PLAN.md → archive/SESSION_014_PLAN.md} +0 -0
- /package/DOCS/{SESSION_LOG_2026-01-07.md → archive/SESSION_LOG_2026-01-07.md} +0 -0
- /package/DOCS/{STRATEGIC_BLUEPRINT_2026-01-07.md → archive/STRATEGIC_BLUEPRINT_2026-01-07.md} +0 -0
- /package/src/viewer/{ReactivityManager.js → ViewerInputHandler.js} +0 -0
package/cpp/build.sh
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# VIB3+ WASM Build Script
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# ./build.sh # Build release WASM
|
|
7
|
+
# ./build.sh debug # Build debug WASM
|
|
8
|
+
# ./build.sh native # Build native (with tests)
|
|
9
|
+
# ./build.sh clean # Clean build directory
|
|
10
|
+
#
|
|
11
|
+
# Requirements:
|
|
12
|
+
# - CMake 3.20+
|
|
13
|
+
# - Emscripten SDK (for WASM builds)
|
|
14
|
+
# - C++20 compiler (for native builds)
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
set -euo pipefail
|
|
18
|
+
|
|
19
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
20
|
+
BUILD_DIR="${SCRIPT_DIR}/build"
|
|
21
|
+
DIST_DIR="${SCRIPT_DIR}/../dist/wasm"
|
|
22
|
+
BUILD_TYPE="${1:-release}"
|
|
23
|
+
NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
|
24
|
+
|
|
25
|
+
# Colors for output
|
|
26
|
+
RED='\033[0;31m'
|
|
27
|
+
GREEN='\033[0;32m'
|
|
28
|
+
YELLOW='\033[1;33m'
|
|
29
|
+
NC='\033[0m' # No Color
|
|
30
|
+
|
|
31
|
+
log() { echo -e "${GREEN}[VIB3]${NC} $*"; }
|
|
32
|
+
warn() { echo -e "${YELLOW}[VIB3]${NC} $*"; }
|
|
33
|
+
error() { echo -e "${RED}[VIB3]${NC} $*" >&2; }
|
|
34
|
+
|
|
35
|
+
case "${BUILD_TYPE}" in
|
|
36
|
+
clean)
|
|
37
|
+
log "Cleaning build directory..."
|
|
38
|
+
rm -rf "${BUILD_DIR}"
|
|
39
|
+
log "Done."
|
|
40
|
+
exit 0
|
|
41
|
+
;;
|
|
42
|
+
|
|
43
|
+
debug)
|
|
44
|
+
log "Building WASM (Debug)..."
|
|
45
|
+
|
|
46
|
+
if ! command -v emcmake &>/dev/null; then
|
|
47
|
+
error "Emscripten not found. Install emsdk and activate it:"
|
|
48
|
+
error " git clone https://github.com/emscripten-core/emsdk.git"
|
|
49
|
+
error " cd emsdk && ./emsdk install latest && ./emsdk activate latest"
|
|
50
|
+
error " source emsdk_env.sh"
|
|
51
|
+
exit 1
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
mkdir -p "${BUILD_DIR}/wasm-debug"
|
|
55
|
+
cd "${BUILD_DIR}/wasm-debug"
|
|
56
|
+
|
|
57
|
+
emcmake cmake "${SCRIPT_DIR}" \
|
|
58
|
+
-DCMAKE_BUILD_TYPE=Debug \
|
|
59
|
+
-DVIB3_BUILD_WASM=ON \
|
|
60
|
+
-DVIB3_BUILD_TESTS=OFF \
|
|
61
|
+
-DVIB3_ENABLE_SIMD=ON
|
|
62
|
+
|
|
63
|
+
cmake --build . -j"${NPROC}"
|
|
64
|
+
|
|
65
|
+
# Copy outputs
|
|
66
|
+
mkdir -p "${DIST_DIR}"
|
|
67
|
+
cp -f bin/vib3.js bin/vib3.wasm "${DIST_DIR}/"
|
|
68
|
+
[ -f bin/vib3.d.ts ] && cp -f bin/vib3.d.ts "${DIST_DIR}/"
|
|
69
|
+
|
|
70
|
+
log "Debug WASM build complete. Output: ${DIST_DIR}/"
|
|
71
|
+
;;
|
|
72
|
+
|
|
73
|
+
release)
|
|
74
|
+
log "Building WASM (Release)..."
|
|
75
|
+
|
|
76
|
+
if ! command -v emcmake &>/dev/null; then
|
|
77
|
+
error "Emscripten not found. Install emsdk and activate it:"
|
|
78
|
+
error " git clone https://github.com/emscripten-core/emsdk.git"
|
|
79
|
+
error " cd emsdk && ./emsdk install latest && ./emsdk activate latest"
|
|
80
|
+
error " source emsdk_env.sh"
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
mkdir -p "${BUILD_DIR}/wasm-release"
|
|
85
|
+
cd "${BUILD_DIR}/wasm-release"
|
|
86
|
+
|
|
87
|
+
emcmake cmake "${SCRIPT_DIR}" \
|
|
88
|
+
-DCMAKE_BUILD_TYPE=Release \
|
|
89
|
+
-DVIB3_BUILD_WASM=ON \
|
|
90
|
+
-DVIB3_BUILD_TESTS=OFF \
|
|
91
|
+
-DVIB3_ENABLE_SIMD=ON
|
|
92
|
+
|
|
93
|
+
cmake --build . -j"${NPROC}"
|
|
94
|
+
|
|
95
|
+
# Copy outputs
|
|
96
|
+
mkdir -p "${DIST_DIR}"
|
|
97
|
+
cp -f bin/vib3.js bin/vib3.wasm "${DIST_DIR}/"
|
|
98
|
+
[ -f bin/vib3.d.ts ] && cp -f bin/vib3.d.ts "${DIST_DIR}/"
|
|
99
|
+
|
|
100
|
+
log "Release WASM build complete. Output: ${DIST_DIR}/"
|
|
101
|
+
ls -lh "${DIST_DIR}/"
|
|
102
|
+
;;
|
|
103
|
+
|
|
104
|
+
native)
|
|
105
|
+
log "Building native (with tests)..."
|
|
106
|
+
|
|
107
|
+
mkdir -p "${BUILD_DIR}/native"
|
|
108
|
+
cd "${BUILD_DIR}/native"
|
|
109
|
+
|
|
110
|
+
cmake "${SCRIPT_DIR}" \
|
|
111
|
+
-DCMAKE_BUILD_TYPE=Debug \
|
|
112
|
+
-DVIB3_BUILD_WASM=OFF \
|
|
113
|
+
-DVIB3_BUILD_TESTS=ON \
|
|
114
|
+
-DVIB3_ENABLE_SIMD=ON
|
|
115
|
+
|
|
116
|
+
cmake --build . -j"${NPROC}"
|
|
117
|
+
|
|
118
|
+
log "Running tests..."
|
|
119
|
+
ctest --output-on-failure
|
|
120
|
+
|
|
121
|
+
log "Native build and tests complete."
|
|
122
|
+
;;
|
|
123
|
+
|
|
124
|
+
*)
|
|
125
|
+
error "Unknown build type: ${BUILD_TYPE}"
|
|
126
|
+
echo "Usage: $0 [release|debug|native|clean]"
|
|
127
|
+
exit 1
|
|
128
|
+
;;
|
|
129
|
+
esac
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crystal.cpp - Octahedral / Crystalline Structure in 4D
|
|
3
|
+
*
|
|
4
|
+
* Generates vertices and edge geometry for crystalline structures
|
|
5
|
+
* in 4D: the regular octahedron (cross-polytope) and its dual,
|
|
6
|
+
* extended with 4D vertices along the W axis.
|
|
7
|
+
*
|
|
8
|
+
* The 4D cross-polytope (hyperoctahedron / 16-cell) has 8 vertices
|
|
9
|
+
* at the 4 axis-aligned unit positions and their negations.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "math/Vec4.hpp"
|
|
13
|
+
#include <vector>
|
|
14
|
+
#include <cmath>
|
|
15
|
+
#include <numbers>
|
|
16
|
+
|
|
17
|
+
namespace vib3 {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate the 8 vertices of a 4D cross-polytope (hyperoctahedron / 16-cell).
|
|
21
|
+
*
|
|
22
|
+
* Vertices lie at (+-1, 0, 0, 0), (0, +-1, 0, 0), (0, 0, +-1, 0), (0, 0, 0, +-1).
|
|
23
|
+
*/
|
|
24
|
+
std::vector<Vec4> generateCrossPolytopeVertices() noexcept {
|
|
25
|
+
std::vector<Vec4> vertices;
|
|
26
|
+
vertices.reserve(8);
|
|
27
|
+
|
|
28
|
+
vertices.emplace_back( 1.0f, 0.0f, 0.0f, 0.0f);
|
|
29
|
+
vertices.emplace_back(-1.0f, 0.0f, 0.0f, 0.0f);
|
|
30
|
+
vertices.emplace_back( 0.0f, 1.0f, 0.0f, 0.0f);
|
|
31
|
+
vertices.emplace_back( 0.0f, -1.0f, 0.0f, 0.0f);
|
|
32
|
+
vertices.emplace_back( 0.0f, 0.0f, 1.0f, 0.0f);
|
|
33
|
+
vertices.emplace_back( 0.0f, 0.0f, -1.0f, 0.0f);
|
|
34
|
+
vertices.emplace_back( 0.0f, 0.0f, 0.0f, 1.0f);
|
|
35
|
+
vertices.emplace_back( 0.0f, 0.0f, 0.0f, -1.0f);
|
|
36
|
+
|
|
37
|
+
return vertices;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generate crystalline geometry with edge interpolation.
|
|
42
|
+
*
|
|
43
|
+
* The 4D cross-polytope has 24 edges: every pair of non-antipodal vertices
|
|
44
|
+
* is connected (i.e., vertices i and j are connected unless they lie on
|
|
45
|
+
* the same axis). Each edge is subdivided into `resolution` segments.
|
|
46
|
+
*
|
|
47
|
+
* Additionally generates midpoint vertices for a dual-lattice structure
|
|
48
|
+
* (the 4D hypercube formed by the dual vertices at the edge midpoints).
|
|
49
|
+
*
|
|
50
|
+
* @param resolution Number of subdivisions per edge (minimum 2)
|
|
51
|
+
* @return Vector of 4D points forming the crystal wireframe
|
|
52
|
+
*/
|
|
53
|
+
std::vector<Vec4> generateCrystal(int resolution) noexcept {
|
|
54
|
+
if (resolution < 2) resolution = 2;
|
|
55
|
+
|
|
56
|
+
auto baseVertices = generateCrossPolytopeVertices();
|
|
57
|
+
|
|
58
|
+
// Edges of the 16-cell: connect every pair of vertices that are
|
|
59
|
+
// NOT antipodal (not on the same axis).
|
|
60
|
+
// 8 vertices, 24 edges total.
|
|
61
|
+
struct Edge { int a, b; };
|
|
62
|
+
std::vector<Edge> edges;
|
|
63
|
+
edges.reserve(24);
|
|
64
|
+
|
|
65
|
+
for (int i = 0; i < 8; ++i) {
|
|
66
|
+
for (int j = i + 1; j < 8; ++j) {
|
|
67
|
+
// Antipodal pairs: (0,1), (2,3), (4,5), (6,7)
|
|
68
|
+
// Skip if on same axis (differ by 1 and i is even)
|
|
69
|
+
if ((i ^ j) == 1 && (i % 2 == 0)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
edges.push_back({i, j});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
std::vector<Vec4> vertices;
|
|
77
|
+
vertices.reserve(edges.size() * static_cast<size_t>(resolution) + 16);
|
|
78
|
+
|
|
79
|
+
// Edge wireframe
|
|
80
|
+
for (const auto& edge : edges) {
|
|
81
|
+
const Vec4& a = baseVertices[static_cast<size_t>(edge.a)];
|
|
82
|
+
const Vec4& b = baseVertices[static_cast<size_t>(edge.b)];
|
|
83
|
+
|
|
84
|
+
for (int i = 0; i < resolution; ++i) {
|
|
85
|
+
float t = static_cast<float>(i) / static_cast<float>(resolution - 1);
|
|
86
|
+
vertices.push_back(a.lerp(b, t));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Dual vertices (tesseract / hypercube dual): midpoints of faces
|
|
91
|
+
// These are the 16 vertices of the dual polytope at (+-0.5, +-0.5, +-0.5, +-0.5)
|
|
92
|
+
for (int i = 0; i < 16; ++i) {
|
|
93
|
+
float x = (i & 1) ? 0.5f : -0.5f;
|
|
94
|
+
float y = (i & 2) ? 0.5f : -0.5f;
|
|
95
|
+
float z = (i & 4) ? 0.5f : -0.5f;
|
|
96
|
+
float w = (i & 8) ? 0.5f : -0.5f;
|
|
97
|
+
vertices.emplace_back(x, y, z, w);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return vertices;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
} // namespace vib3
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fractal.cpp - 4D Iterated Function System Fractal
|
|
3
|
+
*
|
|
4
|
+
* Generates recursive subdivision geometry in 4D using an IFS approach.
|
|
5
|
+
* Starts from an initial set of points and iteratively applies affine
|
|
6
|
+
* contractions toward attractor vertices, building a self-similar
|
|
7
|
+
* fractal structure (a 4D analogue of the Sierpinski tetrahedron).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "math/Vec4.hpp"
|
|
11
|
+
#include <vector>
|
|
12
|
+
#include <cmath>
|
|
13
|
+
#include <numbers>
|
|
14
|
+
#include <cstdint>
|
|
15
|
+
|
|
16
|
+
namespace vib3 {
|
|
17
|
+
|
|
18
|
+
namespace {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 4D Sierpinski-style attractor vertices.
|
|
22
|
+
*
|
|
23
|
+
* Five vertices of a regular 5-cell (pentatope) provide a natural
|
|
24
|
+
* set of contraction centers for a 4D IFS.
|
|
25
|
+
*/
|
|
26
|
+
constexpr int kNumAttractors = 5;
|
|
27
|
+
|
|
28
|
+
Vec4 getAttractorVertex(int index) noexcept {
|
|
29
|
+
// Regular pentatope vertices (5-cell), embedded in R4
|
|
30
|
+
// These are the vertices of a regular simplex in 4D.
|
|
31
|
+
switch (index) {
|
|
32
|
+
case 0: return Vec4( 1.0f, 1.0f, 1.0f, -1.0f / std::numbers::sqrt2_v<float>);
|
|
33
|
+
case 1: return Vec4( 1.0f, -1.0f, -1.0f, -1.0f / std::numbers::sqrt2_v<float>);
|
|
34
|
+
case 2: return Vec4(-1.0f, 1.0f, -1.0f, -1.0f / std::numbers::sqrt2_v<float>);
|
|
35
|
+
case 3: return Vec4(-1.0f, -1.0f, 1.0f, -1.0f / std::numbers::sqrt2_v<float>);
|
|
36
|
+
case 4: return Vec4( 0.0f, 0.0f, 0.0f, 4.0f / std::numbers::sqrt2_v<float>);
|
|
37
|
+
default: return Vec4::zero();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Simple deterministic hash for reproducible pseudo-random attractor selection.
|
|
43
|
+
*/
|
|
44
|
+
constexpr uint32_t hashStep(uint32_t seed) noexcept {
|
|
45
|
+
seed ^= seed << 13;
|
|
46
|
+
seed ^= seed >> 17;
|
|
47
|
+
seed ^= seed << 5;
|
|
48
|
+
return seed;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
} // anonymous namespace
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Generate a 4D IFS fractal via the chaos game.
|
|
55
|
+
*
|
|
56
|
+
* Uses the classic chaos game algorithm: starting from a seed point,
|
|
57
|
+
* repeatedly pick a random attractor and move halfway toward it.
|
|
58
|
+
* After a warm-up period, the trajectory traces out the fractal.
|
|
59
|
+
*
|
|
60
|
+
* @param resolution Controls the number of output points (resolution^2 points)
|
|
61
|
+
* @return Vector of 4D fractal points
|
|
62
|
+
*/
|
|
63
|
+
std::vector<Vec4> generateFractal(int resolution) noexcept {
|
|
64
|
+
if (resolution < 4) resolution = 4;
|
|
65
|
+
|
|
66
|
+
int numPoints = resolution * resolution;
|
|
67
|
+
constexpr int warmUp = 64;
|
|
68
|
+
constexpr float contractionFactor = 0.5f;
|
|
69
|
+
|
|
70
|
+
std::vector<Vec4> vertices;
|
|
71
|
+
vertices.reserve(static_cast<size_t>(numPoints));
|
|
72
|
+
|
|
73
|
+
// Start at the origin
|
|
74
|
+
Vec4 current = Vec4::zero();
|
|
75
|
+
uint32_t seed = 0xDEADBEEF;
|
|
76
|
+
|
|
77
|
+
// Warm-up iterations (discard to converge onto attractor)
|
|
78
|
+
for (int i = 0; i < warmUp; ++i) {
|
|
79
|
+
seed = hashStep(seed);
|
|
80
|
+
int attIdx = static_cast<int>(seed % kNumAttractors);
|
|
81
|
+
Vec4 target = getAttractorVertex(attIdx);
|
|
82
|
+
current = current.lerp(target, contractionFactor);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Generate fractal points
|
|
86
|
+
for (int i = 0; i < numPoints; ++i) {
|
|
87
|
+
seed = hashStep(seed);
|
|
88
|
+
int attIdx = static_cast<int>(seed % kNumAttractors);
|
|
89
|
+
Vec4 target = getAttractorVertex(attIdx);
|
|
90
|
+
current = current.lerp(target, contractionFactor);
|
|
91
|
+
vertices.push_back(current);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return vertices;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Generate a 4D IFS fractal via recursive subdivision.
|
|
99
|
+
*
|
|
100
|
+
* Starts from attractor vertices and recursively subdivides midpoints
|
|
101
|
+
* to a given depth, producing a deterministic point set.
|
|
102
|
+
*
|
|
103
|
+
* @param depth Recursion depth (0 = just vertices, each level multiplies points by 5)
|
|
104
|
+
* @return Vector of 4D fractal points
|
|
105
|
+
*/
|
|
106
|
+
std::vector<Vec4> generateFractalSubdivision(int depth) noexcept {
|
|
107
|
+
if (depth < 0) depth = 0;
|
|
108
|
+
if (depth > 6) depth = 6; // Cap to avoid excessive memory
|
|
109
|
+
|
|
110
|
+
std::vector<Vec4> current;
|
|
111
|
+
current.reserve(static_cast<size_t>(kNumAttractors));
|
|
112
|
+
|
|
113
|
+
// Seed with attractor vertices
|
|
114
|
+
for (int i = 0; i < kNumAttractors; ++i) {
|
|
115
|
+
current.push_back(getAttractorVertex(i));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Recursive subdivision
|
|
119
|
+
for (int d = 0; d < depth; ++d) {
|
|
120
|
+
std::vector<Vec4> next;
|
|
121
|
+
next.reserve(current.size() * static_cast<size_t>(kNumAttractors));
|
|
122
|
+
|
|
123
|
+
for (const auto& point : current) {
|
|
124
|
+
for (int a = 0; a < kNumAttractors; ++a) {
|
|
125
|
+
Vec4 target = getAttractorVertex(a);
|
|
126
|
+
next.push_back(point.lerp(target, 0.5f));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
current = std::move(next);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return current;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
} // namespace vib3
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GeometryGenerator.cpp - Main Geometry Factory
|
|
3
|
+
*
|
|
4
|
+
* Dispatches to individual geometry generators based on geometry index.
|
|
5
|
+
* Uses the VIB3+ encoding: index = coreType * 8 + baseGeometry
|
|
6
|
+
*
|
|
7
|
+
* Core types:
|
|
8
|
+
* 0 = Base (index 0-7) - Pure base geometry
|
|
9
|
+
* 1 = Hypersphere (index 8-15) - Projected onto 3-sphere
|
|
10
|
+
* 2 = Hypertetrahedron (index 16-23) - Warped toward pentatope
|
|
11
|
+
*
|
|
12
|
+
* Base geometries (0-7):
|
|
13
|
+
* 0 = Tetrahedron 4 = Klein Bottle
|
|
14
|
+
* 1 = Hypercube 5 = Fractal
|
|
15
|
+
* 2 = Sphere 6 = Wave
|
|
16
|
+
* 3 = Torus 7 = Crystal
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "math/Vec4.hpp"
|
|
20
|
+
#include <vector>
|
|
21
|
+
#include <algorithm>
|
|
22
|
+
|
|
23
|
+
namespace vib3 {
|
|
24
|
+
|
|
25
|
+
// ---- Forward declarations of individual generators ----
|
|
26
|
+
|
|
27
|
+
// geometry/Tetrahedron.cpp
|
|
28
|
+
std::vector<Vec4> generateTetrahedron(int resolution) noexcept;
|
|
29
|
+
|
|
30
|
+
// geometry/Tesseract.cpp
|
|
31
|
+
std::vector<Vec4> generateTesseract(int resolution) noexcept;
|
|
32
|
+
|
|
33
|
+
// geometry/Sphere.cpp
|
|
34
|
+
std::vector<Vec4> generateSphere(int resolution) noexcept;
|
|
35
|
+
|
|
36
|
+
// geometry/Torus.cpp
|
|
37
|
+
std::vector<Vec4> generateTorus(int resolution) noexcept;
|
|
38
|
+
|
|
39
|
+
// geometry/KleinBottle.cpp
|
|
40
|
+
std::vector<Vec4> generateKleinBottle(int resolution) noexcept;
|
|
41
|
+
|
|
42
|
+
// geometry/Fractal.cpp
|
|
43
|
+
std::vector<Vec4> generateFractal(int resolution) noexcept;
|
|
44
|
+
|
|
45
|
+
// geometry/Wave.cpp
|
|
46
|
+
std::vector<Vec4> generateWave(int resolution) noexcept;
|
|
47
|
+
|
|
48
|
+
// geometry/Crystal.cpp
|
|
49
|
+
std::vector<Vec4> generateCrystal(int resolution) noexcept;
|
|
50
|
+
|
|
51
|
+
// geometry/WarpFunctions.cpp
|
|
52
|
+
Vec4 warpHypersphere(Vec4 point, float radius) noexcept;
|
|
53
|
+
std::vector<Vec4> warpHypersphereBatch(const std::vector<Vec4>& points, float radius) noexcept;
|
|
54
|
+
Vec4 warpHypertetra(Vec4 point) noexcept;
|
|
55
|
+
std::vector<Vec4> warpHypertetraBatch(const std::vector<Vec4>& points) noexcept;
|
|
56
|
+
|
|
57
|
+
// ---- Geometry index encoding ----
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Maximum valid geometry index (3 core types x 8 base geometries - 1).
|
|
61
|
+
*/
|
|
62
|
+
constexpr int kMaxGeometryIndex = 23;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Number of base geometry types.
|
|
66
|
+
*/
|
|
67
|
+
constexpr int kBaseGeometryCount = 8;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Decompose a geometry index into core type and base geometry.
|
|
71
|
+
*
|
|
72
|
+
* @param geometryIndex Combined index (0-23)
|
|
73
|
+
* @param coreType Output: 0=Base, 1=Hypersphere, 2=Hypertetrahedron
|
|
74
|
+
* @param baseGeometry Output: 0-7 base geometry type
|
|
75
|
+
*/
|
|
76
|
+
constexpr void decodeGeometryIndex(int geometryIndex,
|
|
77
|
+
int& coreType,
|
|
78
|
+
int& baseGeometry) noexcept {
|
|
79
|
+
coreType = geometryIndex / kBaseGeometryCount;
|
|
80
|
+
baseGeometry = geometryIndex % kBaseGeometryCount;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Encode core type and base geometry into a geometry index.
|
|
85
|
+
*
|
|
86
|
+
* @param coreType 0=Base, 1=Hypersphere, 2=Hypertetrahedron
|
|
87
|
+
* @param baseGeometry 0-7 base geometry type
|
|
88
|
+
* @return Combined geometry index (0-23)
|
|
89
|
+
*/
|
|
90
|
+
constexpr int encodeGeometryIndex(int coreType, int baseGeometry) noexcept {
|
|
91
|
+
return coreType * kBaseGeometryCount + baseGeometry;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ---- Internal dispatch ----
|
|
95
|
+
|
|
96
|
+
namespace {
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generate base geometry vertices for a given base type.
|
|
100
|
+
*/
|
|
101
|
+
std::vector<Vec4> generateBaseGeometry(int baseGeometry, int resolution) noexcept {
|
|
102
|
+
switch (baseGeometry) {
|
|
103
|
+
case 0: return generateTetrahedron(resolution);
|
|
104
|
+
case 1: return generateTesseract(resolution);
|
|
105
|
+
case 2: return generateSphere(resolution);
|
|
106
|
+
case 3: return generateTorus(resolution);
|
|
107
|
+
case 4: return generateKleinBottle(resolution);
|
|
108
|
+
case 5: return generateFractal(resolution);
|
|
109
|
+
case 6: return generateWave(resolution);
|
|
110
|
+
case 7: return generateCrystal(resolution);
|
|
111
|
+
default:
|
|
112
|
+
// Unknown base geometry, return empty
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Apply core type warp to a set of base vertices.
|
|
119
|
+
*/
|
|
120
|
+
std::vector<Vec4> applyWarp(int coreType, std::vector<Vec4> vertices) noexcept {
|
|
121
|
+
switch (coreType) {
|
|
122
|
+
case 0:
|
|
123
|
+
// Base: no warp
|
|
124
|
+
return vertices;
|
|
125
|
+
|
|
126
|
+
case 1:
|
|
127
|
+
// Hypersphere: project all vertices onto S3
|
|
128
|
+
return warpHypersphereBatch(vertices, 1.0f);
|
|
129
|
+
|
|
130
|
+
case 2:
|
|
131
|
+
// Hypertetrahedron: warp toward pentatope vertices
|
|
132
|
+
return warpHypertetraBatch(vertices);
|
|
133
|
+
|
|
134
|
+
default:
|
|
135
|
+
// Unknown core type, return unmodified
|
|
136
|
+
return vertices;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} // anonymous namespace
|
|
141
|
+
|
|
142
|
+
// ---- Public API ----
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Generate 4D geometry for a given geometry index.
|
|
146
|
+
*
|
|
147
|
+
* This is the main entry point for the geometry library. It decodes the
|
|
148
|
+
* geometry index into a base geometry type and core type warp, generates
|
|
149
|
+
* the base geometry, and then applies the appropriate warp transformation.
|
|
150
|
+
*
|
|
151
|
+
* @param geometryIndex Combined geometry index (0-23)
|
|
152
|
+
* - 0-7: Base geometries (no warp)
|
|
153
|
+
* - 8-15: Hypersphere-warped geometries
|
|
154
|
+
* - 16-23: Hypertetrahedron-warped geometries
|
|
155
|
+
*
|
|
156
|
+
* @param resolution Controls the level of detail. Higher values produce
|
|
157
|
+
* more vertices. The exact meaning varies by geometry type but generally
|
|
158
|
+
* represents subdivisions per dimension. Typical range: 4-100.
|
|
159
|
+
*
|
|
160
|
+
* @return Vector of 4D vertices. Empty if geometryIndex is out of range.
|
|
161
|
+
*/
|
|
162
|
+
std::vector<Vec4> generateGeometry(int geometryIndex, int resolution) noexcept {
|
|
163
|
+
// Clamp to valid range
|
|
164
|
+
if (geometryIndex < 0 || geometryIndex > kMaxGeometryIndex) {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (resolution < 2) resolution = 2;
|
|
169
|
+
if (resolution > 256) resolution = 256;
|
|
170
|
+
|
|
171
|
+
int coreType = 0;
|
|
172
|
+
int baseGeometry = 0;
|
|
173
|
+
decodeGeometryIndex(geometryIndex, coreType, baseGeometry);
|
|
174
|
+
|
|
175
|
+
// Generate base geometry
|
|
176
|
+
std::vector<Vec4> vertices = generateBaseGeometry(baseGeometry, resolution);
|
|
177
|
+
|
|
178
|
+
// Apply core type warp
|
|
179
|
+
return applyWarp(coreType, std::move(vertices));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get the name string for a base geometry type.
|
|
184
|
+
*
|
|
185
|
+
* @param baseGeometry Base geometry index (0-7)
|
|
186
|
+
* @return Human-readable name, or "Unknown" if out of range
|
|
187
|
+
*/
|
|
188
|
+
const char* getBaseGeometryName(int baseGeometry) noexcept {
|
|
189
|
+
switch (baseGeometry) {
|
|
190
|
+
case 0: return "Tetrahedron";
|
|
191
|
+
case 1: return "Hypercube";
|
|
192
|
+
case 2: return "Sphere";
|
|
193
|
+
case 3: return "Torus";
|
|
194
|
+
case 4: return "Klein Bottle";
|
|
195
|
+
case 5: return "Fractal";
|
|
196
|
+
case 6: return "Wave";
|
|
197
|
+
case 7: return "Crystal";
|
|
198
|
+
default: return "Unknown";
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get the name string for a core type.
|
|
204
|
+
*
|
|
205
|
+
* @param coreType Core type index (0-2)
|
|
206
|
+
* @return Human-readable name, or "Unknown" if out of range
|
|
207
|
+
*/
|
|
208
|
+
const char* getCoreTypeName(int coreType) noexcept {
|
|
209
|
+
switch (coreType) {
|
|
210
|
+
case 0: return "Base";
|
|
211
|
+
case 1: return "Hypersphere";
|
|
212
|
+
case 2: return "Hypertetrahedron";
|
|
213
|
+
default: return "Unknown";
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Get a full descriptive name for a geometry index.
|
|
219
|
+
*
|
|
220
|
+
* Combines core type and base geometry names, e.g.
|
|
221
|
+
* "Hypersphere Torus" for index 11.
|
|
222
|
+
*
|
|
223
|
+
* @param geometryIndex Combined index (0-23)
|
|
224
|
+
* @param buffer Output buffer (must be at least 64 chars)
|
|
225
|
+
* @param bufferSize Size of the output buffer
|
|
226
|
+
* @return Number of characters written (excluding null terminator)
|
|
227
|
+
*/
|
|
228
|
+
int getGeometryName(int geometryIndex, char* buffer, int bufferSize) noexcept {
|
|
229
|
+
if (!buffer || bufferSize <= 0) return 0;
|
|
230
|
+
|
|
231
|
+
int coreType = 0;
|
|
232
|
+
int baseGeometry = 0;
|
|
233
|
+
decodeGeometryIndex(geometryIndex, coreType, baseGeometry);
|
|
234
|
+
|
|
235
|
+
const char* coreName = getCoreTypeName(coreType);
|
|
236
|
+
const char* baseName = getBaseGeometryName(baseGeometry);
|
|
237
|
+
|
|
238
|
+
int written = 0;
|
|
239
|
+
|
|
240
|
+
if (coreType == 0) {
|
|
241
|
+
// Base type: just use geometry name
|
|
242
|
+
for (int i = 0; baseName[i] != '\0' && written < bufferSize - 1; ++i) {
|
|
243
|
+
buffer[written++] = baseName[i];
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
// Compound name: "CoreType BaseGeometry"
|
|
247
|
+
for (int i = 0; coreName[i] != '\0' && written < bufferSize - 1; ++i) {
|
|
248
|
+
buffer[written++] = coreName[i];
|
|
249
|
+
}
|
|
250
|
+
if (written < bufferSize - 1) {
|
|
251
|
+
buffer[written++] = ' ';
|
|
252
|
+
}
|
|
253
|
+
for (int i = 0; baseName[i] != '\0' && written < bufferSize - 1; ++i) {
|
|
254
|
+
buffer[written++] = baseName[i];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
buffer[written] = '\0';
|
|
259
|
+
return written;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
} // namespace vib3
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KleinBottle.cpp - Non-Orientable Surface in 4D
|
|
3
|
+
*
|
|
4
|
+
* Generates points on the Klein bottle immersed in R4.
|
|
5
|
+
*
|
|
6
|
+
* The Klein bottle cannot be embedded in R3 without self-intersection,
|
|
7
|
+
* but it can be properly embedded in R4. We use the standard
|
|
8
|
+
* figure-eight parametrization lifted into the 4th dimension:
|
|
9
|
+
*
|
|
10
|
+
* x = (a + b*cos(v)) * cos(u)
|
|
11
|
+
* y = (a + b*cos(v)) * sin(u)
|
|
12
|
+
* z = b * sin(v) * cos(u/2)
|
|
13
|
+
* w = b * sin(v) * sin(u/2)
|
|
14
|
+
*
|
|
15
|
+
* where u in [0, 2*pi), v in [0, 2*pi), and a > b > 0.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "math/Vec4.hpp"
|
|
19
|
+
#include <vector>
|
|
20
|
+
#include <cmath>
|
|
21
|
+
#include <numbers>
|
|
22
|
+
|
|
23
|
+
namespace vib3 {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generate Klein bottle surface points in 4D.
|
|
27
|
+
*
|
|
28
|
+
* Uses the figure-eight immersion lifted to R4, which avoids
|
|
29
|
+
* the self-intersection that occurs in R3.
|
|
30
|
+
*
|
|
31
|
+
* @param resolution Number of subdivisions for each parameter (total points = resolution^2)
|
|
32
|
+
* @return Vector of 4D points on the Klein bottle surface
|
|
33
|
+
*/
|
|
34
|
+
std::vector<Vec4> generateKleinBottle(int resolution) noexcept {
|
|
35
|
+
if (resolution < 4) resolution = 4;
|
|
36
|
+
|
|
37
|
+
constexpr float twoPi = 2.0f * std::numbers::pi_v<float>;
|
|
38
|
+
constexpr float a = 2.0f; // Major radius
|
|
39
|
+
constexpr float b = 1.0f; // Minor radius
|
|
40
|
+
|
|
41
|
+
std::vector<Vec4> vertices;
|
|
42
|
+
vertices.reserve(static_cast<size_t>(resolution) * static_cast<size_t>(resolution));
|
|
43
|
+
|
|
44
|
+
for (int iu = 0; iu < resolution; ++iu) {
|
|
45
|
+
float u = twoPi * static_cast<float>(iu) / static_cast<float>(resolution);
|
|
46
|
+
float cosU = std::cos(u);
|
|
47
|
+
float sinU = std::sin(u);
|
|
48
|
+
float halfU = u * 0.5f;
|
|
49
|
+
float cosHalfU = std::cos(halfU);
|
|
50
|
+
float sinHalfU = std::sin(halfU);
|
|
51
|
+
|
|
52
|
+
for (int iv = 0; iv < resolution; ++iv) {
|
|
53
|
+
float v = twoPi * static_cast<float>(iv) / static_cast<float>(resolution);
|
|
54
|
+
float cosV = std::cos(v);
|
|
55
|
+
float sinV = std::sin(v);
|
|
56
|
+
|
|
57
|
+
float r = a + b * cosV;
|
|
58
|
+
|
|
59
|
+
vertices.emplace_back(
|
|
60
|
+
r * cosU,
|
|
61
|
+
r * sinU,
|
|
62
|
+
b * sinV * cosHalfU,
|
|
63
|
+
b * sinV * sinHalfU
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return vertices;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} // namespace vib3
|