Origin Scripting Language
  • Basics
    • Syntax
    • Types
    • The Execution Loop
    • Defining Variables
      • Clone Objects (=)
      • References To Objects/Variables (@=)
    • Assignment Operators
    • Local Scoping
    • Typed Variables
  • Operators
    • Mathematical Usage
      • Addition Operator (+)
      • Subtraction Operator (-)
      • Divide Operator (/)
      • Multiply Operator (*)
      • To The Power Of (^)
      • Modulo Operator (%)
    • Text Usage
    • String Concatenation Operator (+)
    • Array Operations
    • Comparative Operators
    • Logical Operators
    • Bitwise operators
    • Pipe Operator (|>)
    • Nullish Coalescing Operator (??)
  • Program Flow
    • If Statements
      • if truthy (
      • ) else if truthy (
      • ) else (
      • )
    • Switch Case
    • Iteration
    • While And Until
    • Dynamic OSL Execution
  • Arrays And Objects
    • Making Arrays Or Objects
    • Modifying An Array
    • Clone Objects And References
    • Object Operations
    • Object Property Shorthand
  • Environment
    • The Window System
    • Mouse Cursor
    • Camera
    • Sound System
    • Input Simulation
    • Running Other Languages
    • Notifications
    • Send Data Between Windows
    • Interfacing With Rightclick
    • Permissions
    • Files
      • What is a file? (in ofsf)
      • Creating Directories
      • open("file_path")
      • fileGet(int)
      • listFiles()
  • Storage
    • Save DB
    • Local DB
  • Custom Syntax
    • Commands
    • Methods
    • Functions
    • Inline
    • Lambda
    • Spread Operator
    • Typed Parameters
    • Classes
    • Promises
  • External
    • Make An Iframe App
  • Commands
    • Debugging
      • log "hello world"
      • warn "you should change this"
      • error "something went wrong"
      • void expression
    • Rendering
      • Basics
        • Color Commands
        • Color Picker
        • Modifiers
      • Draw Cursor
        • goto x y
        • set_x x
        • set_y y
        • change_x x
        • change_y y
        • change x y
        • loc a b c d
      • Elements
        • Canvas
        • Rectangle
        • Triangle
        • Icon
        • Text
        • Image
        • Input
        • Pen
        • Hitbox
        • Bar
        • Slider
      • ICN (Icon System)
        • Drawing Commands
        • Dynamic Icons
      • Clipping And Scrolling (frames)
      • 3D Rendering
  • Functions
    • Math
      • Math()
      • random(low,high)
      • min(num1,num2)
      • max(num1,num2)
      • lcm(num1,num2)
      • gcd(num1,num2)
      • sum(num1,..)
      • average(num1,..)
      • dist(x1,y1,x2,y2)
      • degtorad(angle)
      • radtodeg(angle)
      • noise(x, y, z)
      • octaveNoise(x, y, z, octaves, persistence)
    • Types
      • typeof(value)
      • symbol(name)
    • Encoding
      • encodeURIComponent(string)
      • decodeURIComponent(string)
      • btoa/atob(string)
    • function()
    • formatFileSize(bytes)
    • getGamepads()
    • import(path)
    • ouidNew()
    • parseFilePath(path)
  • Global Variables
    • Overview
    • System Information
    • User Information
    • Date and Time
    • Input State
    • Display and UI
    • Network
    • File System
  • Methods
    • Strings
      • .padStart(num,val)
      • .padEnd(num,val)
      • .startsWith(val)
      • .endsWith(val)
      • .wrapText(characters)
      • .trimText(characters)
      • .split(characters)
      • .count(val)
      • .replace(old,new)
      • .replaceFirst(old,new)
      • .oslTokenise()
      • .strip()
      • .toOrdArray()
      • .match(pattern)
      • Encoding
        • .encodeBin()
        • .decodeBin()
        • .encodeHex()
        • .decodeHex()
        • .encodeUTF16()
        • .decodeUTF16()
        • .encrypt(password)
        • .decrypt(password)
        • .ord()
        • .chr()
      • Hashing
        • .hashMD5()
        • .hashSHA1()
        • .hashSHA256()
        • .hashSHA512()
      • Case
        • .toLower()
        • .toUpper()
        • .toMixed()
        • .toTitle()
    • Keyboard
      • .isKeyDown()
      • .onKeyDown()
    • Utilities
      • .len
      • .not
      • .ask()
      • .reverse()
      • .first()
      • .last()
      • .append(val)
      • .prepend(val)
      • .insert(location,val)
      • .delete(location)
      • .concat(val)
      • .trim(idx1,idx2)
      • .left(num)
      • .right(num)
      • .contains(val)
      • .index(val)
    • Maths
      • .abs()
      • .invabs()
      • .log()
      • .ln()
      • .isPrime()
      • .sqrt()
      • .sign()
      • .chance()
      • .clamp(low,high)
      • .toBase(base)
      • Rounding
        • .round(places)
        • .ceiling()
        • .floor()
      • Trigonometry
        • .sin
        • .cos
        • .tan
        • .asin()
        • .acos()
        • .atan()
        • .radSin()
        • .radCos()
    • Iframes
      • .iframeNew()
      • .iframeGoto()
      • .iframeResize()
      • .iframeRedirect()
      • .iframeShow()
      • .iframeHide()
      • .iframeClose()
    • JSON
      • Arrays
        • .pop()
        • .shift()
        • .randomOf()
        • .sort(direction)
        • .sortBy(key,direction)
        • .swap(idx1,idx2)
        • .fill(value)
        • .join(characters)
        • .map(callback)
        • .filter(callback)
        • .some(callback)
        • .every(callback)
      • Objects
        • .getKeys(keys)
        • .getValues()
      • .JsonStringify()
      • .JsonParse()
      • .JsonFormat()
      • .JsonClean()
    • Types
      • .getType()
      • .isType(type)
      • .toNum()
      • .toBool()
      • .toStr()
    • Functions
      • .bind(context)
    • Networking
      • .httpGet()
      • .http(method,data,headers)
      • .getAsync()
      • .roturConnect()
      • .roturSend(msg,target)
      • Websockets
        • .newWebsocket()
        • .wsSend(msg)
        • .wsClose()
        • .wsOpen()
        • .wsHasnew()
        • .wsGetnext()
        • .wsGetcount()
    • Timestamp
      • .timestamp("convert-date")
      • .timestamp("component")
