Capítulo 795 de 859

Chapter 795: Global Constants Reference

Core Idea

Three.js exposes hundreds of named numeric/string constants on the THREE namespace (blending, texture formats, tone mapping, shadow types, animation modes, etc.). This chapter curates the ones you'll actually reach for; the full list (1000+ entries, many WebGPU/compressed-texture format edge cases) lives in the official docs' Global page.

Key Concepts

  • Side: FrontSide (default), BackSide, DoubleSide — which faces of a mesh get rendered.
  • Blending: NoBlending, NormalBlending (default), AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending.
  • ToneMapping: NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping.
  • ColorSpace: NoColorSpace, SRGBColorSpace, LinearSRGBColorSpace.
  • ShadowMapType: BasicShadowMap, PCFShadowMap (default), PCFSoftShadowMap, VSMShadowMap.
  • Wrapping: RepeatWrapping, ClampToEdgeWrapping (default), MirroredRepeatWrapping.
  • TextureFilter: NearestFilter, LinearFilter (default for mag), plus the four *MipmapNearest/LinearFilter combinations for minification.

Reference Tables

Rendering & materials

Constant groupValues
SideFrontSide, BackSide, DoubleSide
BlendingNoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending
Blend equationAddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation
Blend factorZeroFactor, OneFactor, SrcColorFactor, DstColorFactor, SrcAlphaFactor, DstAlphaFactor (+ OneMinus* variants)
Depth/Stencil funcNeverDepthAlwaysDepth, NeverStencilFuncAlwaysStencilFunc (standard comparison-function set)
Stencil opKeepStencilOp, ZeroStencilOp, ReplaceStencilOp, IncrementStencilOp, DecrementStencilOp, InvertStencilOp (+ Wrap variants)
Combine (env map)MultiplyOperation, MixOperation, AddOperation
Normal map spaceTangentSpaceNormalMap, ObjectSpaceNormalMap
Draw modeTrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode

Textures

Constant groupValues
MappingUVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, CubeUVReflectionMapping
WrappingRepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping
FilterNearestFilter, LinearFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter
Data typeUnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType (+ packed UnsignedShort4444/5551Type, UnsignedInt101111/248/5999Type)
Pixel formatRGBAFormat, RedFormat, RGFormat, DepthFormat, DepthStencilFormat (+ Integer variants)
Compressed formatsLarge family: RGB_S3TC_DXT1_Format, RGBA_ASTC_*_Format, RGB_ETC1/ETC2_Format, RGBA_BPTC_Format, RED_RGTC1_Format, etc. — pick per platform support, check renderer.capabilities.
Usage hintsStaticDrawUsage (default), DynamicDrawUsage, StreamDrawUsage (+ *ReadUsage, *CopyUsage)

Rendering pipeline

Constant groupValues
Tone mappingNoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping
Color spaceNoColorSpace, SRGBColorSpace, LinearSRGBColorSpace
Shadow mapBasicShadowMap, PCFShadowMap, PCFSoftShadowMap, VSMShadowMap
Depth packingBasicDepthPacking, RGBADepthPacking, RGBDepthPacking, RGDepthPacking
Coordinate systemWebGLCoordinateSystem, WebGPUCoordinateSystem

Animation

Constant groupValues
Loop modeLoopOnce, LoopRepeat, LoopPingPong
InterpolationInterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InterpolateBezier
Blend modeNormalAnimationBlendMode, AdditiveAnimationBlendMode
EndingZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding

Anti-patterns

  • Hardcoding raw numbers instead of the named constant: constant values aren't part of the public API contract — always reference THREE.AdditiveBlending etc., never the underlying number.
  • Assuming every compressed texture format is supported everywhere: check renderer.capabilities / extension support before relying on ASTC/ETC2/PVRTC/S3TC/BPTC formats.

Key Takeaways

  1. Constants are namespaced flat on THREE (e.g. THREE.AdditiveBlending), not nested per-category.
  2. Defaults worth remembering: FrontSide, NormalBlending, ClampToEdgeWrapping, LinearFilter, PCFShadowMap, StaticDrawUsage.
  3. Compressed texture formats are platform-dependent — always feature-detect, don't assume.
  4. ColorSpace/ToneMapping constants matter for correct HDR/color-managed rendering — mismatches are a common cause of washed-out or over-saturated scenes.

Connects To

  • Material: consumes Side/Blending/DepthPacking constants.
  • Texture: consumes Wrapping/Filter/DataType/PixelFormat constants.
  • WebGLRenderer / WebGPURenderer: consumes ToneMapping/ColorSpace/ShadowMap constants.
  • AnimationAction: consumes LoopMode/BlendMode constants.