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...
102 lines
3.5 KiB
TypeScript
102 lines
3.5 KiB
TypeScript
namespace gdjs {
|
|
gdjs.PixiFiltersTools.registerFilterCreator(
|
|
'Scene3D::DirectionalLight',
|
|
new (class implements gdjs.PixiFiltersTools.FilterCreator {
|
|
makeFilter(
|
|
target: EffectsTarget,
|
|
effectData: EffectData
|
|
): gdjs.PixiFiltersTools.Filter {
|
|
return new (class implements gdjs.PixiFiltersTools.Filter {
|
|
light: THREE.DirectionalLight;
|
|
rotationObject: THREE.Group;
|
|
_isEnabled: boolean = false;
|
|
top: string = 'Y-';
|
|
elevation: float = 45;
|
|
rotation: float = 0;
|
|
|
|
constructor() {
|
|
this.light = new THREE.DirectionalLight();
|
|
this.light.position.set(1, 0, 0);
|
|
this.rotationObject = new THREE.Group();
|
|
this.rotationObject.add(this.light);
|
|
this.updateRotation();
|
|
}
|
|
|
|
isEnabled(target: EffectsTarget): boolean {
|
|
return this._isEnabled;
|
|
}
|
|
setEnabled(target: EffectsTarget, enabled: boolean): boolean {
|
|
if (this._isEnabled === enabled) {
|
|
return true;
|
|
}
|
|
if (enabled) {
|
|
return this.applyEffect(target);
|
|
} else {
|
|
return this.removeEffect(target);
|
|
}
|
|
}
|
|
applyEffect(target: EffectsTarget): boolean {
|
|
const scene = target.get3DRendererObject() as
|
|
| THREE.Scene
|
|
| null
|
|
| undefined;
|
|
if (!scene) {
|
|
return false;
|
|
}
|
|
scene.add(this.rotationObject);
|
|
this._isEnabled = true;
|
|
return true;
|
|
}
|
|
removeEffect(target: EffectsTarget): boolean {
|
|
const scene = target.get3DRendererObject() as
|
|
| THREE.Scene
|
|
| null
|
|
| undefined;
|
|
if (!scene) {
|
|
return false;
|
|
}
|
|
scene.remove(this.rotationObject);
|
|
this._isEnabled = false;
|
|
return true;
|
|
}
|
|
updatePreRender(target: gdjs.EffectsTarget): any {}
|
|
updateDoubleParameter(parameterName: string, value: number): void {
|
|
if (parameterName === 'intensity') {
|
|
this.light.intensity = value;
|
|
} else if (parameterName === 'elevation') {
|
|
this.elevation = value;
|
|
this.updateRotation();
|
|
} else if (parameterName === 'rotation') {
|
|
this.rotation = value;
|
|
this.updateRotation();
|
|
}
|
|
}
|
|
updateStringParameter(parameterName: string, value: string): void {
|
|
if (parameterName === 'color') {
|
|
this.light.color = new THREE.Color(
|
|
gdjs.PixiFiltersTools.rgbOrHexToHexNumber(value)
|
|
);
|
|
}
|
|
if (parameterName === 'top') {
|
|
this.top = value;
|
|
this.updateRotation();
|
|
}
|
|
}
|
|
updateBooleanParameter(parameterName: string, value: boolean): void {}
|
|
updateRotation() {
|
|
if (this.top === 'Z+') {
|
|
// 0° is a light from the right of the screen.
|
|
this.rotationObject.rotation.z = gdjs.toRad(this.rotation);
|
|
this.rotationObject.rotation.y = -gdjs.toRad(this.elevation);
|
|
} else {
|
|
// 0° becomes a light from Z+.
|
|
this.rotationObject.rotation.y = gdjs.toRad(this.rotation) - 90;
|
|
this.rotationObject.rotation.z = -gdjs.toRad(this.elevation);
|
|
}
|
|
}
|
|
})();
|
|
}
|
|
})()
|
|
);
|
|
}
|