121 lines
3.0 KiB
Markdown
121 lines
3.0 KiB
Markdown
## Core API
|
|
Set style ps1 / n64 / saturn
|
|
|
|
set_style("ps1" | "n64" | "saturn")
|
|
|
|
Get time since game boot, in seconds
|
|
time()
|
|
|
|
Get runtime statistics
|
|
stat(name: "draw_calls" | "triangles" | "fps" | "memory_bytes")
|
|
|
|
log(...args: any)
|
|
|
|
set_lighting({
|
|
sun_dir: [0.3,-1,0.2], // normalized internally
|
|
sun_color: [1,1,1], // rgb
|
|
ambient: [0.25,0.25,0.25] // rgb
|
|
})
|
|
|
|
set_fog({
|
|
enabled: false,
|
|
color: [0.5,0.6,0.7],
|
|
near: 10,
|
|
far: 80
|
|
})
|
|
|
|
// lance3d material
|
|
{
|
|
color_map: texture | null, // optional
|
|
paint: color, // required (default: white)
|
|
coverage: "opaque" | "cutoff" | "blend",
|
|
face: "single" | "double",
|
|
lamp: "lit" | "unlit"
|
|
}
|
|
|
|
## Draw API
|
|
Loads a gltf model, returning an array of {mesh, material}, with materials compressed into a render3d material
|
|
load_model(path) -> array<{mesh, material}>
|
|
|
|
make_cube(w, h, d) -> mesh
|
|
make_sphere(r, segments=12) -> mesh
|
|
make_cylinder(r, h, segments=12) -> mesh
|
|
make_plane(w, h) -> mesh
|
|
|
|
Gets information about the animations on a model
|
|
anim_info(model)
|
|
|
|
Generates a pose that can be applied to a model
|
|
sample_pose(model, name, time)
|
|
|
|
Draws a model with a given base transform
|
|
draw_model(model, transform=null, pose=null)
|
|
|
|
Draws a mesh with a material
|
|
draw_mesh(mesh, transform=null, material=null)
|
|
|
|
load_sound(path) -> sound | null
|
|
|
|
play_sound(sound, opts={
|
|
volume: 1.0, // 0..1
|
|
pitch: 1.0, // 1.0 = normal
|
|
pan: 0.0, // -1 = left, 0 = center, 1 = right
|
|
loop: false // boolean
|
|
}) -> voice
|
|
|
|
stop_sound(voice)
|
|
|
|
// when drawing, a provided material will override defaults for the system
|
|
load_texture(path) -> texture
|
|
draw_billboard(texture, x, y, z, size=1.0, mat=null)
|
|
draw_sprite(texture, x, y, size=1.0, mat=null)
|
|
|
|
## Camera API
|
|
camera_look_at(
|
|
ex, ey, ez, // eye
|
|
tx, ty, tz, // target
|
|
upx = 0, upy = 1, upz = 0
|
|
)
|
|
|
|
camera_perspective(fov_deg=60, near=0.1, far=1000)
|
|
camera_ortho(left, right, bottom, top, near=-1, far=1)
|
|
|
|
## Collision API
|
|
add_collider_sphere(transform, radius, opts={layer_mask:1, user:null}) -> collider
|
|
add_collider_box(transform, sx, sy, sz, opts={layer_mask:1, user:null}) -> collider
|
|
|
|
overlaps(layer_mask_a=null, layer_mask_b=null) -> array<{a: collider, b: collider}>
|
|
|
|
raycast(ox,oy,oz, dx,dy,dz, opts={
|
|
max_dist: Infinity,
|
|
layer_mask: 0xFFFFFFFF
|
|
}) -> null | {x,y,z, nx,ny,nz, distance, collider}
|
|
|
|
retro3d.remove_collider(collider)
|
|
|
|
## Input
|
|
btn(id, player=0) -> bool // held
|
|
btnp(id, player=0) -> bool // pressed this frame
|
|
|
|
## Math
|
|
seed(seed_int)
|
|
rand() -> number // [0,1)
|
|
irand(min_inclusive, max_inclusive) -> int
|
|
|
|
## Debug API
|
|
vertex {x, y, z, u=0, v=0, color}
|
|
point(vertex, size=1.0)
|
|
line(vertex_a, vertex_b, width=1.0)
|
|
grid(size, step, norm = {x:0,y:1,z:0}, color)
|
|
|
|
triangle(vertex_a, vertex_b, vertex_c, mat=null)
|
|
ray(ox,oy,oz, dx,dy,dz, len, opts)
|
|
|
|
aabb(cx,cy,cz, ex,ey,ez, opts) // center+extents
|
|
obb(transform, sx,sy,sz, opts) // oriented via transform
|
|
frustum(camera_state_or_params, opts)
|
|
text3d(str, x,y,z, opts={size_px:12, depth:"always"|"test"})
|
|
|
|
Render a specific collider
|
|
collider(collider, color)
|