Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
signorpipo committed Nov 9, 2022
1 parent 2b7313f commit ddf3766
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 78 deletions.
2 changes: 1 addition & 1 deletion wle_pp/wle_pp_bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions wle_pp/wle_pp_bundle.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
WL.registerComponent('pp-gamepad-control-scheme', {
_myStartVisible: { type: WL.Type.Bool, default: true },
_myShowOnStart: { type: WL.Type.Bool, default: true },

_myHandedness: { type: WL.Type.Enum, values: ['left', 'right'], default: 'left' },

_myTextScaleMultiplier: { type: WL.Type.Float, default: 1 },
_myLineLengthMultiplier: { type: WL.Type.Float, default: 1 },
_myLineThicknessMultiplier: { type: WL.Type.Float, default: 1 },

_mySelectText: { type: WL.Type.String, default: "" },
_mySqueezeText: { type: WL.Type.String, default: "" },
_myThumbstickText: { type: WL.Type.String, default: "" },
Expand All @@ -19,6 +15,12 @@ WL.registerComponent('pp-gamepad-control-scheme', {
_myBottomButton: { type: WL.Type.Object, default: null },
_myTopButton: { type: WL.Type.Object, default: null },

_myTextScaleMultiplier: { type: WL.Type.Float, default: 1 },
_myTextOffsetMultiplier: { type: WL.Type.Float, default: 1 },
_myLineLengthMultiplier: { type: WL.Type.Float, default: 1 },
_myLineThicknessMultiplier: { type: WL.Type.Float, default: 1 },
_myDistanceFromButtonsMultiplier: { type: WL.Type.Float, default: 1 },

_myTextMaterial: { type: WL.Type.Material },
_myLineMaterial: { type: WL.Type.Material }
}, {
Expand All @@ -35,22 +37,23 @@ WL.registerComponent('pp-gamepad-control-scheme', {
this._mySetVisibleNextUpdate = false;

this._createControlScheme();
this.setVisible(this._myStartVisible);
this.setVisible(this._myShowOnStart);

this._myVisibleBackup = this._myVisible;
},
update: function (dt) {
if (this._mySetVisibleNextUpdate) {
this._mySetVisibleNextUpdate = false;
this.setVisible(false);
this.setVisible(this._myVisible);
this.setVisible(this._myVisibleBackup);
}
},
onActivate() {
this._mySetVisibleNextUpdate = true;
},
onDeactivate() {
let backupVisible = this._myVisible;
this._myVisibleBackup = this._myVisible;
this.setVisible(false);
this._myVisible = backupVisible;
},
isVisible() {
return this._myVisible;
Expand Down Expand Up @@ -94,10 +97,7 @@ WL.registerComponent('pp-gamepad-control-scheme', {
_createControlScheme() {
this._myRootObject = this.object.pp_addObject();

let objectScale = this.object.pp_getScale();
this.object.pp_resetScale();

let distanceFromButton = 0.015;
let distanceFromButton = 0.02 * this._myDistanceFromButtonsMultiplier;
let lineLength = 0.0935 * this._myLineLengthMultiplier;

let referenceObject = this._myThumbstick;
Expand All @@ -123,27 +123,40 @@ WL.registerComponent('pp-gamepad-control-scheme', {
this._myThumbstickObject);
this._myThumbstickTextComponent.text = this._myThumbstickText;

this._myBottomButtonObject = this._myRootObject.pp_addObject();
this._myBottomButtonTextComponent = this._addScheme(this._myBottomButton, referenceObject,
[0, distanceFromButton, 0],
[0, 0, -lineLength],
this._myBottomButtonObject);
this._myBottomButtonTextComponent.text = this._myBottomButtonText;
let thumbstickPositionLocal = this._myThumbstick.pp_getPositionLocal();
let thumbstickUpLocal = this._myThumbstick.pp_getUpLocal();

this._myTopButtonObject = this._myRootObject.pp_addObject();
this._myTopButtonTextComponent = this._addScheme(this._myTopButton, referenceObject,
[0, distanceFromButton, 0],
[-lineLength * this._myControlSchemeDirection, 0, 0].vec3_rotateAxis(-45 * this._myControlSchemeDirection, [0, 1, 0]),
this._myTopButtonObject);
this._myTopButtonTextComponent.text = this._myTopButtonText;
{
let bottomButtonPositionLocal = this._myBottomButton.pp_getPositionLocal();
let difference = bottomButtonPositionLocal.vec3_sub(thumbstickPositionLocal);
let differenceOnUp = difference.vec3_valueAlongAxis(thumbstickUpLocal);

this._myBottomButtonObject = this._myRootObject.pp_addObject();
this._myBottomButtonTextComponent = this._addScheme(this._myBottomButton, referenceObject,
[0, distanceFromButton - differenceOnUp, 0],
[0, 0, -lineLength],
this._myBottomButtonObject);
this._myBottomButtonTextComponent.text = this._myBottomButtonText;
}

this.object.pp_setScale(objectScale);
{
let topButtonPositionLocal = this._myTopButton.pp_getPositionLocal();
let difference = topButtonPositionLocal.vec3_sub(thumbstickPositionLocal);
let differenceOnUp = difference.vec3_valueAlongAxis(thumbstickUpLocal);

this._myTopButtonObject = this._myRootObject.pp_addObject();
this._myTopButtonTextComponent = this._addScheme(this._myTopButton, referenceObject,
[0, distanceFromButton - differenceOnUp, 0],
[-lineLength * this._myControlSchemeDirection, 0, 0].vec3_rotateAxis(-45 * this._myControlSchemeDirection, [0, 1, 0]),
this._myTopButtonObject);
this._myTopButtonTextComponent.text = this._myTopButtonText;
}
},
_addScheme(buttonObject, referenceObject, startOffset, endOffset, parentObject) {
let buttonPosition = buttonObject.pp_getPosition();
let referenceForward = referenceObject.pp_getForward();
let referenceRight = referenceObject.pp_getRight();
let referenceUp = referenceObject.pp_getUp();
let buttonPosition = buttonObject.pp_getPositionLocal();
let referenceForward = referenceObject.pp_getForwardLocal();
let referenceRight = referenceObject.pp_getRightLocal();
let referenceUp = referenceObject.pp_getUpLocal();

let lineStart = buttonPosition.vec3_add(referenceRight.vec3_scale(startOffset[0]));
lineStart.vec3_add(referenceUp.vec3_scale(startOffset[1]), lineStart);
Expand All @@ -153,7 +166,7 @@ WL.registerComponent('pp-gamepad-control-scheme', {
lineEnd.vec3_add(referenceUp.vec3_scale(endOffset[1]), lineEnd);
lineEnd.vec3_add(referenceForward.vec3_scale(endOffset[2]), lineEnd);

let textOffset = 0.01;
let textOffset = 0.01 * this._myTextOffsetMultiplier;
let textPosition = lineEnd.vec3_add(referenceForward.vec3_scale(-textOffset));

this._addLine(lineStart, lineEnd, parentObject);
Expand All @@ -170,21 +183,21 @@ WL.registerComponent('pp-gamepad-control-scheme', {
lineObject = lineRootObject.pp_addObject();

let lineMesh = lineObject.addComponent('mesh');
lineMesh.mesh = PP.myDefaultResources.myMeshes.myCube;
lineMesh.mesh = PP.myDefaultResources.myMeshes.myCylinder;
lineMesh.material = this._myLineMaterialFinal;

lineRootObject.pp_setPosition(start);
lineRootObject.pp_setPositionLocal(start);

let thickness = 0.001 * this._myLineThicknessMultiplier;
lineObject.pp_scaleObject([thickness / 2, thickness / 2, length / 2]);
lineObject.pp_scaleObject([thickness / 2, length / 2, thickness / 2]);

lineObject.pp_lookTo(lineDirection);
lineObject.pp_translateObject([0, 0, length / 2]);
lineObject.pp_setUpLocal(lineDirection);
lineObject.pp_translateObject([0, length / 2, 0]);
},
_addText(position, forward, up, parentObject) {
let textObject = parentObject.pp_addObject();
textObject.pp_setPosition(position);
textObject.pp_lookTo(up, forward);
textObject.pp_setPositionLocal(position);
textObject.pp_lookToLocal(up, forward);
textObject.pp_scaleObject(0.0935 * this._myTextScaleMultiplier);

let textComponent = textObject.pp_addComponent("text");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ WL.registerComponent('pp-tool-cursor', {
init: function () {
this._myHandednessString = ['left', 'right'][this._myHandedness];

if (this._myHandedness == 0) {
this._myCursorPosition = [-0.01, -0.024, -0.05];
} else {
this._myCursorPosition = [0.01, -0.024, -0.05];
}

this._myCursorRotation = [-0.382, 0, 0, 0.924];
this._myCursorRotation.quat_normalize(this._myCursorRotation);
this._myCursorPosition = [0, -0.035, -0.05];
this._myCursorRotation = [-30, 0, 0];
this._myCursorMeshScale = [0.0025, 0.0025, 0.0025];

this._myCursorColor = [255 / 255, 255 / 255, 255 / 255, 1];

this._myCursorTargetCollisionGroup = 7;
Expand All @@ -25,8 +18,8 @@ WL.registerComponent('pp-tool-cursor', {
this._myFixForwardObject.pp_rotateObject([0, 180, 0]);

this._myCursorObjectVR = WL.scene.addObject(this._myFixForwardObject);
this._myCursorObjectVR.setTranslationLocal(this._myCursorPosition);
this._myCursorObjectVR.rotateObject(this._myCursorRotation);
this._myCursorObjectVR.pp_setPositionLocal(this._myCursorPosition);
this._myCursorObjectVR.pp_rotateObject(this._myCursorRotation);

{
let cursorMeshObject = WL.scene.addObject(this._myCursorObjectVR);
Expand Down
26 changes: 4 additions & 22 deletions wle_pp/wle_pp_bundler/package-lock.json

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

6 changes: 3 additions & 3 deletions wle_pp/wle_pp_bundler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wle_pp",
"version": "0.2.5",
"version": "0.2.6",
"description": "A library for the Wonderland Engine",
"main": "./js/bundle.js",
"exports": "./js/bundle.js",
Expand All @@ -13,8 +13,8 @@
"esbuild": "^0.14.54"
},
"dependencies": {
"@wonderlandengine/components": "^0.8.16",
"gl-matrix": "^3.4.3"
"gl-matrix": "^3.4.3",
"howler": "^2.2.3"
},
"files": [
"js"
Expand Down

0 comments on commit ddf3766

Please sign in to comment.