Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanecsd committed Feb 26, 2024
1 parent 370d7d3 commit 12ba1e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
16 changes: 8 additions & 8 deletions Sources/IO/Misc/OBJWriter/example/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'vtk.js/Sources/favicon';
import '@kitware/vtk.js/favicon';

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

import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';

import vtkOBJWriter from 'vtk.js/Sources/IO/Misc/OBJWriter';
import vtkOBJReader from 'vtk.js/Sources/IO/Misc/OBJReader';
import vtkPolyDataReader from 'vtk.js/Sources/IO/Legacy/PolyDataReader';
import vtkOBJWriter from '@kitware/vtk.js/IO/Misc/OBJWriter';
import vtkOBJReader from '@kitware/vtk.js/IO/Misc/OBJReader';
import vtkPolyDataReader from '@kitware/vtk.js/IO/Legacy/PolyDataReader';
// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------
Expand Down
31 changes: 24 additions & 7 deletions Sources/IO/Misc/OBJWriter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,46 @@ const writeLines = (lines) => {
};

const writePoints = (pts, normals, tcoords) => {
let outputData = '';
const outputData = [];
const nbPts = pts.getNumberOfPoints();

let p;

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

Check failure on line 65 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Expected an assignment or function call and instead saw an expression

Check failure on line 65 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Expected an assignment or function call and instead saw an expression
}

// Normals
if (normals) {
for (let i = 0; i < nbPts; i++) {
p = normals.getTuple(i, p);
outputData += `vn ${p[0]} ${p[1]} ${p[2]}\n`;
outputData.push[`vn ${p[0]} ${p[1]} ${p[2]}`];

Check failure on line 72 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Expected an assignment or function call and instead saw an expression

Check failure on line 72 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Expected an assignment or function call and instead saw an expression
}
}

// Textures
if (tcoords) {
for (let i = 0; i < nbPts; i++) {
p = tcoords.getTuple(i, p);
outputData += `vt ${p[0]} ${p[1]}\n`;
outputData.push[`vt ${p[0]} ${p[1]}`];

Check failure on line 80 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Expected an assignment or function call and instead saw an expression

Check failure on line 80 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Expected an assignment or function call and instead saw an expression
}
}
return outputData;
return outputData.join('/n');
};

const writeOBJ = (polyData) => {
const writeMtl = (baseName, textureFileName) => {
const outputData = [];
// set material
const mtlName = 'material_0';
outputData.push[`newmtl ${mtlName}`];

Check failure on line 90 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Expected an assignment or function call and instead saw an expression

Check failure on line 90 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Expected an assignment or function call and instead saw an expression
outputData.push[`map_Kd ${textureFileName}`];

Check failure on line 91 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Expected an assignment or function call and instead saw an expression

Check failure on line 91 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Expected an assignment or function call and instead saw an expression
return outputData.join('/n');
};


Check failure on line 95 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Delete `⏎`

Check failure on line 95 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Delete `⏎`
const writeOBJ = (polyData, textureFileName) => {
let outputData = '# VTK.js generated OBJ File\n';
const pts = polyData.getPoints();
const polys = polyData.getPolys();
Expand Down Expand Up @@ -139,13 +149,20 @@ function vtkOBJWriter(publicAPI, model) {

publicAPI.requestData = (inData, outData) => {
const input = inData[0];
const inputTexture = inData[1];

if (!input || !input.isA('vtkPolyData')) {
vtkErrorMacro('Invalid or missing input');
return;
}

if (!inputTexture || !input.isA('vtkTexture')) {
vtkErrorMacro('Invalid or missing input');
return;
}

outData[0] = writeOBJ(input);
outData[1], outData[2] = writeMtl(input);

Check failure on line 165 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Expected an assignment or function call and instead saw an expression

Check failure on line 165 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Unexpected use of comma operator

Check failure on line 165 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 18

Replace `outData[2]·=·writeMtl(input` with `(outData[2]·=·writeMtl(input)`

Check failure on line 165 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Expected an assignment or function call and instead saw an expression

Check failure on line 165 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Unexpected use of comma operator

Check failure on line 165 in Sources/IO/Misc/OBJWriter/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-20.04 and node 20

Replace `outData[2]·=·writeMtl(input` with `(outData[2]·=·writeMtl(input)`
};
}

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

// Also make it an algorithm with one input and one output
macro.algo(publicAPI, model, 1, 1);
macro.algo(publicAPI, model, 2, 2);

// Object specific methods
vtkOBJWriter(publicAPI, model);
Expand Down

0 comments on commit 12ba1e8

Please sign in to comment.