• <tfoot id='iaNsI'></tfoot>

    <small id='iaNsI'></small><noframes id='iaNsI'>

    <legend id='iaNsI'><style id='iaNsI'><dir id='iaNsI'><q id='iaNsI'></q></dir></style></legend>
        <bdo id='iaNsI'></bdo><ul id='iaNsI'></ul>
        <i id='iaNsI'><tr id='iaNsI'><dt id='iaNsI'><q id='iaNsI'><span id='iaNsI'><b id='iaNsI'><form id='iaNsI'><ins id='iaNsI'></ins><ul id='iaNsI'></ul><sub id='iaNsI'></sub></form><legend id='iaNsI'></legend><bdo id='iaNsI'><pre id='iaNsI'><center id='iaNsI'></center></pre></bdo></b><th id='iaNsI'></th></span></q></dt></tr></i><div id='iaNsI'><tfoot id='iaNsI'></tfoot><dl id='iaNsI'><fieldset id='iaNsI'></fieldset></dl></div>

        three.js 2D 文本精灵标签

        three.js 2D Text sprite labels(three.js 2D 文本精灵标签)
          <i id='JUFMp'><tr id='JUFMp'><dt id='JUFMp'><q id='JUFMp'><span id='JUFMp'><b id='JUFMp'><form id='JUFMp'><ins id='JUFMp'></ins><ul id='JUFMp'></ul><sub id='JUFMp'></sub></form><legend id='JUFMp'></legend><bdo id='JUFMp'><pre id='JUFMp'><center id='JUFMp'></center></pre></bdo></b><th id='JUFMp'></th></span></q></dt></tr></i><div id='JUFMp'><tfoot id='JUFMp'></tfoot><dl id='JUFMp'><fieldset id='JUFMp'></fieldset></dl></div>
            <bdo id='JUFMp'></bdo><ul id='JUFMp'></ul>
          • <tfoot id='JUFMp'></tfoot>
            1. <legend id='JUFMp'><style id='JUFMp'><dir id='JUFMp'><q id='JUFMp'></q></dir></style></legend>

              <small id='JUFMp'></small><noframes id='JUFMp'>

                    <tbody id='JUFMp'></tbody>

                  本文介绍了three.js 2D 文本精灵标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 three.js 的新手,遇到一些属于 2D 文本的问题:

                  I'm new to three.js and have some issues belonging 2D Text:

                  我想要什么:我想要一些标签,例如.x、y 和 z 轴.标签应始终朝向相机.也许稍后它们应该只显示,如果它们悬停,但这是另一个主题.

                  What I want: I want some Labels for eg. the x,y and z-axis. The labels should always look to the camera. Maybe later they should only be shown, if their hovered but that's another topic.

                  我有什么问题我找到了这个教程(这正是我想要达到的效果 | http://stemkoski.github.io/Three.js/Sprite-Text-Labels.html),但它适用于旧版本的three.js,使用方法如 var spriteAlignment = THREE.SpriteAlignment.topLeft;.我发现了这个解决方法(THREE.SpriteAlignment 显示为未定义)但它不是让我清楚如何使用新方法来满足我的需求.

                  What are my issues I found this tutorial (which is excatly the effect I want to achieve | http://stemkoski.github.io/Three.js/Sprite-Text-Labels.html), but it's for an old version of three.js using methods like var spriteAlignment = THREE.SpriteAlignment.topLeft;. I found this workaround (THREE.SpriteAlignment showing up as undefined) but it's not clear for me how I could use the new approach for my needs.

                  我在寻找什么也许你可以帮我命名我正在搜索的那个东西,或者想出一个简短的方法.

                  What I'm looking for Maybe you could help me name that thing I was searching for or come up with a short approach.

                  推荐答案

                  Text Sprites 很好,但是如果你使用超过数千个它可能会因为 GPU 而减慢一切.

                  Text Sprites are nice, but if you use more then thousand of it it can slow down everything because of the GPU.

                  有一种更好"的方法,将 Sprite 创建为 Canvas,这是我也使用的一个函数:

                  There is a "better" way, create the Sprite as Canvas, here is a function that I use too for it:

                      function makeTextSprite( message, parameters )
                      {
                          if ( parameters === undefined ) parameters = {};
                          var fontface = parameters.hasOwnProperty("fontface") ? parameters["fontface"] : "Arial";
                          var fontsize = parameters.hasOwnProperty("fontsize") ? parameters["fontsize"] : 18;
                          var borderThickness = parameters.hasOwnProperty("borderThickness") ? parameters["borderThickness"] : 4;
                          var borderColor = parameters.hasOwnProperty("borderColor") ?parameters["borderColor"] : { r:0, g:0, b:0, a:1.0 };
                          var backgroundColor = parameters.hasOwnProperty("backgroundColor") ?parameters["backgroundColor"] : { r:255, g:255, b:255, a:1.0 };
                          var textColor = parameters.hasOwnProperty("textColor") ?parameters["textColor"] : { r:0, g:0, b:0, a:1.0 };
                  
                          var canvas = document.createElement('canvas');
                          var context = canvas.getContext('2d');
                          context.font = "Bold " + fontsize + "px " + fontface;
                          var metrics = context.measureText( message );
                          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.lineWidth = borderThickness;
                          roundRect(context, borderThickness/2, borderThickness/2, (textWidth + borderThickness) * 1.1, fontsize * 1.4 + borderThickness, 8);
                  
                          context.fillStyle = "rgba("+textColor.r+", "+textColor.g+", "+textColor.b+", 1.0)";
                          context.fillText( message, 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(0.5 * fontsize, 0.25 * fontsize, 0.75 * fontsize);
                          return sprite;  
                      }
                  

                  这篇关于three.js 2D 文本精灵标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                  <i id='oZ2oN'><tr id='oZ2oN'><dt id='oZ2oN'><q id='oZ2oN'><span id='oZ2oN'><b id='oZ2oN'><form id='oZ2oN'><ins id='oZ2oN'></ins><ul id='oZ2oN'></ul><sub id='oZ2oN'></sub></form><legend id='oZ2oN'></legend><bdo id='oZ2oN'><pre id='oZ2oN'><center id='oZ2oN'></center></pre></bdo></b><th id='oZ2oN'></th></span></q></dt></tr></i><div id='oZ2oN'><tfoot id='oZ2oN'></tfoot><dl id='oZ2oN'><fieldset id='oZ2oN'></fieldset></dl></div>

                  <legend id='oZ2oN'><style id='oZ2oN'><dir id='oZ2oN'><q id='oZ2oN'></q></dir></style></legend>

                      <bdo id='oZ2oN'></bdo><ul id='oZ2oN'></ul>

                      <small id='oZ2oN'></small><noframes id='oZ2oN'>

                      <tfoot id='oZ2oN'></tfoot>

                          <tbody id='oZ2oN'></tbody>