Skip to content

Commit

Permalink
Add an expression, a condition and an action for objects center on Z …
Browse files Browse the repository at this point in the history
…axis (#5682)
  • Loading branch information
D8H authored Sep 25, 2023
1 parent aa7ae75 commit 1335819
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 18 deletions.
34 changes: 34 additions & 0 deletions Extensions/3D/A_RuntimeObject3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,40 @@ namespace gdjs {
return this._z;
}

/**
* Get the Z position of the rendered object.
*
* For most objects, this will returns the same value as getZ(). But if the
* object has an origin that is not the same as the point (0,0,0) of the
* object displayed, getDrawableZ will differ.
*
* @return The Z position of the rendered object.
*/
getDrawableZ(): float {
return this.getZ();
}

/**
* Return the Z position of the object center, **relative to the object Z
* position** (`getDrawableX`).
*
* Use `getCenterZInScene` to get the position of the center in the scene.
*
* @return the Z position of the object center, relative to
* `getDrawableZ()`.
*/
getCenterZ(): float {
return this.getDepth() / 2;
}

getCenterZInScene(): float {
return this.getDrawableZ() + this.getCenterZ();
}

setCenterZInScene(z: float): void {
this.setZ(z + this._z - (this.getDrawableZ() + this.getCenterZ()));
}

setAngle(angle: float): void {
super.setAngle(angle);
this.getRenderer().updateRotation();
Expand Down
19 changes: 19 additions & 0 deletions Extensions/3D/Base3DBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ namespace gdjs {
*/
getZ(): float;

/**
* Return the Z position of the object center, **relative to the scene origin**.
*/
getCenterZInScene(): float;

/**
* Change the object center Z position in the scene.
* @param z The new Z position of the center in the scene.
*/
setCenterZInScene(z: float): void;

/**
* Set the object rotation on the X axis.
*
Expand Down Expand Up @@ -132,6 +143,14 @@ namespace gdjs {
return this.object.getZ();
}

getCenterZInScene(): number {
return this.object.getCenterZInScene();
}

setCenterZInScene(z: number): void {
this.object.setCenterZInScene(z);
}

setRotationX(angle: float): void {
this.object.setRotationX(angle);
}
Expand Down
16 changes: 16 additions & 0 deletions Extensions/3D/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ module.exports = {
.useStandardParameters('number', gd.ParameterOptions.makeNewOptions())
.setFunctionName('setZ')
.setGetter('getZ');

base3D
.addExpressionAndConditionAndAction(
'number',
'CenterZ',
_('Center Z position'),
_('the Z position of the center of rotation'),
_('the Z position of the center'),
_('Position/Center'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'))
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.useStandardParameters('number', gd.ParameterOptions.makeNewOptions())
.setFunctionName('setCenterZInScene')
.setGetter('getCenterZInScene');

base3D
.addExpressionAndConditionAndAction(
Expand Down
10 changes: 10 additions & 0 deletions Extensions/3D/Model3DRuntimeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ namespace gdjs {
return this.getHeight() * centerPoint[1];
}

getCenterZ(): float {
const centerPoint = this._renderer.getCenterPoint();
return this.getDepth() * centerPoint[2];
}

getDrawableX(): float {
const originPoint = this._renderer.getOriginPoint();
return this.getX() - this.getWidth() * originPoint[0];
Expand All @@ -307,6 +312,11 @@ namespace gdjs {
const originPoint = this._renderer.getOriginPoint();
return this.getY() - this.getHeight() * originPoint[1];
}

getDrawableZ(): float {
const originPoint = this._renderer.getOriginPoint();
return this.getZ() - this.getDepth() * originPoint[2];
}
}

export namespace Model3DRuntimeObject {
Expand Down
18 changes: 0 additions & 18 deletions GDevelop.js/types/gdnamedpropertydescriptorslist.js

This file was deleted.

0 comments on commit 1335819

Please sign in to comment.