Try to access parseObj(model,strings) in P5 code

I create obj data on the fly and want to use it directly without going through a file.
loadModel( model, fileName) uses a file, but internally it uses the function :
(line 100206 of p5.js) :

function parseObj(model, lines) {
// OBJ allows a face to specify an index for a vertex (in the above example),
// but it also allows you to specify a custom combination of vertex, UV
// coordinate, and vertex normal. So, “3/4/3” would mean, "use vertex 3 with…

I try to use parseObj or p5.parseObj without success.
I suppose there is some export to set or some prefix to use, but do not know which.

Hi @pirela,

If you check the src/webgl/loading.js file, the only export statement in that file is:

export default p5;

which exports the p5 class with all the new methods added to its prototype.

Unfortunately, the parseObj function is not exported from the file so it can’t be used outside that file.

What you can do is copy and paste that function in your project and use it (with credits so people can see where it comes from, also check the license if it’s a commercial project…).


Another option would be to turn your model data into a data URL and use that with the loadModel function. Here’s an example of how to generate a data URL: javascript - Create data URIs on the fly? - Stack Overflow