Skip to content

Commit

Permalink
Do not use ??, restore ordering of AddRaycastVehicleMessage values
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornstar committed Jan 4, 2022
1 parent 4ee9eb8 commit e58acaf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions examples/src/demos/RaycastVehicle/Vehicle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Wheel } from './Wheel'
import type { BoxProps, WheelInfoOptions } from '@react-three/cannon'
import type { Object3D } from 'three'

export type VehicleProps = Pick<BoxProps, 'angularVelocity' | 'position' | 'rotation'> & {
export type VehicleProps = Required<Pick<BoxProps, 'angularVelocity' | 'position' | 'rotation'>> & {
radius?: number
width?: number
height?: number
Expand Down Expand Up @@ -114,10 +114,10 @@ function Vehicle({
}

if (reset) {
chassisApi.position.set(0, 0.5, 0)
chassisApi.position.set(...position)
chassisApi.velocity.set(0, 0, 0)
chassisApi.angularVelocity.set(0, 0.5, 0)
chassisApi.rotation.set(0, -Math.PI / 4, 0)
chassisApi.angularVelocity.set(...angularVelocity)
chassisApi.rotation.set(...rotation)
}
})

Expand Down
12 changes: 6 additions & 6 deletions examples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@
integrity sha512-W/YMJMX35XgGGzX0gKORBTwnvQ+1loDOFN3XlZkW5fgpEY+7VkRUpPyqPWXQr3n6lHrsLmHIGdpznqZi54ACTQ==

"@react-three/cannon@file:..":
version "4.3.0"
version "4.4.0"
dependencies:
cannon-es "^0.18.0"
cannon-es-debugger "^0.1.4"
cannon-es-debugger "^1.0.0"

"@react-three/drei@^8.3.1":
version "8.3.1"
Expand Down Expand Up @@ -605,10 +605,10 @@ caniuse-lite@^1.0.30001286:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001289.tgz#d62a20175c4d9e740feda12a78b7c8df7866329e"
integrity sha512-hV6x4IfrYViN8cJbGFVbjD7KCrhS/O7wfDgvevYRanJ/IN+hhxpTcXXqaxy3CzPNFe5rlqdimdEB/k7H0YzxHg==

cannon-es-debugger@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/cannon-es-debugger/-/cannon-es-debugger-0.1.4.tgz#22c79ae14c52de44465690988ff647c51c79c62b"
integrity sha512-RefSPWX6gDMQsx3UWoQpkGW3R03Wwn8p1JteexQUYxDC5DnOS3U3iKhns2vVpFp6Q3AKiSSmRf7NIXnGN8L0RA==
cannon-es-debugger@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/cannon-es-debugger/-/cannon-es-debugger-1.0.0.tgz#28c6679b30dcf608e978225239f447a8fe55ccb4"
integrity sha512-sE9lDOBAYFKlh+0w+cvWKwUhJef8HYnUSVPWPL0jD15MAuVRQKno4QYZSGxgOoJkMR3mQqxL4bxys2b3RSWH8g==

cannon-es@^0.18.0:
version "0.18.0"
Expand Down
24 changes: 12 additions & 12 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,24 +794,24 @@ export function useRaycastVehicle(

const currentWorker = worker
const uuid: string[] = [ref.current.uuid]
const raycastVehicleProps = fn()

const chassisBodyUUID = getUUID(raycastVehicleProps.chassisBody)
const wheelUUIDs = raycastVehicleProps.wheels.map((ref) => getUUID(ref))
const {
chassisBody,
indexForwardAxis = 2,
indexRightAxis = 0,
indexUpAxis = 1,
wheelInfos,
wheels,
} = fn()

const chassisBodyUUID = getUUID(chassisBody)
const wheelUUIDs = wheels.map((ref) => getUUID(ref))

if (!chassisBodyUUID || !wheelUUIDs.every(isString)) return

currentWorker.postMessage({
op: 'addRaycastVehicle',
uuid,
props: [
chassisBodyUUID,
wheelUUIDs,
raycastVehicleProps.wheelInfos,
raycastVehicleProps?.indexRightAxis ?? 2,
raycastVehicleProps?.indexForwardAxis ?? 0,
raycastVehicleProps?.indexUpAxis ?? 1,
],
props: [chassisBodyUUID, wheelUUIDs, wheelInfos, indexForwardAxis, indexRightAxis, indexUpAxis],
})
return () => {
currentWorker.postMessage({ op: 'removeRaycastVehicle', uuid })
Expand Down
6 changes: 3 additions & 3 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ self.onmessage = (e) => {
const [chassisBody, wheels, wheelInfos, indexForwardAxis, indexRightAxis, indexUpAxis] = props
const vehicle = new RaycastVehicle({
chassisBody: state.bodies[chassisBody],
indexForwardAxis: indexForwardAxis,
indexRightAxis: indexRightAxis,
indexUpAxis: indexUpAxis,
indexForwardAxis,
indexRightAxis,
indexUpAxis,
})
vehicle.world = state.world
for (let i = 0; i < wheelInfos.length; i++) {
Expand Down

0 comments on commit e58acaf

Please sign in to comment.