@luminocity/lemonate-engine 26.4.4 → 26.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Renderer.d.ts +0 -2
- package/dist/lemonate.es.js +257 -220
- package/dist/lemonate.js +257 -220
- package/dist/lemonate.min.js +3 -3
- package/dist/lemonate.umd.js +257 -220
- package/dist/player.zip +0 -0
- package/dist/tools/Profiler.d.ts +4 -0
- package/package.json +1 -1
package/dist/lemonate.js
CHANGED
|
@@ -87367,7 +87367,7 @@ void main() {
|
|
|
87367
87367
|
}
|
|
87368
87368
|
}
|
|
87369
87369
|
|
|
87370
|
-
var engine$1 = "26.4.
|
|
87370
|
+
var engine$1 = "26.4.7";
|
|
87371
87371
|
var bullet = "3.26";
|
|
87372
87372
|
var lua = "5.4.3";
|
|
87373
87373
|
var packageVersionInfo = {
|
|
@@ -225931,222 +225931,222 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
225931
225931
|
}
|
|
225932
225932
|
async render(renderPassInfo) {
|
|
225933
225933
|
this.renderPassInfo = renderPassInfo;
|
|
225934
|
-
|
|
225935
|
-
|
|
225936
|
-
|
|
225937
|
-
|
|
225938
|
-
|
|
225939
|
-
|
|
225940
|
-
|
|
225941
|
-
}
|
|
225942
|
-
// Activate our scene graph collection
|
|
225943
|
-
// ----------------------------------------------------------------------------------
|
|
225944
|
-
const sceneGraphCollection = renderPassInfo.sceneGraphCollection;
|
|
225945
|
-
this.engine.setActiveSceneGraphCollection(sceneGraphCollection);
|
|
225946
|
-
const rootScene = sceneGraphCollection.getRootScene();
|
|
225947
|
-
let primaryScene = sceneGraphCollection.getPrimaryScene();
|
|
225948
|
-
// We do no physics particles and scripting unless we're in the main scene graph collection.
|
|
225949
|
-
// This is temporarily, until everything has been untangled properly and every sceneGraphCollection
|
|
225950
|
-
// is completely independant from all others
|
|
225951
|
-
// ----------------------------------------------------------------------------------
|
|
225952
|
-
const isMainSceneGraphCollection = this.engine.mainSceneGraphCollection === sceneGraphCollection;
|
|
225953
|
-
const doPhysics = isMainSceneGraphCollection;
|
|
225954
|
-
const doParticleSystemUpdate = isMainSceneGraphCollection;
|
|
225955
|
-
const doScripting = isMainSceneGraphCollection;
|
|
225956
|
-
// Update physics objects and call update/tick methods
|
|
225957
|
-
// ----------------------------------------------------------------------------------
|
|
225958
|
-
if (!renderPassInfo.playerIsPaused) {
|
|
225959
|
-
if (doPhysics) {
|
|
225960
|
-
this.engine.profiler.measure("Physics", "processUpdate", async () => {
|
|
225961
|
-
this.engine.physics.processPhysicsUpdate();
|
|
225962
|
-
});
|
|
225934
|
+
await this.engine.profiler.measureAsync("RenderView", "render", async () => {
|
|
225935
|
+
try {
|
|
225936
|
+
// Activate our canvas for use with canvas Lua API
|
|
225937
|
+
// ----------------------------------------------------------------------------------
|
|
225938
|
+
if (this.canvas) {
|
|
225939
|
+
this.renderer.setActiveCanvas(this.canvas);
|
|
225940
|
+
this.canvas.checkResize(renderPassInfo.resolution);
|
|
225963
225941
|
}
|
|
225964
|
-
|
|
225965
|
-
|
|
225966
|
-
|
|
225967
|
-
|
|
225942
|
+
// Activate our scene graph collection
|
|
225943
|
+
// ----------------------------------------------------------------------------------
|
|
225944
|
+
const sceneGraphCollection = renderPassInfo.sceneGraphCollection;
|
|
225945
|
+
this.engine.setActiveSceneGraphCollection(sceneGraphCollection);
|
|
225946
|
+
const rootScene = sceneGraphCollection.getRootScene();
|
|
225947
|
+
let primaryScene = sceneGraphCollection.getPrimaryScene();
|
|
225948
|
+
// We do no physics particles and scripting unless we're in the main scene graph collection.
|
|
225949
|
+
// This is temporarily, until everything has been untangled properly and every sceneGraphCollection
|
|
225950
|
+
// is completely independant from all others
|
|
225951
|
+
// ----------------------------------------------------------------------------------
|
|
225952
|
+
const isMainSceneGraphCollection = this.engine.mainSceneGraphCollection === sceneGraphCollection;
|
|
225953
|
+
const doPhysics = isMainSceneGraphCollection;
|
|
225954
|
+
const doParticleSystemUpdate = isMainSceneGraphCollection;
|
|
225955
|
+
const doScripting = isMainSceneGraphCollection;
|
|
225956
|
+
// Update physics objects and call update/tick methods
|
|
225957
|
+
// ----------------------------------------------------------------------------------
|
|
225958
|
+
if (!renderPassInfo.playerIsPaused) {
|
|
225959
|
+
if (doPhysics) {
|
|
225960
|
+
this.engine.profiler.measure("Physics", "processUpdate", async () => {
|
|
225961
|
+
this.engine.physics.processPhysicsUpdate();
|
|
225962
|
+
});
|
|
225963
|
+
}
|
|
225964
|
+
if (doScripting) {
|
|
225965
|
+
await this.engine.profiler.measureAsync("Scripting", "update", async () => {
|
|
225966
|
+
return this.engine.player.update();
|
|
225967
|
+
});
|
|
225968
|
+
}
|
|
225968
225969
|
}
|
|
225969
|
-
|
|
225970
|
-
|
|
225971
|
-
|
|
225972
|
-
|
|
225973
|
-
|
|
225974
|
-
|
|
225975
|
-
|
|
225976
|
-
|
|
225977
|
-
|
|
225978
|
-
|
|
225979
|
-
this.cameraMode = this.cameraModeOverride;
|
|
225980
|
-
}
|
|
225981
|
-
else {
|
|
225982
|
-
const primarySceneItem = sceneGraphCollection.getPrimarySceneItem();
|
|
225983
|
-
if (primarySceneItem && typeof primarySceneItem.getCameraMode === 'function')
|
|
225984
|
-
this.cameraMode = primarySceneItem.getCameraMode();
|
|
225985
|
-
else
|
|
225986
|
-
this.cameraMode = CameraMode.AutomaticUserControllable;
|
|
225987
|
-
}
|
|
225988
|
-
// Set clear color
|
|
225989
|
-
// ----------------------------------------------------------------------------------
|
|
225990
|
-
if (primaryScene.userData?.customRenderSettings) {
|
|
225991
|
-
const clearColor = primaryScene.userData.customRenderSettings.clearColor;
|
|
225992
|
-
if (clearColor) {
|
|
225993
|
-
const clearColorRGB = (clearColor.r << 16) + (clearColor.g << 8) + clearColor.b;
|
|
225994
|
-
this.webGlRenderer.setClearColor(clearColorRGB, clearColor.a / 255);
|
|
225970
|
+
// Call beforeRender hook on all items
|
|
225971
|
+
// ----------------------------------------------------------------------------------
|
|
225972
|
+
const itemInstances = this.engine.loadingManager.getAllItemInstances();
|
|
225973
|
+
for (const item of itemInstances) {
|
|
225974
|
+
item.beforeRender();
|
|
225975
|
+
}
|
|
225976
|
+
// Set camera mode
|
|
225977
|
+
// ----------------------------------------------------------------------------------
|
|
225978
|
+
if (this.cameraModeOverride !== CameraMode.None) {
|
|
225979
|
+
this.cameraMode = this.cameraModeOverride;
|
|
225995
225980
|
}
|
|
225996
225981
|
else {
|
|
225997
|
-
|
|
225982
|
+
const primarySceneItem = sceneGraphCollection.getPrimarySceneItem();
|
|
225983
|
+
if (primarySceneItem && typeof primarySceneItem.getCameraMode === 'function')
|
|
225984
|
+
this.cameraMode = primarySceneItem.getCameraMode();
|
|
225985
|
+
else
|
|
225986
|
+
this.cameraMode = CameraMode.AutomaticUserControllable;
|
|
225998
225987
|
}
|
|
225999
|
-
|
|
226000
|
-
|
|
226001
|
-
|
|
226002
|
-
|
|
226003
|
-
|
|
226004
|
-
|
|
226005
|
-
|
|
226006
|
-
rootScene.fog = primaryScene.fog;
|
|
226007
|
-
// Animate scene
|
|
226008
|
-
// ----------------------------------------------------------------------------------
|
|
226009
|
-
if (!renderPassInfo.playerIsPaused) {
|
|
226010
|
-
this.engine.profiler.measure("RenderView", "animate", async () => {
|
|
226011
|
-
this._animate(sceneGraphCollection, renderPassInfo.deltaPlayerTimeMs);
|
|
226012
|
-
});
|
|
226013
|
-
}
|
|
226014
|
-
// Init GUI
|
|
226015
|
-
// ----------------------------------------------------------------------------------
|
|
226016
|
-
const needToRenderGui = this.engine.player.needToRenderGui();
|
|
226017
|
-
if (needToRenderGui) {
|
|
226018
|
-
renderPassInfo.guiCaptureInfo = this.engine.imgui.newFrame(renderPassInfo.currentPlayerTimeMs);
|
|
226019
|
-
}
|
|
226020
|
-
if (doParticleSystemUpdate)
|
|
226021
|
-
this.renderer.renderParticleSystems(renderPassInfo);
|
|
226022
|
-
this.renderer.updateViewHelper(renderPassInfo);
|
|
226023
|
-
this.renderer.updateControls(renderPassInfo);
|
|
226024
|
-
// whenever we playback, we assume, we're moving
|
|
226025
|
-
if (this.engine.player && this.engine.player.isPlaying()) {
|
|
226026
|
-
renderPassInfo.didMove = true;
|
|
226027
|
-
}
|
|
226028
|
-
if (!renderPassInfo.cameraIsStill && renderPassInfo.currentTimeMs - renderPassInfo.lastMovementMs > 500) {
|
|
226029
|
-
renderPassInfo.cameraIsStill = true;
|
|
226030
|
-
renderPassInfo.didMove = true;
|
|
226031
|
-
}
|
|
226032
|
-
// Check if we actually need to render a frame due to movements or data updates
|
|
226033
|
-
// ----------------------------------------------------------------------------------
|
|
226034
|
-
if (renderPassInfo.didMove ||
|
|
226035
|
-
renderPassInfo.screenWasResized ||
|
|
226036
|
-
this.renderer.alwaysRender ||
|
|
226037
|
-
this.renderer.updateRender) {
|
|
226038
|
-
if (this.webGlRenderer && this.renderer.activeCamera) {
|
|
226039
|
-
renderPassInfo.cameraDidMove = renderPassInfo.didMove || renderPassInfo.screenWasResized;
|
|
226040
|
-
// We'll remove the scene environment, because it will be applied to anything including
|
|
226041
|
-
// helpers and we don't want that. We'll apply it manually in the hooks and set it back after rendering
|
|
226042
|
-
// ----------------------------------------------------------------------------------
|
|
226043
|
-
renderPassInfo.sceneEnvironment = primaryScene.environment;
|
|
226044
|
-
renderPassInfo.sceneEnvironmentIntensity =
|
|
226045
|
-
primaryScene.environmentIntensity !== undefined
|
|
226046
|
-
? primaryScene.environmentIntensity
|
|
226047
|
-
: 1;
|
|
226048
|
-
// Call before render to set any overrides like visibility, material or envmap
|
|
226049
|
-
// ----------------------------------------------------------------------------------
|
|
226050
|
-
this.beforeRender(renderPassInfo);
|
|
226051
|
-
// Do light, material, etc. updates
|
|
226052
|
-
// ----------------------------------------------------------------------------------
|
|
226053
|
-
this.setRendererSettingsFromScene();
|
|
226054
|
-
this.renderer.updateMaterialUniforms(renderPassInfo.currentPlayerTimeMs, renderPassInfo.resolution);
|
|
226055
|
-
// Check if we have transform controls which we need to hide
|
|
226056
|
-
// ----------------------------------------------------------------------------------
|
|
226057
|
-
let transformControlsWereDisabled = false;
|
|
226058
|
-
if (rootScene.transformControls &&
|
|
226059
|
-
rootScene.transformControls.visible &&
|
|
226060
|
-
(!renderPassInfo.renderOptions.showHelpers || this.renderer.editorOutputOption.outputMode !== OutputMode.EditorCamera)) {
|
|
226061
|
-
transformControlsWereDisabled = true;
|
|
226062
|
-
rootScene.transformControls.visible = false;
|
|
226063
|
-
}
|
|
226064
|
-
// Check if we need to render background and transfer to root scene
|
|
226065
|
-
// ----------------------------------------------------------------------------------
|
|
226066
|
-
rootScene.backgroundBlurriness = primaryScene.backgroundBlurriness;
|
|
226067
|
-
rootScene.backgroundIntensity = primaryScene.backgroundIntensity;
|
|
226068
|
-
if (!renderPassInfo.renderOptions.showBackground) {
|
|
226069
|
-
rootScene.background = null;
|
|
226070
|
-
rootScene.backgroundShader = undefined;
|
|
226071
|
-
}
|
|
226072
|
-
else if (this.renderer.backgroundOverrideColor) {
|
|
226073
|
-
rootScene.background = tools.hexColorToColor(this.renderer.backgroundOverrideColor);
|
|
226074
|
-
rootScene.backgroundShader = undefined;
|
|
225988
|
+
// Set clear color
|
|
225989
|
+
// ----------------------------------------------------------------------------------
|
|
225990
|
+
if (primaryScene.userData?.customRenderSettings) {
|
|
225991
|
+
const clearColor = primaryScene.userData.customRenderSettings.clearColor;
|
|
225992
|
+
if (clearColor) {
|
|
225993
|
+
const clearColorRGB = (clearColor.r << 16) + (clearColor.g << 8) + clearColor.b;
|
|
225994
|
+
this.webGlRenderer.setClearColor(clearColorRGB, clearColor.a / 255);
|
|
226075
225995
|
}
|
|
226076
225996
|
else {
|
|
226077
|
-
|
|
226078
|
-
rootScene.backgroundShader = primaryScene.backgroundShader;
|
|
226079
|
-
}
|
|
226080
|
-
// Render any items that need to be rendered first
|
|
226081
|
-
// ----------------------------------------------------------------------------------
|
|
226082
|
-
for (const item of itemInstances) {
|
|
226083
|
-
item.render(rootScene, renderPassInfo);
|
|
226084
|
-
}
|
|
226085
|
-
// Update physics debug geometry
|
|
226086
|
-
// ----------------------------------------------------------------------------------
|
|
226087
|
-
if (doPhysics) {
|
|
226088
|
-
this.engine.profiler.measure("Physics", "renderDebugInfo", () => {
|
|
226089
|
-
this.engine.physics.renderDebugInfo();
|
|
226090
|
-
});
|
|
226091
|
-
}
|
|
226092
|
-
// Render the scene
|
|
226093
|
-
// ----------------------------------------------------------------------------------
|
|
226094
|
-
this._renderScene(renderPassInfo);
|
|
226095
|
-
// Call render hook
|
|
226096
|
-
// ----------------------------------------------------------------------------------
|
|
226097
|
-
if (!renderPassInfo.playerIsPaused && doScripting) {
|
|
226098
|
-
await this.engine.profiler.measureAsync("Scripting", "render", () => {
|
|
226099
|
-
return this.engine.player.render();
|
|
226100
|
-
});
|
|
225997
|
+
this.webGlRenderer.setClearColor(0x000000, 1);
|
|
226101
225998
|
}
|
|
226102
|
-
|
|
226103
|
-
|
|
226104
|
-
|
|
226105
|
-
|
|
226106
|
-
|
|
226107
|
-
|
|
225999
|
+
}
|
|
226000
|
+
else {
|
|
226001
|
+
this.webGlRenderer.setClearColor(0x000000, 1);
|
|
226002
|
+
}
|
|
226003
|
+
// Set fog of the primary scene if any
|
|
226004
|
+
// ----------------------------------------------------------------------------------
|
|
226005
|
+
// @ts-ignore
|
|
226006
|
+
rootScene.fog = primaryScene.fog;
|
|
226007
|
+
// Animate scene
|
|
226008
|
+
// ----------------------------------------------------------------------------------
|
|
226009
|
+
if (!renderPassInfo.playerIsPaused) {
|
|
226010
|
+
this.engine.profiler.measure("RenderView", "animate", async () => {
|
|
226011
|
+
this._animate(sceneGraphCollection, renderPassInfo.deltaPlayerTimeMs);
|
|
226012
|
+
});
|
|
226013
|
+
}
|
|
226014
|
+
// Init GUI
|
|
226015
|
+
// ----------------------------------------------------------------------------------
|
|
226016
|
+
const needToRenderGui = this.engine.player.needToRenderGui();
|
|
226017
|
+
if (needToRenderGui) {
|
|
226018
|
+
renderPassInfo.guiCaptureInfo = this.engine.imgui.newFrame(renderPassInfo.currentPlayerTimeMs);
|
|
226019
|
+
}
|
|
226020
|
+
if (doParticleSystemUpdate)
|
|
226021
|
+
this.renderer.renderParticleSystems(renderPassInfo);
|
|
226022
|
+
this.renderer.updateViewHelper(renderPassInfo);
|
|
226023
|
+
this.renderer.updateControls(renderPassInfo);
|
|
226024
|
+
// whenever we playback, we assume, we're moving
|
|
226025
|
+
if (this.engine.player && this.engine.player.isPlaying()) {
|
|
226026
|
+
renderPassInfo.didMove = true;
|
|
226027
|
+
}
|
|
226028
|
+
if (!renderPassInfo.cameraIsStill && renderPassInfo.currentTimeMs - renderPassInfo.lastMovementMs > 500) {
|
|
226029
|
+
renderPassInfo.cameraIsStill = true;
|
|
226030
|
+
renderPassInfo.didMove = true;
|
|
226031
|
+
}
|
|
226032
|
+
// Check if we actually need to render a frame due to movements or data updates
|
|
226033
|
+
// ----------------------------------------------------------------------------------
|
|
226034
|
+
if (renderPassInfo.didMove ||
|
|
226035
|
+
renderPassInfo.screenWasResized ||
|
|
226036
|
+
this.renderer.alwaysRender ||
|
|
226037
|
+
this.renderer.updateRender) {
|
|
226038
|
+
if (this.webGlRenderer && this.renderer.activeCamera) {
|
|
226039
|
+
renderPassInfo.cameraDidMove = renderPassInfo.didMove || renderPassInfo.screenWasResized;
|
|
226040
|
+
// We'll remove the scene environment, because it will be applied to anything including
|
|
226041
|
+
// helpers and we don't want that. We'll apply it manually in the hooks and set it back after rendering
|
|
226042
|
+
// ----------------------------------------------------------------------------------
|
|
226043
|
+
renderPassInfo.sceneEnvironment = primaryScene.environment;
|
|
226044
|
+
renderPassInfo.sceneEnvironmentIntensity =
|
|
226045
|
+
primaryScene.environmentIntensity !== undefined
|
|
226046
|
+
? primaryScene.environmentIntensity
|
|
226047
|
+
: 1;
|
|
226048
|
+
// Call before render to set any overrides like visibility, material or envmap
|
|
226049
|
+
// ----------------------------------------------------------------------------------
|
|
226050
|
+
this.beforeRender(renderPassInfo);
|
|
226051
|
+
// Do light, material, etc. updates
|
|
226052
|
+
// ----------------------------------------------------------------------------------
|
|
226053
|
+
this.setRendererSettingsFromScene();
|
|
226054
|
+
this.renderer.updateMaterialUniforms(renderPassInfo.currentPlayerTimeMs, renderPassInfo.resolution);
|
|
226055
|
+
// Check if we have transform controls which we need to hide
|
|
226056
|
+
// ----------------------------------------------------------------------------------
|
|
226057
|
+
let transformControlsWereDisabled = false;
|
|
226058
|
+
if (rootScene.transformControls &&
|
|
226059
|
+
rootScene.transformControls.visible &&
|
|
226060
|
+
(!renderPassInfo.renderOptions.showHelpers || this.renderer.editorOutputOption.outputMode !== OutputMode.EditorCamera)) {
|
|
226061
|
+
transformControlsWereDisabled = true;
|
|
226062
|
+
rootScene.transformControls.visible = false;
|
|
226063
|
+
}
|
|
226064
|
+
// Check if we need to render background and transfer to root scene
|
|
226065
|
+
// ----------------------------------------------------------------------------------
|
|
226066
|
+
rootScene.backgroundBlurriness = primaryScene.backgroundBlurriness;
|
|
226067
|
+
rootScene.backgroundIntensity = primaryScene.backgroundIntensity;
|
|
226068
|
+
if (!renderPassInfo.renderOptions.showBackground) {
|
|
226069
|
+
rootScene.background = null;
|
|
226070
|
+
rootScene.backgroundShader = undefined;
|
|
226071
|
+
}
|
|
226072
|
+
else if (this.renderer.backgroundOverrideColor) {
|
|
226073
|
+
rootScene.background = tools.hexColorToColor(this.renderer.backgroundOverrideColor);
|
|
226074
|
+
rootScene.backgroundShader = undefined;
|
|
226075
|
+
}
|
|
226076
|
+
else {
|
|
226077
|
+
rootScene.background = primaryScene.background;
|
|
226078
|
+
rootScene.backgroundShader = primaryScene.backgroundShader;
|
|
226079
|
+
}
|
|
226080
|
+
// Render any items that need to be rendered first
|
|
226081
|
+
// ----------------------------------------------------------------------------------
|
|
226082
|
+
for (const item of itemInstances) {
|
|
226083
|
+
item.render(rootScene, renderPassInfo);
|
|
226084
|
+
}
|
|
226085
|
+
// Update physics debug geometry
|
|
226086
|
+
// ----------------------------------------------------------------------------------
|
|
226087
|
+
if (doPhysics) {
|
|
226088
|
+
this.engine.profiler.measure("Physics", "renderDebugInfo", () => {
|
|
226089
|
+
this.engine.physics.renderDebugInfo();
|
|
226108
226090
|
});
|
|
226109
226091
|
}
|
|
226110
|
-
|
|
226111
|
-
|
|
226112
|
-
|
|
226113
|
-
|
|
226114
|
-
|
|
226115
|
-
|
|
226116
|
-
|
|
226117
|
-
|
|
226118
|
-
|
|
226119
|
-
|
|
226120
|
-
|
|
226121
|
-
|
|
226122
|
-
|
|
226123
|
-
|
|
226124
|
-
|
|
226125
|
-
|
|
226126
|
-
|
|
226127
|
-
|
|
226128
|
-
|
|
226129
|
-
|
|
226130
|
-
|
|
226131
|
-
|
|
226132
|
-
|
|
226133
|
-
|
|
226134
|
-
|
|
226135
|
-
|
|
226092
|
+
// Render the scene
|
|
226093
|
+
// ----------------------------------------------------------------------------------
|
|
226094
|
+
this._renderScene(renderPassInfo);
|
|
226095
|
+
// Call render hook
|
|
226096
|
+
// ----------------------------------------------------------------------------------
|
|
226097
|
+
if (!renderPassInfo.playerIsPaused && doScripting) {
|
|
226098
|
+
await this.engine.profiler.measureAsync("Scripting", "render", () => {
|
|
226099
|
+
return this.engine.player.render();
|
|
226100
|
+
});
|
|
226101
|
+
}
|
|
226102
|
+
// Create GUI
|
|
226103
|
+
// ----------------------------------------------------------------------------------
|
|
226104
|
+
if (needToRenderGui && doScripting) {
|
|
226105
|
+
if (!renderPassInfo.playerIsPaused) {
|
|
226106
|
+
await this.engine.profiler.measureAsync("Scripting", "renderGui", () => {
|
|
226107
|
+
return this.engine.player.renderGui();
|
|
226108
|
+
});
|
|
226109
|
+
}
|
|
226110
|
+
this.engine.imgui.endFrame();
|
|
226111
|
+
}
|
|
226112
|
+
// Call the after render function to revert all the overrides
|
|
226113
|
+
// ----------------------------------------------------------------------------------
|
|
226114
|
+
this.afterRender(renderPassInfo);
|
|
226115
|
+
// Render the canvas
|
|
226116
|
+
// ----------------------------------------------------------------------------------
|
|
226117
|
+
if (this.canvas)
|
|
226118
|
+
this.canvas.render();
|
|
226119
|
+
// Finish rendering GUI
|
|
226120
|
+
// ----------------------------------------------------------------------------------
|
|
226121
|
+
if (needToRenderGui && doScripting) {
|
|
226122
|
+
this.engine.imgui.render();
|
|
226123
|
+
}
|
|
226124
|
+
this.webGlRenderer.resetState();
|
|
226125
|
+
// Emit framebuffer as event, if queued
|
|
226126
|
+
// ----------------------------------------------------------------------------------
|
|
226127
|
+
if (this.renderer.emitFramebuffer) {
|
|
226128
|
+
const frame = textureTools.grabFramebufferImage(this, renderPassInfo.viewport);
|
|
226129
|
+
this.engine.eventBus.$emit("engine:frameBufferResult", frame);
|
|
226130
|
+
this.renderer.emitFramebuffer = false;
|
|
226131
|
+
}
|
|
226132
|
+
// Restore transform controls
|
|
226133
|
+
// ----------------------------------------------------------------------------------
|
|
226134
|
+
if (transformControlsWereDisabled) {
|
|
226135
|
+
rootScene.transformControls.visible = true;
|
|
226136
|
+
}
|
|
226136
226137
|
}
|
|
226137
226138
|
}
|
|
226138
226139
|
}
|
|
226139
|
-
|
|
226140
|
-
|
|
226141
|
-
|
|
226142
|
-
|
|
226143
|
-
|
|
226144
|
-
|
|
226145
|
-
|
|
226146
|
-
|
|
226147
|
-
|
|
226148
|
-
|
|
226149
|
-
}
|
|
226140
|
+
catch (err) {
|
|
226141
|
+
console.error(err);
|
|
226142
|
+
}
|
|
226143
|
+
finally {
|
|
226144
|
+
// we keep the canvas active for now since async script operations might still access it.
|
|
226145
|
+
// needs to be properly solved later.
|
|
226146
|
+
//this.renderer.setActiveCanvas(null);
|
|
226147
|
+
this.engine.setActiveSceneGraphCollection(undefined);
|
|
226148
|
+
}
|
|
226149
|
+
});
|
|
226150
226150
|
}
|
|
226151
226151
|
_animate(sceneGraphCollection, deltaTimeMs) {
|
|
226152
226152
|
const deltaTimeSecs = deltaTimeMs / 1000;
|
|
@@ -226898,7 +226898,7 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
226898
226898
|
options;
|
|
226899
226899
|
renderView = null;
|
|
226900
226900
|
webGlRenderer;
|
|
226901
|
-
webGpuRenderer;
|
|
226901
|
+
//webGpuRenderer: WebGPURenderer;
|
|
226902
226902
|
raycaster;
|
|
226903
226903
|
renderers = {};
|
|
226904
226904
|
requestFrameFuncs = [];
|
|
@@ -226975,7 +226975,7 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
226975
226975
|
this.layers.push(`Layer ${i + 1}`);
|
|
226976
226976
|
}
|
|
226977
226977
|
this.webGlRenderer = this._createWebGlRenderer(options);
|
|
226978
|
-
this.webGpuRenderer = this._createWebGpuRenderer();
|
|
226978
|
+
//this.webGpuRenderer = this._createWebGpuRenderer();
|
|
226979
226979
|
this.setDevicePixelRatio();
|
|
226980
226980
|
this.setShadowType(ShadowMode.Pcf);
|
|
226981
226981
|
this.setRendererSettings();
|
|
@@ -227065,12 +227065,6 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
227065
227065
|
return webGpuRenderer;
|
|
227066
227066
|
}
|
|
227067
227067
|
async init() {
|
|
227068
|
-
try {
|
|
227069
|
-
await this.webGpuRenderer.init();
|
|
227070
|
-
}
|
|
227071
|
-
catch (err) {
|
|
227072
|
-
console.error("Failed to initialize WebGPU Renderer: ", err);
|
|
227073
|
-
}
|
|
227074
227068
|
try {
|
|
227075
227069
|
await loadFontFace("OpenSansRegular", openSansRegularUrl);
|
|
227076
227070
|
}
|
|
@@ -227082,9 +227076,9 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
227082
227076
|
getWebGLRenderer() {
|
|
227083
227077
|
return this.webGlRenderer;
|
|
227084
227078
|
}
|
|
227085
|
-
getWebGPURenderer() {
|
|
227079
|
+
/*getWebGPURenderer(): WebGPURenderer {
|
|
227086
227080
|
return this.webGpuRenderer;
|
|
227087
|
-
}
|
|
227081
|
+
}*/
|
|
227088
227082
|
hookEvents() {
|
|
227089
227083
|
if (this.renderView) {
|
|
227090
227084
|
// We have to remember the pressed buttons of the pointer controller because we will only ever receive a single
|
|
@@ -229736,6 +229730,11 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
229736
229730
|
const droppedItemIsDescendantOfThis = this.isDescendantOf(sgDroppedItem);
|
|
229737
229731
|
if (!droppedItemIsDescendantOfThis) {
|
|
229738
229732
|
this.engine.moveTreeItemsToNewParent([droppedItem.id], this.getId(), undefined, destinationSubNode);
|
|
229733
|
+
// in case the item is dropped to a subnode, its parenting needs to be updated
|
|
229734
|
+
if (destinationSubNode) {
|
|
229735
|
+
sgDroppedItem.updateParenting();
|
|
229736
|
+
sgDroppedItem.updateBoxHelper();
|
|
229737
|
+
}
|
|
229739
229738
|
return true;
|
|
229740
229739
|
}
|
|
229741
229740
|
}
|
|
@@ -256098,9 +256097,9 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
256098
256097
|
|
|
256099
256098
|
var lua_api_audio = "\nlocal _internal = require('engine/_internal');\n\n--- @module audio\nlocal audio = {}\n\n---Get an FFT analysis from the audio engine. It returns an array of 256 samples\n---@function getAnalysis\nfunction audio.getAnalysis()\n return _internal.sendMessage('audio.getAnalysis')\nend\n\nreturn audio\n";
|
|
256100
256099
|
|
|
256101
|
-
var lua_api_behaviour = "local SceneObject = require('engine/sceneobject')\nlocal Canvas = require('engine/canvas')\nlocal JE = require('engine/json/jsonencoder')()\n\nlocal _behavioursMapByNodeId = {}\nlocal _behavioursMapByScriptId = {}\n\nlocal Behaviour = Class.new()\n\n-- Put the class in the global scope (Behaviour is the old deprecated name)\n_G.Behaviour = Behaviour\n_G.Entity = Behaviour\n\n--- Constructor hook called when a new Behaviour is created.\n---@private\nfunction Behaviour:__new()\n self._isBehaviour = true\n self._type = \"Behaviour\"\n self._nodeId = nil\n self._scriptName = \"\"\n self._isActive = true\n self._isInitialized = false\n\n -- Adds a default node property\n self:addProperty(\"node\", Property.Node)\nend\n\n--- Destructor hook called before the Behaviour is destroyed.\n---@private\nfunction Behaviour:__destroy()\n print(\"__destroy called for: \", self._nodeId)\nend\n\n--- Get all behaviours attached to a specific node ID.\n---@param nodeId string The ID of the scene graph node\n---@return table A table containing all behaviours attached to the node\nfunction Behaviour.getByNodeId(nodeId)\n local result = {}\n local nodeBehaviours = _behavioursMapByNodeId[nodeId]\n if nodeBehaviours then\n for k,v in pairs(nodeBehaviours) do\n table.insert(result, v.behaviour)\n end\n end\n return result\nend\n\n--- Get a single behaviour attached to a node ID with a specific script name.\n---@param nodeId string The ID of the scene graph node\n---@param scriptName string The script name of the behaviour\n---@return Behaviour|nil The behaviour if found, or nil\nfunction Behaviour.getByNodeIdAndScriptName(nodeId, scriptName)\n local nodeEntities = _behavioursMapByNodeId[nodeId]\n if nodeEntities then\n for k,v in pairs(nodeEntities) do\n if v.scriptName == scriptName then\n return v.behaviour\n end\n end\n end\n return nil\nend\n\n--- Returns the node ID this Behaviour is attached to.\n---@return string|nil Node ID of the attached scene object\nfunction Behaviour:getNodeId()\n return self._nodeId\nend\n\n--- Returns the script name of this Behaviour.\n---@return string Script name\nfunction Behaviour:getScriptName()\n return self._scriptName\nend\n\n--- Returns a table of all properties defined on the behaviour class.\n---@return table A table with fields: name, defaultValue, type, order\nfunction Behaviour:getProperties()\n local props = {}\n local class = self.getClass()\n\n for k,v in pairs(class) do\n if type(v) == 'table' and v._isProperty then\n table.insert(props, { name=k, defaultValue=v.value, type=v.datatype, order=v.order, info=v.info })\n end\n end\n\n for k,v in pairs(class.properties) do\n if type(v) == 'table' and v._isProperty then\n table.insert(props, { name=k, defaultValue=v.value, type=v.datatype, order=v.order, info=v.info })\n end\n end\n\n return props\nend\n\n--- When a script is destroyed, we need to call this to clear the behaviour out of the list\n---@private\nfunction Behaviour:_disposeBehaviour()\n local scripts = _behavioursMapByNodeId[self._nodeId]\n if scripts then\n scripts[self._scriptId] = nil\n end\n\n _behavioursMapByScriptId[self._scriptId] = nil\nend\n\n--- Internal setter for a property\n---@private\n---@param name string Property name\n---@param value any Value to set\nfunction Behaviour:_setProperty(name, value)\n self[name] = value\nend\n\n--- Internal method to attach a scene node to this Behaviour\n---@private\n---@param msg table Contains fields: value=nodeId, scriptName, scriptId\nfunction Behaviour:_setNode(msg)\n __assertTrace(type(msg) == 'table', \"_setNode() called with nil or a non-table.\")\n\n if self.node then\n error(\"Node is already set on behaviour!\")\n end\n\n local nodeId = msg.value\n __assertTrace(type(nodeId) == 'string', \"_setNode() needs a nodeId of type string.\")\n\n local node = SceneObject.findById(nodeId)\n __assertTrace(node, \"_setNode() node not found\")\n\n local scriptName = msg.scriptName\n __assertTrace(scriptName, \"_setNode() needs a scriptName\")\n\n local scriptId = msg.scriptId\n __assertTrace(scriptId, \"_setNode() needs a scriptId\")\n\n self.node = node\n self._nodeId = nodeId\n self._scriptName = msg.scriptName\n self._scriptId = scriptId\n\n _behavioursMapByScriptId[scriptId] = self\n\n if not _behavioursMapByNodeId[nodeId] then\n _behavioursMapByNodeId[nodeId] = {}\n end\n _behavioursMapByNodeId[nodeId][scriptId] = {\n node = node,\n scriptName = scriptName,\n behaviour = self\n }\nend\n\n--- Return the properties of this Behaviour as JSON\n---@private\n---@return string JSON string of properties\nfunction Behaviour:_getPropsJson()\n return JE(self:getProperties())\nend\n\n--- Returns the active state of the behaviour. If the owner item is inactive, so are all attached behaviours\n---@return boolean true, if active, othersise false\nfunction Behaviour:isActive()\n return self._isActive\nend\n\n--- Returns the initialized state of the behaviour. If true, init ran through or there is no init\n---@return boolean true, if initialized, othersise false\nfunction Behaviour:isInitialized()\n return self._isInitialized\nend\n\n--- Clears all registered behaviours (used internally). They are expected to be empty anyway due to scripts\n--- cleaning up behind themselves. This function will assert this\n---@private\nfunction Behaviour._clearBehaviours()\n -- Clear in-place to avoid any stale references to the _behaviours table object\n -- preventing Lua GC from reclaiming behaviour instances.\n for nodeId, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n -- nodeBehaviours is a keyed table (scriptId -> { ... })\n if nodeBehaviours and next(nodeBehaviours) ~= nil then\n -- This warning is useful when scripts forget to dispose their behaviours,\n -- but the check previously used `#nodeBehaviours` which is incorrect for keyed tables.\n print(\"WARNING: Some behaviours did not get cleaned properly. This is an engine bug!\")\n -- Keep clearing anyway to enable GC.\n end\n\n if nodeBehaviours then\n for scriptId in pairs(nodeBehaviours) do\n nodeBehaviours[scriptId] = nil\n end\n end\n\n _behavioursMapByNodeId[nodeId] = nil\n end\n\n -- Also clear the second map that has the behaviours by their script ID directly\n _behavioursMapByScriptId = {}\nend\n\nfunction Behaviour:_init()\n if type(self.init) == 'function' then\n local ok, err = pcall(self.init, self)\n if not ok then\n print(self._scriptName .. \":init() failed:\", err)\n end\n end\n self._isInitialized = true\n self._isActive = true\nend\n\nfunction Behaviour:_ondisable()\n self._isActive = false\n if type(self.ondisable) == 'function' then\n local ok, err = pcall(self.ondisable, self)\n if not ok then\n print(self._scriptName .. \":ondisable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_onenable()\n self._isActive = true\n if type(self.onenable) == 'function' then\n local ok, err = pcall(self.onenable, self)\n if not ok then\n print(self._scriptName .. \":onenable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_ondestroy()\n if type(self.ondestroy) == 'function' then\n local ok, err = pcall(self.ondestroy, self)\n if not ok then\n print(self._scriptName .. \":ondestroy() failed:\", err)\n end\n end\n self._isActive = false\n self._isInitialized = false\nend\n\nfunction Behaviour._updateAll(deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n for _, behaviour in pairs(_behavioursMapByScriptId) do\n if behaviour._isActive and behaviour._isInitialized and type(behaviour.update) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(behaviour.update, behaviour, deltaTime, deltaTimeSmooth)\n if not ok then\n print(behaviour._scriptName .. \":update() failed:\", err)\n end\n end\n\n -- call the deprecated prerender hook if it exists\n if behaviour._isActive and behaviour._isInitialized and type(behaviour.prerender) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(behaviour.prerender, behaviour)\n if not ok then\n print(behaviour._scriptName .. \":prerender() failed:\", err)\n end\n end\n end\n\n return callcount\nend\n\nfunction Behaviour._renderAll()\n local callcount = 0\n\n for _, behaviour in pairs(_behavioursMapByScriptId) do\n if behaviour._isActive and behaviour._isInitialized and type(behaviour.render) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(behaviour.render, behaviour, deltaTime, deltaTimeSmooth)\n if not ok then\n print(behaviour._scriptName .. \":render() failed:\", err)\n end\n end\n end\n\n Canvas.commit()\n\n return callcount\nend\n\nfunction Behaviour._renderguiAll()\n local callcount = 0\n\n for _, behaviour in pairs(_behavioursMapByScriptId) do\n if behaviour._isActive and behaviour._isInitialized and type(behaviour.rendergui) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(behaviour.rendergui, behaviour, deltaTime, deltaTimeSmooth)\n if not ok then\n print(behaviour._scriptName .. \":rendergui() failed:\", err)\n end\n end\n end\n\n return callcount\nend\n\nfunction Behaviour._setActive(nodes)\n for scriptId, active in pairs(nodes) do\n local node = _behavioursMapByScriptId[scriptId]\n if node then\n node._isActive = active\n else\n print(\"ERROR: Behaviour._setActive() cannot find script: \" .. scriptId)\n end\n end\nend\n\nfunction Behaviour._debugStats()\n local nodeCount = 0\n local behaviourCount = 0\n for _, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n nodeCount = nodeCount + 1\n if nodeBehaviours then\n for _ in pairs(nodeBehaviours) do\n behaviourCount = behaviourCount + 1\n end\n end\n end\n\n return {\n nodeCount = nodeCount,\n behaviourCount = behaviourCount\n }\nend\n\nreturn Behaviour\n";
|
|
256100
|
+
var lua_api_behaviour = "local SceneObject = require('engine/sceneobject')\nlocal Canvas = require('engine/canvas')\nlocal JE = require('engine/json/jsonencoder')()\n\nlocal _behavioursMapByNodeId = {}\nlocal _behavioursMapByScriptId = {}\nlocal _behavioursMapByExecutionOrder = {}\nlocal _executionIndex = 1\n\nlocal Behaviour = Class.new()\n\n-- Put the class in the global scope (Behaviour is the old deprecated name)\n_G.Behaviour = Behaviour\n_G.Entity = Behaviour\n\n--- Constructor hook called when a new Behaviour is created.\n---@private\nfunction Behaviour:__new()\n self._isBehaviour = true\n self._type = \"Behaviour\"\n self._nodeId = nil\n self._scriptName = \"\"\n self._executionIndex = _executionIndex\n self._isActive = true\n self._isInitialized = false\n\n _executionIndex = _executionIndex + 1\n\n -- Adds a default node property\n self:addProperty(\"node\", Property.Node)\nend\n\n--- Destructor hook called before the Behaviour is destroyed.\n---@private\nfunction Behaviour:__destroy()\n print(\"__destroy called for: \", self._nodeId)\nend\n\n--- Get all behaviours attached to a specific node ID.\n---@param nodeId string The ID of the scene graph node\n---@return table A table containing all behaviours attached to the node\nfunction Behaviour.getByNodeId(nodeId)\n local result = {}\n local nodeBehaviours = _behavioursMapByNodeId[nodeId]\n if nodeBehaviours then\n for k,v in pairs(nodeBehaviours) do\n table.insert(result, v.behaviour)\n end\n end\n return result\nend\n\n--- Get a single behaviour attached to a node ID with a specific script name.\n---@param nodeId string The ID of the scene graph node\n---@param scriptName string The script name of the behaviour\n---@return Behaviour|nil The behaviour if found, or nil\nfunction Behaviour.getByNodeIdAndScriptName(nodeId, scriptName)\n local nodeEntities = _behavioursMapByNodeId[nodeId]\n if nodeEntities then\n for k,v in pairs(nodeEntities) do\n if v.scriptName == scriptName then\n return v.behaviour\n end\n end\n end\n return nil\nend\n\n--- Returns the node ID this Behaviour is attached to.\n---@return string|nil Node ID of the attached scene object\nfunction Behaviour:getNodeId()\n return self._nodeId\nend\n\n--- Returns the script name of this Behaviour.\n---@return string Script name\nfunction Behaviour:getScriptName()\n return self._scriptName\nend\n\n--- Returns a table of all properties defined on the behaviour class.\n---@return table A table with fields: name, defaultValue, type, order\nfunction Behaviour:getProperties()\n local props = {}\n local class = self.getClass()\n\n for k,v in pairs(class) do\n if type(v) == 'table' and v._isProperty then\n table.insert(props, { name=k, defaultValue=v.value, type=v.datatype, order=v.order, info=v.info })\n end\n end\n\n for k,v in pairs(class.properties) do\n if type(v) == 'table' and v._isProperty then\n table.insert(props, { name=k, defaultValue=v.value, type=v.datatype, order=v.order, info=v.info })\n end\n end\n\n return props\nend\n\n--- When a script is destroyed, we need to call this to clear the behaviour out of the list\n---@private\nfunction Behaviour:_disposeBehaviour()\n local scripts = _behavioursMapByNodeId[self._nodeId]\n if scripts then\n scripts[self._scriptId] = nil\n end\n\n _behavioursMapByScriptId[self._scriptId] = nil\n _behavioursMapByExecutionOrder[self._executionIndex] = nil\nend\n\n--- Internal setter for a property\n---@private\n---@param name string Property name\n---@param value any Value to set\nfunction Behaviour:_setProperty(name, value)\n self[name] = value\nend\n\n--- Internal method to attach a scene node to this Behaviour\n---@private\n---@param msg table Contains fields: value=nodeId, scriptName, scriptId\nfunction Behaviour:_setNode(msg)\n __assertTrace(type(msg) == 'table', \"_setNode() called with nil or a non-table.\")\n\n if self.node then\n error(\"Node is already set on behaviour!\")\n end\n\n local nodeId = msg.value\n __assertTrace(type(nodeId) == 'string', \"_setNode() needs a nodeId of type string.\")\n\n local node = SceneObject.findById(nodeId)\n __assertTrace(node, \"_setNode() node not found\")\n\n local scriptName = msg.scriptName\n __assertTrace(scriptName, \"_setNode() needs a scriptName\")\n\n local scriptId = msg.scriptId\n __assertTrace(scriptId, \"_setNode() needs a scriptId\")\n\n self.node = node\n self._nodeId = nodeId\n self._scriptName = msg.scriptName\n self._scriptId = scriptId\n\n _behavioursMapByScriptId[scriptId] = self\n _behavioursMapByExecutionOrder[self._executionIndex] = self\n\n if not _behavioursMapByNodeId[nodeId] then\n _behavioursMapByNodeId[nodeId] = {}\n end\n _behavioursMapByNodeId[nodeId][scriptId] = {\n node = node,\n scriptName = scriptName,\n behaviour = self\n }\nend\n\n--- Return the properties of this Behaviour as JSON\n---@private\n---@return string JSON string of properties\nfunction Behaviour:_getPropsJson()\n return JE(self:getProperties())\nend\n\n--- Returns the active state of the behaviour. If the owner item is inactive, so are all attached behaviours\n---@return boolean true, if active, othersise false\nfunction Behaviour:isActive()\n return self._isActive\nend\n\n--- Returns the initialized state of the behaviour. If true, init ran through or there is no init\n---@return boolean true, if initialized, othersise false\nfunction Behaviour:isInitialized()\n return self._isInitialized\nend\n\n--- Clears all registered behaviours (used internally). They are expected to be empty anyway due to scripts\n--- cleaning up behind themselves. This function will assert this\n---@private\nfunction Behaviour._clearBehaviours()\n -- Clear in-place to avoid any stale references to the _behaviours table object\n -- preventing Lua GC from reclaiming behaviour instances.\n for nodeId, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n -- nodeBehaviours is a keyed table (scriptId -> { ... })\n if nodeBehaviours and next(nodeBehaviours) ~= nil then\n -- This warning is useful when scripts forget to dispose their behaviours,\n -- but the check previously used `#nodeBehaviours` which is incorrect for keyed tables.\n print(\"WARNING: Some behaviours did not get cleaned properly. This is an engine bug!\")\n -- Keep clearing anyway to enable GC.\n end\n\n if nodeBehaviours then\n for scriptId in pairs(nodeBehaviours) do\n nodeBehaviours[scriptId] = nil\n end\n end\n\n _behavioursMapByNodeId[nodeId] = nil\n end\n\n -- Also clear the second map that has the behaviours by their script ID directly and the execution order map\n _behavioursMapByScriptId = {}\n _behavioursMapByExecutionOrder = {}\n _executionIndex = 1\nend\n\nfunction Behaviour:_init()\n if type(self.init) == 'function' then\n local ok, err = pcall(self.init, self)\n if not ok then\n print(self._scriptName .. \":init() failed:\", err)\n end\n end\n self._isInitialized = true\n self._isActive = true\nend\n\nfunction Behaviour:_ondisable()\n self._isActive = false\n if type(self.ondisable) == 'function' then\n local ok, err = pcall(self.ondisable, self)\n if not ok then\n print(self._scriptName .. \":ondisable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_onenable()\n self._isActive = true\n if type(self.onenable) == 'function' then\n local ok, err = pcall(self.onenable, self)\n if not ok then\n print(self._scriptName .. \":onenable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_ondestroy()\n if type(self.ondestroy) == 'function' then\n local ok, err = pcall(self.ondestroy, self)\n if not ok then\n print(self._scriptName .. \":ondestroy() failed:\", err)\n end\n end\n self._isActive = false\n self._isInitialized = false\nend\n\nfunction Behaviour._callHookOnAll(hookName, deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n for _, behaviour in pairs(_behavioursMapByExecutionOrder) do\n local hookFunc = behaviour[hookName]\n if behaviour._isActive and behaviour._isInitialized and type(hookFunc) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(hookFunc, behaviour, deltaTime, deltaTimeSmooth)\n if not ok then\n print(behaviour._scriptName .. \":\" .. hookName .. \"() failed:\", err)\n end\n end\n end\n\n return callcount\nend\n\nfunction Behaviour._updateAll(deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n callcount = callcount + Behaviour._callHookOnAll(\"preUpdate\", deltaTime, deltaTimeSmooth)\n callcount = callcount + Behaviour._callHookOnAll(\"update\", deltaTime, deltaTimeSmooth)\n callcount = callcount + Behaviour._callHookOnAll(\"lateUpdate\", deltaTime, deltaTimeSmooth)\n\n return callcount\nend\n\nfunction Behaviour._renderAll()\n\n if Canvas.autoClear then\n Canvas.clear()\n end\n\n local callcount = 0\n\n callcount = Behaviour._callHookOnAll(\"prerender\")\n callcount = Behaviour._callHookOnAll(\"render\")\n\n Canvas.commit()\n\n return callcount\nend\n\nfunction Behaviour._renderguiAll()\n return Behaviour._callHookOnAll(\"rendergui\")\nend\n\nfunction Behaviour._setActive(nodes)\n for scriptId, active in pairs(nodes) do\n local behaviour = _behavioursMapByScriptId[scriptId]\n if behaviour then\n behaviour._isActive = active\n else\n print(\"ERROR: Behaviour._setActive() cannot find script: \" .. scriptId)\n end\n end\nend\n\nfunction Behaviour._debugStats()\n local nodeCount = 0\n local behaviourCount = 0\n for _, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n nodeCount = nodeCount + 1\n if nodeBehaviours then\n for _ in pairs(nodeBehaviours) do\n behaviourCount = behaviourCount + 1\n end\n end\n end\n\n return {\n nodeCount = nodeCount,\n behaviourCount = behaviourCount\n }\nend\n\nreturn Behaviour\n";
|
|
256102
256101
|
|
|
256103
|
-
var lua_api_canvas = "\nlocal _internal = require('engine/_internal');\n\n---@module canvas\nlocal canvas = {}\n\n-- Lua-side command buffer for canvas calls.\nlocal _cmds = {}\n\nlocal function _captureSendMessage(target, payload, buffers)\n table.insert(_cmds, {\n target = target,\n payload = payload,\n buffers = buffers\n })\n return nil\nend\n\nlocal function _runWithCapturedSend(fn, ...)\n local oldSendMessage = _internal.sendMessage\n _internal.sendMessage = _captureSendMessage\n\n local result = { pcall(fn, ...) }\n\n _internal.sendMessage = oldSendMessage\n\n if not result[1] then\n error(result[2])\n end\n\n return table.unpack(result, 2)\nend\n\nlocal function _commitIfNeeded()\n if #_cmds == 0 then\n return { committed = 0 }\n end\n\n local result = _internal.sendMessage('canvas.commit', { cmds = _cmds })\n _cmds = {}\n return result\nend\n\n---Commit all pending buffered canvas commands.\n---@return table|nil result Optional engine-side debug info.\nfunction canvas.commit()\n return _commitIfNeeded()\nend\n\n---Debug helper: returns count of pending buffered commands in Lua.\n---@return number\nfunction canvas.getPendingCommandCount()\n return #_cmds\nend\n\n---Debug helper: returns current pending buffered commands in Lua.\n---@return table\nfunction canvas.getPendingCommands()\n return _cmds\nend\n\n---Debug helper: returns most recently committed command list on engine side.\n---@return table\nfunction canvas.getLastCommittedCommands()\n _commitIfNeeded()\n return _internal.sendMessage('canvas.getLastCommittedCommands')\nend\n\n---Clear the canvas.\n---@function\nfunction canvas.clear()\n _internal.sendMessage('canvas.clear')\nend\n\n---Returns the width of the canvas in pixels.\n---@function\nfunction canvas.getWidth()\n return _internal.sendMessage('canvas.getWidth')\nend\n\n---Returns the height of the canvas in pixels.\n---@function\nfunction canvas.getHeight()\n return _internal.sendMessage('canvas.getHeight')\nend\n\n---Sets the width of lines in the canvas.\n---@param w number the width to set the lines to.\nfunction canvas.setLineWidth(w)\n _internal.sendMessage('canvas.setLineWidth', { w=w })\nend\n\n---Sets the type of endings applied to the ends of a line.\n---@param cap string the type of corner to create on a line. One of \"butt\", \"round\", \"square\".\nfunction canvas.setLineCap(cap)\n _internal.sendMessage('canvas.setLineCap', { cap=cap })\nend\n\n---Sets the type of corner created when two lines meet.\n---@param join string the type of connection to create between two lines. One of \"bevel\", \"round\", or \"miter\".\nfunction canvas.setLineJoin(join)\n _internal.sendMessage('canvas.setLineJoin', { join=join })\nend\n\n---Sets the maximum miter length. Miter length is the distance between the inner corner and the outer corner of the join.\n---@param limit number the maximum miter length. When the miter length exceeds this value, the corner is trimmed.\nfunction canvas.setMiterLimit(limit)\n _internal.sendMessage('canvas.setMiterLimit', { limit=limit })\nend\n\n---Sets the color of the stroke (outline) for shapes drawn on the canvas.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setStrokeColor(r, g, b, a)\n _internal.sendMessage('canvas.setStrokeColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the color that is used to fill in shapes and text when they are drawn on the canvas.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setFillColor(r, g, b, a)\n _internal.sendMessage('canvas.setFillColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the color to use for shadows.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setShadowColor(r, g, b, a)\n _internal.sendMessage('canvas.setShadowColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the blur level for shadows.\n---@param level number the level of blur to be applied to shadows (in pixels).\nfunction canvas.setShadowBlurLevel(level)\n _internal.sendMessage('canvas.setShadowBlurLevel', { level=level })\nend\n\n---Sets the blur level for shadows.\n---@param x number the vertical offset of the shadow in pixels.\n---@param y number the horizontal offset of the shadow in pixels.\nfunction canvas.setShadowOffset(x, y)\n _internal.sendMessage('canvas.setShadowOffset', { x=x, y=y })\nend\n\n---Begins a new path.\n---@function\nfunction canvas.beginPath()\n _internal.sendMessage('canvas.beginPath')\nend\n\n---Close the current path by connecting the last and first point in the path, creating a loop.\n---@function\nfunction canvas.closePath()\n _internal.sendMessage('canvas.closePath')\nend\n\n---Determines if the specified point is in the current path.\n---@param x number x-coordinate of the point to check.\n---@param y number y-coordinate of the point to check.\n---@return boolean indicating if the point is in the path or not.\nfunction canvas.isPointInPath(x, y)\n return _internal.sendMessage('canvas.isPointInPath', { x=x, y=y })\nend\n\n---Sets the clipping path to the current drawing path.\n---@function\nfunction canvas.clip()\n _internal.sendMessage('canvas.clip')\nend\n\n---Draws the outline of a shape or path using the current stroke style, line width and styles.\n---@function\nfunction canvas.stroke()\n _internal.sendMessage('canvas.stroke')\nend\n\n---Fills a shape or path with the current fill style.\n---@function\nfunction canvas.fill()\n _internal.sendMessage('canvas.fill')\nend\n\n---Moves the current drawing position to the specified coordinates.\n---@param x number x-coordinate of the new current drawing position.\n---@param y number y-coordinate of the new current drawing position.\nfunction canvas.moveTo(x, y)\n _internal.sendMessage('canvas.moveTo', { x=x, y=y })\nend\n\n---Draws a straight line from the current position to the specified coordinates.\n---@param x number the x-coordinate to draw the line to.\n---@param y number the y-coordinate to draw the line to.\nfunction canvas.lineTo(x, y)\n _internal.sendMessage('canvas.lineTo', { x=x, y=y })\nend\n\n---Sets the type of compositing operation to apply when drawing new shapes.\n---@param operation string the compositing operation to use, possible values are:\n---\"source-over\", \"source-in\", \"source-out\", \"source-atop\", \"destination-over\",\n---\"destination-in\", \"destination-out\", \"destination-atop\", \"lighter\", \"copy\", \"xor\".\nfunction canvas.setCompositeOperation(operation)\n _internal.sendMessage('canvas.setCompositeOperation', { operation=operation })\nend\n\n---Sets the transparency value that is applied to all rendering operations.\n---@param value number a value between 0.0 (fully transparent) and 1.0 (fully opaque).\nfunction canvas.setGlobalAlpha(value)\n _internal.sendMessage('canvas.setGlobalAlpha', { value=value })\nend\n\n---Creates a rectangle path which is only drawn after calling stroke() or fill().\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.pathRect(x, y, w, h)\n _internal.sendMessage('canvas.pathRect', { x=x, y=y, w=w, h=h })\nend\n\n---Adds a rounded rectangle to the current path. Must be followed by stroke() or fill().\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\n---@param radius number|table corner radius applied to all four corners (uniform), or a table\n---of 1–4 values to set individual corner radius in the order [top-left, top-right,\n---bottom-right, bottom-left], following the HTML Canvas API specification.\nfunction canvas.roundRect(x, y, w, h, radius)\n _internal.sendMessage('canvas.roundRect', { x=x, y=y, w=w, h=h, radius=radius })\nend\n\n---Draw a rectangle outline using the current stroke style.\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.strokeRect(x, y, w, h)\n _internal.sendMessage('canvas.strokeRect', { x=x, y=y, w=w, h=h })\nend\n\n---Draw a rectangle with a filled interior using the current fill style,\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.fillRect(x, y, w, h)\n _internal.sendMessage('canvas.fillRect', { x=x, y=y, w=w, h=h })\nend\n\n---Clears the specified rectangle by setting its pixels to transparent.\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.clearRect(x, y, w, h)\n _internal.sendMessage('canvas.clearRect', { x=x, y=y, w=w, h=h })\nend\n\n---Draws a circle with given parameters. Must be followed by stroke() or fill().\n---@param x number x-coordinates of the center of the circle.\n---@param y number y-coordinates of the center of the circle.\n---@param r number the radius of the circle\nfunction canvas.circle(x, y, r)\n _internal.sendMessage('canvas.circle', { x=x, y=y, r=r })\nend\n\n---Draws an arc with given parameters. Must be followed by stroke() or fill().\n---@param x number x-coordinates of the center of the circle.\n---@param y number y-coordinates of the center of the circle.\n---@param r number the radius of the circle.\n---@param startAngle number the starting angle in radians.\n---@param endAngle number the ending angle, in radians.\n---@param anticlockwise boolean a flag which specifies whether the drawing should be counterclockwise or clockwise.\nfunction canvas.arc(x, y, r, startAngle, endAngle, anticlockwise)\n _internal.sendMessage('canvas.arc', { x=x, y=y, r=r, startAngle=startAngle,\n endAngle=endAngle, anticlockwise=anticlockwise })\nend\n\n---Adds a quadratic Bézier curve to the path with given control point and end point.\n---@param cpx number x-coordinate of the control point.\n---@param cpy number y-coordinate of the control point.\n---@param x number x-coordinate of the end point.\n---@param y number y-coordinate of the end point.\nfunction canvas.quadraticCurve(cpx, cpy, x, y)\n _internal.sendMessage('canvas.quadraticCurve', { cpx=cpx, cpy=cpy, x=x, y=y })\nend\n\n---Draws a bezier curve from the current position to the specified point, using the specified control points.\n---@param cp1x number x-coordinate of the first control point.\n---@param cp1y number y-coordinate of the first control point.\n---@param cp2x number x-coordinate of the second control point.\n---@param cp2y number y-coordinate of the second control point.\n---@param x number x-coordinate of the end point.\n---@param y number y-coordinate of the end point.\nfunction canvas.bezierCurve(cp1x, cp1y, cp2x, cp2y, x, y)\n _internal.sendMessage('canvas.bezierCurve', { cp1x=cp1x, cp1y=cp1y,\n cp2x=cp2x, cp2y=cp2y,\n x=x, y=y })\nend\n\n---@class Gradient\n---A class to internally link gradient objects from the Lua environment to Lumino codebase.\n---A Gradient object can be create using @{createLinearGradient} or @{createRadialGradient}\n---@private\nlocal Gradient = {}\n\n---Creates a new gradient object with the given index\n---@param idx number index of the gradient object\n---@private\nfunction Gradient:new(idx)\n -- Store the gradient object in a field of the class instance metatable\n local obj = { idx = idx}\n Class.__setmetatable(obj, self)\n self.__index = self\n -- Return the instance\n return obj\nend\n\n---Hook that runs before an object is deleted by the garbage collector.\n---It calls a function to delete the gradient object in JS\n---@private\nfunction Gradient:__gc()\n -- Keep deletion ordering deterministic when gradient operations are buffered.\n _commitIfNeeded()\n _internal.sendMessage('canvas.deleteGradient', { gradientIdx = self.idx })\nend\n-- Add the Gradient class to the Canvas namespace\ncanvas.Gradient = Gradient\n\n---Sets a gradient object to active.\n---@param gradient Gradient a gradient object\nfunction canvas.setGradientActive(gradient)\n if gradient.idx >= 0 then\n _internal.sendMessage('canvas.setGradientActive', { gradientIdx = gradient.idx })\n end\nend\n\n---Adds a new stop, defined by an offset and a color, to a gradient object.\n---@param gradient Gradient a gradient object\n---@param offset number a value between 0.0 and 1.0 where the new color stop is positioned.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.colorStop(gradient, offset, r, g, b, a)\n _internal.sendMessage('canvas.colorStop', { gradientIdx=gradient.idx, offset=offset, r=r, g=g, b=b, a=a })\nend\n\n---Creates a linear gradient object.\n---@param x1 number the x-coordinate of the start point of the gradient\n---@param y1 number the y-coordinate of the start point of the gradient\n---@param x2 number the x-coordinate of the end point of the gradient\n---@param y2 number the y-coordinate of the end point of the gradient\n---@return Gradient a new gradient object\n---@usage local gradient = Canvas.createLinearGradient(0, 0, 50, 0)\nfunction canvas.createLinearGradient(x1, y1, x2, y2)\n local idx = _internal.sendMessage('canvas.createLinearGradient', { x1=x1, y1=y1,\n x2=x2, y2=y2 })\n local gradient = Gradient:new(idx)\n return gradient\nend\n\n---Creates a radial gradient object.\n---@param x1 number x-coordinate of the start circle\n---@param y1 number y-coordinate of the start circle\n---@param r1 number radius of the start circle\n---@param x2 number x-coordinate of the end circle\n---@param y2 number y-coordinate of the end circle\n---@param r2 number radius of the end circle\n---@return Gradient a new gradient object\nfunction canvas.createRadialGradient(x1, y1, r1, x2, y2, r2)\n local idx = _internal.sendMessage('canvas.createRadialGradient', { x1=x1, y1=y1, r1=r1,\n x2=x2, y2=y2, r2=r2})\n local gradient = Gradient:new(idx)\n return gradient\nend\n\n---Returns an array with strings of all available fonts. This will list all custom loaded fonts through Loader.loadFont and\n---fonts registered in Canvas Fonts in your project. It will also probe for common system fonts although the list might not be complete.\n---It is strongly recommended to use only custom uploaded fonts to have reliable results on all platforms.\n---@return table an array with all the available fonts as strings\nfunction canvas.getAvailableFonts()\n return _internal.sendMessage('canvas.getAvailableFonts')\nend\n\n---Sets a font style.\n---@param font string The font style to be set, in the format of 'font-style font-size font-family'. Example: 'italic 20px Arial'.\nfunction canvas.setFont(font)\n _internal.sendMessage('canvas.setFont', { font=font })\nend\n\n---Sets the current text alignment\n---@param align string The new text alignment to be set. One of 'start', 'end', 'left', 'right', or 'center'.\nfunction canvas.setTextAlign(align)\n _internal.sendMessage('canvas.setTextAlign', { align=align })\nend\n\n---Sets the text baseline used when drawing text.\n---@param baseline string The text baseline to set. One of 'alphabetic', 'top', 'hanging', 'middle', 'ideographic', or 'bottom'.\nfunction canvas.setTextBaseline(baseline)\n _internal.sendMessage('canvas.setTextBaseline', { baseline=baseline })\nend\n\n---Measures the width of the specified text in pixels.\n---@param text string The text to measure.\nfunction canvas.measureTextWidth(text)\n return _internal.sendMessage('canvas.measureTextWidth', { text=text })\nend\n\n---Draws and fills a given text string at the specified coordinates.\n---@param text string The text string to be drawn and filled.\n---@param x number The x-coordinate where the text will be drawn.\n---@param y number The y-coordinate where the text will be drawn.\nfunction canvas.fillText(text, x, y)\n _internal.sendMessage('canvas.fillText', { text=text, x=x, y=y })\nend\n\n---Draws the outline of the given text at the specified coordinates.\n---@param text string The text string to be drawn.\n---@param x number The x-coordinate where the text will be drawn.\n---@param y number The y-coordinate where the text will be drawn.\nfunction canvas.strokeText(text, x, y)\n _internal.sendMessage('canvas.strokeText', { text=text, x=x, y=y })\nend\n\n-- -TODO: ImageData is not yet ready for deployment because using it for pixel manipulation would be\n-- -inefficient and slow due to the need for JSON communication with JavaScript. While JSON\n-- -communication is necessary for the security of the application, it is not well-suited for tasks\n-- -that require frequent or high-volume data transfer. It is better to use ImageData for low\n-- -frequency tasks such as updating UI and handling events, rather than trying to use it for more\n-- -demanding tasks that may be slowed down by the use of JSON objects.\n\n-- --- Image class to link imageData objects in the canvas to Lua\n-- ---@class imageData\n-- local Image = {}\n\n-- --- Creates a new Image object with the given index\n-- ---@param idx number index of the imageData object in the canvas\n-- function Image:new(idx)\n-- local obj = {}\n-- Class.__setmetatable(obj, self)\n-- self.__index = self\n-- self.idx = idx\n-- return obj\n-- end\n-- canvas.Image = Image\n\n-- ---Creates a new, blank Image object with the specified dimensions.\n-- ---All of the pixels in the new object are transparent black.\n-- ---@param width number the width of the Image object\n-- ---@param height number the height of the Image object\n-- ---@return Image a new Image object\n-- function canvas.createImage(width, height)\n-- local idx = _internal.sendMessage('canvas.createImage', { width=width, height=height })\n-- local image = Image:new(idx)\n-- return image\n-- end\n\n-- ---Write the RGBA channels of an Image object\n-- ---@param r number the r channel of the Image object\n-- ---@param g number the g channel of the Image object\n-- ---@param b number the b channel of the Image object\n-- ---@param a number the a channel of the Image object\n-- function canvas.writeImageChannels(image, r, g, b, a)\n-- _internal.sendMessage('canvas.writeImageChannels', { imageIdx=image.idx, r=r, g=g, b=b, a=a })\n-- end\n\n-- ---Draws an image given by an url at the specified position and dimensions.\n-- ---@param url string\n-- ---@param x number\n-- ---@param y number\n-- ---@param width number\n-- ---@param height number\n-- function canvas.drawImageFromUrl(url, x, y, width, height)\n-- _internal.sendMessage('canvas.drawImageFromUrl', { url=url, x=x, y=y, width=width, height=height })\n-- end\n\n-- ---Repeats a given image on the canvas with a given pattern.\n-- ---@param image imageSource an image object\n-- ---@param repeat string one of repeat, repeat-x, repeat-y, no-repeat\n-- function canvas.imagePattern(image, repeatPattern)\n-- _internal.sendMessage('canvas.pattern', { image=image, repeatPattern=repeatPattern })\n-- end\n\n---Draws the image data at the given coordinates.\n---@param image Texture the image data to paint\n---@param x number x-coordinate of the top left corner where the image data will be painted\n---@param y number y-coordinate of the top left corner where the image data will be painted\n---@param width number width of the image on screen (optional)\n---@param height number height of the image on screen (optional)\n---@param mode number mode to use for stretching. possible values are 0 = stretch, 1 = fit, 2 = cover\nfunction canvas.drawImage(image, x, y, width, height, mode)\n __assertTrace(image and image._isTexture, \"image is not a Texture object\")\n _internal.sendMessage('canvas.drawImage', { image= image._handle, x=x, y=y, width=width, height=height, mode=mode })\nend\n\n---Draws the image data at the given coordinates.\n---@param image Texture the image data to paint\n---@param x number x-coordinate of the top left corner where the image data will be painted\n---@param y number y-coordinate of the top left corner where the image data will be painted\n---@param width number width of the image on screen (optional)\n---@param height number height of the image on screen (optional)\nfunction canvas.drawSubImage(image, x, y, width, height, sourceX, sourceY, sourceWidth, sourceHeight)\n __assertTrace(image and image._isTexture, \"image is not a Texture object\")\n _internal.sendMessage('canvas.drawSubImage', { image= image._handle,\n x=x, y=y, width=width, height=height,\n sourceX=sourceX, sourceY=sourceY, sourceWidth=sourceWidth, sourceHeight=sourceHeight })\nend\n\n--- Scales the canvas by the specified factors along the x and y axes.\n--- Transformations are applied relative to the canvas origin (0,0).\n--- To scale around a different point, use `translate()` to move the origin before scaling.\n---@param x number Scale factor along the x-axis.\n---@param y number Scale factor along the y-axis.\nfunction canvas.scale(x, y)\n _internal.sendMessage('canvas.scale', { x=x, y=y })\nend\n\n--- Rotates the canvas by the specified angle in radians.\n--- Rotation is performed around the canvas origin (0,0).\n--- To rotate around a different point, translate the canvas to that point before calling rotate().\n---@param a number Angle in radians.\nfunction canvas.rotate(a)\n _internal.sendMessage('canvas.rotate', { a=a })\nend\n\n\n--- Moves (translates) the canvas origin by the specified amounts.\n--- All subsequent drawing and transformations (scale, rotate, etc.) are relative to the new origin.\n---@param x number Amount to translate along the x-axis.\n---@param y number Amount to translate along the y-axis.\nfunction canvas.translate(x, y)\n _internal.sendMessage('canvas.translate', { x=x, y=y })\nend\n\n---Applies a 2D transformation matrix to the canvas.\n---@param horizontal_scale number The amount to scale horizontally.\n---@param horizontal_skew number The amount of horizontal skew.\n---@param vertical_skew number The amount of vertical skew.\n---@param vertical_scale number The amount to scale vertically.\n---@param horizontal_translation number The amount of horizontal translation.\n---@param vertical_translation number The amount of vertical translation.\nfunction canvas.transform(horizontal_scale, horizontal_skew, vertical_skew,\n vertical_scale, horizontal_translation, vertical_translation)\n _internal.sendMessage('canvas.transform', { a=horizontal_scale, b=horizontal_skew,\n c=vertical_skew, d=vertical_scale,\n e=horizontal_translation, f=vertical_translation })\nend\n\n---Resets the current canvas transform to the identity matrix and then invokes the transform() function with the given parameters.\n---@param horizontal_scale number The amount to scale horizontally.\n---@param horizontal_skew number The amount of horizontal skew.\n---@param vertical_skew number The amount of vertical skew.\n---@param vertical_scale number The amount to scale vertically.\n---@param horizontal_translation number The amount of horizontal translation.\n---@param vertical_translation number The amount of vertical translation.\nfunction canvas.resetAndSetTransform(horizontal_scale, horizontal_skew, vertical_skew,\n vertical_scale, horizontal_translation, vertical_translation)\n _internal.sendMessage('canvas.resetAndSetTransform', { a=horizontal_scale, b=horizontal_skew,\n c=vertical_skew, d=vertical_scale,\n e=horizontal_translation, f=vertical_translation })\nend\n\n---Reset the transformation matrix to the identity matrix.\n---@function\nfunction canvas.resetTransform()\n _internal.sendMessage('canvas.resetTransform')\nend\n\n---Pushes the current canvas state to a stack so that you can restore it.\n---This can be useful for performing multiple transformations or styles on the canvas, and\n---then restoring it to its original state. The canvas state in fact includes current transformation matrix\n---stroke and fill styles, shadow styles, and other attributes. To restore the canvas state you call\n---the restoreState() function.\n---@function\nfunction canvas.saveState()\n _internal.sendMessage('canvas.saveState')\nend\n\n---Pops the the most recently saved canvas from the saved state stack and restores it.\n---@function\nfunction canvas.restoreState()\n _internal.sendMessage('canvas.restoreState')\nend\n\n--- Resets the canvas to its default state, clearing the canvas and restoring all\n--- context -properties (transforms, styles, clipping region, etc.) to their\n--- defaults. Reset() is more thorough than -calling clear() alone, which only\n--- erases pixels but leaves context state intact.\n---@function\nfunction canvas.reset()\n _internal.sendMessage('canvas.reset')\nend\n\n-- Automatically wrap canvas methods for buffering, so non-query calls are queued\n-- and query/result-producing calls force an immediate commit first.\nlocal _passthroughMethods = {\n commit = true,\n getPendingCommandCount = true,\n getPendingCommands = true,\n}\n\nlocal _immediateMethods = {\n getLastCommittedCommands = true,\n getWidth = true,\n getHeight = true,\n isPointInPath = true,\n createLinearGradient = true,\n createRadialGradient = true,\n getAvailableFonts = true,\n measureTextWidth = true,\n}\n\nfor name, fn in pairs(canvas) do\n if type(fn) == \"function\" and name ~= \"Gradient\" then\n if _passthroughMethods[name] then\n -- keep as-is\n elseif _immediateMethods[name] then\n canvas[name] = function(...)\n _commitIfNeeded()\n return fn(...)\n end\n else\n canvas[name] = function(...)\n return _runWithCapturedSend(fn, ...)\n end\n end\n end\nend\n\nreturn canvas\n";
|
|
256102
|
+
var lua_api_canvas = "\nlocal _internal = require('engine/_internal');\n\n---@module canvas\nlocal canvas = {\n autoClear = false\n}\n\n-- Lua-side command buffer for canvas calls.\nlocal _cmds = {}\n\nlocal function _captureSendMessage(target, payload, buffers)\n table.insert(_cmds, {\n target = target,\n payload = payload,\n buffers = buffers\n })\n return nil\nend\n\nlocal function _runWithCapturedSend(fn, ...)\n local oldSendMessage = _internal.sendMessage\n _internal.sendMessage = _captureSendMessage\n\n local result = { pcall(fn, ...) }\n\n _internal.sendMessage = oldSendMessage\n\n if not result[1] then\n error(result[2])\n end\n\n return table.unpack(result, 2)\nend\n\nlocal function _commitIfNeeded()\n if #_cmds == 0 then\n return { committed = 0 }\n end\n\n local result = _internal.sendMessage('canvas.commit', { cmds = _cmds })\n _cmds = {}\n return result\nend\n\n---If set to true, the canvas will automatically clear once before the render hook is called\n---@param value boolean the flag value\nfunction canvas.setAutoClear(value)\n self.autoClear = value\nend\n\n---Returns the value of the auto clear flag\n---@return boolean the flag value\nfunction canvas.getAutoClear()\n return self.autoClear\nend\n\n---Commit all pending buffered canvas commands.\n---@return table|nil result Optional engine-side debug info.\nfunction canvas.commit()\n return _commitIfNeeded()\nend\n\n---Debug helper: returns count of pending buffered commands in Lua.\n---@return number\nfunction canvas.getPendingCommandCount()\n return #_cmds\nend\n\n---Debug helper: returns current pending buffered commands in Lua.\n---@return table\nfunction canvas.getPendingCommands()\n return _cmds\nend\n\n---Debug helper: returns most recently committed command list on engine side.\n---@return table\nfunction canvas.getLastCommittedCommands()\n _commitIfNeeded()\n return _internal.sendMessage('canvas.getLastCommittedCommands')\nend\n\n---Clear the canvas.\n---@function\nfunction canvas.clear()\n _internal.sendMessage('canvas.clear')\nend\n\n---Returns the width of the canvas in pixels.\n---@function\nfunction canvas.getWidth()\n return _internal.sendMessage('canvas.getWidth')\nend\n\n---Returns the height of the canvas in pixels.\n---@function\nfunction canvas.getHeight()\n return _internal.sendMessage('canvas.getHeight')\nend\n\n---Sets the width of lines in the canvas.\n---@param w number the width to set the lines to.\nfunction canvas.setLineWidth(w)\n _internal.sendMessage('canvas.setLineWidth', { w=w })\nend\n\n---Sets the type of endings applied to the ends of a line.\n---@param cap string the type of corner to create on a line. One of \"butt\", \"round\", \"square\".\nfunction canvas.setLineCap(cap)\n _internal.sendMessage('canvas.setLineCap', { cap=cap })\nend\n\n---Sets the type of corner created when two lines meet.\n---@param join string the type of connection to create between two lines. One of \"bevel\", \"round\", or \"miter\".\nfunction canvas.setLineJoin(join)\n _internal.sendMessage('canvas.setLineJoin', { join=join })\nend\n\n---Sets the maximum miter length. Miter length is the distance between the inner corner and the outer corner of the join.\n---@param limit number the maximum miter length. When the miter length exceeds this value, the corner is trimmed.\nfunction canvas.setMiterLimit(limit)\n _internal.sendMessage('canvas.setMiterLimit', { limit=limit })\nend\n\n---Sets the color of the stroke (outline) for shapes drawn on the canvas.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setStrokeColor(r, g, b, a)\n _internal.sendMessage('canvas.setStrokeColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the color that is used to fill in shapes and text when they are drawn on the canvas.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setFillColor(r, g, b, a)\n _internal.sendMessage('canvas.setFillColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the color to use for shadows.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setShadowColor(r, g, b, a)\n _internal.sendMessage('canvas.setShadowColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the blur level for shadows.\n---@param level number the level of blur to be applied to shadows (in pixels).\nfunction canvas.setShadowBlurLevel(level)\n _internal.sendMessage('canvas.setShadowBlurLevel', { level=level })\nend\n\n---Sets the blur level for shadows.\n---@param x number the vertical offset of the shadow in pixels.\n---@param y number the horizontal offset of the shadow in pixels.\nfunction canvas.setShadowOffset(x, y)\n _internal.sendMessage('canvas.setShadowOffset', { x=x, y=y })\nend\n\n---Begins a new path.\n---@function\nfunction canvas.beginPath()\n _internal.sendMessage('canvas.beginPath')\nend\n\n---Close the current path by connecting the last and first point in the path, creating a loop.\n---@function\nfunction canvas.closePath()\n _internal.sendMessage('canvas.closePath')\nend\n\n---Determines if the specified point is in the current path.\n---@param x number x-coordinate of the point to check.\n---@param y number y-coordinate of the point to check.\n---@return boolean indicating if the point is in the path or not.\nfunction canvas.isPointInPath(x, y)\n return _internal.sendMessage('canvas.isPointInPath', { x=x, y=y })\nend\n\n---Sets the clipping path to the current drawing path.\n---@function\nfunction canvas.clip()\n _internal.sendMessage('canvas.clip')\nend\n\n---Draws the outline of a shape or path using the current stroke style, line width and styles.\n---@function\nfunction canvas.stroke()\n _internal.sendMessage('canvas.stroke')\nend\n\n---Fills a shape or path with the current fill style.\n---@function\nfunction canvas.fill()\n _internal.sendMessage('canvas.fill')\nend\n\n---Moves the current drawing position to the specified coordinates.\n---@param x number x-coordinate of the new current drawing position.\n---@param y number y-coordinate of the new current drawing position.\nfunction canvas.moveTo(x, y)\n _internal.sendMessage('canvas.moveTo', { x=x, y=y })\nend\n\n---Draws a straight line from the current position to the specified coordinates.\n---@param x number the x-coordinate to draw the line to.\n---@param y number the y-coordinate to draw the line to.\nfunction canvas.lineTo(x, y)\n _internal.sendMessage('canvas.lineTo', { x=x, y=y })\nend\n\n---Sets the type of compositing operation to apply when drawing new shapes.\n---@param operation string the compositing operation to use, possible values are:\n---\"source-over\", \"source-in\", \"source-out\", \"source-atop\", \"destination-over\",\n---\"destination-in\", \"destination-out\", \"destination-atop\", \"lighter\", \"copy\", \"xor\".\nfunction canvas.setCompositeOperation(operation)\n _internal.sendMessage('canvas.setCompositeOperation', { operation=operation })\nend\n\n---Sets the transparency value that is applied to all rendering operations.\n---@param value number a value between 0.0 (fully transparent) and 1.0 (fully opaque).\nfunction canvas.setGlobalAlpha(value)\n _internal.sendMessage('canvas.setGlobalAlpha', { value=value })\nend\n\n---Creates a rectangle path which is only drawn after calling stroke() or fill().\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.pathRect(x, y, w, h)\n _internal.sendMessage('canvas.pathRect', { x=x, y=y, w=w, h=h })\nend\n\n---Adds a rounded rectangle to the current path. Must be followed by stroke() or fill().\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\n---@param radius number|table corner radius applied to all four corners (uniform), or a table\n---of 1–4 values to set individual corner radius in the order [top-left, top-right,\n---bottom-right, bottom-left], following the HTML Canvas API specification.\nfunction canvas.roundRect(x, y, w, h, radius)\n _internal.sendMessage('canvas.roundRect', { x=x, y=y, w=w, h=h, radius=radius })\nend\n\n---Draw a rectangle outline using the current stroke style.\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.strokeRect(x, y, w, h)\n _internal.sendMessage('canvas.strokeRect', { x=x, y=y, w=w, h=h })\nend\n\n---Draw a rectangle with a filled interior using the current fill style,\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.fillRect(x, y, w, h)\n _internal.sendMessage('canvas.fillRect', { x=x, y=y, w=w, h=h })\nend\n\n---Clears the specified rectangle by setting its pixels to transparent.\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.clearRect(x, y, w, h)\n _internal.sendMessage('canvas.clearRect', { x=x, y=y, w=w, h=h })\nend\n\n---Draws a circle with given parameters. Must be followed by stroke() or fill().\n---@param x number x-coordinates of the center of the circle.\n---@param y number y-coordinates of the center of the circle.\n---@param r number the radius of the circle\nfunction canvas.circle(x, y, r)\n _internal.sendMessage('canvas.circle', { x=x, y=y, r=r })\nend\n\n---Draws an arc with given parameters. Must be followed by stroke() or fill().\n---@param x number x-coordinates of the center of the circle.\n---@param y number y-coordinates of the center of the circle.\n---@param r number the radius of the circle.\n---@param startAngle number the starting angle in radians.\n---@param endAngle number the ending angle, in radians.\n---@param anticlockwise boolean a flag which specifies whether the drawing should be counterclockwise or clockwise.\nfunction canvas.arc(x, y, r, startAngle, endAngle, anticlockwise)\n _internal.sendMessage('canvas.arc', { x=x, y=y, r=r, startAngle=startAngle,\n endAngle=endAngle, anticlockwise=anticlockwise })\nend\n\n---Adds a quadratic Bézier curve to the path with given control point and end point.\n---@param cpx number x-coordinate of the control point.\n---@param cpy number y-coordinate of the control point.\n---@param x number x-coordinate of the end point.\n---@param y number y-coordinate of the end point.\nfunction canvas.quadraticCurve(cpx, cpy, x, y)\n _internal.sendMessage('canvas.quadraticCurve', { cpx=cpx, cpy=cpy, x=x, y=y })\nend\n\n---Draws a bezier curve from the current position to the specified point, using the specified control points.\n---@param cp1x number x-coordinate of the first control point.\n---@param cp1y number y-coordinate of the first control point.\n---@param cp2x number x-coordinate of the second control point.\n---@param cp2y number y-coordinate of the second control point.\n---@param x number x-coordinate of the end point.\n---@param y number y-coordinate of the end point.\nfunction canvas.bezierCurve(cp1x, cp1y, cp2x, cp2y, x, y)\n _internal.sendMessage('canvas.bezierCurve', { cp1x=cp1x, cp1y=cp1y,\n cp2x=cp2x, cp2y=cp2y,\n x=x, y=y })\nend\n\n---@class Gradient\n---A class to internally link gradient objects from the Lua environment to Lumino codebase.\n---A Gradient object can be create using @{createLinearGradient} or @{createRadialGradient}\n---@private\nlocal Gradient = {}\n\n---Creates a new gradient object with the given index\n---@param idx number index of the gradient object\n---@private\nfunction Gradient:new(idx)\n -- Store the gradient object in a field of the class instance metatable\n local obj = { idx = idx}\n Class.__setmetatable(obj, self)\n self.__index = self\n -- Return the instance\n return obj\nend\n\n---Hook that runs before an object is deleted by the garbage collector.\n---It calls a function to delete the gradient object in JS\n---@private\nfunction Gradient:__gc()\n -- Keep deletion ordering deterministic when gradient operations are buffered.\n _commitIfNeeded()\n _internal.sendMessage('canvas.deleteGradient', { gradientIdx = self.idx })\nend\n-- Add the Gradient class to the Canvas namespace\ncanvas.Gradient = Gradient\n\n---Sets a gradient object to active.\n---@param gradient Gradient a gradient object\nfunction canvas.setGradientActive(gradient)\n if gradient.idx >= 0 then\n _internal.sendMessage('canvas.setGradientActive', { gradientIdx = gradient.idx })\n end\nend\n\n---Adds a new stop, defined by an offset and a color, to a gradient object.\n---@param gradient Gradient a gradient object\n---@param offset number a value between 0.0 and 1.0 where the new color stop is positioned.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.colorStop(gradient, offset, r, g, b, a)\n _internal.sendMessage('canvas.colorStop', { gradientIdx=gradient.idx, offset=offset, r=r, g=g, b=b, a=a })\nend\n\n---Creates a linear gradient object.\n---@param x1 number the x-coordinate of the start point of the gradient\n---@param y1 number the y-coordinate of the start point of the gradient\n---@param x2 number the x-coordinate of the end point of the gradient\n---@param y2 number the y-coordinate of the end point of the gradient\n---@return Gradient a new gradient object\n---@usage local gradient = Canvas.createLinearGradient(0, 0, 50, 0)\nfunction canvas.createLinearGradient(x1, y1, x2, y2)\n local idx = _internal.sendMessage('canvas.createLinearGradient', { x1=x1, y1=y1,\n x2=x2, y2=y2 })\n local gradient = Gradient:new(idx)\n return gradient\nend\n\n---Creates a radial gradient object.\n---@param x1 number x-coordinate of the start circle\n---@param y1 number y-coordinate of the start circle\n---@param r1 number radius of the start circle\n---@param x2 number x-coordinate of the end circle\n---@param y2 number y-coordinate of the end circle\n---@param r2 number radius of the end circle\n---@return Gradient a new gradient object\nfunction canvas.createRadialGradient(x1, y1, r1, x2, y2, r2)\n local idx = _internal.sendMessage('canvas.createRadialGradient', { x1=x1, y1=y1, r1=r1,\n x2=x2, y2=y2, r2=r2})\n local gradient = Gradient:new(idx)\n return gradient\nend\n\n---Returns an array with strings of all available fonts. This will list all custom loaded fonts through Loader.loadFont and\n---fonts registered in Canvas Fonts in your project. It will also probe for common system fonts although the list might not be complete.\n---It is strongly recommended to use only custom uploaded fonts to have reliable results on all platforms.\n---@return table an array with all the available fonts as strings\nfunction canvas.getAvailableFonts()\n return _internal.sendMessage('canvas.getAvailableFonts')\nend\n\n---Sets a font style.\n---@param font string The font style to be set, in the format of 'font-style font-size font-family'. Example: 'italic 20px Arial'.\nfunction canvas.setFont(font)\n _internal.sendMessage('canvas.setFont', { font=font })\nend\n\n---Sets the current text alignment\n---@param align string The new text alignment to be set. One of 'start', 'end', 'left', 'right', or 'center'.\nfunction canvas.setTextAlign(align)\n _internal.sendMessage('canvas.setTextAlign', { align=align })\nend\n\n---Sets the text baseline used when drawing text.\n---@param baseline string The text baseline to set. One of 'alphabetic', 'top', 'hanging', 'middle', 'ideographic', or 'bottom'.\nfunction canvas.setTextBaseline(baseline)\n _internal.sendMessage('canvas.setTextBaseline', { baseline=baseline })\nend\n\n---Measures the width of the specified text in pixels.\n---@param text string The text to measure.\nfunction canvas.measureTextWidth(text)\n return _internal.sendMessage('canvas.measureTextWidth', { text=text })\nend\n\n---Draws and fills a given text string at the specified coordinates.\n---@param text string The text string to be drawn and filled.\n---@param x number The x-coordinate where the text will be drawn.\n---@param y number The y-coordinate where the text will be drawn.\nfunction canvas.fillText(text, x, y)\n _internal.sendMessage('canvas.fillText', { text=text, x=x, y=y })\nend\n\n---Draws the outline of the given text at the specified coordinates.\n---@param text string The text string to be drawn.\n---@param x number The x-coordinate where the text will be drawn.\n---@param y number The y-coordinate where the text will be drawn.\nfunction canvas.strokeText(text, x, y)\n _internal.sendMessage('canvas.strokeText', { text=text, x=x, y=y })\nend\n\n-- -TODO: ImageData is not yet ready for deployment because using it for pixel manipulation would be\n-- -inefficient and slow due to the need for JSON communication with JavaScript. While JSON\n-- -communication is necessary for the security of the application, it is not well-suited for tasks\n-- -that require frequent or high-volume data transfer. It is better to use ImageData for low\n-- -frequency tasks such as updating UI and handling events, rather than trying to use it for more\n-- -demanding tasks that may be slowed down by the use of JSON objects.\n\n-- --- Image class to link imageData objects in the canvas to Lua\n-- ---@class imageData\n-- local Image = {}\n\n-- --- Creates a new Image object with the given index\n-- ---@param idx number index of the imageData object in the canvas\n-- function Image:new(idx)\n-- local obj = {}\n-- Class.__setmetatable(obj, self)\n-- self.__index = self\n-- self.idx = idx\n-- return obj\n-- end\n-- canvas.Image = Image\n\n-- ---Creates a new, blank Image object with the specified dimensions.\n-- ---All of the pixels in the new object are transparent black.\n-- ---@param width number the width of the Image object\n-- ---@param height number the height of the Image object\n-- ---@return Image a new Image object\n-- function canvas.createImage(width, height)\n-- local idx = _internal.sendMessage('canvas.createImage', { width=width, height=height })\n-- local image = Image:new(idx)\n-- return image\n-- end\n\n-- ---Write the RGBA channels of an Image object\n-- ---@param r number the r channel of the Image object\n-- ---@param g number the g channel of the Image object\n-- ---@param b number the b channel of the Image object\n-- ---@param a number the a channel of the Image object\n-- function canvas.writeImageChannels(image, r, g, b, a)\n-- _internal.sendMessage('canvas.writeImageChannels', { imageIdx=image.idx, r=r, g=g, b=b, a=a })\n-- end\n\n-- ---Draws an image given by an url at the specified position and dimensions.\n-- ---@param url string\n-- ---@param x number\n-- ---@param y number\n-- ---@param width number\n-- ---@param height number\n-- function canvas.drawImageFromUrl(url, x, y, width, height)\n-- _internal.sendMessage('canvas.drawImageFromUrl', { url=url, x=x, y=y, width=width, height=height })\n-- end\n\n-- ---Repeats a given image on the canvas with a given pattern.\n-- ---@param image imageSource an image object\n-- ---@param repeat string one of repeat, repeat-x, repeat-y, no-repeat\n-- function canvas.imagePattern(image, repeatPattern)\n-- _internal.sendMessage('canvas.pattern', { image=image, repeatPattern=repeatPattern })\n-- end\n\n---Draws the image data at the given coordinates.\n---@param image Texture the image data to paint\n---@param x number x-coordinate of the top left corner where the image data will be painted\n---@param y number y-coordinate of the top left corner where the image data will be painted\n---@param width number width of the image on screen (optional)\n---@param height number height of the image on screen (optional)\n---@param mode number mode to use for stretching. possible values are 0 = stretch, 1 = fit, 2 = cover\nfunction canvas.drawImage(image, x, y, width, height, mode)\n __assertTrace(image and image._isTexture, \"image is not a Texture object\")\n _internal.sendMessage('canvas.drawImage', { image= image._handle, x=x, y=y, width=width, height=height, mode=mode })\nend\n\n---Draws the image data at the given coordinates.\n---@param image Texture the image data to paint\n---@param x number x-coordinate of the top left corner where the image data will be painted\n---@param y number y-coordinate of the top left corner where the image data will be painted\n---@param width number width of the image on screen (optional)\n---@param height number height of the image on screen (optional)\nfunction canvas.drawSubImage(image, x, y, width, height, sourceX, sourceY, sourceWidth, sourceHeight)\n __assertTrace(image and image._isTexture, \"image is not a Texture object\")\n _internal.sendMessage('canvas.drawSubImage', { image= image._handle,\n x=x, y=y, width=width, height=height,\n sourceX=sourceX, sourceY=sourceY, sourceWidth=sourceWidth, sourceHeight=sourceHeight })\nend\n\n--- Scales the canvas by the specified factors along the x and y axes.\n--- Transformations are applied relative to the canvas origin (0,0).\n--- To scale around a different point, use `translate()` to move the origin before scaling.\n---@param x number Scale factor along the x-axis.\n---@param y number Scale factor along the y-axis.\nfunction canvas.scale(x, y)\n _internal.sendMessage('canvas.scale', { x=x, y=y })\nend\n\n--- Rotates the canvas by the specified angle in radians.\n--- Rotation is performed around the canvas origin (0,0).\n--- To rotate around a different point, translate the canvas to that point before calling rotate().\n---@param a number Angle in radians.\nfunction canvas.rotate(a)\n _internal.sendMessage('canvas.rotate', { a=a })\nend\n\n\n--- Moves (translates) the canvas origin by the specified amounts.\n--- All subsequent drawing and transformations (scale, rotate, etc.) are relative to the new origin.\n---@param x number Amount to translate along the x-axis.\n---@param y number Amount to translate along the y-axis.\nfunction canvas.translate(x, y)\n _internal.sendMessage('canvas.translate', { x=x, y=y })\nend\n\n---Applies a 2D transformation matrix to the canvas.\n---@param horizontal_scale number The amount to scale horizontally.\n---@param horizontal_skew number The amount of horizontal skew.\n---@param vertical_skew number The amount of vertical skew.\n---@param vertical_scale number The amount to scale vertically.\n---@param horizontal_translation number The amount of horizontal translation.\n---@param vertical_translation number The amount of vertical translation.\nfunction canvas.transform(horizontal_scale, horizontal_skew, vertical_skew,\n vertical_scale, horizontal_translation, vertical_translation)\n _internal.sendMessage('canvas.transform', { a=horizontal_scale, b=horizontal_skew,\n c=vertical_skew, d=vertical_scale,\n e=horizontal_translation, f=vertical_translation })\nend\n\n---Resets the current canvas transform to the identity matrix and then invokes the transform() function with the given parameters.\n---@param horizontal_scale number The amount to scale horizontally.\n---@param horizontal_skew number The amount of horizontal skew.\n---@param vertical_skew number The amount of vertical skew.\n---@param vertical_scale number The amount to scale vertically.\n---@param horizontal_translation number The amount of horizontal translation.\n---@param vertical_translation number The amount of vertical translation.\nfunction canvas.resetAndSetTransform(horizontal_scale, horizontal_skew, vertical_skew,\n vertical_scale, horizontal_translation, vertical_translation)\n _internal.sendMessage('canvas.resetAndSetTransform', { a=horizontal_scale, b=horizontal_skew,\n c=vertical_skew, d=vertical_scale,\n e=horizontal_translation, f=vertical_translation })\nend\n\n---Reset the transformation matrix to the identity matrix.\n---@function\nfunction canvas.resetTransform()\n _internal.sendMessage('canvas.resetTransform')\nend\n\n---Pushes the current canvas state to a stack so that you can restore it.\n---This can be useful for performing multiple transformations or styles on the canvas, and\n---then restoring it to its original state. The canvas state in fact includes current transformation matrix\n---stroke and fill styles, shadow styles, and other attributes. To restore the canvas state you call\n---the restoreState() function.\n---@function\nfunction canvas.saveState()\n _internal.sendMessage('canvas.saveState')\nend\n\n---Pops the the most recently saved canvas from the saved state stack and restores it.\n---@function\nfunction canvas.restoreState()\n _internal.sendMessage('canvas.restoreState')\nend\n\n--- Resets the canvas to its default state, clearing the canvas and restoring all\n--- context -properties (transforms, styles, clipping region, etc.) to their\n--- defaults. Reset() is more thorough than -calling clear() alone, which only\n--- erases pixels but leaves context state intact.\n---@function\nfunction canvas.reset()\n _internal.sendMessage('canvas.reset')\nend\n\n-- Automatically wrap canvas methods for buffering, so non-query calls are queued\n-- and query/result-producing calls force an immediate commit first.\nlocal _passthroughMethods = {\n commit = true,\n getPendingCommandCount = true,\n getPendingCommands = true,\n}\n\nlocal _immediateMethods = {\n getLastCommittedCommands = true,\n getWidth = true,\n getHeight = true,\n isPointInPath = true,\n createLinearGradient = true,\n createRadialGradient = true,\n getAvailableFonts = true,\n measureTextWidth = true,\n}\n\nfor name, fn in pairs(canvas) do\n if type(fn) == \"function\" and name ~= \"Gradient\" then\n if _passthroughMethods[name] then\n -- keep as-is\n elseif _immediateMethods[name] then\n canvas[name] = function(...)\n _commitIfNeeded()\n return fn(...)\n end\n else\n canvas[name] = function(...)\n return _runWithCapturedSend(fn, ...)\n end\n end\n end\nend\n\nreturn canvas\n";
|
|
256104
256103
|
|
|
256105
256104
|
var lua_api_class = "\nlocal Class = {}\n\nClass.__setmetatable = setmetatable\n_G.setmetatable = function()\n error(\"Do not use setmetatable. Use Class.new() instead!\")\nend\n\n-- Put the class in the global scope\n_G.Class = Class\n\nfunction Class.new(self, super)\n if self ~= Class then\n -- new was called with dot syntax, so we need to move self to super.\n super = self\n end\n\n local class, metatable, properties = {}, {}, {}\n class.metatable = metatable\n class.properties = properties\n\n function metatable:__index(key)\n local prop = properties[key]\n if prop then\n return prop:get()\n elseif class[key] ~= nil then\n return class[key]\n elseif class.__customIndex then\n return class.__customIndex(self, key)\n elseif super then\n return super.metatable.__index(self, key)\n else\n return nil\n end\n end\n\n function metatable:__newindex(key, value)\n local prop = properties[key]\n if prop then\n prop:set(value)\n elseif class.__customNewIndex then\n class.__customNewIndex(self, key, value)\n else\n if (super and super.metatable.__customnewindex(self, key, value)) then\n return\n end\n rawset(self, key, value)\n end\n end\n\n function metatable:__customnewindex(key, value)\n if class.__customNewIndex then\n class.__customNewIndex(self, key, value)\n return true\n elseif super then\n return super.metatable.__customnewindex(self, key, value)\n end\n return false\n end\n\n function class:getClass()\n return class\n end\n\n function class.new(self, ...)\n local obj = Class.__setmetatable({}, class.metatable)\n\n if obj.__new then\n if self ~= class then\n -- new was called with dot syntax\n obj:__new(self, ...)\n else\n obj:__new(...)\n end\n end\n\n return obj\n end\n\n function tableLength(T)\n local count = 0\n for _ in pairs(T) do\n count = count + 1\n end\n return count\n end\n\n function class:addProperty(key, propType, defaultValue, options)\n options = options or {}\n if type(options) == 'string' then\n options = { info=options }\n end\n\n if class.properties[key] then\n error(\"A property with the name '\" .. key .. \"' already exists!\");\n return;\n end\n class.properties[key] = Property.new(propType, defaultValue, tableLength(class.properties), options);\n end\n\n return class\nend\n\nreturn Class\n";
|
|
256106
256105
|
|
|
@@ -286557,6 +286556,26 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
286557
286556
|
pushChildTask(task) {
|
|
286558
286557
|
this.childTasks.push(task);
|
|
286559
286558
|
}
|
|
286559
|
+
findPerformanceIssuePath(limit) {
|
|
286560
|
+
limit = limit || this.profiler.performanceWarningLimitMs;
|
|
286561
|
+
let path = "";
|
|
286562
|
+
if (this.duration > limit) {
|
|
286563
|
+
path += ` -> ${this.subsystem}/${this.taskname} (${Math.ceil(this.duration)}ms)`;
|
|
286564
|
+
}
|
|
286565
|
+
let worstChild = undefined;
|
|
286566
|
+
for (const child of this.childTasks) {
|
|
286567
|
+
if (!worstChild || child.duration > worstChild.duration) {
|
|
286568
|
+
worstChild = child;
|
|
286569
|
+
}
|
|
286570
|
+
}
|
|
286571
|
+
if (worstChild) {
|
|
286572
|
+
const subPath = worstChild.findPerformanceIssuePath(limit);
|
|
286573
|
+
if (subPath) {
|
|
286574
|
+
path += subPath;
|
|
286575
|
+
}
|
|
286576
|
+
}
|
|
286577
|
+
return path;
|
|
286578
|
+
}
|
|
286560
286579
|
toData() {
|
|
286561
286580
|
return {
|
|
286562
286581
|
subsystem: this.subsystem,
|
|
@@ -286578,6 +286597,8 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
286578
286597
|
lastRecording;
|
|
286579
286598
|
loggedCalls = new Map();
|
|
286580
286599
|
lastLoggedCalls = undefined;
|
|
286600
|
+
performanceWaningEnabled = false;
|
|
286601
|
+
performanceWarningLimitMs = 20;
|
|
286581
286602
|
constructor(engine) {
|
|
286582
286603
|
this.engine = engine;
|
|
286583
286604
|
this.dummyTask = {
|
|
@@ -286617,11 +286638,21 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
286617
286638
|
}
|
|
286618
286639
|
return null;
|
|
286619
286640
|
}
|
|
286641
|
+
testPerformanceWarning(task, limit) {
|
|
286642
|
+
limit = limit || this.performanceWarningLimitMs;
|
|
286643
|
+
if (task.duration > limit) {
|
|
286644
|
+
const path = task.findPerformanceIssuePath(limit);
|
|
286645
|
+
console.warn(`Profiler performance warning! Task took ${Math.ceil(task.duration)}ms! Path: ${path}`);
|
|
286646
|
+
}
|
|
286647
|
+
}
|
|
286620
286648
|
endRecord() {
|
|
286621
286649
|
try {
|
|
286622
286650
|
if (!this.root)
|
|
286623
286651
|
return null;
|
|
286624
286652
|
this.root.done();
|
|
286653
|
+
if (this.performanceWaningEnabled) {
|
|
286654
|
+
this.testPerformanceWarning(this.root);
|
|
286655
|
+
}
|
|
286625
286656
|
this.lastRecording = this.root.toData();
|
|
286626
286657
|
this.lastLoggedCalls = Array.from(this.loggedCalls.values());
|
|
286627
286658
|
this.engine.eventBus.$emit("profiler:update", this.lastRecording, this.lastLoggedCalls);
|
|
@@ -288328,10 +288359,16 @@ var<${access}> ${ name } : ${ structName };`;
|
|
|
288328
288359
|
.map(result => {
|
|
288329
288360
|
const item = result.item;
|
|
288330
288361
|
const container = item.getContainer();
|
|
288331
|
-
|
|
288332
|
-
|
|
288333
|
-
|
|
288334
|
-
|
|
288362
|
+
// in case we are moving to a new non-subnode parent, we want to remember the old
|
|
288363
|
+
// world matrix to compensate for the reparenting so the object stays in its position
|
|
288364
|
+
// in case we move between subnodes, we want to keep the local transform, so the object
|
|
288365
|
+
// actually moves
|
|
288366
|
+
if (!destinationSubNode) {
|
|
288367
|
+
container.updateWorldMatrix(true, false);
|
|
288368
|
+
item.block.moveData = {
|
|
288369
|
+
oldWorldMatrix: container.matrixWorld.clone(),
|
|
288370
|
+
};
|
|
288371
|
+
}
|
|
288335
288372
|
return item.block;
|
|
288336
288373
|
});
|
|
288337
288374
|
let i = index;
|