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

Extend STLLoaderPlugin to handle data directly, not only loaded from file #572

Closed
MaxGeldner opened this issue Feb 23, 2021 · 3 comments
Closed
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@MaxGeldner
Copy link
Contributor

MaxGeldner commented Feb 23, 2021

Is this feature critical for your commercial enterprise?
Yes, it is critical for the DBI project (we are in talks over a license agreement atm I think).

Is your feature request related to a problem? Please describe.
I'd like to plug data directly into the STL loader and not go the extra way of having to write my data into a file, to use the STL loaders load() function.
Assuming a part of my code generates a STL string, it would be better to have a method in the STL loader that can handle this STL string directly.

Describe the solution you'd like
At the moment the STL loader uses the parse() function to actually load the STL string, taken from a file via the load() function, into Xeokit.
Solutions would be:

  • Either: Expose the parse() function as a public function of the STLLoader class. In that case the caller would need to create a modelNode (instance of Node) by itself and pass it together with the LoaderPlugin instance (and options).
    At the moment a call would look something like this:
const loader = new STLLoaderPlugin(viewer, {});
const modelNode = new Node(viewer.scene, utils.apply({ id: this.model.id }, { isModel: true }));
loader._loader.parse(stlData, loader, modelNode, {});
  • Or: Create/Modify a method in the STLLoaderPlugin that does everything similar to the STLLoaderPlugins load() function, but can handle STL data as a parameter of the params fn parameter or via a second parameter (probably the cleaner solution).
    For example (a call could look like this):
const loader = new STLLoaderPlugin(viewer, {});
loader.load({ stlData: stlData });
@xeolabs xeolabs added the enhancement New feature or request label Mar 3, 2021
@xeolabs xeolabs self-assigned this Mar 3, 2021
@xeolabs xeolabs added this to the 1.7.0 milestone Mar 3, 2021
@xeolabs xeolabs changed the title Make STL loader able to handle data directly, not only via file Extend STLLoaderPlugin to handle data directly, not only loaded from file Mar 3, 2021
xeolabs added a commit that referenced this issue Mar 3, 2021
@xeolabs
Copy link
Member

xeolabs commented Mar 3, 2021

Solution

If we already have our STL file in memory (perhaps pre-loaded, or even generated in-client), then we can just pass that
file data straight to the STLLoaderPlugin#load method. In the example below, we'll show how it's done by pre-loading
our STL file data, before passing it to that method.

loadSTL("./models/stl/binary/spurGear.stl", (stlData) =>{

     const model = stlLoader.load({
         id: "myModel",
         stl: stlData,
         smoothNormals: true
     });
})

function loadSTL(src, ok, error) {
    const request = new XMLHttpRequest();
    request.overrideMimeType("application/json");
    request.open('GET', src, true);
    request.responseType = 'arraybuffer';
    request.onreadystatechange = function () {
        if (request.readyState === 4) {
            if (request.status === 200) {
                ok(request.response);
            } else if (error) {
                    error(request.statusText);
            }
        }
    };
    request.send(null);
}

@xeolabs xeolabs closed this as completed Mar 3, 2021
@xeolabs
Copy link
Member

xeolabs commented Mar 5, 2021

/ping @MaxGeldner - I just released this fix in 1.7.0-alpha.4

See all changes in that pre-release here: https://github.com/xeokit/xeokit-sdk/blob/master/CHANGE_LOG.md

Everything under the "1.7.0" heading in that change log is pre-released in 1.7.0-alpha.4.

The other issue that (if I understand correctly) is important for our project is #579, which allows us to load STL models with double-precision global coordinates, so they properly render align with double-precision map coordinates without rounding errors.

@MaxGeldner
Copy link
Contributor Author

/ping @MaxGeldner - I just released this fix in 1.7.0-alpha.4

See all changes in that pre-release here: https://github.com/xeokit/xeokit-sdk/blob/master/CHANGE_LOG.md

Everything under the "1.7.0" heading in that change log is pre-released in 1.7.0-alpha.4.

The other issue that (if I understand correctly) is important for our project is #579, which allows us to load STL models with double-precision global coordinates, so they properly render align with double-precision map coordinates without rounding errors.

@xeolabs Thank you very much :) I hope to integrate the new version before our meeting next monday and get back to you with questions on that appointment, if I have any.

Until then have a nice weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants