Declarative three.js custom renderer for Luna
Dependencies
moon add mizchi/luna_three@0.1.0
moon add mizchi/three@0.1.3
moon add mizchi/luna@0.24.1
moon add mizchi/signals@0.6.5
pnpm add three@0.185.1 @mizchi/three-mbt@link:./.mooncakes/mizchi/three/js// moon.pkg
import {
"mizchi/three",
"mizchi/luna_three" @lt,
"mizchi/luna/core" @luna,
"mizchi/luna/js/resource" @reactivity,
"mizchi/signals",
}
supported_targets = "js"let x = @reactivity.signal(0.0)
let scene = @three.Scene()
let root = @lt.mount(scene.as_object3d(), @luna.component(fn() {
@lt.group([
@lt.mesh(
geometry=Box(1, 1, 1),
material=Standard(0x49c6bb, 0.4, 0.2),
props=[
@lt.prop(Name("box")),
@lt.dynamic(fn() { Position(x.get(), 0, 0) }),
],
),
@lt.ambient_light(intensity=2),
@lt.directional_light(props=[@lt.prop(Position(3, 5, 4))]),
])
}))
x.set(2.0) // Updates the existing mesh synchronously.
// Render/export scene with mizchi/three, then release this tree:
root.unmount()@luna.for_each(fn() {
items.get().map(fn(id) {
@lt.mesh(
key=id,
geometry=Sphere(0.5, 24, 16),
material=Basic(0xffb86b),
props=[@lt.prop(Name(id))],
)
})
})just test-luna-three
just test-luna-three-browser
just mouse
# http://127.0.0.1:4173/luna-three.html
just build-mouse
# _build/mouse-site/luna-three.htmlpub(all) enum Geometry {
Box(Double, Double, Double)
Sphere(Double, Int, Int)
Plane(Double, Double)
Cylinder(Double, Double, Double, Int)
Cone(Double, Double, Int)
Torus(Double, Double, Int, Int)
Borrowed(BufferGeometry)
}pub(all) enum Property {
Key(String)
Name(String)
Position(Double, Double, Double)
Rotation(Double, Double, Double)
Scale(Double, Double, Double)
Visible(Bool)
CastShadow(Bool)
ReceiveShadow(Bool)
Geometry(Geometry)
Material(Material)
Light(Int, Double)
Perspective(Double, Double, Double, Double)
Object(Object3D)
}pub struct Root {
// private fields
}Install
Download zipDeclarative three.js custom renderer for Luna
Dependencies