@kitware/vtk.js 34.5.0 → 34.7.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.
Files changed (70) hide show
  1. package/Common/Core/CellArray.d.ts +3 -0
  2. package/Common/Core/CellArray.js +12 -1
  3. package/Common/Core/DataArray.d.ts +15 -0
  4. package/Common/Core/DataArray.js +8 -4
  5. package/Common/Core/Math/index.js +12 -1
  6. package/Common/Core/Math.d.ts +24 -18
  7. package/Common/Core/Math.js +1 -1
  8. package/Common/DataModel/Triangle.d.ts +68 -19
  9. package/Common/DataModel/Triangle.js +136 -2
  10. package/Common/DataModel/TriangleStrip.d.ts +180 -0
  11. package/Common/DataModel/TriangleStrip.js +396 -0
  12. package/Common/DataModel.js +3 -1
  13. package/Common/Transform/LandmarkTransform.js +1 -1
  14. package/Common/Transform/Transform.d.ts +112 -1
  15. package/Common/Transform/Transform.js +301 -2
  16. package/Filters/Core/Cutter.js +42 -0
  17. package/Filters/General/OBBTree.js +1 -1
  18. package/Filters/General/TransformPolyDataFilter.d.ts +75 -0
  19. package/Filters/General/TransformPolyDataFilter.js +194 -0
  20. package/Filters/General.js +2 -0
  21. package/Filters/Sources/CircleSource.js +1 -1
  22. package/Filters/Sources/PointSource.js +1 -1
  23. package/Filters/Texture/TextureMapToPlane.js +1 -1
  24. package/IO/Geometry/DracoReader.js +1 -1
  25. package/IO/Geometry/GLTFImporter/Animations.js +1 -1
  26. package/IO/Geometry/GLTFImporter/Reader.js +2 -2
  27. package/IO/Image/HDRReader/Utils.js +1 -1
  28. package/IO/Image/HDRReader.js +1 -1
  29. package/IO/Misc/OBJWriter.d.ts +103 -0
  30. package/IO/Misc/OBJWriter.js +235 -0
  31. package/IO/Misc.js +2 -0
  32. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
  33. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  34. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +1 -1
  35. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
  36. package/Interaction/Style/InteractorStyleManipulator.js +75 -2
  37. package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
  38. package/Interaction/Widgets/PiecewiseGaussianWidget.js +1 -1
  39. package/Proxy/Core/View2DProxy.js +1 -1
  40. package/Rendering/Core/AbstractImageMapper.js +1 -1
  41. package/Rendering/Core/AbstractMapper3D.js +1 -1
  42. package/Rendering/Core/Camera.d.ts +3 -3
  43. package/Rendering/Core/Camera.js +33 -3
  44. package/Rendering/Core/ColorTransferFunction/CssFilters.js +1 -1
  45. package/Rendering/Core/ColorTransferFunction.js +1 -1
  46. package/Rendering/Core/Coordinate.js +1 -1
  47. package/Rendering/Core/CubeAxesActor.js +1 -1
  48. package/Rendering/Core/Glyph3DMapper.js +1 -1
  49. package/Rendering/Core/ImageArrayMapper.js +1 -1
  50. package/Rendering/Core/ImageMapper.js +1 -1
  51. package/Rendering/Core/Mapper.js +1 -1
  52. package/Rendering/Core/Prop3D.js +1 -1
  53. package/Rendering/Core/RenderWindowInteractor.js +3 -3
  54. package/Rendering/Core/Renderer.js +1 -1
  55. package/Rendering/Core/ScalarBarActor.js +1 -1
  56. package/Rendering/Core/TextActor.js +1 -1
  57. package/Rendering/Core/VectorText/Utils.js +1 -1
  58. package/Rendering/Core/VolumeProperty.js +1 -1
  59. package/Rendering/OpenGL/PolyDataMapper2D.js +1 -1
  60. package/Rendering/OpenGL/Texture.js +1 -1
  61. package/Rendering/OpenGL/VolumeMapper.js +21 -19
  62. package/Widgets/Manipulators/LineManipulator.js +1 -1
  63. package/Widgets/Representations/PolyLineRepresentation.js +1 -1
  64. package/Widgets/Widgets3D/AngleWidget.js +1 -1
  65. package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
  66. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
  67. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
  68. package/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
  69. package/index.d.ts +3 -0
  70. package/package.json +1 -1
@@ -0,0 +1,194 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import vtkDataArray from '../../Common/Core/DataArray.js';
3
+ import vtkPoints from '../../Common/Core/Points.js';
4
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
5
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
6
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
7
+
8
+ const {
9
+ vtkErrorMacro
10
+ } = macro;
11
+
12
+ // ----------------------------------------------------------------------------
13
+ // vtkTransformPolyDataFilter methods
14
+ // ----------------------------------------------------------------------------
15
+
16
+ function vtkTransformPolyDataFilter(publicAPI, model) {
17
+ // Set our className
18
+ model.classHierarchy.push('vtkTransformPolyDataFilter');
19
+
20
+ // Internal method to handle the actual transformation
21
+ function transformPolyData(input, output) {
22
+ if (!model.transform) {
23
+ vtkErrorMacro('No transform defined!');
24
+ return false;
25
+ }
26
+ const inPts = input.getPoints();
27
+ const inPtData = input.getPointData();
28
+ const outPD = output.getPointData();
29
+ const inCellData = input.getCellData();
30
+ const outCD = output.getCellData();
31
+ if (!inPts) {
32
+ // Input polydata is empty. This is not an error, the output will be just empty, too.
33
+ return true;
34
+ }
35
+ const numPoints = inPts.getNumberOfPoints();
36
+
37
+ // Get input vectors and normals (points and cells)
38
+ const inVectors = inPtData.getVectors();
39
+ const inNormals = inPtData.getNormals();
40
+ const inCellVectors = inCellData.getVectors();
41
+ const inCellNormals = inCellData.getNormals();
42
+
43
+ // Set the desired precision for the points in the output
44
+ let pointType = inPts.getDataType();
45
+ if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
46
+ pointType = VtkDataTypes.FLOAT;
47
+ } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
48
+ pointType = VtkDataTypes.DOUBLE;
49
+ }
50
+
51
+ // Create output points with appropriate precision
52
+ const outPts = vtkPoints.newInstance({
53
+ dataType: pointType
54
+ });
55
+
56
+ // Transform points
57
+ const inPtsData = inPts.getData();
58
+ outPts.setNumberOfPoints(numPoints);
59
+ const outPtsData = outPts.getData();
60
+
61
+ // Transform vectors if present
62
+ let outVectors = null;
63
+ if (inVectors) {
64
+ outVectors = vtkDataArray.newInstance({
65
+ name: inVectors.getName(),
66
+ numberOfComponents: 3,
67
+ size: numPoints * 3
68
+ });
69
+ }
70
+
71
+ // Transform normals if present
72
+ let outNormals = null;
73
+ if (inNormals) {
74
+ outNormals = vtkDataArray.newInstance({
75
+ name: inNormals.getName(),
76
+ numberOfComponents: 3,
77
+ size: numPoints * 3
78
+ });
79
+ }
80
+ if (inVectors || inNormals) {
81
+ model.transform.transformPointsNormalsVectors(inPts, outPts, inNormals, outNormals, inVectors, outVectors);
82
+ } else {
83
+ model.transform.transformPoints(inPtsData, outPtsData);
84
+ }
85
+
86
+ // Transform cell vectors if present
87
+ let outCellVectors = null;
88
+ if (inCellVectors) {
89
+ const numCells = inCellVectors.getNumberOfTuples();
90
+ outCellVectors = vtkDataArray.newInstance({
91
+ name: inCellVectors.getName(),
92
+ numberOfComponents: 3,
93
+ size: numCells * 3
94
+ });
95
+ model.transform.transformVectors(inCellVectors, outCellVectors);
96
+ }
97
+
98
+ // Transform cell normals if present
99
+ let outCellNormals = null;
100
+ if (inCellNormals) {
101
+ const numCells = inCellNormals.getNumberOfTuples();
102
+ outCellNormals = vtkDataArray.newInstance({
103
+ name: inCellNormals.getName(),
104
+ numberOfComponents: 3,
105
+ size: numCells * 3
106
+ });
107
+ model.transform.transformNormals(inCellNormals, outCellNormals);
108
+ }
109
+
110
+ // Set output data
111
+ output.setPoints(outPts);
112
+
113
+ // Copy cell topology
114
+ output.setVerts(input.getVerts());
115
+ output.setLines(input.getLines());
116
+ output.setPolys(input.getPolys());
117
+ output.setStrips(input.getStrips());
118
+
119
+ // Set transformed point data
120
+ if (outNormals) {
121
+ outPD.setNormals(outNormals);
122
+ outPD.copyFieldOff(outNormals.getName());
123
+ }
124
+ if (outVectors) {
125
+ outPD.setVectors(outVectors);
126
+ outPD.copyFieldOff(outVectors.getName());
127
+ }
128
+
129
+ // Set transformed cell data
130
+ if (outCellNormals) {
131
+ outCD.setNormals(outCellNormals);
132
+ outCD.copyFieldOff(outCellNormals.getName());
133
+ }
134
+ if (outCellVectors) {
135
+ outCD.setVectors(outCellVectors);
136
+ outCD.copyFieldOff(outCellVectors.getName());
137
+ }
138
+
139
+ // Pass through other data
140
+ outPD.passData(inPtData);
141
+ outCD.passData(inCellData);
142
+ return true;
143
+ }
144
+ publicAPI.requestData = (inData, outData) => {
145
+ const input = inData[0];
146
+ const output = outData[0] || vtkPolyData.newInstance();
147
+ if (transformPolyData(input, output)) {
148
+ outData[0] = output;
149
+ } else {
150
+ vtkErrorMacro('TransformPolyDataFilter failed to transform input data.');
151
+ }
152
+ };
153
+ }
154
+
155
+ // ----------------------------------------------------------------------------
156
+ // Object factory
157
+ // ----------------------------------------------------------------------------
158
+
159
+ const DEFAULT_VALUES = {
160
+ transform: null,
161
+ outputPointsPrecision: DesiredOutputPrecision.DEFAULT
162
+ };
163
+
164
+ // ----------------------------------------------------------------------------
165
+
166
+ function extend(publicAPI, model) {
167
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
168
+ Object.assign(model, DEFAULT_VALUES, initialValues);
169
+
170
+ // Make this a VTK object
171
+ macro.obj(publicAPI, model);
172
+
173
+ // Also make it an algorithm with one input and one output
174
+ macro.algo(publicAPI, model, 1, 1);
175
+
176
+ // Set/Get methods
177
+ macro.setGet(publicAPI, model, ['transform', 'outputPointsPrecision']);
178
+
179
+ // Object specific methods
180
+ vtkTransformPolyDataFilter(publicAPI, model);
181
+ }
182
+
183
+ // ----------------------------------------------------------------------------
184
+
185
+ const newInstance = macro.newInstance(extend, 'vtkTransformPolyDataFilter');
186
+
187
+ // ----------------------------------------------------------------------------
188
+
189
+ var vtkTransformPolyDataFilter$1 = {
190
+ newInstance,
191
+ extend
192
+ };
193
+
194
+ export { vtkTransformPolyDataFilter$1 as default, extend, newInstance };
@@ -15,6 +15,7 @@ import vtkOBBTree from './General/OBBTree.js';
15
15
  import vtkOutlineFilter from './General/OutlineFilter.js';
