Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/g.frame.common.camera_controls/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.idea
.DS_Store
20 changes: 20 additions & 0 deletions packages/g.frame.common.camera_controls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# g.frame.components.window
Module repo template for g.frame

## How to use
* Create new repo and use this project as template
* Clone it
* Change all `g.frame.components.window` occurrences to your module name `g.frame.module_name`
* Rename `.github_` folder to `.github`
* Update to use latest version of `g.frame` and `three`
* Use `npm install` to install all dependencies


## How to build
* Use `npm run build` to build your module
* Use `npm run lint` to lint your code
* Use `npm run test` to run unit tests
* Use `npm run docs` to generate docs

## Useful links
* `g.frame` repo https://github.com/VeryBigThings/g.frame
25 changes: 25 additions & 0 deletions packages/g.frame.common.camera_controls/create-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# get current commit hash for tag
commit=$(git rev-parse HEAD)

# get repo name from git
remote=$(git config --get remote.origin.url)
repo=$(basename $remote .git)

# get version from package.json file
VERSION=$(jq -r '.version' package.json)
# create new tag
new=v$VERSION
# show new tag
echo $new

# POST a new ref to repo via Github API
curl -s -X POST https://api.github.com/repos/$REPO_OWNER/$repo/git/refs \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
{
"ref": "refs/tags/$new",
"sha": "$commit"
}
EOF
10 changes: 10 additions & 0 deletions packages/g.frame.common.camera_controls/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const base = require("../../jest.config.base.js");
const pack = require("./package");

module.exports = {
...base,
displayName: pack.name,
name: pack.name,
rootDir: "../..",
testMatch: [`<rootDir>/packages/${pack.name}/tests/**/.*.(test|spec)).(js|ts)`],
};
57 changes: 57 additions & 0 deletions packages/g.frame.common.camera_controls/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@verybigthings/g.frame.common.camera_controls",
"version": "0.1.0",
"description": "Template module from g.frame",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"directories": {
"doc": "docs"
},
"scripts": {
"build": "run-s clean && run-p build:*",
"build:main": "tsc -p tsconfig.json",
"clean": "trash build test",
"test": "jest --passWithNoTests",
"lint": "tslint 'src/**/*.ts?(x)'",
"docs": "trash docs && typedoc && touch docs/.nojekyll"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VeryBigThings/g.frame.git"
},
"keywords": [
"webgl",
"three.js",
"g.frame"
],
"author": "Very Big Things",
"license": "ISC",
"bugs": {
"url": "https://github.com/VeryBigThings/g.frame/issues"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/@VeryBigThings"
},
"homepage": "https://github.com/VeryBigThings/g.frame#readme",
"dependencies": {
},
"peerDependencies": {
"@verybigthings/g.frame.core": "0.1.6",
"three": "^0.123.0"
},
"devDependencies": {
"@types/jest": "^25.1.4",
"@types/node": "^13.9.1",
"copyfiles": "^2.2.0",
"jest": "^25.1.0",
"npm-run-all": "^4.1.5",
"trash-cli": "^3.0.0",
"ts-jest": "^25.2.1",
"tslint": "^6.1.0",
"typedoc": "^0.17.4",
"typescript": "^3.8.3",
"@verybigthings/g.frame.core": "0.1.6",
"three": "^0.123.0"
},
"gitHead": "2adcda2e0de0598d1351dea6068d39f70edc7f99"
}
72 changes: 72 additions & 0 deletions packages/g.frame.common.camera_controls/src/CameraControls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {EventDispatcher, Quaternion, Vector3} from 'three';
import {Constructor} from '@verybigthings/g.frame.core';

export class CameraControls extends EventDispatcher {
public __agentConstructor: Function;
public enabled: boolean = false;
public readonly platform: string;

constructor() {
super();
}

setPosition(newX: number, newY: number, newZ: number) {

}

copyPosition(newPosition: Vector3) {
this.setPosition(newPosition.x, newPosition.y, newPosition.z);
}

addPosition(addedPosition: Vector3) {

}

getPosition(): Vector3 {
return new Vector3();
}

setOrientation(newOrientation: Quaternion) {

}

getOrientation(): Quaternion {
return new Quaternion();
}

setPitch(newPitch: number): void {

}

setYaw(newYaw: number): void {

}

setRoll(newRoll: number): void {

}

getPitch(): number {
return 0;
}

getYaw(): number {
return 0;
}

getRoll(): number {
return 0;
}


getSpecific<T extends CameraControls>(constructorFunction: Constructor<T>): T {
return new constructorFunction();
}


setPositions(positionsMap: {
[platformName: string]: Vector3 | Array<number> | number | { x: number; y: number; z: number }
}): void {

}
}
94 changes: 94 additions & 0 deletions packages/g.frame.common.camera_controls/src/CameraControlsAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {Quaternion, Vector3} from 'three';
import {CameraControls} from './CameraControls';
import {Constructor} from '@verybigthings/g.frame.core';

