mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
* STL files preview with three's own STLLoader
react-stl-viewer inlines a copy of three-stdlib 2.17.2's STLLoader, which reads
ASCII STL text with LoaderUtils.decodeText. three removed that in r175, so
every ASCII STL preview failed. The three-stdlib override never reached that
copy, and react-stl-viewer has had no release since January 2024.
The 3MF preview's three.js viewer now previews STL files too, loading each
format with the loader that ships with three, so the loader always matches the
installed three. react-stl-viewer and the three-stdlib override are removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* An e2e spec previews ASCII and binary STL files in a real browser
The STL preview only fails in a browser with WebGL, so the spec opens both
encodings on the live stack and checks the dimensions line appears without a
load error. fb:reset can now write binary files ({base64: ...}).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* STL previews stand Z-up models upright
STLs are Z-up (the 3D printing convention) and three is Y-up, so the
preview rotates STL geometry to stand the model upright, as react-stl-viewer
did. Model Z reads as Height again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* 3MF previews stand Z-up models upright too
3MF is Z-up like STL, so the rotation moves from the STL loader into the
shared viewer and applies to every model. Model Z reads as Height.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* File previews show their buttons without scrolling
.preview-fit reserved a fixed 18.75rem for the rest of the preview modal,
which was short: every framed preview overflowed a little, and a 3D model's
dimensions line pushed the action buttons below the fold. The preview modal
now fills its height as a flex column, and the .preview-fit takes whatever
height is left. Previews without a .preview-fit keep their content's height.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* 3D previews frame the model and light it brightly
- The camera fits the model's bounding sphere into the narrower field of view,
from a raised three-quarter front view, instead of backing off 2.2x along Z.
- A hemisphere light and a headlight that follows the camera (from a little
above and left) replace lights whose intensities were set before three's
r155 lighting change and read dim.
- Geometry without normals (3MF) gets creased normals, so flat faces no longer
shade into their neighbors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.2 KiB
JavaScript
89 lines
3.2 KiB
JavaScript
/*
|
|
* Previewing STL files, exercised against the live stack in a real browser (WebGL).
|
|
*
|
|
* An STL is either ASCII text or binary. Both must load in the preview: the dimensions line
|
|
* is only shown after the model has been parsed and framed, and a load failure is shown as an
|
|
* error (or thrown, which fails the test).
|
|
*/
|
|
import {assertWROLModeOff, SANDBOX, teardownFileBrowser} from '../../support/file-browser';
|
|
|
|
// One right triangle, legs of 2 along X and 1 along Y.
|
|
const ASCII_STL = `solid ASCII
|
|
facet normal 0 0 1
|
|
outer loop
|
|
vertex 0 0 0
|
|
vertex 2 0 0
|
|
vertex 0 1 0
|
|
endloop
|
|
endfacet
|
|
endsolid
|
|
`;
|
|
|
|
function binaryStlBase64() {
|
|
// 80-byte header, uint32 triangle count, then one 50-byte triangle: normal, three vertices.
|
|
const buffer = new ArrayBuffer(84 + 50);
|
|
const view = new DataView(buffer);
|
|
view.setUint32(80, 1, true);
|
|
const floats = [0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0];
|
|
floats.forEach((value, i) => view.setFloat32(84 + i * 4, value, true));
|
|
return Cypress.Buffer.from(buffer).toString('base64');
|
|
}
|
|
|
|
// Requires the full stack (API + real media directory); CI runs only the React dev server.
|
|
(Cypress.env('CI') ? describe.skip : describe)('STL preview', () => {
|
|
|
|
before(() => {
|
|
assertWROLModeOff();
|
|
cy.task('fb:reset', {
|
|
files: {
|
|
'ascii.stl': ASCII_STL,
|
|
'binary.stl': {base64: binaryStlBase64()},
|
|
},
|
|
});
|
|
cy.refreshFiles([SANDBOX]);
|
|
});
|
|
|
|
after(() => {
|
|
teardownFileBrowser();
|
|
});
|
|
|
|
const openPreview = (name) => {
|
|
const params = new URLSearchParams({folders: `${SANDBOX}/`, preview: `${SANDBOX}/${name}`});
|
|
cy.visit(`/files?${params}`);
|
|
cy.get('[role="dialog"]').should('contain', name);
|
|
};
|
|
|
|
const expectTriangleDimensions = () => {
|
|
// The triangle is 2 wide along X, which only a parsed model can report. Which axis
|
|
// reads as Height or Length depends on how the viewer orients the model, so only
|
|
// Width is asserted.
|
|
cy.get('[role="dialog"]').contains('Width:', {timeout: 20000}).parent()
|
|
.should('contain', 'Width: 2.00');
|
|
cy.get('[role="dialog"]').should('not.contain', 'Failed to');
|
|
};
|
|
|
|
it('previews an ASCII STL file', () => {
|
|
openPreview('ascii.stl');
|
|
expectTriangleDimensions();
|
|
});
|
|
|
|
it('previews a binary STL file', () => {
|
|
openPreview('binary.stl');
|
|
expectTriangleDimensions();
|
|
});
|
|
|
|
it('shows the action buttons without scrolling the preview', () => {
|
|
cy.viewport(1280, 720);
|
|
openPreview('binary.stl');
|
|
// The dimensions line is the last thing the preview adds, so the layout is final.
|
|
expectTriangleDimensions();
|
|
cy.get('.mantine-Modal-content').should(([content]) => {
|
|
expect(content.scrollHeight, 'preview modal content scrolls')
|
|
.to.be.at.most(content.clientHeight);
|
|
});
|
|
cy.get('.wrolpi-modal-actions').should(([actions]) => {
|
|
expect(actions.getBoundingClientRect().bottom, 'action buttons bottom edge')
|
|
.to.be.at.most(actions.ownerDocument.defaultView.innerHeight);
|
|
});
|
|
});
|
|
});
|