【问题标题】:Three.js new THREE.TextBufferGeometry() Cannot read property 'yMax' of undefined errorThree.js new THREE.TextBufferGeometry() 无法读取未定义错误的属性“yMax”
【发布时间】:2018-08-21 03:18:37
【问题描述】:

将文本添加到 three.js 场景时,我收到错误“Uncaught TypeError: Cannot read property 'yMax' of undefined”。

let loader = new THREE.FontLoader();

  let font = loader.parse( jsonFont );

  let geometry = new THREE.TextBufferGeometry( 'MY TEXT', {
        font: font,
        size: 80,
        height: 5,
        curveSegments: 12,
        bevelEnabled: true,
        bevelThickness: 10,
        bevelSize: 8,
        bevelSegments: 5
  } );

Chrome浏览器完成控制台错误显示:

Uncaught TypeError: Cannot read property 'yMax' of undefined

【问题讨论】:

  • m_scene.add( font );你这样做是为了什么?
  • 我是从官方文档中获取的,我认为没有必要,但以防万一......
  • 我删除了 m_scene.add( font );
  • 什么是jsonFont?它有什么价值?

标签: javascript three.js


【解决方案1】:

我找到了解决问题的方法。

解决方案来源: https://threejs.org/examples/#webgl_geometry_text_shapes https://github.com/mrdoob/three.js/blob/master/examples/webgl_geometry_text_shapes.html

我的代码错误: https://github.com/mrdoob/three.js/issues/13665

|---------------|

这段代码对我有用:

let loader = new THREE.FontLoader();
loader.load( "/fonts/helvetiker_regular.typeface.json", ( font ) =>
{
  let xMid;
  let shapes = font.generateShapes( "Sample Test", 100, 2 );

  let textShape = new THREE.BufferGeometry();
  let geometry = new THREE.ShapeGeometry( shapes );
  geometry.computeBoundingBox();

  let material = new THREE.MeshBasicMaterial( {
                                               color      : 0x006699,
                                               transparent: true,
                                               opacity    : 0.4,
                                               side       : THREE.DoubleSide
                                             } );

  xMid = -0.5 * ( geometry.boundingBox.max.x - geometry.boundingBox.min.x );
  geometry.translate( xMid, 0, 0 );

  textShape.fromGeometry( geometry );
  let mesh = new THREE.Mesh( textShape, material );
  m_scene.add( mesh );

} );

【讨论】:

    猜你喜欢
    • 2013-06-16
    • 2017-01-07
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 2020-10-15
    • 2016-09-12
    相关资源
    最近更新 更多