Skip to content

Adventures in UI #356

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

Open
wants to merge 100 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
795dd2c
Simple UI panel thing
hmans Oct 8, 2022
7f5650e
Remove unneeded props
hmans Oct 8, 2022
1824bd6
Cleanup
hmans Oct 8, 2022
4c11d7a
Pivot
hmans Oct 8, 2022
baaab2f
Prepare anchor
hmans Oct 8, 2022
d34d205
UIPanel
hmans Oct 8, 2022
9cdb2c6
Make anchors work
hmans Oct 8, 2022
dc2c32d
Try an anchor const
hmans Oct 8, 2022
62c5fab
Almost...
hmans Oct 8, 2022
14317b9
Good
hmans Oct 8, 2022
379a9f8
Button
hmans Oct 8, 2022
82d9763
Make test canvas bigger
hmans Oct 8, 2022
a1b526c
Prepare for that depth thing
hmans Oct 8, 2022
32d6811
Add PP
hmans Oct 8, 2022
c34eda0
Cool!
hmans Oct 8, 2022
1c3a0aa
[RC] `clearColor` etc. flags
hmans Oct 8, 2022
1b5a875
Use them
hmans Oct 8, 2022
bc588ed
Merge branch 'dev' into adventures-in-ui
hmans Oct 8, 2022
6a5fc27
Re-enable debug stuffs
hmans Oct 8, 2022
c0fa3d7
Make it bigger
hmans Oct 8, 2022
56c5509
Tidy up anti-z-fighting measures
hmans Oct 8, 2022
225c738
Debug improvements
hmans Oct 8, 2022
f5585b8
Rect
hmans Oct 8, 2022
36eaf7d
Play with camera
hmans Oct 8, 2022
17547bd
Merge branch 'dev' into adventures-in-ui
hmans Oct 9, 2022
479cd8e
MouseCursor
hmans Oct 9, 2022
03a40b7
Merge branch 'dev' into adventures-in-ui
hmans Oct 11, 2022
d50fe6c
Merge branch 'dev' into adventures-in-ui
hmans Oct 12, 2022
a216e33
Merge branch 'dev' into adventures-in-ui
hmans Oct 16, 2022
93bd217
Merge branch 'dev' into adventures-in-ui
hmans Oct 19, 2022
a50f963
Merge branch 'dev' into adventures-in-ui
hmans Oct 19, 2022
06bf208
Merge branch 'main' into adventures-in-ui
hmans Oct 25, 2022
e176590
Merge branch 'main' into adventures-in-ui
hmans Nov 19, 2022
d04e8da
Merge branch 'main' into adventures-in-ui
hmans Nov 19, 2022
deb4988
Merge branch 'main' into adventures-in-ui
hmans Nov 21, 2022
38184a4
Events and labels
hmans Nov 21, 2022
4714f44
Cleanup
hmans Nov 21, 2022
bd39c7e
Set up @hmans/scene-ui package
hmans Nov 21, 2022
9d674e6
Extract bits into package
hmans Nov 21, 2022
b187a86
Merge branch 'main' into adventures-in-ui
hmans Nov 21, 2022
3a85f03
Rename UIRect to Rect
hmans Nov 21, 2022
a2407b0
Merge branch 'main' into adventures-in-ui
hmans Nov 21, 2022
2739fbe
Don't preconstruct dev automatically
hmans Nov 21, 2022
68f0a80
Never mind
hmans Nov 21, 2022
c511fb8
Merge branch 'main' into adventures-in-ui
hmans Nov 21, 2022
6cb8d15
Add scene-ui-examples app
hmans Nov 21, 2022
4ada7b4
Clear out scaffolding
hmans Nov 21, 2022
170fbd6
Get an actual app going
hmans Nov 21, 2022
fcb938d
Render debug panels doublesided
hmans Nov 21, 2022
ea29034
Extract ScenePass into RenderComposer
hmans Nov 21, 2022
4cec180
Use Render Composer
hmans Nov 21, 2022
ac44032
Clone implementation
hmans Nov 21, 2022
75f8dd6
Yo
hmans Nov 21, 2022
0f8ebc2
Cleanup
hmans Nov 21, 2022
e9efba8
Cleanup
hmans Nov 21, 2022
f54406c
Simplify
hmans Nov 21, 2022
fd2629f
Reduce font size
hmans Nov 21, 2022
b7b52e3
Button
hmans Nov 21, 2022
ab01f08
Display example in scene
hmans Nov 21, 2022
7b9f4d2
Extract Rect and MouseCursor
hmans Nov 21, 2022
923a69c
Increase child z offset
hmans Nov 21, 2022
24f59e0
Use cyan wireframe for debugging
hmans Nov 21, 2022
0191b55
Reduce child offset
hmans Nov 21, 2022
10caf70
Eh
hmans Nov 21, 2022
5754ee5
Disable Space Rage HUD for now
hmans Nov 21, 2022
c4028f7
Fix layouting
hmans Nov 21, 2022
008e2d4
Use different colors for debugging
hmans Nov 21, 2022
f329dca
Tweak colors
hmans Nov 21, 2022
9f86970
Experimento
hmans Nov 21, 2022
a84fe0d
Merge branch 'main' into adventures-in-ui
hmans Nov 21, 2022
dd0354f
Commit
hmans Nov 22, 2022
2278125
Merge branch 'main' into adventures-in-ui
hmans Nov 22, 2022
3d30c9a
Cleanup
hmans Nov 22, 2022
583eb84
Scale
hmans Nov 22, 2022
b6f0903
Percentage width
hmans Nov 22, 2022
c4f2ee9
Another approach
hmans Nov 22, 2022
131a429
Offset
hmans Nov 22, 2022
6d1307a
Page title
hmans Nov 22, 2022
0fd5bb0
Simplify debug view
hmans Nov 22, 2022
52041b0
Buttonnnnn
hmans Nov 22, 2022
db5f3c6
Ok!
hmans Nov 22, 2022
564916f
Anchor markers
hmans Nov 22, 2022
79accc5
Separate Canvas from Rect
hmans Nov 23, 2022
dd9795b
Draw debug pane for Canvas
hmans Nov 23, 2022
dc9bd92
Apply anchors
hmans Nov 23, 2022
26544c5
It works! Kinda...
hmans Nov 23, 2022
96c471d
Now it's fine.
hmans Nov 23, 2022
080db69
Disable HUD for now (fix spacerage build)
hmans Nov 23, 2022
22ab94b
ok?
hmans Nov 23, 2022
42468df
It works
hmans Nov 23, 2022
9fe8345
Cool!
hmans Nov 23, 2022
3a5685e
Cleanup
hmans Nov 23, 2022
3116cd9
Make anchors work like in CSS
hmans Nov 23, 2022
3707524
Fix le button
hmans Nov 23, 2022
6f6a5bc
Offset
hmans Nov 23, 2022
71d3faa
Le button
hmans Nov 23, 2022
d5303a6
Margin
hmans Nov 23, 2022
d81cb8b
Cool
hmans Nov 23, 2022
c230c8b
Not using pivot yet
hmans Nov 23, 2022
394ca46
sizing values
hmans Nov 23, 2022
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
16 changes: 16 additions & 0 deletions .changeset/poor-tigers-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"render-composer": patch
---

