FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
03-30-2023 10:51 PM - edited 03-30-2023 10:53 PM
Solved! Go to Solution.
03-31-2023 08:53 AM
Do you know the How To: Store-and-How-to/WebIQ-Render-a-3D-model maybe you find some helpful information there
03-31-2023 09:43 AM
Thanks.
I have already read that how-to. I already succesfully loaded my model in .obj format. You can use the OBJloader without importing anyhing else but ThreeJS.
But I want to display a model with texture and for this a gltf file is easier. Therefor I have imported the ThreeJS GLTF loader. But I am not able to call/use this package. Normally you would need to import this in your script in order to use it. But If I try to do that I receive the following message:
Am I doing something wrong here?
Thanks!
03-31-2023 10:22 AM
This is a normal JavaScript error:
https://www.google.com/search?q=%22cannot+use+import+statement+outside+of+module%22
The message is fully correct, you'd have to include your script like this:
<script type="module" src="....">
However, you cannot specify this currently in WebIQ. The workaround would be to modify the index.html file of the HMI manually, however please note that this will be updated (read: overwritten) on each publish automatically.
04-02-2023 06:32 PM
Instead of the manual entry in the index.html this can also be done by a "Local script" in WebIQ. This has the advantage that it does not have to be inserted manually again and again.
The attached example shows a module that exports 2 functions:
HINTS:
Example module
const iTest = 10
function myLog1(sInfo) {
let dt = new Date()
shmi.notify(`myLog1:${sInfo} ${("" + dt.getSeconds()).padStart(2, "0")}`)
}
function myLog2(sInfo) {
let dt = new Date()
shmi.notify(`myLog2:${sInfo} ${("" + dt.getSeconds()).padStart(3, "0")}`)
}
export {iTest, myLog1, myLog2}
Local script which adds the modul to WebIQ
(function () {
var MODULE_NAME = "initModul",
ENABLE_LOGGING = false,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME,
ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg(MODULE_NAME);
/**
* loads a module into WebIQ...
*/
module.run = function (self) {
// create script and add it to section head of HTML document
let myScript = document.createElement("script")
myScript.type = "module"
myScript.text = `
import * as myModule from "./js/custom-libs/modules/myModule.js"
window.myModule = myModule`
document.getElementsByTagName("head")[0].appendChild(myScript)
/* called when this local-script is disabled */
self.onDisable = function () {
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
// MODULE CODE - END
fLog("module loaded");
})();