Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading of models from strings #6891

Closed
1 of 17 tasks
Kabaril opened this issue Mar 18, 2024 · 5 comments · Fixed by #7165
Closed
1 of 17 tasks

Allow loading of models from strings #6891

Kabaril opened this issue Mar 18, 2024 · 5 comments · Fixed by #7165

Comments

@Kabaril
Copy link

Kabaril commented Mar 18, 2024

Increasing access

  • Can help increase portability of examples (as in copy + paste),
  • Allows loading models without a server

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

Feature enhancement details

The current loadModel function takes a path to load a model from a .stl or .obj file, however this requires that a server exists that serves these assets.

A function that loads models directly from a string can increase portability of examples (as in copy + paste) and allows loading models without a server.

The following example:

//draw a spinning octahedron
let octahedron;

function preload() {
  octahedron = loadModel('assets/octahedron.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);
}

could also be written as:

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 = loadModelString(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);
}

The changes in code should be trivial, as this can reuse already existing helper functions.

Copy link

welcome bot commented Mar 18, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@davepagurek
Copy link
Contributor

I agree this feature makes sense! Although I would follow the precedent set by shaders, where loadShader is called in preload and loads from a file, and createShader is called in setup and loads from a string. That would imply that we'd have loadModel from a file and createModel from a string.

@mathewpan2
Copy link
Contributor

I'd like to try and work on this.

@mathewpan2
Copy link
Contributor

@davepagurek I implemented the method to load obj/stl from a string, but wonder if this is still up for debate and I was a little premature. Should I make the pr?

@davepagurek
Copy link
Contributor

Feel free to make a PR, thanks!

Garima3110 added a commit to Garima3110/p5.js that referenced this issue Aug 9, 2024
@Garima3110 Garima3110 mentioned this issue Aug 9, 2024
3 tasks
davepagurek added a commit that referenced this issue Aug 20, 2024
lukeplowden pushed a commit to lukeplowden/p5-attributes that referenced this issue Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants