Platform
Resources
Pricing
Sign in
Contact us
Ben Simonds
Workspace
Fork
Public
By
Ben Simonds
Edited
Oct 24, 2023
Insert cell
Insert cell
viewof
boxParams
=
Inputs
.
form
(
{
x
:
Inputs
.
range
(
[
0
,
10
]
,
{
value
:
5
,
step
:
0.5
,
label
:
"Width"
}
)
,
y
:
Inputs
.
range
(
[
0
,
10
]
,
{
value
:
5
,
step
:
0.5
,
label
:
"Height"
}
)
,
z
:
Inputs
.
range
(
[
0
,
10
]
,
{
value
:
5
,
step
:
0.5
,
label
:
"Depth"
}
)
,
}
)
Insert cell
renderer
.
domElement
Insert cell
cube
=
{
const
material
=
new
THREE
.
MeshStandardMaterial
(
)
;
const
geometry
=
new
THREE
.
BoxGeometry
(
boxParams
.
x
,
boxParams
.
y
,
boxParams
.
z
)
;
const
cube
=
new
THREE
.
Mesh
(
geometry
,
material
)
;
return
cube
;
}
Insert cell
// Continuously updates
{
while
(
true
)
{
cube
.
rotation
.
y
+=
0.01
;
renderer
.
render
(
scene
,
camera
)
;
yield
null
;
}
}
Insert cell
THREE
=
{
const
THREE
=
window
.
THREE
=
await
require
(
"three@0.130.0/build/three.min.js"
)
;
await
require
(
"three@0.130.0/examples/js/controls/OrbitControls.js"
)
.
catch
(
(
)
=>
{
}
)
;
return
THREE
;
}
Insert cell
renderer
=
{
const
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
)
;
renderer
.
setSize
(
width
,
height
)
;
renderer
.
setPixelRatio
(
devicePixelRatio
)
;
const
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
)
;
controls
.
addEventListener
(
"change"
,
(
)
=>
renderer
.
render
(
scene
,
camera
)
)
;
invalidation
.
then
(
(
)
=>
(
controls
.
dispose
(
)
,
renderer
.
dispose
(
)
)
)
;
return
renderer
;
}
Insert cell
camera
=
{
const
fov
=
45
;
const
aspect
=
width
/
height
;
const
near
=
1
;
const
far
=
1000
;
const
camera
=
new
THREE
.
PerspectiveCamera
(
fov
,
aspect
,
near
,
far
)
;
camera
.
position
.
set
(
2
,
2
,
-
2
)
camera
.
lookAt
(
new
THREE
.
Vector3
(
0
,
0
,
0
)
)
;
return
camera
;
}
Insert cell
scene
=
{
const
scene
=
new
THREE
.
Scene
(
)
;
scene
.
background
=
new
THREE
.
Color
(
0x222222
)
;
scene
.
add
(
cube
)
;
const
light
=
new
THREE
.
AmbientLight
(
0x404040
)
;
scene
.
add
(
light
)
;
const
directionalLight
=
new
THREE
.
DirectionalLight
(
0xffffff
,
0.5
)
;
directionalLight
.
position
.
set
(
.5
,
0.5
,
0.5
)
scene
.
add
(
directionalLight
)
;
return
scene
;
}
Insert cell
height
=
600
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
boxParams
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cube
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
THREE
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
renderer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
camera
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
scene
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
height
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML