mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
added cast shadow ? support on directionnal light + resolution parameter
This commit is contained in:
@@ -20,7 +20,6 @@ namespace gdjs {
|
||||
light: THREE.DirectionalLight;
|
||||
rotationObject: THREE.Group;
|
||||
_isEnabled: boolean = false;
|
||||
_isCastingShadow: boolean = true;
|
||||
top: string = 'Y-';
|
||||
elevation: float = 45;
|
||||
rotation: float = 0;
|
||||
@@ -28,7 +27,6 @@ namespace gdjs {
|
||||
|
||||
constructor() {
|
||||
this.light = new THREE.DirectionalLight();
|
||||
this.light.castShadow = this._isCastingShadow;
|
||||
this.light.shadow.mapSize.width = this.shadowSize;
|
||||
this.light.shadow.mapSize.height = this.shadowSize;
|
||||
this.light.shadow.camera.near = 1;
|
||||
@@ -139,6 +137,34 @@ namespace gdjs {
|
||||
this.top = value;
|
||||
this.updateRotation();
|
||||
}
|
||||
if(parameterName === 'shadowQuality')
|
||||
{
|
||||
console.log("il y a un paramètre shadowQuality");
|
||||
if(value === 'Low')
|
||||
{
|
||||
this.light.shadow.mapSize.height = 64;
|
||||
this.light.shadow.mapSize.width = 64;
|
||||
this.light.shadow.map = null; // Force la recréation du shadow map
|
||||
|
||||
this.light.shadow.needsUpdate = true;
|
||||
}
|
||||
if(value === 'Medium')
|
||||
{
|
||||
this.light.shadow.mapSize.width = 1024;
|
||||
this.light.shadow.mapSize.height = 1024;
|
||||
this.light.shadow.map = null; // Force la recréation du shadow map
|
||||
this.light.shadow.needsUpdate = true;
|
||||
|
||||
}
|
||||
if(value === 'High')
|
||||
{
|
||||
this.light.shadow.mapSize.width = 4096;
|
||||
this.light.shadow.mapSize.height = 4096;
|
||||
this.light.shadow.map = null; // Force la recréation du shadow map
|
||||
this.light.shadow.needsUpdate = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
updateColorParameter(parameterName: string, value: number): void {
|
||||
if (parameterName === 'color') {
|
||||
@@ -151,7 +177,13 @@ namespace gdjs {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
updateBooleanParameter(parameterName: string, value: boolean): void {}
|
||||
updateBooleanParameter(parameterName: string, value: boolean): void {
|
||||
if(parameterName === 'isCastingShadow')
|
||||
{
|
||||
this.light.castShadow = value;
|
||||
}
|
||||
}
|
||||
|
||||
updateRotation() {
|
||||
if (this.top === 'Z+') {
|
||||
// 0° is a light from the right of the screen.
|
||||
|
@@ -1928,9 +1928,9 @@ module.exports = {
|
||||
.setType('number')
|
||||
.setGroup(_('Orientation'));
|
||||
properties
|
||||
.getOrCreate('castShadow')
|
||||
.getOrCreate('isCastingShadow')
|
||||
.setValue('true')
|
||||
.setLabel(_('Casting shadows'))
|
||||
.setLabel(_('Shadow casting'))
|
||||
.setType('boolean')
|
||||
.setGroup(_('Shadows'));
|
||||
properties
|
||||
|
@@ -127,8 +127,8 @@ namespace gdjs {
|
||||
objectData.content.materialType
|
||||
);
|
||||
|
||||
this._isCastingShadow = objectData.content.isCastingShadow;
|
||||
this._isReceivingShadow = objectData.content.isReceivingShadow;
|
||||
this.setIsCastingShadow(objectData.content.isCastingShadow);
|
||||
this.setIsReceivingShadow(objectData.content.isReceivingShadow);
|
||||
this.onModelChanged(objectData);
|
||||
|
||||
this._crossfadeDuration = objectData.content.crossfadeDuration || 0;
|
||||
@@ -205,13 +205,13 @@ namespace gdjs {
|
||||
oldObjectData.content.isCastingShadow !==
|
||||
newObjectData.content.isCastingShadow
|
||||
) {
|
||||
this._isCastingShadow = newObjectData.content.isCastingShadow;
|
||||
this.setIsCastingShadow(newObjectData.content.isCastingShadow);
|
||||
}
|
||||
if (
|
||||
oldObjectData.content.isReceivingShadow !==
|
||||
newObjectData.content.isReceivingShadow
|
||||
) {
|
||||
this._isReceivingShadow = newObjectData.content.isReceivingShadow;
|
||||
this.setIsReceivingShadow(newObjectData.content.isReceivingShadow);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -376,12 +376,14 @@ namespace gdjs {
|
||||
return this._renderer.hasAnimationEnded();
|
||||
}
|
||||
|
||||
setIsCastShadow(value: boolean): void {
|
||||
setIsCastingShadow(value: boolean): void {
|
||||
this._isCastingShadow = value;
|
||||
this._renderer._updateShadow();
|
||||
}
|
||||
|
||||
setIsReceiveShadow(value: boolean): void {
|
||||
setIsReceivingShadow(value: boolean): void {
|
||||
this._isReceivingShadow = value;
|
||||
this._renderer._updateShadow();
|
||||
}
|
||||
|
||||
setCrossfadeDuration(duration: number): void {
|
||||
|
@@ -286,10 +286,7 @@ namespace gdjs {
|
||||
this.get3DRendererObject().remove(this._threeObject);
|
||||
this.get3DRendererObject().add(threeObject);
|
||||
this._threeObject = threeObject;
|
||||
this._threeObject.traverse((child) => {
|
||||
child.castShadow = this._model3DRuntimeObject._isCastingShadow;
|
||||
child.receiveShadow = this._model3DRuntimeObject._isReceivingShadow;
|
||||
});
|
||||
this._updateShadow();
|
||||
|
||||
// Start the current animation on the new 3D object.
|
||||
this._animationMixer = new THREE.AnimationMixer(root);
|
||||
@@ -327,6 +324,14 @@ namespace gdjs {
|
||||
return this._originalModel.animations[animationIndex].name;
|
||||
}
|
||||
|
||||
_updateShadow()
|
||||
{
|
||||
this._threeObject.traverse((child) => {
|
||||
child.castShadow = this._model3DRuntimeObject._isCastingShadow;
|
||||
child.receiveShadow = this._model3DRuntimeObject._isReceivingShadow;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if animation has ended.
|
||||
* The animation had ended if:
|
||||
|
Reference in New Issue
Block a user