diff --git a/.gitmodules b/.gitmodules index 4b77b01a..227cf025 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ -[submodule "public/assets"] - path = public/assets - url = https://github.com/vircadia/vircadia-assets.git +[submodule "public/assets"] + path = public/assets + url = https://github.com/vircadia/vircadia-assets.git +[submodule "src/vircadia-world"] + path = src/vircadia-world + url = https://github.com/vircadia/vircadia-world.git diff --git a/package-lock.json b/package-lock.json index 25618f70..70a485ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -248,23 +248,23 @@ } }, "node_modules/@babylonjs/core": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/core/-/core-6.45.1.tgz", - "integrity": "sha512-wkORoAqpnZb10bUhrI0vinE9IiW7+gSgH4U4Zp41wO4kSeV0mtJY+Q5Ez6/n9ad9sLykD2FD7650B+Qi5tTMSw==" + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/core/-/core-6.49.0.tgz", + "integrity": "sha512-jU/JyqebRqqziNwHLcBYzANrVRd9S55yNZEjejwg2p4I8NRnoBBNgf4wuUVw17UKNHc1v3KD/Vnr5C2+dIWAqQ==" }, "node_modules/@babylonjs/gui": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/gui/-/gui-6.45.1.tgz", - "integrity": "sha512-lev/3nprv4t8lu3kW1zdlH7VzlWh9dmyZ2PkzybmBI6nB48bswPm7cX2ppaFTkpY8Z904js9TOsrYQotMzsUiw==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/gui/-/gui-6.49.0.tgz", + "integrity": "sha512-ZrfhWpvsva35P4NW/Ox8RiSJJ2RfTwU+azRZQDatWXHg86p8Lxu7oDEOg4ALiMLHn3cYkfDMXv29euLCLKEfxw==", "peer": true, "peerDependencies": { "@babylonjs/core": "^6.0.0" } }, "node_modules/@babylonjs/gui-editor": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/gui-editor/-/gui-editor-6.45.1.tgz", - "integrity": "sha512-o3Hjb+2SKEVVu6iBAlwT5GX1AqAogA7VAi9QHUxy9ZImPMa79qfdkuESKFyH+HIfQixBsEEaLcB3gQAsfMIB7A==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/gui-editor/-/gui-editor-6.49.0.tgz", + "integrity": "sha512-+GigFovMeIW93CUOppsEOdqYG3rJggIM+UZjkKWLR80FPvgJQyfgguEdoUF6WEzgfakpjSIhrfXg2mOR6KSUqA==", "peer": true, "peerDependencies": { "@babylonjs/core": "^6.0.0", @@ -274,9 +274,9 @@ } }, "node_modules/@babylonjs/inspector": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/inspector/-/inspector-6.45.1.tgz", - "integrity": "sha512-4YhJLD2FrVXUFIU+ttBanhevVaCBVLaBxhPuwrxXxKWkuBulFOQz7GkvRT/CJwA3Ad9/66qwS5+vfRT99GLM/w==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/inspector/-/inspector-6.49.0.tgz", + "integrity": "sha512-VaQhNLRyzqmBmrcqNHcY0+EIsdNua5yPjw1Ml5dVg8ICedOaQyDGky0oxMHcagHv93Dz80yPOUM/04J6nkIrgA==", "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.1.0", "@fortawesome/free-regular-svg-icons": "^6.0.0", @@ -294,27 +294,27 @@ } }, "node_modules/@babylonjs/loaders": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/loaders/-/loaders-6.45.1.tgz", - "integrity": "sha512-a75JvRVxT3DROCrl5iigLEpI5/eR7Rh4wdsDzZNn7bv3sXB40Kbw8EL60W3jDBXPdGUqNVzqtrxJF/ec2udg/Q==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/loaders/-/loaders-6.49.0.tgz", + "integrity": "sha512-Cy5t20wnYDFmKgVvgMWQpxo/eq+gND60hWxtDT/HwXB0FMeVMlNRpqOWpFuGcVdM4tYCP9eYrhQxvwAJZC/dlA==", "peerDependencies": { "@babylonjs/core": "^6.0.0", "babylonjs-gltf2interface": "^6.0.0" } }, "node_modules/@babylonjs/materials": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/materials/-/materials-6.45.1.tgz", - "integrity": "sha512-v1jqgG0bfX+8Qezq4eDT2sSjpQYW+ocNU70dbJF0AYrhuhhgf0SpM28C7DAKi9GUOKjMvZrIBEbFmJ6AijLjcQ==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/materials/-/materials-6.49.0.tgz", + "integrity": "sha512-FSdseo+rruhDxOw2IICmW8zcJjPOWifovLB0YeKxSF9NjuRBwl9xtpS0M2YE/jJCSFRZYhTWNRKbIMy+GKzWyQ==", "peer": true, "peerDependencies": { "@babylonjs/core": "^6.0.0" } }, "node_modules/@babylonjs/serializers": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/@babylonjs/serializers/-/serializers-6.45.1.tgz", - "integrity": "sha512-iSPUdjZhQIbSyi21IFiFC/wm6Bj4zcH9NhsN9i+xqLTbO/Uho49cHU0ew39n0Xn+LRsGRMTJWQLTsp+TPvAvrw==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/@babylonjs/serializers/-/serializers-6.49.0.tgz", + "integrity": "sha512-N6Yuhy2qo2oEWv7bltrcPlWQZUnOiysY1Yft9CVktskJItt78d0EybyQ11YsKS/rldCdC0O71nh142yFNXBRIQ==", "peer": true, "peerDependencies": { "@babylonjs/core": "^6.0.0", @@ -840,9 +840,9 @@ "dev": true }, "node_modules/@types/prop-types": { - "version": "15.7.11", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.11.tgz", - "integrity": "sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==", + "version": "15.7.12", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", + "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==", "peer": true }, "node_modules/@types/qs": { @@ -858,31 +858,24 @@ "dev": true }, "node_modules/@types/react": { - "version": "18.2.61", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.61.tgz", - "integrity": "sha512-NURTN0qNnJa7O/k4XUkEW2yfygA+NxS0V5h1+kp9jPwhzZy95q3ADoGMP0+JypMhrZBTTgjKAUlTctde1zzeQA==", + "version": "18.3.3", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.3.tgz", + "integrity": "sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==", "peer": true, "dependencies": { "@types/prop-types": "*", - "@types/scheduler": "*", "csstype": "^3.0.2" } }, "node_modules/@types/react-dom": { - "version": "18.2.19", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.19.tgz", - "integrity": "sha512-aZvQL6uUbIJpjZk4U8JZGbau9KDeAwMfmhyWorxgBkqDIEf6ROjRozcmPIicqsUwPUjbkDfHKgGee1Lq65APcA==", + "version": "18.3.0", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.0.tgz", + "integrity": "sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==", "peer": true, "dependencies": { "@types/react": "*" } }, - "node_modules/@types/scheduler": { - "version": "0.16.8", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.8.tgz", - "integrity": "sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==", - "peer": true - }, "node_modules/@types/semver": { "version": "7.5.8", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", @@ -1752,9 +1745,9 @@ } }, "node_modules/babylonjs-gltf2interface": { - "version": "6.45.1", - "resolved": "https://registry.npmjs.org/babylonjs-gltf2interface/-/babylonjs-gltf2interface-6.45.1.tgz", - "integrity": "sha512-D7Z8y333VZg1lOIJsrv3yr5C9JyMShoTng49I/TRIPJH64I2T51DVroyh04tACVuM00AX1sI9fys/5a5YK3+Bw==", + "version": "6.49.0", + "resolved": "https://registry.npmjs.org/babylonjs-gltf2interface/-/babylonjs-gltf2interface-6.49.0.tgz", + "integrity": "sha512-4qzKCgEayti/YUaeMgAAZxZJlx/kLqXxoC+G8gODYz9wOV9UjnHF09wREZ5cuELzzY/rjSJMqkgDfYbUQIQ6/A==", "peer": true }, "node_modules/balanced-match": { diff --git a/src/modules/entity/entities/Entity.ts b/src/modules/entity/entities/Entity.ts index f2f4225a..59db48ac 100644 --- a/src/modules/entity/entities/Entity.ts +++ b/src/modules/entity/entities/Entity.ts @@ -1,407 +1,407 @@ -// -// Entity.ts -// -// Created by Nolan Huang on 3 Aug 2022. -// Copyright 2022 Vircadia contributors. -// Copyright 2022 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -import { IVector3Property, IQuaternionProperty, EntityType } from "../EntityProperties"; -import { IEntity } from "../EntityInterfaces"; -import { Observable } from "@babylonjs/core"; -import { EntityProperties } from "@vircadia/web-sdk"; -import { EntityMapper } from "../package"; - -export class EntityPropertyChangeObservable { - _entity: T; - public observable: Observable = new Observable(); - public isDirty = false; - - constructor(entity: T) { - this._entity = entity; - } - - public update(): void { - if (this.isDirty) { - this.observable.notifyObservers(this._entity); - this.isDirty = false; - } - } -} - -export abstract class Entity implements IEntity { - protected _id: string; - protected _type: EntityType; - protected _name: string | undefined; - protected _parentID: string | undefined; - protected _visible: boolean | undefined; - protected _position: IVector3Property | undefined; - protected _rotation: IQuaternionProperty | undefined; - protected _dimensions: IVector3Property | undefined; - // render mode properties - protected _billboardMode: string | undefined; - // script Properties - protected _script: string | undefined; - protected _userData: string | undefined; - // collision Properties - protected _collisionless: boolean | undefined; - protected _collisionMask: number | undefined; - protected _collisionSoundURL: string | undefined; - protected _dynamic: boolean | undefined; - // physics Properties - protected _velocity: IVector3Property | undefined; - protected _damping: number | undefined; - protected _angularVelocity: IVector3Property | undefined; - protected _angularDamping: number | undefined; - protected _restitution: number | undefined; - protected _friction: number | undefined; - protected _density: number | undefined; - protected _gravity: IVector3Property | undefined; - - protected _propertyChangeObservables: Array>; - - protected _onCommonPropertiesChanged: EntityPropertyChangeObservable; - protected _onRenderModeChanged: EntityPropertyChangeObservable; - protected _onParentChanged: EntityPropertyChangeObservable; - protected _onPositionAndRotationChanged: EntityPropertyChangeObservable; - protected _onDimensionChanged: EntityPropertyChangeObservable; - protected _onScriptChanged: EntityPropertyChangeObservable; - protected _onUserDataChanged: EntityPropertyChangeObservable; - protected _onCollisionPropertiesChanged: EntityPropertyChangeObservable; - protected _onPhysicsPropertiesChanged: EntityPropertyChangeObservable; - - constructor(id: string, type: EntityType) { - this._id = id; - this._type = type; - - this._propertyChangeObservables = new Array>(); - - this._onCommonPropertiesChanged = this.createPropertyChangeObservable(); - this._onParentChanged = this.createPropertyChangeObservable(); - this._onPositionAndRotationChanged = this.createPropertyChangeObservable(); - this._onDimensionChanged = this.createPropertyChangeObservable(); - this._onRenderModeChanged = this.createPropertyChangeObservable(); - this._onScriptChanged = this.createPropertyChangeObservable(); - this._onUserDataChanged = this.createPropertyChangeObservable(); - this._onCollisionPropertiesChanged = this.createPropertyChangeObservable(); - this._onPhysicsPropertiesChanged = this.createPropertyChangeObservable(); - } - - protected createPropertyChangeObservable(): EntityPropertyChangeObservable { - const observable = new EntityPropertyChangeObservable(this); - this._propertyChangeObservables.push(observable); - return observable; - } - - public get id(): string { - return this._id; - } - - public get type(): EntityType { - return this._type; - } - - public get name(): string | undefined { - return this._name; - } - - public set name(value : string | undefined) { - if (value && value !== this._name) { - this._name = value; - this._onCommonPropertiesChanged.isDirty = true; - } - } - - public get parentID(): string | undefined { - return this._parentID; - } - - public set parentID(value: string | undefined) { - if (value && value !== this._parentID) { - this._parentID = value; - this._onParentChanged.isDirty = true; - } - } - - public get visible(): boolean | undefined { - return this._visible; - } - - public set visible(value: boolean | undefined) { - if (value !== undefined && value !== this._visible) { - this._visible = value; - this._onCommonPropertiesChanged.isDirty = true; - } - } - - public get position(): IVector3Property | undefined { - return this._position; - } - - public set position(value: IVector3Property | undefined) { - if (value) { - this._position = value; - this._onPositionAndRotationChanged.isDirty = true; - } - } - - public get rotation(): IQuaternionProperty | undefined { - return this._rotation; - } - - public set rotation(value: IQuaternionProperty | undefined) { - if (value) { - this._rotation = value; - this._onPositionAndRotationChanged.isDirty = true; - } - } - - public get dimensions(): IVector3Property | undefined { - return this._dimensions; - } - - public set dimensions(value: IVector3Property | undefined) { - if (value) { - this._dimensions = value; - this._onDimensionChanged.isDirty = true; - } - } - - public get billboardMode(): string | undefined { - return this._billboardMode; - } - - public set billboardMode(value: string | undefined) { - if (value !== undefined && this._billboardMode !== value) { - this._billboardMode = value; - this._onRenderModeChanged.isDirty = true; - } - } - - public get script(): string | undefined { - return this._script; - } - - public set script(value: string | undefined) { - if (value && this._script !== value) { - this._script = value; - this._onScriptChanged.isDirty = true; - } - } - - public get userData(): string | undefined { - return this._userData; - } - - public set userData(value: string | undefined) { - if (value && this._userData !== value) { - this._userData = value; - this._onUserDataChanged.isDirty = true; - } - } - - public get collisionless(): boolean | undefined { - return this._collisionless; - } - - public set collisionless(value: boolean | undefined) { - if (value !== undefined && value !== this._collisionless) { - this._collisionless = value; - this._onCollisionPropertiesChanged.isDirty = true; - } - } - - public get collisionMask(): number | undefined { - return this._collisionMask; - } - - public set collisionMask(value: number | undefined) { - if (typeof value === "number" && value !== this._collisionMask) { - this._collisionMask = value; - this._onCollisionPropertiesChanged.isDirty = true; - } - } - - public get collisionSoundURL(): string | undefined { - return this._collisionSoundURL; - } - - public set collisionSoundURL(value: string | undefined) { - if (value !== undefined && value !== this._collisionSoundURL) { - this._collisionSoundURL = value; - this._onCollisionPropertiesChanged.isDirty = true; - } - } - - public get dynamic(): boolean | undefined { - return this._dynamic; - } - - public set dynamic(value: boolean | undefined) { - if (value !== undefined && value !== this._collisionless) { - this._dynamic = value; - this._onCollisionPropertiesChanged.isDirty = true; - } - } - - public get velocity(): IVector3Property | undefined { - return this._velocity; - } - - public set velocity(value: IVector3Property | undefined) { - if (value && this._velocity !== value) { - this._velocity = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get damping(): number | undefined { - return this._damping; - } - - public set damping(value: number | undefined) { - if (typeof value === "number" && this._damping !== value) { - this._damping = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get angularVelocity(): IVector3Property | undefined { - return this._angularVelocity; - } - - public set angularVelocity(value: IVector3Property | undefined) { - if (value && this._angularVelocity !== value) { - this._angularVelocity = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get angularDamping(): number | undefined { - return this._angularDamping; - } - - public set angularDamping(value: number | undefined) { - if (typeof value === "number" && this._angularDamping !== value) { - this._angularDamping = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get restitution(): number | undefined { - return this._restitution; - } - - public set restitution(value: number | undefined) { - if (typeof value === "number" && this._restitution !== value) { - this._restitution = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get friction(): number | undefined { - return this._friction; - } - - public set friction(value: number | undefined) { - if (typeof value === "number" && this._friction !== value) { - this._friction = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get density(): number | undefined { - return this._density; - } - - public set density(value: number | undefined) { - if (typeof value === "number" && this._density !== value) { - this._density = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get gravity(): IVector3Property | undefined { - return this._gravity; - } - - public set gravity(value: IVector3Property | undefined) { - if (value && this._gravity !== value) { - this._gravity = value; - this._onPhysicsPropertiesChanged.isDirty = true; - } - } - - public get onCommonPropertiesChanged(): Observable { - return this._onCommonPropertiesChanged.observable; - } - - public get onParentChanged(): Observable { - return this._onParentChanged.observable; - } - - public get onPositionAndRotationChanged(): Observable { - return this._onPositionAndRotationChanged.observable; - } - - public get onDimensionChanged(): Observable { - return this._onDimensionChanged.observable; - } - - public get onRenderModeChanged(): Observable { - return this._onRenderModeChanged.observable; - } - - public get onScriptChanged(): Observable { - return this._onScriptChanged.observable; - } - - public get onUserDataChanged(): Observable { - return this._onUserDataChanged.observable; - } - - public get onCollisionPropertiesChanged(): Observable { - return this._onCollisionPropertiesChanged.observable; - } - - public get onPhysicsPropertiesChanged(): Observable { - return this._onPhysicsPropertiesChanged.observable; - } - - public update(): void { - this._propertyChangeObservables.forEach((observable) => { - observable.update(); - }); - } - - public copyFormPacketData(props: EntityProperties): void { - this.name = props.name; - this.position = props.position; - this.rotation = props.rotation; - this.dimensions = props.dimensions; - this.parentID = props.parentID?.stringify(); - this.visible = props.visible; - // render mode properties - this.billboardMode = EntityMapper.mapToEntityBillboardMode(props.billboardMode); - // script properties - this.script = props.script; - this.userData = props.userData; - // collision properties - this.collisionless = props.collisionless; - this.collisionMask = props.collisionMask; - this.collisionSoundURL = props.collisionSoundURL; - this.dynamic = props.dynamic; - // physics properties - this.velocity = props.velocity; - this.damping = props.damping; - this.angularVelocity = props.angularVelocity; - this.angularDamping = props.angularDampling; - this.restitution = props.restitution; - this.friction = props.friction; - this.density = props.density; - this.gravity = props.gravity; - } -} +// +// Entity.ts +// +// Created by Nolan Huang on 3 Aug 2022. +// Copyright 2022 Vircadia contributors. +// Copyright 2022 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import { IVector3Property, IQuaternionProperty, EntityType } from "../EntityProperties"; +import { IEntity } from "../EntityInterfaces"; +import { Observable } from "@babylonjs/core"; +import { EntityProperties } from "@vircadia/web-sdk"; +import { EntityMapper } from "../package"; + +export class EntityPropertyChangeObservable { + _entity: T; + public observable: Observable = new Observable(); + public isDirty = false; + + constructor(entity: T) { + this._entity = entity; + } + + public update(): void { + if (this.isDirty) { + this.observable.notifyObservers(this._entity); + this.isDirty = false; + } + } +} + +export abstract class Entity implements IEntity { + protected _id: string; + protected _type: EntityType; + protected _name: string | undefined; + protected _parentID: string | undefined; + protected _visible: boolean | undefined; + protected _position: IVector3Property | undefined; + protected _rotation: IQuaternionProperty | undefined; + protected _dimensions: IVector3Property | undefined; + // render mode properties + protected _billboardMode: string | undefined; + // script Properties + protected _script: string | undefined; + protected _userData: string | undefined; + // collision Properties + protected _collisionless: boolean | undefined; + protected _collisionMask: number | undefined; + protected _collisionSoundURL: string | undefined; + protected _dynamic: boolean | undefined; + // physics Properties + protected _velocity: IVector3Property | undefined; + protected _damping: number | undefined; + protected _angularVelocity: IVector3Property | undefined; + protected _angularDamping: number | undefined; + protected _restitution: number | undefined; + protected _friction: number | undefined; + protected _density: number | undefined; + protected _gravity: IVector3Property | undefined; + + protected _propertyChangeObservables: Array>; + + protected _onCommonPropertiesChanged: EntityPropertyChangeObservable; + protected _onRenderModeChanged: EntityPropertyChangeObservable; + protected _onParentChanged: EntityPropertyChangeObservable; + protected _onPositionAndRotationChanged: EntityPropertyChangeObservable; + protected _onDimensionChanged: EntityPropertyChangeObservable; + protected _onScriptChanged: EntityPropertyChangeObservable; + protected _onUserDataChanged: EntityPropertyChangeObservable; + protected _onCollisionPropertiesChanged: EntityPropertyChangeObservable; + protected _onPhysicsPropertiesChanged: EntityPropertyChangeObservable; + + constructor(id: string, type: EntityType) { + this._id = id; + this._type = type; + + this._propertyChangeObservables = new Array>(); + + this._onCommonPropertiesChanged = this.createPropertyChangeObservable(); + this._onParentChanged = this.createPropertyChangeObservable(); + this._onPositionAndRotationChanged = this.createPropertyChangeObservable(); + this._onDimensionChanged = this.createPropertyChangeObservable(); + this._onRenderModeChanged = this.createPropertyChangeObservable(); + this._onScriptChanged = this.createPropertyChangeObservable(); + this._onUserDataChanged = this.createPropertyChangeObservable(); + this._onCollisionPropertiesChanged = this.createPropertyChangeObservable(); + this._onPhysicsPropertiesChanged = this.createPropertyChangeObservable(); + } + + protected createPropertyChangeObservable(): EntityPropertyChangeObservable { + const observable = new EntityPropertyChangeObservable(this); + this._propertyChangeObservables.push(observable); + return observable; + } + + public get id(): string { + return this._id; + } + + public get type(): EntityType { + return this._type; + } + + public get name(): string | undefined { + return this._name; + } + + public set name(value: string | undefined) { + if (value && value !== this._name) { + this._name = value; + this._onCommonPropertiesChanged.isDirty = true; + } + } + + public get parentID(): string | undefined { + return this._parentID; + } + + public set parentID(value: string | undefined) { + if (value && value !== this._parentID) { + this._parentID = value; + this._onParentChanged.isDirty = true; + } + } + + public get visible(): boolean | undefined { + return this._visible; + } + + public set visible(value: boolean | undefined) { + if (value !== undefined && value !== this._visible) { + this._visible = value; + this._onCommonPropertiesChanged.isDirty = true; + } + } + + public get position(): IVector3Property | undefined { + return this._position; + } + + public set position(value: IVector3Property | undefined) { + if (value) { + this._position = value; + this._onPositionAndRotationChanged.isDirty = true; + } + } + + public get rotation(): IQuaternionProperty | undefined { + return this._rotation; + } + + public set rotation(value: IQuaternionProperty | undefined) { + if (value) { + this._rotation = value; + this._onPositionAndRotationChanged.isDirty = true; + } + } + + public get dimensions(): IVector3Property | undefined { + return this._dimensions; + } + + public set dimensions(value: IVector3Property | undefined) { + if (value) { + this._dimensions = value; + this._onDimensionChanged.isDirty = true; + } + } + + public get billboardMode(): string | undefined { + return this._billboardMode; + } + + public set billboardMode(value: string | undefined) { + if (value !== undefined && this._billboardMode !== value) { + this._billboardMode = value; + this._onRenderModeChanged.isDirty = true; + } + } + + public get script(): string | undefined { + return this._script; + } + + public set script(value: string | undefined) { + if (value && this._script !== value) { + this._script = value; + this._onScriptChanged.isDirty = true; + } + } + + public get userData(): string | undefined { + return this._userData; + } + + public set userData(value: string | undefined) { + if (value && this._userData !== value) { + this._userData = value; + this._onUserDataChanged.isDirty = true; + } + } + + public get collisionless(): boolean | undefined { + return this._collisionless; + } + + public set collisionless(value: boolean | undefined) { + if (value !== undefined && value !== this._collisionless) { + this._collisionless = value; + this._onCollisionPropertiesChanged.isDirty = true; + } + } + + public get collisionMask(): number | undefined { + return this._collisionMask; + } + + public set collisionMask(value: number | undefined) { + if (typeof value === "number" && value !== this._collisionMask) { + this._collisionMask = value; + this._onCollisionPropertiesChanged.isDirty = true; + } + } + + public get collisionSoundURL(): string | undefined { + return this._collisionSoundURL; + } + + public set collisionSoundURL(value: string | undefined) { + if (value !== undefined && value !== this._collisionSoundURL) { + this._collisionSoundURL = value; + this._onCollisionPropertiesChanged.isDirty = true; + } + } + + public get dynamic(): boolean | undefined { + return this._dynamic; + } + + public set dynamic(value: boolean | undefined) { + if (value !== undefined && value !== this._collisionless) { + this._dynamic = value; + this._onCollisionPropertiesChanged.isDirty = true; + } + } + + public get velocity(): IVector3Property | undefined { + return this._velocity; + } + + public set velocity(value: IVector3Property | undefined) { + if (value && this._velocity !== value) { + this._velocity = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get damping(): number | undefined { + return this._damping; + } + + public set damping(value: number | undefined) { + if (typeof value === "number" && this._damping !== value) { + this._damping = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get angularVelocity(): IVector3Property | undefined { + return this._angularVelocity; + } + + public set angularVelocity(value: IVector3Property | undefined) { + if (value && this._angularVelocity !== value) { + this._angularVelocity = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get angularDamping(): number | undefined { + return this._angularDamping; + } + + public set angularDamping(value: number | undefined) { + if (typeof value === "number" && this._angularDamping !== value) { + this._angularDamping = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get restitution(): number | undefined { + return this._restitution; + } + + public set restitution(value: number | undefined) { + if (typeof value === "number" && this._restitution !== value) { + this._restitution = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get friction(): number | undefined { + return this._friction; + } + + public set friction(value: number | undefined) { + if (typeof value === "number" && this._friction !== value) { + this._friction = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get density(): number | undefined { + return this._density; + } + + public set density(value: number | undefined) { + if (typeof value === "number" && this._density !== value) { + this._density = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get gravity(): IVector3Property | undefined { + return this._gravity; + } + + public set gravity(value: IVector3Property | undefined) { + if (value && this._gravity !== value) { + this._gravity = value; + this._onPhysicsPropertiesChanged.isDirty = true; + } + } + + public get onCommonPropertiesChanged(): Observable { + return this._onCommonPropertiesChanged.observable; + } + + public get onParentChanged(): Observable { + return this._onParentChanged.observable; + } + + public get onPositionAndRotationChanged(): Observable { + return this._onPositionAndRotationChanged.observable; + } + + public get onDimensionChanged(): Observable { + return this._onDimensionChanged.observable; + } + + public get onRenderModeChanged(): Observable { + return this._onRenderModeChanged.observable; + } + + public get onScriptChanged(): Observable { + return this._onScriptChanged.observable; + } + + public get onUserDataChanged(): Observable { + return this._onUserDataChanged.observable; + } + + public get onCollisionPropertiesChanged(): Observable { + return this._onCollisionPropertiesChanged.observable; + } + + public get onPhysicsPropertiesChanged(): Observable { + return this._onPhysicsPropertiesChanged.observable; + } + + public update(): void { + this._propertyChangeObservables.forEach((observable) => { + observable.update(); + }); + } + + public copyFormPacketData(props: EntityProperties): void { + this.name = props.name; + this.position = props.position; + this.rotation = props.rotation; + this.dimensions = props.dimensions; + this.parentID = props.parentID?.stringify(); + this.visible = props.visible; + // render mode properties + this.billboardMode = EntityMapper.mapToEntityBillboardMode(props.billboardMode); + // script properties + this.script = props.script; + this.userData = props.userData; + // collision properties + this.collisionless = props.collisionless; + this.collisionMask = props.collisionMask; + this.collisionSoundURL = props.collisionSoundURL; + this.dynamic = props.dynamic; + // physics properties + this.velocity = props.velocity; + this.damping = props.damping; + this.angularVelocity = props.angularVelocity; + this.angularDamping = props.angularDampling; + this.restitution = props.restitution; + this.friction = props.friction; + this.density = props.density; + this.gravity = props.gravity; + } +} diff --git a/src/modules/entity/entities/ModelEntity.ts b/src/modules/entity/entities/ModelEntity.ts index b5a3067c..bad2ccf1 100644 --- a/src/modules/entity/entities/ModelEntity.ts +++ b/src/modules/entity/entities/ModelEntity.ts @@ -1,114 +1,114 @@ -// -// ModelEntity.ts -// -// Created by Nolan Huang on 3 Aug 2022. -// Copyright 2022 Vircadia contributors. -// Copyright 2022 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -import { IEntity, IModelEntity } from "../EntityInterfaces"; -import { Observable } from "@babylonjs/core"; -import { Entity, EntityPropertyChangeObservable } from "./Entity"; -import { IAnimationProperties } from "../EntityProperties"; -import { EntityMapper } from "../package"; -import { EntityProperties, ModelEntityProperties } from "@vircadia/web-sdk"; - -class AnimationProperties implements IAnimationProperties { - private _running = true; - private _loop = true; - private _onPropertyChanged: EntityPropertyChangeObservable; - - constructor(onPropertyChanged: EntityPropertyChangeObservable) { - this._onPropertyChanged = onPropertyChanged; - } - - public get running(): boolean | undefined { - return this._running; - } - - public set running(value: boolean | undefined) { - if (value !== undefined && value !== this._running) { - this._running = value; - this._onPropertyChanged.isDirty = true; - } - } - - public get loop(): boolean { - return this._loop; - } - - public set loop(value: boolean | undefined) { - if (value !== undefined && value !== this._loop) { - this._loop = value; - this._onPropertyChanged.isDirty = true; - } - } - -} - -export class ModelEntity extends Entity implements IModelEntity { - protected _modelURL = ""; - protected _shapeType: string | undefined; - protected _animation: AnimationProperties; - protected _onModelURLChanged: EntityPropertyChangeObservable; - protected _onAnimationChanged: EntityPropertyChangeObservable; - - constructor(id: string) { - super(id, "Model"); - this._onModelURLChanged = this.createPropertyChangeObservable(); - this._onAnimationChanged = this.createPropertyChangeObservable(); - - this._animation = new AnimationProperties(this._onAnimationChanged); - } - - public get modelURL(): string | undefined { - return this._modelURL; - } - - public set modelURL(value: string | undefined) { - if (value && value !== this._modelURL) { - this._modelURL = value; - this._onModelURLChanged.isDirty = true; - } - } - - public get shapeType(): string | undefined { - return this._shapeType; - } - - public set shapeType(value: string | undefined) { - if (value && value !== this._shapeType) { - this._shapeType = value; - this._onCollisionPropertiesChanged.isDirty = true; - } - } - - public get onModelURLChanged(): Observable { - return this._onModelURLChanged.observable; - } - - public get onAnimationChanged(): Observable { - return this._onAnimationChanged.observable; - } - - public get animation(): IAnimationProperties { - return this._animation; - } - - public copyFormPacketData(props: EntityProperties): void { - super.copyFormPacketData(props); - - const modelProps = props as ModelEntityProperties; - this.modelURL = modelProps.modelURL; - - if (modelProps.animation) { - this._animation.running = modelProps.animation.animationPlaying; - this._animation.loop = modelProps.animation.animationLoop; - } - - this.shapeType = EntityMapper.mapToShapeType(modelProps.shapeType); - } -} +// +// ModelEntity.ts +// +// Created by Nolan Huang on 3 Aug 2022. +// Copyright 2022 Vircadia contributors. +// Copyright 2022 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import { IEntity, IModelEntity } from "../EntityInterfaces"; +import { Observable } from "@babylonjs/core"; +import { Entity, EntityPropertyChangeObservable } from "./Entity"; +import { IAnimationProperties } from "../EntityProperties"; +import { EntityMapper } from "../package"; +import { EntityProperties, ModelEntityProperties } from "@vircadia/web-sdk"; + +class AnimationProperties implements IAnimationProperties { + private _running = true; + private _loop = true; + private _onPropertyChanged: EntityPropertyChangeObservable; + + constructor(onPropertyChanged: EntityPropertyChangeObservable) { + this._onPropertyChanged = onPropertyChanged; + } + + public get running(): boolean | undefined { + return this._running; + } + + public set running(value: boolean | undefined) { + if (value !== undefined && value !== this._running) { + this._running = value; + this._onPropertyChanged.isDirty = true; + } + } + + public get loop(): boolean { + return this._loop; + } + + public set loop(value: boolean | undefined) { + if (value !== undefined && value !== this._loop) { + this._loop = value; + this._onPropertyChanged.isDirty = true; + } + } + +} + +export class ModelEntity extends Entity implements IModelEntity { + protected _modelURL = ""; + protected _shapeType: string | undefined; + protected _animation: AnimationProperties; + protected _onModelURLChanged: EntityPropertyChangeObservable; + protected _onAnimationChanged: EntityPropertyChangeObservable; + + constructor(id: string) { + super(id, "Model"); + this._onModelURLChanged = this.createPropertyChangeObservable(); + this._onAnimationChanged = this.createPropertyChangeObservable(); + + this._animation = new AnimationProperties(this._onAnimationChanged); + } + + public get modelURL(): string | undefined { + return this._modelURL; + } + + public set modelURL(value: string | undefined) { + if (value && value !== this._modelURL) { + this._modelURL = value; + this._onModelURLChanged.isDirty = true; + } + } + + public get shapeType(): string | undefined { + return this._shapeType; + } + + public set shapeType(value: string | undefined) { + if (value && value !== this._shapeType) { + this._shapeType = value; + this._onCollisionPropertiesChanged.isDirty = true; + } + } + + public get onModelURLChanged(): Observable { + return this._onModelURLChanged.observable; + } + + public get onAnimationChanged(): Observable { + return this._onAnimationChanged.observable; + } + + public get animation(): IAnimationProperties { + return this._animation; + } + + public copyFormPacketData(props: EntityProperties): void { + super.copyFormPacketData(props); + + const modelProps = props as ModelEntityProperties; + this.modelURL = modelProps.modelURL; + + if (modelProps.animation) { + this._animation.running = modelProps.animation.animationPlaying; + this._animation.loop = modelProps.animation.animationLoop; + } + + this.shapeType = EntityMapper.mapToShapeType(modelProps.shapeType); + } +} diff --git a/src/modules/entity/package/EntityMapper.ts b/src/modules/entity/package/EntityMapper.ts index e3b09c61..7f36f41e 100644 --- a/src/modules/entity/package/EntityMapper.ts +++ b/src/modules/entity/package/EntityMapper.ts @@ -125,7 +125,7 @@ export class EntityMapper { } - public static mapToShapeType(shape: number | undefined): ShapeType { + public static mapToShapeType(shape: number | undefined): ShapeType | undefined { switch (shape) { case PackageShapeType.BOX: return "box"; @@ -161,8 +161,10 @@ export class EntityMapper { return "sphere"; case PackageShapeType.STATIC_MESH: return "static-mesh"; - default: + case PackageShapeType.NONE: return "none"; + default: + return undefined; } } diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index d61a1d47..d6cb065a 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -704,6 +704,7 @@ export class VScene { this._css3DRenderer.removeAllCSS3DObjects(); this._css3DRenderer.scene = this._scene; } + this._scene.collisionsEnabled = true; } diff --git a/src/vircadia-world b/src/vircadia-world new file mode 160000 index 00000000..dd6127c2 --- /dev/null +++ b/src/vircadia-world @@ -0,0 +1 @@ +Subproject commit dd6127c2639c696179ae80bd28b5a9a0f3db8354