简体   繁体   English

伪造函数generateTexture()

[英]Forge function generateTexture()

In the following example, there is a function called generateTexture() . 在以下示例中,有一个名为generateTexture()的函数。

Is it possible to draw text (numbers) into the pixel array? 是否可以在像素阵列中绘制文本(数字)? Or is it possible to draw text (numbers) on top of that shader? 或者是否可以在该着色器上绘制文本(数字)?

Our goal is to draw a circle with a number inside of it. 我们的目标是绘制一个带有数字的圆圈。

https://forge.autodesk.com/blog/using-dynamic-texture-inside-custom-shaders https://forge.autodesk.com/blog/using-dynamic-texture-inside-custom-shaders

UPDATE: We noticed that each circle can't use a unique generateTexture() . 更新:我们注意到每个圆圈都不能使用唯一的generateTexture() The generateTexture() result is used by every single one of them. generateTexture()结果由它们中的每一个使用。 The only thing that can be customized per object is the color, plus what texture is used. 每个对象唯一可以自定义的是颜色,以及使用的纹理。

We could create a workaround for this, which is to generate every texture from 0 to 99, and to then have each object choose the correct texture based on the number we want to display. 我们可以为此创建一个解决方法,即生成从0到99的每个纹理,然后让每个对象根据我们想要显示的数字选择正确的纹理。 We don't know if this will be efficient enough to work properly though. 我们不知道这是否足够有效以便正常工作。 Otherwise, it might have to be 0 to 9+ or something in that direction. 否则,它可能必须是0到9+或那个方向的东西。 Any guides on our updated question would be really appreciated. 任何关于我们更新的问题的指南都将非常感激。 Thanks. 谢谢。

I am able to successfully display text with the following code, simply replace generateTexture() by generateCanvasTexture() in the sample and you should get the result below: 我能够使用以下代码成功显示文本,只需在示例中用generateCanvasTexture()替换generateTexture() ,您应该得到以下结果:

const generateCanvasTexture = () => {

  const canvas = document.createElement("canvas")
  const ctx = canvas.getContext('2d')

  ctx.font = '20pt Arial'
  ctx.textAlign = 'center'
  ctx.textBaseline = 'middle'
  ctx.fillText(new Date().toLocaleString(),
    canvas.width / 2, canvas.height / 2)

  const canvasTexture = new THREE.Texture(canvas)

  canvasTexture.needsUpdate = true
  canvasTexture.flipX = false
  canvasTexture.flipY = false

  return canvasTexture
}

在此输入图像描述

It is possible but you would need to implement it yourself. 这是可能的,但你需要自己实现它。 Shaders are a pretty low level feature so there is no way to directly draw a number or a text, but you can convert a given character into its representation as a 2d pixel array. 着色器是一个相当低级别的功能,因此无法直接绘制数字或文本,但您可以将给定字符转换为其表示为2d像素数组。

暂无
暂无

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

相关问题 函数getManifest Autodesk forge PHP客户端 - Function getManifest Autodesk forge PHP client Forge Viewer v7:“getViewableUrn 不是函数”- 7.33.1 - Forge Viewer v7: “getViewableUrn is not a function” - 7.33.1 使用 Forge Viewer SceneBuilder Extension 报错“addMesh()” is not a function - Use Forge Viewer SceneBuilder Extension to report an error “addMesh()” is not a function Autodesk Forge Viewer 调用内置扩展功能 - Autodesk Forge Viewer call Built-in Extension function 未捕获的TypeError:P.addInstancingSupport不是函数[autodesk-forge] - Uncaught TypeError: P.addInstancingSupport is not a function [autodesk-forge] Autodesk forge标记3D错误TypeError:$(…).tooltip不是函数 - Autodesk forge markup 3D error TypeError: $(…).tooltip is not a function Autodesk Forge .NET SDK GetObject 函数和从 BIM 360 Docs 中心下载文件 - Autodesk Forge .NET SDK GetObject function and downloading files from BIM 360 Docs hub 是否可以通过从外部 web 页面接收特定 ID 在 Forge Viewer 中实现突出显示 function? - Is it possible to implement the highlight function in Forge Viewer by receiving a specific ID from an external web page? 在链接模型中的元素上使用Autodesk Forge Viewer的搜索功能时,返回的dbId不能执行fitToView,但dbId + 1有效吗? - When using search function of Autodesk Forge Viewer on elements in linked models, the returned dbId cannot do fitToView, but dbId + 1 works? Autodesk Forge:Forge查看器中的BIM空间和房间 - Autodesk Forge: BIM spaces and rooms in the Forge viewer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM