This repository was archived by the owner on Jun 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
New Root API #42
Open
nksaraf
wants to merge
18
commits into
main
Choose a base branch
from
roots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Root API #42
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2540423
init remotion support
nksaraf 88e5cd4
init remotion support
nksaraf d779bb4
cleanup types
nksaraf 6f2dd81
prop types simplify to one file
nksaraf ee3a52d
refactor editor panels to separate ControlledPanel & ControlledDynami…
nksaraf 8a67397
remove console logs
nksaraf a1decaa
dont optimize three with remotion
nksaraf 7d3c2a1
editable element fixes
nksaraf c39d96a
3d with remotion
nksaraf 38ee168
remotion commands
nksaraf b0c59ca
roots
nksaraf 50b1c30
Merge branch 'remotion' into roots
nksaraf 1d263f0
fix
nksaraf 7a8f6cd
editable roots
nksaraf deaf7fb
add gpt commit summarizer
nksaraf 8e91675
remove commit summary
nksaraf 1da0d95
fix some more root stuff
nksaraf 806e606
add threejs root system with horizontal panels
nksaraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ root.render( | |
> | ||
<Canvas | ||
ref={(node) => { | ||
console.log("hereee") | ||
// store.canvas = node | ||
}} | ||
camera={{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,99 @@ | ||
import * as THREE from 'three' | ||
import React, { useEffect, useState, useRef } from 'react' | ||
import { Canvas, useThree, useFrame } from '@react-three/fiber' | ||
import { OrbitControls } from '@react-three/drei' | ||
import { OrbitControls } from "@react-three/drei"; | ||
import { Canvas, useFrame, useThree } from "@react-three/fiber"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import * as THREE from "three"; | ||
|
||
function AdaptivePixelRatio() { | ||
const gl = useThree((state) => state.gl) | ||
const current = useThree((state) => state.performance.current) | ||
const initialDpr = useThree((state) => state.viewport.initialDpr) | ||
const setDpr = useThree((state) => state.setDpr) | ||
// Restore initial pixelratio on unmount | ||
useEffect(() => { | ||
const domElement = gl.domElement | ||
return () => { | ||
setDpr(initialDpr) | ||
domElement.style.imageRendering = 'auto' | ||
} | ||
}, []) | ||
// Set adaptive pixelratio | ||
useEffect(() => { | ||
setDpr(current * initialDpr) | ||
gl.domElement.style.imageRendering = current === 1 ? 'auto' : 'pixelated' | ||
}, [current]) | ||
return null | ||
const gl = useThree(state => state.gl); | ||
const current = useThree(state => state.performance.current); | ||
const initialDpr = useThree(state => state.viewport.initialDpr); | ||
const setDpr = useThree(state => state.setDpr); | ||
|
||
// Restore initial pixelratio on unmount | ||
useEffect(() => { | ||
const domElement = gl.domElement; | ||
|
||
return () => { | ||
setDpr(initialDpr); | ||
domElement.style.imageRendering = "auto"; | ||
}; | ||
}, []); | ||
|
||
// Set adaptive pixelratio | ||
useEffect(() => { | ||
setDpr(current * initialDpr); | ||
gl.domElement.style.imageRendering = current === 1 ? "auto" : "pixelated"; | ||
}, [current]); | ||
|
||
return null; | ||
} | ||
|
||
function AdaptiveEvents() { | ||
const get = useThree((state) => state.get) | ||
const current = useThree((state) => state.performance.current) | ||
useEffect(() => { | ||
const enabled = get().events.enabled | ||
return () => void (get().events.enabled = enabled) | ||
}, []) | ||
useEffect(() => void (get().events.enabled = current === 1), [current]) | ||
return null | ||
const get = useThree(state => state.get); | ||
const current = useThree(state => state.performance.current); | ||
|
||
useEffect(() => { | ||
const enabled = get().events.enabled; | ||
return () => void (get().events.enabled = enabled); | ||
}, []); | ||
|
||
useEffect(() => void (get().events.enabled = current === 1), [current]); | ||
return null; | ||
} | ||
|
||
function Scene() { | ||
const group = useRef<THREE.Group>(null!) | ||
const [showCube, setShowCube] = useState(false) | ||
const [hovered, setHovered] = useState(false) | ||
const [color, setColor] = useState('pink') | ||
const group = useRef<THREE.Group>(null!); | ||
const [showCube, setShowCube] = useState(false); | ||
const [hovered, setHovered] = useState(false); | ||
const [color, setColor] = useState("pink"); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => setShowCube((showCube) => !showCube), 1000) | ||
return () => clearInterval(interval) | ||
}, []) | ||
useEffect(() => { | ||
const interval = setInterval(() => setShowCube(showCube => !showCube), 1000); | ||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
useFrame(({ clock }) => group.current?.rotation.set(Math.sin(clock.elapsedTime), 0, 0)) | ||
useFrame(( | ||
{ | ||
clock | ||
} | ||
) => group.current?.rotation.set(Math.sin(clock.elapsedTime), 0, 0)); | ||
|
||
return ( | ||
<> | ||
<ambientLight intensity={0.5} /> | ||
<pointLight position={[10, 10, 10]} intensity={2} /> | ||
<pointLight position={[-10, -10, -10]} color="red" intensity={4} /> | ||
|
||
<mesh | ||
scale={hovered ? 1.25 : 1} | ||
onPointerOver={() => setHovered(true)} | ||
onPointerOut={() => setHovered(false)} | ||
onClick={() => setColor(color === 'pink' ? 'peachpuff' : 'pink')}> | ||
<sphereGeometry args={[0.5, 32, 32]} /> | ||
<meshStandardMaterial color={showCube ? 'white' : 'red'} /> | ||
</mesh> | ||
<group ref={group}> | ||
{showCube ? ( | ||
<mesh position={[1.5, 0, 0]}> | ||
<boxGeometry args={[1, 1]} /> | ||
<meshNormalMaterial transparent opacity={0.5} /> | ||
</mesh> | ||
) : ( | ||
<mesh> | ||
<icosahedronGeometry args={[1]} /> | ||
<meshStandardMaterial color="orange" transparent opacity={0.5} /> | ||
</mesh> | ||
)} | ||
<mesh position={[-2, -2, 0]}> | ||
<sphereGeometry args={[0.2, 32, 32]} /> | ||
<meshPhongMaterial> | ||
{showCube ? <color attach="color" args={[0, 0, 1]} /> : <color attach="color" args={[1, 0, 0]} />} | ||
</meshPhongMaterial> | ||
return (<> | ||
<ambientLight intensity={0.5} /> | ||
<pointLight position={[10, 10, 10]} intensity={2.2} /> | ||
<pointLight position={[-10, -10, -10]} color="rgb(137, 48, 48)" intensity={6.6} /> | ||
<mesh scale={hovered ? 1.25 : 1} onPointerOver={() => setHovered(true)} onPointerOut={() => setHovered(false)} onClick={() => setColor(color === "pink" ? "peachpuff" : "pink")}> | ||
<sphereGeometry args={[0.5, 32, 32]} /> | ||
<meshStandardMaterial color={showCube ? "white" : "red"} /> | ||
</mesh> | ||
</group> | ||
<OrbitControls regress /> | ||
<AdaptivePixelRatio /> | ||
<AdaptiveEvents /> | ||
</> | ||
) | ||
<group ref={group}> | ||
{showCube ? (<mesh position={[1.5, 0, 0]}> | ||
<boxGeometry args={[1, 1]} /> | ||
<meshNormalMaterial transparent opacity={0.5} /> | ||
</mesh>) : (<mesh> | ||
<icosahedronGeometry args={[1]} /> | ||
<meshStandardMaterial color="orange" transparent opacity={0.5} /> | ||
</mesh>)} | ||
<mesh position={[-2, -2, 0]}> | ||
<sphereGeometry args={[0.2, 32, 32]} /> | ||
<meshPhongMaterial> | ||
{showCube ? (<color attach="color" args={[0, 0, 1]} />) : (<color attach="color" args={[1, 0, 0]} />)} | ||
</meshPhongMaterial> | ||
</mesh> | ||
</group> | ||
<OrbitControls regress /> | ||
<AdaptivePixelRatio /> | ||
<AdaptiveEvents /> | ||
</>); | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<Canvas dpr={[1, 2]} frameloop="always" performance={{ min: 0.1 }}> | ||
<Scene /> | ||
</Canvas> | ||
) | ||
} | ||
return (<Canvas | ||
dpr={[1, 2]} | ||
frameloop="always" | ||
performance={{ | ||
min: 0.1 | ||
}}> | ||
<Scene /> | ||
</Canvas>); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT summary of 9d173c - ce0e5e:
Error: couldn't generate summary