export class CameraControlsAgent extends CameraControls {

constructor(private instances: Array<CameraControls>) {
super();
}

getSpecific<T extends CameraControls>(constructorFunction: Constructor<T>): T {
for (let i = 0; i < this.instances.length; i++) {
if (Object.getPrototypeOf(this.instances[i]).constructor === constructorFunction) return <T>this.instances[i];
}
}

setOrientation(newOrientation: Quaternion) {
for (let i = 0; i < this.instances.length; i++) {
this.instances[i].setOrientation(newOrientation);
}
}

getOrientation(): Quaternion {
for (let i = 0; i < this.instances.length; i++) {
const quaternion = this.instances[i].getOrientation();
if (quaternion) return quaternion;
}
}

setPositions(positionsMap: {
[platformName: string]: Vector3 | Array<number> | number | { x: number; y: number; z: number }
}): void {
for (let i = 0; i < this.instances.length; i++) {
const platform = this.instances[i].platform;
if (positionsMap.hasOwnProperty(platform)) {
let position: Vector3;
if (positionsMap[platform] instanceof Array) {
position = new Vector3(positionsMap[platform][0], positionsMap[platform][1], positionsMap[platform][2]);
} else if (typeof positionsMap[platform] === 'number') {
position = new Vector3(<number>positionsMap[platform], <number>positionsMap[platform], <number>positionsMap[platform]);
} else if (positionsMap[platform] instanceof Vector3) {
position = new Vector3().copy(<Vector3>positionsMap[platform]);
} else if (positionsMap[platform] instanceof Object) {
// @ts-ignore
position = new Vector3(positionsMap[platform].x, positionsMap[platform].y, positionsMap[platform].z);
}

this.instances[i].copyPosition(position);
}
}
}

setPitch(pitch: number) {
for (let i = 0; i < this.instances.length; i++) {
this.instances[i].setPitch(pitch);
}
}

setYaw(yaw: number) {
for (let i = 0; i < this.instances.length; i++) {
this.instances[i].setYaw(yaw);
}
}

setRoll(roll: number) {
for (let i = 0; i < this.instances.length; i++) {
this.instances[i].setRoll(roll);
}
}

getPitch(): number {
for (let i = 0; i < this.instances.length; i++) {
const pitch = this.instances[i].getPitch();
if (!isNaN(pitch)) return pitch;
}
}

getYaw(): number {
for (let i = 0; i < this.instances.length; i++) {
const yaw = this.instances[i].getYaw();
if (yaw) return yaw;
}
}

getRoll(): number {
for (let i = 0; i < this.instances.length; i++) {
const roll = this.instances[i].getRoll();
if (!isNaN(roll)) return roll;
}
}

}

CameraControls.prototype.__agentConstructor = CameraControlsAgent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {AbstractModule, AbstractModuleStatus, ConstructorInstanceMap} from '@verybigthings/g.frame.core';


export class CameraControlsModule extends AbstractModule {

constructor() {
super();
}

async preInit(): Promise<AbstractModuleStatus> {
console.warn('CameraControlsModule pre-initialization prevented. ' +
'You need to extend this module, look `g.frame.desktop` module.');
return {
enabled: false
};
}

async onInit(data: any): Promise<Array<any>> {
return [];
}

afterInit(agents: ConstructorInstanceMap<any>): void {
}

onUpdate(params: { currentTime: number; frame: any }): void {
}

onDestroy(): void {
}

onResume(): void {
}

onPause(): void {
}
}
2 changes: 2 additions & 0 deletions packages/g.frame.common.camera_controls/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './CameraControls';
export * from './CameraControlsAgent';
47 changes: 47 additions & 0 deletions packages/g.frame.common.camera_controls/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"compilerOptions": {
"target": "es2017",
"outDir": "build/main",
"rootDir": "src",
"moduleResolution": "node",
"module": "commonjs",
"declaration": true,
"inlineSourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "strict": true /* Enable all strict type-checking options. */,

/* Strict Type-Checking Options */
// "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
// "strictNullChecks": true /* Enable strict null checks. */,
// "strictFunctionTypes": true /* Enable strict checking of function types. */,
// "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
// "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
// "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,

// /* Additional Checks */
// "noUnusedLocals": true /* Report errors on unused locals. */,
// "noUnusedParameters": true /* Report errors on unused parameters. */,
// "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
// "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,

/* Debugging Options */
"traceResolution": false /* Report module resolution log messages. */,
"listEmittedFiles": false /* Print names of generated files part of the compilation. */,
"listFiles": false /* Print names of files part of the compilation. */,
"pretty": true /* Stylize errors and messages using color and context. */,

// /* Experimental Options */
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
// "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,

"lib": ["es2017", "dom"],
"types": ["node", "jest"],
"typeRoots": ["node_modules/@types", "src/types"]
},
"include": [
"src/**/*"
],
"exclude": ["node_modules/**", "src/**/*.spec.ts"],
"compileOnSave": false
}
Loading