材料与颜色和图像作为纹理同时在three.js

时间:2016-04-26 13:30:53

标签: javascript three.js

我有一个png,我用作PlaneGeometry的纹理,但我想添加蓝色背景。 我正在使用画布渲染器,如果这是相关的。

这是我的代码,图片有效,但颜色没有:

var material2 = getTextureMaterial('img/ok.png');
var plane2 = new THREE.PlaneGeometry(100, 100);
meshImage = new THREE.Mesh(plane2, material2);
meshImage.position.set(1000, -40, 200);
meshImage.userData.name = 'image';
meshImage.rotateY(Math.PI / 2);

function getTextureMaterial(path) {
    var texture = new THREE.Texture(texture_placeholder);
    var material = new THREE.MeshBasicMaterial({
        color: new THREE.Color(0xff0000),
        map: texture,
        overdraw: 0.5,
        side: THREE.DoubleSide,
    });
    var image = new Image();
    image.onload = function() {
        texture.image = this;
        texture.needsUpdate = true;
    };
    image.src = path;
    return material;
}

0 个答案:

没有答案