Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / examples / scripts / jpeg_heightfield.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, 160, 0.5, 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, 0, 0, 0, 0, 0, 0]
            int parent = 2
            float64[2] position = [0, 0]
            float64[2] sources = [0, 0]
            str[13] texts = ["luce-image", "## A JPEG as a colored height field (luce-image reads it).\nfrom luce_geocore.script import Cook, Geometry\nfrom luce_image.image import Image\n\npub func cook(k: Cook*) -> !:\n    let path = k.file(\"image\", \"heightfield.jpg\")\n    let divisions = k.i32(\"divisions\", 160)\n    let height = k.f32(\"height\", 0.5)\n    let opened = try Image.open(path)\n    defer opened.release()\n    let image = try opened.get()\n    let w = try image.width()\n    let h = try image.height()\n    let size: f32 = 4.0\n    var grid = try Geometry.grid(size = (f64)size, divisions = (i64)divisions)\n    let positions = try grid.positions()\n    let colors = try grid.point_vec3s(\"Cd\")\n    for i in 0..<positions.length:\n        # The grid spans -size/2..size/2 in X and Z: the pixel under the point.\n        let u = (usize)(fit(positions[i].x / size + 0.5) * (f32)(w - 1))\n        let v = (usize)(fit(positions[i].z / size + 0.5) * (f32)(h - 1))\n        let r = (f32)(try image.get_sample(u, v, 0)) / 255.0\n        let g = (f32)(try image.get_sample(u, v, 1)) / 255.0\n        let b = (f32)(try image.get_sample(u, v, 2)) / 255.0\n        positions[i].y = (0.2126 * r + 0.7152 * g + 0.0722 * b) * height\n        colors[i].x = r\n        colors[i].y = g\n        colors[i].z = b\n    print(f\"{w} x {h} pixels onto {positions.length} points\")\n    try k.set_geometry(grid)\n\n## `t` held to 0..1.\nfunc fit(t: f32) -> f32:\n    return 0.0 if t < 0.0 else (1.0 if t > 1.0 else t)\n", "", "image\t5\t0\t0\tfile\t\ndivisions\t16\t1\t1\nheight\t17\t1\t0", "", "heightfield.jpg", "", "", "", "", "", "", ""]
            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, 10.221173912774946, 0, 0.25133157172240317, 0, 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]
    }
}