Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.4

0.11.4 / examples / scripts / galaxy_fog.prisma

#prisma 4.0
def luced3d "scene" {
    int display = 2
    int next_id = 3
    bool preview = true
    int scope = -1
    int selected = 2
    int take = 0
    float64[4] time = [1, 1, 240, 24]
    str units = "mm"
    int version = 1
    def network "nodes" {
        def Script "n2" {
            int edit_count = 0
            bool enabled = true
            str frozen = ""
            int guard = 0
            str[0] hidden = []
            int id = 2
            float64[2] inputs = [-1, -1]
            str name = "Script 2"
            int output = 1
            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 = -1
            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[1] cameras = [""]
            float64[1] counts = [0]
            float64[1] enabled = [1]
            str[1] hidden = [""]
            float64[1] ids = [2]
            str name = "Main"
            float64[0] transforms = []
            float64[1] visible = [1]
        }
    }
    def editor_view "view" {
        float64[6] camera = [0.69999999999999996, 0.55000000000000004, 9.387306113079573, -0.014999999664723873, -0.014999999664723873, -0.014999999664723873]
        float64[3] network = [1, 0, 0]
    }
}