【问题标题】:THREE js get material context三个js获取材质上下文
【发布时间】:2016-07-07 21:27:16
【问题描述】:

我有一张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?

【问题讨论】:

  • 你会很丑,并且在处理和更新这个数组时会产生另一个问题
  • context= o.material.map.image.getContext("2d"); ?它有效,但这可以吗?
  • 也许可以解释一下您要做什么以及为什么再次需要上下文。
  • 在每一帧中更新它,并防止在内存中存储旧的上下文和旧的纹理
  • 再问一个问题没用:stackoverflow.com/questions/38245038/…

标签: javascript canvas three.js


【解决方案1】:

为我工作:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 2014-03-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多