**New:** `ScenePass`, a new render pass that renders a scene to the current render target. The scene is passed to this component as its children, and is expected to set up its own camera, lights, and so on.

```jsx
<ScenePass>
<PerspectiveCamera position={[0, 0, 20]} makeDefault />
<directionalLight position={[20, 40, 40]} />
<mesh>
<boxGeometry />
<meshStandardMaterial color="hotpink" />
</mesh>
</ScenePass>
```
24 changes: 24 additions & 0 deletions apps/scene-ui-examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions apps/scene-ui-examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>scene-ui-examples</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions apps/scene-ui-examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "scene-ui-examples",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@hmans/scene-ui": "workspace:^0.0.1",
"r3f-stage": "workspace:^0.3.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"render-composer": "workspace:^0.2.8"
},
"devDependencies": {
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@vitejs/plugin-react": "^2.2.0",
"typescript": "^4.6.4",
"vite": "^3.2.3"
}
}
1 change: 1 addition & 0 deletions apps/scene-ui-examples/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions apps/scene-ui-examples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "r3f-stage/styles.css"
import { Application } from "r3f-stage"
import * as UI from "@hmans/scene-ui"
import { Anchor } from "@hmans/scene-ui"

export const App = () => {
return (
<Application>
<UI.Canvas width={6} height={4} debug>
<UI.Rect margin={0.25}>
<UI.Rect anchor={Anchor.BottomCenter} margin={[-1, 1.5, 0.25, 1.5]} />
</UI.Rect>
</UI.Canvas>
</Application>
)
}
Empty file.
10 changes: 10 additions & 0 deletions apps/scene-ui-examples/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react"
import ReactDOM from "react-dom/client"
import { App } from "./App"
import "./index.css"

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
1 change: 1 addition & 0 deletions apps/scene-ui-examples/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
21 changes: 21 additions & 0 deletions apps/scene-ui-examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
9 changes: 9 additions & 0 deletions apps/scene-ui-examples/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions apps/scene-ui-examples/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
})
1 change: 1 addition & 0 deletions apps/spacerage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@dimforge/rapier3d-compat": "^0.9.0",
"@hmans/r3f-create-loader": "workspace:^0.0.3",
"@hmans/r3f-shared-resource": "^0.1.0",
"@hmans/scene-ui": "workspace:^0.0.1",
"@hmans/things": "^0.0.6",
"@hmans/use-const": "^0.0.1",
"@hmans/use-rerender": "^0.0.2",
Expand Down
10 changes: 8 additions & 2 deletions apps/spacerage/src/scenes/gameplay/GameplayScene.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Physics } from "@react-three/rapier"
import { Suspense } from "react"
import * as RC from "render-composer"
import { bitmask, Layers } from "render-composer"
import { Vec3 } from "shader-composer"
import { Color } from "three"
Expand All @@ -10,7 +11,6 @@ import { Nebula } from "../menu/vfx/Nebula"
import { Asteroids } from "./Asteroids"
import { Bullets } from "./Bullets"
import { FollowCamera } from "./FollowCamera"
import { HUD } from "./HUD"
import { Pickups } from "./Pickups"
import { Player } from "./Player"
import { PostProcessing } from "./PostProcessing"
Expand Down Expand Up @@ -89,7 +89,13 @@ const GameplayScene = () => {
</Physics>
</group>

<HUD />
{/* <ScenePass>
<HUD />
</ScenePass> */}

<RC.EffectPass>
<RC.SMAAEffect />
</RC.EffectPass>
</Suspense>
)
}
Expand Down
18 changes: 10 additions & 8 deletions apps/spacerage/src/scenes/gameplay/HUD.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { PerspectiveCamera, Text } from "@react-three/drei"
import { Color } from "three"
import { ScenePass } from "../../lib/ScenePass"
import { OrbitControls, PerspectiveCamera } from "@react-three/drei"
import { useThree } from "@react-three/fiber"

