Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene3D #41

Open
wants to merge 167 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
0eaa889
early wip, works
mhuebert Dec 11, 2024
5adac81
select points, scale with zoom
mhuebert Dec 11, 2024
5ba8ad3
orbit camera works
mhuebert Dec 11, 2024
b1681e6
improved picking
mhuebert Dec 11, 2024
1f1b978
controlled highlights
mhuebert Dec 11, 2024
a386fd8
clean up
mhuebert Dec 11, 2024
1fe4bad
cache uniforms
mhuebert Dec 11, 2024
52bd2b2
onPointClick fires on mouseup, not mousedown
mhuebert Dec 12, 2024
2e4da95
cleanup: fps
mhuebert Dec 12, 2024
659c463
cleanup: camera
mhuebert Dec 12, 2024
13870c0
cleanup: picking
mhuebert Dec 12, 2024
0f51c8f
cleanup: webgl/buffers init
mhuebert Dec 12, 2024
99dc2c3
cleanup: picking
mhuebert Dec 12, 2024
772f81a
cleanup: picking
mhuebert Dec 12, 2024
62fa2d9
picking: nearest point within threshold (4px)
mhuebert Dec 12, 2024
414a94d
decorations - working for one index
mhuebert Dec 12, 2024
c2b46b7
decorations: work for all indexes, with texture
mhuebert Dec 12, 2024
8da89db
decorations: add minSize
mhuebert Dec 12, 2024
7198c5a
add names to decoration structure
mhuebert Dec 12, 2024
7cb5672
alpha blending
mhuebert Dec 12, 2024
efd70c4
true on-demand render loop
mhuebert Dec 13, 2024
eb145c2
set dimensions on points3d
mhuebert Dec 13, 2024
e21daa5
rename to scene3d
mhuebert Dec 13, 2024
e4bc755
organize utls
mhuebert Dec 13, 2024
fc13209
more granular reactive updates. Found the reason picking was breaking.
mhuebert Dec 14, 2024
fb8a250
works again
mhuebert Dec 16, 2024
2b92e5e
cleanup
mhuebert Dec 16, 2024
f46947f
more efficient decorations
mhuebert Dec 16, 2024
f065b29
cleaner picking
mhuebert Dec 16, 2024
e7ac5c1
reuse main shader for picking
mhuebert Dec 16, 2024
e2113db
fix picking issue
mhuebert Dec 17, 2024
4fa89c2
cleanup
mhuebert Dec 17, 2024
a6d049f
simplify mouse/interaction state
mhuebert Dec 17, 2024
08c331a
simplify requestRender
mhuebert Dec 17, 2024
7be9e31
functional camera state
mhuebert Dec 17, 2024
7ec142f
remove blend modes
mhuebert Dec 18, 2024
c4bd5f3
use position/color instead of xyz/rgb
mhuebert Dec 18, 2024
2d50560
move camera into module
mhuebert Dec 18, 2024
8b090aa
typing fixes
mhuebert Dec 18, 2024
057b48f
add genstudio.alpha.scene3d module
mhuebert Dec 18, 2024
0b9a3f3
simplify camera / move webgl-utils into main file
mhuebert Dec 19, 2024
f96b4a0
support position.scale attr.
mhuebert Dec 19, 2024
aed59b7
update docstring, default point size
mhuebert Dec 19, 2024
14e9871
update alpha script
mhuebert Dec 19, 2024
c548708
empty commit
mhuebert Dec 19, 2024
114348e
re-render when points change
mhuebert Dec 20, 2024
79815f4
wip: scene3dNew
mhuebert Jan 9, 2025
0a03a7e
render quads
mhuebert Jan 10, 2025
a99c62e
fix initial render, orbit directions
mhuebert Jan 10, 2025
271e6cb
webgpu: torus demo
mhuebert Jan 10, 2025
0c3d0a3
render ellipsoids
mhuebert Jan 15, 2025
8540a0b
pan/zoom
mhuebert Jan 15, 2025
cdbe13d
depth and better shading
mhuebert Jan 15, 2025
1c2b564
improve lighting
mhuebert Jan 15, 2025
ca26b9b
parameterize sphere complexity
mhuebert Jan 15, 2025
306bf29
alpha blending
mhuebert Jan 15, 2025
490c566
EllipsoidBands
mhuebert Jan 15, 2025
cf474e3
ellipsoid lines
mhuebert Jan 15, 2025
9b7ec46
use torus geometry for ellipsoids
mhuebert Jan 15, 2025
63b382e
camera-relative lighting
mhuebert Jan 15, 2025
8b0a4f3
more sample data
mhuebert Jan 15, 2025
2888d8e
pick points
mhuebert Jan 15, 2025
65e830c
pick points accurately
mhuebert Jan 15, 2025
dc9cf5f
picking ellipsoids/bounds
mhuebert Jan 15, 2025
f68fae6
all 3 major axes for ellipsoid bounds
mhuebert Jan 15, 2025
dfe7ca9
picking ellipsoids, bounds
mhuebert Jan 15, 2025
c4ccb51
demo
mhuebert Jan 16, 2025
bff754b
more dynamic scene - support arbitrary number of element entries
mhuebert Jan 18, 2025
a5cf629
add cuboid primitive
mhuebert Jan 18, 2025
d8f79f1
fix cuboid winding order and culling
mhuebert Jan 18, 2025
5f0e1c4
dispose cache
mhuebert Jan 18, 2025
dabd53a
measure picking perf
mhuebert Jan 18, 2025
3d419c8
render only when elements or camera changes
mhuebert Jan 20, 2025
e7a04ec
better handling of gpu resources
mhuebert Jan 21, 2025
844a49e
hover state is smarter about updates
mhuebert Jan 21, 2025
cf654d9
align release.yml with main
mhuebert Jan 24, 2025
7f289b8
wip: composable scene element api
mhuebert Jan 24, 2025
7d8255e
wip: decorations
mhuebert Jan 24, 2025
e91ea59
wip: handle dimensions nicely
mhuebert Jan 24, 2025
95056c4
wip: camera
mhuebert Jan 24, 2025
d36b097
scene3d: controlled camera
mhuebert Jan 27, 2025
bad2f3d
better camera params / movement
mhuebert Jan 27, 2025
6134cb0
controlled/uncontrolled camera
mhuebert Jan 27, 2025
0c6c2bd
factor out camera3d
mhuebert Jan 27, 2025
5b9f9a2
ensure camera can handle any 'up'
mhuebert Jan 27, 2025
17a9e23
fix: texture sizes
mhuebert Jan 27, 2025
75f7271
lazy picking for performance
mhuebert Jan 27, 2025
e6f9d50
perf: reuse buffers
mhuebert Jan 28, 2025
41490b5
cleanup types
mhuebert Jan 28, 2025
fc5b9f7
fix types
mhuebert Jan 28, 2025
15be577
factor out common code from shading/picking pipelines
mhuebert Jan 28, 2025
de9df4c
fix point occlusion
mhuebert Jan 28, 2025
289d7c5
fis specular highlights
mhuebert Jan 28, 2025
e963c21
correct alpha blending
mhuebert Jan 28, 2025
3268539
minor cleanup
mhuebert Jan 28, 2025
3da3866
cleanup specs
mhuebert Jan 28, 2025
81f2d6d
consolidate specs
mhuebert Jan 28, 2025
fc09b18
scene elements allow js inputs
mhuebert Jan 28, 2025
e59ded9
formatting/comments
mhuebert Jan 29, 2025
ef12f32
organize scene3d code
mhuebert Jan 29, 2025
842a8aa
elements -> components
mhuebert Jan 29, 2025
158b898
accept singular component options
mhuebert Jan 29, 2025
d1fe47d
fix typing
mhuebert Jan 29, 2025
ef66468
clean up shader code
mhuebert Jan 29, 2025
7c40835
naming
mhuebert Jan 29, 2025
c2382df
flatten component config
mhuebert Jan 29, 2025
bf9b7a2
show FPS
mhuebert Jan 29, 2025
d3d4a57
add LineCylinders component
mhuebert Jan 30, 2025
d94e2b7
clean up geometry resource code
mhuebert Jan 30, 2025
25f1677
remove createRenderObject from specs
mhuebert Jan 30, 2025
2db5d7e
decorations cleanup
mhuebert Jan 30, 2025
8e5a77f
decorations code cleanup
mhuebert Jan 30, 2025
f96ae4e
cleaner deco code
mhuebert Jan 30, 2025
e008469
consistent api
mhuebert Jan 30, 2025
1718014
cylinder -> beam
mhuebert Jan 31, 2025
61075ee
move shader code next to spec
mhuebert Jan 31, 2025
c2094f0
- rectangular line beams with size/sizes param
mhuebert Jan 31, 2025
66850e6
scene3d docs
mhuebert Jan 31, 2025
b8a66d5
- add .merge method to SceneComponent
mhuebert Jan 31, 2025
891a635
cleanup
mhuebert Jan 31, 2025
2ae1175
fix controls
mhuebert Feb 1, 2025
e1b096f
single draw for each component type
mhuebert Feb 1, 2025
cb9dfcf
unified data collection
mhuebert Feb 1, 2025
bda1327
add ellipsoid demo
mhuebert Feb 1, 2025
71968e1
coerce arrays to float32
mhuebert Feb 1, 2025
e46c590
sort ellipsoids
mhuebert Feb 1, 2025
22da66e
improved sorting
mhuebert Feb 2, 2025
7043a6c
camera accepts BigInts
mhuebert Feb 3, 2025
b0b59fb
convert all bigints
mhuebert Feb 3, 2025
0ba4e26
fix sorting bug
mhuebert Feb 3, 2025
42ad95d
update transparency when camera moves
mhuebert Feb 3, 2025
2acb3a0
use sorted indexes in picking
mhuebert Feb 3, 2025
2b65a9f
cleaner index handling
mhuebert Feb 3, 2025
27e5790
move shaders out of file
mhuebert Feb 3, 2025
b3da1f2
synchronize transparency info
mhuebert Feb 3, 2025
eb27385
re-use sorted indices in picking
mhuebert Feb 3, 2025
364d67f
add docs
mhuebert Feb 4, 2025
77e5584
improve FPS calculation, add controls=['fps'] param
mhuebert Feb 4, 2025
d0338d5
pass through release args
mhuebert Feb 4, 2025
f0b7b47
standardize layouts
mhuebert Feb 4, 2025
fde0bff
standardize entrypoints
mhuebert Feb 4, 2025
8832da8
consistent index handling
mhuebert Feb 4, 2025
0742740
re-use arrays in renderData
mhuebert Feb 4, 2025
efc82a3
TypedArray for sortedIindices
mhuebert Feb 4, 2025
7998fd3
re-use picking array
mhuebert Feb 4, 2025
e8bb580
move layouts
mhuebert Feb 4, 2025
9cf804c
eliminate global picking index
mhuebert Feb 5, 2025
208529e
update heart demo
mhuebert Feb 5, 2025
74ce593
fix html mode with buffers
mhuebert Feb 5, 2025
a2de59c
improve heart viz
mhuebert Feb 5, 2025
61c813a
re-use transparency distances array
mhuebert Feb 5, 2025
cf36d8a
- spec includes type name
mhuebert Feb 5, 2025
2ad4b70
correctly pick with multiple components per render object
mhuebert Feb 5, 2025
6eb5d2f
lazy picking
mhuebert Feb 5, 2025
c6daee8
move getCenters to spec
mhuebert Feb 5, 2025
7ad526a
fix sorting
mhuebert Feb 5, 2025
206140d
organize buildRenderObjects
mhuebert Feb 5, 2025
ee7087a
simplify getCenters, transparency props
mhuebert Feb 5, 2025
0fbf9de
align16, transparency simplification
mhuebert Feb 5, 2025
b7db0b2
simplify typeArray loops
mhuebert Feb 5, 2025
3402c6c
cleanups
mhuebert Feb 5, 2025
5df9c21
no need for a centers array
mhuebert Feb 5, 2025
35ce9b6
organize into files
mhuebert Feb 5, 2025
a5afe5b
update comments
mhuebert Feb 6, 2025
bbf8883
add scene3d tests
mhuebert Feb 6, 2025
3fd8206
Slider accepts JSExpr args
mhuebert Feb 6, 2025
c47832d
accept bool (false) for slider controls
mhuebert Feb 6, 2025
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
126 changes: 114 additions & 12 deletions docs/api/plot.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ Parameters

