-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
The Support for colored STL and OBJ files is not present. #6670
Comments
I would love to have a discussion over this and see if the current functionality of p5.js allows implementing the feature, I would like to implement it. |
I'm less familiar with the stl format, does it include colors all in one file? .obj files also don't currently support color imports, but I gather the blocker there is also the fact that typically they come in two parts: a .obj file that specifies shape and material names, and a .mtl file with the material definitions. Adding color support for objs would need an update to the APIs to include loading that second file too, would STL be the same? Another complication is that p5.Geometry supports per-vertex colors, but not necessarily per-vertex materials. .obj materials not only include color, but also things like specular color, diffuse color, etc. To support that, I think we'd need to make a new class that can contain multiple p5.Geometry objects with a transformation matrix and material settings for each, allowing one to store multiple shapes + settings in one object. If STL materials also work the same way, they'd also need that. If they really only have colors, then they could potentially be imported just as p5.Geoemtry vertex colors. |
I think adding just colors could be a good way to start regardless, and we definitely have the ability to do that in p5.Geometry. I'm going to tag the other WebGL stewards too: @aferriss, @aceslowman, @ShenpaiSharma, @ChihYungChang, @teragramgius, @JazerUCSB, @richardegil, @itsjoopark, @Gaurav-1306, @jeanetteandrews, does that seem light the right approach to you, both for right now and for how it might need to be extended in the future? |
@davepagurek Thanks a lot for tagging other stewards. The approach seems fair enough to take this forward. |
That sounds good to me! Looking at the .mtl spec on wikipedia, it looks like they set a bunch of comopnents of the material: ambient color, diffuse color, and specular color, among other things. We can translate diffuse colors to the |
Seems like a plan! I'll start looking into the translation of diffuse colors to vertexColors array for now. |
@davepagurek
and taking an example mtl file ,after parsing would look something like this:
model.materials from the returned model:
Then extract diffuse colors from it and translate them into vertexColors array in p5.Geometry as We are going to ignore other properties for now and only use diffuse colors. |
That looks like a great start!
|
@davepagurek thanks for the heads up on what to do next. |
Increasing Access
Went through the learn pages and found out that p5.js currently does not support colored STL files while creating custom geometry.
Found the relevant code here:
Link to the code:
https://github.com/processing/p5.js/blob/8f2b47c2957fda064992ddffbceb62983a26103c/src/webgl/loading.js#L357C1-L375C1
Most appropriate sub-area of p5.js?
Feature request details
STL files can have color information in the form of per-face or per-vertex color attributes. We would need to modify the parser to extract and interpret this color data and then use it appropriately in the application.
Here's a high-level overview of the steps:
Parse Color Information:
For binary STL files, understand the format's structure to locate color information.
For ASCII STL files, adapt the parser to recognize and process color data in the file.
Integrate Color in Rendering:
Modify the rendering code to consider color information while rendering the 3D model.
Adjust shaders or rendering logic to incorporate color attributes.
Update File Upload and Display:
When handling file uploads, ensure that the code correctly interprets and processes color data from STL files.
Update the UI to display the 3D model with color.
Testing:
Test the implementation with STL files containing color information to verify that both geometry and color are rendered correctly.
I think this is where the functionality should be implemented:
}
if (hasColors) {
// add support for colors here.
}
return model;
}
p5.js/src/webgl/loading.js
Lines 439 to 445 in 8f2b47c
The text was updated successfully, but these errors were encountered: