AFrame:使用资产中的图像时,a-image 会抛出错误

AFrame: a-image throws error when using image from assets

我正在尝试将 src 指向资产标签内的项目之一的图像添加到我的场景中:

<a-assets>
    <a-asset-item id="shoot" src="/assets/icons/shoot.png"></a-asset-item>
</a-assets>

...
<a-image src="#shoot" 
    position="0 0 -0.2" 
    scale="0.05 0.05 0.05" 
    material="alphaTest: 0.5"></a-image>
...

我在控制台中收到以下错误:

THREE.WebGLState: TypeError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Overload resolution failed.
    at Object.texImage2D (aframe-master.js:27470)
    at uploadTexture (aframe-master.js:28387)
    at setTexture2D (aframe-master.js:27939)
    at WebGLTextures.safeSetTexture2D (aframe-master.js:28819)
    at SingleUniform.setValueT1 [as setValue] (aframe-master.js:23479)
    at Function.WebGLUniforms.upload (aframe-master.js:23938)
    at setProgram (aframe-master.js:32143)
    at WebGLRenderer.renderBufferDirect (aframe-master.js:30878)
    at renderObject (aframe-master.js:31625)
    at renderObjects (aframe-master.js:31595)
    at WebGLRenderer.render (aframe-master.js:31376)
    at HTMLElement.render (aframe-master.js:79612)
    at bound (aframe-master.js:83391)
    at onAnimationFrame (aframe-master.js:31231)
    at onAnimationFrame (aframe-master.js:21566)

我也试过用这种方式加载它,但没有用:

<a-assets>
    <a-asset-item id="shoot" src="/assets/icons/shoot.png"></a-asset-item>
</a-assets>
<a-image src="/assets/icons/shoot.png" 
    position="0 0 -0.2" 
    scale="0.05 0.05 0.05" 
    material="alphaTest: 0.5"></a-image>

但是如果我删除一个资产项目,它会起作用:

<a-image src="/assets/icons/shoot.png" 
    position="0 0 -0.2" 
    scale="0.05 0.05 0.05" 
    material="alphaTest: 0.5"></a-image>

你能告诉我做错了什么吗?这是一个错误吗?

是的,我两天前发现了类似的问题,实际上 a-assets 只有当您通过服务器 运行 时才有效。我已经通过使用 django 解决了这个问题。

我的错。我应该使用 img 而不是 a-asset-item 标签