- `frames` (list): A list of plot specifications or renderable objects to animate.

- `**opts`: Additional options for the animation, such as fps (frames per second).
- `key` (str | None): The state key to use for the frame index. If None, uses "frame".

- `slider` (bool): Whether to show the slider control. Defaults to True.

- `tail` (bool): Whether animation should stop at the end. Defaults to False.

- `**opts` (Any): Additional options for the animation, such as fps (frames per second).

Returns
{: .api .api-section }


- A Hiccup-style representation of the animated plot.
- A Hiccup-style representation of the animated plot. (LayoutItem)



Expand Down Expand Up @@ -81,7 +87,7 @@ Parameters

- `controls` (list): List of controls to display, such as ["slider", "play", "fps"]. Defaults to ["slider"] if fps is not set, otherwise ["slider", "play"].

- `**kwargs`: Additional keyword arguments.
- `**kwargs` (Any): Additional keyword arguments.

Returns
{: .api .api-section }
Expand All @@ -101,9 +107,7 @@ Must be passed as the 'render' option to a mark, e.g.:
onClick=handle_click
))

This function enhances the rendering of plot elements by adding interactive behaviors
such as dragging, clicking, and tracking position changes. It's designed to work with
Observable Plot's rendering pipeline.
This function enhances the rendering of plot elements by adding interactive behaviors such as dragging, clicking, and tracking position changes. It's designed to work with Observable Plot's rendering pipeline.

Parameters
{: .api .api-section }
Expand Down Expand Up @@ -264,6 +268,40 @@ Parameters



### cond {: .api .api-member }

Render content based on conditions, like Clojure's cond.

Takes pairs of test/expression arguments, evaluating each test in order.
When a test is truthy, returns its corresponding expression.
An optional final argument serves as the "else" expression.

Parameters
{: .api .api-section }


- `*args`: Alternating test/expression pairs, with optional final else expression



### case {: .api .api-member }

Render content based on matching a value against cases, like a switch statement.

Takes a value to match against, followed by pairs of case/expression arguments.
When a case matches the value, returns its corresponding expression.
An optional final argument serves as the default expression.

Parameters
{: .api .api-section }


- `value` (Union[JSCode, str, Any]): The value to match against cases

- `*args`: Alternating case/expression pairs, with optional final default expression



### html {: .api .api-member }

Wraps a Hiccup-style list to be rendered as an interactive widget in the JavaScript runtime.
Expand All @@ -276,20 +314,32 @@ Render a string as Markdown, in a LayoutItem.



### JSExpr {: .api .api-member }

A type alias representing JavaScript expressions that can be evaluated in the runtime.




## JavaScript Interop

### js {: .api .api-member }

Represents raw JavaScript code to be evaluated as a LayoutItem.

