简体   繁体   English

使用three.js,我该如何徒手绘制多维数据集?

[英]Using three.js, how would I do to draw freehand on a cube?

I've been trying for most of today to find a way to basically represent a graffitti wall, and can't find any pointers in that direction. 我在今天的大部分时间里一直在尝试寻找一种方法来基本上表示graffitti墙,并且找不到该方向的任何指针。 My first assumption was that I'd need to do some kind of custom texture, but I really can't figure it out; 我的第一个假设是我需要做一些自定义纹理,但是我真的不知道。 idk if it's because I'm burnt out, or what, but I just can't think of a way to do it in three.js terms. idk是因为我精疲力尽,还是什么,但我只是想不出一种用three.js术语来做到这一点的方法。

Has any of you had better luck, or knows a way where I could potentially do something like this? 你们中有人有更好的运气吗,还是知道我有可能做这样的事情?

For more details, by "like this" I basically mean applying a given bitmap brush on top of the material in a CubeGeometry. 对于更多细节,通过“像这样”,我基本上是指在CubeGeometry中将给定的位图画笔应用于材质的顶部。

I know it's a bit old, but I've been messing around with this lately, and I think I found a way to do it. 我知道它有些旧,但是最近我一直在搞弄它,我想我找到了一种方法。

Create a canvas, then create a texture using that canvas. 创建一个画布,然后使用该画布创建纹理。 After that, use any of the codes HERE . 之后,请使用此处的任何代码。 It should work pretty ok with plain surfaces, but its kind of tricky with spheres or non-regular shapes. 它在平整的表面上应该可以很好地工作,但是对于球体或非规则形状则有点棘手。

Should be something like this: 应该是这样的:

 var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); /* context options here */ var texture = new THREE.Texture(canvas); texture.needsUpdate = true; var graffWall = new.MeshBasicMaterial({ map:texture1 }); mesh.material=material; //or: var mesh = new THREE.Mesh(geometry, material); //and here comes the magic... more or less var wall = document.getElementById('canvas'); var ctx = mesh.material.map.image.getContext('2d'); var ctx = el.getContext('2d'); var isDrawing; wall.onmousedown = function(e) { isDrawing = true; ctx.lineWidth = 10; ctx.lineJoin = ctx.lineCap = 'round'; ctx.moveTo(e.clientX, e.clientY); }; wall.onmousemove = function(e) { if (isDrawing) { ctx.lineTo(e.clientX, e.clientY); ctx.stroke(); } }; wall.onmouseup = function() { isDrawing = false; }; 

not sure if it would work, but it is an approach. 不知道它是否会起作用,但这是一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM