Skip to content

Commit

Permalink
chore: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-mason committed Apr 14, 2024
1 parent 47cdb58 commit ac4f258
Show file tree
Hide file tree
Showing 26 changed files with 1,568 additions and 1,703 deletions.
12 changes: 6 additions & 6 deletions packages/react-three-jolt/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"tabWidth": 4,
"bracketSameLine": true
}
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"tabWidth": 4,
"bracketSameLine": true
}
159 changes: 98 additions & 61 deletions packages/react-three-jolt/README.md

Large diffs are not rendered by default.

139 changes: 70 additions & 69 deletions packages/react-three-jolt/package.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
{
"name": "@react-three/jolt",
"description": "Jolt physics in React",
"keywords": [
"physics",
"jolt-physics",
"react-three-fiber",
"react",
"three"
],
"version": "0.0.1",
"author": "Dennis Smolek",
"contributors": [
"Dennis Smolek",
"Isaac Mason <[email protected]>"
],
"license": "MIT",
"homepage": "https://github.com/pmndrs/react-three-jolt",
"bugs": {
"url": "https://github.com/pmndrs/react-three-jolt/issues"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"name": "@react-three/jolt",
"description": "Jolt physics in React",
"keywords": [
"physics",
"jolt-physics",
"react-three-fiber",
"react",
"three"
],
"version": "0.0.1",
"author": "Dennis Smolek",
"contributors": [
"Dennis Smolek",
"Isaac Mason <[email protected]>"
],
"license": "MIT",
"homepage": "https://github.com/pmndrs/react-three-jolt",
"bugs": {
"url": "https://github.com/pmndrs/react-three-jolt/issues"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"files": [
"dist/**",
"README.md",
"LICENSE"
],
"scripts": {
"test": "vitest run --coverage",
"build": "tsc && rollup --config rollup.config.mjs",
"format": "prettier --write ."
},
"peerDependencies": {
"@react-three/fiber": ">=8.9.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"dependencies": {
"gamepad.js": "^2.1.0",
"jolt-physics": "^0.22.0"
},
"devDependencies": {
"@react-three/fiber": "8.16.1",
"@react-three/test-renderer": "^8.2.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/three": "^0.163.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^7.5.0",
"@vitest/coverage-v8": "^1.4.0",
"eslint": "^9.0.0",
"happy-dom": "^14.7.0",
"prettier": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^4.14.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-filesize": "^10.0.0",
"three": "^0.163.0",
"typescript": "^5.4.4",
"vitest": "^1.5.0"
}
},
"files": [
"dist/**",
"README.md",
"LICENSE"
],
"scripts": {
"test": "vitest run --coverage",
"build": "tsc && rollup --config rollup.config.mjs"
},
"peerDependencies": {
"@react-three/fiber": ">=8.9.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"dependencies": {
"gamepad.js": "^2.1.0",
"jolt-physics": "^0.22.0"
},
"devDependencies": {
"@react-three/fiber": "8.16.1",
"@react-three/test-renderer": "^8.2.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/three": "^0.163.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^7.5.0",
"@vitest/coverage-v8": "^1.4.0",
"eslint": "^9.0.0",
"happy-dom": "^14.7.0",
"prettier": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^4.14.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-filesize": "^10.0.0",
"three": "^0.163.0",
"typescript": "^5.4.4",
"vitest": "^1.5.0"
}
}
7 changes: 4 additions & 3 deletions packages/react-three-jolt/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const Layer = {
MOVING: 0,
NON_MOVING: 1,
KINEMATIC: 2,
RIG: 3,
};
export const NUM_OBJECT_LAYERS = 3;
RIG: 3
};

export const NUM_OBJECT_LAYERS = 3;
19 changes: 6 additions & 13 deletions packages/react-three-jolt/src/heightField/generators-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export function textureToCanvas(texture: THREE.Texture) {
return canvas;
}

