xl-public-utils 1.0.12 → 1.0.14
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/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/drcUtils.js +1 -0
- package/src/threeFont/index.js +38 -2
package/index.d.ts
CHANGED
|
@@ -988,7 +988,7 @@ declare module "xl-public-utils" {
|
|
|
988
988
|
bevelSize: number;
|
|
989
989
|
bevelEnabled: boolean;
|
|
990
990
|
}
|
|
991
|
-
|
|
991
|
+
export interface IndexData { zeroIndexs: number[], oneIndexs: number[] };
|
|
992
992
|
export class FontManager {
|
|
993
993
|
private constructor(); // 使用单例模式
|
|
994
994
|
static Mgr(): FontManager;
|
package/package.json
CHANGED
package/src/drcUtils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { vec3 } from "gl-matrix";
|
|
2
2
|
import { int8ArrayToBase64 } from './utils.js'
|
|
3
3
|
import vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData.js";
|
|
4
|
+
import vtkDracoReader from "@kitware/vtk.js/IO/Geometry/DracoReader";
|
|
4
5
|
/**
|
|
5
6
|
* @typedef {Object} AttrOption
|
|
6
7
|
* @property {number[]} [colors] 颜色数组
|
package/src/threeFont/index.js
CHANGED
|
@@ -68,7 +68,7 @@ class FontManager {
|
|
|
68
68
|
* @param {string} text
|
|
69
69
|
* @param {string} fontName
|
|
70
70
|
* @param {vec3} scale
|
|
71
|
-
* @returns {{ polyData:
|
|
71
|
+
* @returns {{ polyData: vtkPolyData, indexData: { zeroIndexs: number[], oneIndexs: number[] } }}
|
|
72
72
|
*/
|
|
73
73
|
generateShapes(text, fontName = 'defaultFont', scale = [0.018, 0.018, 0.018]) {
|
|
74
74
|
const scaleM4 = mat4.scale(mat4.create(), mat4.create(), scale);
|
|
@@ -87,7 +87,9 @@ class FontManager {
|
|
|
87
87
|
|
|
88
88
|
let polyData = this.createPolyData(extrude.vertices, extrude.faces);
|
|
89
89
|
polyData = deduplicatePolyData(polyData);
|
|
90
|
+
polyData = this.reIndexPolyData(polyData);
|
|
90
91
|
const indexData = this.getPointsMapData(polyData);
|
|
92
|
+
// console.log(indexData);
|
|
91
93
|
|
|
92
94
|
const _polyData = clonePolyData(polyData);
|
|
93
95
|
pointsApplyMat4(scaleM4, _polyData);
|
|
@@ -103,7 +105,7 @@ class FontManager {
|
|
|
103
105
|
|
|
104
106
|
/**
|
|
105
107
|
* 获取前后层顶点索引映射数据
|
|
106
|
-
* @param {
|
|
108
|
+
* @param {vtkPolyData} polydata
|
|
107
109
|
* @returns {{ zeroIndexs: number[], oneIndexs: number[] }}
|
|
108
110
|
*/
|
|
109
111
|
getPointsMapData(polydata) {
|
|
@@ -134,6 +136,40 @@ class FontManager {
|
|
|
134
136
|
oneIndexs
|
|
135
137
|
};
|
|
136
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param {vtkPolyData} polydata
|
|
142
|
+
* @returns {vtkPolyData} 重组索引之后的polydata
|
|
143
|
+
*/
|
|
144
|
+
reIndexPolyData(polydata) {
|
|
145
|
+
const indexData = this.getPointsMapData(polydata);
|
|
146
|
+
const allIndexData = [...indexData.zeroIndexs, ...indexData.oneIndexs]
|
|
147
|
+
const nowPoints = polydata.getPoints().getData();
|
|
148
|
+
const nowFaces = polydata.getPolys().getData();
|
|
149
|
+
const newPoints = new Float32Array(nowPoints.length);
|
|
150
|
+
const indexMap = {};
|
|
151
|
+
for(let i = 0; i < allIndexData.length; i++) {
|
|
152
|
+
const index = allIndexData[i];
|
|
153
|
+
const x = nowPoints[index * 3];
|
|
154
|
+
const y = nowPoints[index * 3 + 1];
|
|
155
|
+
const z = nowPoints[index * 3 + 2];
|
|
156
|
+
newPoints[i * 3] = x
|
|
157
|
+
newPoints[i * 3 + 1] = y
|
|
158
|
+
newPoints[i * 3 + 2] = z
|
|
159
|
+
indexMap[index] = i;
|
|
160
|
+
}
|
|
161
|
+
for(let i =0; i< nowFaces.length; i += 4) {
|
|
162
|
+
const p1 = nowFaces[i + 1];
|
|
163
|
+
const p2 = nowFaces[i + 2]
|
|
164
|
+
const p3 = nowFaces[i + 3]
|
|
165
|
+
nowFaces[i + 1] = indexMap[p1]
|
|
166
|
+
nowFaces[i + 2] = indexMap[p2]
|
|
167
|
+
nowFaces[i + 3] = indexMap[p3]
|
|
168
|
+
}
|
|
169
|
+
polydata.getPoints().setData(newPoints);
|
|
170
|
+
polydata.getPolys().setData(nowFaces);
|
|
171
|
+
return polydata
|
|
172
|
+
}
|
|
137
173
|
|
|
138
174
|
/**
|
|
139
175
|
* 创建 vtkPolyData 对象
|