The code will be evaluated in a scope that includes:
- $state: Current plot state
- html: render HTML using a JavaScript hiccup syntax
- d3: D3.js library
- genstudio.api: roughly, the api exposed via the genstudio.plot module

Parameters
{: .api .api-section }


- `txt` (str): JavaScript code with optional %1, %2, etc. placeholders

- `*params`: Values to substitute for %1, %2, etc. placeholders
- `*params` (Any): Values to substitute for %1, %2, etc. placeholders

- `expression` (bool): Whether to evaluate as expression or statement

Expand Down Expand Up @@ -2562,6 +2612,18 @@ Sets `{"inset": i}`.

Set margin values for a plot using CSS-style margin shorthand.

Parameters
{: .api .api-section }


- `*args` (Any): Margin values as integers or floats, following CSS margin shorthand rules

Returns
{: .api .api-section }


- A dictionary mapping margin properties to their values (dict)



### repeat {: .api .api-member }
Expand Down Expand Up @@ -2603,7 +2665,7 @@ Sets `{"width": width}`.
Returns a new ellipse mark for the given *values* and *options*.

If neither **x** nor **y** are specified, *values* is assumed to be an array of
pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …] such that **x** = [*x₀*,
pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*, …] such that **x** = [*x₀*,
*x₁*, *x₂*, …] and **y** = [*y₀*, *y₁*, *y₂*, …].

