@tolokoban/tgd
v2.4.0
Published
ToloGameDev library for WebGL2
Readme
tgd2
ToloGameDev library for WebGL2. Please look at the online documentation (in french).
Development
Open a terminal in the lib/ folder and type the following command
to build the library in the dist/ folder:
npm startOpen another terminal in the doc/ folder and type the following command
to launch a browser with the documentation:
npm startRelease notes
v2.4.0
- New TgdPainterBBox: Painter to visualize a bounding box with configurable wireframe stroke and semi-transparent filled faces. Accepts a
TgdBoundingBoxor{min, max}object, with customizablecolorStrokeandcolorFill. - TgdColor constructor expanded: Now accepts
ArrayNumber3 | TgdVec3in addition toArrayNumber4 | TgdVec4, making it easier to create colors from RGB triples. - TgdBoundingBox constructor expanded: Now accepts
TgdVec3 | TgdVec4in addition toArrayNumber3as constructor points. - TgdContext.takeSnapshot() fix: Now triggers a
paint()call to ensure a frame is rendered before capturing the snapshot.
v2.3.3
- TgdContext.takeSnapshot(): Added an argument to set the mime type quan quality of the generated image.
v2.3.1
- webglPresetDepth expanded: Added
greater,greaterOrEqual,greaterReadOnly, andgreaterOrEqualReadOnlypresets to the depth state utility.
v2.3.0
- TgdQuat.fromEuler(): New static factory method to create a quaternion from Euler angles (degrees around X, Y, Z axes).
v2.2.0
- TgdPainterLOD Quadtree mode: Added a
modeoption ("xyz"|"xz") toTgdPainterLODOptions. When set to"xz", the LOD uses a Quadtree instead of an Octree, subdividing only along the X and Z axes (Y axis is never split). Defaults to"xyz". - TgdPainterLOD mutable
surfaceThreshold:surfaceThresholdis now a public property that can be changed after construction.
v2.1.4
- TgdUniformBufferObjectCamera new uniforms: Added
uniScreenSize(vec2, width/height in pixels),uniScreenAspectRatio(float, width/height), anduniScreenAspectRatioInverse(float, height/width) to the camera UBO.
v2.1.3
- TgdPainterMesh.computeBoundingBox fix: Now correctly uses
geometry.attPositioninstead of the hardcoded"POSITION"attribute name, fixing bounding box computation for geometries with a custom position attribute name.
v2.1.2
TgdCamera.fitBoundingBoxnow takes aReadonly<TgdBoundingBox>as unique argument.
v2.1.0
- New util function
tgdTypeArrayForElements()that will create the smallest typed array for elements indices.
v2.0.147
- TgdMaterialFlatTexture provide a
textureattribute, but until now, changing it was not working.
v2.0.145
- TgdPainterPointsCloud and TgdPainterPointsCloudMorphing were using squares with back face facing.
v2.0.144
- TgdContext resolution deferred to paint cycle: Setting
context.resolutionno longer immediately resizes the canvas. Instead, the canvas dimensions are updated at the top of the nextactualPaintcall usingMath.ceil, avoiding mid-frame layout thrashing and ensuring consistent sizing.
v2.0.143
- TgdPainterOverlay resolution fix: Overlay coordinate transformations now correctly account for
context.resolution, fixing layout misalignment on high-DPI displays when a customwidth/heightis set.
v2.0.142
- TgdPainterSegments and TgdPainterSegmentsMorphing: fix a bug in the materials.
v2.0.141
- TgdPainterPointsCloud rewritten with instanced billboards: Points are now rendered using
TRIANGLE_FANinstanced quads instead ofgl_Point, removing the macOS 64pxgl_PointSizelimitation. NewenableSpecularoption, sharedfragCodeSphere/fragCodeFlatshader helpers extracted into dedicated modules with configurablelightDirectionanddepthPrecision. - TgdPainterPointsCloudMorphing uses instanced billboards: Morphing cloud also switched from
gl_Pointto instanced quads for macOS compatibility, using the same shared shader helpers. - TgdContext.pointSizeMin / pointSizeMax: New readonly properties exposing the hardware
ALIASED_POINT_SIZE_RANGE. - TgdContext.execBeforeNextPaint / execAfterNextPaint: Schedule one-shot actions to run before or after the next paint cycle.
- TgdCamera.fitBoundingBox(): New method to automatically position the camera (distance, near, far, orientation) to frame a
TgdBoundingBox. - TgdCamera.setCurrentState() returns
this: Enables fluent chaining. - TgdMaterial texture management: Materials now accept a
texturesrecord (Record<string, TgdTexture2D | TgdTextureCube>) that auto-generates sampler uniforms and activates textures during paint — no manualtexture.activate()needed. - TgdPainterGroup
activeoption: Groups can now be created withactive: falseto skip painting. - TgdPainterSegments
varRadiusHasBeenClamped: New varying that indicates when a segment radius was clamped to minimum size. - TgdCodeBloc accepts
false:falsevalues are now valid in code blocs (filtered out likenull), simplifying conditional shader code generation.
v2.0.140
- TgdPainterGizmo error handling: The async initialization now catches errors via
context.console.errorand guards against painting on a deleted context. - Console methods as arrow functions:
Consoleclass methods (log,info,debug,error,warn) are now arrow function properties, ensuring correctthisbinding when passed as callbacks (e.g..catch(context.console.error)).
v2.0.139
- Fix a bug in TgdContext related to
isDeleted.
v2.0.137
- TgdContext verbose defaults to
false: Theverboseoption now defaults tofalseinstead oftrue, reducing console noise in production. - TgdContext deletion safety:
actualPaintnow guards against painting after the context has been deleted;delete()cancels any pending animation frame. - TgdContext.isDeleted: New getter to check whether the context has been deleted.
- TgdPainter unique IDs: Painter IDs are now human-readable strings (
[#0],[#1], …) generated by the newnextId()utility; constructor accepts an optionalnameparameter; addednameUniqgetter for guaranteed-unique display names. - TgdPainterGroup name forwarding: Constructor now passes the
nameoption to the parentTgdPainterconstructor. - New utility
TgdValueWaitable<T>: Async-friendly value holder — callwaitUntilDefined()to get aPromise<T>that resolves as soon as the value is set. - New utility
nextId(): Centralized incremental ID generator exported fromutils/id.
v2.0.136
- New TgdGeometry.join(): Static method and standalone
tgdGeometryJoin()function to merge multiple geometries into a single one, combining positions, normals, UVs, and elements with proper index offsetting. - TgdGeometry.fitElementsInTypeArray(): New static helper that picks the smallest typed array (
Uint8Array,Uint16Array, orUint32Array) for a given elements array based on the maximum index value. - New isTgdTypeArrayForElements type guard: Runtime check for valid element typed arrays (
Uint8Array | Uint16Array | Uint32Array). - TgdDataset.get(): New method to extract all values of a given attribute into a plain
number[]array. - TgdTexture2D: Better texture format. Only the compatible triplet of internal format, format and type are available.
- TgdContext.extensions: Access to all the WebGL2 extensions that are available on this hardware.
v2.0.135
- New TgdPainterParticles: Fully implemented GPU particle system using Transform Feedback with ping-pong buffers, configurable draw mode (
POINTS,LINES,TRIANGLES), custom uniforms callback, and automatic attribute-to-varying mapping viaprefixAttribute/prefixVaryingoptions. - TgdShaderVertex improvements: Added
name,clone(),createShader()methods, andmainCodeHeadersfor injecting code before the main body. - TgdShaderFragment improvements: Added
nameandclone()methods. - TgdDataset.getTypeRecord(): New method returning the full attribute type record.
v2.0.134
- TgdMaterialGlass configurable opacity: Added
opacityMinandopacityMaxoptions toTgdMaterialGlassOptions, allowing control over glass transparency range from the constructor (defaults:0.1/0.2).
v2.0.133
- TgdMaterialFlatTexture mutable texture:
textureis now a read/write property (getter + setter) instead of areadonlyfield, allowing dynamic texture swapping at runtime.
v2.0.132
- New camera property: Added
spacePerPixelgetter onTgdCamera— returns the size in space units of a single screen pixel at the target (useful for scalebars). - TgdTexture2D improvements: Removed unnecessary
unbind()calls after parameter/mipmap operations; added safety checks for incompleteHTMLImageElementand zero-sizeHTMLCanvasElement. - tgdCanvasCreate Safari fix: Forces backing store allocation via
getContext("2d")to preventINVALID_OPERATIONerrors with textures on Safari.
v2.0.131
- TgdPainterNode refactored:
TgdPainterNodenow extendsTgdPainterGroupinstead ofTgdPainter, enabling richer group-based behavior.add()now acceptsTgdPainter,TgdPainterFunction, orTgdInterfaceTransformable(previously limited toTgdPainterNodeChild).logicis now a collection (add/exec pattern) instead of a single optional callback, allowing multiple logic functions per node.- Removed the
TgdPainterNodeChildtype alias in favor of standardTgdPaintertypes. - Added runtime validation with
isTgdInterfaceTransformablePaintertype guard and descriptive error messages on invalid children.
- TgdPainterGizmo resizable:
alignX,alignY,size, andmarginare now reactive setters; changing them after construction updates the gizmo immediately. - New type guard: Added
isTgdInterfaceTransformablePainter()ininterface/transformable.tsfor runtime checking of transformable painters. - New utility: Added
tgdCanvasToArrayBuffer()inutils/canvas.tsto convert a canvas to anArrayBuffer(supports PNG, JPEG, WebP). - TgdContext debug logging: Constructor and
delete()now emit debug messages viathis.console.debugfor easier tracing. - GLB mesh factory cleanup:
factory/mesh-glb.tsnow usesTgdPainterdirectly instead ofTgdPainterNodeChild/TgdInterfaceTransformablefor children and mesh painter types.
