三个js获得物质背景

时间:2016-07-07 12:44:27

标签: javascript canvas three.js

我有Canvas地图(纹理):

var mesh;
var canvas = document.createElement('canvas');
var context= canvas.getContext("2d");
    context.canvas.width  = context.canvas.height = 128;
    context.fillStyle = 'rgba(255,255,255,0.4)';
    context.fillText('lala', 64, 85);
var texture = new THREE.Texture(canvas); 
    texture.needsUpdate = true;
var material = new THREE.PointsMaterial( { size: 128, map: texture } );
var geometry = new THREE.Geometry();      
    geometry.vertices.push( new THREE.Vector3() );  
mesh = new THREE.Points( geometry, material );
scene.add(mesh);

如何通过网格对象引用来更新上下文?

mesh.material.map.image....context?? ... ? what is the correct approach?

1 个答案:

答案 0 :(得分:0)

适合我:

var context = mesh.material.map.image.getContext("2d"); 
    context.clearRect(0, 0, 128, 128);
    //..... draw sprite;
mesh.material.map.needsUpdate = true;