I have started working on creating bindings for three.js so that it can be used from WebAssembly, in particular, from Rust (via wasm-bindgen). With the current state of WebAssembly, the bindings will work by creating and manipulating three.js objects in the browser's js engine. The aim of this project is to bring the well-tested rendering capabilities and interactivity of three.js to WebAssembly.
@mrdoob do you have any interest in this project? If so, would you be willing to collaborate?
Hey! What do you need from me?
Maybe not unrelated? https://github.com/three-rs/three π
@mrdoob answers to a couple designed related questions from time to time. What is the fastest way to get a complete hierarchy of the classes in three.js?
@donmccurdy not so related actually. This is a three.js inspired project that doesn't render to WebGL or use three.js as far as I tell.
@mrdoob What is the fastest way to get a complete hierarchy of the classes in three.js?
Not sure... π€
Maybe something like:
npm install --global tree-node-cli
tree src/ -I "src/renderers/webgl|src/renderers/shaders|.d.ts"
βββ Three.Legacy.js
βββ Three.js
βββ animation
β βββ AnimationAction.js
β βββ AnimationClip.js
β βββ AnimationMixer.js
β βββ AnimationObjectGroup.js
β βββ AnimationUtils.js
β βββ KeyframeTrack.js
β βββ PropertyBinding.js
β βββ PropertyMixer.js
β βββ tracks
β βββ BooleanKeyframeTrack.js
β βββ ColorKeyframeTrack.js
β βββ NumberKeyframeTrack.js
β βββ QuaternionKeyframeTrack.js
β βββ StringKeyframeTrack.js
β βββ VectorKeyframeTrack.js
βββ audio
β βββ Audio.js
β βββ AudioAnalyser.js
β βββ AudioContext.js
β βββ AudioListener.js
β βββ PositionalAudio.js
βββ cameras
β βββ ArrayCamera.js
β βββ Camera.js
β βββ CubeCamera.js
β βββ OrthographicCamera.js
β βββ PerspectiveCamera.js
β βββ StereoCamera.js
βββ constants.js
βββ core
β βββ BufferAttribute.js
β βββ BufferGeometry.js
β βββ Clock.js
β βββ DirectGeometry.js
β βββ EventDispatcher.js
β βββ Face3.js
β βββ Geometry.js
β βββ InstancedBufferAttribute.js
β βββ InstancedBufferGeometry.js
β βββ InstancedInterleavedBuffer.js
β βββ InterleavedBuffer.js
β βββ InterleavedBufferAttribute.js
β βββ Layers.js
β βββ Object3D.js
β βββ Raycaster.js
β βββ Uniform.js
βββ extras
β βββ Earcut.js
β βββ ImageUtils.js
β βββ PMREMGenerator.js
β βββ ShapeUtils.js
β βββ core
β β βββ Curve.js
β β βββ CurvePath.js
β β βββ Font.js
β β βββ Interpolations.js
β β βββ Path.js
β β βββ Shape.js
β β βββ ShapePath.js
β βββ curves
β β βββ ArcCurve.js
β β βββ CatmullRomCurve3.js
β β βββ CubicBezierCurve.js
β β βββ CubicBezierCurve3.js
β β βββ Curves.js
β β βββ EllipseCurve.js
β β βββ LineCurve.js
β β βββ LineCurve3.js
β β βββ QuadraticBezierCurve.js
β β βββ QuadraticBezierCurve3.js
β β βββ SplineCurve.js
β βββ objects
β βββ ImmediateRenderObject.js
βββ geometries
β βββ BoxGeometry.js
β βββ CircleGeometry.js
β βββ ConeGeometry.js
β βββ CylinderGeometry.js
β βββ DodecahedronGeometry.js
β βββ EdgesGeometry.js
β βββ ExtrudeGeometry.js
β βββ Geometries.js
β βββ IcosahedronGeometry.js
β βββ LatheGeometry.js
β βββ OctahedronGeometry.js
β βββ ParametricGeometry.js
β βββ PlaneGeometry.js
β βββ PolyhedronGeometry.js
β βββ RingGeometry.js
β βββ ShapeGeometry.js
β βββ SphereGeometry.js
β βββ TetrahedronGeometry.js
β βββ TextGeometry.js
β βββ TorusGeometry.js
β βββ TorusKnotGeometry.js
β βββ TubeGeometry.js
β βββ WireframeGeometry.js
βββ helpers
β βββ ArrowHelper.js
β βββ AxesHelper.js
β βββ Box3Helper.js
β βββ BoxHelper.js
β βββ CameraHelper.js
β βββ DirectionalLightHelper.js
β βββ GridHelper.js
β βββ HemisphereLightHelper.js
β βββ PlaneHelper.js
β βββ PointLightHelper.js
β βββ PolarGridHelper.js
β βββ SkeletonHelper.js
β βββ SpotLightHelper.js
βββ lights
β βββ AmbientLight.js
β βββ AmbientLightProbe.js
β βββ DirectionalLight.js
β βββ DirectionalLightShadow.js
β βββ HemisphereLight.js
β βββ HemisphereLightProbe.js
β βββ Light.js
β βββ LightProbe.js
β βββ LightShadow.js
β βββ PointLight.js
β βββ PointLightShadow.js
β βββ RectAreaLight.js
β βββ SpotLight.js
β βββ SpotLightShadow.js
βββ loaders
β βββ AnimationLoader.js
β βββ AudioLoader.js
β βββ BufferGeometryLoader.js
β βββ Cache.js
β βββ CompressedTextureLoader.js
β βββ CubeTextureLoader.js
β βββ DataTextureLoader.js
β βββ FileLoader.js
β βββ FontLoader.js
β βββ ImageBitmapLoader.js
β βββ ImageLoader.js
β βββ Loader.js
β βββ LoaderUtils.js
β βββ LoadingManager.js
β βββ MaterialLoader.js
β βββ ObjectLoader.js
β βββ TextureLoader.js
βββ materials
β βββ LineBasicMaterial.js
β βββ LineDashedMaterial.js
β βββ Material.js
β βββ Materials.js
β βββ MeshBasicMaterial.js
β βββ MeshDepthMaterial.js
β βββ MeshDistanceMaterial.js
β βββ MeshLambertMaterial.js
β βββ MeshMatcapMaterial.js
β βββ MeshNormalMaterial.js
β βββ MeshPhongMaterial.js
β βββ MeshPhysicalMaterial.js
β βββ MeshStandardMaterial.js
β βββ MeshToonMaterial.js
β βββ PointsMaterial.js
β βββ RawShaderMaterial.js
β βββ ShaderMaterial.js
β βββ ShadowMaterial.js
β βββ SpriteMaterial.js
βββ math
β βββ Box2.js
β βββ Box3.js
β βββ Color.js
β βββ Cylindrical.js
β βββ Euler.js
β βββ Frustum.js
β βββ Interpolant.js
β βββ Line3.js
β βββ MathUtils.js
β βββ Matrix3.js
β βββ Matrix4.js
β βββ Plane.js
β βββ Quaternion.js
β βββ Ray.js
β βββ Sphere.js
β βββ Spherical.js
β βββ SphericalHarmonics3.js
β βββ Triangle.js
β βββ Vector2.js
β βββ Vector3.js
β βββ Vector4.js
β βββ interpolants
β βββ CubicInterpolant.js
β βββ DiscreteInterpolant.js
β βββ LinearInterpolant.js
β βββ QuaternionLinearInterpolant.js
βββ objects
β βββ Bone.js
β βββ Group.js
β βββ InstancedMesh.js
β βββ LOD.js
β βββ Line.js
β βββ LineLoop.js
β βββ LineSegments.js
β βββ Mesh.js
β βββ Points.js
β βββ Skeleton.js
β βββ SkinnedMesh.js
β βββ Sprite.js
βββ polyfills.js
βββ renderers
β βββ WebGLCubeRenderTarget.js
β βββ WebGLMultisampleRenderTarget.js
β βββ WebGLRenderTarget.js
β βββ WebGLRenderer.js
β βββ webxr
β βββ WebXRManager.js
βββ scenes
β βββ Fog.js
β βββ FogExp2.js
β βββ Scene.js
βββ textures
β βββ CanvasTexture.js
β βββ CompressedTexture.js
β βββ CubeTexture.js
β βββ DataTexture.js
β βββ DataTexture2DArray.js
β βββ DataTexture3D.js
β βββ DepthTexture.js
β βββ Texture.js
β βββ VideoTexture.js
βββ utils.js
@allsey87 the problem that JS<-->WASM inter-operations is pretty slow and this bindings can be not so good in performance if you send data more than 1-10 in one rAF, look at this comparison https://github.com/ivanceras/sauron-perf. Projects that written completely in Rust looks more consistent. A good mix JS with Rust for example for physics or if you port heavy math to it.
Try to benchmark your solution, sometime I was getting weird result and performance regress when I tried wasm. (self-promotion here https://github.com/munrocket/double.js)
Reportedly it's getting much faster, especially if you can keep the calls monomorphic. Only 1-10 calls per frame would be pretty unfortunate, though, I hope that's not true recently? But I can't see how to count individual calls in the example you link to.
Probably I took too small numbers and it can be 1000, but anyway it's memory copy from wasm sandbox to js runtime with non zero cost. Pretty easy to shoot in a knee when you create rust bindings to JS library.
monomorphic
Interesting article, I doesnβt know that it useful for wasm too.
I am suggested similar monomorphic data structure for tags in β/examples/file.jsβ, but we ended up with dictionary with arrays. Little bit unrelated but I hope mrdoob is reading :)
@donmccurdy thanks for that list of classes, it is at the least a good starting point.
@munrocket so for my use case, I want to connect three.js to nphysics, although my plan is to keep the bindings as consistent as possible with the three.js API so that others can use them for other applications.
Regarding speed in general, there is several proposals at the moment that look like they will make js and wasm interoperability much faster in the near future. This is partially the motivation for developing these bindings, the other part being that it makes sense in the broader scope of a project that I am working on.
Small update on this: I am working at the moment on automatically generating the bindings by parsing the typescript definition files using SWC's ECMA Parser. This will be much more reliable (and far less mind numbing) than doing the bindings by hand ;)
Most helpful comment
Maybe something like: