简体   繁体   English

Forge Viewer Autodesk v7 在使用 THREE.ShaderMaterial 时重新着色 THREE.BufferGeoemtry 问题

[英]Forge Viewer Autodesk v7 issues with recolouring THREE.BufferGeoemtry when using THREE.ShaderMaterial

EDIT: The Forge Viewer I'm using has customized version of Three.js release r71 (source) which is why I'm using outdated code.编辑:我使用的 Forge Viewer 有 Three.js release r71 (source) 的自定义版本,这就是我使用过时代码的原因。 The current release of Three.js is r121. Three.js 的当前版本是 r121。

I've created THREE.Group() that contains various THREE.Pointcloud(geometry, material).我创建了包含各种 THREE.Pointcloud(geometry, material) 的 THREE.Group()。 One of the Points is composed of THREE.BufferGeometry() and THREE.ShaderMaterial().其中一个点由 THREE.BufferGeometry() 和 THREE.ShaderMaterial() 组成。

When I add a colour attribute to a BufferGeometry, only only red (1,0,0), white (1,1,1), or yellow (1,1,0) seem to work.当我向 BufferGeometry 添加颜色属性时,似乎只有红色 (1,0,0)、白色 (1,1,1) 或黄色 (1,1,0) 有效。 This image is when I set the colour to (1,0,0).图像是我将颜色设置为 (1,0,0) 时的图像 This image is when I set the colour to blue (0,0,1).图像是我将颜色设置为蓝色 (0,0,1) 时的图像。

My question is, how do I resolve this?我的问题是,我该如何解决这个问题? Is the issue in the shaders?是着色器的问题吗? Is the issue with how I build the BufferGeometry?我如何构建 BufferGeometry 有问题吗? Is it a bug?这是一个错误吗? Thanks.谢谢。

My shaders:我的着色器:

var vShader = `uniform float size;
        varying vec3 vColor;
        void main() {
            vColor = color;
            vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
            gl_PointSize = size * ( size / (length(mvPosition.xyz) + 0.00001) );
            gl_Position = projectionMatrix * mvPosition;
        }`
        var fShader = `varying vec3 vColor;
        uniform sampler2D sprite;
        void main() {
            gl_FragColor = vec4(vColor, 1.0 ) * texture2D( sprite, gl_PointCoord );
            if (gl_FragColor.x < 0.2) discard;
        }`

My material:我的材料:

var materialForBuffers = new THREE.ShaderMaterial( {
            uniforms: {
                size: { type: 'f', value: this.pointSize},
                sprite: { type: 't', value: THREE.ImageUtils.loadTexture("../data/white.png") },
            },
            vertexShader: vShader,
            fragmentShader: fShader,
            transparent: true,
            vertexColors: true,
        });

How the color is added:如何添加颜色:

const colors = new Float32Array( [ 1.0, 0.0, 0.0 ] );
                geometryForBuffers.addAttribute('color', new THREE.BufferAttribute( colors, 3 ));

Link to code 代码链接

It looks like you may already be using parts of that sample code but if not, please refer to https://github.com/petrbroz/forge-point-clouds/blob/develop/public/scripts/extensions/pointcloud.js (live demo https://forge-point-clouds.autodesk.io ).看起来您可能已经在使用该示例代码的一部分,但如果没有,请参阅https://github.com/petrbroz/forge-point-clouds/blob/develop/public/scripts/extensions/pointcloud.js (现场演示https://forge-point-clouds.autodesk.io )。 This sample code uses the color geometry attribute already to specify colors of individual points.此示例代码已使用color几何属性来指定各个点的颜色。

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

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