three.js SpriteCanvasMaterial: TypeError: Cannot read property 'replace' of undefined (in render function)

与世无争的帅哥 提交于 2019-12-13 19:21:47

问题


console log info: THREE.WebGLRenderer 91dev

    var main3d = {
        scene: null, camera: null, renderer: null,

        init: function () {
            // initialize scene, camera etc.

            var _dotGeometry = new THREE.Geometry();
            _dotGeometry.vertices.push(new THREE.Vector3(2, 4, 0));
            //var _dotMaterial = new THREE.PointsMaterial({ size: 5, sizeAttenuation: false, color: 0x00ff00 });
            _dotMaterial = new THREE.SpriteCanvasMaterial({
                color: 0x00ff00,
                program: function (context) {
                    context.beginPath();
                    context.arc(0, 0, 0.05, 0, Math.PI * 2, true);
                    context.fill();
                }
            });
            var _dot = new THREE.Points(_dotGeometry, _dotMaterial);
            this.scene.add(_dot);
        }
    };

function animate() {
    requestAnimationFrame(animate);
    render();
    update();
}

function update() {
    main3d.controls.update();
}

function render() {
    if (main3d.renderer) {
        main3d.renderer.render(main3d.scene, main3d.camera);
    }
}

function initializeMain3d() {
    main3d.init();
    animate();
}

If I use THREE.SpriteCanvasMaterial, I will get exception in render() function. But if I use THREE.PointsMaterial then everything works fine.


回答1:


SpriteCanvasMaterial is to be used with CanvasRenderer.

When using WebGLRenderer, use SpriteMaterial with THREE.Sprite and use PointsMaterial with THREE.Points.

three.js r.90



来源:https://stackoverflow.com/questions/49156896/three-js-spritecanvasmaterial-typeerror-cannot-read-property-replace-of-unde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!