three-text 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -156
- package/dist/index.cjs +370 -81
- package/dist/index.d.ts +46 -17
- package/dist/index.js +369 -80
- package/dist/index.min.cjs +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.umd.js +374 -83
- package/dist/index.umd.min.js +2 -2
- package/dist/p5/index.cjs +33 -0
- package/dist/p5/index.d.ts +19 -0
- package/dist/p5/index.js +31 -0
- package/dist/three/index.cjs +50 -0
- package/dist/three/index.d.ts +29 -0
- package/dist/three/index.js +48 -0
- package/dist/{react/index.cjs → three/react.cjs} +14 -4
- package/dist/three/react.d.ts +346 -0
- package/dist/{react/index.js → three/react.js} +14 -4
- package/dist/types/core/Text.d.ts +1 -1
- package/dist/types/core/cache/GlyphCache.d.ts +4 -4
- package/dist/types/core/cache/GlyphContourCollector.d.ts +2 -2
- package/dist/types/core/cache/GlyphGeometryBuilder.d.ts +3 -2
- package/dist/types/core/geometry/BoundaryClusterer.d.ts +2 -2
- package/dist/types/core/geometry/Polygonizer.d.ts +3 -3
- package/dist/types/core/layout/TextLayout.d.ts +1 -2
- package/dist/types/core/shaping/TextShaper.d.ts +1 -2
- package/dist/types/core/types.d.ts +13 -16
- package/dist/types/core/vectors.d.ts +75 -0
- package/dist/types/p5/index.d.ts +17 -0
- package/dist/types/{react → three}/ThreeText.d.ts +2 -2
- package/dist/types/three/index.d.ts +21 -0
- package/dist/types/three/react.d.ts +10 -0
- package/dist/types/webgl/index.d.ts +48 -0
- package/dist/types/webgpu/index.d.ts +16 -0
- package/dist/webgl/index.cjs +88 -0
- package/dist/webgl/index.d.ts +51 -0
- package/dist/webgl/index.js +86 -0
- package/dist/webgpu/index.cjs +99 -0
- package/dist/webgpu/index.d.ts +19 -0
- package/dist/webgpu/index.js +97 -0
- package/package.json +22 -6
- package/dist/react/index.d.ts +0 -18
- package/dist/types/react/index.d.ts +0 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// WebGPU adapter - lightweight utility to create GPU buffers from core geometry
|
|
2
|
+
function createWebGPUBuffers(device, textGeometry) {
|
|
3
|
+
const { vertices, normals, indices, colors } = textGeometry;
|
|
4
|
+
const vertexCount = indices.length;
|
|
5
|
+
// Interleave position and normal data for better cache coherency
|
|
6
|
+
// Layout: [px, py, pz, nx, ny, nz, px, py, pz, nx, ny, nz, ...]
|
|
7
|
+
const interleavedData = new Float32Array((vertices.length / 3) * 6);
|
|
8
|
+
for (let i = 0; i < vertices.length / 3; i++) {
|
|
9
|
+
const baseIndex = i * 6;
|
|
10
|
+
const vertIndex = i * 3;
|
|
11
|
+
// Position (NO FLIP - pass through)
|
|
12
|
+
interleavedData[baseIndex] = vertices[vertIndex];
|
|
13
|
+
interleavedData[baseIndex + 1] = vertices[vertIndex + 1];
|
|
14
|
+
interleavedData[baseIndex + 2] = vertices[vertIndex + 2];
|
|
15
|
+
// Normal (NO FLIP - pass through)
|
|
16
|
+
interleavedData[baseIndex + 3] = normals[vertIndex];
|
|
17
|
+
interleavedData[baseIndex + 4] = normals[vertIndex + 1];
|
|
18
|
+
interleavedData[baseIndex + 5] = normals[vertIndex + 2];
|
|
19
|
+
}
|
|
20
|
+
// Create vertex buffer with interleaved data
|
|
21
|
+
const vertexBuffer = device.createBuffer({
|
|
22
|
+
size: interleavedData.byteLength,
|
|
23
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
24
|
+
mappedAtCreation: true
|
|
25
|
+
});
|
|
26
|
+
new Float32Array(vertexBuffer.getMappedRange()).set(interleavedData);
|
|
27
|
+
vertexBuffer.unmap();
|
|
28
|
+
// Create index buffer (NO FLIP - pass through)
|
|
29
|
+
const indexBuffer = device.createBuffer({
|
|
30
|
+
size: indices.byteLength,
|
|
31
|
+
usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST,
|
|
32
|
+
mappedAtCreation: true
|
|
33
|
+
});
|
|
34
|
+
new Uint32Array(indexBuffer.getMappedRange()).set(indices);
|
|
35
|
+
indexBuffer.unmap();
|
|
36
|
+
// Vertex buffer layout for interleaved data
|
|
37
|
+
const vertexLayout = {
|
|
38
|
+
arrayStride: 24, // 6 floats * 4 bytes = 24 bytes per vertex
|
|
39
|
+
attributes: [
|
|
40
|
+
{
|
|
41
|
+
shaderLocation: 0,
|
|
42
|
+
offset: 0,
|
|
43
|
+
format: 'float32x3' // position
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
shaderLocation: 1,
|
|
47
|
+
offset: 12, // 3 floats * 4 bytes
|
|
48
|
+
format: 'float32x3' // normal
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const buffers = {
|
|
53
|
+
vertex: vertexBuffer,
|
|
54
|
+
indices: indexBuffer
|
|
55
|
+
};
|
|
56
|
+
const layout = {
|
|
57
|
+
vertex: vertexLayout
|
|
58
|
+
};
|
|
59
|
+
// Optional color buffer
|
|
60
|
+
let colorBuffer;
|
|
61
|
+
let colorLayout;
|
|
62
|
+
if (colors) {
|
|
63
|
+
colorBuffer = device.createBuffer({
|
|
64
|
+
size: colors.byteLength,
|
|
65
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
66
|
+
mappedAtCreation: true
|
|
67
|
+
});
|
|
68
|
+
new Float32Array(colorBuffer.getMappedRange()).set(colors);
|
|
69
|
+
colorBuffer.unmap();
|
|
70
|
+
colorLayout = {
|
|
71
|
+
arrayStride: 12, // 3 floats * 4 bytes
|
|
72
|
+
attributes: [
|
|
73
|
+
{
|
|
74
|
+
shaderLocation: 2,
|
|
75
|
+
offset: 0,
|
|
76
|
+
format: 'float32x3'
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
buffers.color = colorBuffer;
|
|
81
|
+
layout.color = colorLayout;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
buffers,
|
|
85
|
+
layout,
|
|
86
|
+
indexFormat: 'uint32',
|
|
87
|
+
vertexCount,
|
|
88
|
+
dispose() {
|
|
89
|
+
vertexBuffer.destroy();
|
|
90
|
+
indexBuffer.destroy();
|
|
91
|
+
if (colorBuffer)
|
|
92
|
+
colorBuffer.destroy();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { createWebGPUBuffers };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-text",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "3D font rendering and text layout engine for the web",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
@@ -11,9 +11,25 @@
|
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"require": "./dist/index.cjs"
|
|
13
13
|
},
|
|
14
|
-
"./
|
|
15
|
-
"import": "./dist/
|
|
16
|
-
"require": "./dist/
|
|
14
|
+
"./three": {
|
|
15
|
+
"import": "./dist/three/index.js",
|
|
16
|
+
"require": "./dist/three/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./three/react": {
|
|
19
|
+
"import": "./dist/three/react.js",
|
|
20
|
+
"require": "./dist/three/react.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./webgl": {
|
|
23
|
+
"import": "./dist/webgl/index.js",
|
|
24
|
+
"require": "./dist/webgl/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./webgpu": {
|
|
27
|
+
"import": "./dist/webgpu/index.js",
|
|
28
|
+
"require": "./dist/webgpu/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./p5": {
|
|
31
|
+
"import": "./dist/p5/index.js",
|
|
32
|
+
"require": "./dist/p5/index.cjs"
|
|
17
33
|
},
|
|
18
34
|
"./patterns/*": "./dist/patterns/*"
|
|
19
35
|
},
|
|
@@ -30,7 +46,7 @@
|
|
|
30
46
|
"build": "rollup -c && npm run copy:harfbuzz",
|
|
31
47
|
"dev": "rollup -c -w",
|
|
32
48
|
"serve": "npx http-server . -c-1 -p 8080 --cors",
|
|
33
|
-
"clean": "rimraf dist/index.* dist/react dist/hb dist/types",
|
|
49
|
+
"clean": "rimraf dist/index.* dist/react dist/three dist/hb dist/types",
|
|
34
50
|
"prepublishOnly": "npm run clean && npm run test:build && npm run build",
|
|
35
51
|
"test": "vitest run",
|
|
36
52
|
"test:build": "node scripts/verifyBuild.mjs",
|
package/dist/react/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
import { TextOptions, TextGeometryInfo } from '../core/types';
|
|
4
|
-
|
|
5
|
-
interface ThreeTextProps extends Omit<TextOptions, "text"> {
|
|
6
|
-
children: string;
|
|
7
|
-
font: string | ArrayBuffer;
|
|
8
|
-
material?: THREE.Material;
|
|
9
|
-
position?: [number, number, number];
|
|
10
|
-
rotation?: [number, number, number];
|
|
11
|
-
scale?: [number, number, number];
|
|
12
|
-
onLoad?: (geometry: THREE.BufferGeometry, info: TextGeometryInfo) => void;
|
|
13
|
-
onError?: (error: Error) => void;
|
|
14
|
-
vertexColors?: boolean;
|
|
15
|
-
}
|
|
16
|
-
declare const ThreeText: react.ForwardRefExoticComponent<ThreeTextProps & react.RefAttributes<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material | THREE.Material[], THREE.Object3DEventMap>>>;
|
|
17
|
-
|
|
18
|
-
export { ThreeText, ThreeTextProps };
|