export const HUD = () => {
const camera = useThree((state) => state.camera)

return (
<ScenePass>
<>
<PerspectiveCamera position={[0, 0, 20]} makeDefault />
<directionalLight position={[20, 40, 40]} />
<OrbitControls />

<Text color={new Color("hotpink")} fontSize={1} position={[-3, 7, 0]}>
723.389.150
</Text>
</ScenePass>
{/* {camera && (
)} */}
</>
)
}
20 changes: 20 additions & 0 deletions packages/hmans-scene-ui/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2022 Hendrik Mans

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions packages/hmans-scene-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Scene UI

Experimental scene-space UI for Three.js.
52 changes: 52 additions & 0 deletions packages/hmans-scene-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@hmans/scene-ui",
"author": {
"name": "Hendrik Mans",
"email": "[email protected]",
"url": "https://hmans.co"
},
"description": "",
"version": "0.0.1",
"main": "dist/hmans-scene-ui.cjs.js",
"module": "dist/hmans-scene-ui.esm.js",
"files": [
"dist/**",
"LICENSE",
"README.md"
],
"license": "MIT",
"sideEffects": false,
"scripts": {
"build": "preconstruct build"
},
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react",
[
"@babel/preset-typescript",
{
"isTSX": true,
"allExtensions": true
}
]
]
},
"peerDependencies": {
"@react-three/fiber": "^8.8.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"three": "^0.145.0"
},
"devDependencies": {
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/three": "^0.144.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"three": "^0.145.0"
},
"dependencies": {
"troika-three-text": "^0.46.4"
}
}
28 changes: 28 additions & 0 deletions packages/hmans-scene-ui/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { GroupProps } from "@react-three/fiber"
import React from "react"
import { MouseCursor } from "./MouseCursor"
import { Text } from "./Text"

export const Button = ({
label,
...props
}: {
label: string
} & GroupProps) => {
return (
<MouseCursor {...props}>
<mesh>
<planeGeometry args={[4, 1]} />
<meshBasicMaterial color="#444" />
</mesh>

<Text
maxWidth={8}
fontSize={0.5}
textAlign="center"
depthOffset={-1}
text="Click Me"
/>
</MouseCursor>
)
}
28 changes: 28 additions & 0 deletions packages/hmans-scene-ui/src/components/Button3D.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { GroupProps } from "@react-three/fiber"
import React from "react"
import { MouseCursor } from "./MouseCursor"
import { Text } from "./Text"

export const Button3D = ({
label,
...props
}: {
label: string
} & GroupProps) => {
return (
<MouseCursor position-z={0.25} {...props}>
<mesh>
<boxGeometry args={[4, 1, 0.5]} />
<meshBasicMaterial color="#444" />
</mesh>
<Text
maxWidth={8}
fontSize={0.5}
textAlign="center"
position-z={0.25}
depthOffset={-0.001}
text="Click Me"
/>
</MouseCursor>
)
}
29 changes: 29 additions & 0 deletions packages/hmans-scene-ui/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { GroupProps } from "@react-three/fiber"
import React, { forwardRef } from "react"
import { Group } from "three"
import { RectContext } from "./Rect"

export type CanvasProps = GroupProps & {
width: number
height: number
debug?: boolean
}

export const Canvas = forwardRef<Group, CanvasProps>(
({ children, width, height, debug = false, ...props }, ref) => {
return (
<RectContext.Provider
value={{ width, height, debug, debugColorIndex: 0 }}
>
{debug && (
<mesh scale={[width, height, 1]}>
<planeGeometry />
<meshBasicMaterial color="white" wireframe />
</mesh>
)}

<group {...props}>{children}</group>
</RectContext.Provider>
)
}
)
Loading