The **rx** and **ry** options specify the x and y radii respectively. If only
Expand All @@ -2617,7 +2679,7 @@ Parameters
{: .api .api-section }


- `values`: The data for the ellipses.
- `values` (Any): The data for the ellipses.

- `options` (dict[str, Any]): Additional options for customizing the ellipses.

Expand Down Expand Up @@ -2743,9 +2805,9 @@ Parameters
{: .api .api-section }


- `values` (dict): A dictionary mapping state variable names to their initial values.
- `values` (dict[str, Any]): A dictionary mapping state variable names to their initial values.

- `sync` (Union[set, bool, None]): Controls which state variables are synced between Python and JavaScript.
- `sync` (Union[set[str], bool, None]): Controls which state variables are synced between Python and JavaScript.

If True, all variables are synced. If a set, only variables in the set are synced.

Expand All @@ -2755,7 +2817,7 @@ Returns
{: .api .api-section }


- An object that initializes the state variables when rendered.
- An object that initializes the state variables when rendered. (JSCall)



Expand Down Expand Up @@ -2793,3 +2855,43 @@ Returns
### dimensions {: .api .api-member }

Attaches dimension metadata, for further processing in JavaScript.



### Import {: .api .api-member }

Import JavaScript code into the GenStudio environment.

Parameters
{: .api .api-section }


- `source` (str): JavaScript source code. Can be:

- Inline JavaScript code

- URL starting with http(s):// for remote modules

- Local file path starting with path: prefix

- `alias` (Optional[str]): Namespace alias for the entire module

- `default` (Optional[str]): Name for the default export

- `refer` (Optional[list[str]]): Set of names to import directly, or True to import all

- `refer_all` (bool): Alternative to refer=True

- `rename` (Optional[dict[str, str]]): Dict of original->new names for referred imports

- `exclude` (Optional[list[str]]): Set of names to exclude when using refer_all

- `format` (str): Module format ('esm' or 'commonjs')

Examples
{: .api .api-section }


```python
[(<DocstringSectionKind.text: 'text'>, '# CDN import with namespace alias'), (<DocstringSectionKind.examples: 'examples'>, '>>> Plot.Import(\n... source="https://cdn.skypack.dev/lodash-es",\n... alias="_",\n... refer=["flattenDeep", "partition"],\n... rename={"flattenDeep": "deepFlatten"}\n... )'), (<DocstringSectionKind.text: 'text'>, '# Local file import'), (<DocstringSectionKind.examples: 'examples'>, '>>> Plot.Import(\n... source="path:src/app/utils.js", # relative to working directory\n... refer=["formatDate"]\n... )'), (<DocstringSectionKind.text: 'text'>, '# Inline source with refer_all'), (<DocstringSectionKind.examples: 'examples'>, '>>> Plot.Import(\n... source=\'\'\'\n... export const add = (a, b) => a + b;\n... export const subtract = (a, b) => a - b;\n... \'\'\',\n... refer_all=True,\n... exclude=["subtract"]\n... )'), (<DocstringSectionKind.text: 'text'>, '# Default export handling'), (<DocstringSectionKind.examples: 'examples'>, '>>> Plot.Import(\n... source="https://cdn.skypack.dev/d3-scale",\n... default="createScale"\n... )')]
```
Expand Down
Loading