Description
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:
/**
* This function parses the Binary STL files.
* https://en.wikipedia.org/wiki/STL_%28file_format%29#Binary_STL
*
* Currently there is no support for the colors provided in STL files.
*/
function parseBinarySTL(model, buffer) {
const reader = new DataView(buffer);
// Number of faces is present following the header
const faces = reader.getUint32(80, true);
let r,
g,
b,
hasColors = false,
colors;
let defaultR, defaultG, defaultB;
// Binary files contain 80-byte header, which is generally ignored.
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?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build Process
- Unit Testing
- Internalization
- Friendly Errors
- Other (specify if possible)
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;
}
Lines 439 to 445 in 8f2b47c