### Install and Run Examples Source: https://github.com/hmans/composer-suite/blob/main/packages/vfx-composer/README.md Instructions for cloning the repository and running the examples locally using yarn. This is useful for development and testing. ```bash yarn && yarn examples ``` -------------------------------- ### Managing Multiple Examples Source: https://github.com/hmans/composer-suite/blob/main/packages/r3f-stage/README.md Illustrates how to structure multiple examples using the `Example` component, including setting a default example with `makeDefault` and providing titles. ```tsx import { Application, Example, Description } from "r3f-stage" function App() { return ( This is a very simple example. This is also a very simple example. ) } ``` -------------------------------- ### Development Environment Setup and Execution Source: https://github.com/hmans/composer-suite/blob/main/README.md Instructions for setting up and running the development environment for the Composer Suite monorepo using Preconstruct and Turborepo. It covers linking packages and running individual or all example applications. ```sh # Link all apps and packages for development pnpm dev:link # Start all apps in development mode pnpm dev # Start individual apps pnpm dev --filter spacerage pnpm dev --filter vfx-composer-examples pnpm dev --filter shader-composer-examples ``` -------------------------------- ### Structuring Navigation with Headings Source: https://github.com/hmans/composer-suite/blob/main/packages/r3f-stage/README.md Explains how to use the `Heading` component to organize examples within the navigation UI, creating distinct sections for different groups of examples. ```tsx import { Application, Example, Heading } from "r3f-stage" function App() { return ( Main Examples Extra Examples ) } ``` -------------------------------- ### Install R3F Stage Source: https://github.com/hmans/composer-suite/blob/main/packages/r3f-stage/README.md Installs the R3F Stage library and its optional TypeScript types using Yarn. ```sh # Mandatory yarn install r3f-stage # Types (optional, but very useful) yarn install -D @types/three ``` -------------------------------- ### Adding Descriptions to Examples Source: https://github.com/hmans/composer-suite/blob/main/packages/r3f-stage/README.md Shows how to use the `Description` component within the `Application` to display text descriptions for your Three.js examples. ```tsx import { Application, Description } from "r3f-stage" function App() { return ( This is a really simple example. Let's move on to more interesting things! ) } ``` -------------------------------- ### Development Setup Commands Source: https://github.com/hmans/composer-suite/blob/main/packages/timeline-composer/README.md Commands to set up the development environment for Timeline Composer using the PNPM package manager. ```sh pnpm install pnpm dev ``` -------------------------------- ### Basic Application Setup Source: https://github.com/hmans/composer-suite/blob/main/packages/r3f-stage/README.md Demonstrates the basic usage of the `Application` component from `r3f-stage` to render a simple Three.js mesh. It also shows how to import the global stylesheet. ```tsx import { Application } from "r3f-stage" /* r3f-stage provides a global stylesheet. Please import it in your application and remove any other global styles you may have defined. */ import "r3f-stage/styles.css" function App() { return ( ) } ``` -------------------------------- ### Using Uniforms in Shader Composition Source: https://github.com/hmans/composer-suite/blob/main/apps/shader-composer-examples/index.html Illustrates how to incorporate uniform variables into shader compositions, allowing for dynamic control of shader properties at runtime. This example shows passing a color uniform. ```javascript import { ShaderComposer } from 'shader-composer'; import { UniformNode, Vec3Node, AddNode, OutputNode } from 'shader-composer/nodes'; const composer = new ShaderComposer(); const colorUniform = new UniformNode('u_color', new Vec3Node(1.0, 0.0, 0.0)); // Red color const baseColor = new Vec3Node(0.1, 0.1, 0.1); const mixedColor = new AddNode(baseColor, colorUniform); const output = new OutputNode(mixedColor); composer.addNode(output); const shader = composer.compile({ uniforms: { u_color: { value: [0.2, 0.8, 0.3] } // Pass a green color } }); console.log(shader.fragmentShader); ``` -------------------------------- ### Conditional Logic with IfNode Source: https://github.com/hmans/composer-suite/blob/main/apps/shader-composer-examples/index.html Demonstrates how to implement conditional logic within shaders using the IfNode. This example changes output based on a uniform value. ```javascript import { ShaderComposer } from 'shader-composer'; import { IfNode, FloatNode, Vec3Node, OutputNode } from 'shader-composer/nodes'; const composer = new ShaderComposer(); const condition = new FloatNode(0.5); const valueIfTrue = new Vec3Node(1.0, 0.0, 0.0); // Red const valueIfFalse = new Vec3Node(0.0, 0.0, 1.0); // Blue const conditionalOutput = new IfNode(condition, valueIfTrue, valueIfFalse); const output = new OutputNode(conditionalOutput); composer.addNode(output); const shader = composer.compile({ uniforms: { condition: { value: 0.7 } // This will make the output blue } }); console.log(shader.fragmentShader); ``` -------------------------------- ### Basic Shader Composition Source: https://github.com/hmans/composer-suite/blob/main/apps/shader-composer-examples/index.html Demonstrates the fundamental process of creating a simple shader using shader-composer nodes. This includes setting up input nodes, processing nodes, and an output node. ```javascript import { ShaderComposer } from 'shader-composer'; import { Vec3Node, AddNode, MultiplyNode, OutputNode } from 'shader-composer/nodes'; const composer = new ShaderComposer(); const inputA = new Vec3Node(1.0, 0.5, 0.2); const inputB = new Vec3Node(0.2, 0.3, 0.8); const added = new AddNode(inputA, inputB); const multiplied = new MultiplyNode(added, new Vec3Node(0.5, 0.5, 0.5)); const output = new OutputNode(multiplied); composer.addNode(output); const shader = composer.compile(); console.log(shader.vertexShader); console.log(shader.fragmentShader); ``` -------------------------------- ### Install Timeline Composer Source: https://github.com/hmans/composer-suite/blob/main/packages/timeline-composer/README.md Instructions for adding the timeline-composer package to your project using popular package managers. ```sh yarn add timeline-composer npm add timeline-composer pnpm add timeline-composer ``` -------------------------------- ### Basic Render Pipeline Setup Source: https://github.com/hmans/composer-suite/blob/main/packages/render-composer/README.md Demonstrates the basic usage of Render Composer by setting up a render pipeline within a React Three Fiber canvas. It includes a directional light and a mesh. ```tsx import * as RC from "render-composer" function App() { return ( {/* Just do normal R3F stuff inside. */} ) } ``` -------------------------------- ### Lazy-loading Components in Examples Source: https://github.com/hmans/composer-suite/blob/main/packages/r3f-stage/README.md Demonstrates how to use `React.lazy` to load components asynchronously within an R3F Stage example. R3F Stage will display a loading indicator during the component's load time. ```tsx import { Application, Example, Description } from "r3f-stage" import { lazy } from "react" const HugeExample = lazy(() => import("./HugeExample")) function App() { return ( This is an example that uses a lot of resources and uses a long time to load, which is why we're loading it lazily. {/* ... */} ) } ``` -------------------------------- ### Functional Composition Example Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer/README.md Demonstrates functional composition for creating shader effects, including a nested approach and a more readable version using fp-ts pipe. ```js ShaderMaterialMaster({ color: Mul(new Color("hotpink"), NormalizePlusMinusOne(Sin(Time()))) }) ``` -------------------------------- ### createLoader Usage Example Source: https://github.com/hmans/composer-suite/blob/main/packages/hmans-r3f-create-loader/README.md Demonstrates how to use the createLoader hook to define and use preloaded assets. It shows defining loaders in a central module and consuming them in a component. ```js import { createLoader } from "@hmans/r3f-create-loader" /* ...import loaders... */ export const useAsset = { asteroid: createLoader(GLTFLoader, "/models/asteroid.gltf"), music: createLoader(AudioLoader, "/sounds/music.mp3"), fog: createLoader(TextureLoader, "/textures/fog.png") } import { useAsset } from "./assets" function Asteroid() { /* Equivalent to `useTexture(\"/textures/fog.png\")`, but you can't get the URL wrong and the preloading is triggered at time of importing `assets.ts`. */ const fog = useAsset.fog() return /* ... */ } ``` -------------------------------- ### Transitioning to Gameplay State Source: https://github.com/hmans/composer-suite/blob/main/packages/state-composer/README.md Provides an example of a function that transitions the state machine from the 'menu' state to the 'gameplay' state. It includes a guard to check the current state and executes initialization logic before the transition. ```typescript export const enterGameplay = () => { /* Check if we're currently in an expected state */ if (!GameState.is("menu")) return /* Execute some code that should run at the transition */ initializeGameplay() /* Transition to the next state */ GameState.enter("gameplay") } ``` -------------------------------- ### Basic Animation Timeline Example Source: https://github.com/hmans/composer-suite/blob/main/packages/timeline-composer/README.md Demonstrates orchestrating a staggered animation using Delay and Lifetime components within a React project. ```jsx ``` -------------------------------- ### Shader Composer Example Source: https://github.com/hmans/composer-suite/blob/main/README.md Demonstrates how to use Shader Composer to create a dynamic shader material in React. It utilizes hooks like `useShader` and functions like `pipe`, `Vec3`, `Mix`, `NormalizePlusMinusOne`, `Sin`, `Add`, and `Fresnel` to define shader logic. ```jsx const ShaderComposerExample = () => { const shader = useShader(() => ShaderMaterialMaster({ color: pipe( Vec3(new Color("red")), (v) => Mix(v, new Color("white"), NormalizePlusMinusOne(Sin(Time()))), (v) => Add(v, Fresnel()) ) }) ) return ( ) } ``` -------------------------------- ### Combining Timeline Components Source: https://github.com/hmans/composer-suite/blob/main/packages/timeline-composer/README.md An example showcasing the combination of Lifetime, Repeat, and Delay components to create complex animation sequences. ```jsx

