Number of output ports

Hello,

I want to set a model in .obj on the web and i have a problem.
I did my tests with a .obj found on the web and it’s working well, it’s a lego man with 6 outputPorts, corresponding to each part of his body.
I tried to do it with a machine, with about 50 elements in it. But when i load it, my loop runs like a thousands times (nb iteration = nb outputPorts). But if i reduce de quality of the machine, the number of loops decrease a little.

This is the loop :
const nbPorts = model.getNumberOfOutputPorts();
for (let i = 0; i < 300/nbPorts/; i++) {
const polydata = model.getOutputData(i);
const mapper = vtkMapper.newInstance();
const actor = vtkActor.newInstance();
const name = polydata.get(‘name’).name;

			actor.setMapper(mapper);
			mapper.setInputData(polydata);
			document.getElementById("count").innerHTML = i;
			material.applyMaterialToActor(name, actor);
			renderer.addActor(actor);
		}

The machine is quite simple, the quality is already pretty low and do not have a lot of angles. Only the box with no details in it excepted holes on each side of the box count more than 300 iterations.

Can someone help me with this issue, if the number of output ports do not correspond to the number of elements, so how can i reduce this number.

Thank you

Sorry, it’s only for (let i = 0; i < nbPorts; i++)

What is the question or the issue? I’m not sure that I’m following.

The question is :
Why do i have thousands of output ports with a model with 50 elements in it ?
To what correspond the number of output ports ?
Why does this number is reduced with a reduced quality ?

Sorry for not being clear,
Thank you.

You can choose to only have 1 output port if you don’t need to split the output by material. Also I’m not sure what you call elements or reduced quality.

Can you share a sample obj file with the number or outputs vs elements that you find?

That’s why i separate the model into ~50 elements.
I call an element an output port. That’s why i don’t get why it finds a lot more.
Reduce quality of the model before turning it into .obj file. So that curves are less smooth.

I can’t share this .obj with about 50 elements and 1186 ouput ports because it’s too big, but there is a picture of it.

Output port is a VTK concept that has nothing to do with the obj.
Maybe you could explain how you choose to have 50 elements and the code snippet that you use to load the obj. My guess is that the splitMode that you use does not match your elements definition.

Can you try to run the following command line to see if your obj properly describe your elements and have the same count as you expect.

cat file.obj | grep $splitMode | wc -l

I guessed i had 50 elements because before getting the file into an obj, i had 50 elements in it.
I use var model = vtkOBJReader.newInstance({ splitMode: 'usemtl' });

I’m not on Linux but Windows and i’m not really familiar with windows, i tried Type file.obj | findstr $splitMode | find /c /v "" and found 0
So i just Type file.obj but it seems to only have coordinates

Since you use usemtl for splitMode the command line should be Type file.obj | findstr usemtl | find /c /v ""

I would think the splitMode should be for you either o or g but without your obj, it is hard to tell.

Ok, i found the same number as nbPorts. I don’t know how to reduce the number of output ports in the obj file.

splitMode “o” finds only 1 output port and “g” more than “usemtl”.
Is it possible to send you the obj by wetransfer if it helps ?

Have the obj may help, but now that you validated that vtk-js is doing what it is expected to do, I’m not sure I will know how to find those 50 elements in your file if they are not actually available.

Yes, that makes sens.
And thanks to you, i understand how it works.
Is there a way to reduce the number of output ports, without removing the “usemtl” tag by hand ?

Thank you.

usemtl is to define which material should be used by it. You might be able to keep those tags but just rename them so only 50 different names actually exist at the end.

Thank you Sebastien.