added createModel() to enable loading stl/obj files from a plaintext string within editor
Resolves #6891
Changes
Added a method called createModel() within src/webgl/loading.js that allows users to call for loading a obj or stl file from a plain text string within the editor. It includes the same options as the loadModel() function, as well as using p5._validateParameters('loadModel', arguments); to check for arguments (I wasn't sure it warranted adding a separate check for 'createModel' since they share the same arguments).
Wanted to make sure this implementation was acceptable before adding unit tests.
Screenshots of the change
const octahedron_model = `
v 0.000000E+00 0.000000E+00 40.0000
v 22.5000 22.5000 0.000000E+00
v 22.5000 -22.5000 0.000000E+00
v -22.5000 -22.5000 0.000000E+00
v -22.5000 22.5000 0.000000E+00
v 0.000000E+00 0.000000E+00 -40.0000
f 1 2 3
f 1 3 4
f 1 4 5
f 1 5 2
f 6 5 4
f 6 4 3
f 6 3 2
f 6 2 1
f 6 1 5
`
//draw a spinning octahedron
let octahedron;
function preload() {
octahedron = createModel(octahedron_model, {type: 'obj'});
}
function setup() {
createCanvas(100, 100, WEBGL);
describe('Vertically rotating 3-d octahedron.');
}
function draw() {
background(200);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
model(octahedron);
}
Given the sampe code above, this successfully generates a rotating 3D model from the string:
PR Checklist
- [x]
npm run lintpasses - [x] Inline documentation is included / updated
- [ ] Unit tests are included / updated
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!
Hey, sorry for the delay! Finally getting back to this. It looks like the tests are currently failing:
Hii @mathewpan2 , I noticed this PR has been open for a while without any activity. If you're unable to continue working on it, I'd be happy to take over and implement the suggested changes to help solve the issue. Please let me know if that works for you.
I'm going to close this as @Garima3110 finished it up in another PR. Thanks for your work getting this feature in!
@all-contributors please add @mathewpan2 for code