Skip to content

Commit 12ba1e8

Browse files
committed
WIP
1 parent 370d7d3 commit 12ba1e8

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

Sources/IO/Misc/OBJWriter/example/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import 'vtk.js/Sources/favicon';
1+
import '@kitware/vtk.js/favicon';
22

33
// Load the rendering pieces we want to use (for both WebGL and WebGPU)
4-
import 'vtk.js/Sources/Rendering/Profiles/Geometry';
4+
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
55

6-
import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
7-
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
8-
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
6+
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
7+
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
8+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
99

10-
import vtkOBJWriter from 'vtk.js/Sources/IO/Misc/OBJWriter';
11-
import vtkOBJReader from 'vtk.js/Sources/IO/Misc/OBJReader';
12-
import vtkPolyDataReader from 'vtk.js/Sources/IO/Legacy/PolyDataReader';
10+
import vtkOBJWriter from '@kitware/vtk.js/IO/Misc/OBJWriter';
11+
import vtkOBJReader from '@kitware/vtk.js/IO/Misc/OBJReader';
12+
import vtkPolyDataReader from '@kitware/vtk.js/IO/Legacy/PolyDataReader';
1313
// ----------------------------------------------------------------------------
1414
// Standard rendering code setup
1515
// ----------------------------------------------------------------------------

Sources/IO/Misc/OBJWriter/index.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,46 @@ const writeLines = (lines) => {
5454
};
5555

5656
const writePoints = (pts, normals, tcoords) => {
57-
let outputData = '';
57+
const outputData = [];
5858
const nbPts = pts.getNumberOfPoints();
5959

6060
let p;
6161

6262
// Positions
6363
for (let i = 0; i < nbPts; i++) {
6464
p = pts.getPoint(i, p);
65-
outputData += `v ${p[0]} ${p[1]} ${p[2]}\n`;
65+
outputData.push[`v ${p[0]} ${p[1]} ${p[2]}`];
6666
}
6767

6868
// Normals
6969
if (normals) {
7070
for (let i = 0; i < nbPts; i++) {
7171
p = normals.getTuple(i, p);
72-
outputData += `vn ${p[0]} ${p[1]} ${p[2]}\n`;
72+
outputData.push[`vn ${p[0]} ${p[1]} ${p[2]}`];
7373
}
7474
}
7575

7676
// Textures
7777
if (tcoords) {
7878
for (let i = 0; i < nbPts; i++) {
7979
p = tcoords.getTuple(i, p);
80-
outputData += `vt ${p[0]} ${p[1]}\n`;
80+
outputData.push[`vt ${p[0]} ${p[1]}`];
8181
}
8282
}
83-
return outputData;
83+
return outputData.join('/n');
8484
};
8585

86-
const writeOBJ = (polyData) => {
86+
const writeMtl = (baseName, textureFileName) => {
87+
const outputData = [];
88+
// set material
89+
const mtlName = 'material_0';
90+
outputData.push[`newmtl ${mtlName}`];
91+
outputData.push[`map_Kd ${textureFileName}`];
92+
return outputData.join('/n');
93+
};
94+
95+
96+
const writeOBJ = (polyData, textureFileName) => {
8797
let outputData = '# VTK.js generated OBJ File\n';
8898
const pts = polyData.getPoints();
8999
const polys = polyData.getPolys();
@@ -139,13 +149,20 @@ function vtkOBJWriter(publicAPI, model) {
139149

140150
publicAPI.requestData = (inData, outData) => {
141151
const input = inData[0];
152+
const inputTexture = inData[1];
142153

143154
if (!input || !input.isA('vtkPolyData')) {
144155
vtkErrorMacro('Invalid or missing input');
145156
return;
146157
}
147158

159+
if (!inputTexture || !input.isA('vtkTexture')) {
160+
vtkErrorMacro('Invalid or missing input');
161+
return;
162+
}
163+
148164
outData[0] = writeOBJ(input);
165+
outData[1], outData[2] = writeMtl(input);
149166
};
150167
}
151168

@@ -164,7 +181,7 @@ export function extend(publicAPI, model, initialValues = {}) {
164181
macro.obj(publicAPI, model);
165182

166183
// Also make it an algorithm with one input and one output
167-
macro.algo(publicAPI, model, 1, 1);
184+
macro.algo(publicAPI, model, 2, 2);
168185

169186
// Object specific methods
170187
vtkOBJWriter(publicAPI, model);

0 commit comments

Comments
 (0)