three-text 0.2.18 → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  // WebGPU adapter - lightweight utility to create GPU buffers from core geometry
2
2
  function createWebGPUBuffers(device, textGeometry) {
3
- const { vertices, normals, indices, colors } = textGeometry;
3
+ const { vertices, normals, indices, colors, glyphAttributes } = textGeometry;
4
4
  const indexCount = indices.length;
5
5
  const indexFormat = indices instanceof Uint16Array ? 'uint16' : 'uint32';
6
6
  // Interleave position and normal data for better cache coherency
@@ -81,6 +81,75 @@ function createWebGPUBuffers(device, textGeometry) {
81
81
  buffers.color = colorBuffer;
82
82
  layout.color = colorLayout;
83
83
  }
84
+ // Optional glyph attribute buffers
85
+ let glyphCenterBuffer;
86
+ let glyphIndexBuffer;
87
+ let glyphLineIndexBuffer;
88
+ let glyphProgressBuffer;
89
+ let glyphBaselineYBuffer;
90
+ if (glyphAttributes) {
91
+ let nextShaderLocation = colors ? 3 : 2;
92
+ glyphCenterBuffer = device.createBuffer({
93
+ size: glyphAttributes.glyphCenter.byteLength,
94
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
95
+ mappedAtCreation: true
96
+ });
97
+ new Float32Array(glyphCenterBuffer.getMappedRange()).set(glyphAttributes.glyphCenter);
98
+ glyphCenterBuffer.unmap();
99
+ buffers.glyphCenter = glyphCenterBuffer;
100
+ layout.glyphCenter = {
101
+ arrayStride: 12,
102
+ attributes: [{ shaderLocation: nextShaderLocation++, offset: 0, format: 'float32x3' }]
103
+ };
104
+ glyphIndexBuffer = device.createBuffer({
105
+ size: glyphAttributes.glyphIndex.byteLength,
106
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
107
+ mappedAtCreation: true
108
+ });
109
+ new Float32Array(glyphIndexBuffer.getMappedRange()).set(glyphAttributes.glyphIndex);
110
+ glyphIndexBuffer.unmap();
111
+ buffers.glyphIndex = glyphIndexBuffer;
112
+ layout.glyphIndex = {
113
+ arrayStride: 4,
114
+ attributes: [{ shaderLocation: nextShaderLocation++, offset: 0, format: 'float32' }]
115
+ };
116
+ glyphLineIndexBuffer = device.createBuffer({
117
+ size: glyphAttributes.glyphLineIndex.byteLength,
118
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
119
+ mappedAtCreation: true
120
+ });
121
+ new Float32Array(glyphLineIndexBuffer.getMappedRange()).set(glyphAttributes.glyphLineIndex);
122
+ glyphLineIndexBuffer.unmap();
123
+ buffers.glyphLineIndex = glyphLineIndexBuffer;
124
+ layout.glyphLineIndex = {
125
+ arrayStride: 4,
126
+ attributes: [{ shaderLocation: nextShaderLocation++, offset: 0, format: 'float32' }]
127
+ };
128
+ glyphProgressBuffer = device.createBuffer({
129
+ size: glyphAttributes.glyphProgress.byteLength,
130
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
131
+ mappedAtCreation: true
132
+ });
133
+ new Float32Array(glyphProgressBuffer.getMappedRange()).set(glyphAttributes.glyphProgress);
134
+ glyphProgressBuffer.unmap();
135
+ buffers.glyphProgress = glyphProgressBuffer;
136
+ layout.glyphProgress = {
137
+ arrayStride: 4,
138
+ attributes: [{ shaderLocation: nextShaderLocation++, offset: 0, format: 'float32' }]
139
+ };
140
+ glyphBaselineYBuffer = device.createBuffer({
141
+ size: glyphAttributes.glyphBaselineY.byteLength,
142
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
143
+ mappedAtCreation: true
144
+ });
145
+ new Float32Array(glyphBaselineYBuffer.getMappedRange()).set(glyphAttributes.glyphBaselineY);
146
+ glyphBaselineYBuffer.unmap();
147
+ buffers.glyphBaselineY = glyphBaselineYBuffer;
148
+ layout.glyphBaselineY = {
149
+ arrayStride: 4,
150
+ attributes: [{ shaderLocation: nextShaderLocation++, offset: 0, format: 'float32' }]
151
+ };
152
+ }
84
153
  return {
85
154
  buffers,
86
155
  layout,
@@ -91,6 +160,16 @@ function createWebGPUBuffers(device, textGeometry) {
91
160
  indexBuffer.destroy();
92
161
  if (colorBuffer)
93
162
  colorBuffer.destroy();
163
+ if (glyphCenterBuffer)
164
+ glyphCenterBuffer.destroy();
165
+ if (glyphIndexBuffer)
166
+ glyphIndexBuffer.destroy();
167
+ if (glyphLineIndexBuffer)
168
+ glyphLineIndexBuffer.destroy();
169
+ if (glyphProgressBuffer)
170
+ glyphProgressBuffer.destroy();
171
+ if (glyphBaselineYBuffer)
172
+ glyphBaselineYBuffer.destroy();
94
173
  }
95
174
  };
96
175
  }
