【问题标题】:'vertices' does not exist on type 'BufferGeometry' in threejsThreejs中的“BufferGeometry”类型上不存在“顶点”
【发布时间】:2021-10-26 18:49:19
【问题描述】:

我正在使用three.js 库将图像绘制到屏幕上。当我创建我的plainGeometry打字稿说顶点不存在于particles.geometry.vertices中,但是当我运行我的模块时,一切都加载并响应它应该除了它给我这个错误说顶点不存在,如果它们不存在我不会画那个图像。

几何有一个属性叫做顶点,当我通过three.point(geometry, material)创建物体粒子时;我从几何中获取所有顶点并通过执行 this.particles.geometry.vertices 来访问它们,但打字稿说该属性在几何中不存在,即使它有效

这是错误显示

“PlaneGeometry”类型上不存在属性“顶点”。

下面是我做的代码。你能帮我解决这个问题吗

代码: https://stackblitz.com/edit/angular-threejs-demo-basic-hhtztu

【问题讨论】:

    标签: three.js


    【解决方案1】:

    由于r125,所有像PlaneGeometry 这样的几何生成器都是从BufferGeometry 派生的。在同一版本中,Geometry 已被删除,这意味着 BufferGeometry 是现在处理几何数据的唯一方法。

    这意味着您无法再访问vertices 属性。在您的代码中实现简单顶点置换的常用方法是:

    const positionAttribute = geometry.getAttribute('position');
    
    for (let i = 0; i < positionAttribute.count; i ++) {
    
        vertex.fromBufferAttribute(positionAttribute, i);
    
        const waveX1 = 0.25 * Math.sin(v.x * 2 + t * 3)
        const waveX2 = 0.125 * Math.sin(v.x * 3 + t * 2)
        const waveY1 = 0.1 * Math.sin(v.y * 5 + t * 0.5)
        
        vertex.z = (waveX1 + waveX2 + waveY1);
    
        positionAttribute.setZ(i, vertex.z);
    
    
    }
    
    positionAttribute.needsUpdate = true;
    

    【讨论】:

    • 我添加了上面的代码,但出现错误属性 'getAttribute' 在类型 'Geometry | 上不存在' BufferGeometry'。如果可能的话,你可以在我上面的代码中实现它吗
    • 请将three.js升级到最新版本。此外,TS 声明文件现已在此处提供:github.com/three-types/three-ts-types
    • 好的,谢谢兄弟......
    猜你喜欢
    • 2018-01-23
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2020-12-05
    相关资源
    最近更新 更多