Skip to content

Commit

Permalink
Sync PP
Browse files Browse the repository at this point in the history
  • Loading branch information
signorpipo committed Jul 31, 2024
1 parent a34cd08 commit e963b35
Show file tree
Hide file tree
Showing 58 changed files with 3,753 additions and 1,784 deletions.
4 changes: 2 additions & 2 deletions wle_pp/wle_pp/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 wle_pp/wle_pp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wle-pp",
"version": "0.6.16",
"version": "0.6.17",
"author": "Pipo",
"description": "A library for the Wonderland Engine",
"homepage": "https://github.com/signorpipo/wle-pp",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Component } from "@wonderlandengine/api";
import { property } from "@wonderlandengine/api/decorators.js";
import { XRUtils } from "../../../cauldron/utils/xr_utils.js";

export class ClearConsoleComponent extends Component {
public static override TypeName = "pp-clear-console";

@property.enum(["Init", "Start", "Update", "Enter XR", "Exit XR"], "Init")
private _myWhen!: number;

@property.bool(true)
private _myFirstTimeOnly!: boolean;

private _myFirstTimeDone: boolean = false;

public override init(): void {
if (this._myWhen == 0) {
this._clearConsole();
}
}

public override start(): void {
if (this._myWhen == 1) {
this._clearConsole();
}
}

public override update(dt: number): void {
if (this._myWhen == 2) {
this._clearConsole();
}
}

private _onXRSessionStart(): void {
if (this._myWhen == 3) {
this._clearConsole();
}
}

private _onXRSessionEnd(): void {
if (this._myWhen == 4) {
this._clearConsole();
}
}

private _clearConsole(): void {
if (!this._myFirstTimeOnly || !this._myFirstTimeDone) {
console.clear();

this._myFirstTimeDone = true;
}

if (this._myFirstTimeOnly && this._myFirstTimeDone) {
this.active = false;
}
}

public override onActivate(): void {
if (this._myWhen == 3) {
XRUtils.registerSessionStartEventListener(this, this._onXRSessionStart.bind(this), true, true, this.engine);
}

if (this._myWhen == 4) {
XRUtils.registerSessionEndEventListener(this, this._onXRSessionEnd.bind(this), this.engine);
}
}

public override onDeactivate(): void {
XRUtils.unregisterSessionStartEndEventListeners(this, this.engine);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, LogLevel } from "@wonderlandengine/api";
import { property } from "@wonderlandengine/api/decorators.js";

export class SetEngineLogLevelComponent extends Component {
public static override TypeName = "pp-set-engine-log-level";

@property.bool(true)
private _myInfoEnabled!: boolean;

@property.bool(true)
private _myWarnEnabled!: boolean;

@property.bool(true)
private _myErrorEnabled!: boolean;

public override init(): void {
const logLevelsToDisable = [];

if (!this._myInfoEnabled) {
logLevelsToDisable.push(LogLevel.Info);
}

if (!this._myWarnEnabled) {
logLevelsToDisable.push(LogLevel.Warn);
}

if (!this._myErrorEnabled) {
logLevelsToDisable.push(LogLevel.Error);
}

if (logLevelsToDisable.length > 0) {
this.engine.log.levels.disable(...logLevelsToDisable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class PhysicsCollisionCollector {
if (type == CollisionEventType.Touch || type == CollisionEventType.TriggerTouch) {
collisionValid = this._onCollisionStart(type, physXComponent);
} else if (type == CollisionEventType.TouchLost || type == CollisionEventType.TriggerTouchLost) {
collisionValid = this._onCollisionEnd(type, physXComponent);
collisionValid = this._onCollisionEnd(type, physXComponent, physXComponent.object);
}

if (collisionValid) {
Expand Down Expand Up @@ -227,7 +227,7 @@ export class PhysicsCollisionCollector {
}
}

private _onCollisionEnd(type: CollisionEventType, physXComponent: PhysXComponent): boolean {
private _onCollisionEnd(type: CollisionEventType, physXComponent: PhysXComponent, physXObject: Object3D): boolean {
let componentFound = false;
for (const physXComponentToCheck of this._myCollisions) {
if (physXComponentToCheck.equals(physXComponent)) {
Expand All @@ -237,7 +237,7 @@ export class PhysicsCollisionCollector {
}

if (this._myLogEnabled && !componentFound) {
console.error("Collision End on physX component not collected - Object ID: " + physXComponent.object.pp_getID());
console.error("Collision End on physX component not collected - Object ID: " + physXObject.pp_getID());
}

if (componentFound) {
Expand All @@ -252,7 +252,7 @@ export class PhysicsCollisionCollector {

if (this._myUpdateActive && this._myCollisionStartEndProcessingActive) {
this._myCollisionsEndedToProcess.push(physXComponent);
this._myCollisionObjectsEndedToProcess.push(physXComponent.object);
this._myCollisionObjectsEndedToProcess.push(physXObject);

const indexesToRemove = this._myCollisionsStartedToProcess.pp_findAllIndexes(function (physXComponentToCheck: PhysXComponent) {
return physXComponentToCheck.equals(physXComponent);
Expand All @@ -265,7 +265,7 @@ export class PhysicsCollisionCollector {
}

if (this._myLogEnabled) {
console.log("Collision End - Object ID: " + physXComponent.object.pp_getID());
console.log("Collision End - Object ID: " + physXObject.pp_getID());
}

this._myCollisionEndEmitter.notify(this._myPhysXComponent, physXComponent, type);
Expand Down Expand Up @@ -310,18 +310,18 @@ export class PhysicsCollisionCollector {
}

if (collisionsToEndIndexes.length > 0) {
const physXComponentsToEnd: PhysXComponent[] = [];
const physXComponentsToEnd: [Object3D, PhysXComponent][] = [];
for (let i = 0; i < collisionsToEndIndexes.length; i++) {
physXComponentsToEnd.push(this._myCollisions[collisionsToEndIndexes[i]]);
physXComponentsToEnd.push([this._myCollisionObjects[collisionsToEndIndexes[i]], this._myCollisions[collisionsToEndIndexes[i]]]);
}

for (const physXComponentToEnd of physXComponentsToEnd) {
if (this._myLogEnabled) {
console.log("Trigger Desync Fix - Object ID: " + physXComponentToEnd.object.pp_getID());
console.log("Trigger Desync Fix - Object ID: " + physXComponentToEnd[0].pp_getID());
}

if (this._onCollisionEnd(CollisionEventType.TriggerTouchLost, physXComponentToEnd)) {
this._myCollisionEmitter.notify(this._myPhysXComponent, physXComponentToEnd, CollisionEventType.TriggerTouchLost);
if (this._onCollisionEnd(CollisionEventType.TriggerTouchLost, physXComponentToEnd[1], physXComponentToEnd[0])) {
this._myCollisionEmitter.notify(this._myPhysXComponent, physXComponentToEnd[1], CollisionEventType.TriggerTouchLost);
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion wle_pp/wle_pp/src/pp/cauldron/utils/array/mat3_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mat3 as gl_mat3, quat as gl_quat, type mat3 as gl_mat3_type, type quat
import { Matrix3, Quaternion, Vector3 } from "../../type_definitions/array_type_definitions.js";
import { QuatUtils, create as quat_utils_create } from "./quat_utils.js";
import { Vec3Utils } from "./vec3_utils.js";
import { getMatrix3AllocationFunction, setMatrix3AllocationFunction } from "./vec_allocation_utils.js";

export function create(): Matrix3;
export function create(m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Matrix3;
Expand All @@ -11,7 +12,7 @@ export function create(
m10?: number, m11?: number, m12?: number,
m20?: number, m21?: number, m22?: number): Matrix3 {

const out = gl_mat3.create() as unknown as Matrix3;
const out = getAllocationFunction()();

if (m00 != null) {
Mat3Utils.set(out,
Expand All @@ -23,6 +24,15 @@ export function create(
return out;
}

export function getAllocationFunction(): () => Matrix3 {
return getMatrix3AllocationFunction();
}

/** Specify the function that will be used to allocate the matrix when calling the {@link create} function */
export function setAllocationFunction(allocationFunction: () => Matrix3): void {
setMatrix3AllocationFunction(allocationFunction);
}

export function set<T extends Matrix3>(matrix: T, m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): T;
export function set<T extends Matrix3>(matrix: T, uniformValue: number): T;
export function set<T extends Matrix3>(matrix: T,
Expand Down Expand Up @@ -106,6 +116,8 @@ export function fromAxes<T extends Matrix3>(left: Readonly<Vector3>, up: Readonl

export const Mat3Utils = {
create,
getAllocationFunction,
setAllocationFunction,
set,
copy,
clone,
Expand Down
14 changes: 13 additions & 1 deletion wle_pp/wle_pp/src/pp/cauldron/utils/array/mat4_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MathUtils } from "../math_utils.js";
import { Quat2Utils } from "./quat2_utils.js";
import { QuatUtils, create as quat_utils_create } from "./quat_utils.js";
import { Vec3Utils, create as vec3_utils_create, set as vec3_utils_set } from "./vec3_utils.js";
import { getMatrix4AllocationFunction, setMatrix4AllocationFunction } from "./vec_allocation_utils.js";

export function create(): Matrix4;
export function create(
Expand All @@ -18,7 +19,7 @@ export function create(
m10?: number, m11?: number, m12?: number, m13?: number,
m20?: number, m21?: number, m22?: number, m23?: number,
m30?: number, m31?: number, m32?: number, m33?: number): Matrix4 {
const out = gl_mat4.create() as unknown as Matrix4;
const out = getAllocationFunction()();

if (m00 != null) {
Mat4Utils.set(
Expand All @@ -32,6 +33,15 @@ export function create(
return out;
}

export function getAllocationFunction(): () => Matrix4 {
return getMatrix4AllocationFunction();
}

/** Specify the function that will be used to allocate the matrix when calling the {@link create} function */
export function setAllocationFunction(allocationFunction: () => Matrix4): void {
setMatrix4AllocationFunction(allocationFunction);
}

export function set<T extends Matrix4>(matrix: T,
m00: number, m01: number, m02: number, m03: number,
m10: number, m11: number, m12: number, m13: number,
Expand Down Expand Up @@ -448,6 +458,8 @@ export function fromQuat<T extends Matrix4>(quat: Readonly<Quaternion2>, out: Ma
*/
export const Mat4Utils = {
create,
getAllocationFunction,
setAllocationFunction,
set,
copy,
clone,
Expand Down
14 changes: 13 additions & 1 deletion wle_pp/wle_pp/src/pp/cauldron/utils/array/quat2_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { create as mat3_utils_create } from "./mat3_utils.js";
import { Mat4Utils } from "./mat4_utils.js";
import { QuatUtils, create as quat_utils_create } from "./quat_utils.js";
import { Vec3Utils, create as vec3_utils_create } from "./vec3_utils.js";
import { getQuaternion2AllocationFunction, setQuaternion2AllocationFunction } from "./vec_allocation_utils.js";

export function create(): Quaternion2;
export function create(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quaternion2;
export function create(x1?: number, y1?: number, z1?: number, w1?: number, x2?: number, y2?: number, z2?: number, w2?: number): Quaternion2 {
const out = gl_quat2.create() as unknown as Quaternion2;
const out = getAllocationFunction()();

if (x1 != null) {
Quat2Utils.set(out, x1, y1!, z1!, w1!, x2!, y2!, z2!, w2!);
Expand All @@ -18,6 +19,15 @@ export function create(x1?: number, y1?: number, z1?: number, w1?: number, x2?:
return out;
}

export function getAllocationFunction(): () => Quaternion2 {
return getQuaternion2AllocationFunction();
}

/** Specify the function that will be used to allocate the quaternion when calling the {@link create} function */
export function setAllocationFunction(allocationFunction: () => Quaternion2): void {
setQuaternion2AllocationFunction(allocationFunction);
}

export function set<T extends Quaternion2>(quat: T, x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): T;
export function set<T extends Quaternion2>(quat: T, uniformValue: number): T;
export function set<T extends Quaternion2>(quat: T, x1: number, y1?: number, z1?: number, w1?: number, x2?: number, y2?: number, z2?: number, w2?: number): T {
Expand Down Expand Up @@ -431,6 +441,8 @@ export function fromMatrix<T extends Quaternion2>(matrix: Readonly<Matrix4>, out
*/
export const Quat2Utils = {
create,
getAllocationFunction,
setAllocationFunction,
set,
copy,
clone,
Expand Down
14 changes: 13 additions & 1 deletion wle_pp/wle_pp/src/pp/cauldron/utils/array/quat_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { EasingFunction, MathUtils } from "../math_utils.js";
import { ArrayUtils } from "./array_utils.js";
import { Mat3Utils, create as mat3_utils_create } from "./mat3_utils.js";
import { Vec3Utils, create as vec3_utils_create } from "./vec3_utils.js";
import { getQuaternionAllocationFunction, setQuaternionAllocationFunction } from "./vec_allocation_utils.js";

export function create(): Quaternion;
export function create(x: number, y: number, z: number, w: number): Quaternion;
export function create(uniformValue: number): Quaternion;
export function create(x?: number, y?: number, z?: number, w?: number): Quaternion {
const out = gl_quat.create() as unknown as Quaternion;
const out = getAllocationFunction()();

if (x != null) {
QuatUtils.set(out, x, y!, z!, w!);
Expand All @@ -18,6 +19,15 @@ export function create(x?: number, y?: number, z?: number, w?: number): Quaterni
return out;
}

export function getAllocationFunction(): () => Quaternion {
return getQuaternionAllocationFunction();
}

/** Specify the function that will be used to allocate the quaternion when calling the {@link create} function */
export function setAllocationFunction(allocationFunction: () => Quaternion): void {
setQuaternionAllocationFunction(allocationFunction);
}

export function set<T extends Quaternion>(quat: T, x: number, y: number, z: number, w: number): T;
export function set<T extends Quaternion>(quat: T, uniformValue: number): T;
export function set<T extends Quaternion>(quat: T, x: number, y?: number, z?: number, w?: number): T {
Expand Down Expand Up @@ -834,6 +844,8 @@ export const rotateAxisRadians = function () {
*/
export const QuatUtils = {
create,
getAllocationFunction,
setAllocationFunction,
set,
copy,
clone,
Expand Down
Loading

0 comments on commit e963b35

Please sign in to comment.