alice_lol/lib.rs
1//! # ALICE-LOL: Law-Oriented Language
2//!
3//! A text language for signed distance fields: the `lol!` macro (compile time)
4//! and [`runtime_parser`] (run time) turn the same text into an
5//! [`SdfNode`] tree, which can be evaluated on the CPU, transpiled to
6//! GLSL / WGSL / HLSL, exported for 3D printing, and checked against
7//! geometric constraints ([`law`]). [`research_law`] holds unit-checked
8//! formulas with valid ranges, residuals and provenance.
9//!
10//! ```rust
11//! use alice_lol::lol;
12//! use alice_lol::runtime_parser::parse_lol;
13//! use alice_lol::Vec3;
14//!
15//! // Compile time: the macro builds the tree
16//! let scene = lol! {
17//! smooth_union(0.2,
18//! sphere(1.0),
19//! translate(2.0, 0.0, 0.0, box3d(0.5, 0.5, 0.5))
20//! )
21//! };
22//!
23//! // Run time: the same text through the parser (from a file or a language model)
24//! let parsed = parse_lol(
25//! "smooth_union(0.2, sphere(1.0), translate(2.0, 0.0, 0.0, box3d(0.5, 0.5, 0.5)))",
26//! )
27//! .unwrap();
28//!
29//! // Both are the same field; the origin is inside the sphere
30//! let p = Vec3::new(0.3, 0.1, 0.0);
31//! assert_eq!(alice_lol::eval(&scene, p), alice_lol::eval(&parsed, p));
32//! assert!(alice_lol::eval(&scene, Vec3::ZERO) < 0.0);
33//!
34//! // GLSL source for a shader (default feature `glsl`)
35//! let glsl = alice_lol::to_glsl(&scene);
36//! assert!(!glsl.is_empty());
37//! ```
38
39// ── ランタイム LOL パーサー(LLM Text-to-3D 用) ──
40// `parse_lol("sphere(1.0)")` → `SdfNode` に変換
41/// The LOL DSL grammar (`lol.gbnf`, GBNF) as shipped with this crate version.
42///
43/// Feature-free on purpose: downstream crates (the pipeline crate → text-to-print,
44/// or any llama.cpp-compatible runtime) embed the *same* bytes instead of
45/// keeping a copy that drifts. With `llm-bridge` enabled,
46/// [`bridge::lol_grammar`] parses exactly this text.
47///
48/// The grammar is deliberately stricter than [`runtime_parser`] (no `//`
49/// comments, at most one whitespace char between tokens); see the file
50/// header for why.
51pub const LOL_GBNF: &str = include_str!("../lol.gbnf");
52
53pub mod runtime_parser;
54
55pub mod limits;
56
57/// Canonicalizing a user-supplied angle before it is converted to radians
58pub mod angle;
59
60/// `SdfNode` → LOL text (runtime parser の逆変換、Track C0)
61pub mod emit;
62
63/// When two evaluations of a field agree (IEEE-total: ±∞ and NaN are results)
64pub mod parity;
65
66// ── 3Dプリント向けエクスポート ──
67// LOL → SdfNode → Mesh → STL/3MF のワンストップパイプライン
68pub mod print_export;
69
70// ── Roblox 向けエクスポート ──
71// LOL → SdfNode → Mesh → OBJ/FBX (MeshPart / アクセサリー用)
72#[cfg(feature = "roblox")]
73pub mod roblox_export;
74
75// ── LLM Guided Generation ブリッジ (Phase X.8 B-6) ──
76// alice-llm の GBNF parser + FSM + logits mask を薄く再輸出し、
77// `lol.gbnf` の LazyLock cached parse を提供する
78#[cfg(feature = "llm-bridge")]
79pub mod bridge;
80
81// ── レーザー彫刻向け2Dパターン生成 ──
82// hatch, crosshatch, halftone, dither, guilloche, lissajous, rose, phyllotaxis, turing
83pub mod laser_pattern;
84
85// ── 空間枝刈りコンパイラ ──
86pub mod pruned_compile;
87
88// ── 法則(Law)制約チェッカー ──
89// LawSet ビルダー、静的矛盾検出、残差フィルタリング
90pub mod law;
91pub mod law_id;
92
93// ── 幾何評価 (text→`SdfNode`→評価結果) の意味論の識別子 ──
94// `law_id` (監査 / 研究 Law 専用) とは別軸: rotate/rotate_q の算術世代・TPMS の
95// 受理境界・emit の canonical form 等、`SdfNode` の数値評価そのものを pin する
96pub mod geometry_id;
97
98// ── 研究 Law (単位付きの多変数の式 + 成立範囲 + 残差 + 出典 + oracle) ──
99// 上の `law` (SDF の幾何制約チェッカー) とは別物: データに対する主張としての式を扱う
100pub mod research_law;
101
102// ── 監査 Law (検査器が何件比べたか / 既知の違反がどこまでか を主張する) ──
103// 上の 2 つとも別物: 一致を検査する対象が測定そのもので、判定は 6 値
104pub mod audit_law;
105
106// ── 入力の読み方 (型を持つ x-input と request の JSON) ──
107// 型に合わない値は入力全体が合わない: 監査は測られていない、量の法則は拒否
108pub mod law_input;
109
110// ── 構文名の一覧 (parser の dispatch と README の構文表を突き合わせる test 専用) ──
111#[cfg(test)]
112mod syntax_table;
113
114// ── Intent Layer (Milestone B.1、Phase 3 Intent 相 IR skeleton) ──
115// IntentNode + Program 独立型、GPU backend との型分離、L1 Physical Intent 14 verb + Sequence/Parallel
116pub mod intent;
117
118// ── Standard Library (Phase A.1、hardsurface primitive collection) ──
119// 実プリント検証済みの機械要素 primitive (fastener/joint/reinforcement/mount) を SdfNode helper で提供
120pub mod stdlib;
121
122// ── crate 内専用の決定論的 max / min (clippy-lib gate が f32/f64::max/min 直呼びを禁止) ──
123mod det_math;
124
125// ── G2: 証明済みに安全な raw max/min 呼び出しの唯一の置き場 (scripts/raw_minmax_manifest.py が数える) ──
126mod raw_minmax;
127
128// ── Re-export the proc_macro ──
129pub use alice_lol_macro::lol;
130
131// ── Re-exports used by macro-generated code ──
132pub use alice_sdf::SdfNode;
133pub use glam::{EulerRot, Quat, Vec2, Vec3};
134
135// ── Transpile functions ──
136
137/// Transpile an `SdfNode` tree to GLSL (hardcoded constants).
138#[must_use]
139#[cfg(feature = "glsl")]
140pub fn to_glsl(node: &SdfNode) -> String {
141 use alice_sdf::compiled::glsl::{GlslShader, GlslTranspileMode};
142 GlslShader::transpile(node, GlslTranspileMode::Hardcoded).source
143}
144
145/// Transpile an `SdfNode` tree to GLSL with dynamic parameters (uniform block).
146#[must_use]
147#[cfg(feature = "glsl")]
148pub fn to_glsl_dynamic(node: &SdfNode) -> String {
149 use alice_sdf::compiled::glsl::{GlslShader, GlslTranspileMode};
150 GlslShader::transpile(node, GlslTranspileMode::Dynamic).source
151}
152
153/// Transpile an `SdfNode` tree to WGSL (hardcoded constants).
154#[must_use]
155#[cfg(feature = "wgsl")]
156pub fn to_wgsl(node: &SdfNode) -> String {
157 use alice_sdf::compiled::wgsl::{TranspileMode, WgslShader};
158 WgslShader::transpile(node, TranspileMode::Hardcoded).source
159}
160
161/// Transpile an `SdfNode` tree to WGSL with dynamic parameters.
162#[must_use]
163#[cfg(feature = "wgsl")]
164pub fn to_wgsl_dynamic(node: &SdfNode) -> String {
165 use alice_sdf::compiled::wgsl::{TranspileMode, WgslShader};
166 WgslShader::transpile(node, TranspileMode::Dynamic).source
167}
168
169/// Transpile an `SdfNode` tree to HLSL (hardcoded constants).
170#[must_use]
171#[cfg(feature = "hlsl")]
172pub fn to_hlsl(node: &SdfNode) -> String {
173 use alice_sdf::compiled::hlsl::{HlslShader, HlslTranspileMode};
174 HlslShader::transpile(node, HlslTranspileMode::Hardcoded).source
175}
176
177/// Transpile an `SdfNode` tree to HLSL with dynamic parameters.
178#[must_use]
179#[cfg(feature = "hlsl")]
180pub fn to_hlsl_dynamic(node: &SdfNode) -> String {
181 use alice_sdf::compiled::hlsl::{HlslShader, HlslTranspileMode};
182 HlslShader::transpile(node, HlslTranspileMode::Dynamic).source
183}
184
185/// フルレンダリングパイプライン付きGLSLを生成
186///
187/// PBR (Cook-Torrance), 大気散乱, 昼夜サイクル, 天候, ポストプロセスを含む
188/// 完全なフラグメントシェーダーを出力する。
189#[must_use]
190#[cfg(feature = "glsl")]
191pub fn to_glsl_full(node: &SdfNode, config: &RenderConfig) -> String {
192 use alice_sdf::compiled::glsl::{GlslShader, GlslTranspileMode};
193 GlslShader::transpile(node, GlslTranspileMode::Hardcoded).to_fragment_shader_full(config)
194}
195
196// ── RenderConfig re-export ──
197#[cfg(feature = "glsl")]
198pub use alice_sdf::compiled::glsl::RenderConfig;
199
200/// Evaluate the SDF distance at a single point (CPU).
201#[must_use]
202pub fn eval(node: &SdfNode, point: Vec3) -> f32 {
203 alice_sdf::eval(node, point)
204}
205
206// ── Interval arithmetic re-exports (for spatial pruning) ──
207pub use alice_sdf::interval::{eval_interval, Interval, Vec3Interval};
208
209// ── Autodiff re-exports (勾配・曲率解析) ──
210pub use alice_sdf::autodiff::{
211 eval_hessian, eval_with_gradient, gaussian_curvature, mean_curvature, principal_curvatures,
212 Dual, Dual3,
213};
214
215// ── CompiledSdf re-exports (高速評価) ──
216pub use alice_sdf::compiled::{
217 eval_compiled, eval_compiled_batch_simd, eval_compiled_batch_simd_parallel,
218 eval_compiled_batch_soa, eval_compiled_batch_soa_parallel, eval_compiled_bvh,
219 eval_compiled_distance_and_normal, eval_compiled_normal, eval_compiled_simd, get_scene_aabb,
220 AabbPacked, CompileError, CompiledSdf, CompiledSdfBvh, Vec3x8,
221};
222
223// ── Physics bridge re-exports (物理連携) ──
224// alice-sdf 1.7.7 以降 physics_bridge / sim_bridge module は crates.io publish のため
225// alice-sdf 側 physics feature ごと削除済 (source 上は cfg-gate 保持) alice-sdf が
226// physics feature を復活させたら以下 pub use を再度有効化する
227// #[cfg(feature = "physics")]
228// pub use alice_sdf::physics_bridge::{sdf_to_physics_field, CompiledSdfField};
229// #[cfg(feature = "physics")]
230// pub use alice_sdf::sim_bridge::{attach_physics, simulate_sdf, SimulatedSdf};