Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / examples / scripts / galaxy_fog.prisma

#prisma 4.0
def luced3d "scene" {
    int display = 3
    int next_id = 4
    int scope = 2
    int selected = 3
    int take = 0
    float64[4] time = [1, 1, 240, 24]
    float64[4] tolerances = [0.01, 0.001, 0.0017453292519943296, 0.0050000000000000001]
    str units = "mm"
    int version = 1
    def network "nodes" {
        def Geo "n2" {
            int edit_count = 0
            bool enabled = true
            str frozen = ""
            int guard = 0
            int held_actions = 0
            str held_aligns = ""
            str held_failure = ""
            str held_file = ""
            int held_input = 0
            int held_key = 0
            str held_note = ""
            str[0] hidden = []
            int id = 2
            float64[0] inputs = []
            str name = "Geo 2"
            float64[48] parameters = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
            int parent = -1
            float64[2] position = [40, 70]
            float64[0] sources = []
            str[3] texts = ["", "weight", "renamed"]
            bool time_dependent = false
            bool visible = true
            def recipes "edits" {
            }
        }
        def Script "n3" {
            int edit_count = 0
            bool enabled = true
            str frozen = ""
            int guard = 0
            int held_actions = 0
            str held_aligns = ""
            str held_failure = ""
            str held_file = ""
            int held_input = 0
            int held_key = 0
            str held_note = ""
            str[0] hidden = []
            int id = 3
            float64[2] inputs = [-1, -1]
            str name = "Script 3"
            float64[64] parameters = [30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40000, 0.029999999999999999, 2.2000000000000002, 0.12, 8, 0.75, 0.80000000000000004, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
            int parent = 2
            float64[2] position = [0, 0]
            float64[2] sources = [0, 0]
            str[13] texts = ["", "## A spiral galaxy as a sparse fog volume: stars scattered along two arms,\n## each splatted into the voxels around it. Leaves are made only where\n## stars land, so the empty space between the arms costs nothing.\nfrom luce_std import math32\nfrom luce_geocore.script import Cook, Geometry, VolumeClass\n\n## The next number of a small deterministic random sequence, in 0..1.\nfunc next(seed: u64*) -> f32:\n    *seed = *seed *% 6364136223846793005 +% 1442695040888963407\n    return (f32)(*seed >> 40) / 16777216.0\n\npub func cook(k: Cook*) -> !:\n    let stars = k.i32(\"stars\", 40000)\n    let voxel = k.f32(\"voxel\", 0.03)\n    let twist = k.f32(\"twist\", 2.2)\n    let glow = k.f32(\"glow\", 0.12)\n    var g = try Geometry.empty()\n    # Sparse: the box is empty until stars write into it.\n    let fog = try g.add_volume(\"density\", VolumeClass.fog, [0.0, 0.0, 0.0, 0.0], [4.0, 1.0, 4.0, 0.0], voxel = (f64)voxel, dense = false)\n    var seed: u64 = 7\n    for s in 0..<stars:\n        # Two arms, denser and thicker toward the core.\n        let arm = (f32)(s % 2) * math32.pi\n        let r = next(&seed)\n        let radius = 0.08 + r * r * 1.8\n        let angle = arm + radius * twist + (next(&seed) - 0.5) * 0.9 * (1.0 - r * 0.6)\n        let wobble = (next(&seed) - 0.5) * 0.15\n        let height = (next(&seed) - 0.5) * 0.25 * (1.0 - r) * (1.0 - r)\n        let at = fog.to_index([math32.cos(angle) * (radius + wobble), height, math32.sin(angle) * (radius + wobble), 0.0])\n        let ci = (i64)math32.floor(at[0])\n        let cj = (i64)math32.floor(at[1])\n        let ck = (i64)math32.floor(at[2])\n        # A soft blob over the 3x3x3 voxels around the star.\n        for dz in 0..<3:\n            for dy in 0..<3:\n                for dx in 0..<3:\n                    let i = ci + (i64)dx - 1\n                    let j = cj + (i64)dy - 1\n                    let n = ck + (i64)dz - 1\n                    let ox = at[0] - (f32)i\n                    let oy = at[1] - (f32)j\n                    let oz = at[2] - (f32)n\n                    let weight = math32.exp(-(ox * ox + oy * oy + oz * oz) * 1.2) * glow\n                    try fog.set(i, j, n, fog.get(i, j, n) + weight)\n    # How the viewport draws the grid (its look, as the Volume Visualization\n    # node sets it): thick, softly shadowed, tinted smoke.\n    try fog.set_look(density = (f64)k.f32(\"density\", 8.0), shadow = 0.4, smoke = k.color(\"tint\", [0.75, 0.8, 1.0, 0.0]))\n    print(f\"{stars} stars in {fog.count() // 512} leaves, {fog.active_count()} voxels\")\n    try k.set_geometry(g)\n", "", "stars\t16\t1\t1\nvoxel\t17\t1\t0\ntwist\t18\t1\t0\nglow\t19\t1\t0\ndensity\t20\t1\t0\ntint\t21\t3\t0\tcolor\t", "", "", "", "", "", "", "", "", ""]
            bool time_dependent = false
            bool visible = true
            def recipes "edits" {
            }
        }
    }
    def takes "takes" {
        def take "t0" {
            str[2] cameras = ["", ""]
            float64[2] counts = [12, 0]
            float64[2] enabled = [1, 1]
            str[2] hidden = ["", ""]
            float64[2] ids = [2, 3]
            str name = "Main"
            float64[12] transforms = [0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0]
            float64[2] visible = [1, 1]
        }
    }
    def editor_view "view" {
        float64[3] network = [1, 0, 0]
        float64[46] panes = [0, 1, 1, -1, 0, 1.5707963267948966, 9, 0, 0.80000000000000004, 0, 0, 1, 45, 0, -1, 0.69999999999999996, 0.55000000000000004, 9.387306113079573, -0.014999999664723873, -0.014999999664723873, -0.014999999664723873, 0, 0, 45, 3, -1, 0, 0, 9, 0, 0.80000000000000004, 0, 0, 1, 45, 6, -1, 1.5707963267948966, 0, 9, 0, 0.80000000000000004, 0, 0, 1, 45]
    }
}