From eed7ce3066f884ece62b55885fcfb7fb1ec8cffc Mon Sep 17 00:00:00 2001 From: bbupton Date: Tue, 8 Aug 2023 14:52:30 -0700 Subject: [PATCH] Avatar User Added a tweak to allow users to be avatars. Also deleted the old Rapier module --- packages/full/index.js | 4 - packages/kernel/CHANGELOG.md | 2 + packages/kernel/src/Spec.js | 21 ---- packages/kernel/src/User.js | 3 +- packages/rapier/CHANGELOG.md | 3 + packages/rapier/src/RapierPhysics.js | 173 --------------------------- 6 files changed, 6 insertions(+), 200 deletions(-) delete mode 100644 packages/rapier/src/RapierPhysics.js diff --git a/packages/full/index.js b/packages/full/index.js index 9da0ca76..f354a4ac 100644 --- a/packages/full/index.js +++ b/packages/full/index.js @@ -2,7 +2,3 @@ export * from "@croquet/worldcore-kernel"; export * from "@croquet/worldcore-three"; export * from "@croquet/worldcore-widget"; export * from "@croquet/worldcore-widget2"; - -// export * from "@croquet/worldcore-rapier"; -// export * from "@croquet/worldcore-widget3"; -// export * from "@croquet/worldcore-widget"; diff --git a/packages/kernel/CHANGELOG.md b/packages/kernel/CHANGELOG.md index 316f2156..ca1730bc 100644 --- a/packages/kernel/CHANGELOG.md +++ b/packages/kernel/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Spatial can have a non-spatial parent - NavGrid & PathToBehavior - AM_Spec +- AccountManager +- LevelManager - user-level say() does an additional `publish("__wc", "say")`, internal `_say()` does not ### Changed diff --git a/packages/kernel/src/Spec.js b/packages/kernel/src/Spec.js index 87ccb93e..c3d222d2 100644 --- a/packages/kernel/src/Spec.js +++ b/packages/kernel/src/Spec.js @@ -32,27 +32,6 @@ export const AM_Spec = superclass => class extends superclass { return spec; } - // createFromSpec(spec) { - // let out = this; - // const actor = spec.actor; - // const children = spec.children || []; - // const options = {...spec}; - // options.parent = this; - // delete options.actor; - // delete options.children; - - // const a = Constants.WC_SPEC.get(actor); - // if (a) { - // out = a.create(options); - // } else { - // if (actor) console.error(actor + " not found during createFromSpec!"); - // } - - // for (const child of children) out.createFromSpec(child); - - // return out; - // } - }; RegisterMixin(AM_Spec); diff --git a/packages/kernel/src/User.js b/packages/kernel/src/User.js index 04b9be77..37a0465a 100644 --- a/packages/kernel/src/User.js +++ b/packages/kernel/src/User.js @@ -9,6 +9,7 @@ import { ModelService} from "./Root"; export class User extends Actor { get userId() { return this._userId } + get driver() { return this._userId } get userNumber() { return this._userNumber } } User.register('User'); @@ -116,8 +117,6 @@ export const PM_Avatar = superclass => class extends superclass { export class Account extends Actor { get accountId() { return this._accountId } - // get online() { return this._online } - // get owner() { return this._owner } } Account.register('Account'); diff --git a/packages/rapier/CHANGELOG.md b/packages/rapier/CHANGELOG.md index 0342e307..f7ac71d2 100644 --- a/packages/rapier/CHANGELOG.md +++ b/packages/rapier/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +Kinematic rigid bodies + ### Changed Upgraded to Rapier 0.11.0 RapierManager doesn't hold world diff --git a/packages/rapier/src/RapierPhysics.js b/packages/rapier/src/RapierPhysics.js deleted file mode 100644 index 34f00dd3..00000000 --- a/packages/rapier/src/RapierPhysics.js +++ /dev/null @@ -1,173 +0,0 @@ -import { RegisterMixin, ModelService, q_identity, v3_multiply, v3_zero } from "@croquet/worldcore-kernel"; - -export let RAPIER; - -export function RapierVersion() { - return RAPIER.version(); -} - -//------------------------------------------------------------------------------------------ -//-- RapierPhysicsManager ------------------------------------------------------------------ -//------------------------------------------------------------------------------------------ - -// Maintains a list of players connected to the session. - -export class RapierPhysicsManager extends ModelService { - - static async asyncStart() { - console.log("Starting Rapier physics!"); - RAPIER = await import("@dimforge/rapier3d"); - } - - static types() { - if (!RAPIER) return {}; - return { - "RAPIER.World": { - cls: RAPIER.World, - write: world => world.takeSnapshot(), - read: snapshot => RAPIER.World.restoreSnapshot(snapshot) - }, - "RAPIER.EventQueue": { - cls: RAPIER.EventQueue, - write: q => {}, - read: q => new RAPIER.EventQueue(true) - }, - }; - } - - init(options = {}) { - super.init('RapierPhysicsManager'); - if (options.useCollisionEventQueue) { - this.queue = new RAPIER.EventQueue(true); - } - - const gravity = options.gravity || [0.0, -9.8, 0.0]; - const timeStep = options.timeStep || 50; // In ms - - const g = new RAPIER.Vector3(...gravity); - this.world = new RAPIER.World(g); - - this.timeStep = timeStep; - this.world.timestep = this.timeStep / 1000; - this.rigidBodies = []; - this.future(0).tick(); - } - - destroy() { - super.destroy(); - this.world.free(); - this.world = null; - } - - pause() { - this.isPaused = true; - } - - resume() { - this.isPaused = false; - } - - tick() { - if (!this.isPaused) { - this.world.step(this.queue); // may be undefined - this.world.forEachActiveRigidBodyHandle(h => { - const rb = this.rigidBodies[h]; - const t = rb.rigidBody.translation(); - const r = rb.rigidBody.rotation(); - - const v = [t.x, t.y, t.z]; - const q = [r.x, r.y, r.z, r.w]; - - rb.moveTo(v); - rb._say("translating", v); - rb.rotateTo(q); - }); - if (this.queue) { - if (this.contactEventHandler) { - queue.drainContactEvents((handle1, handle2, started) => { - let rb1 = this.rigidBodies[handle1]; - let rb2 = this.rigidBodies[handle2]; - this.contactEventHandler.contactEvent(rb1, rb2, started); - }); - } - if (this.intersectionEventHandler) { - queue.drainIntersectionEvents((handle1, handle2, intersecting) => { - let rb1 = this.rigidBodies[handle1]; - let rb2 = this.rigidBodies[handle2]; - this.intersectionEventHandler.intersectionEvent(rb1, rb2, intersecting); - }); - } - } - } - this.future(this.timeStep).tick(); - } - - registerContactEventHandler(handler) { - this.contactEventHandler = handler; - } - registerIntersectionEventHandler(handler) { - this.intersectionEventHandler = handler; - } -} -RapierPhysicsManager.register("RapierPhysicsManager"); - - -//------------------------------------------------------------------------------------------ -//-- RapierPhysics ------------------------------------------------------------------------- -//------------------------------------------------------------------------------------------ - -//-- Actor --------------------------------------------------------------------------------- - -export const AM_RapierPhysics = superclass => class extends superclass { - - destroy() { - this.removeRigidBody(); - super.destroy(); - } - - get rigidBody() { - if (!this.$rigidBody) { - if (this.rigidBodyHandle === undefined) return undefined; - const physicsManager = this.service('RapierPhysicsManager'); - this.$rigidBody = physicsManager.world.getRigidBody(this.rigidBodyHandle); - } - return this.$rigidBody; - } - - createRigidBody(rbd) { - this.removeRigidBody(); - rbd.translation = new RAPIER.Vector3(...this.translation); - rbd.rotation = new RAPIER.Quaternion(...this.rotation); - const physicsManager = this.service('RapierPhysicsManager'); - this.$rigidBody = physicsManager.world.createRigidBody(rbd); - this.rigidBodyHandle = this.$rigidBody.handle; - physicsManager.rigidBodies[this.rigidBodyHandle] = this; - - if (this.rigidBody.bodyType() === RAPIER.RigidBodyType.KinematicPositionBased) { - this.listen("setTranslation", this.setKinematicTranslation); - this.listen("setRotation", this.setKinematicRotation); - this.listen("moveTo", this.setKinematicTranslation); - this.listen("rotateTo", this.setKinematicRotation); - } - } - - setKinematicTranslation(v) { this.rigidBody.setNextKinematicTranslation(new RAPIER.Vector3(...v)); } - setKinematicRotation(q) { this.rigidBody.setNextKinematicRotation(new RAPIER.Quaternion(...q)); } - - removeRigidBody() { - if (!this.rigidBody) return; - const physicsManager = this.service('RapierPhysicsManager'); - physicsManager.rigidBodies[this.rigidBodyHandle] = undefined; - physicsManager.world.removeRigidBody(this.rigidBody); - this.rigidBodyHandle = undefined; - this.$rigidBody = undefined; - } - - createCollider(cd) { - const physicsManager = this.service('RapierPhysicsManager'); - const c = physicsManager.world.createCollider(cd, this.rigidBodyHandle); - return c.handle; - } - -}; -RegisterMixin(AM_RapierPhysics);