mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix aspect ratio being lost when hot-reloading 3D models (#7868)
This commit is contained in:
@@ -97,6 +97,14 @@ namespace gdjs {
|
||||
oldObjectData: Object3DData,
|
||||
newObjectData: Object3DData
|
||||
): boolean {
|
||||
this.updateOriginalDimensionsFromObjectData(oldObjectData, newObjectData);
|
||||
return true;
|
||||
}
|
||||
|
||||
updateOriginalDimensionsFromObjectData(
|
||||
oldObjectData: Object3DData,
|
||||
newObjectData: Object3DData
|
||||
): void {
|
||||
// There is no need to check if they changed because events can't modify them.
|
||||
this._setOriginalWidth(
|
||||
getValidDimensionValue(newObjectData.content.width)
|
||||
@@ -107,7 +115,6 @@ namespace gdjs {
|
||||
this._setOriginalDepth(
|
||||
getValidDimensionValue(newObjectData.content.depth)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
getNetworkSyncData(
|
||||
|
@@ -153,6 +153,14 @@ namespace gdjs {
|
||||
}
|
||||
}
|
||||
|
||||
override updateOriginalDimensionsFromObjectData(
|
||||
oldObjectData: Object3DData,
|
||||
newObjectData: Object3DData
|
||||
): void {
|
||||
// Original dimensions must not be reset by `super.updateFromObjectData`.
|
||||
// `_updateModel` has a different logic to evaluate them using `keepAspectRatio`.
|
||||
}
|
||||
|
||||
updateFromObjectData(
|
||||
oldObjectData: Model3DObjectData,
|
||||
newObjectData: Model3DObjectData
|
||||
@@ -182,8 +190,14 @@ namespace gdjs {
|
||||
oldObjectData.content.keepAspectRatio !==
|
||||
newObjectData.content.keepAspectRatio ||
|
||||
oldObjectData.content.materialType !==
|
||||
newObjectData.content.materialType
|
||||
newObjectData.content.materialType ||
|
||||
oldObjectData.content.centerLocation !==
|
||||
newObjectData.content.centerLocation
|
||||
) {
|
||||
// The center is applied to the model by `_updateModel`.
|
||||
this._centerPoint = getPointForLocation(
|
||||
newObjectData.content.centerLocation
|
||||
);
|
||||
this._updateModel(newObjectData);
|
||||
}
|
||||
if (
|
||||
@@ -193,14 +207,7 @@ namespace gdjs {
|
||||
this._originPoint = getPointForLocation(
|
||||
newObjectData.content.originLocation
|
||||
);
|
||||
}
|
||||
if (
|
||||
oldObjectData.content.centerLocation !==
|
||||
newObjectData.content.centerLocation
|
||||
) {
|
||||
this._centerPoint = getPointForLocation(
|
||||
newObjectData.content.centerLocation
|
||||
);
|
||||
this._renderer.updatePosition();
|
||||
}
|
||||
if (
|
||||
oldObjectData.content.isCastingShadow !==
|
||||
@@ -281,14 +288,17 @@ namespace gdjs {
|
||||
const rotationX = objectData.content.rotationX || 0;
|
||||
const rotationY = objectData.content.rotationY || 0;
|
||||
const rotationZ = objectData.content.rotationZ || 0;
|
||||
const width = objectData.content.width || 100;
|
||||
const height = objectData.content.height || 100;
|
||||
const depth = objectData.content.depth || 100;
|
||||
const keepAspectRatio = objectData.content.keepAspectRatio;
|
||||
this._renderer._updateModel(
|
||||
rotationX,
|
||||
rotationY,
|
||||
rotationZ,
|
||||
this._getOriginalWidth(),
|
||||
this._getOriginalHeight(),
|
||||
this._getOriginalDepth(),
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
keepAspectRatio
|
||||
);
|
||||
}
|
||||
|
@@ -233,6 +233,10 @@ namespace gdjs {
|
||||
this._object._setOriginalWidth(scaleRatio * modelWidth);
|
||||
this._object._setOriginalHeight(scaleRatio * modelHeight);
|
||||
this._object._setOriginalDepth(scaleRatio * modelDepth);
|
||||
} else {
|
||||
this._object._setOriginalWidth(originalWidth);
|
||||
this._object._setOriginalHeight(originalHeight);
|
||||
this._object._setOriginalDepth(originalDepth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +290,7 @@ namespace gdjs {
|
||||
this.get3DRendererObject().remove(this._threeObject);
|
||||
this.get3DRendererObject().add(threeObject);
|
||||
this._threeObject = threeObject;
|
||||
this.updatePosition();
|
||||
this._updateShadow();
|
||||
|
||||
// Start the current animation on the new 3D object.
|
||||
|
@@ -348,7 +348,7 @@ namespace gdjs {
|
||||
// It can't actually happen.
|
||||
this._logs.push({
|
||||
kind: 'error',
|
||||
message: "Can't hot-reload as no scene are opened.",
|
||||
message: "Can't hot-reload as no scene is opened.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user