package/package.json CHANGED
@@ -1,37 +1,52 @@
1
1
  {
2
2
  "name": "three-text",
3
- "version": "0.2.18",
4
- "description": "3D font rendering and text layout engine for the web",
5
- "main": "dist/index.cjs",
6
- "module": "dist/index.js",
3
+ "version": "0.3.0",
4
+ "description": "3D mesh font geometry and text layout engine for the web",
5
+ "main": "dist/three/index.cjs",
6
+ "module": "dist/three/index.js",
7
7
  "type": "module",
8
- "types": "dist/index.d.ts",
8
+ "types": "dist/three/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
+ "types": "./dist/three/index.d.ts",
12
+ "import": "./dist/three/index.js",
13
+ "require": "./dist/three/index.cjs"
14
+ },
15
+ "./core": {
16
+ "types": "./dist/index.d.ts",
11
17
  "import": "./dist/index.js",
12
18
  "require": "./dist/index.cjs"
13
19
  },
14
20
  "./three": {
21
+ "types": "./dist/three/index.d.ts",
15
22
  "import": "./dist/three/index.js",
16
23
  "require": "./dist/three/index.cjs"
17
24
  },
18
25
  "./three/react": {
26
+ "types": "./dist/three/react.d.ts",
19
27
  "import": "./dist/three/react.js",
20
28
  "require": "./dist/three/react.cjs"
21
29
  },
22
30
  "./webgl": {
31
+ "types": "./dist/webgl/index.d.ts",
23
32
  "import": "./dist/webgl/index.js",
24
33
  "require": "./dist/webgl/index.cjs"
25
34
  },
26
35
  "./webgpu": {
36
+ "types": "./dist/webgpu/index.d.ts",
27
37
  "import": "./dist/webgpu/index.js",
28
38
  "require": "./dist/webgpu/index.cjs"
29
39
  },
30
40
  "./p5": {
41
+ "types": "./dist/p5/index.d.ts",
31
42
  "import": "./dist/p5/index.js",
32
43
  "require": "./dist/p5/index.cjs"
33
44
  },
34
- "./patterns/*": "./dist/patterns/*"
45
+ "./patterns/*": {
46
+ "types": "./dist/patterns/*.d.ts",
47
+ "import": "./dist/patterns/*.js",
48
+ "require": "./dist/patterns/*.cjs"
49
+ }
35
50
  },
36
51
  "files": [
37
52
  "dist",
@@ -95,6 +110,7 @@
95
110
  "libtess": "^1.2.2"
96
111
  },
97
112
  "devDependencies": {
113
+ "@webgpu/types": "^0.1.64",
98
114
  "@react-three/fiber": ">=8.0.0",
99
115
  "@rollup/plugin-commonjs": "^25.0.0",
100
116
  "@rollup/plugin-node-resolve": "^15.0.0",