简体   繁体   English

在 Autodesk Forge 中无法看到 2D 文本精灵

[英]Unable to see 2D text sprites in Autodesk Forge

I'm trying to render 2D text using Sprites in the Autodesk Forge viewer, but I can't get it to show up.我正在尝试在 Autodesk Forge 查看器中使用 Sprites 渲染 2D 文本,但无法显示。 If I consult the layer by console I see that it contains the created Sprite but nevertheless I can't see it in the scene.如果我通过控制台查询图层,我会看到它包含创建的 Sprite,但我在场景中看不到它。 I have tried different scaling and position settings but no results.我尝试了不同的缩放比例和 position 设置,但没有结果。

I attach the code below:我附上以下代码:

function createText(text, preferencia, tamanyo) {
    
    var sprite = spriteTexto("Prueba texto sprite", preferencia, tamanyo);
    
    if (!NOP_VIEWER.impl.overlayScenes['overlaySprites']) 
        NOP_VIEWER.impl.createOverlayScene('overlaySprites');
    
    NOP_VIEWER.impl.addOverlay('overlaySprites', sprite);
}


function spriteTexto(text, preferencia, tamanyo) {
    
    var fontface = NOP_VIEWER.fontName;
    var fontsize = 18;      //tamanyo
    var borderThickness = 4;
    var borderColor = { r:0, g:0, b:0, a:1.0 };
    var backgroundColor = { r:0, g:0, b:0, a:0.0 };
    var textColor = { r:0, g:0, b:255, a:1 };       //hexadecimalARgb(preferencia.color);

    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');
    context.font = "Bold " + fontsize + "px " + fontface;
    var metrics = context.measureText( text );
    var textWidth = metrics.width;

    context.fillStyle   = "rgba(" + backgroundColor.r + "," + backgroundColor.g + "," + backgroundColor.b + "," + backgroundColor.a + ")";
    context.strokeStyle = "rgba(" + borderColor.r + "," + borderColor.g + "," + borderColor.b + "," + borderColor.a + ")";
    context.fillStyle = "rgba(" + textColor.r+", " + textColor.g + ", " + textColor.b + ", 1.0)";
    context.fillText( text, borderThickness, fontsize + borderThickness);

    var texture = new THREE.Texture(canvas);
    texture.needsUpdate = true;
    var spriteMaterial = new THREE.SpriteMaterial( { map: texture, useScreenCoordinates: false } );
    var sprite = new THREE.Sprite( spriteMaterial );
    sprite.scale.set(1*fontsize,1*fontsize,1*fontsize);
    sprite.position.set(5,5,6);
    return sprite;  
}

I would be very grateful if you could help me find the error, thank you very much in advance for your help!如果您能帮我找到错误,我将不胜感激,非常感谢您的帮助!

EDIT:------------------------------------------------编辑: - - - - - - - - - - - - - - - - - - - - - - - -

We want to render 2D text that can be interacted with (specifically select, rotate, and move).我们想要渲染可以交互的 2D 文本(特别是 select、旋转和移动)。

To do this currently we are working with meshes (using MeshBasicMaterial, Mesh and TextGeometry), but it turns out that the text does not look perfectly sharp, it presents aliasing and we've found that according to the API reference, the antialiasing is not applicable to 2d.为此,目前我们正在使用网格(使用 MeshBasicMaterial、Mesh 和 TextGeometry),但事实证明,文本看起来并不十分清晰,它呈现出锯齿,我们发现根据 API 参考,抗锯齿不是适用于 2d。

Here are some examples of the problem, as you can see, the more we move away from the plane, the worse the text looks (and even up close it doesn't look perfect):这里有一些问题的例子,正如你所看到的,我们越远离平面,文本看起来越糟糕(即使靠近它看起来也不完美):

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

We were trying to make a test representing the text with Sprites (despite the fact that it would mean having to change the entire implementation already made with meshes) to try to implement it in another way that will solve the problem.我们试图用 Sprites 进行表示文本的测试(尽管这意味着必须更改已经用网格完成的整个实现)以尝试以另一种解决问题的方式来实现它。 But we see that it is not possible either.但我们看到这也是不可能的。

How can we correct the rendering of the text then?那么我们如何纠正文本的渲染呢? Is there a way to fix it or is this the most we can get in 2D?有没有办法修复它,或者这是我们在 2D 中所能得到的最多的? We've tried searching for information on this but we haven't find anything helpful.我们已经尝试搜索这方面的信息,但没有找到任何有用的信息。

Unfortunately, Forge Viewer doesn't support THREE.Sprite at present.不幸的是,Forge Viewer 目前不支持THREE.Sprite It uses a self-maintained three.js r71 and removes this support as I know.它使用自维护的 three.js r71 并删除了我所知道的这种支持。

Could you share the use case in detail on why you want to use THREE.Sprite with Forge Viewer?您能否详细分享一下为什么要将THREE.Sprite与 Forge Viewer 一起使用的用例? If you don't want to share that publicly, you can send it to forge (DOT) help (AT) autodesk (DOT) com .如果您不想公开分享,可以将其发送到forge (DOT) help (AT) autodesk (DOT) com

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

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