OSL 3dr System - Mistium/Origin-OS GitHub Wiki
Info
The 3d system only works on apps in fullscreen
Setting up the 3d environment
Starting the environment
3dr "setup"
// this puts the window into fullscreen so that the scripts can run
Setting up the camera
3dr "setup_perspective" fov min max
3dr "setup_orthographic" min max
// min and max are the minimum and maximum draw distances for rendering
Managing assets
Making and deleting a mesh
mesh = newMesh()
// returns a mesh id and makes a new mesh
mesh.meshDelete()
// delete the mesh
log mesh.meshExists()
// logs true/false of if the mesh exists
Editing Mesh Data
3dr "set_mesh_to_obj" mesh obj_as_array
// load the mesh as an obj through an array of each line
3dr "set_mesh_xy" mesh array_x array_y
// load the mesh as a 2d plane with each point inside of 2 arrays
3dr "set_mesh_xyz" mesh array_x array_y array_z
// load the mesh as a 3d shape with each point inside of 3 arrays
3dr "set_mesh_blending" mesh "default"/"additive"/"subtractive"/"multiply"/"invert"/"mask"/"erase"
// set the render mode of the mesh
3dr "set_mesh_culling" mesh "nothing"/"back faces"/"front faces"
// change the culling of the mesh
Rendering a mesh
3dr "reset_transform"
// start a new transformation
3dr "transform_xyz" x y z
// change the position of the next rendered mesh by a set of x,y,z co-ords
3dr "scale_xyz" x y z
// scale the next rendered mesh by a multiplier, default is 1 for x, y and z
3dr "draw_mesh" mesh
3dr "draw_mesh_at" mesh x y z
// combines the transform_xyz command into the draw mesh command
Mesh info
log mesh.meshExists()
// mesh exists? true/false
log mesh.meshHasTexture()
// check if a mesh has a texture
Example code
3dr "setup"
cam_x = 0
cam_y = 3
cam_yv = 0
cam_z = 0
plane_x = [-1,1,-1,-1,1,1]
plane_y = [-1,-1,1,1,-1,1]
plane_u = [0,100,0,0,100,100]
plane_v = [0,0,100,100,0,100]
grid_texture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAABfSURBVFhH7daxCQBBCERRtxD7L8HAJjawC1sQ7uDgGtgNJvnmA8NLxpWZjx3czHwpdz9Im/35RQEEEEAAAQTkAhGhXUN5gaq6Eujuu3+AAggggAACCMgF9t7aNVQXeAH0+VkwQQSNOAAAAABJRU5ErkJggg=="
plane = meshNew()
3dr "set_mesh_xy" plane plane_x plane_y
3dr "set_mesh_texture_url" plane grid_texture "repeat"
3dr "set_texture_uv" plane plane_u plane_v
3dr "mipmap" plane "smooth"
3dr "start_perspective" 90 0.01 1000
// setup fov, mindist, maxdist
mainloop:
cursor "hide"
3dr "to_view_space"
// select the view space
3dr "reset_transform"
// start transformation
3dr "rotate" "x" 0 - mouse_y
3dr "rotate" "y" 0 - mouse_x
// camera rotation
tx = ( "a".pressed - "d".pressed ) * delta_time * 20
tz = ( "w".pressed - "s".pressed ) * delta_time * 20
// change movement speed by delta_time
3dr "transform_view_to_world" tx 0 tz
// movement
cam_x += 3drTransformX()
cam_yv -= delta_time * 5
cam_yv.clamp(-4,4)
cam_y += cam_yv / 10
cam_y.clamp(3,100)
// handle jump velocity
cam_z += 3drTransformZ()
3dr "transform_xyz" cam_x cam_y cam_z
// offset the camera position by the change
3dr "clear"
// clear the screen
3dr "to_world_space"
// select the world space
3dr "reset_transform"
// start a new transformation
3dr "scale_xyz" 100 100 100
// scale the mesh
3dr "rotate" "x" 90
// rotate the mesh
3dr "draw_mesh" plane
// render the "plane" mesh
loc 2 2 10 -20
text `${fps} ${cam_x} ${cam_y} ${cam_z}` 10
if "space".onpress and cam_y == 3 (
cam_yv = 4
// jump code
)
// render ui info
import "win-buttons"