mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00

* This provides new 3D objects: 3D Box (perfect to create walls, floors, or billboards) and 3D Model (to import objects created in a 3D modeling app). * 2D and 3D can be mixed in a same game. Each layer of a game can contain 2D objects, 3D objects or a mix of both. * This allows to build 2D games, 2.5D games and full 3D games: platformers, racing games, FPS, hyper casual games. It's easy to start adding 3D objects to an existing 2D game. * You can set up a light by adding an ambient light and/or directional light in the effects of a 3D layer. 3D objects can be configured to react to light or ignore it. * In the future, support for 3D objects will be improved: light objects, animations, etc...
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
namespace gdjs {
|
|
export abstract class RuntimeObject3DRenderer {
|
|
protected _object: gdjs.RuntimeObject3D;
|
|
private _threeObject3D: THREE.Object3D;
|
|
|
|
constructor(
|
|
runtimeObject: gdjs.RuntimeObject3D,
|
|
instanceContainer: gdjs.RuntimeInstanceContainer,
|
|
threeObject3D: THREE.Object3D
|
|
) {
|
|
this._object = runtimeObject;
|
|
this._threeObject3D = threeObject3D;
|
|
this._threeObject3D.rotation.order = 'ZYX';
|
|
|
|
instanceContainer
|
|
.getLayer('')
|
|
.getRenderer()
|
|
.add3DRendererObject(this._threeObject3D);
|
|
}
|
|
|
|
get3DRendererObject() {
|
|
return this._threeObject3D;
|
|
}
|
|
|
|
updatePosition() {
|
|
this._threeObject3D.position.set(
|
|
this._object.x + this._object.getWidth() / 2,
|
|
this._object.y + this._object.getHeight() / 2,
|
|
this._object.getZ() + this._object.getDepth() / 2
|
|
);
|
|
}
|
|
|
|
updateRotation() {
|
|
this._threeObject3D.rotation.set(
|
|
gdjs.toRad(this._object.getRotationX()),
|
|
gdjs.toRad(this._object.getRotationY()),
|
|
gdjs.toRad(this._object.angle)
|
|
);
|
|
}
|
|
|
|
updateSize() {
|
|
const object = this._object;
|
|
this._threeObject3D.scale.set(
|
|
object.isFlippedX() ? -object.getWidth() : object.getWidth(),
|
|
object.isFlippedY() ? -object.getHeight() : object.getHeight(),
|
|
object.isFlippedZ() ? -object.getDepth() : object.getDepth()
|
|
);
|
|
this.updatePosition();
|
|
}
|
|
|
|
updateVisibility() {
|
|
this._threeObject3D.visible = !this._object.isHidden();
|
|
}
|
|
}
|
|
}
|