@anov/3d 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -1
- package/dist/core/camera.d.ts +31 -4
- package/dist/core/camera.js +62 -52
- package/dist/core/control/transformControls.d.ts +12 -0
- package/dist/core/control/transformControls.js +72 -0
- package/dist/core/cssRenderer.d.ts +17 -0
- package/dist/core/cssRenderer.js +36 -0
- package/dist/core/global/global.d.ts +27 -0
- package/dist/core/global/global.js +72 -0
- package/dist/core/global/globalControl.d.ts +17 -0
- package/dist/core/global/globalControl.js +62 -0
- package/dist/core/group.d.ts +51 -6
- package/dist/core/group.js +124 -16
- package/dist/core/line.d.ts +13 -0
- package/dist/core/line.js +83 -0
- package/dist/core/mesh.d.ts +12 -7
- package/dist/core/mesh.js +57 -56
- package/dist/core/model.d.ts +11 -3
- package/dist/core/model.js +34 -7
- package/dist/core/scene.d.ts +84 -25
- package/dist/core/scene.js +207 -53
- package/dist/core/use/useScene.d.ts +10 -0
- package/dist/core/use/useScene.js +14 -0
- package/dist/core/use/useframe.d.ts +6 -0
- package/dist/core/use/useframe.js +11 -0
- package/dist/export.d.ts +41 -0
- package/dist/export.js +37 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.js +5 -6
- package/dist/threeCell.d.ts +8 -0
- package/dist/threeCell.js +16 -0
- package/dist/type.d.ts +4 -3
- package/dist/utils/createElement.d.ts +103 -0
- package/dist/utils/createElement.js +145 -0
- package/dist/utils/createLabel.d.ts +2 -0
- package/dist/utils/createLabel.js +4 -0
- package/dist/utils/index.d.ts +36 -0
- package/dist/utils/index.js +76 -0
- package/dist/utils/line.d.ts +0 -0
- package/dist/utils/line.js +0 -0
- package/dist/utils/move.d.ts +48 -0
- package/dist/utils/move.js +149 -0
- package/examples/fonts/LICENSE +13 -0
- package/examples/fonts/README.md +11 -0
- package/examples/fonts/droid/NOTICE +190 -0
- package/examples/fonts/droid/README.txt +18 -0
- package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
- package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
- package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
- package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
- package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
- package/examples/fonts/gentilis_bold.typeface.json +1 -0
- package/examples/fonts/gentilis_regular.typeface.json +1 -0
- package/examples/fonts/helvetiker_bold.typeface.json +1 -0
- package/examples/fonts/helvetiker_regular.typeface.json +1 -0
- package/examples/fonts/optimer_bold.typeface.json +1 -0
- package/examples/fonts/optimer_regular.typeface.json +1 -0
- package/examples/fonts/ttf/README.md +9 -0
- package/examples/fonts/ttf/kenpixel.ttf +0 -0
- package/examples/jsm/animation/AnimationClipCreator.js +116 -0
- package/examples/jsm/animation/CCDIKSolver.js +482 -0
- package/examples/jsm/animation/MMDAnimationHelper.js +1207 -0
- package/examples/jsm/animation/MMDPhysics.js +1406 -0
- package/examples/jsm/cameras/CinematicCamera.js +208 -0
- package/examples/jsm/capabilities/WebGL.js +91 -0
- package/examples/jsm/capabilities/WebGPU.js +53 -0
- package/examples/jsm/controls/ArcballControls.js +3224 -0
- package/examples/jsm/controls/DragControls.js +220 -0
- package/examples/jsm/controls/FirstPersonControls.js +325 -0
- package/examples/jsm/controls/FlyControls.js +300 -0
- package/examples/jsm/controls/MapControls.js +28 -0
- package/examples/jsm/controls/OrbitControls.js +1388 -0
- package/examples/jsm/controls/PointerLockControls.js +162 -0
- package/examples/jsm/controls/TrackballControls.js +828 -0
- package/examples/jsm/controls/TransformControls.js +1557 -0
- package/examples/jsm/csm/CSM.js +384 -0
- package/examples/jsm/csm/CSMFrustum.js +152 -0
- package/examples/jsm/csm/CSMHelper.js +193 -0
- package/examples/jsm/csm/CSMShader.js +252 -0
- package/examples/jsm/curves/CurveExtras.js +422 -0
- package/examples/jsm/curves/NURBSCurve.js +80 -0
- package/examples/jsm/curves/NURBSSurface.js +52 -0
- package/examples/jsm/curves/NURBSUtils.js +487 -0
- package/examples/jsm/effects/AnaglyphEffect.js +154 -0
- package/examples/jsm/effects/AsciiEffect.js +263 -0
- package/examples/jsm/effects/OutlineEffect.js +539 -0
- package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -0
- package/examples/jsm/effects/PeppersGhostEffect.js +153 -0
- package/examples/jsm/effects/StereoEffect.js +55 -0
- package/examples/jsm/environments/DebugEnvironment.js +52 -0
- package/examples/jsm/environments/RoomEnvironment.js +148 -0
- package/examples/jsm/exporters/DRACOExporter.js +267 -0
- package/examples/jsm/exporters/EXRExporter.js +501 -0
- package/examples/jsm/exporters/GLTFExporter.js +3161 -0
- package/examples/jsm/exporters/KTX2Exporter.js +292 -0
- package/examples/jsm/exporters/MMDExporter.js +217 -0
- package/examples/jsm/exporters/OBJExporter.js +284 -0
- package/examples/jsm/exporters/PLYExporter.js +528 -0
- package/examples/jsm/exporters/STLExporter.js +199 -0
- package/examples/jsm/exporters/USDZExporter.js +711 -0
- package/examples/jsm/geometries/BoxLineGeometry.js +69 -0
- package/examples/jsm/geometries/ConvexGeometry.js +53 -0
- package/examples/jsm/geometries/DecalGeometry.js +356 -0
- package/examples/jsm/geometries/ParametricGeometries.js +254 -0
- package/examples/jsm/geometries/ParametricGeometry.js +139 -0
- package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -0
- package/examples/jsm/geometries/TeapotGeometry.js +704 -0
- package/examples/jsm/geometries/TextGeometry.js +57 -0
- package/examples/jsm/helpers/LightProbeHelper.js +130 -0
- package/examples/jsm/helpers/OctreeHelper.js +73 -0
- package/examples/jsm/helpers/PositionalAudioHelper.js +109 -0
- package/examples/jsm/helpers/RectAreaLightHelper.js +85 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +96 -0
- package/examples/jsm/helpers/VertexTangentsHelper.js +88 -0
- package/examples/jsm/helpers/ViewHelper.js +333 -0
- package/examples/jsm/interactive/HTMLMesh.js +565 -0
- package/examples/jsm/interactive/InteractiveGroup.js +116 -0
- package/examples/jsm/interactive/SelectionBox.js +227 -0
- package/examples/jsm/interactive/SelectionHelper.js +104 -0
- package/examples/jsm/libs/ammo.wasm.js +822 -0
- package/examples/jsm/libs/ammo.wasm.wasm +0 -0
- package/examples/jsm/libs/basis/README.md +46 -0
- package/examples/jsm/libs/basis/basis_transcoder.js +21 -0
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/chevrotain.module.min.js +141 -0
- package/examples/jsm/libs/draco/README.md +32 -0
- package/examples/jsm/libs/draco/draco_decoder.js +34 -0
- package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/draco_encoder.js +33 -0
- package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
- package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
- package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
- package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/examples/jsm/libs/ecsy.module.js +1792 -0
- package/examples/jsm/libs/fflate.module.js +2474 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -0
- package/examples/jsm/libs/lil-gui.module.min.js +8 -0
- package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +178 -0
- package/examples/jsm/libs/mikktspace.module.js +128 -0
- package/examples/jsm/libs/mmdparser.module.js +11530 -0
- package/examples/jsm/libs/motion-controllers.module.js +397 -0
- package/examples/jsm/libs/opentype.module.js +14568 -0
- package/examples/jsm/libs/potpack.module.js +125 -0
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/libs/stats.module.js +167 -0
- package/examples/jsm/libs/tween.module.js +803 -0
- package/examples/jsm/libs/utif.module.js +1579 -0
- package/examples/jsm/libs/zstddec.module.js +1 -0
- package/examples/jsm/lights/IESSpotLight.js +25 -0
- package/examples/jsm/lights/LightProbeGenerator.js +252 -0
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -0
- package/examples/jsm/lines/Line2.js +19 -0
- package/examples/jsm/lines/LineGeometry.js +79 -0
- package/examples/jsm/lines/LineMaterial.js +702 -0
- package/examples/jsm/lines/LineSegments2.js +361 -0
- package/examples/jsm/lines/LineSegmentsGeometry.js +241 -0
- package/examples/jsm/lines/Wireframe.js +56 -0
- package/examples/jsm/lines/WireframeGeometry2.js +24 -0
- package/examples/jsm/loaders/3DMLoader.js +1497 -0
- package/examples/jsm/loaders/3MFLoader.js +1478 -0
- package/examples/jsm/loaders/AMFLoader.js +521 -0
- package/examples/jsm/loaders/BVHLoader.js +437 -0
- package/examples/jsm/loaders/ColladaLoader.js +4122 -0
- package/examples/jsm/loaders/DDSLoader.js +274 -0
- package/examples/jsm/loaders/DRACOLoader.js +612 -0
- package/examples/jsm/loaders/EXRLoader.js +2309 -0
- package/examples/jsm/loaders/FBXLoader.js +4142 -0
- package/examples/jsm/loaders/FontLoader.js +183 -0
- package/examples/jsm/loaders/GCodeLoader.js +261 -0
- package/examples/jsm/loaders/GLTFLoader.js +4576 -0
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -0
- package/examples/jsm/loaders/IESLoader.js +337 -0
- package/examples/jsm/loaders/KMZLoader.js +130 -0
- package/examples/jsm/loaders/KTX2Loader.js +868 -0
- package/examples/jsm/loaders/KTXLoader.js +176 -0
- package/examples/jsm/loaders/LDrawLoader.js +2464 -0
- package/examples/jsm/loaders/LUT3dlLoader.js +151 -0
- package/examples/jsm/loaders/LUTCubeLoader.js +153 -0
- package/examples/jsm/loaders/LWOLoader.js +1052 -0
- package/examples/jsm/loaders/LogLuvLoader.js +606 -0
- package/examples/jsm/loaders/LottieLoader.js +77 -0
- package/examples/jsm/loaders/MD2Loader.js +399 -0
- package/examples/jsm/loaders/MDDLoader.js +102 -0
- package/examples/jsm/loaders/MMDLoader.js +2273 -0
- package/examples/jsm/loaders/MTLLoader.js +567 -0
- package/examples/jsm/loaders/MaterialXLoader.js +734 -0
- package/examples/jsm/loaders/NRRDLoader.js +699 -0
- package/examples/jsm/loaders/OBJLoader.js +905 -0
- package/examples/jsm/loaders/PCDLoader.js +467 -0
- package/examples/jsm/loaders/PDBLoader.js +232 -0
- package/examples/jsm/loaders/PLYLoader.js +771 -0
- package/examples/jsm/loaders/PVRLoader.js +251 -0
- package/examples/jsm/loaders/RGBELoader.js +468 -0
- package/examples/jsm/loaders/RGBMLoader.js +1065 -0
- package/examples/jsm/loaders/STLLoader.js +403 -0
- package/examples/jsm/loaders/SVGLoader.js +3172 -0
- package/examples/jsm/loaders/TDSLoader.js +1124 -0
- package/examples/jsm/loaders/TGALoader.js +517 -0
- package/examples/jsm/loaders/TIFFLoader.js +36 -0
- package/examples/jsm/loaders/TTFLoader.js +214 -0
- package/examples/jsm/loaders/TiltLoader.js +520 -0
- package/examples/jsm/loaders/USDZLoader.js +633 -0
- package/examples/jsm/loaders/VOXLoader.js +311 -0
- package/examples/jsm/loaders/VRMLLoader.js +3533 -0
- package/examples/jsm/loaders/VTKLoader.js +1163 -0
- package/examples/jsm/loaders/XYZLoader.js +106 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +1218 -0
- package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
- package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
- package/examples/jsm/materials/MeshGouraudMaterial.js +420 -0
- package/examples/jsm/math/Capsule.js +137 -0
- package/examples/jsm/math/ColorConverter.js +36 -0
- package/examples/jsm/math/ConvexHull.js +1271 -0
- package/examples/jsm/math/ImprovedNoise.js +71 -0
- package/examples/jsm/math/Lut.js +204 -0
- package/examples/jsm/math/MeshSurfaceSampler.js +250 -0
- package/examples/jsm/math/OBB.js +423 -0
- package/examples/jsm/math/Octree.js +462 -0
- package/examples/jsm/math/SimplexNoise.js +444 -0
- package/examples/jsm/misc/ConvexObjectBreaker.js +519 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +446 -0
- package/examples/jsm/misc/Gyroscope.js +66 -0
- package/examples/jsm/misc/MD2Character.js +276 -0
- package/examples/jsm/misc/MD2CharacterComplex.js +576 -0
- package/examples/jsm/misc/MorphAnimMesh.js +75 -0
- package/examples/jsm/misc/MorphBlendMesh.js +322 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +323 -0
- package/examples/jsm/misc/RollerCoaster.js +566 -0
- package/examples/jsm/misc/TubePainter.js +205 -0
- package/examples/jsm/misc/Volume.js +473 -0
- package/examples/jsm/misc/VolumeSlice.js +229 -0
- package/examples/jsm/modifiers/CurveModifier.js +326 -0
- package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +525 -0
- package/examples/jsm/modifiers/TessellateModifier.js +307 -0
- package/examples/jsm/nodes/Nodes.js +171 -0
- package/examples/jsm/nodes/accessors/BitangentNode.js +89 -0
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +99 -0
- package/examples/jsm/nodes/accessors/BufferNode.js +30 -0
- package/examples/jsm/nodes/accessors/CameraNode.js +98 -0
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +103 -0
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +77 -0
- package/examples/jsm/nodes/accessors/InstanceNode.js +71 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +267 -0
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +39 -0
- package/examples/jsm/nodes/accessors/ModelNode.js +34 -0
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +29 -0
- package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
- package/examples/jsm/nodes/accessors/NormalNode.js +96 -0
- package/examples/jsm/nodes/accessors/Object3DNode.js +150 -0
- package/examples/jsm/nodes/accessors/PointUVNode.js +26 -0
- package/examples/jsm/nodes/accessors/PositionNode.js +104 -0
- package/examples/jsm/nodes/accessors/ReferenceNode.js +72 -0
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -0
- package/examples/jsm/nodes/accessors/SceneNode.js +52 -0
- package/examples/jsm/nodes/accessors/SkinningNode.js +93 -0
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +27 -0
- package/examples/jsm/nodes/accessors/TangentNode.js +103 -0
- package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +271 -0
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
- package/examples/jsm/nodes/accessors/UVNode.js +47 -0
- package/examples/jsm/nodes/accessors/UserDataNode.js +29 -0
- package/examples/jsm/nodes/code/CodeNode.js +78 -0
- package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
- package/examples/jsm/nodes/code/FunctionCallNode.js +96 -0
- package/examples/jsm/nodes/code/FunctionNode.js +127 -0
- package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
- package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
- package/examples/jsm/nodes/core/ArrayUniformNode.js +26 -0
- package/examples/jsm/nodes/core/AttributeNode.js +102 -0
- package/examples/jsm/nodes/core/BypassNode.js +45 -0
- package/examples/jsm/nodes/core/CacheNode.js +46 -0
- package/examples/jsm/nodes/core/ConstNode.js +32 -0
- package/examples/jsm/nodes/core/ContextNode.js +61 -0
- package/examples/jsm/nodes/core/IndexNode.js +66 -0
- package/examples/jsm/nodes/core/InputNode.js +83 -0
- package/examples/jsm/nodes/core/LightingModel.js +15 -0
- package/examples/jsm/nodes/core/Node.js +454 -0
- package/examples/jsm/nodes/core/NodeAttribute.js +15 -0
- package/examples/jsm/nodes/core/NodeBuilder.js +1016 -0
- package/examples/jsm/nodes/core/NodeCache.js +26 -0
- package/examples/jsm/nodes/core/NodeCode.js +15 -0
- package/examples/jsm/nodes/core/NodeFrame.js +110 -0
- package/examples/jsm/nodes/core/NodeFunction.js +22 -0
- package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -0
- package/examples/jsm/nodes/core/NodeKeywords.js +80 -0
- package/examples/jsm/nodes/core/NodeParser.js +11 -0
- package/examples/jsm/nodes/core/NodeUniform.js +28 -0
- package/examples/jsm/nodes/core/NodeUtils.js +212 -0
- package/examples/jsm/nodes/core/NodeVar.js +14 -0
- package/examples/jsm/nodes/core/NodeVarying.js +17 -0
- package/examples/jsm/nodes/core/PropertyNode.js +61 -0
- package/examples/jsm/nodes/core/StackNode.js +99 -0
- package/examples/jsm/nodes/core/TempNode.js +58 -0
- package/examples/jsm/nodes/core/UniformNode.js +61 -0
- package/examples/jsm/nodes/core/VarNode.js +87 -0
- package/examples/jsm/nodes/core/VaryingNode.js +69 -0
- package/examples/jsm/nodes/core/constants.js +27 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +99 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +100 -0
- package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -0
- package/examples/jsm/nodes/display/FrontFacingNode.js +27 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +106 -0
- package/examples/jsm/nodes/display/PosterizeNode.js +32 -0
- package/examples/jsm/nodes/display/ToneMappingNode.js +141 -0
- package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
- package/examples/jsm/nodes/display/ViewportNode.js +115 -0
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -0
- package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -0
- package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
- package/examples/jsm/nodes/fog/FogNode.js +37 -0
- package/examples/jsm/nodes/fog/FogRangeNode.js +34 -0
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -0
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +29 -0
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +18 -0
- package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -0
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +20 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +343 -0
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -0
- package/examples/jsm/nodes/functions/material/getRoughness.js +18 -0
- package/examples/jsm/nodes/geometry/RangeNode.js +104 -0
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -0
- package/examples/jsm/nodes/lighting/AONode.js +27 -0
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +184 -0
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -0
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +191 -0
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -0
- package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
- package/examples/jsm/nodes/lighting/LightNode.js +57 -0
- package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
- package/examples/jsm/nodes/lighting/LightingContextNode.js +102 -0
- package/examples/jsm/nodes/lighting/LightingNode.js +21 -0
- package/examples/jsm/nodes/lighting/LightsNode.js +128 -0
- package/examples/jsm/nodes/lighting/PointLightNode.js +68 -0
- package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -0
- package/examples/jsm/nodes/loaders/NodeLoader.js +108 -0
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -0
- package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -0
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -0
- package/examples/jsm/nodes/materials/Materials.js +12 -0
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +27 -0
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -0
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -0
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +128 -0
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +536 -0
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +49 -0
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +103 -0
- package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -0
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -0
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +56 -0
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +618 -0
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +19 -0
- package/examples/jsm/nodes/math/CondNode.js +86 -0
- package/examples/jsm/nodes/math/MathNode.js +359 -0
- package/examples/jsm/nodes/math/OperatorNode.js +269 -0
- package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -0
- package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -0
- package/examples/jsm/nodes/procedural/CheckerNode.js +42 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +420 -0
- package/examples/jsm/nodes/utils/ArrayElementNode.js +33 -0
- package/examples/jsm/nodes/utils/ConvertNode.js +65 -0
- package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
- package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -0
- package/examples/jsm/nodes/utils/JoinNode.js +51 -0
- package/examples/jsm/nodes/utils/LoopNode.js +186 -0
- package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -0
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -0
- package/examples/jsm/nodes/utils/OscNode.js +81 -0
- package/examples/jsm/nodes/utils/PackingNode.js +55 -0
- package/examples/jsm/nodes/utils/RemapNode.js +42 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +43 -0
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
- package/examples/jsm/nodes/utils/SplitNode.js +104 -0
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -0
- package/examples/jsm/nodes/utils/TimerNode.js +94 -0
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -0
- package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
- package/examples/jsm/objects/Lensflare.js +377 -0
- package/examples/jsm/objects/MarchingCubes.js +1176 -0
- package/examples/jsm/objects/Reflector.js +264 -0
- package/examples/jsm/objects/ReflectorForSSRPass.js +349 -0
- package/examples/jsm/objects/Refractor.js +324 -0
- package/examples/jsm/objects/ShadowMesh.js +80 -0
- package/examples/jsm/objects/Sky.js +219 -0
- package/examples/jsm/objects/Water.js +330 -0
- package/examples/jsm/objects/Water2.js +358 -0
- package/examples/jsm/offscreen/jank.js +45 -0
- package/examples/jsm/offscreen/offscreen.js +8 -0
- package/examples/jsm/offscreen/scene.js +86 -0
- package/examples/jsm/physics/AmmoPhysics.js +285 -0
- package/examples/jsm/physics/RapierPhysics.js +199 -0
- package/examples/jsm/postprocessing/AfterimagePass.js +104 -0
- package/examples/jsm/postprocessing/BloomPass.js +172 -0
- package/examples/jsm/postprocessing/BokehPass.js +140 -0
- package/examples/jsm/postprocessing/ClearPass.js +46 -0
- package/examples/jsm/postprocessing/CubeTexturePass.js +85 -0
- package/examples/jsm/postprocessing/DotScreenPass.js +65 -0
- package/examples/jsm/postprocessing/EffectComposer.js +231 -0
- package/examples/jsm/postprocessing/FilmPass.js +66 -0
- package/examples/jsm/postprocessing/GlitchPass.js +128 -0
- package/examples/jsm/postprocessing/HalftonePass.js +79 -0
- package/examples/jsm/postprocessing/LUTPass.js +173 -0
- package/examples/jsm/postprocessing/MaskPass.js +104 -0
- package/examples/jsm/postprocessing/OutlinePass.js +654 -0
- package/examples/jsm/postprocessing/OutputPass.js +91 -0
- package/examples/jsm/postprocessing/Pass.js +84 -0
- package/examples/jsm/postprocessing/RenderPass.js +81 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -0
- package/examples/jsm/postprocessing/SAOPass.js +411 -0
- package/examples/jsm/postprocessing/SMAAPass.js +201 -0
- package/examples/jsm/postprocessing/SSAARenderPass.js +228 -0
- package/examples/jsm/postprocessing/SSAOPass.js +440 -0
- package/examples/jsm/postprocessing/SSRPass.js +641 -0
- package/examples/jsm/postprocessing/SavePass.js +79 -0
- package/examples/jsm/postprocessing/ShaderPass.js +77 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +189 -0
- package/examples/jsm/postprocessing/TexturePass.js +67 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +215 -0
- package/examples/jsm/renderers/CSS3DRenderer.js +335 -0
- package/examples/jsm/renderers/Projector.js +918 -0
- package/examples/jsm/renderers/SVGRenderer.js +553 -0
- package/examples/jsm/renderers/common/Animation.js +58 -0
- package/examples/jsm/renderers/common/Attributes.js +75 -0
- package/examples/jsm/renderers/common/Backend.js +162 -0
- package/examples/jsm/renderers/common/Background.js +136 -0
- package/examples/jsm/renderers/common/Binding.js +19 -0
- package/examples/jsm/renderers/common/Bindings.js +165 -0
- package/examples/jsm/renderers/common/Buffer.js +38 -0
- package/examples/jsm/renderers/common/BufferUtils.js +33 -0
- package/examples/jsm/renderers/common/ChainMap.js +89 -0
- package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
- package/examples/jsm/renderers/common/Constants.js +14 -0
- package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
- package/examples/jsm/renderers/common/DataMap.js +54 -0
- package/examples/jsm/renderers/common/Geometries.js +215 -0
- package/examples/jsm/renderers/common/Info.js +73 -0
- package/examples/jsm/renderers/common/Pipeline.js +13 -0
- package/examples/jsm/renderers/common/Pipelines.js +370 -0
- package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
- package/examples/jsm/renderers/common/RenderContext.js +38 -0
- package/examples/jsm/renderers/common/RenderContexts.js +49 -0
- package/examples/jsm/renderers/common/RenderList.js +178 -0
- package/examples/jsm/renderers/common/RenderLists.js +38 -0
- package/examples/jsm/renderers/common/RenderObject.js +129 -0
- package/examples/jsm/renderers/common/RenderObjects.js +95 -0
- package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
- package/examples/jsm/renderers/common/Renderer.js +895 -0
- package/examples/jsm/renderers/common/SampledTexture.js +80 -0
- package/examples/jsm/renderers/common/Sampler.js +18 -0
- package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +218 -0
- package/examples/jsm/renderers/common/Uniform.js +140 -0
- package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
- package/examples/jsm/renderers/common/UniformsGroup.js +299 -0
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +39 -0
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +21 -0
- package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +330 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
- package/examples/jsm/renderers/webgl/nodes/SlotNode.js +26 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +764 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +49 -0
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +844 -0
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +32 -0
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +902 -0
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -0
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +274 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +223 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +533 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +163 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +964 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +92 -0
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +87 -0
- package/examples/jsm/shaders/AfterimageShader.js +56 -0
- package/examples/jsm/shaders/BasicShader.js +27 -0
- package/examples/jsm/shaders/BleachBypassShader.js +62 -0
- package/examples/jsm/shaders/BlendShader.js +47 -0
- package/examples/jsm/shaders/BokehShader.js +143 -0
- package/examples/jsm/shaders/BokehShader2.js +393 -0
- package/examples/jsm/shaders/BrightnessContrastShader.js +54 -0
- package/examples/jsm/shaders/ColorCorrectionShader.js +50 -0
- package/examples/jsm/shaders/ColorifyShader.js +51 -0
- package/examples/jsm/shaders/ConvolutionShader.js +103 -0
- package/examples/jsm/shaders/CopyShader.js +45 -0
- package/examples/jsm/shaders/DOFMipMapShader.js +54 -0
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +166 -0
- package/examples/jsm/shaders/DigitalGlitch.js +101 -0
- package/examples/jsm/shaders/DotScreenShader.js +70 -0
- package/examples/jsm/shaders/ExposureShader.js +44 -0
- package/examples/jsm/shaders/FXAAShader.js +286 -0
- package/examples/jsm/shaders/FilmShader.js +102 -0
- package/examples/jsm/shaders/FocusShader.js +87 -0
- package/examples/jsm/shaders/FreiChenShader.js +94 -0
- package/examples/jsm/shaders/GammaCorrectionShader.js +43 -0
- package/examples/jsm/shaders/GodRaysShader.js +313 -0
- package/examples/jsm/shaders/HalftoneShader.js +310 -0
- package/examples/jsm/shaders/HorizontalBlurShader.js +59 -0
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +61 -0
- package/examples/jsm/shaders/HueSaturationShader.js +65 -0
- package/examples/jsm/shaders/KaleidoShader.js +56 -0
- package/examples/jsm/shaders/LuminosityHighPassShader.js +64 -0
- package/examples/jsm/shaders/LuminosityShader.js +46 -0
- package/examples/jsm/shaders/MMDToonShader.js +132 -0
- package/examples/jsm/shaders/MirrorShader.js +54 -0
- package/examples/jsm/shaders/NormalMapShader.js +53 -0
- package/examples/jsm/shaders/OutputShader.js +78 -0
- package/examples/jsm/shaders/RGBShiftShader.js +54 -0
- package/examples/jsm/shaders/SAOShader.js +188 -0
- package/examples/jsm/shaders/SMAAShader.js +460 -0
- package/examples/jsm/shaders/SSAOShader.js +288 -0
- package/examples/jsm/shaders/SSRShader.js +364 -0
- package/examples/jsm/shaders/SepiaShader.js +52 -0
- package/examples/jsm/shaders/SobelOperatorShader.js +90 -0
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +88 -0
- package/examples/jsm/shaders/TechnicolorShader.js +43 -0
- package/examples/jsm/shaders/ToonShader.js +326 -0
- package/examples/jsm/shaders/TriangleBlurShader.js +72 -0
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +45 -0
- package/examples/jsm/shaders/VelocityShader.js +128 -0
- package/examples/jsm/shaders/VerticalBlurShader.js +59 -0
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +61 -0
- package/examples/jsm/shaders/VignetteShader.js +51 -0
- package/examples/jsm/shaders/VolumeShader.js +289 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +93 -0
- package/examples/jsm/textures/FlakesTexture.js +40 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +1373 -0
- package/examples/jsm/utils/CameraUtils.js +73 -0
- package/examples/jsm/utils/GPUStatsPanel.js +128 -0
- package/examples/jsm/utils/GeometryCompressionUtils.js +639 -0
- package/examples/jsm/utils/GeometryUtils.js +221 -0
- package/examples/jsm/utils/LDrawUtils.js +202 -0
- package/examples/jsm/utils/PackedPhongMaterial.js +178 -0
- package/examples/jsm/utils/SceneUtils.js +254 -0
- package/examples/jsm/utils/ShadowMapViewer.js +210 -0
- package/examples/jsm/utils/SkeletonUtils.js +413 -0
- package/examples/jsm/utils/TextureUtils.js +86 -0
- package/examples/jsm/utils/UVsDebug.js +165 -0
- package/examples/jsm/utils/WorkerPool.js +102 -0
- package/examples/jsm/webxr/ARButton.js +208 -0
- package/examples/jsm/webxr/OculusHandModel.js +109 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +413 -0
- package/examples/jsm/webxr/Text2D.js +38 -0
- package/examples/jsm/webxr/VRButton.js +200 -0
- package/examples/jsm/webxr/XRButton.js +198 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +299 -0
- package/examples/jsm/webxr/XREstimatedLight.js +223 -0
- package/examples/jsm/webxr/XRHandMeshModel.js +112 -0
- package/examples/jsm/webxr/XRHandModelFactory.js +105 -0
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +103 -0
- package/examples/jsm/webxr/XRPlanes.js +100 -0
- package/lib/3d.min.js +1 -0
- package/package.json +25 -12
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension, GPUFeatureName
|
|
3
|
+
} from './WebGPUConstants.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
CubeTexture, Texture,
|
|
7
|
+
NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter,
|
|
8
|
+
RepeatWrapping, MirroredRepeatWrapping,
|
|
9
|
+
RGB_ETC2_Format, RGBA_ETC2_EAC_Format,
|
|
10
|
+
RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthStencilFormat,
|
|
11
|
+
RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format,
|
|
12
|
+
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type,
|
|
13
|
+
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare
|
|
14
|
+
} from 'three';
|
|
15
|
+
|
|
16
|
+
import { CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from 'three';
|
|
17
|
+
|
|
18
|
+
import WebGPUTextureMipmapUtils from './WebGPUTextureMipmapUtils.js';
|
|
19
|
+
|
|
20
|
+
const _compareToWebGPU = {
|
|
21
|
+
[ NeverCompare ]: 'never',
|
|
22
|
+
[ LessCompare ]: 'less',
|
|
23
|
+
[ EqualCompare ]: 'equal',
|
|
24
|
+
[ LessEqualCompare ]: 'less-equal',
|
|
25
|
+
[ GreaterCompare ]: 'greater',
|
|
26
|
+
[ GreaterEqualCompare ]: 'greater-equal',
|
|
27
|
+
[ AlwaysCompare ]: 'always',
|
|
28
|
+
[ NotEqualCompare ]: 'not-equal'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class WebGPUTextureUtils {
|
|
32
|
+
|
|
33
|
+
constructor( backend ) {
|
|
34
|
+
|
|
35
|
+
this.backend = backend;
|
|
36
|
+
|
|
37
|
+
this.mipmapUtils = null;
|
|
38
|
+
|
|
39
|
+
this.defaultTexture = null;
|
|
40
|
+
this.defaultCubeTexture = null;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
createSampler( texture ) {
|
|
45
|
+
|
|
46
|
+
const backend = this.backend;
|
|
47
|
+
const device = backend.device;
|
|
48
|
+
|
|
49
|
+
const textureGPU = backend.get( texture );
|
|
50
|
+
|
|
51
|
+
const samplerDescriptorGPU = {
|
|
52
|
+
addressModeU: this._convertAddressMode( texture.wrapS ),
|
|
53
|
+
addressModeV: this._convertAddressMode( texture.wrapT ),
|
|
54
|
+
addressModeW: this._convertAddressMode( texture.wrapR ),
|
|
55
|
+
magFilter: this._convertFilterMode( texture.magFilter ),
|
|
56
|
+
minFilter: this._convertFilterMode( texture.minFilter ),
|
|
57
|
+
mipmapFilter: this._convertFilterMode( texture.minFilter ),
|
|
58
|
+
maxAnisotropy: texture.anisotropy
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if ( texture.isDepthTexture && texture.compareFunction !== null ) {
|
|
62
|
+
|
|
63
|
+
samplerDescriptorGPU.compare = _compareToWebGPU[ texture.compareFunction ];
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
textureGPU.sampler = device.createSampler( samplerDescriptorGPU );
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
createDefaultTexture( texture ) {
|
|
72
|
+
|
|
73
|
+
let textureGPU;
|
|
74
|
+
|
|
75
|
+
if ( texture.isCubeTexture ) {
|
|
76
|
+
|
|
77
|
+
textureGPU = this._getDefaultCubeTextureGPU();
|
|
78
|
+
|
|
79
|
+
} else {
|
|
80
|
+
|
|
81
|
+
textureGPU = this._getDefaultTextureGPU();
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.backend.get( texture ).texture = textureGPU;
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
createTexture( texture, options = {} ) {
|
|
90
|
+
|
|
91
|
+
const backend = this.backend;
|
|
92
|
+
const textureData = backend.get( texture );
|
|
93
|
+
|
|
94
|
+
if ( textureData.initialized ) {
|
|
95
|
+
|
|
96
|
+
throw new Error( 'WebGPUTextureUtils: Texture already initialized.' );
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { width, height, depth } = this._getSize( texture );
|
|
101
|
+
|
|
102
|
+
const needsMipmaps = this._needsMipmaps( texture );
|
|
103
|
+
const dimension = this._getDimension( texture );
|
|
104
|
+
const mipLevelCount = this._getMipLevelCount( texture, width, height, needsMipmaps );
|
|
105
|
+
const format = texture.internalFormat || this._getFormat( texture );
|
|
106
|
+
|
|
107
|
+
const sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
|
|
108
|
+
const primarySampleCount = texture.isRenderTargetTexture ? 1 : sampleCount;
|
|
109
|
+
|
|
110
|
+
let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC;
|
|
111
|
+
|
|
112
|
+
if ( texture.isCompressedTexture !== true ) {
|
|
113
|
+
|
|
114
|
+
usage |= GPUTextureUsage.RENDER_ATTACHMENT;
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const textureDescriptorGPU = {
|
|
119
|
+
label: texture.name,
|
|
120
|
+
size: {
|
|
121
|
+
width: width,
|
|
122
|
+
height: height,
|
|
123
|
+
depthOrArrayLayers: depth,
|
|
124
|
+
},
|
|
125
|
+
mipLevelCount: mipLevelCount,
|
|
126
|
+
sampleCount: primarySampleCount,
|
|
127
|
+
dimension: dimension,
|
|
128
|
+
format: format,
|
|
129
|
+
usage: usage
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// texture creation
|
|
133
|
+
|
|
134
|
+
if ( texture.isVideoTexture ) {
|
|
135
|
+
|
|
136
|
+
const video = texture.source.data;
|
|
137
|
+
const videoFrame = new VideoFrame( video );
|
|
138
|
+
|
|
139
|
+
textureDescriptorGPU.size.width = videoFrame.displayWidth;
|
|
140
|
+
textureDescriptorGPU.size.height = videoFrame.displayHeight;
|
|
141
|
+
|
|
142
|
+
videoFrame.close();
|
|
143
|
+
|
|
144
|
+
textureData.externalTexture = video;
|
|
145
|
+
|
|
146
|
+
} else {
|
|
147
|
+
|
|
148
|
+
if ( format === undefined ) {
|
|
149
|
+
|
|
150
|
+
console.warn( 'WebGPURenderer: Texture format not supported.' );
|
|
151
|
+
|
|
152
|
+
return this.createDefaultTexture( texture );
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
textureData.texture = backend.device.createTexture( textureDescriptorGPU );
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if ( texture.isRenderTargetTexture && sampleCount > 1 ) {
|
|
161
|
+
|
|
162
|
+
const msaaTextureDescriptorGPU = Object.assign( {}, textureDescriptorGPU );
|
|
163
|
+
|
|
164
|
+
msaaTextureDescriptorGPU.label = msaaTextureDescriptorGPU.label + '-msaa';
|
|
165
|
+
msaaTextureDescriptorGPU.sampleCount = sampleCount;
|
|
166
|
+
|
|
167
|
+
textureData.msaaTexture = backend.device.createTexture( msaaTextureDescriptorGPU );
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
textureData.initialized = true;
|
|
172
|
+
|
|
173
|
+
textureData.needsMipmaps = needsMipmaps;
|
|
174
|
+
textureData.textureDescriptorGPU = textureDescriptorGPU;
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
destroyTexture( texture ) {
|
|
179
|
+
|
|
180
|
+
const backend = this.backend;
|
|
181
|
+
const textureData = backend.get( texture );
|
|
182
|
+
|
|
183
|
+
textureData.texture.destroy();
|
|
184
|
+
|
|
185
|
+
if ( textureData.msaaTexture !== undefined ) textureData.msaaTexture.destroy();
|
|
186
|
+
|
|
187
|
+
backend.delete( texture );
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
destroySampler( texture ) {
|
|
192
|
+
|
|
193
|
+
const backend = this.backend;
|
|
194
|
+
const textureData = backend.get( texture );
|
|
195
|
+
|
|
196
|
+
delete textureData.sampler;
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
generateMipmaps( texture ) {
|
|
201
|
+
|
|
202
|
+
const textureData = this.backend.get( texture );
|
|
203
|
+
|
|
204
|
+
if ( texture.isCubeTexture ) {
|
|
205
|
+
|
|
206
|
+
for ( let i = 0; i < 6; i ++ ) {
|
|
207
|
+
|
|
208
|
+
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i );
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
} else {
|
|
213
|
+
|
|
214
|
+
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU );
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
updateTexture( texture ) {
|
|
221
|
+
|
|
222
|
+
const textureData = this.backend.get( texture );
|
|
223
|
+
|
|
224
|
+
const { needsMipmaps, textureDescriptorGPU } = textureData;
|
|
225
|
+
|
|
226
|
+
if ( textureDescriptorGPU === undefined ) // unsupported texture format
|
|
227
|
+
return;
|
|
228
|
+
|
|
229
|
+
// transfer texture data
|
|
230
|
+
|
|
231
|
+
if ( texture.isDataTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
|
|
232
|
+
|
|
233
|
+
this._copyBufferToTexture( texture.image, textureData.texture, textureDescriptorGPU, needsMipmaps );
|
|
234
|
+
|
|
235
|
+
} else if ( texture.isCompressedTexture ) {
|
|
236
|
+
|
|
237
|
+
this._copyCompressedBufferToTexture( texture.mipmaps, textureData.texture, textureDescriptorGPU );
|
|
238
|
+
|
|
239
|
+
} else if ( texture.isCubeTexture ) {
|
|
240
|
+
|
|
241
|
+
if ( texture.image.length === 6 ) {
|
|
242
|
+
|
|
243
|
+
this._copyCubeMapToTexture( texture.image, texture, textureData.texture, textureDescriptorGPU, needsMipmaps );
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
} else if ( texture.isRenderTargetTexture ) {
|
|
248
|
+
|
|
249
|
+
if ( needsMipmaps === true ) this._generateMipmaps( textureData.texture, textureDescriptorGPU );
|
|
250
|
+
|
|
251
|
+
} else if ( texture.isVideoTexture ) {
|
|
252
|
+
|
|
253
|
+
const video = texture.source.data;
|
|
254
|
+
|
|
255
|
+
textureData.externalTexture = video;
|
|
256
|
+
|
|
257
|
+
} else if ( texture.image !== null ) {
|
|
258
|
+
|
|
259
|
+
this._copyImageToTexture( texture.image, texture, textureData.texture, textureDescriptorGPU, needsMipmaps );
|
|
260
|
+
|
|
261
|
+
} else {
|
|
262
|
+
|
|
263
|
+
console.warn( 'WebGPUTextureUtils: Unable to update texture.' );
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//
|
|
268
|
+
|
|
269
|
+
textureData.version = texture.version;
|
|
270
|
+
|
|
271
|
+
if ( texture.onUpdate ) texture.onUpdate( texture );
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async copyTextureToBuffer( texture, x, y, width, height ) {
|
|
276
|
+
|
|
277
|
+
const device = this.backend.device;
|
|
278
|
+
|
|
279
|
+
const textureData = this.backend.get( texture );
|
|
280
|
+
const textureGPU = textureData.texture;
|
|
281
|
+
const format = textureData.textureDescriptorGPU.format;
|
|
282
|
+
const bytesPerTexel = this._getBytesPerTexel( format );
|
|
283
|
+
|
|
284
|
+
const readBuffer = device.createBuffer(
|
|
285
|
+
{
|
|
286
|
+
size: width * height * bytesPerTexel,
|
|
287
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const encoder = device.createCommandEncoder();
|
|
292
|
+
|
|
293
|
+
encoder.copyTextureToBuffer(
|
|
294
|
+
{
|
|
295
|
+
texture: textureGPU,
|
|
296
|
+
origin: { x, y },
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
buffer: readBuffer,
|
|
300
|
+
bytesPerRow: width * bytesPerTexel
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
width: width,
|
|
304
|
+
height: height
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const typedArrayType = this._getTypedArrayType( format );
|
|
310
|
+
|
|
311
|
+
device.queue.submit( [ encoder.finish() ] );
|
|
312
|
+
|
|
313
|
+
await readBuffer.mapAsync( GPUMapMode.READ );
|
|
314
|
+
|
|
315
|
+
const buffer = readBuffer.getMappedRange();
|
|
316
|
+
|
|
317
|
+
return new typedArrayType( buffer );
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
_isEnvironmentTexture( texture ) {
|
|
322
|
+
|
|
323
|
+
const mapping = texture.mapping;
|
|
324
|
+
|
|
325
|
+
return ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) || ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
|
|
326
|
+
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
_getDefaultTextureGPU() {
|
|
330
|
+
|
|
331
|
+
let defaultTexture = this.defaultTexture;
|
|
332
|
+
|
|
333
|
+
if ( defaultTexture === null ) {
|
|
334
|
+
|
|
335
|
+
const texture = new Texture();
|
|
336
|
+
texture.minFilter = NearestFilter;
|
|
337
|
+
texture.magFilter = NearestFilter;
|
|
338
|
+
|
|
339
|
+
this.createTexture( texture );
|
|
340
|
+
|
|
341
|
+
this.defaultTexture = defaultTexture = texture;
|
|
342
|
+
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return this.backend.get( defaultTexture ).texture;
|
|
346
|
+
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
_getDefaultCubeTextureGPU() {
|
|
350
|
+
|
|
351
|
+
let defaultCubeTexture = this.defaultTexture;
|
|
352
|
+
|
|
353
|
+
if ( defaultCubeTexture === null ) {
|
|
354
|
+
|
|
355
|
+
const texture = new CubeTexture();
|
|
356
|
+
texture.minFilter = NearestFilter;
|
|
357
|
+
texture.magFilter = NearestFilter;
|
|
358
|
+
|
|
359
|
+
this.createTexture( texture );
|
|
360
|
+
|
|
361
|
+
this.defaultCubeTexture = defaultCubeTexture = texture;
|
|
362
|
+
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return this.backend.get( defaultCubeTexture ).texture;
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
_copyImageToTexture( image, texture, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth ) {
|
|
370
|
+
|
|
371
|
+
if ( this._isHTMLImage( image ) ) {
|
|
372
|
+
|
|
373
|
+
this._getImageBitmapFromHTML( image, texture ).then( imageBitmap => {
|
|
374
|
+
|
|
375
|
+
this._copyExternalImageToTexture( imageBitmap, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth );
|
|
376
|
+
|
|
377
|
+
} );
|
|
378
|
+
|
|
379
|
+
} else {
|
|
380
|
+
|
|
381
|
+
// assume ImageBitmap
|
|
382
|
+
|
|
383
|
+
this._copyExternalImageToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth );
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
_isHTMLImage( image ) {
|
|
390
|
+
|
|
391
|
+
return ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement );
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
_copyCubeMapToTexture( images, texture, textureGPU, textureDescriptorGPU, needsMipmaps ) {
|
|
396
|
+
|
|
397
|
+
for ( let i = 0; i < 6; i ++ ) {
|
|
398
|
+
|
|
399
|
+
const image = images[ i ];
|
|
400
|
+
|
|
401
|
+
if ( image.isDataTexture ) {
|
|
402
|
+
|
|
403
|
+
this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, needsMipmaps, i );
|
|
404
|
+
|
|
405
|
+
} else {
|
|
406
|
+
|
|
407
|
+
this._copyImageToTexture( image, texture, textureGPU, textureDescriptorGPU, needsMipmaps, i );
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
_copyExternalImageToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth = 0 ) {
|
|
416
|
+
|
|
417
|
+
const device = this.backend.device;
|
|
418
|
+
|
|
419
|
+
device.queue.copyExternalImageToTexture(
|
|
420
|
+
{
|
|
421
|
+
source: image
|
|
422
|
+
}, {
|
|
423
|
+
texture: textureGPU,
|
|
424
|
+
mipLevel: 0,
|
|
425
|
+
origin: { x: 0, y: 0, z: originDepth }
|
|
426
|
+
}, {
|
|
427
|
+
width: image.width,
|
|
428
|
+
height: image.height,
|
|
429
|
+
depthOrArrayLayers: 1
|
|
430
|
+
}
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
if ( needsMipmaps ) this._generateMipmaps( textureGPU, textureDescriptorGPU, originDepth );
|
|
434
|
+
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
_generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) {
|
|
438
|
+
|
|
439
|
+
if ( this.mipmapUtils === null ) {
|
|
440
|
+
|
|
441
|
+
this.mipmapUtils = new WebGPUTextureMipmapUtils( this.backend.device );
|
|
442
|
+
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
this.mipmapUtils.generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer );
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
_getImageBitmapFromHTML( image, texture ) {
|
|
450
|
+
|
|
451
|
+
const width = image.width;
|
|
452
|
+
const height = image.height;
|
|
453
|
+
|
|
454
|
+
const options = {};
|
|
455
|
+
|
|
456
|
+
options.imageOrientation = ( texture.flipY === true ) ? 'flipY' : 'none';
|
|
457
|
+
options.premultiplyAlpha = ( texture.premultiplyAlpha === true ) ? 'premultiply' : 'default';
|
|
458
|
+
|
|
459
|
+
return createImageBitmap( image, 0, 0, width, height, options );
|
|
460
|
+
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
_copyBufferToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth = 0 ) {
|
|
464
|
+
|
|
465
|
+
// @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
|
|
466
|
+
// @TODO: Consider to support valid buffer layouts with other formats like RGB
|
|
467
|
+
|
|
468
|
+
const device = this.backend.device;
|
|
469
|
+
|
|
470
|
+
const data = image.data;
|
|
471
|
+
|
|
472
|
+
const bytesPerTexel = this._getBytesPerTexel( textureDescriptorGPU.format );
|
|
473
|
+
const bytesPerRow = image.width * bytesPerTexel;
|
|
474
|
+
|
|
475
|
+
device.queue.writeTexture(
|
|
476
|
+
{
|
|
477
|
+
texture: textureGPU,
|
|
478
|
+
mipLevel: 0,
|
|
479
|
+
origin: { x: 0, y: 0, z: originDepth }
|
|
480
|
+
},
|
|
481
|
+
data,
|
|
482
|
+
{
|
|
483
|
+
offset: 0,
|
|
484
|
+
bytesPerRow
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
width: image.width,
|
|
488
|
+
height: image.height,
|
|
489
|
+
depthOrArrayLayers: ( image.depth !== undefined ) ? image.depth : 1
|
|
490
|
+
} );
|
|
491
|
+
|
|
492
|
+
if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureDescriptorGPU, originDepth );
|
|
493
|
+
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
_copyCompressedBufferToTexture( mipmaps, textureGPU, textureDescriptorGPU ) {
|
|
497
|
+
|
|
498
|
+
// @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
|
|
499
|
+
|
|
500
|
+
const device = this.backend.device;
|
|
501
|
+
|
|
502
|
+
const blockData = this._getBlockData( textureDescriptorGPU.format );
|
|
503
|
+
|
|
504
|
+
for ( let i = 0; i < mipmaps.length; i ++ ) {
|
|
505
|
+
|
|
506
|
+
const mipmap = mipmaps[ i ];
|
|
507
|
+
|
|
508
|
+
const width = mipmap.width;
|
|
509
|
+
const height = mipmap.height;
|
|
510
|
+
|
|
511
|
+
const bytesPerRow = Math.ceil( width / blockData.width ) * blockData.byteLength;
|
|
512
|
+
|
|
513
|
+
device.queue.writeTexture(
|
|
514
|
+
{
|
|
515
|
+
texture: textureGPU,
|
|
516
|
+
mipLevel: i
|
|
517
|
+
},
|
|
518
|
+
mipmap.data,
|
|
519
|
+
{
|
|
520
|
+
offset: 0,
|
|
521
|
+
bytesPerRow
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
width: Math.ceil( width / blockData.width ) * blockData.width,
|
|
525
|
+
height: Math.ceil( height / blockData.width ) * blockData.width,
|
|
526
|
+
depthOrArrayLayers: 1
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
_getBlockData( format ) {
|
|
535
|
+
|
|
536
|
+
// this method is only relevant for compressed texture formats
|
|
537
|
+
|
|
538
|
+
if ( format === GPUTextureFormat.BC1RGBAUnorm || format === GPUTextureFormat.BC1RGBAUnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; // DXT1
|
|
539
|
+
if ( format === GPUTextureFormat.BC2RGBAUnorm || format === GPUTextureFormat.BC2RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // DXT3
|
|
540
|
+
if ( format === GPUTextureFormat.BC3RGBAUnorm || format === GPUTextureFormat.BC3RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // DXT5
|
|
541
|
+
if ( format === GPUTextureFormat.BC4RUnorm || format === GPUTextureFormat.BC4RSNorm ) return { byteLength: 8, width: 4, height: 4 }; // RGTC1
|
|
542
|
+
if ( format === GPUTextureFormat.BC5RGUnorm || format === GPUTextureFormat.BC5RGSnorm ) return { byteLength: 16, width: 4, height: 4 }; // RGTC2
|
|
543
|
+
if ( format === GPUTextureFormat.BC6HRGBUFloat || format === GPUTextureFormat.BC6HRGBFloat ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (float)
|
|
544
|
+
if ( format === GPUTextureFormat.BC7RGBAUnorm || format === GPUTextureFormat.BC7RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (unorm)
|
|
545
|
+
|
|
546
|
+
if ( format === GPUTextureFormat.ETC2RGB8Unorm || format === GPUTextureFormat.ETC2RGB8UnormSRGB ) return { byteLength: 8, width: 4, height: 4 };
|
|
547
|
+
if ( format === GPUTextureFormat.ETC2RGB8A1Unorm || format === GPUTextureFormat.ETC2RGB8A1UnormSRGB ) return { byteLength: 8, width: 4, height: 4 };
|
|
548
|
+
if ( format === GPUTextureFormat.ETC2RGBA8Unorm || format === GPUTextureFormat.ETC2RGBA8UnormSRGB ) return { byteLength: 16, width: 4, height: 4 };
|
|
549
|
+
if ( format === GPUTextureFormat.EACR11Unorm ) return { byteLength: 8, width: 4, height: 4 };
|
|
550
|
+
if ( format === GPUTextureFormat.EACR11Snorm ) return { byteLength: 8, width: 4, height: 4 };
|
|
551
|
+
if ( format === GPUTextureFormat.EACRG11Unorm ) return { byteLength: 16, width: 4, height: 4 };
|
|
552
|
+
if ( format === GPUTextureFormat.EACRG11Snorm ) return { byteLength: 16, width: 4, height: 4 };
|
|
553
|
+
|
|
554
|
+
if ( format === GPUTextureFormat.ASTC4x4Unorm || format === GPUTextureFormat.ASTC4x4UnormSRGB ) return { byteLength: 16, width: 4, height: 4 };
|
|
555
|
+
if ( format === GPUTextureFormat.ASTC5x4Unorm || format === GPUTextureFormat.ASTC5x4UnormSRGB ) return { byteLength: 16, width: 5, height: 4 };
|
|
556
|
+
if ( format === GPUTextureFormat.ASTC5x5Unorm || format === GPUTextureFormat.ASTC5x5UnormSRGB ) return { byteLength: 16, width: 5, height: 5 };
|
|
557
|
+
if ( format === GPUTextureFormat.ASTC6x5Unorm || format === GPUTextureFormat.ASTC6x5UnormSRGB ) return { byteLength: 16, width: 6, height: 5 };
|
|
558
|
+
if ( format === GPUTextureFormat.ASTC6x6Unorm || format === GPUTextureFormat.ASTC6x6UnormSRGB ) return { byteLength: 16, width: 6, height: 6 };
|
|
559
|
+
if ( format === GPUTextureFormat.ASTC8x5Unorm || format === GPUTextureFormat.ASTC8x5UnormSRGB ) return { byteLength: 16, width: 8, height: 5 };
|
|
560
|
+
if ( format === GPUTextureFormat.ASTC8x6Unorm || format === GPUTextureFormat.ASTC8x6UnormSRGB ) return { byteLength: 16, width: 8, height: 6 };
|
|
561
|
+
if ( format === GPUTextureFormat.ASTC8x8Unorm || format === GPUTextureFormat.ASTC8x8UnormSRGB ) return { byteLength: 16, width: 8, height: 8 };
|
|
562
|
+
if ( format === GPUTextureFormat.ASTC10x5Unorm || format === GPUTextureFormat.ASTC10x5UnormSRGB ) return { byteLength: 16, width: 10, height: 5 };
|
|
563
|
+
if ( format === GPUTextureFormat.ASTC10x6Unorm || format === GPUTextureFormat.ASTC10x6UnormSRGB ) return { byteLength: 16, width: 10, height: 6 };
|
|
564
|
+
if ( format === GPUTextureFormat.ASTC10x8Unorm || format === GPUTextureFormat.ASTC10x8UnormSRGB ) return { byteLength: 16, width: 10, height: 8 };
|
|
565
|
+
if ( format === GPUTextureFormat.ASTC10x10Unorm || format === GPUTextureFormat.ASTC10x10UnormSRGB ) return { byteLength: 16, width: 10, height: 10 };
|
|
566
|
+
if ( format === GPUTextureFormat.ASTC12x10Unorm || format === GPUTextureFormat.ASTC12x10UnormSRGB ) return { byteLength: 16, width: 12, height: 10 };
|
|
567
|
+
if ( format === GPUTextureFormat.ASTC12x12Unorm || format === GPUTextureFormat.ASTC12x12UnormSRGB ) return { byteLength: 16, width: 12, height: 12 };
|
|
568
|
+
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
_convertAddressMode( value ) {
|
|
572
|
+
|
|
573
|
+
let addressMode = GPUAddressMode.ClampToEdge;
|
|
574
|
+
|
|
575
|
+
if ( value === RepeatWrapping ) {
|
|
576
|
+
|
|
577
|
+
addressMode = GPUAddressMode.Repeat;
|
|
578
|
+
|
|
579
|
+
} else if ( value === MirroredRepeatWrapping ) {
|
|
580
|
+
|
|
581
|
+
addressMode = GPUAddressMode.MirrorRepeat;
|
|
582
|
+
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return addressMode;
|
|
586
|
+
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
_convertFilterMode( value ) {
|
|
590
|
+
|
|
591
|
+
let filterMode = GPUFilterMode.Linear;
|
|
592
|
+
|
|
593
|
+
if ( value === NearestFilter || value === NearestMipmapNearestFilter || value === NearestMipmapLinearFilter ) {
|
|
594
|
+
|
|
595
|
+
filterMode = GPUFilterMode.Nearest;
|
|
596
|
+
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return filterMode;
|
|
600
|
+
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
_getSize( texture ) {
|
|
604
|
+
|
|
605
|
+
const image = texture.image;
|
|
606
|
+
|
|
607
|
+
let width, height, depth;
|
|
608
|
+
|
|
609
|
+
if ( texture.isCubeTexture ) {
|
|
610
|
+
|
|
611
|
+
const faceImage = image.length > 0 ? image[ 0 ].image || image[ 0 ] : null;
|
|
612
|
+
|
|
613
|
+
width = faceImage ? faceImage.width : 1;
|
|
614
|
+
height = faceImage ? faceImage.height : 1;
|
|
615
|
+
depth = 6; // one image for each side of the cube map
|
|
616
|
+
|
|
617
|
+
} else if ( image !== null ) {
|
|
618
|
+
|
|
619
|
+
width = image.width;
|
|
620
|
+
height = image.height;
|
|
621
|
+
depth = ( image.depth !== undefined ) ? image.depth : 1;
|
|
622
|
+
|
|
623
|
+
} else {
|
|
624
|
+
|
|
625
|
+
width = height = depth = 1;
|
|
626
|
+
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return { width, height, depth };
|
|
630
|
+
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
_needsMipmaps( texture ) {
|
|
634
|
+
|
|
635
|
+
if ( this._isEnvironmentTexture( texture ) ) return true;
|
|
636
|
+
|
|
637
|
+
return ( texture.isCompressedTexture !== true ) /*&& ( texture.generateMipmaps === true )*/ && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
|
|
638
|
+
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
_getBytesPerTexel( format ) {
|
|
642
|
+
|
|
643
|
+
if ( format === GPUTextureFormat.R8Unorm ) return 1;
|
|
644
|
+
if ( format === GPUTextureFormat.R16Float ) return 2;
|
|
645
|
+
if ( format === GPUTextureFormat.RG8Unorm ) return 2;
|
|
646
|
+
if ( format === GPUTextureFormat.RG16Float ) return 4;
|
|
647
|
+
if ( format === GPUTextureFormat.R32Float ) return 4;
|
|
648
|
+
if ( format === GPUTextureFormat.RGBA8Unorm || format === GPUTextureFormat.RGBA8UnormSRGB ) return 4;
|
|
649
|
+
if ( format === GPUTextureFormat.RG32Float ) return 8;
|
|
650
|
+
if ( format === GPUTextureFormat.RGBA16Float ) return 8;
|
|
651
|
+
if ( format === GPUTextureFormat.RGBA32Float ) return 16;
|
|
652
|
+
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
_getTypedArrayType( format ) {
|
|
656
|
+
|
|
657
|
+
if ( format === GPUTextureFormat.R8Uint ) return Uint8Array;
|
|
658
|
+
if ( format === GPUTextureFormat.R8Sint ) return Int8Array;
|
|
659
|
+
if ( format === GPUTextureFormat.R8Unorm ) return Uint8Array;
|
|
660
|
+
if ( format === GPUTextureFormat.R8Snorm ) return Int8Array;
|
|
661
|
+
if ( format === GPUTextureFormat.RG8Uint ) return Uint8Array;
|
|
662
|
+
if ( format === GPUTextureFormat.RG8Sint ) return Int8Array;
|
|
663
|
+
if ( format === GPUTextureFormat.RG8Unorm ) return Uint8Array;
|
|
664
|
+
if ( format === GPUTextureFormat.RG8Snorm ) return Int8Array;
|
|
665
|
+
if ( format === GPUTextureFormat.RGBA8Uint ) return Uint8Array;
|
|
666
|
+
if ( format === GPUTextureFormat.RGBA8Sint ) return Int8Array;
|
|
667
|
+
if ( format === GPUTextureFormat.RGBA8Unorm ) return Uint8Array;
|
|
668
|
+
if ( format === GPUTextureFormat.RGBA8Snorm ) return Int8Array;
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
if ( format === GPUTextureFormat.R16Uint ) return Uint16Array;
|
|
672
|
+
if ( format === GPUTextureFormat.R16Sint ) return Int16Array;
|
|
673
|
+
if ( format === GPUTextureFormat.RG16Uint ) return Uint16Array;
|
|
674
|
+
if ( format === GPUTextureFormat.RG16Sint ) return Int16Array;
|
|
675
|
+
if ( format === GPUTextureFormat.RGBA16Uint ) return Uint16Array;
|
|
676
|
+
if ( format === GPUTextureFormat.RGBA16Sint ) return Int16Array;
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
if ( format === GPUTextureFormat.R32Uint ) return Uint32Array;
|
|
680
|
+
if ( format === GPUTextureFormat.R32Sint ) return Int32Array;
|
|
681
|
+
if ( format === GPUTextureFormat.R32Float ) return Float32Array;
|
|
682
|
+
if ( format === GPUTextureFormat.RG32Uint ) return Uint32Array;
|
|
683
|
+
if ( format === GPUTextureFormat.RG32Sint ) return Int32Array;
|
|
684
|
+
if ( format === GPUTextureFormat.RG32Float ) return Float32Array;
|
|
685
|
+
if ( format === GPUTextureFormat.RGBA32Uint ) return Uint32Array;
|
|
686
|
+
if ( format === GPUTextureFormat.RGBA32Sint ) return Int32Array;
|
|
687
|
+
if ( format === GPUTextureFormat.RGBA32Float ) return Float32Array;
|
|
688
|
+
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
_getDimension( texture ) {
|
|
692
|
+
|
|
693
|
+
let dimension;
|
|
694
|
+
|
|
695
|
+
if ( texture.isData3DTexture ) {
|
|
696
|
+
|
|
697
|
+
dimension = GPUTextureDimension.ThreeD;
|
|
698
|
+
|
|
699
|
+
} else {
|
|
700
|
+
|
|
701
|
+
dimension = GPUTextureDimension.TwoD;
|
|
702
|
+
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return dimension;
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
_getMipLevelCount( texture, width, height, needsMipmaps ) {
|
|
710
|
+
|
|
711
|
+
let mipLevelCount;
|
|
712
|
+
|
|
713
|
+
if ( texture.isCompressedTexture ) {
|
|
714
|
+
|
|
715
|
+
mipLevelCount = texture.mipmaps.length;
|
|
716
|
+
|
|
717
|
+
} else if ( needsMipmaps ) {
|
|
718
|
+
|
|
719
|
+
mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;
|
|
720
|
+
|
|
721
|
+
} else {
|
|
722
|
+
|
|
723
|
+
mipLevelCount = 1; // a texture without mipmaps has a base mip (mipLevel 0)
|
|
724
|
+
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
return mipLevelCount;
|
|
728
|
+
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
_getFormat( texture ) {
|
|
732
|
+
|
|
733
|
+
const format = texture.format;
|
|
734
|
+
const type = texture.type;
|
|
735
|
+
const colorSpace = texture.colorSpace;
|
|
736
|
+
|
|
737
|
+
let formatGPU;
|
|
738
|
+
|
|
739
|
+
if ( /*texture.isRenderTargetTexture === true ||*/ texture.isFramebufferTexture === true ) {
|
|
740
|
+
|
|
741
|
+
formatGPU = GPUTextureFormat.BGRA8Unorm;
|
|
742
|
+
|
|
743
|
+
} else if ( texture.isCompressedTexture === true ) {
|
|
744
|
+
|
|
745
|
+
switch ( format ) {
|
|
746
|
+
|
|
747
|
+
case RGBA_S3TC_DXT1_Format:
|
|
748
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
|
|
749
|
+
break;
|
|
750
|
+
|
|
751
|
+
case RGBA_S3TC_DXT3_Format:
|
|
752
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm;
|
|
753
|
+
break;
|
|
754
|
+
|
|
755
|
+
case RGBA_S3TC_DXT5_Format:
|
|
756
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
|
|
757
|
+
break;
|
|
758
|
+
|
|
759
|
+
case RGB_ETC2_Format:
|
|
760
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm;
|
|
761
|
+
break;
|
|
762
|
+
|
|
763
|
+
case RGBA_ETC2_EAC_Format:
|
|
764
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGBA8UnormSRGB : GPUTextureFormat.ETC2RGBA8Unorm;
|
|
765
|
+
break;
|
|
766
|
+
|
|
767
|
+
case RGBA_ASTC_4x4_Format:
|
|
768
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC4x4UnormSRGB : GPUTextureFormat.ASTC4x4Unorm;
|
|
769
|
+
break;
|
|
770
|
+
|
|
771
|
+
case RGBA_ASTC_5x4_Format:
|
|
772
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x4UnormSRGB : GPUTextureFormat.ASTC5x4Unorm;
|
|
773
|
+
break;
|
|
774
|
+
|
|
775
|
+
case RGBA_ASTC_5x5_Format:
|
|
776
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x5UnormSRGB : GPUTextureFormat.ASTC5x5Unorm;
|
|
777
|
+
break;
|
|
778
|
+
|
|
779
|
+
case RGBA_ASTC_6x5_Format:
|
|
780
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x5UnormSRGB : GPUTextureFormat.ASTC6x5Unorm;
|
|
781
|
+
break;
|
|
782
|
+
|
|
783
|
+
case RGBA_ASTC_6x6_Format:
|
|
784
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x6UnormSRGB : GPUTextureFormat.ASTC6x6Unorm;
|
|
785
|
+
break;
|
|
786
|
+
|
|
787
|
+
case RGBA_ASTC_8x5_Format:
|
|
788
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x5UnormSRGB : GPUTextureFormat.ASTC8x5Unorm;
|
|
789
|
+
break;
|
|
790
|
+
|
|
791
|
+
case RGBA_ASTC_8x6_Format:
|
|
792
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x6UnormSRGB : GPUTextureFormat.ASTC8x6Unorm;
|
|
793
|
+
break;
|
|
794
|
+
|
|
795
|
+
case RGBA_ASTC_8x8_Format:
|
|
796
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x8UnormSRGB : GPUTextureFormat.ASTC8x8Unorm;
|
|
797
|
+
break;
|
|
798
|
+
|
|
799
|
+
case RGBA_ASTC_10x5_Format:
|
|
800
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x5UnormSRGB : GPUTextureFormat.ASTC10x5Unorm;
|
|
801
|
+
break;
|
|
802
|
+
|
|
803
|
+
case RGBA_ASTC_10x6_Format:
|
|
804
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x6UnormSRGB : GPUTextureFormat.ASTC10x6Unorm;
|
|
805
|
+
break;
|
|
806
|
+
|
|
807
|
+
case RGBA_ASTC_10x8_Format:
|
|
808
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x8UnormSRGB : GPUTextureFormat.ASTC10x8Unorm;
|
|
809
|
+
break;
|
|
810
|
+
|
|
811
|
+
case RGBA_ASTC_10x10_Format:
|
|
812
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x10UnormSRGB : GPUTextureFormat.ASTC10x10Unorm;
|
|
813
|
+
break;
|
|
814
|
+
|
|
815
|
+
case RGBA_ASTC_12x10_Format:
|
|
816
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x10UnormSRGB : GPUTextureFormat.ASTC12x10Unorm;
|
|
817
|
+
break;
|
|
818
|
+
|
|
819
|
+
case RGBA_ASTC_12x12_Format:
|
|
820
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x12UnormSRGB : GPUTextureFormat.ASTC12x12Unorm;
|
|
821
|
+
break;
|
|
822
|
+
|
|
823
|
+
default:
|
|
824
|
+
console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
825
|
+
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
} else {
|
|
829
|
+
|
|
830
|
+
switch ( format ) {
|
|
831
|
+
|
|
832
|
+
case RGBAFormat:
|
|
833
|
+
|
|
834
|
+
switch ( type ) {
|
|
835
|
+
|
|
836
|
+
case UnsignedByteType:
|
|
837
|
+
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm;
|
|
838
|
+
break;
|
|
839
|
+
|
|
840
|
+
case HalfFloatType:
|
|
841
|
+
formatGPU = GPUTextureFormat.RGBA16Float;
|
|
842
|
+
break;
|
|
843
|
+
|
|
844
|
+
case FloatType:
|
|
845
|
+
formatGPU = GPUTextureFormat.RGBA32Float;
|
|
846
|
+
break;
|
|
847
|
+
|
|
848
|
+
default:
|
|
849
|
+
console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type );
|
|
850
|
+
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
break;
|
|
854
|
+
|
|
855
|
+
case RedFormat:
|
|
856
|
+
|
|
857
|
+
switch ( type ) {
|
|
858
|
+
|
|
859
|
+
case UnsignedByteType:
|
|
860
|
+
formatGPU = GPUTextureFormat.R8Unorm;
|
|
861
|
+
break;
|
|
862
|
+
|
|
863
|
+
case HalfFloatType:
|
|
864
|
+
formatGPU = GPUTextureFormat.R16Float;
|
|
865
|
+
break;
|
|
866
|
+
|
|
867
|
+
case FloatType:
|
|
868
|
+
formatGPU = GPUTextureFormat.R32Float;
|
|
869
|
+
break;
|
|
870
|
+
|
|
871
|
+
default:
|
|
872
|
+
console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type );
|
|
873
|
+
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
break;
|
|
877
|
+
|
|
878
|
+
case RGFormat:
|
|
879
|
+
|
|
880
|
+
switch ( type ) {
|
|
881
|
+
|
|
882
|
+
case UnsignedByteType:
|
|
883
|
+
formatGPU = GPUTextureFormat.RG8Unorm;
|
|
884
|
+
break;
|
|
885
|
+
|
|
886
|
+
case HalfFloatType:
|
|
887
|
+
formatGPU = GPUTextureFormat.RG16Float;
|
|
888
|
+
break;
|
|
889
|
+
|
|
890
|
+
case FloatType:
|
|
891
|
+
formatGPU = GPUTextureFormat.RG32Float;
|
|
892
|
+
break;
|
|
893
|
+
|
|
894
|
+
default:
|
|
895
|
+
console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type );
|
|
896
|
+
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
break;
|
|
900
|
+
|
|
901
|
+
case DepthFormat:
|
|
902
|
+
|
|
903
|
+
switch ( type ) {
|
|
904
|
+
|
|
905
|
+
case UnsignedShortType:
|
|
906
|
+
formatGPU = GPUTextureFormat.Depth16Unorm;
|
|
907
|
+
break;
|
|
908
|
+
|
|
909
|
+
case UnsignedIntType:
|
|
910
|
+
formatGPU = GPUTextureFormat.Depth24Plus;
|
|
911
|
+
break;
|
|
912
|
+
|
|
913
|
+
case FloatType:
|
|
914
|
+
formatGPU = GPUTextureFormat.Depth32Float;
|
|
915
|
+
break;
|
|
916
|
+
|
|
917
|
+
default:
|
|
918
|
+
console.error( 'WebGPURenderer: Unsupported texture type with DepthFormat.', type );
|
|
919
|
+
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
break;
|
|
923
|
+
|
|
924
|
+
case DepthStencilFormat:
|
|
925
|
+
|
|
926
|
+
switch ( type ) {
|
|
927
|
+
|
|
928
|
+
case UnsignedInt248Type:
|
|
929
|
+
formatGPU = GPUTextureFormat.Depth24PlusStencil8;
|
|
930
|
+
break;
|
|
931
|
+
|
|
932
|
+
case FloatType:
|
|
933
|
+
|
|
934
|
+
if ( this.device.features.has( GPUFeatureName.Depth32FloatStencil8 ) === false ) {
|
|
935
|
+
|
|
936
|
+
console.error( 'WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.' );
|
|
937
|
+
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
formatGPU = GPUTextureFormat.Depth32FloatStencil8;
|
|
941
|
+
|
|
942
|
+
break;
|
|
943
|
+
|
|
944
|
+
default:
|
|
945
|
+
console.error( 'WebGPURenderer: Unsupported texture type with DepthStencilFormat.', type );
|
|
946
|
+
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
break;
|
|
950
|
+
|
|
951
|
+
default:
|
|
952
|
+
console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
953
|
+
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
return formatGPU;
|
|
959
|
+
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
export default WebGPUTextureUtils;
|