-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrading the pixiJS demo adding a slider effect like https://tympanu…
- Loading branch information
Showing
18 changed files
with
20,871 additions
and
66 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { Vector2, Mesh } from '@babylonjs/core'; | ||
import { useBabylonScene } from '../../../../dist/react-babylonjs'; | ||
import './shaders'; | ||
let customProceduralTexture = null; | ||
let time = 0; | ||
|
||
const onCustomProceduralTextureCreated = (cpt) => { | ||
customProceduralTexture = cpt; // assigning to reflection/refraction of mirrorball | ||
} | ||
|
||
const VaporWave = (props) => { | ||
const scene = useBabylonScene(); | ||
useEffect(() => { | ||
const observable = scene.onBeforeRenderObservable.add((scene) => { | ||
if (scene !== null && customProceduralTexture !== null) { | ||
time += scene.getEngine().getDeltaTime(); | ||
customProceduralTexture.setFloat("time", time); | ||
} | ||
}) | ||
return () => { | ||
scene.onBeforeRenderObservable.remove(observable); | ||
} | ||
}) | ||
|
||
return (<> | ||
<plane | ||
name='vaporWareSunset' | ||
width={20} | ||
height={20} | ||
billboardMode={Mesh.BILLBOARDMODE_ALL}> | ||
<standardMaterial name='shaderMat'> | ||
<customProceduralTexture | ||
name='vaporWaveTexture' | ||
texturePath="vaporWave" | ||
size={512} | ||
onCreated={onCustomProceduralTextureCreated} | ||
assignTo='diffuseTexture' | ||
setVector2={["resolution", new Vector2(1, 1)]} | ||
/> | ||
</standardMaterial> | ||
</plane> | ||
</>) | ||
} | ||
|
||
export default VaporWave |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { createContext, useRef, useContext } from "react" | ||
import { useBeforeRender } from '../../../../dist/react-babylonjs' | ||
import { Vector3, } from '@babylonjs/core'; | ||
import lerp from "lerp" | ||
import state from "./store" | ||
|
||
const offsetContext = createContext(0) | ||
|
||
function Block({ children, offset, factor, ...props }) { | ||
const { offset: parentOffset, sectionHeight } = useBlock() | ||
offset = offset !== undefined ? offset : parentOffset | ||
const ref = useRef() | ||
useBeforeRender((scene) => { | ||
if(ref.current && ref.current.hostInstance.position){ | ||
const curY = ref.current.hostInstance.position.y; | ||
const curTop = state.top.current; | ||
ref.current.hostInstance.position.y = lerp(curY, (curTop / state.zoom) * factor, 0.1); | ||
} | ||
}); | ||
|
||
return ( | ||
<offsetContext.Provider value={offset}> | ||
<transformNode {...props} name={`transformNode${Math.random()}`} position={new Vector3(0, -sectionHeight * offset * factor, 0)}> | ||
<transformNode name={`tweenNode-${Math.random()}`} ref={ref}>{children}</transformNode> | ||
</transformNode> | ||
</offsetContext.Provider> | ||
) | ||
} | ||
|
||
function useBlock() { | ||
const { sections, pages, zoom } = state | ||
const viewPortSize = { | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
} | ||
const size = viewPortSize; | ||
const viewport = viewPortSize; | ||
const offset = useContext(offsetContext) | ||
const viewportWidth = viewport.width | ||
const viewportHeight = viewport.height | ||
const canvasWidth = viewportWidth / zoom | ||
const canvasHeight = viewportHeight / zoom | ||
const mobile = size.width < 700 | ||
const margin = canvasWidth * (mobile ? 0.2 : 0.1) | ||
const contentMaxWidth = canvasWidth * (mobile ? 0.8 : 0.6) | ||
const sectionHeight = canvasHeight * ((pages - 1) / (sections - 1)) | ||
const offsetFactor = (offset + 1.0) / sections | ||
|
||
return { | ||
viewport, | ||
offset, | ||
viewportWidth, | ||
viewportHeight, | ||
canvasWidth, | ||
canvasHeight, | ||
mobile, | ||
margin, | ||
contentMaxWidth, | ||
sectionHeight, | ||
offsetFactor | ||
} | ||
} | ||
|
||
export { Block, useBlock } |
File renamed without changes.
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
Oops, something went wrong.