Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jniac committed May 28, 2024
1 parent 9320714 commit 15412c3
Show file tree
Hide file tree
Showing 26 changed files with 2,804 additions and 6,899 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ http://localhost:8000/tests/examples-vanilla/triangle/
npm run examples-webpack
```


## Build
```shell
npx rollup -c
```

5 changes: 5 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.10:
- disabling mipmaps
- update to three 0.164.1 (no more "XxxBufferGeometry")
- update tests (vanilla, typescript / webpack)
- update other dev dependencies (rollup, webpack, canvas...)

## 1.0.9:
- enable "alpha discard" when using the "NormalBlending" (fix the z-depth issue).
Expand Down
339 changes: 169 additions & 170 deletions dist/PointTextHelper.three.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/PointTextHelper/PointTextHelper/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { ColorRepresentation } from 'three';
import { Blending, BufferGeometry, Color, ColorRepresentation, Points, Vector3 } from 'three';
import { PointTextHelperMaterial } from './PointTextHelperMaterial';
declare const defaultDisplayParams: {
position: {
x: number;
Expand All @@ -10,26 +10,26 @@ declare const defaultDisplayParams: {
size: number;
text: string;
};
declare type DisplayParams = Partial<typeof defaultDisplayParams>;
declare class PointTextHelper extends THREE.Points {
type DisplayParams = Partial<typeof defaultDisplayParams>;
declare class PointTextHelper extends Points<BufferGeometry, PointTextHelperMaterial> {
private charMax;
constructor({ charMax, blending, zOffset, }?: {
charMax?: number;
blending?: THREE.Blending;
blending?: Blending;
zOffset?: number;
});
private push;
private pushFill;
display(params?: DisplayParams | DisplayParams[]): void;
displayVertices(vertices: THREE.Vector3[] | ArrayLike<number> | THREE.BufferGeometry, options?: {
displayVertices(vertices: Vector3[] | ArrayLike<number> | BufferGeometry, options?: {
size?: number | ((index: number) => number);
color?: ColorRepresentation | ((index: number) => ColorRepresentation);
format?: (index: number) => string;
}): any;
displayFaces(geometry: THREE.BufferGeometry, { color, size, format, }?: {
displayFaces(geometry: BufferGeometry, { color, size, format, }?: {
size?: number;
color?: string | THREE.Color;
color?: string | Color;
format?: (index: number) => string;
}): void;
}
export { PointTextHelper, };
export { PointTextHelper };
8 changes: 8 additions & 0 deletions dist/PointTextHelper/atlas-core.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export declare const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #@&$%?!+-_=*/\\|[](){}<>.;:,\u00D7";
export declare const width = 4096;
export declare const height = 256;
export declare const grid_width = 64;
export declare const grid_height = 2;
export declare const char_width = 64;
export declare const char_height = 120;
export declare const data: string;
9 changes: 1 addition & 8 deletions dist/PointTextHelper/atlas.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import * as utils from './atlas-utils';
export declare const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #@&$%?!+-_=*/\\|[](){}<>.;:,\u00D7";
export declare const width = 4096;
export declare const height = 256;
export declare const grid_width = 64;
export declare const grid_height = 2;
export declare const char_width = 64;
export declare const char_height = 120;
export declare const data: string;
export * from './atlas-core';
export { utils };
43 changes: 20 additions & 23 deletions dist/PointTextHelper/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import atlas_data from './atlas-data.js';
import { Texture, RawShaderMaterial, Vector2, NormalBlending, MultiplyBlending, Points, AdditiveBlending, BufferGeometry, BufferAttribute, Color } from 'three';
import { Texture, RawShaderMaterial, Vector2, NormalBlending, MultiplyBlending, Points, BufferGeometry, BufferAttribute, AdditiveBlending, Color } from 'three';

const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #@&$%?!+-_=*/\\|[](){}<>.;:,×';
const width = 4096;
const height = 256;
const grid_width = 64;
const grid_height = 2;
const char_width = 64;
const char_height = 120;
const data = atlas_data;

const get_char_offset = (char) => {
if (typeof char === 'number') {
Expand Down Expand Up @@ -35,31 +44,22 @@ const get_count_and_offsets = (s, max = 4) => {

var atlasUtils = /*#__PURE__*/Object.freeze({
__proto__: null,
get_char_offset: get_char_offset,
get_char_index: get_char_index,
get_char_offset: get_char_offset,
get_count_and_offsets: get_count_and_offsets
});

const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #@&$%?!+-_=*/\\|[](){}<>.;:,×';
const width = 4096;
const height = 256;
const grid_width = 64;
const grid_height = 2;
const char_width = 64;
const char_height = 120;
const data = atlas_data;

var atlas = /*#__PURE__*/Object.freeze({
__proto__: null,
chars: chars,
width: width,
height: height,
grid_width: grid_width,
grid_height: grid_height,
char_width: char_width,
char_height: char_height,
char_width: char_width,
chars: chars,
data: data,
utils: atlasUtils
grid_height: grid_height,
grid_width: grid_width,
height: height,
utils: atlasUtils,
width: width
});

var vertexShaderSource = "precision highp float;\n#define GLSLIFY 1\n\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float z_offset;\n\nattribute vec3 position;\n\nattribute float char_count;\nvarying float v_char_count;\n\nattribute float size;\n\nattribute vec3 color;\nvarying vec3 v_color;\n\n// REPLACE-DECLARE:\nattribute vec2 char_offset_X;\nvarying vec2 v_char_offset_X;\n// REPLACE-END\n\nvoid main() {\n\n v_char_count = char_count;\n v_color = color;\n \n // REPLACE-COMPUTE:\n v_char_offset_X = char_offset_X;\n // REPLACE-END\n \n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n gl_Position.z += z_offset;\n\tgl_PointSize = size * 2000.0 / -mvPosition.z;\n}"; // eslint-disable-line
Expand Down Expand Up @@ -109,10 +109,10 @@ const get_shaders = (char_max) => {
const img = document.createElement('img');
img.src = data;
const texture = new Texture(img);
texture.generateMipmaps = false; // Important, otherwise the texture is blurry (because texture LOD is not working here).
img.onload = () => texture.needsUpdate = true;
class PointTextHelperMaterial extends RawShaderMaterial {
constructor(char_max, blending, zOffset) {
console.log('PointTextHelperMaterial');
const [vertexShader, fragmentShader] = get_shaders(char_max);
const uniforms = {
atlas_texture: { value: texture },
Expand All @@ -130,7 +130,6 @@ class PointTextHelperMaterial extends RawShaderMaterial {
if (blending === NormalBlending) {
defines.BLEND_NORMAL = true;
}
console.log(uniforms);
super({
uniforms,
defines,
Expand All @@ -142,8 +141,6 @@ class PointTextHelperMaterial extends RawShaderMaterial {
transparent: blending === NormalBlending,
depthWrite: blending === NormalBlending,
});
console.log('yoooooooo');
console.log(this.uniforms);
}
get alpha() { return this.uniforms.opacity.value; }
set alpha(value) {
Expand Down Expand Up @@ -188,7 +185,7 @@ class PointTextHelper extends Points {
geometry.setAttribute(`char_offset_${i}`, new BufferAttribute(new Float32Array(0), 2));
}
const material = new PointTextHelperMaterial(charMax, blending, zOffset);
// const material = new THREE.PointsMaterial({ color: 0x888888 });
// const material = new PointsMaterial({ color: 0x888888 });
super(geometry, material);
this.charMax = charMax;
}
Expand Down
Loading

0 comments on commit 15412c3

Please sign in to comment.