16
16
  import vtkPaintFilter from './General/PaintFilter.js';
17
17
  import vtkScalarToRGBA from './General/ScalarToRGBA.js';
18
+ import vtkTransformPolyDataFilter from './General/TransformPolyDataFilter.js';
18
19
  import vtkTriangleFilter from './General/TriangleFilter.js';
19
20
  import vtkTubeFilter from './General/TubeFilter.js';
20
21
  import vtkWarpScalar from './General/WarpScalar.js';
@@ -38,6 +39,7 @@ var General = {
38
39
  vtkOutlineFilter,
39
40
  vtkPaintFilter,
40
41
  vtkScalarToRGBA,
42
+ vtkTransformPolyDataFilter,
41
43
  vtkTriangleFilter,
42
44
  vtkTubeFilter,
43
45
  vtkWarpScalar,
@@ -1,7 +1,7 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
3
3
  import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
4
- import { w as multiplyScalar } from '../../Common/Core/Math/index.js';
4
+ import { x as multiplyScalar } from '../../Common/Core/Math/index.js';
5
5
 
6
6
  // ----------------------------------------------------------------------------
7
7
  // vtkCircleSource methods
@@ -1,5 +1,5 @@
1
1
  import { m as macro } from '../../macros2.js';
2
- import { x as random } from '../../Common/Core/Math/index.js';
2
+ import { y as random } from '../../Common/Core/Math/index.js';
3
3
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
4
4
 
5
5
  // ----------------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkDataArray from '../../Common/Core/DataArray.js';
3
- import { l as normalize, d as dot, j as cross, e as distance2BetweenPoints, y as determinant3x3, z as rowsToMat3 } from '../../Common/Core/Math/index.js';
3
+ import { l as normalize, d as dot, j as cross, e as distance2BetweenPoints, z as determinant3x3, A as rowsToMat3 } from '../../Common/Core/Math/index.js';
4
4
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
5
5
 
6
6
  const {
@@ -137,7 +137,7 @@ function getPolyDataFromDracoGeometry(decoder, dracoGeometry) {
137
137
  const indices = decodeIndices(decoder, dracoGeometry);
138
138
  const nCells = indices.length - 2;
139
139
  const cells = vtkCellArray.newInstance();
140
- cells.resize(4 * indices.length / 3);
140
+ cells.allocate(4 * indices.length / 3);
141
141
  for (let cellId = 0; cellId < nCells; cellId += 3) {
142
142
  const cell = indices.slice(cellId, cellId + 3);
143
143
  cells.insertNextCell(cell);
@@ -1,5 +1,5 @@
1
1
  import { m as macro } from '../../../macros2.js';
2
- import { A as degreesFromRadians } from '../../../Common/Core/Math/index.js';
2
+ import { B as degreesFromRadians } from '../../../Common/Core/Math/index.js';
3
3
  import { quat, vec3 } from 'gl-matrix';
4
4
 
5
5
  const {
@@ -1,5 +1,5 @@
1
1
  import { m as macro } from '../../../macros2.js';
2
- import { A as degreesFromRadians } from '../../../Common/Core/Math/index.js';
2
+ import { B as degreesFromRadians } from '../../../Common/Core/Math/index.js';
3
3
  import vtkActor from '../../../Rendering/Core/Actor.js';
4
4
  import vtkCamera from '../../../Rendering/Core/Camera.js';
5
5
  import vtkDataArray from '../../../Common/Core/DataArray.js';
@@ -125,7 +125,7 @@ async function createPolyDataFromGLTFMesh(primitive) {
125
125
  vtkWarningMacro('GL_LINE_LOOP not implemented');
126
126
  break;
127
127
  default:
128
- cells.resize(4 * indices.length / 3);
128
+ cells.allocate(4 * indices.length / 3);
129
129
  for (let cellId = 0; cellId < nCells; cellId += 3) {
130
130
  const cell = indices.slice(cellId, cellId + 3);
131
131
  cells.insertNextCell(cell);
@@ -1,4 +1,4 @@
1
- import { B as ldexp } from '../../../Common/Core/Math/index.js';
1
+ import { C as ldexp } from '../../../Common/Core/Math/index.js';
2
2
 
3
3
  /**
4
4
  * Read a line from a Uint8Array
@@ -1,7 +1,7 @@
1
1
  import '../Core/DataAccessHelper/LiteHttpDataAccessHelper.js';
2
2
  import { m as macro } from '../../macros2.js';
3
3
  import DataAccessHelper from '../Core/DataAccessHelper.js';
4
- import { C as xyz2rgb } from '../../Common/Core/Math/index.js';
4
+ import { D as xyz2rgb } from '../../Common/Core/Math/index.js';
5
5
  import vtkImageData from '../../Common/DataModel/ImageData.js';
6
6
  import vtkDataArray from '../../Common/Core/DataArray.js';
7
7
  import { readLine, rgbe2float } from './HDRReader/Utils.js';
@@ -0,0 +1,103 @@
1
+ import vtkPolyData from './../../Common/DataModel/PolyData';
2
+ import vtkTexture from './../../Rendering/Core/Texture';
3
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export interface IOBJWriterInitialValues {
9
+ modelFilename?: string;
10
+ materialFilename?: string;
11
+ texture?: vtkTexture;
12
+ textureFileName?: string;
13
+ }
14
+
15
+ type vtkOBJWriterBase = vtkObject & vtkAlgorithm;
16
+
17
+ export interface vtkOBJWriter extends vtkOBJWriterBase {
18
+ /**
19
+ * Get the zip file containing the OBJ and MTL files.
20
+ */
21
+ exportAsZip(): Promise<Uint8Array>;
22
+
23
+ /**
24
+ * Get the MTL file as a string.
25
+ */
26
+ getMtl(): string;
27
+
28
+ /**
29
+ *
30
+ * @param inData
31
+ * @param outData
32
+ */
33
+ requestData(inData: any, outData: any): void;
34
+
35
+ /**
36
+ * Set the material filename.
37
+ * @param materialFilename
38
+ * @returns {boolean} true if the material file name was set successfully
39
+ */
40
+ setMaterialFilename(materialFilename: string): boolean;
41
+
42
+ /**
43
+ * Set the model filename.
44
+ * @param modelFilename
45
+ */
46
+ setModelFilename(modelFilename: string): boolean;
47
+
48
+ /**
49
+ * Set the texture instance.
50
+ * @param {vtkTexture} texture
51
+ * @returns {boolean} true if the texture was set successfully
52
+ */
53
+ setTexture(texture: vtkTexture): boolean;
54
+
55
+ /**
56
+ * Set the texture file name.
57
+ * @param {string} textureFileName
58
+ * @returns {boolean} true if the texture file name was set successfully
59
+ */
60
+ setTextureFileName(textureFileName: string): boolean;
61
+ }
62
+
63
+ /**
64
+ * Method used to decorate a given object (publicAPI+model) with vtkOBJWriter characteristics.
65
+ *
66
+ * @param publicAPI object on which methods will be bounds (public)
67
+ * @param model object on which data structure will be bounds (protected)
68
+ * @param {IOBJWriterInitialValues} [initialValues] (default: {})
69
+ */
70
+ export function extend(
71
+ publicAPI: object,
72
+ model: object,
73
+ initialValues?: IOBJWriterInitialValues
74
+ ): void;
75
+
76
+ /**
77
+ * Method used to create a new instance of vtkOBJWriter
78
+ * @param {IOBJWriterInitialValues} [initialValues] for pre-setting some of its content
79
+ */
80
+ export function newInstance(
81
+ initialValues?: IOBJWriterInitialValues
82
+ ): vtkOBJWriter;
83
+
84
+ /**
85
+ *
86
+ * @param {vktPolyData} polyData
87
+ */
88
+ export function writeOBJ(polyData: vtkPolyData): vtkPolyData;
89
+
90
+ /**
91
+ * vtkOBJWriter writes wavefront obj (.obj) files in ASCII form. OBJ files
92
+ * contain the geometry including lines, triangles and polygons. Normals and
93
+ * texture coordinates on points are also written if they exist.
94
+ *
95
+ * One can specify a texture passing a vtkTexture using `setTexture`. If a texture is
96
+ * set, additional .mtl and .png files are generated.
97
+ */
98
+ export declare const vtkOBJWriter: {
99
+ newInstance: typeof newInstance;
100
+ extend: typeof extend;
101
+ writeOBJ: typeof writeOBJ;
102
+ };
103
+ export default vtkOBJWriter;
@@ -0,0 +1,235 @@
1
+ import { strToU8, zipSync } from 'fflate';
2
+ import { m as macro } from '../../macros2.js';
3
+ import vtkCellArray from '../../Common/Core/CellArray.js';
4
+ import vtkTriangleStrip from '../../Common/DataModel/TriangleStrip.js';
5
+
6
+ const {
7
+ vtkErrorMacro
8
+ } = macro;
9
+
10
+ // ----------------------------------------------------------------------------
11
+ // Global methods
12
+ // ----------------------------------------------------------------------------
13
+
14
+ // ----------------------------------------------------------------------------
15
+ // vtkOBJWriter methods
16
+ // ----------------------------------------------------------------------------
17
+
18
+ const writeFaces = (faces, withNormals, withTCoords) => {
19
+ let outputData = '';
20
+ const fd = faces.getData();
21
+ let offset = 0;
22
+ while (offset < fd.length) {
23
+ const faceSize = fd[offset++];
24
+ outputData += 'f';
25
+ for (let i = 0; i < faceSize; i++) {
26
+ outputData += ` ${fd[offset + i] + 1}`;
27
+ if (withTCoords) {
28
+ outputData += `/${fd[offset + i] + 1}`;
29
+ if (withNormals) {
30
+ outputData += `//${fd[offset + i] + 1}`;
31
+ }
32
+ } else if (withNormals) {
33
+ outputData += `//${fd[offset + i] + 1}`;
34
+ }
35
+ }
36
+ offset += faceSize;
37
+ outputData += '\n';
38
+ }
39
+ return outputData;
40
+ };
41
+ const writeLines = lines => {
42
+ let outputData = '';
43
+ const ld = lines.getData();
44
+ let offset = 0;
45
+ while (offset < ld.length) {
46
+ const lineSize = ld[offset++];
47
+ outputData += 'l';
48
+ for (let i = 0; i < lineSize; i++) {
49
+ outputData += ` ${ld[offset + i] + 1}`;
50
+ }
51
+ offset += lineSize;
52
+ outputData += '\n';
53
+ }
54
+ return outputData;
55
+ };
56
+ const writePoints = (pts, normals, tcoords) => {
57
+ const outputData = [];
58
+ const nbPts = pts.getNumberOfPoints();
59
+ let p;
60
+
61
+ // Positions
62
+ for (let i = 0; i < nbPts; i++) {
63
+ p = pts.getPoint(i);
64
+ outputData.push(`v ${p[0]} ${p[1]} ${p[2]}`);
65
+ }
66
+
67
+ // Normals
68
+ if (normals) {
69
+ for (let i = 0; i < nbPts; i++) {
70
+ p = normals.getTuple(i);
71
+ outputData.push(`vn ${p[0]} ${p[1]} ${p[2]}`);
72
+ }
73
+ }
74
+
75
+ // Textures
76
+ if (tcoords) {
77
+ for (let i = 0; i < nbPts; i++) {
78
+ p = tcoords.getTuple(i);
79
+ if (p[0] !== -1.0) {
80
+ outputData.push(`vt ${p[0]} ${p[1]}`);
81
+ }
82
+ }
83
+ }
84
+ return `${outputData.join('\n')}\n`;
85
+ };
86
+ const writeMTL = (materialName, textureFileName) => {
87
+ const outputData = [];
88
+ outputData.push(`newmtl ${materialName}`);
89
+ outputData.push(`map_Kd ${textureFileName}`);
90
+ return outputData.join('\n');
91
+ };
92
+ const writeOBJ = (polyData, materialFilename, materialName) => {
93
+ let outputData = '# VTK.js generated OBJ File\n';
94
+ const pts = polyData.getPoints();
95
+ const polys = polyData.getPolys();
96
+ const strips = polyData.getStrips() ? polyData.getStrips().getData() : null;
97
+ const lines = polyData.getLines();
98
+ const normals = polyData.getPointData().getNormals();
99
+ const tcoords = polyData.getPointData().getTCoords();
100
+ const hasPtNormals = normals !== null;
101
+ const hasPtTCoords = tcoords !== null;
102
+ if (!pts) {
103
+ vtkErrorMacro('No data to write!');
104
+ return outputData;
105
+ }
106
+ if (materialFilename) {
107
+ // Write material library
108
+ outputData += `mtllib ${materialFilename}\n`;
109
+ }
110
+
111
+ // Write material if a texture is specified
112
+ if (materialName) {
113
+ // declare material in obj file
114
+ outputData += `usemtl ${materialName}\n`;
115
+ }
116
+
117
+ // Write points
118
+ outputData += writePoints(pts, normals, tcoords);
119
+
120
+ // Decompose any triangle strips into triangles
121
+ const polyStrips = vtkCellArray.newInstance();
122
+ if (strips && strips.length > 0) {
123
+ vtkTriangleStrip.decomposeStrip(pts, polyStrips);
124
+ }
125
+
126
+ // Write triangle strips
127
+ if (polyStrips.getNumberOfCells() > 0) {
128
+ outputData += writeFaces(polyStrips, hasPtNormals, hasPtTCoords);
129
+ }
130
+
131
+ // Write polygons.
132
+ if (polys) {
133
+ outputData += writeFaces(polys, hasPtNormals, hasPtTCoords);
134
+ }
135
+
136
+ // Write lines.
137
+ if (lines) {
138
+ outputData += writeLines(lines);
139
+ }
140
+ return outputData;
141
+ };
142
+
143
+ // ----------------------------------------------------------------------------
144
+ // Static API
145
+ // ----------------------------------------------------------------------------
146
+
147
+ const STATIC = {
148
+ writeOBJ
149
+ };
150
+
151
+ // ----------------------------------------------------------------------------
152
+ // vtkOBJWriter methods
153
+ // ----------------------------------------------------------------------------
154
+
155
+ function vtkOBJWriter(publicAPI, model) {
156
+ // Set our className
157
+ model.classHierarchy.push('vtkOBJWriter');
158
+ publicAPI.exportAsZip = () => {
159
+ publicAPI.update();
160
+ const modelFilename = model.modelFilename;
161
+ const materialFilename = model.materialFilename;
162
+ const textureFileName = model.textureFileName;
163
+ const imageData = model.texture.getInputAsJsImageData?.();
164
+ const zipContent = {};
165
+ zipContent[`${modelFilename}.obj`] = strToU8(model.output[0]);
166
+ zipContent[`${materialFilename}.mtl`] = strToU8(model.mtl);
167
+ const canvas = new OffscreenCanvas(imageData.width, imageData.height);
168
+ const ctx = canvas.getContext('2d');
169
+ ctx.putImageData(imageData, 0, 0);
170
+ return new Promise(resolve => {
171
+ canvas.toBlob(async blob => {
172
+ const arrayBuffer = await blob.arrayBuffer();
173
+ zipContent[`${textureFileName}.png`] = new Uint8Array(arrayBuffer);
174
+ resolve(zipSync(zipContent));
175
+ }, 'image/png');
176
+ });
177
+ };
178
+ publicAPI.requestData = (inData, outData) => {
179
+ const input = inData[0];
180
+ if (!input || !input.isA('vtkPolyData')) {
181
+ vtkErrorMacro('Invalid or missing vtkPolyData input');
182
+ return;
183
+ }
184
+
185
+ // Update output
186
+ const materialFilename = `${model.materialFilename}.mtl`;
187
+ const textureFileName = `${model.textureFileName}.png`;
188
+ outData[0] = writeOBJ(input, materialFilename, model.materialName);
189
+ model.mtl = writeMTL(model.materialName, textureFileName);
190
+ };
191
+ }
192
+
193
+ // ----------------------------------------------------------------------------
194
+ // Object factory
195
+ // ----------------------------------------------------------------------------
196
+
197
+ const DEFAULT_VALUES = {
198
+ modelFilename: 'model',
199
+ materialName: 'mat_01',
200
+ materialFilename: 'material',
201
+ texture: null,
202
+ textureFileName: 'texture'
203
+ };
204
+
205
+ // ----------------------------------------------------------------------------
206
+
207
+ function extend(publicAPI, model) {
208
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
209
+ Object.assign(model, DEFAULT_VALUES, initialValues);
210
+
211
+ // Make this a VTK object
212
+ macro.obj(publicAPI, model);
213
+
214
+ // Also make it an algorithm with one input and one output
215
+ macro.algo(publicAPI, model, 1, 1);
216
+ macro.get(publicAPI, model, ['mtl']);
217
+ macro.set(publicAPI, model, ['modelFilename', 'materialFilename', 'texture', 'textureFileName']);
218
+
219
+ // Object specific methods
220
+ vtkOBJWriter(publicAPI, model);
221
+ }
222
+
223
+ // ----------------------------------------------------------------------------
224
+
225
+ const newInstance = macro.newInstance(extend, 'vtkOBJWriter');
226
+
227
+ // ----------------------------------------------------------------------------
228
+
229
+ var vtkOBJWriter$1 = {
230
+ newInstance,
231
+ extend,
232
+ ...STATIC
233
+ };
234
+
235
+ export { STATIC, vtkOBJWriter$1 as default, extend, newInstance };
package/IO/Misc.js CHANGED
@@ -5,6 +5,7 @@ import vtkJSONNucleoReader from './Misc/JSONNucleoReader.js';
5
5
  import vtkJSONReader from './Misc/JSONReader.js';
6
6
  import vtkMTLReader from './Misc/MTLReader.js';
7
7
  import vtkOBJReader from './Misc/OBJReader.js';
8
+ import vtkOBJWriter from './Misc/OBJWriter.js';
8
9
  import vtkPDBReader from './Misc/PDBReader.js';
9
10
  import vtkSkyboxReader from './Misc/SkyboxReader.js';
10
11
  import vtkGCodeReader from './Misc/GCodeReader.js';
@@ -17,6 +18,7 @@ var Misc = {
17
18
  vtkJSONReader,
18
19
  vtkMTLReader,
19
20
  vtkOBJReader,
21
+ vtkOBJWriter,
20
22
  vtkPDBReader,
21
23
  vtkSkyboxReader,
22
24
  vtkGCodeReader
@@ -2,7 +2,7 @@ import { mat4, vec3 } from 'gl-matrix';
2
2
  import { m as macro } from '../../macros2.js';
3
3
  import vtkCompositeCameraManipulator from './CompositeCameraManipulator.js';
4
4
  import vtkCompositeMouseManipulator from './CompositeMouseManipulator.js';
5
- import { r as radiansFromDegrees, A as degreesFromRadians } from '../../Common/Core/Math/index.js';
5
+ import { r as radiansFromDegrees, B as degreesFromRadians } from '../../Common/Core/Math/index.js';
6
6
 
7
7
  // ----------------------------------------------------------------------------
8
8
  // vtkMouseCameraTrackballRollManipulator methods
@@ -2,7 +2,7 @@ import { mat4, vec3 } from 'gl-matrix';
2
2
  import { m as macro } from '../../macros2.js';
3
3
  import vtkCompositeCameraManipulator from './CompositeCameraManipulator.js';
4
4
  import vtkCompositeMouseManipulator from './CompositeMouseManipulator.js';
5
- import { w as multiplyScalar, d as dot, k as add, r as radiansFromDegrees, j as cross } from '../../Common/Core/Math/index.js';
5
+ import { x as multiplyScalar, d as dot, k as add, r as radiansFromDegrees, j as cross } from '../../Common/Core/Math/index.js';
6
6
 
7
7
  // ----------------------------------------------------------------------------
8
8
  // vtkMouseCameraTrackballRotateManipulator methods
@@ -3,7 +3,7 @@ import vtkCompositeMouseManipulator from './CompositeMouseManipulator.js';
3
3
  import vtkInteractorStyleConstants from '../../Rendering/Core/InteractorStyle/Constants.js';
4
4
  import vtkMouseCameraUnicamRotateManipulator from './MouseCameraUnicamRotateManipulator.js';
5
5
  import { m as macro } from '../../macros2.js';
6
- import { s as subtract, w as multiplyScalar, l as normalize, d as dot, r as radiansFromDegrees, j as cross } from '../../Common/Core/Math/index.js';
6
+ import { s as subtract, x as multiplyScalar, l as normalize, d as dot, r as radiansFromDegrees, j as cross } from '../../Common/Core/Math/index.js';
7
7
 
8
8
  const {
9
9
  States