Skip to content

Commit

Permalink
Merge commit 'bca1844d6d94cce18e2d034883009f9dc5fd3abb' as 'libs/ff-s…
Browse files Browse the repository at this point in the history
…cene'
  • Loading branch information
sdumetz committed Jun 25, 2024
2 parents 8985a81 + bca1844 commit c4eb393
Show file tree
Hide file tree
Showing 75 changed files with 7,722 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libs/ff-scene/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# FOLDERS
.idea/
.vscode/
node_modules/
built/
doc/

# FILES
.env
.DS_Store
*.log
*.tsbuildinfo
14 changes: 14 additions & 0 deletions libs/ff-scene/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright 2019 [Frame Factory GmbH](https://framefactory.ch), [Ralph Wiedemeier](https://about.me/ralphw)

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 libs/ff-scene/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# FF Scene - Typescript Foundation Library

Copyright 2019 [Frame Factory GmbH](https://framefactory.ch), [Ralph Wiedemeier](https://about.me/ralphw)
37 changes: 37 additions & 0 deletions libs/ff-scene/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "ff-scene",
"version": "0.1.0",
"description": "FF Scene Typescript Foundation Library",
"scripts": {
"build": "tsc -p source",
"test": "tsc -p test; mocha -c --ui tdd node_modules/@ff/test/scene/test.js || exit 0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/framelab/ff-scene.git"
},
"keywords": [
"typescript",
"react"
],
"author": {
"name": "Ralph Wiedemeier",
"url": "https://about.me/ralphw"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/framelab/ff-scene/issues"
},
"homepage": "https://github.com/framelab/ff-scene#readme",
"dependencies": {
"three": "^0.116.0"
},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"chai": "^4.2.0",
"mocha": "^7.0.1",
"module-alias": "^2.2.2",
"typescript": "^3.8.3"
}
}
135 changes: 135 additions & 0 deletions libs/ff-scene/source/RenderQuadView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* FF Typescript Foundation Library
* Copyright 2019 Ralph Wiedemeier, Frame Factory GmbH
*
* License: MIT
*/

import { ITypedEvent } from "@ff/core/Publisher";
import System from "@ff/graph/System";

import Viewport from "@ff/three/Viewport";
import { EViewPreset, EProjection } from "@ff/three/UniversalCamera";

import RenderView, { IPointerEvent, ITriggerEvent } from "./RenderView";

////////////////////////////////////////////////////////////////////////////////

export { IPointerEvent, ITriggerEvent };

export enum EQuadViewLayout { Single, HorizontalSplit, VerticalSplit, Quad }

export interface ILayoutChange extends ITypedEvent<"layout">
{
layout: EQuadViewLayout;
}

export default class RenderQuadView extends RenderView
{
private _layout: EQuadViewLayout = EQuadViewLayout.Quad;
private _horizontalSplit = 0.5;
private _verticalSplit = 0.5;

constructor(system: System, canvas: HTMLCanvasElement, overlay: HTMLElement)
{
super(system, canvas, overlay);
this.addEvent("layout");

this.layout = EQuadViewLayout.Single;
}

set layout(layout: EQuadViewLayout) {

if (layout === this._layout) {
return;
}

this._layout = layout;
const viewports = this.viewports;

switch (this._layout) {
case EQuadViewLayout.Single:
this.setViewportCount(1);
break;

case EQuadViewLayout.HorizontalSplit:
case EQuadViewLayout.VerticalSplit:
this.setViewportCount(2);
break;

case EQuadViewLayout.Quad:
this.setViewportCount(4);
break;
}

this.updateSplitPositions();

if (viewports[1]) {
viewports[1].setBuiltInCamera(EProjection.Orthographic, EViewPreset.Top);
viewports[1].enableCameraControl(true).orientationEnabled = false;
}

if (viewports[2]) {
viewports[2].setBuiltInCamera(EProjection.Orthographic, EViewPreset.Left);
viewports[2].enableCameraControl(true).orientationEnabled = false;
}

if (viewports[3]) {
viewports[3].setBuiltInCamera(EProjection.Orthographic, EViewPreset.Front);
viewports[3].enableCameraControl(true).orientationEnabled = false;
}

this.emit<ILayoutChange>({ type: "layout", layout });
}

get layout() {
return this._layout;
}

set horizontalSplit(value: number) {
this._horizontalSplit = value;
this.updateSplitPositions();
}

get horizontalSplit() {
return this._horizontalSplit;
}

set verticalSplit(value: number) {
this._verticalSplit = value;
this.updateSplitPositions();
}

get verticalSplit() {
return this._verticalSplit;
}

protected updateSplitPositions()
{
const h = this._horizontalSplit;
const v = this._verticalSplit;

switch (this._layout) {
case EQuadViewLayout.Single:
this.viewports[0].setSize(0, 0, 1, 1);
break;

case EQuadViewLayout.HorizontalSplit:
this.viewports[0].setSize(0, 0, h, 1);
this.viewports[1].setSize(h, 0, 1-h, 1);
break;

case EQuadViewLayout.VerticalSplit:
this.viewports[0].setSize(0, 1-v, 1, v);
this.viewports[1].setSize(0, 0, 1, 1-v);
break;

case EQuadViewLayout.Quad:
this.viewports[0].setSize(0, 1-v, h, v);
this.viewports[1].setSize(h, 1-v, 1-h, v);
this.viewports[2].setSize(0, 0, h, 1-v);
this.viewports[3].setSize(h, 0, 1-h, 1-v);
break;
}
}
}
Loading

0 comments on commit c4eb393

Please sign in to comment.