Skip to content

Commit

Permalink
Merge pull request #47 from ninjadev/example-project
Browse files Browse the repository at this point in the history
Bump to version 2.1.0
  • Loading branch information
sigvef authored Jul 7, 2022
2 parents 9847cf5 + 9c1396a commit b49f0e3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 355 deletions.
2 changes: 1 addition & 1 deletion example-project/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "renin-example-project",
"version": "1.0.0",
"version": "2.1.0",
"type": "module",
"private": true,
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions example-project/src/JumpingBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
BoxGeometry,
Color,
DoubleSide,
FloatType,
LinearEncoding,
Mesh,
MeshBasicMaterial,
NoToneMapping,
PerspectiveCamera,
RawShaderMaterial,
Scene,
Expand All @@ -29,11 +32,13 @@ export class JumpingBox extends ReninNode {
beam: Mesh<BoxGeometry, MeshBasicMaterial>;

/* The renderTarget for this node. */
renderTarget = new WebGLRenderTarget(640, 360);
renderTarget = new WebGLRenderTarget(640, 360, {
type: FloatType,
});

/* In the constructor we set up our scene. */
constructor() {
super();
constructor(renin: Renin) {
super(renin);
this.cube = new Mesh(
new BoxGeometry(),
new ShaderMaterial({
Expand Down Expand Up @@ -105,6 +110,8 @@ export class JumpingBox extends ReninNode {
/* At the end of our render implementation, we finally render
* to the renderTarget, making the output available to the parent node. */
renderer.setRenderTarget(this.renderTarget);
renderer.toneMapping = NoToneMapping;
renderer.outputEncoding = LinearEncoding;
renderer.render(this.scene, this.camera);
}
}
19 changes: 10 additions & 9 deletions example-project/src/PostFx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ export class PostFx extends ReninNode {
})
);

children = children<{
switcher: SceneSwitcher;
}>({
switcher: SceneSwitcher,
});

constructor() {
super();
constructor(renin: Renin) {
super(renin);
this.scene.add(this.screen);
this.camera.position.z = 10;

this.children = children<{
switcher: SceneSwitcher;
}>({
switcher: new SceneSwitcher(renin),
});
}

public render(frame: number, renderer: WebGLRenderer, _renin: Renin) {
this.screen.material.uniforms.frame.value = frame;
this.screen.material.uniforms.tDiffuse.value = this.children.switcher.renderTarget.texture;
//@ts-ignore
this.screen.material.uniforms.tDiffuse.value = this.children?.switcher.renderTarget.texture;
this.screen.material.needsUpdate = true;
renderer.render(this.scene, this.camera);
}
Expand Down
28 changes: 15 additions & 13 deletions example-project/src/SceneSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@ export class SceneSwitcher extends ReninNode {
camera = new OrthographicCamera(-1, 1, 1, -1);
renderTarget = new WebGLRenderTarget(640, 360);
screen = new Mesh(new BoxGeometry(2, 2, 2), new MeshBasicMaterial());

children = children<{
spinningcube: SpinningDonut;
jumpingbox: JumpingBox;
}>({
spinningcube: SpinningDonut,
jumpingbox: JumpingBox,
});
public resize(width: number, height: number) {
this.renderTarget.setSize(width, height);
}

constructor() {
super();
constructor(renin: Renin) {
super(renin);

this.children = children<{
spinningcube: SpinningDonut;
jumpingbox: JumpingBox;
}>({
spinningcube: new SpinningDonut(renin),
jumpingbox: new JumpingBox(renin),
});
this.scene.add(this.screen);
this.scene.add(this.camera);
this.camera.position.z = 10;
}

public render(frame: number, renderer: WebGLRenderer, _renin: Renin) {
public render(frame: number, renderer: WebGLRenderer, renin: Renin) {
this.screen.material.map = null;
if (this.children.jumpingbox.isActive) {
if (this.children?.jumpingbox.isActive) {
//@ts-ignore
this.screen.material.map = this.children.jumpingbox.renderTarget.texture;
}
if (this.children.spinningcube.isActive) {
if (this.children?.spinningcube.isActive) {
//@ts-ignore
this.screen.material.map = this.children.spinningcube.renderTarget.texture;
}
this.screen.material.needsUpdate = true;
Expand Down
13 changes: 10 additions & 3 deletions example-project/src/SpinningDonut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import envMap from './envMap.jpg';
import {
BufferGeometry,
EquirectangularReflectionMapping,
FloatType,
LinearEncoding,
Mesh,
MeshPhysicalMaterial,
MeshStandardMaterial,
Expand All @@ -14,6 +16,7 @@ import {
WebGLRenderer,
WebGLRenderTarget,
} from 'three';
import { Renin } from 'renin/lib/renin';

export class SpinningDonut extends ReninNode {
/* The frame range this node will be active. */
Expand All @@ -25,11 +28,13 @@ export class SpinningDonut extends ReninNode {
cube: Mesh<BufferGeometry, MeshStandardMaterial>;

/* The renderTarget for this node. */
renderTarget = new WebGLRenderTarget(640, 360);
renderTarget = new WebGLRenderTarget(640, 360, {
type: FloatType,
});

/* In the constructor we set up our scene. */
constructor() {
super();
constructor(renin: Renin) {
super(renin);

/* Here load an image that we will use as an envMap. In renin,
* we can load images by just using THREE's built-in TextureLoader
Expand Down Expand Up @@ -75,7 +80,9 @@ export class SpinningDonut extends ReninNode {

/* At the end of our render implementation, we finally render
* to the renderTarget, making the output available to the parent node. */

renderer.setRenderTarget(this.renderTarget);
renderer.outputEncoding = LinearEncoding;
renderer.render(this.scene, this.camera);
}
}
2 changes: 1 addition & 1 deletion example-project/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const renin = new Renin({
subdivision: 12,
beatOffset: 4,
},
root: new PostFx(),
root: PostFx,
productionMode: import.meta.env.PROD,
rendererOptions: {
powerPreference: 'high-performance',
Expand Down
Loading

0 comments on commit b49f0e3

Please sign in to comment.