简体   繁体   English

动态更新X3DOM模型中的纹理

[英]Update textures in X3DOM model dynamically

I am developing a Web 3D app and I produced some code in Javascript that implements the following tag to an external .html file with the model in it, within an iframe. 我正在开发一个Web 3D应用程序,我在Javascript中生成了一些代码,这些代码在iframe中使用模型实现以下标记到外部.html文件。

In the <appearance> element in the X3D code block of the external .html file: 在外部.html文件的X3D代码块中的<appearance>元素中:

<texture id="XXX" repeats="true" repeatt="true" url="" scale="true"
hidechildren="true">
<img src="" attr=".../BMW.jpg" style="display: none; visibility: hidden;">
</texture>

Javascript code that places the above code in the appropriate block in the iframe after I click on a button: 我单击按钮后将上述代码放在iframe中相应块中的Javascript代码:

ogl = true;
function toggleTexture(){
if (!ogl) {
    var t = document.createElement("Texture");
    t.setAttribute("id", "XXX");
    t.setAttribute("repeatS", "true");
    t.setAttribute("repeatT", "true");
    var imgElement = document.createElement("img");
    imgElement.setAttribute("src", "../HomeFurniture/assets/BMW.jpg");
    t.appendChild(imgElement);

    var iframe = document.getElementById("frame");
    var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
    innerDoc.getElementById("anApp").appendChild(t);
    innderDoc.x3dom.reload();
} else {
    var iframe = document.getElementById("frame");
    var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
    var ot = innerDoc.getElementById("anApp");
    ot.removeChild(innerDoc.getElementById('XXX'));
}

return false;
}

The result in the debugging of Chrome browser shows that the piece of code needed is inserted, but the actual model is not updated with the appropriate texture. Chrome浏览器调试的结果显示插入了所需的代码片段,但实际模型未使用适当的纹理进行更新。

There must be something that I miss, but I cannot find the solution. 必须有一些我想念的东西,但我找不到解决方案。 Any help would be appreciated. 任何帮助,将不胜感激。

FIXED: The problem was Google Chrome. 修复:问题是Google Chrome。 I tested the Web app in Mozilla Firefox and everything works :) 我在Mozilla Firefox中测试了Web应用程序,一切正常:)

Additionally, I tried the Javascript code in the child html file and it works in Chrome. 另外,我在子html文件中尝试了Javascript代码,它可以在Chrome中运行。 It just refuses to work when the parent html file load the child html file within an iframe block. 当父html文件在iframe块中加载子html文件时,它只是拒绝工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM