Skip to content

Commit

Permalink
0.7.4: Add collisionGroupsMask, deprecate collisionGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
rafern committed Feb 29, 2024
1 parent 7238985 commit c3cc468
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
17 changes: 11 additions & 6 deletions example-project/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ import {CursorTarget} from '@wonderlandengine/components';
import {loadRuntime} from '@wonderlandengine/api';

/* wle:auto-constants:start */
const RuntimeOptions = {
physx: false,
loader: false,
xrFramebufferScaleFactor: 1,
canvas: 'canvas',
};
const Constants = {
ProjectName: 'lazy-widgets-wle-example-project',
RuntimeBaseName: 'WonderlandRuntime',
WebXRRequiredFeatures: ['local',],
WebXROptionalFeatures: ['local','hand-tracking','hit-test',],
};
const RuntimeOptions = {
physx: false,
loader: false,
xrFramebufferScaleFactor: 1,
xrOfferSession: {
mode: 'auto',
features: Constants.WebXRRequiredFeatures,
optionalFeatures: Constants.WebXROptionalFeatures,
},
canvas: 'canvas',
};
/* wle:auto-constants:end */

const engine = await loadRuntime(Constants.RuntimeBaseName, RuntimeOptions);
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lazy-widgets-wle",
"version": "0.7.3",
"version": "0.7.4",
"description": "Typescript retained mode GUI for the HTML canvas API - Wonderland Engine integration",
"wonderlandengine": {},
"main": "dist/index.js",
Expand Down
8 changes: 8 additions & 0 deletions src/components/NoDriverPropsBaseLazyWidgetsComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ export abstract class NoDriverPropsBaseLazyWidgetsComponent<WLRootType extends W
/**
* The collision group that this root's collider will belong to. If
* negative, collider and cursor-target will not be added.
* @deprecated Use {@link NoDriverPropsBaseLazyWidgetsComponent#collisionGroupsMask} instead
*/
@property.int(WLRoot.defaultCollisionGroup)
collisionGroup!: number;
/**
* The collision groups that this root's collider will belong to. If 0,
* collider and cursor-target will not be added.
*/
@property.int(WLRoot.defaultCollisionGroupsMask)
collisionGroupsMask!: number;
/**
* Should the material used for the Root be cloned? If false, then the
* actual material will be used, which will lead to issues if the material
Expand Down Expand Up @@ -275,6 +282,7 @@ export abstract class NoDriverPropsBaseLazyWidgetsComponent<WLRootType extends W
return {
unitsPerPixel: this.unitsPerPixel,
collisionGroup: this.collisionGroup,
collisionGroupsMask: this.collisionGroupsMask,
cloneMaterial: this.cloneMaterial,
textureUniformName: this.textureUniformName,
cursorStyleManager: this.cursorStyleManagerObject?.getComponent(this.cursorStyleManagerName),
Expand Down
32 changes: 20 additions & 12 deletions src/core/WLRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ export interface WLRootProperties extends RootProperties {
/**
* The collision group that this root's collider will belong to. If null,
* collider and cursor-target will not be added.
* @deprecated Use {@link WLRootProperties#collisionGroupsMask} instead
*/
collisionGroup?: number,
/**
* Register the default pointer driver to this root? If collisionGroup is
* null, this is forced to false.
* The collision groups that this root's collider will belong to. If 0,
* collider and cursor-target will not be added.
*/
collisionGroupsMask?: number,
/**
* Register the default pointer driver to this root? If collisionGroupsMask
* is 0, this is forced to false.
*/
registerPointerDriver?: boolean,
/** Register the default keyboard driver to this root? */
Expand Down Expand Up @@ -117,8 +123,13 @@ export interface WLRootProperties extends RootProperties {
export class WLRoot extends Root {
/** Default units-per-pixel */
static readonly defaultUnitsPerPixel = 0.01;
/** Default collision group */
/**
* Default collision group
* @deprecated Use {@link WLRoot.defaultCollisionGroupsMask} instead
*/
static readonly defaultCollisionGroup = 1;
/** Default collision groups, as a bitmask */
static readonly defaultCollisionGroupsMask = 0;
/** Are materials cloned by default? */
static readonly defaultCloneMaterial = true;
/** Are pointer drivers auto-registered by default? */
Expand Down Expand Up @@ -300,11 +311,8 @@ export class WLRoot extends Root {
this.hasPasteEvents = true;
}

let collisionGroup: number | null = properties.collisionGroup ?? WLRoot.defaultCollisionGroup;
if (collisionGroup < 0) {
collisionGroup = null;
}

// TODO remove collisionGroup in next major
const collisionGroupsMask: number = (properties?.collisionGroupsMask ?? WLRoot.defaultCollisionGroupsMask) | (1 << (properties?.collisionGroup ?? WLRoot.defaultCollisionGroup));
const registerPointerDriver = properties.registerPointerDriver ?? WLRoot.defaultRegisterPointerDriver;
const registerKeyboardDriver = properties.registerKeyboardDriver ?? WLRoot.defaultRegisterKeyboardDriver;
this.unitsPerPixel = properties.unitsPerPixel ?? WLRoot.defaultUnitsPerPixel;
Expand All @@ -327,7 +335,7 @@ export class WLRoot extends Root {
this.meshObject.active = false;

// Setup drivers
if(collisionGroup !== null && registerPointerDriver) {
if(collisionGroupsMask !== 0 && registerPointerDriver) {
this.registerDriver(WLRoot.pointerDriver);
}

Expand Down Expand Up @@ -372,11 +380,11 @@ export class WLRoot extends Root {
this._setupMesh(0, 1, 1, 0);

// Setup mouse pointer input
if(collisionGroup !== null) {
if(collisionGroupsMask !== 0) {
this.collision = this.meshObject.addComponent('collision', {
collider: Collider.Box,
extents: [1, 1, 0.01],
group: 1 << collisionGroup,
group: collisionGroupsMask,
});

if (this.collision === null) {
Expand Down Expand Up @@ -836,7 +844,7 @@ export class WLRoot extends Root {

/**
* Get the collision component used for detecting cursor input. Will be null
* if a {@link WLRootProperties#collisionGroup} is not provided when
* if a {@link WLRootProperties#collisionGroupsMask} is not provided when
* creating this WLRoot.
*/
getCollider() {
Expand Down

0 comments on commit c3cc468

Please sign in to comment.