在使用CustomNavCube.js修改navcube时 发生了报错
**免责声明:**我使用的是英语到中文的翻译工具来撰写这篇帖子。
为了回答你的问题,我们需要更多关于你是如何调用 addFaces()
函数的信息。听起来你正在使用最初在这里发布的 CustomNavCube.js 概念验证代码:
作为一个快速检查,我可以在只对 Overlay
类中已弃用的代码进行最小更改的情况下成功运行该示例。对于添加 mesh(网格),我并没有进行任何更改。
Hello, Tino. I encountered an issue while using CustomNavCube.js. I incorporated the code into the modelStructureReady() function.
Below is my code: // Hide/Disable the default cube (optional)
hwv.view.getNavCube().disable();
const navcube = new CustomNavCube(hwv);
const textColor = Communicator.Color.createFromFloat(0.5, 0.5, 0.5); // Gray text color const backgroundColor = Communicator.Color.white(); // White background const selectionFaceColor= Communicator.Color.yellow();
const outlineColor = Communicator.Color.blue();
await navcube.init(
[ “LEFT”,“RIGHT”,“FRONT”,“BACK”,“BOTTOM”,“TOP” ],
textColor,
backgroundColor,
selectionFaceColor,
outlineColor
);
const op = new CustomNavCubeOperator(hwv, navcube);
const h = hwv.operatorManager.registerCustomOperator(op);
hwv.operatorManager.push(h);
navcube.enable();
However, during the usage process, an error occurred, indicating “Uncaught (in promise) TypeError: meshData.addFaces is not a function” at CustomNavCube._createCube (CustomNavCube.js:1353:26)
at CustomNavCube._createGeometry (CustomNavCube.js:388:28)
at CustomNavCube.init (CustomNavCube.js:213:20)
at async modelStructureReady
This is the way I refer to JavaScript. JavaScript is at the same level as HTML.
The code I used is the original CustomNavCube.js concept verification code that was released here initially. I did not make any modifications to it.
Then the version I used was hoops communicator 2024.5.0
Could you provide me with a simple editable example?
Looking forward to your reply
So just to confirm, does the issue you are experiencing only happen when enabling the custom nav cube operator through a modelStructureReady
callback? Are you able to use it without a callback?
Thanks,
Tino
Hello, Tino. Yes, this error occurs when the “modelStructureReady” callback is invoked. However, if this method is not called within the callback, it will not take effect because the model has not been fully loaded.
Can you run your code after the model has fully loaded to confirm that the error does not occur? If it works when the model is fully loaded then the issue is not with the custom nav cube code. Rather, the issue might be due to timing of the callback.
After the model is loaded, if this method is called in the callback, the following error will occur
Uncaught (in promise) TypeError: meshData.addFaces is not a function”
Hello Tino, may I ask if this is related to the Hoops Communicator version?
Then I printed out the data type of meshdata as follows. It seems that there is no “addFaces” option.
I don’t think it is the Communicator version that is the issue. Also, the meshData
object, per your screenshot, in the dev console won’t show the member function for the class so this is expected.
Below are the steps that I followed to confirm the CustomNavCube.js works. Steps #1 and #3 will replace the existing files in the folder:
-
Download the following JavaScript and put it in the directory HOOPS_Communicator_2025.4.0\web_viewer\examples\scripts\examples
minimal.js (1.7 KB)
-
Download the following JavaScript and put it in the directory HOOPS_Communicator_2025.4.0\web_viewer\examples\scripts
CustomNavCube.js (61.4 KB)
-
Download the following HTML and put it in the directory HOOPS_Communicator_2025.4.0\web_viewer\examples
minimal.html (1.2 KB)
-
Launch the server in quickstart by double-clicking start_server.bat found in the directory HOOPS_Communicator_2025.4.0\quick_start
-
Launch the Web Viewer and load the example using the custom nav cube implementation by clicking the following URL:
http://localhost:11180/minimal.html?viewer=csr
My suggestion to debug is, rather than encapsulating your code in a callback, just copy the code inside the modelStructureReady
callback and paste it in the web browser dev console to run it.
Thank you, Tino. My problem has been solved. I’m grateful for the help you provided and for guiding me through the debugging process.