【问题标题】:Three js texture offset not updating三个js纹理偏移不更新
【发布时间】:2020-12-04 03:39:35
【问题描述】:

我目前正在尝试创建一个使用数据纹理着色的网格,我的初始着色显示得很好,但现在我的下一个目标是沿 y 轴偏移纹理。和这个例子很相似。

http://math.hws.edu/graphicsbook/demos/c5/textures.html

我如何创建纹理/网格:

this.colorTexture = new DataTexture(colors, this.frameWidth, frameCount, RGBFormat, FloatType, UVMapping, RepeatWrapping, RepeatWrapping);

    const material = new MeshBasicMaterial({
        side: FrontSide,
        vertexColors: true,
        wireframe: false,
        map: this.colorTexture
    });
    
    this.mesh = new Mesh(geometry, material);

我如何尝试使用偏移为纹理设置动画:

    this.mesh.material.map.offset.y -= 0.001;
    this.mesh.material.map.needsUpdate = true;
    this.mesh.material.needsUpdate = true;
    this.mesh.needsUpdate = true;

我已经确认在每个动画帧期间都会调用我用来尝试偏移的函数,但是除了我写入纹理的颜色的初始定位之外,可视化本身没有动画或显示变化。 非常感谢任何帮助:)

【问题讨论】:

    标签: three.js


    【解决方案1】:

    只要将Texture.matrixAutoUpdate 设置为true(这也是默认值),纹理的uv 变换矩阵就会自动更新。您可以简单地调制Texture.offset。无需设置任何needsUpdate 标志(Mesh.needsUpdate 无论如何都不存在)。

    最好严格遵守webgl_materials_texture_rotation 示例中的代码。如果此代码不起作用,请通过实际示例演示该问题。

    【讨论】:

    • 感谢您的回复,我在此代码笔中重新创建了问题,在该代码笔中我非常相似地生成了几何/网格,并在纹理中间添加了一条线,该线应该只是向上移动 Y轴并最终环绕。 codepen.io/samantha-palmer/pen/ZEpQKow?editors=0010
    • 您的几何图形没有uv 属性。没有纹理坐标,就不能使用纹理。
    • 对 uvs 进行了更多阅读,为我的几何图形生成了一组 uvs,并且成功了!非常感谢。对于那些遇到非常类似问题的人来说,这里是我的固定代码。 codepen.io/samantha-palmer/pen/ZEpQKow?editors=0010
    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多