Add expressions to access the components of forward/up/right vectors of 3D objects (#8558)

- These are advanced expressions mostly useful for extensions manipulating objects in 3D space.
This commit is contained in:
D8H
2026-05-04 15:19:35 +02:00
committed by GitHub
parent 5dd2b8ffd8
commit 18cd4f9110
11 changed files with 988 additions and 26 deletions
+36
View File
@@ -331,6 +331,42 @@ namespace gdjs {
this.setAngle(gdjs.toDegrees(mesh.rotation.z));
}
getForwardX(): float {
return this.getRenderer().getForwardX();
}
getForwardY(): float {
return this.getRenderer().getForwardY();
}
getForwardZ(): float {
return this.getRenderer().getForwardZ();
}
getUpX(): float {
return this.getRenderer().getUpX();
}
getUpY(): float {
return this.getRenderer().getUpY();
}
getUpZ(): float {
return this.getRenderer().getUpZ();
}
getRightX(): float {
return this.getRenderer().getRightX();
}
getRightY(): float {
return this.getRenderer().getRightY();
}
getRightZ(): float {
return this.getRenderer().getRightZ();
}
override getOriginalWidth(): float {
return this._originalWidth;
}
@@ -3,6 +3,8 @@ namespace gdjs {
export abstract class RuntimeObject3DRenderer {
protected _object: gdjs.RuntimeObject3D;
private _threeObject3D: THREE.Object3D;
private _basis: Basis | null = null;
private static matrix4: THREE.Matrix4 | null = null;
constructor(
runtimeObject: gdjs.RuntimeObject3D,
@@ -39,6 +41,7 @@ namespace gdjs {
gdjs.toRad(this._object.getRotationY()),
gdjs.toRad(this._object.angle)
);
this.invalidateRotation();
}
updateSize() {
@@ -54,5 +57,91 @@ namespace gdjs {
updateVisibility() {
this._threeObject3D.visible = !this._object.isHidden();
}
invalidateRotation(): void {
if (this._basis) {
this._basis.isDirty = true;
}
}
getForwardX(): float {
return this.getBasis().forwardX;
}
getForwardY(): float {
return this.getBasis().forwardY;
}
getForwardZ(): float {
return this.getBasis().forwardZ;
}
getUpX(): float {
return this.getBasis().upX;
}
getUpY(): float {
return this.getBasis().upY;
}
getUpZ(): float {
return this.getBasis().upZ;
}
getRightX(): float {
return this.getBasis().rightX;
}
getRightY(): float {
return this.getBasis().rightY;
}
getRightZ(): float {
return this.getBasis().rightZ;
}
private getBasis(): Basis {
if (!this._basis) {
this._basis = new Basis();
}
if (!this._basis.isDirty) {
return this._basis;
}
let rotationMatrix = gdjs.RuntimeObject3DRenderer.matrix4;
if (!rotationMatrix) {
rotationMatrix = new THREE.Matrix4();
gdjs.RuntimeObject3DRenderer.matrix4 = rotationMatrix;
}
rotationMatrix.makeRotationFromEuler(this._threeObject3D.rotation);
const elements = rotationMatrix.elements;
this._basis.forwardX = elements[0];
this._basis.forwardY = elements[1];
this._basis.forwardZ = elements[2];
this._basis.rightX = -elements[4];
this._basis.rightY = -elements[5];
this._basis.rightZ = -elements[6];
this._basis.upX = elements[8];
this._basis.upY = elements[9];
this._basis.upZ = elements[10];
return this._basis;
}
}
class Basis {
isDirty = true;
forwardX: float = 0;
forwardY: float = 0;
forwardZ: float = 0;
upX: float = 0;
upY: float = 0;
upZ: float = 0;
rightX: float = 0;
rightY: float = 0;
rightZ: float = 0;
}
}
+84 -3
View File
@@ -79,6 +79,51 @@ namespace gdjs {
*/
turnAroundZ(deltaAngle: float): void;
/**
* Get the X component of the forward vector of the object.
*/
getForwardX(): float;
/**
* Get the Y component of the forward vector of the object.
*/
getForwardY(): float;
/**
* Get the Z component of the forward vector of the object.
*/
getForwardZ(): float;
/**
* Get the X component of the up vector of the object.
*/
getUpX(): float;
/**
* Get the Y component of the up vector of the object.
*/
getUpY(): float;
/**
* Get the Z component of the up vector of the object.
*/
getUpZ(): float;
/**
* Get the X component of the right vector of the object.
*/
getRightX(): float;
/**
* Get the Y component of the right vector of the object.
*/
getRightY(): float;
/**
* Get the Z component of the right vector of the object.
*/
getRightZ(): float;
/**
* Get the object size on the Z axis (called "depth").
*/
@@ -94,7 +139,7 @@ namespace gdjs {
*
* @param newScale The new scale (must be greater than 0).
*/
setScaleZ(newScale: number): void;
setScaleZ(newScale: float): void;
/**
* Get the scale of the object on Z axis.
@@ -111,13 +156,13 @@ namespace gdjs {
* Return the bottom Z of the object.
* Rotations around X and Y are not taken into account.
*/
getUnrotatedAABBMinZ(): number;
getUnrotatedAABBMinZ(): float;
/**
* Return the top Z of the object.
* Rotations around X and Y are not taken into account.
*/
getUnrotatedAABBMaxZ(): number;
getUnrotatedAABBMaxZ(): float;
/**
* Return the depth of the object before any custom size is applied.
@@ -231,6 +276,42 @@ namespace gdjs {
this.object.turnAroundZ(deltaAngle);
}
getForwardX(): float {
return this.object.getForwardX();
}
getForwardY(): float {
return this.object.getForwardY();
}
getForwardZ(): float {
return this.object.getForwardZ();
}
getUpX(): float {
return this.object.getUpX();
}
getUpY(): float {
return this.object.getUpY();
}
getUpZ(): float {
return this.object.getUpZ();
}
getRightX(): float {
return this.object.getRightX();
}
getRightY(): float {
return this.object.getRightY();
}
getRightZ(): float {
return this.object.getRightZ();
}
getDepth(): float {
return this.object.getDepth();
}
+36
View File
@@ -287,6 +287,42 @@ namespace gdjs {
this.setAngle(gdjs.toDegrees(mesh.rotation.z));
}
getForwardX(): float {
return this.getRenderer().getForwardX();
}
getForwardY(): float {
return this.getRenderer().getForwardY();
}
getForwardZ(): float {
return this.getRenderer().getForwardZ();
}
getUpX(): float {
return this.getRenderer().getUpX();
}
getUpY(): float {
return this.getRenderer().getUpY();
}
getUpZ(): float {
return this.getRenderer().getUpZ();
}
getRightX(): float {
return this.getRenderer().getRightX();
}
getRightY(): float {
return this.getRenderer().getRightY();
}
getRightZ(): float {
return this.getRenderer().getRightZ();
}
/**
* @return the internal top bound of the object according to its children.
*/
@@ -13,6 +13,8 @@ namespace gdjs {
_instanceContainer: gdjs.CustomRuntimeObjectInstanceContainer;
_isContainerDirty: boolean = true;
_threeGroup: THREE.Group;
private _basis: Basis | null = null;
private static matrix4: THREE.Matrix4 | null = null;
constructor(
object: gdjs.CustomRuntimeObject3D,
@@ -118,6 +120,9 @@ namespace gdjs {
updateRotation() {
this._isContainerDirty = true;
if (this._basis) {
this._basis.isDirty = true;
}
}
updateSize() {
@@ -136,6 +141,81 @@ namespace gdjs {
// Layers are not handled for 3D custom objects.
}
getForwardX(): float {
return this.getBasis().forwardX;
}
getForwardY(): float {
return this.getBasis().forwardY;
}
getForwardZ(): float {
return this.getBasis().forwardZ;
}
getUpX(): float {
return this.getBasis().upX;
}
getUpY(): float {
return this.getBasis().upY;
}
getUpZ(): float {
return this.getBasis().upZ;
}
getRightX(): float {
return this.getBasis().rightX;
}
getRightY(): float {
return this.getBasis().rightY;
}
getRightZ(): float {
return this.getBasis().rightZ;
}
private getBasis(): Basis {
if (!this._basis) {
this._basis = new Basis();
}
if (!this._basis.isDirty) {
return this._basis;
}
const threeObject3D = this.get3DRendererObject();
// Make sure the rotation is up to date.
threeObject3D.rotation.set(
gdjs.toRad(this._object.getRotationX()),
gdjs.toRad(this._object.getRotationY()),
gdjs.toRad(this._object.angle)
);
let rotationMatrix = gdjs.CustomRuntimeObject3DRenderer.matrix4;
if (!rotationMatrix) {
rotationMatrix = new THREE.Matrix4();
gdjs.CustomRuntimeObject3DRenderer.matrix4 = rotationMatrix;
}
rotationMatrix.makeRotationFromEuler(threeObject3D.rotation);
const elements = rotationMatrix.elements;
this._basis.forwardX = elements[0];
this._basis.forwardY = elements[1];
this._basis.forwardZ = elements[2];
this._basis.rightX = -elements[4];
this._basis.rightY = -elements[5];
this._basis.rightZ = -elements[6];
this._basis.upX = elements[8];
this._basis.upY = elements[9];
this._basis.upZ = elements[10];
return this._basis;
}
static getAnimationFrameTextureManager(
imageManager: gdjs.PixiImageManager
): ThreeAnimationFrameTextureManager {
@@ -178,4 +258,17 @@ namespace gdjs {
return map ? map.image.height : 0;
}
}
class Basis {
isDirty = true;
forwardX: float = 0;
forwardY: float = 0;
forwardZ: float = 0;
upX: float = 0;
upY: float = 0;
upZ: float = 0;
rightX: float = 0;
rightY: float = 0;
rightZ: float = 0;
}
}
+255 -3
View File
@@ -249,6 +249,114 @@ module.exports = {
.addParameter('number', _('Angle to add (in degrees)'), '', false)
.markAsAdvanced()
.setFunctionName('turnAroundZ');
base3D
.addExpression(
'ForwardX',
_('Forward vector X component'),
_('Return the object forward vector X component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getForwardX');
base3D
.addExpression(
'ForwardY',
_('Forward vector Y component'),
_('Return the object forward vector Y component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getForwardY');
base3D
.addExpression(
'ForwardZ',
_('Forward vector Z component'),
_('Return the object forward vector Z component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getForwardZ');
base3D
.addExpression(
'UpX',
_('Up vector X component'),
_('Return the object up vector X component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getUpX');
base3D
.addExpression(
'UpY',
_('Up vector Y component'),
_('Return the object up vector Y component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getUpY');
base3D
.addExpression(
'UpZ',
_('Up vector Z component'),
_('Return the object up vector Z component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getUpZ');
base3D
.addExpression(
'RightX',
_('Right vector X component'),
_('Return the object right vector X component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getRightX');
base3D
.addExpression(
'RightY',
_('Right vector Y component'),
_('Return the object right vector Y component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getRightY');
base3D
.addExpression(
'RightZ',
_('Right vector Z component'),
_('Return the object right vector Z component.'),
_('Object basis'),
'res/conditions/3d_box.svg'
)
.addParameter('object', _('3D object'), '', false)
.addParameter('behavior', _('Behavior'), 'Base3DBehavior')
.setFunctionName('getRightZ');
}
{
@@ -1696,7 +1804,7 @@ module.exports = {
'CameraZ',
_('Camera Z position'),
_('the camera position on Z axis'),
_('the camera position on Z axis'),
_('the camera position on Z axis (layer: _PARAM3_)'),
'',
'res/conditions/3d_box.svg'
)
@@ -1717,7 +1825,7 @@ module.exports = {
'CameraRotationX',
_('Camera X rotation'),
_('the camera rotation on X axis'),
_('the camera rotation on X axis'),
_('the camera rotation on X axis (layer: _PARAM3_)'),
'',
'res/conditions/3d_box.svg'
)
@@ -1743,7 +1851,7 @@ module.exports = {
'CameraRotationY',
_('Camera Y rotation'),
_('the camera rotation on Y axis'),
_('the camera rotation on Y axis'),
_('the camera rotation on Y axis (layer: _PARAM3_)'),
'',
'res/conditions/3d_box.svg'
)
@@ -1763,6 +1871,150 @@ module.exports = {
.setGetter('gdjs.scene3d.camera.getCameraRotationY')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraForwardX',
_('Camera forward vector X component'),
_('Return the camera forward vector X component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraForwardX')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraForwardY',
_('Camera forward vector Y component'),
_('Return the camera forward vector Y component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraForwardY')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraForwardZ',
_('Camera forward vector Z component'),
_('Return the camera forward vector Z component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraForwardZ')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraUpX',
_('Camera up vector X component'),
_('Return the camera up vector X component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraUpX')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraUpY',
_('Camera up vector Y component'),
_('Return the camera up vector Y component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraUpY')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraUpZ',
_('Camera up vector Z component'),
_('Return the camera up vector Z component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraUpZ')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraRightX',
_('Camera right vector X component'),
_('Return the camera right vector X component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraRightX')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraRightY',
_('Camera right vector Y component'),
_('Return the camera right vector Y component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraRightY')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addExpression(
'CameraRightZ',
_('Camera right vector Z component'),
_('Return the camera right vector Z component.'),
_('Camera basis'),
'res/conditions/3d_box.svg'
)
.addCodeOnlyParameter('currentScene', '')
.addParameter('layer', _('Layer'), '', true)
.setDefaultValue('""')
.addParameter('expression', _('Camera number (default : 0)'), '', true)
.setDefaultValue('0')
.setFunctionName('gdjs.scene3d.camera.getCameraRightZ')
.setIncludeFile('Extensions/3D/Scene3DTools.js');
extension
.addAction(
'TurnCameraTowardObject',
+83 -20
View File
@@ -45,11 +45,7 @@ namespace gdjs {
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
const layerRenderer = layer.getRenderer();
const threeCamera = layerRenderer.getThreeCamera();
if (!threeCamera) return 0;
return gdjs.toDegrees(threeCamera.rotation.x);
return layer.getCameraRotationX(cameraIndex);
};
export const setCameraRotationX = (
@@ -59,12 +55,7 @@ namespace gdjs {
cameraIndex: integer
) => {
const layer = runtimeScene.getLayer(layerName);
const layerRenderer = layer.getRenderer();
const threeCamera = layerRenderer.getThreeCamera();
if (!threeCamera) return;
threeCamera.rotation.x = gdjs.toRad(angle);
layer.setCameraRotationX(angle, cameraIndex);
};
export const getCameraRotationY = (
@@ -73,11 +64,7 @@ namespace gdjs {
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
const layerRenderer = layer.getRenderer();
const threeCamera = layerRenderer.getThreeCamera();
if (!threeCamera) return 0;
return gdjs.toDegrees(threeCamera.rotation.y);
return layer.getCameraRotationY(cameraIndex);
};
export const setCameraRotationY = (
@@ -87,12 +74,88 @@ namespace gdjs {
cameraIndex: integer
) => {
const layer = runtimeScene.getLayer(layerName);
const layerRenderer = layer.getRenderer();
layer.setCameraRotationY(angle, cameraIndex);
};
const threeCamera = layerRenderer.getThreeCamera();
if (!threeCamera) return;
export const getCameraForwardX = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraForwardX(cameraIndex);
};
threeCamera.rotation.y = gdjs.toRad(angle);
export const getCameraForwardY = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraForwardY(cameraIndex);
};
export const getCameraForwardZ = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraForwardZ(cameraIndex);
};
export const getCameraUpX = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraUpX(cameraIndex);
};
export const getCameraUpY = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraUpY(cameraIndex);
};
export const getCameraUpZ = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraUpZ(cameraIndex);
};
export const getCameraRightX = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraRightX(cameraIndex);
};
export const getCameraRightY = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraRightY(cameraIndex);
};
export const getCameraRightZ = (
runtimeScene: RuntimeScene,
layerName: string,
cameraIndex: integer
): float => {
const layer = runtimeScene.getLayer(layerName);
return layer.getCameraRightZ(cameraIndex);
};
export const turnCameraTowardObject = (
+48
View File
@@ -67,6 +67,54 @@ namespace gdjs {
override setCameraRotation(rotation: float, cameraId?: integer): void {}
override getCameraRotationY(cameraId?: integer): float {
return 0;
}
override setCameraRotationY(rotationY: float, cameraId?: integer): void {}
override getCameraRotationX(cameraId?: integer): float {
return 0;
}
override setCameraRotationX(rotationX: float, cameraId?: integer): void {}
override getCameraForwardX(cameraId?: integer): number {
return 0;
}
override getCameraForwardY(cameraId?: integer): number {
return 0;
}
override getCameraForwardZ(cameraId?: integer): number {
return -1;
}
override getCameraUpX(cameraId?: integer): number {
return 0;
}
override getCameraUpY(cameraId?: integer): number {
return -1;
}
override getCameraUpZ(cameraId?: integer): number {
return 0;
}
override getCameraRightX(cameraId?: integer): number {
return 1;
}
override getCameraRightY(cameraId?: integer): number {
return 0;
}
override getCameraRightZ(cameraId?: integer): number {
return 0;
}
override convertCoords(
x: float,
y: float,
+95
View File
@@ -422,6 +422,101 @@ namespace gdjs {
*/
abstract setCameraRotation(rotation: float, cameraId?: integer): void;
/**
* Get the rotation around Y axis of the 3D camera, expressed in degrees.
*
* @param cameraId The camera number. Currently ignored.
* @return The rotation, in degrees.
*/
abstract getCameraRotationY(cameraId?: integer): float;
/**
* Set the rotation around Y axis of the 3D camera, expressed in degrees.
*
* @param rotation The new rotation, in degrees.
* @param cameraId The camera number. Currently ignored.
*/
abstract setCameraRotationY(rotationY: float, cameraId?: integer): void;
/**
* Get the rotation around X axis of the 3D camera, expressed in degrees.
*
* @param cameraId The camera number. Currently ignored.
* @return The rotation, in degrees.
*/
abstract getCameraRotationX(cameraId?: integer): float;
/**
* Set the rotation around X axis of the 3D camera, expressed in degrees.
*
* @param rotation The new rotation, in degrees.
* @param cameraId The camera number. Currently ignored.
*/
abstract setCameraRotationX(rotationX: float, cameraId?: integer): void;
/**
* Get the X component of the forward vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraForwardX(cameraId?: integer): number;
/**
* Get the Y component of the forward vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraForwardY(cameraId?: integer): number;
/**
* Get the Z component of the forward vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraForwardZ(cameraId?: integer): number;
/**
* Get the X component of the up vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraUpX(cameraId?: integer): number;
/**
* Get the Y component of the up vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraUpY(cameraId?: integer): number;
/**
* Get the Z component of the up vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraUpZ(cameraId?: integer): number;
/**
* Get the X component of the right vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraRightX(cameraId?: integer): number;
/**
* Get the Y component of the right vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraRightY(cameraId?: integer): number;
/**
* Get the Z component of the right vector of the 3D camera.
*
* @param cameraId The camera number. Currently ignored.
*/
abstract getCameraRightZ(cameraId?: integer): number;
/**
* Convert a point from the canvas coordinates (for example,
* the mouse position) to the container coordinates.
+53
View File
@@ -258,6 +258,59 @@ namespace gdjs {
override setCameraRotation(rotation: float, cameraId?: integer): void {
this._cameraRotation = rotation;
this._renderer.updatePosition();
this._renderer.invalidateRotation();
}
override getCameraRotationY(cameraId?: integer): float {
return this._renderer.getCameraRotationY();
}
override setCameraRotationY(rotationY: float, cameraId?: integer): void {
this._renderer.setCameraRotationY(rotationY);
}
override getCameraRotationX(cameraId?: integer): float {
return this._renderer.getCameraRotationX();
}
override setCameraRotationX(rotationX: float, cameraId?: integer): void {
this._renderer.setCameraRotationX(rotationX);
}
override getCameraForwardX(cameraId?: integer): number {
return this._renderer.getCameraForwardX();
}
override getCameraForwardY(cameraId?: integer): number {
return this._renderer.getCameraForwardY();
}
override getCameraForwardZ(cameraId?: integer): number {
return this._renderer.getCameraForwardZ();
}
override getCameraUpX(cameraId?: integer): number {
return this._renderer.getCameraUpX();
}
override getCameraUpY(cameraId?: integer): number {
return this._renderer.getCameraUpY();
}
override getCameraUpZ(cameraId?: integer): number {
return this._renderer.getCameraUpZ();
}
override getCameraRightX(cameraId?: integer): number {
return this._renderer.getCameraRightX();
}
override getCameraRightY(cameraId?: integer): number {
return this._renderer.getCameraRightY();
}
override getCameraRightZ(cameraId?: integer): number {
return this._renderer.getCameraRightZ();
}
/**
@@ -215,6 +215,8 @@ namespace gdjs {
| null = null;
private _threeCameraDirty: boolean = false;
private _threeEffectComposer: THREE_ADDONS.EffectComposer | null = null;
private _basis: Basis | null = null;
private static matrix4: THREE.Matrix4 | null = null;
// For a 2D+3D layer, the 2D rendering is done on the render texture
// and then must be displayed on a plane in the 3D world:
@@ -1005,6 +1007,107 @@ namespace gdjs {
);
}
getCameraRotationY(): number {
return this._threeCamera
? gdjs.toDegrees(this._threeCamera.rotation.y)
: 0;
}
setCameraRotationY(rotationY: float): void {
if (!this._threeCamera) {
return;
}
this._threeCamera.rotation.y = gdjs.toRad(rotationY);
this.invalidateRotation();
}
getCameraRotationX(): number {
return this._threeCamera
? gdjs.toDegrees(this._threeCamera.rotation.x)
: 0;
}
setCameraRotationX(rotationX: float): void {
if (!this._threeCamera) {
return;
}
this._threeCamera.rotation.x = gdjs.toRad(rotationX);
this.invalidateRotation();
}
invalidateRotation(): void {
if (this._basis) {
this._basis.isDirty = true;
}
}
getCameraForwardX(): number {
return this.getBasis().forwardX;
}
getCameraForwardY(): number {
return this.getBasis().forwardY;
}
getCameraForwardZ(): number {
return this.getBasis().forwardZ;
}
getCameraUpX(): number {
return this.getBasis().upX;
}
getCameraUpY(): number {
return this.getBasis().upY;
}
getCameraUpZ(): number {
return this.getBasis().upZ;
}
getCameraRightX(): number {
return this.getBasis().rightX;
}
getCameraRightY(): number {
return this.getBasis().rightY;
}
getCameraRightZ(): number {
return this.getBasis().rightZ;
}
private getBasis(): Basis {
if (!this._basis) {
this._basis = new Basis();
}
if (!this._basis.isDirty || !this._threeCamera) {
return this._basis;
}
let rotationMatrix = gdjs.LayerPixiRenderer.matrix4;
if (!rotationMatrix) {
rotationMatrix = new THREE.Matrix4();
gdjs.LayerPixiRenderer.matrix4 = rotationMatrix;
}
rotationMatrix.makeRotationFromEuler(this._threeCamera.rotation);
const elements = rotationMatrix.elements;
this._basis.forwardX = -elements[8];
this._basis.forwardY = elements[9];
this._basis.forwardZ = -elements[10];
this._basis.rightX = elements[0];
this._basis.rightY = -elements[1];
this._basis.rightZ = elements[2];
this._basis.upX = elements[4];
this._basis.upY = -elements[5];
this._basis.upZ = elements[6];
return this._basis;
}
transformTo3DWorld(
screenX: float,
screenY: float,
@@ -1262,6 +1365,19 @@ namespace gdjs {
}
}
class Basis {
isDirty = true;
forwardX: float = 0;
forwardY: float = 0;
forwardZ: float = 0;
upX: float = 0;
upY: float = 0;
upZ: float = 0;
rightX: float = 0;
rightY: float = 0;
rightZ: float = 0;
}
//Register the class to let the engine use it.
/**
* @category Renderers > Layers