export async function imageUrlToImageData(
url: string,
scalingFactor?: number,
): Promise<ImageData> {
export async function imageUrlToImageData(url: string, scalingFactor?: number): Promise<ImageData> {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => {
Expand All @@ -30,12 +27,8 @@ export async function imageUrlToImageData(
reject(new Error('No context'));
return;
}
const width = scalingFactor
? image.width * scalingFactor
: image.width;
const height = scalingFactor
? image.height * scalingFactor
: image.height;
const width = scalingFactor ? image.width * scalingFactor : image.width;
const height = scalingFactor ? image.height * scalingFactor : image.height;
canvas.width = width;
canvas.height = height;
context.drawImage(image, 0, 0, width, height);
Expand Down Expand Up @@ -63,7 +56,7 @@ export function textureToImageData(texture: THREE.Texture): ImageData {
height / 2,
height / -2,
1,
1000,
1000
);
const planeGeometry = new THREE.PlaneGeometry(width, height);
const planeMaterial = new THREE.MeshBasicMaterial({ map: texture });
Expand All @@ -84,7 +77,7 @@ export function textureToImageData(texture: THREE.Texture): ImageData {
export function applyHeightmapImgDataToPlane(
plane: THREE.Mesh,
heightmap: ImageData,
displacementScale: number,
displacementScale: number
) {
const { width, height } = heightmap;
const geometry = plane.geometry as THREE.PlaneGeometry;
Expand All @@ -107,7 +100,7 @@ export function applyHeightmapImgDataToPlane(
export async function applyHeightmapToPlane(
plane: THREE.Mesh,
heightmap: string | THREE.Texture,
displacementScale: number,
displacementScale: number
) {
let heightmapImgData: ImageData;
if (typeof heightmap === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ function handleMessage(message) {
}

// setup the canvas and renderer
function initializeRenderer(
newCanvas: OffscreenCanvas,
height = 1024,
width = 1024,
) {
function initializeRenderer(newCanvas: OffscreenCanvas, height = 1024, width = 1024) {
if (!newCanvas) console.log('WORKER: no canvas sent, creating a new one');
canvas = newCanvas || new OffscreenCanvas(width, height);
renderer = new THREE.WebGLRenderer({ canvas });
Expand All @@ -68,7 +64,7 @@ function initializeScene(width = 1024, height = 1024, resolution = 1) {
width,
height,
width / resolution,
height / resolution,
height / resolution
);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
plane = new THREE.Mesh(geometry, material);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as THREE from 'three';
// setup a single worker regardless of how many heightfields we have
const worker = new Worker(new URL('./heightfield-worker.ts', import.meta.url), {
type: 'module',
type: 'module'
});

export class HeightfieldManager {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-three-jolt/src/hooks/use-forwarded-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ForwardedRef, MutableRefObject, useRef } from 'react';
// Need to catch the case where forwardedRef is a function... how to do that?
export const useForwardedRef = <T>(
forwardedRef: ForwardedRef<T>,
defaultValue: T | null = null,
defaultValue: T | null = null
): MutableRefObject<T> => {
const innerRef = useRef<T>(defaultValue);

Expand Down
42 changes: 11 additions & 31 deletions packages/react-three-jolt/src/systems/camera-rig-system-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ export class CameraRigManager {
// trigger the camera change listeners
private triggerCameraChange() {
console.log('triggering camera change', this.activeCamera);
this.cameraChangeListeners.forEach((listener) =>
listener(this.activeCamera)
);
this.cameraChangeListeners.forEach((listener) => listener(this.activeCamera));
}

//attach a camera to a point
Expand Down Expand Up @@ -195,24 +193,16 @@ export class CameraRigManager {

createCollar() {
const collar = this.createRigPoint('collar', { color: '#0098DE' });
const joint = this.constraintSystem.addConstraint(
'hinge',
this.base,
collar,
{
axis: new THREE.Vector3(0, 1, 0),
normal: new THREE.Vector3(0, 0, 1),
const joint = this.constraintSystem.addConstraint('hinge', this.base, collar, {
axis: new THREE.Vector3(0, 1, 0),
normal: new THREE.Vector3(0, 0, 1),

spring: {
strength: 1
}
spring: {
strength: 1
}
);
});
// TODO convert this to the constraint map
this.collarConstraint = Raw.module.castObject(
joint,
Raw.module.HingeConstraint
);
this.collarConstraint = Raw.module.castObject(joint, Raw.module.HingeConstraint);
}

//create the camera mount
Expand All @@ -225,10 +215,7 @@ export class CameraRigManager {
mGravityFactor: 0
}
};
const mountHandle = this.physicsSystem.bodySystem.addBody(
mesh,
options
);
const mountHandle = this.physicsSystem.bodySystem.addBody(mesh, options);
const mount = this.physicsSystem.bodySystem.getBody(mountHandle);
//change the mass
this.physicsSystem.bodySystem.setMass(mountHandle, 0.00001);
Expand Down Expand Up @@ -341,10 +328,7 @@ export class CameraRigManager {
this.timeRecentering += deltaTime;
const newPosition = !this.allowFollowDelay
? anchorPosition
: basePosition.lerp(
anchorPosition,
smoothFactor * deltaTime * this.cameraFollowSpeed
);
: basePosition.lerp(anchorPosition, smoothFactor * deltaTime * this.cameraFollowSpeed);
this.base.setPosition(newPosition);
}

Expand Down Expand Up @@ -441,11 +425,7 @@ export class CameraRigManager {
//TODO move this to the body system
//create rig points
createRigPoint(name, options?): BodyState {
const {
color = '#767B91',
type = 'sphere',
motionType
} = options || {};
const { color = '#767B91', type = 'sphere', motionType } = options || {};
/* / TODO Cylinder throws errors
const geometry =
type == 'sphere'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as THREE from 'three';
import { MathUtils } from 'three';
import Jolt from 'jolt-physics';
import { Raw } from '../raw';
import { Layer } from '../constants'
import { Layer } from '../constants';
import { PhysicsSystem } from './physics-system';
import { _matrix4, _position, _quaternion, _rotation, _scale, _vector3 } from '../tmp';
import { quat, vec3 } from '../utils';
Expand Down

0 comments on commit ac4f258

Please sign in to comment.