三.精灵画布材料不起作用



此代码(基于此代码):

    drawCircle = (context) ->
        pos = 0.5
        radius = 0.5
        context.scale(0.05, -0.05)
        context.beginPath()
        context.arc(pos, pos, radius, 0, 2*Math.PI, false)
        context.fillStyle = 'white'
        context.fill()
    m = new THREE.SpriteCanvasMaterial( {program: drawCircle } )
    s = new THREE.Sprite( m )

返回错误

    Uncaught TypeError: Cannot read property 'x' of undefined. 

三.js:36534行:

    _gl.uniform2f( uniforms.uvScale, material.uvScale.x, material.uvScale.y );

似乎材质 uvScale 和 uvOffset 属性未正确初始化...为什么?如果我自己设置这些属性:

    m.uvScale = new THREE.Vector2()
    m.uvOffset = new THREE.Vector2()

错误消失了,但我看不到粒子(我不知道在画布中绘制什么位置,以及为什么要缩放它)。

您正在使用用于webglrenderer中的canvas2D材质。您应该使用画布渲染器或使用其他材质(SpriteMaterial)。

最新更新