Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/processing_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub enum ProcessingError {
TransformNotFound,
#[error("Material not found")]
MaterialNotFound,
#[error("Light not found")]
LightNotFound,
#[error("Light belongs to another graphics")]
LightOnOtherGraphics,
#[error("Unknown shader property: {0}")]
UnknownShaderProperty(String),
#[error("GLTF load error: {0}")]
Expand Down
12 changes: 12 additions & 0 deletions crates/processing_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,18 @@ pub extern "C" fn processing_light_create_spot(
.unwrap_or(0)
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_light(graphics_id: u64, light_id: u64) {
error::clear_error();
error::check(|| graphics_light(Entity::from_bits(graphics_id), Entity::from_bits(light_id)));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_light_destroy(light_id: u64) {
error::clear_error();
error::check(|| light_destroy(Entity::from_bits(light_id)));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_material_create_pbr() -> u64 {
error::clear_error();
Expand Down
5 changes: 1 addition & 4 deletions crates/processing_pyo3/examples/Basics/Camera/move_eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
# The camera lifts up (controlled by mouseY) while looking at the same point.
from mewnala import *

light = None


def setup():
global light
size(640, 360)
mode_3d()
fill(0.8)
light = directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.0)

# Change height of the camera with mouseY (the world is y-up)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
from mewnala import *

show_perspective = False
light = None


def setup():
global light
size(600, 360)
mode_3d()
no_fill()
fill(1.0)
no_stroke()
light = directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.0)
far = remap(mouse_x, 0, width, 120, 400)
if show_perspective:
Expand Down
5 changes: 1 addition & 4 deletions crates/processing_pyo3/examples/Basics/Camera/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
# to set the area precisely.
from mewnala import *

light = None


def setup():
global light
size(640, 360)
mode_3d()
no_stroke()
light = directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.0)
camera_y = height / 2.0
# A fov of 0 would divide by zero below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
def setup():
size(640, 360)
mode_3d()
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)
no_loop()


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.0)

no_stroke()
Expand Down
8 changes: 2 additions & 6 deletions crates/processing_pyo3/examples/Basics/Lights/directional.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
# scatters in all directions.
from mewnala import *

light = None


def setup():
global light
size(640, 360)
mode_3d()
no_stroke()
fill(0.8)
# Lights are created once; the shapes become lit once a material property is set
light = directional_light((0.8, 0.8, 0.8), 2500.0)
# The shapes become lit once a material property is set
roughness(0.6)


Expand All @@ -27,7 +23,7 @@ def draw():
dir_y = (mouse_y / height - 0.5) * 2
dir_x = (mouse_x / width - 0.5) * 2
# The world is y-up, so the vertical direction is flipped
light.look_at(-dir_x, dir_y, -1)
directional_light((0.8, 0.8, 0.8), 2500.0, look_at=(-dir_x, dir_y, -1))
translate(-100, 0, 0)
sphere(80)
translate(200, 0, 0)
Expand Down
33 changes: 14 additions & 19 deletions crates/processing_pyo3/examples/Basics/Lights/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,32 @@
# Display a box with three different kinds of lights.
from mewnala import *

point = None
directional = None
spot = None


def setup():
global point, directional, spot
size(640, 360)
mode_3d()
no_stroke()
roughness(0.6)


def draw():
background(0.0)

# Lights are created once; the world is y-up, so the y of every
# position and direction is flipped
# The world is y-up, so the y of every position and direction is flipped
# Orange point light on the right
point = point_light((0.59, 0.39, 0.0), 3000000000.0, 600.0, 1.0, # Color
position=(200, 150, 0)) # Position
point_light((0.59, 0.39, 0.0), 3000000000.0, 600.0, 1.0, # Color
position=(200, 150, 0)) # Position

# Blue directional light from the left
directional = directional_light((0.0, 0.4, 1.0), 4000.0, # Color
look_at=(1, 0, 0)) # The x-, y-, z-axis direction
directional_light((0.0, 0.4, 1.0), 4000.0, # Color
look_at=(1, 0, 0)) # The x-, y-, z-axis direction

# Yellow spotlight from the front
spot = spot_light((1.0, 1.0, 0.43), 2000000000.0, 600.0, 1.0, # Color
PI / 4, PI / 2, # Angle, concentration
position=(0, -40, 200), # Position
look_at=(0, -40 + 0.5, 200 - 0.5)) # Direction
roughness(0.6)

spot_light((1.0, 1.0, 0.43), 2000000000.0, 600.0, 1.0, # Color
PI / 4, PI / 2, # Angle, concentration
position=(0, -40, 200), # Position
look_at=(0, -40 + 0.5, 200 - 0.5)) # Direction

def draw():
background(0.0)
rotate_y(remap(mouse_x, 0, width, 0, PI))
rotate_x(remap(mouse_y, 0, height, 0, PI))
box(150)
Expand Down
29 changes: 12 additions & 17 deletions crates/processing_pyo3/examples/Basics/Lights/mixture_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
# Display a 2D grid of boxes with three different kinds of lights.
from mewnala import *

point = None
directional = None
spot = None


def setup():
size(640, 360)
mode_3d()
no_stroke()
define_lights()
roughness(0.6)


def draw():
background(0.0)
define_lights()

for x in range(0, width + 1, 60):
for y in range(0, height + 1, 60):
Expand All @@ -30,23 +27,21 @@ def draw():


def define_lights():
global point, directional, spot
# The lights are created once, placed relative to the top-left corner
# as in the original (the world is centered and y-up)
# The lights are placed relative to the top-left corner as in the
# original (the world is centered and y-up)
# Orange point light on the right
point = point_light((0.59, 0.39, 0.0), 3000000000.0, 600.0, 1.0, # Color
position=(200 - width / 2, height / 2 + 150, 0)) # Position
point_light((0.59, 0.39, 0.0), 3000000000.0, 600.0, 1.0, # Color
position=(200 - width / 2, height / 2 + 150, 0)) # Position

# Blue directional light from the left
directional = directional_light((0.0, 0.4, 1.0), 4000.0, # Color
look_at=(1, 0, 0)) # The x-, y-, z-axis direction
directional_light((0.0, 0.4, 1.0), 4000.0, # Color
look_at=(1, 0, 0)) # The x-, y-, z-axis direction

# Yellow spotlight from the front
spot = spot_light((1.0, 1.0, 0.43), 2000000000.0, 600.0, 1.0, # Color
PI / 4, PI / 2, # Angle, concentration
position=(-width / 2, height / 2 - 40, 200), # Position
look_at=(-width / 2, height / 2 - 40 + 0.5, 200 - 0.5)) # Direction
roughness(0.6)
spot_light((1.0, 1.0, 0.43), 2000000000.0, 600.0, 1.0, # Color
PI / 4, PI / 2, # Angle, concentration
position=(-width / 2, height / 2 - 40, 200), # Position
look_at=(-width / 2, height / 2 - 40 + 0.5, 200 - 0.5)) # Direction


run()
4 changes: 1 addition & 3 deletions crates/processing_pyo3/examples/Basics/Lights/on_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
from mewnala import *

spin = 0.0
light = None


def setup():
global light
size(640, 360)
mode_3d()
no_stroke()
light = directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))


def draw():
global spin
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.2)

# A lit material turns the lights on; unlit() turns them off
Expand Down
5 changes: 1 addition & 4 deletions crates/processing_pyo3/examples/Basics/Lights/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
# with the horizontal position of the mouse.
from mewnala import *

light = None


def setup():
global light
size(640, 360)
mode_3d()
no_stroke()
fill(0.4)
light = directional_light((0.8, 0.8, 0.8), 4000.0, look_at=(0, 0, -1))


def draw():
directional_light((0.8, 0.8, 0.8), 4000.0, look_at=(0, 0, -1))
background(0.0)
# A smoother (less rough) material gives a stronger specular highlight
s = mouse_x / width
Expand Down
36 changes: 14 additions & 22 deletions crates/processing_pyo3/examples/Basics/Lights/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,32 @@
# of a blue spot light.
from mewnala import *

bottom = None
orange = None
blue = None


def setup():
global bottom, orange, blue
size(640, 360)
mode_3d()
no_stroke()
fill(0.8)

# Lights are created once and positioned relative to the top-left corner
# as in the original (the world is centered and y-up)
# Light the bottom of the sphere
bottom = directional_light((0.2, 0.4, 0.49), 4000.0, look_at=(0, 1, 0))

# Orange light on the upper-right of the sphere
orange = spot_light((0.8, 0.6, 0.0), 10000000000.0, 1200.0, 1.0, 0.0, PI / 12,
position=(360 - width / 2, height / 2 - 160, 600),
look_at=(360 - width / 2, height / 2 - 160, 0))

# Moving spotlight that follows the mouse
blue = spot_light((0.4, 0.6, 0.8), 10000000000.0, 1200.0, 1.0, 0.0, PI / 12,
position=(360 - width / 2, height / 2, 600),
look_at=(360 - width / 2, height / 2, 0))
roughness(0.6)


def draw():
background(0.0)

blue.position(360 - width / 2, height / 2 - mouse_y, 600)
blue.look_at(360 - width / 2, height / 2 - mouse_y, 0)
# Lights are positioned relative to the top-left corner as in the
# original (the world is centered and y-up)
# Light the bottom of the sphere
directional_light((0.2, 0.4, 0.49), 4000.0, look_at=(0, 1, 0))

# Orange light on the upper-right of the sphere
spot_light((0.8, 0.6, 0.0), 10000000000.0, 1200.0, 1.0, 0.0, PI / 12,
position=(360 - width / 2, height / 2 - 160, 600),
look_at=(360 - width / 2, height / 2 - 160, 0))

# Moving spotlight that follows the mouse
spot_light((0.4, 0.6, 0.8), 10000000000.0, 1200.0, 1.0, 0.0, PI / 12,
position=(360 - width / 2, height / 2 - mouse_y, 600),
look_at=(360 - width / 2, height / 2 - mouse_y, 0))

sphere(120, 60, 60)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def setup():
size(640, 360)
mode_3d()
rocket = load_model("data/rocket.obj") # GAP: load_model() (OBJ with .mtl and texture) is missing
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)


def draw():
global ry
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.0)

translate(0, -100, -200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def setup():
size(640, 360)
mode_3d()
no_stroke()
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)


def draw():
global a
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(0.0, 0.0, 0.1)

for i in range(num):
Expand Down
4 changes: 2 additions & 2 deletions crates/processing_pyo3/examples/Demos/Graphics/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
def setup():
size(1024, 768)
mode_3d()
# lights()
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
roughness(0.6)
build()


def draw():
# lights()
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
background(1.0)
scale(0.9)
rotate_y(remap(mouse_x, 0, width, -PI, PI))
Expand Down
Loading
Loading