Add an expression, a condition and an action for objects center on Z axis (#5682)

This commit is contained in:
D8H
2023-09-25 10:12:03 +02:00
committed by GitHub
parent aa7ae758f7
commit 1335819ea7
5 changed files with 79 additions and 18 deletions

View File

@@ -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();

View File

@@ -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.
*
@@ -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);
}

View File

@@ -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(

View File

@@ -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];
@@ -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 {

View File

@@ -1,18 +0,0 @@
// Automatically generated by GDevelop.js/scripts/generate-types.js
// Automatically generated by GDevelop.js/scripts/generate-types.js
declare class gdNamedPropertyDescriptorsList {
constructor(): void;
insertNew(name: string, pos: number): gdNamedPropertyDescriptor;
insert(item: gdNamedPropertyDescriptor, pos: number): gdNamedPropertyDescriptor;
has(name: string): boolean;
get(name: string): gdNamedPropertyDescriptor;
getAt(pos: number): gdNamedPropertyDescriptor;
remove(name: string): void;
move(oldIndex: number, newIndex: number): void;
getCount(): number;
getPosition(item: gdNamedPropertyDescriptor): number;
size(): number;
at(index: number): gdNamedPropertyDescriptor;
delete(): void;
ptr: number;
};