Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning #105

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ name: "CodeQL config"

paths-ignore:
- "node_modules"
- "examples"
- "examples"
- "docs"
- "packages"
25 changes: 16 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import stylistic from '@stylistic/eslint-plugin';

export default [
{
files: ['**/*.{js,ts}'],
},
{
ignores: ['dist', 'vite.config.js', 'examples', 'test', 'docs', 'packages'],
},
js.configs.recommended,
...tseslint.configs.strict,
stylistic.configs.customize({
jsx: false,
semi: true,
commaDangle: 'never',
arrowParens: true,
braceStyle: '1tbs'
}),
{
ignores: ['dist', 'docs', 'packages']
},
{
rules: {
'camelcase': 'warn',
'no-unused-vars': 'off',
'no-undef': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off'
},
},
'@typescript-eslint/no-wrapper-object-types': 'off',
'@typescript-eslint/no-dynamic-delete': 'off'
}
}
];
4 changes: 2 additions & 2 deletions examples/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const box = new Mesh(new BoxGeometry(0.1, 0.1, 0.1), new MeshNormalMaterial());
box.draggable = true;
box.on('animate', (e) => box.rotateX(e.delta).rotateY(e.delta * 2));
box.on(['pointerover', 'pointerout'], function (e) {
this.tween('id').to(500, { scale: e.type === 'pointerover' ? 1.5 : 1 }, { easing: 'easeOutElastic' }).start();
this.tween('id').to(500, { scale: e.type === 'pointerover' ? 1.5 : 1 }, { easing: 'easeOutElastic' }).start();
});

const scene = new Scene().add(box);

const main = new Main({ fullscreen: false });
main.createView({ scene, camera: new PerspectiveCameraAuto(70).translateZ(1) });
main.createView({ scene, camera: new PerspectiveCameraAuto(70).translateZ(1) });
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"vite-plugin-dts": "^4.3.0",
"vite-plugin-externalize-deps": "^0.8.0",
"vite-plugin-static-copy": "^1.0.6",
"vitest": "^0.34.6"
"vitest": "^0.34.6",
"@stylistic/eslint-plugin": "^2.10.1"
},
"peerDependencies": {
"three": ">=0.151.0"
Expand Down
8 changes: 3 additions & 5 deletions src/binding/Binding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Object3D, Scene } from "three";
import { Object3D, Scene } from 'three';

/** @internal */
export interface BindingCallback<T = any> {
Expand All @@ -9,7 +9,6 @@ export interface BindingCallback<T = any> {

/** @internal */
export class Binding {

public static detectChanges(target: Object3D, resursive: boolean): void {
this.executeAllCallbacks(target);
if (resursive) {
Expand All @@ -21,7 +20,7 @@ export class Binding {

public static bindProperty<T>(key: string, target: Object3D, getValue: () => T, renderOnChange?: boolean): void {
if (this.getIndexByKey(target, key) > -1) {
console.error("Cannot override property already bound.");
console.error('Cannot override property already bound.');
return;
}

Expand Down Expand Up @@ -65,7 +64,7 @@ export class Binding {
public static setManualDetectionMode(target: Object3D): void {
if (target.__manualDetection) return;
if (target.__boundCallbacks.length > 0) {
console.error("Cannot change detectChangesMode if a binding is already created.");
console.error('Cannot change detectChangesMode if a binding is already created.');
} else {
target.__manualDetection = true;
}
Expand Down Expand Up @@ -108,5 +107,4 @@ export class Binding {
this.executeAllCallbacks(target);
}
}

}
90 changes: 45 additions & 45 deletions src/cameras/OrthographicCameraAuto.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { OrthographicCamera } from "three";
import { OrthographicCamera } from 'three';

/**
* Extends the OrthographicCamera to automatically resize based on a fixed width or height dimension.
*/
export class OrthographicCameraAuto extends OrthographicCamera {
private _size: number;
private _fixedWidth: boolean;
private _width = -1;
private _height = -1;
private _size: number;
private _fixedWidth: boolean;
private _width = -1;
private _height = -1;

/**
/**
* Gets or sets the fixed width or height dimension based on the 'fixedWidth' property.
*/
public get size(): number { return this._size }
public set size(value: number) {
this._size = value;
this.update();
}
public get size(): number { return this._size; }
public set size(value: number) {
this._size = value;
this.update();
}

/**
/**
* Determines whether the 'size' property refers to the width (true) or height (false).
*/
public get fixedWidth(): boolean { return this._fixedWidth }
public set fixedWidth(value: boolean) {
this._fixedWidth = value;
this.update();
}
public get fixedWidth(): boolean { return this._fixedWidth; }
public set fixedWidth(value: boolean) {
this._fixedWidth = value;
this.update();
}

/**
/**
* @param size Fixed width or height dimension based on the 'fixedWidth' property. Default `2`.
* @param fixedWidth If true, the 'size' property will refer to the width. If not, to the height. Default `true`.
* @param near Camera frustum near plane. Default `0.1`.
* @param far Camera frustum far plane. Default `2000`.
*/
constructor(size = 2, fixedWidth = true, near?: number, far?: number) {
super(-1, 1, 1, -1, near, far);
this._size = size;
this._fixedWidth = fixedWidth;
constructor(size = 2, fixedWidth = true, near?: number, far?: number) {
super(-1, 1, 1, -1, near, far);
this._size = size;
this._fixedWidth = fixedWidth;

this.on("viewportresize", (e) => {
this._width = e.width;
this._height = e.height;
this.update();
});
}
this.on('viewportresize', (e) => {
this._width = e.width;
this._height = e.height;
this.update();
});
}

private update(): void {
const halfSize = 0.5 * this._size;
private update(): void {
const halfSize = 0.5 * this._size;

if (this._fixedWidth) {
const aspect = this._height / this._width;
this.left = -halfSize;
this.right = halfSize;
this.top = halfSize * aspect;
this.bottom = -halfSize * aspect;
} else {
const aspect = this._width / this._height;
this.left = -halfSize * aspect;
this.right = halfSize * aspect;
this.top = halfSize;
this.bottom = -halfSize;
}

this.updateProjectionMatrix();
if (this._fixedWidth) {
const aspect = this._height / this._width;
this.left = -halfSize;
this.right = halfSize;
this.top = halfSize * aspect;
this.bottom = -halfSize * aspect;
} else {
const aspect = this._width / this._height;
this.left = -halfSize * aspect;
this.right = halfSize * aspect;
this.top = halfSize;
this.bottom = -halfSize;
}

this.updateProjectionMatrix();
}
}
21 changes: 10 additions & 11 deletions src/cameras/PerspectiveCameraAuto.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { PerspectiveCamera } from "three";
import { PerspectiveCamera } from 'three';

/**
* Extends the PerspectiveCamera to automatically adjust its aspect ratio on renderer resize.
*/
export class PerspectiveCameraAuto extends PerspectiveCamera {

/**
/**
* @param fov Camera frustum vertical field of view in degrees. Default `50`.
* @param near Camera frustum near plane distance. Default `0.1`.
* @param far Camera frustum far plane distance. Default `2000`.
*/
constructor(fov?: number, near?: number, far?: number) {
super(fov, undefined, near, far);
this.on("viewportresize", (e) => {
this.aspect = e.width / e.height;
this.updateProjectionMatrix();
});
}
constructor(fov?: number, near?: number, far?: number) {
super(fov, undefined, near, far);

this.on('viewportresize', (e) => {
this.aspect = e.width / e.height;
this.updateProjectionMatrix();
});
}
}
Loading
Loading