以下THREE.js(r83 - latest)代码无错误地运行,并且当 geom 传递给 THREE.Points()时正确呈现,如下所述。
传递 bufferGeometry ,这只是使用 .fromGeometry(geom)从 geom 进行的转换,不会渲染任何内容。没有报告错误。
// "vertexshader"
varying vec3 vColor;
void main()
{
vColor = vec3(1.0, 0.0, 0.0);
gl_PointSize = 2.0;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
// "fragmentshader"
uniform sampler2D texture;
varying vec3 vColor;
void main()
{
gl_FragColor = vec4( vColor, 1.0 );
gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
}
我使用了一个愚蠢的 THREE.js 渲染动画:
var geom = new THREE.Geometry();
...
geom.vertices.push(particle);
...
var customUniforms =
{
texture: { type: "t", value: texture },
};
var material = new THREE.ShaderMaterial(
{
uniforms: customUniforms,
vertexShader: document.getElementById( 'vertexshader' ).textContent,
fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
opacity: .5,
transparent: true,
alphaTest: 0.5,
});
var bufferGeometry = new THREE.BufferGeometry().fromGeometry( geom );
// Renders correctly if I pass in 'geom', does nothing if 'bufferGeometry'
cloud = new THREE.Points(bufferGeometry, material);
...
从我所看到和读到的这应该工作。似乎 .fromGeometry()以某种方式失败但没有报告错误。在Mac(Chrome,Safari)和Windows(Chrome)上测试。
文档很少,但似乎是与转换过程中几何索引相关的 THREE.js 问题( bufferGeometry 将自身报告为nonIndexed)。