From b4266d842e9a69db13b9fe5bea2184de121b8cf5 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Wed, 6 Nov 2024 13:30:15 -0800 Subject: [PATCH] update build setup: - export both WebGL and WebGPU renderers from 'three' module so that existing projects can update without needing to configure their existing builds - provide separate optional WebGL-only and WebGPU-only entry points and builds - expose the WebGPU.Nodes builds in package exports for consistency with other builds - rename /src/renderers/extras/PMREMGenerator to PMREMGenerator2 to avoid confusion with src/extras/PMREMGenerator - ensure that all entry points have the same lines, but commented or uncommented, for sanity checking --- package.json | 2 + src/Three.WebGL.js | 209 ++++++++++++++++++ src/Three.WebGPU.Nodes.js | 7 +- src/Three.WebGPU.js | 5 +- src/Three.js | 24 ++ src/nodes/core/NodeBuilder.js | 4 +- .../{PMREMGenerator.js => PMREMGenerator2.js} | 4 +- utils/build/rollup.config.js | 25 +++ 8 files changed, 274 insertions(+), 6 deletions(-) create mode 100644 src/Three.WebGL.js rename src/renderers/common/extras/{PMREMGenerator.js => PMREMGenerator2.js} (99%) diff --git a/package.json b/package.json index e406f104e36786..e2b68cc4b18f21 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "./addons": "./examples/jsm/Addons.js", "./addons/*": "./examples/jsm/*", "./src/*": "./src/*", + "./webgl": "./build/three.webgl.js", "./webgpu": "./build/three.webgpu.js", + "./webgpu.nodes": "./build/three.webgpu.nodes.js", "./tsl": "./build/three.webgpu.js" }, "repository": { diff --git a/src/Three.WebGL.js b/src/Three.WebGL.js new file mode 100644 index 00000000000000..a6d3d68e3f059d --- /dev/null +++ b/src/Three.WebGL.js @@ -0,0 +1,209 @@ +// This entry point exports only WebGLRenderer. + +import { REVISION } from './constants.js'; + +export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js'; +export { WebGL3DRenderTarget } from './renderers/WebGL3DRenderTarget.js'; +export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js'; +export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js'; +export { WebGLRenderer } from './renderers/WebGLRenderer.js'; +export { ShaderLib } from './renderers/shaders/ShaderLib.js'; +export { UniformsLib } from './renderers/shaders/UniformsLib.js'; +export { UniformsUtils } from './renderers/shaders/UniformsUtils.js'; +export { ShaderChunk } from './renderers/shaders/ShaderChunk.js'; +export { FogExp2 } from './scenes/FogExp2.js'; +export { Fog } from './scenes/Fog.js'; +export { Scene } from './scenes/Scene.js'; +export { Sprite } from './objects/Sprite.js'; +export { LOD } from './objects/LOD.js'; +export { SkinnedMesh } from './objects/SkinnedMesh.js'; +export { Skeleton } from './objects/Skeleton.js'; +export { Bone } from './objects/Bone.js'; +export { Mesh } from './objects/Mesh.js'; +export { InstancedMesh } from './objects/InstancedMesh.js'; +export { BatchedMesh } from './objects/BatchedMesh.js'; +export { LineSegments } from './objects/LineSegments.js'; +export { LineLoop } from './objects/LineLoop.js'; +export { Line } from './objects/Line.js'; +export { Points } from './objects/Points.js'; +export { Group } from './objects/Group.js'; +export { VideoTexture } from './textures/VideoTexture.js'; +export { FramebufferTexture } from './textures/FramebufferTexture.js'; +export { Source } from './textures/Source.js'; +export { DataTexture } from './textures/DataTexture.js'; +export { DataArrayTexture } from './textures/DataArrayTexture.js'; +export { Data3DTexture } from './textures/Data3DTexture.js'; +export { CompressedTexture } from './textures/CompressedTexture.js'; +export { CompressedArrayTexture } from './textures/CompressedArrayTexture.js'; +export { CompressedCubeTexture } from './textures/CompressedCubeTexture.js'; +export { CubeTexture } from './textures/CubeTexture.js'; +export { CanvasTexture } from './textures/CanvasTexture.js'; +export { DepthTexture } from './textures/DepthTexture.js'; +export { Texture } from './textures/Texture.js'; +export * from './geometries/Geometries.js'; +export * from './materials/Materials.js'; +// export { Material } from './materials/Material.js'; +export { AnimationLoader } from './loaders/AnimationLoader.js'; +export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js'; +export { CubeTextureLoader } from './loaders/CubeTextureLoader.js'; +export { DataTextureLoader } from './loaders/DataTextureLoader.js'; +export { TextureLoader } from './loaders/TextureLoader.js'; +export { ObjectLoader } from './loaders/ObjectLoader.js'; +export { MaterialLoader } from './loaders/MaterialLoader.js'; +export { BufferGeometryLoader } from './loaders/BufferGeometryLoader.js'; +export { DefaultLoadingManager, LoadingManager } from './loaders/LoadingManager.js'; +export { ImageLoader } from './loaders/ImageLoader.js'; +export { ImageBitmapLoader } from './loaders/ImageBitmapLoader.js'; +export { FileLoader } from './loaders/FileLoader.js'; +export { Loader } from './loaders/Loader.js'; +export { LoaderUtils } from './loaders/LoaderUtils.js'; +export { Cache } from './loaders/Cache.js'; +export { AudioLoader } from './loaders/AudioLoader.js'; +export { SpotLight } from './lights/SpotLight.js'; +export { PointLight } from './lights/PointLight.js'; +export { RectAreaLight } from './lights/RectAreaLight.js'; +export { HemisphereLight } from './lights/HemisphereLight.js'; +export { DirectionalLight } from './lights/DirectionalLight.js'; +export { AmbientLight } from './lights/AmbientLight.js'; +export { Light } from './lights/Light.js'; +export { LightProbe } from './lights/LightProbe.js'; +export { StereoCamera } from './cameras/StereoCamera.js'; +export { PerspectiveCamera } from './cameras/PerspectiveCamera.js'; +export { OrthographicCamera } from './cameras/OrthographicCamera.js'; +export { CubeCamera } from './cameras/CubeCamera.js'; +export { ArrayCamera } from './cameras/ArrayCamera.js'; +export { Camera } from './cameras/Camera.js'; +export { AudioListener } from './audio/AudioListener.js'; +export { PositionalAudio } from './audio/PositionalAudio.js'; +export { AudioContext } from './audio/AudioContext.js'; +export { AudioAnalyser } from './audio/AudioAnalyser.js'; +export { Audio } from './audio/Audio.js'; +export { VectorKeyframeTrack } from './animation/tracks/VectorKeyframeTrack.js'; +export { StringKeyframeTrack } from './animation/tracks/StringKeyframeTrack.js'; +export { QuaternionKeyframeTrack } from './animation/tracks/QuaternionKeyframeTrack.js'; +export { NumberKeyframeTrack } from './animation/tracks/NumberKeyframeTrack.js'; +export { ColorKeyframeTrack } from './animation/tracks/ColorKeyframeTrack.js'; +export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js'; +export { PropertyMixer } from './animation/PropertyMixer.js'; +export { PropertyBinding } from './animation/PropertyBinding.js'; +export { KeyframeTrack } from './animation/KeyframeTrack.js'; +export { AnimationUtils } from './animation/AnimationUtils.js'; +export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js'; +export { AnimationMixer } from './animation/AnimationMixer.js'; +export { AnimationClip } from './animation/AnimationClip.js'; +export { AnimationAction } from './animation/AnimationAction.js'; +export { RenderTarget } from './core/RenderTarget.js'; +export { Uniform } from './core/Uniform.js'; +export { UniformsGroup } from './core/UniformsGroup.js'; +export { InstancedBufferGeometry } from './core/InstancedBufferGeometry.js'; +export { BufferGeometry } from './core/BufferGeometry.js'; +export { InterleavedBufferAttribute } from './core/InterleavedBufferAttribute.js'; +export { InstancedInterleavedBuffer } from './core/InstancedInterleavedBuffer.js'; +export { InterleavedBuffer } from './core/InterleavedBuffer.js'; +export { InstancedBufferAttribute } from './core/InstancedBufferAttribute.js'; +export { GLBufferAttribute } from './core/GLBufferAttribute.js'; +export * from './core/BufferAttribute.js'; +export { Object3D } from './core/Object3D.js'; +export { Raycaster } from './core/Raycaster.js'; +export { Layers } from './core/Layers.js'; +export { EventDispatcher } from './core/EventDispatcher.js'; +export { Clock } from './core/Clock.js'; +export { QuaternionLinearInterpolant } from './math/interpolants/QuaternionLinearInterpolant.js'; +export { LinearInterpolant } from './math/interpolants/LinearInterpolant.js'; +export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js'; +export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js'; +export { Interpolant } from './math/Interpolant.js'; +export { Triangle } from './math/Triangle.js'; +export { MathUtils } from './math/MathUtils.js'; +export { Spherical } from './math/Spherical.js'; +export { Cylindrical } from './math/Cylindrical.js'; +export { Plane } from './math/Plane.js'; +export { Frustum } from './math/Frustum.js'; +export { Sphere } from './math/Sphere.js'; +export { Ray } from './math/Ray.js'; +export { Matrix4 } from './math/Matrix4.js'; +export { Matrix3 } from './math/Matrix3.js'; +export { Matrix2 } from './math/Matrix2.js'; +export { Box3 } from './math/Box3.js'; +export { Box2 } from './math/Box2.js'; +export { Line3 } from './math/Line3.js'; +export { Euler } from './math/Euler.js'; +export { Vector4 } from './math/Vector4.js'; +export { Vector3 } from './math/Vector3.js'; +export { Vector2 } from './math/Vector2.js'; +export { Quaternion } from './math/Quaternion.js'; +export { Color } from './math/Color.js'; +export { ColorManagement } from './math/ColorManagement.js'; +export { SphericalHarmonics3 } from './math/SphericalHarmonics3.js'; +export { SpotLightHelper } from './helpers/SpotLightHelper.js'; +export { SkeletonHelper } from './helpers/SkeletonHelper.js'; +export { PointLightHelper } from './helpers/PointLightHelper.js'; +export { HemisphereLightHelper } from './helpers/HemisphereLightHelper.js'; +export { GridHelper } from './helpers/GridHelper.js'; +export { PolarGridHelper } from './helpers/PolarGridHelper.js'; +export { DirectionalLightHelper } from './helpers/DirectionalLightHelper.js'; +export { CameraHelper } from './helpers/CameraHelper.js'; +export { BoxHelper } from './helpers/BoxHelper.js'; +export { Box3Helper } from './helpers/Box3Helper.js'; +export { PlaneHelper } from './helpers/PlaneHelper.js'; +export { ArrowHelper } from './helpers/ArrowHelper.js'; +export { AxesHelper } from './helpers/AxesHelper.js'; +export * from './extras/curves/Curves.js'; +export { Shape } from './extras/core/Shape.js'; +export { Path } from './extras/core/Path.js'; +export { ShapePath } from './extras/core/ShapePath.js'; +export { CurvePath } from './extras/core/CurvePath.js'; +export { Curve } from './extras/core/Curve.js'; +export { Controls } from './extras/Controls.js'; +export { DataUtils } from './extras/DataUtils.js'; +export { ImageUtils } from './extras/ImageUtils.js'; +export { ShapeUtils } from './extras/ShapeUtils.js'; +export { TextureUtils } from './extras/TextureUtils.js'; +export { PMREMGenerator } from './extras/PMREMGenerator.js'; +export { WebGLUtils } from './renderers/webgl/WebGLUtils.js'; +export { createCanvasElement } from './utils.js'; +export * from './constants.js'; +export * from './Three.Legacy.js'; + +//export * from './materials/nodes/NodeMaterials.js'; +//export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.js'; +//export { default as ClippingGroup } from './renderers/common/ClippingGroup.js'; +//export { default as Lighting } from './renderers/common/Lighting.js'; +//export { default as BundleGroup } from './renderers/common/BundleGroup.js'; +//export { default as QuadMesh } from './renderers/common/QuadMesh.js'; +//export { default as PMREMGenerator2 } from './renderers/common/extras/PMREMGenerator2.js'; +//export { default as PostProcessing } from './renderers/common/PostProcessing.js'; +//import * as PostProcessingUtils from './renderers/common/PostProcessingUtils.js'; +//export { PostProcessingUtils }; +//export { default as StorageTexture } from './renderers/common/StorageTexture.js'; +//export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js'; +//export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js'; +//export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js'; +//export { default as IESSpotLight } from './lights/webgpu/IESSpotLight.js'; +//export { default as NodeLoader } from './loaders/nodes/NodeLoader.js'; +//export { default as NodeObjectLoader } from './loaders/nodes/NodeObjectLoader.js'; +//export { default as NodeMaterialLoader } from './loaders/nodes/NodeMaterialLoader.js'; +//export * from './nodes/Nodes.js'; +//export * from './nodes/TSL.js'; + +if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: { + revision: REVISION, + } } ) ); + +} + +if ( typeof window !== 'undefined' ) { + + if ( window.__THREE__ ) { + + console.warn( 'WARNING: Multiple instances of Three.js being imported.' ); + + } else { + + window.__THREE__ = REVISION; + + } + +} diff --git a/src/Three.WebGPU.Nodes.js b/src/Three.WebGPU.Nodes.js index 8c021dca947b60..5320a61281db1e 100644 --- a/src/Three.WebGPU.Nodes.js +++ b/src/Three.WebGPU.Nodes.js @@ -1,3 +1,5 @@ +// This entry point exports only WebGPURenderer.Nodes. + import { REVISION } from './constants.js'; export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js'; @@ -156,6 +158,7 @@ export { Controls } from './extras/Controls.js'; export { DataUtils } from './extras/DataUtils.js'; export { ImageUtils } from './extras/ImageUtils.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; +//export { TextureUtils } from './extras/TextureUtils.js'; //export { PMREMGenerator } from './extras/PMREMGenerator.js'; //export { WebGLUtils } from './renderers/webgl/WebGLUtils.js'; export { createCanvasElement } from './utils.js'; @@ -164,9 +167,11 @@ export * from './Three.Legacy.js'; export * from './materials/nodes/NodeMaterials.js'; export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.Nodes.js'; +// export { default as ClippingGroup } from './renderers/common/ClippingGroup.js'; export { default as Lighting } from './renderers/common/Lighting.js'; +// export { default as BundleGroup } from './renderers/common/BundleGroup.js'; export { default as QuadMesh } from './renderers/common/QuadMesh.js'; -export { default as PMREMGenerator } from './renderers/common/extras/PMREMGenerator.js'; +export { default as PMREMGenerator2 } from './renderers/common/extras/PMREMGenerator2.js'; export { default as PostProcessing } from './renderers/common/PostProcessing.js'; import * as PostProcessingUtils from './renderers/common/PostProcessingUtils.js'; export { PostProcessingUtils }; diff --git a/src/Three.WebGPU.js b/src/Three.WebGPU.js index eb77205de000ed..66861cc83fdd0f 100644 --- a/src/Three.WebGPU.js +++ b/src/Three.WebGPU.js @@ -1,3 +1,5 @@ +// This entry point exports only WebGPURenderer. + import { REVISION } from './constants.js'; export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js'; @@ -156,6 +158,7 @@ export { Controls } from './extras/Controls.js'; export { DataUtils } from './extras/DataUtils.js'; export { ImageUtils } from './extras/ImageUtils.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; +//export { TextureUtils } from './extras/TextureUtils.js'; //export { PMREMGenerator } from './extras/PMREMGenerator.js'; //export { WebGLUtils } from './renderers/webgl/WebGLUtils.js'; export { createCanvasElement } from './utils.js'; @@ -168,7 +171,7 @@ export { default as ClippingGroup } from './renderers/common/ClippingGroup.js'; export { default as Lighting } from './renderers/common/Lighting.js'; export { default as BundleGroup } from './renderers/common/BundleGroup.js'; export { default as QuadMesh } from './renderers/common/QuadMesh.js'; -export { default as PMREMGenerator } from './renderers/common/extras/PMREMGenerator.js'; +export { default as PMREMGenerator2 } from './renderers/common/extras/PMREMGenerator2.js'; export { default as PostProcessing } from './renderers/common/PostProcessing.js'; import * as PostProcessingUtils from './renderers/common/PostProcessingUtils.js'; export { PostProcessingUtils }; diff --git a/src/Three.js b/src/Three.js index df38bf82139a10..66cbcd472ab70b 100644 --- a/src/Three.js +++ b/src/Three.js @@ -1,3 +1,5 @@ +// This entry point exports all renderers. + import { REVISION } from './constants.js'; export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js'; @@ -40,6 +42,7 @@ export { DepthTexture } from './textures/DepthTexture.js'; export { Texture } from './textures/Texture.js'; export * from './geometries/Geometries.js'; export * from './materials/Materials.js'; +export { Material } from './materials/Material.js'; export { AnimationLoader } from './loaders/AnimationLoader.js'; export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js'; export { CubeTextureLoader } from './loaders/CubeTextureLoader.js'; @@ -162,6 +165,27 @@ export { createCanvasElement } from './utils.js'; export * from './constants.js'; export * from './Three.Legacy.js'; +export * from './materials/nodes/NodeMaterials.js'; +export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.js'; +export { default as ClippingGroup } from './renderers/common/ClippingGroup.js'; +export { default as Lighting } from './renderers/common/Lighting.js'; +export { default as BundleGroup } from './renderers/common/BundleGroup.js'; +export { default as QuadMesh } from './renderers/common/QuadMesh.js'; +export { default as PMREMGenerator2 } from './renderers/common/extras/PMREMGenerator2.js'; +export { default as PostProcessing } from './renderers/common/PostProcessing.js'; +import * as PostProcessingUtils from './renderers/common/PostProcessingUtils.js'; +export { PostProcessingUtils }; +export { default as StorageTexture } from './renderers/common/StorageTexture.js'; +export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js'; +export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js'; +export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js'; +export { default as IESSpotLight } from './lights/webgpu/IESSpotLight.js'; +export { default as NodeLoader } from './loaders/nodes/NodeLoader.js'; +export { default as NodeObjectLoader } from './loaders/nodes/NodeObjectLoader.js'; +export { default as NodeMaterialLoader } from './loaders/nodes/NodeMaterialLoader.js'; +export * from './nodes/Nodes.js'; +export * from './nodes/TSL.js'; + if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: { diff --git a/src/nodes/core/NodeBuilder.js b/src/nodes/core/NodeBuilder.js index 33c8262519676f..5893c235b59ac5 100644 --- a/src/nodes/core/NodeBuilder.js +++ b/src/nodes/core/NodeBuilder.js @@ -20,7 +20,7 @@ import { getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js'; import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js'; import ChainMap from '../../renderers/common/ChainMap.js'; -import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js'; +import PMREMGenerator2 from '../../renderers/common/extras/PMREMGenerator2.js'; import BindGroup from '../../renderers/common/BindGroup.js'; @@ -168,7 +168,7 @@ class NodeBuilder { // TODO: Move Materials.js to outside of the Nodes.js in order to remove this function and improve tree-shaking support - return new PMREMGenerator( this.renderer ); + return new PMREMGenerator2( this.renderer ); } diff --git a/src/renderers/common/extras/PMREMGenerator.js b/src/renderers/common/extras/PMREMGenerator2.js similarity index 99% rename from src/renderers/common/extras/PMREMGenerator.js rename to src/renderers/common/extras/PMREMGenerator2.js index 110bc0f7639053..07f7d44771177a 100644 --- a/src/renderers/common/extras/PMREMGenerator.js +++ b/src/renderers/common/extras/PMREMGenerator2.js @@ -95,7 +95,7 @@ const outputDirection = vec3( direction.x, direction.y.negate(), direction.z ); * https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view */ -class PMREMGenerator { +class PMREMGenerator2 { constructor( renderer ) { @@ -768,4 +768,4 @@ function _getEquirectMaterial( envTexture ) { } -export default PMREMGenerator; +export default PMREMGenerator2; diff --git a/utils/build/rollup.config.js b/utils/build/rollup.config.js index eb5a722af03e22..9e2956457b20d8 100644 --- a/utils/build/rollup.config.js +++ b/utils/build/rollup.config.js @@ -74,6 +74,18 @@ const builds = [ } ] }, + { + input: 'src/Three.WebGL.js', + plugins: [ + header() + ], + output: [ + { + format: 'esm', + file: 'build/three.webgl.js' + } + ] + }, { input: 'src/Three.WebGPU.js', plugins: [ @@ -112,6 +124,19 @@ const builds = [ } ] }, + { + input: 'src/Three.WebGL.js', + plugins: [ + header(), + terser() + ], + output: [ + { + format: 'esm', + file: 'build/three.webgl.min.js' + } + ] + }, { input: 'src/Three.WebGPU.js', plugins: [