Powered by GitBook
On this page
  • Setting Up the Environment
  • Initialize 3D Rendering
  • Camera Setup
  • Mesh Management
  • Creating and Deleting Meshes
  • Mesh Data Operations
  • Transformation and Rendering
  • Transform Operations
  • Space Management
  • Mesh Properties
  • Example: Interactive 3D Scene
  • Important Notes

Was this helpful?

Edit on GitHub
  1. Commands
  2. Rendering

3D Rendering

OSL provides a powerful 3D rendering system for creating three-dimensional graphics and interactive environments.

Note: The 3D system only works on apps in fullscreen mode.

Setting Up the Environment

Initialize 3D Rendering

3dr "setup"  // Puts the window into fullscreen mode

Camera Setup

// Perspective projection
3dr "setup_perspective" fov min_distance max_distance

// Orthographic projection
3dr "setup_orthographic" min_distance max_distance

Mesh Management

Creating and Deleting Meshes

// Create a new mesh
mesh = newMesh()  // Returns a mesh ID

// Delete a mesh
mesh.meshDelete()

// Check if mesh exists
mesh.meshExists()  // Returns boolean

Mesh Data Operations

// Load mesh from OBJ format
3dr "set_mesh_to_obj" mesh obj_line_array

// Create 2D plane mesh
3dr "set_mesh_xy" mesh array_x array_y

// Create 3D mesh
3dr "set_mesh_xyz" mesh array_x array_y array_z

// Set mesh blending mode
3dr "set_mesh_blending" mesh mode
// Modes: "default", "additive", "subtractive", "multiply", "invert", "mask", "erase"

// Set mesh culling
3dr "set_mesh_culling" mesh mode
// Modes: "nothing", "back faces", "front faces"

Transformation and Rendering

Transform Operations

// Reset transformation matrix
3dr "reset_transform"

// Translate mesh
3dr "transform_xyz" x y z

// Scale mesh
3dr "scale_xyz" x y z  // Default: 1,1,1

// Draw mesh
3dr "draw_mesh" mesh

// Draw mesh at position
3dr "draw_mesh_at" mesh x y z

Space Management

// Switch to view space
3dr "to_view_space"

// Switch to world space
3dr "to_world_space"

// Transform from view to world space
3dr "transform_view_to_world" x y z

Mesh Properties

// Check mesh existence
mesh.meshExists()  // Returns boolean

// Check texture status
mesh.meshHasTexture()  // Returns boolean

Example: Interactive 3D Scene

// Setup 3D environment
3dr "setup"

// Camera position
cam_x = 0
cam_y = 3
cam_z = 0

// Create textured plane
plane = newMesh()
plane_x = [-1,1,-1,-1,1,1]
plane_y = [-1,-1,1,1,-1,1]
3dr "set_mesh_xy" plane plane_x plane_y

// Setup camera
3dr "setup_perspective" 90 0.01 1000

mainloop:
    // Camera rotation
    3dr "to_view_space"
    3dr "reset_transform"
    3dr "rotate" "x" 0 - mouse_y
    3dr "rotate" "y" 0 - mouse_x
    
    // Movement
    tx = ("a".pressed - "d".pressed) * delta_time * 20
    tz = ("w".pressed - "s".pressed) * delta_time * 20
    
    // Update camera position
    3dr "transform_view_to_world" tx 0 tz
    cam_x += 3drTransformX()
    cam_z += 3drTransformZ()
    
    // Render scene
    3dr "clear"
    3dr "to_world_space"
    3dr "reset_transform"
    3dr "draw_mesh" plane

Important Notes

  1. Performance Considerations

    • Minimize mesh updates during runtime

    • Use appropriate culling modes

    • Optimize texture sizes and formats

  2. Best Practices

    • Always check mesh existence before operations

    • Clean up unused meshes

    • Use delta_time for smooth animations

    • Handle fullscreen mode appropriately

  3. Limitations

    • Only works in fullscreen mode

    • Performance depends on browser capabilities

    • Mesh complexity affects rendering speed

  4. Camera Controls

    • Use mouse for rotation

    • WASD for movement

    • Consider adding smooth transitions

    • Implement collision detection if needed

PreviousClipping And Scrolling (frames)NextMath

Last updated 3 months ago

Was this helpful?