@@ -20,24 +20,35 @@ import { getPopulatedCoordinateBuffer } from '../bufferUtils.js';
2020 * @type {import('./index.js').PrimitiveFunction }
2121 */
2222
23- export default function ( { color = [ 0 , 0 , 0 ] , coords, opacity = 1 , pointSize = 1 } , uniforms , extent , container ) {
23+ export default function (
24+ { color = [ 0 , 0 , 0 ] , coords, opacity = 1 , pointSize = 1 } ,
25+ uniforms ,
26+ extent ,
27+ container
28+ ) {
29+ const containerWidth = parseInt ( getComputedStyle ( container ) . width ) ;
30+ const safeWidth =
31+ isNaN ( containerWidth ) || containerWidth <= 0 ? 500 : containerWidth ;
2432
25- const containerWidth = parseInt ( getComputedStyle ( container ) . width ) ;
26- const safeWidth = ( isNaN ( containerWidth ) || containerWidth <= 0 ) ? 500 : containerWidth ;
33+ const validatedSize = isNaN ( pointSize ) || pointSize <= 0 ? 1.0 : pointSize ;
34+ const finalPointSize = ( validatedSize * safeWidth ) . toFixed ( 4 ) ;
2735
28- const validatedSize = ( isNaN ( pointSize ) || pointSize <= 0 ) ? 1.0 : pointSize ;
29- const finalPointSize = ( validatedSize * safeWidth ) . toFixed ( 4 ) ;
30-
31- return new Points (
32- new BufferGeometry ( ) . setAttribute (
33- 'position' ,
34- new BufferAttribute ( getPopulatedCoordinateBuffer ( coords , extent ) , 3 )
35- ) ,
36- new RawShaderMaterial ( {
37- transparent : true ,
38- depthWrite : false ,
39- // 2. THE SHADER SHOULD ONLY RECEIVE THE FINAL NUMBER
40- vertexShader : `#version 300 es
36+ // We are passing a PointsMaterial when we should be passing a RawShaderMaterial.
37+ // rocky doesn't know how to properly fix this. So...
38+ // @ts -ignore
39+ return new Points (
40+ new BufferGeometry ( ) . setAttribute (
41+ 'position' ,
42+ new BufferAttribute (
43+ getPopulatedCoordinateBuffer ( coords , extent ) ,
44+ 3
45+ )
46+ ) ,
47+ new RawShaderMaterial ( {
48+ transparent : true ,
49+ depthWrite : false ,
50+ // 2. THE SHADER SHOULD ONLY RECEIVE THE FINAL NUMBER
51+ vertexShader : `#version 300 es
4152 in vec3 position;
4253 uniform mat4 projectionMatrix;
4354 uniform mat4 modelViewMatrix;
@@ -47,13 +58,13 @@ export default function ({ color = [0, 0, 0], coords, opacity = 1, pointSize = 1
4758 gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1);
4859 }
4960 ` ,
50- fragmentShader : `#version 300 es
61+ fragmentShader : `#version 300 es
5162 out lowp vec4 pc_fragColor;
5263 void main() {
5364 if (length(gl_PointCoord - 0.5) > 0.5) discard;
5465 pc_fragColor = vec4(${ color [ 0 ] } , ${ color [ 1 ] } , ${ color [ 2 ] } , ${ opacity } );
5566 }
5667 `
57- } )
58- ) ;
68+ } )
69+ ) ;
5970}
0 commit comments