【问题标题】:how can I create a-assets programmatically in aframe?如何在框架中以编程方式创建资产?
【发布时间】:2019-10-07 01:37:07
【问题描述】:

我正在使用 cloudinary 为平面提供纹理。我已经为 cloudinary 创建了一个后端,以便我可以替换 cloudinary 上的图像,但为了反映我的 aframe 应用程序,我需要在每次有人加载页面时更改 URL 中的版本我如何以编程方式为此目的设置 a-assets我尝试创建一个 addasset 组件并将其附加到 a-assets 但它在这里不起作用是我创建的代码的 sn-p

如果有办法通过发出任何事件来重新加载 a 资产,请告知,因为这也可以 img 已添加到我在 chrome 调试工具中检查过的 a-assets 中

AFRAME.registerComponent('addasset', {
  init: function() {
    var version = Math.floor(Math.random() * 101);
    var str = "https://res.cloudinary.com/blinklink-solutions/image/upload/v" + version + "/v1/Fizan%20Polarized%20Sunglasses.jpeg.jpg"
    // var str="https://res.cloudinary.com/blinklink-solutions/image/upload/v"+version+"/eyesdeal%20texture/dialogleft.png"
    var assets = document.getElementById('assets');
    var img = document.createElement("img");
    img.setAttribute("id", "off1");
    img.setAttribute("src", str);
    console.log(assets);
    console.log(str);
    assets.appendChild(img);
    var plane = document.getElementById("offer_plane");
    plane.setAttribute("src", "#off1")
  },
});

【问题讨论】:

    标签: javascript aframe webvr


    【解决方案1】:

    a-assets 用于在场景开始渲染之前预取资源。加载后修改它没有意义。两种选择:

    1. 不要使用a-assets,并在运行时在平面上设置正确的图像URL。例如; planeEl.setAttribute('src', 'url(xxx)');
    2. 在将页面发送到客户端之前,生成您的 HTML 服务器端并使用正确的 URL 填充 a-assets。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多