I miss the blink tag!

``` -------------------------------- ### Toggling Between States with Repeat Source: https://github.com/hmans/composer-suite/blob/main/packages/timeline-composer/README.md An example of repeatedly toggling between two states using Repeat, Lifetime, and Delay components. ```jsx

See

Saw

``` -------------------------------- ### Configure Three.js Bindings Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer-three/README.md Imports and configures the Shader Composer Three.js bindings. This setup is necessary to use Shader Composer with Three.js materials and shaders. ```js import { compileShader } from "@shader-composer/core" import configureThree from "@shader-composer/three" configureThree() ``` -------------------------------- ### Material Composer Example Source: https://github.com/hmans/composer-suite/blob/main/README.md Illustrates the usage of Material Composer to customize Three.js materials within a React application. It shows how to layer modules like `Modules.Color` and `Modules.Fresnel`, and control their properties using functions like `NormalizePlusMinusOne`, `Sin`, and `Time`. ```jsx const MaterialComposerExample = () => ( ) ``` -------------------------------- ### Emitter with Timeline Composer Integration Source: https://github.com/hmans/composer-suite/blob/main/packages/vfx-composer-r3f/README.md Provides an example of integrating the Emitter component with Timeline Composer's Repeat and Lifetime components for timed and repeated emission bursts. ```jsx ``` -------------------------------- ### Adding Full-Screen Post-Processing Effects Source: https://github.com/hmans/composer-suite/blob/main/packages/render-composer/README.md Shows how to integrate post-processing effects from the 'postprocessing' library using Render Composer's effect wrappers. This example includes SMAA, Selective Bloom, and Vignette effects. ```tsx import * as RC from "render-composer" function App() { return ( {/* ...normal R3F stuff here. */} ) } ``` -------------------------------- ### Timeline Composer Animation Sequence Source: https://github.com/hmans/composer-suite/blob/main/README.md Provides an example of using Timeline Composer's React components to orchestrate an animation sequence. It demonstrates the use of `Lifetime`, `Delay`, `SmokeRing`, `Fireball`, `CameraShake`, `Rocks`, and `SmokeCloud` to define timed events and visual elements. ```jsx ``` -------------------------------- ### Example Usage of useNullableState Source: https://github.com/hmans/composer-suite/blob/main/packages/hmans-use-nullable-state/README.md Demonstrates how to use the useNullableState hook in a React component to manage a piece of state that can be null. It includes buttons to set the state to a value and to clear it (set to null). ```javascript import React from 'react'; import useNullableState from './useNullableState'; // Assuming the hook is in this file function MyComponent() { const [data, setData] = useNullableState(null); const handleSetData = () => { setData('Some data value'); }; const handleClearData = () => { setData(null); }; return (

Current state: {data === null ? 'null' : data}

); } export default MyComponent; ``` -------------------------------- ### Composer Suite Core Tenets Source: https://github.com/hmans/composer-suite/blob/main/README.md This section details the fundamental principles guiding the development of the Composer Suite libraries. It highlights the commitment to TypeScript for enhanced type safety, seamless Hot Module Reloading (HMR) for an improved developer experience, a preference for declarative programming paradigms (like JSX) over imperative ones, and the design goal of creating libraries that are both independently usable and interoperable. ```text Authored in and for TypeScript. All libraries are authored in TypeScript, with first-class type support. This means that you can use these libraries in JavaScript, but you will get the best experience when using TypeScript. If you're using them from within JavaScript, please be aware that these libraries will not make any significant effort to provide runtime type checking or similar. Flawless HMR. The libraries should provide a fun and flawless development experience with the best support for hot-module reloading possible. The user should be able to hot-reload their code and see the changes immediately in the browser. Where possible, state should be retained; there must never be errors when hot-reloading. Prefer Declarative over Imperative. Where possible, allow the user to declare logic and data using JSX, instead of forcing them out of the declarative JSX layer and towards hooks (or even further into the imperative world.) Usable Individually, and Together. Where possible, libraries should be designed so they can be used individually, but also together. ``` -------------------------------- ### Unit Initialization with Expressions Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer/README.md Demonstrates initializing shader units with plain JavaScript values, references to other units, or GLSL expressions using tagged template literals. ```ts const number = Unit("float", 1.5) const number = Unit("float", Add(1, 0.5)) const number = Unit("float", $`1 + 0.5`) ``` -------------------------------- ### Create and Use State Machine Source: https://github.com/hmans/composer-suite/blob/main/packages/state-composer/README.md Demonstrates how to define states for a state machine and create an instance using createStateMachine. This sets up the foundation for managing game states. ```typescript /* Define a type of possible states */ type State = "menu" | "gameplay" | "pause" | "gameover" /* Create and export the State Machine */ export const GameState = createStateMachine("menu") ``` -------------------------------- ### Basic Shader Material Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer/README.md Demonstrates the creation of a basic shader graph for use with THREE.ShaderMaterial, setting a fixed color. ```javascript const root = ShaderMaterialMaster({ color: new Color("hotpink") }) ``` -------------------------------- ### Creating Custom Shader Units Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer/README.md Illustrates how to create custom shader units using the `Unit` function, specifying the GLSL type, value, and configuration options. ```ts const color = Unit("vec3", new Color("hotpink"), { name: "My favorite color" }) ``` -------------------------------- ### Readable Shader Composition with fp-ts Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer/README.md Shows how to use the `pipe` function from fp-ts for more readable shader graph construction, composing Time, Sin, NormalizePlusMinusOne, and Mul operations. ```ts import { pipe } from "fp-ts/function" const ModulateOverTime = (color: Input<"vec3">) => pipe( Time(), (v) => Sin(v), (v) => NormalizePlusMinusOne(v), (v) => Mul(color, v) ) ShaderMaterialMaster({ color: ModulateOverTime(new Color("hotpink")) }) ``` -------------------------------- ### Creating Reusable Shader Unit Functions Source: https://github.com/hmans/composer-suite/blob/main/packages/shader-composer/README.md Shows how to create functions that generate shader units, accepting `Input` types for flexibility and using expressions for GLSL code. ```ts const AddTwoNumbers = (a: Input<"float">, b: Input<"float"> ) => Unit("float", $`${a} + ${b}`) ``` -------------------------------- ### Three.js Audio Primitive Wrappers Source: https://github.com/hmans/composer-suite/blob/main/packages/audio-composer/README.md Wrappers for basic Three.js audio primitives like AudioListener, PositionalAudio, and Audio. These are foundational components for integrating audio into React-Three-Fiber applications. ```jsx import { AudioListener, PositionalAudio, Audio } from '@react-three/fiber'; // Example usage: