Skip to content

Commit 5d79d05

Browse files
committed
docs: add environment example
1 parent df40752 commit 5d79d05

5 files changed

Lines changed: 56 additions & 9 deletions

File tree

playground/App.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { A, Route, Router } from "@solidjs/router"
22
import type { ParentProps } from "solid-js"
33
import * as THREE from "three"
44
import { Canvas, createT } from "../src/index.ts"
5-
import { SimplePortal } from "./examples/SimplePortal.tsx"
6-
import { SimpleSolarExample } from "./examples/SimpleSolar.tsx"
5+
import { EnvironmentExample } from "./examples/EnvironmentExample.tsx"
6+
import { PortalExample } from "./examples/PortalExample.tsx"
7+
import { SolarExample } from "./examples/SolarExample.tsx"
78
import "./index.css"
89

910
const T = createT(THREE)
@@ -55,6 +56,17 @@ function Layout(props: ParentProps) {
5556
>
5657
Portal
5758
</A>
59+
<A
60+
href="/environment"
61+
style={{
62+
color: "white",
63+
"text-decoration": "none",
64+
padding: "5px 10px",
65+
display: "block",
66+
}}
67+
>
68+
Environment
69+
</A>
5870
</nav>
5971
{props.children}
6072
</>
@@ -64,8 +76,9 @@ function Layout(props: ParentProps) {
6476
export function App() {
6577
return (
6678
<Router root={Layout}>
67-
<Route path="/simple-solar" component={SimpleSolarExample} />
68-
<Route path="/portal" component={SimplePortal} />
79+
<Route path="/simple-solar" component={SolarExample} />
80+
<Route path="/portal" component={PortalExample} />
81+
<Route path="/environment" component={EnvironmentExample} />
6982
<Route
7083
path="/"
7184
component={() => (
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as THREE from "three"
2+
import { Canvas, createT } from "../../src/index.ts"
3+
import { OrbitControls } from "../controls/OrbitControls.tsx"
4+
5+
const T = createT(THREE)
6+
7+
export function EnvironmentExample() {
8+
const texture = new THREE.CubeTextureLoader()
9+
.setPath(
10+
"https://rawcdn.githack.com/mrdoob/three.js/54ac263593c81b669ca9a089491ddd9e240427d2/examples/textures/cube/Bridge2/",
11+
)
12+
.load(["posx.jpg", "negx.jpg", "posy.jpg", "negy.jpg", "posz.jpg", "negz.jpg"])
13+
14+
return (
15+
<Canvas
16+
style={{ width: "100vw", height: "100vh" }}
17+
camera={{ position: new THREE.Vector3(0, 0, 30) }}
18+
onClick={event => console.debug("canvas clicked", event)}
19+
onClickMissed={event => console.debug("canvas click missed", event)}
20+
onPointerLeave={event => console.debug("canvas pointer leave", event)}
21+
onPointerEnter={event => console.debug("canvas pointer enter", event)}
22+
scene={{
23+
environment: texture,
24+
}}
25+
>
26+
<OrbitControls />
27+
<T.Mesh>
28+
<T.TorusKnotGeometry args={[1, 0.5, 128, 32]} />
29+
<T.MeshStandardMaterial metalness={1} roughness={0} color="white" />
30+
</T.Mesh>
31+
</Canvas>
32+
)
33+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Canvas, createT, Entity, Portal } from "../../src/index.ts"
33

44
const T = createT(THREE)
55

6-
export function SimplePortal() {
6+
export function PortalExample() {
77
const group = new THREE.Group()
88
return (
99
<Canvas
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ function CelestialBody(
116116
)
117117
}
118118

119-
export function SimpleSolarExample() {
119+
export function SolarExample() {
120120
return (
121121
<Canvas
122-
style={{ width: "100vw", height: "100vh" }}
123122
camera={{ position: new THREE.Vector3(0, 0, 30) }}
124123
onClick={event => console.debug("canvas clicked", event)}
125124
onClickMissed={event => console.debug("canvas click missed", event)}
@@ -129,9 +128,7 @@ export function SimpleSolarExample() {
129128
<OrbitControls />
130129
<T.AmbientLight intensity={0.2} />
131130
<T.PointLight position={[0, 0, 0]} intensity={2} />
132-
133131
<T.Group rotation={[0, 0, Math.PI / 2]}>
134-
{/* Sun */}
135132
<CelestialBody name="sun" radius={1.5} color="#FDB813">
136133
<CelestialBody name="earth" radius={0.5} color="#1E90FF" orbit={[8, 6]}>
137134
<CelestialBody

playground/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ body {
33
margin: 0px;
44
font-family: arial;
55
}
6+
7+
#root {
8+
height: 100vh;
9+
}

0 commit comments

Comments
 (0)