Comments (8)
In my strong opinion if this is going to be added the loader should use the URL( ... )
syntax by default so users don't have to set the decoder path. If this works in browsers and some of the most popular bundlers it should be the default. The existing API (or something like it) can be maintained for backwards compatibility and handling other types of bundler cases. Now that the examples and loaders all support es6 imports exclusively it's time to make this change.
from three.js.
Related:
This is a promising solution to the problems blocking earlier attempts... I think the approach should work?
/cc @gkjohnson @CodyJasonBennett
from three.js.
I'm not sure what this does differently, but I have no further concerns if CDNs play well with it.
@RenaudRohlinger I remember making a host of fixes offline to Vite for assets -- particularly with import.meta.url
and its assets resolver. Does this ring a bell? I don't have access to our fork anymore. This is the only tool I recall having issues here, but they're good about backporting fixes if they're still needed.
from three.js.
I would really like to see this happen for the loaders in a way that works across vanilla JS and build processes. Having to rely on CDNs or manual file configuration in builds feels a bit dirty.
const wasmUrl = new URL('./mymodule.wasm', import.meta.url).toString();
@cgauld Can you confirm that it's enough to have only a URL in this form in order for the referenced files to be included in the build? It doesn't need to be detected in an import
, fetch
, or Worker
function call argument?
Generally having the above line as a default is safe. It should work in a web browser and in bundlers that support it - and it shouldn't cause systems that don't support it to choke assuming the user properly sets a custom path. In terms of bundler coverage it might be worth determining whether this works in ESBuild and Rollup, as well. Vite would be good to get working, as well. Otherwise it would be worth making some issues in the big bundlers to help promote some consistency in behavior here.
Dynamically importing the KTX or DRACO loaders is a separate problem that would be nice to address in the future.
from three.js.
Hi @gkjohnson - I can confirm that the new URL(..., import.meta.url)
structure is all that's required for Parcel and Webpack to include the file in the bundle. When this structure is used on its own, the bundlers will copy the file into the output bundle without performing any transformation (i.e. they will consider it to be a raw file and won't parse it for further dependency resolution or optimisation).
With my proposal we'd not include this structure in DRACOLoader
itself - instead the loader would do exactly what it currently does but with one modification - it would call the resolveDependency
function to get the URL to fetch
for each given file (falling back to what it currently does if no resolveDependency
function is provided by the user). That way the user (who knows which bundler they're using, if any) can use whichever structure works for them to ensure the file is included in the output and that DRACOLoader has a 'fetchable' URL for it. For webpack and parcel they'd implement a switch like the one above. Existing users wouldn't experience any change in behavior as long as they don't provide resolveDependency
.
An alternative would be to update DRACOLoader
to use this structure directly. That would have the benefit of working 'out of the box' for bundlers like Parcel and Webpack, without the user having to provide any resolveDependency
function. The structure should also work directly in browsers, assuming the user places the dependencies beside the JS file they're calling DRACOLoader
from. I don't have any direct experience with Vite but their documentation suggests it also supports the new URL...
structure. In general though it seems likely there are users out there using different bundlers where it wouldn't work out of the box.
On balance, my recommendation would be the first option. It's a way that's agnostic to build processes and that allows users to work with whichever bundler they want. Perhaps in the future, when we're confident of support for the new URL
structure across a broad spectrum of bundlers, a move to the second approach would make sense?
from three.js.
Cool - that definitely works for us π. I can pull a MR together that takes a shot at this if everyone is happy for me to do so? One element of the implementation that I should point out is that I think we should move DRACOLoader's dependencies from where they currently are (examples/jsm/libs/draco) to somewhere closer to the DRACOLoader itself (e.g. examples/jsm/loaders/draco). That way the the URL reference inside DRACOLoader will look something like this:
new URL('./draco/...', import.meta.url)
Which (as a path) will be much easier for those not using a bundler to replicate.
from three.js.
One element of the implementation that I should point out is that I think we should move DRACOLoader's dependencies from where they currently are (examples/jsm/libs/draco) to somewhere closer to the DRACOLoader itself
I don't have strong feelings here but I expect this will be easier to merge without a discussion on how to rearrange the /libs
directory. Maybe this can be done separately if you feel it's important.
from three.js.
Hi! I've popped a draft PR here with these changes. I've left the libs where they are for the time being :-) Let me know your thoughts!
from three.js.
Related Issues (20)
- GTAO/SSAO alter transparent materials appearence HOT 4
- Provide an iterative version of Object3D.traverse() HOT 2
- WebGLBackend: Support for Accessing External Elements in StorageBuffer HOT 4
- Raytracing material & lighting HOT 3
- move addons out of the examples folder HOT 1
- WebGLRenderer: Setting Scissor and Viewport is imprecise due to rounding issues HOT 2
- Minor Improvements to Lensflare Module HOT 5
- 3DM Exporter: Possible new addition HOT 2
- TransformControl change X and Z when rotation happen on Y axis HOT 1
- render error after WKWebView crash HOT 3
- WebXR: Make Depth sensing occlusion tunable
- After the InstancedMesh instance changes its position once, why canβt the ray hit it again? HOT 2
- Rendering into RGIntegerFormat textures doesn't work HOT 2
- WebGPURenderer: Add support for ShadowMaterial
- WebGPURenderer: VideoTexture produces multiple warnings in the console
- Remove `hand-tracking` from VRButton's `optionalFeatures` HOT 3
- Material: It's currently not possible to determine if a material failed to compile HOT 7
- Object3D / Raycaster: Provide way to stop raycast intersection traversal HOT 4
- Add the same warning in the doc for object3D.applyMatrix4 than for Matrix4.decompose HOT 5
- Scene: Lighting does not work if environment map has dimensions < 64 pixels HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from three.js.