Skip to content

WML Three

The WML Three.js library provides a streamlined way to integrate Three.js into your Angular applications. It offers a set of classes and utilities that simplify the creation and management of 3D scenes, renderers, cameras, controls, lights, objects, and animations. This library is designed to help developers quickly set up interactive 3D graphics without dealing with the boilerplate code typically associated with Three.js.

Installation

Terminal window
npm install -s --verbose @windmillcode/wml-three @windmillcode/wml-components-base three

Roadmap

[ ] multiple renderer need to accurately choose the correct object from the mouse []

Caveats

  • must set in tsconfig.json compilerOptions
"noImplicitAny": false,
"skipLibCheck": true
  • also when you know a property exists on an object you must use @ts-ignore and debug the property to make sure until we can have more advanced typescript types, for our classes we provide getters for different types of the same property but for threejs objects thats harder if not impossible to do

Usage

Getting Started

Animating Elements

Adding An Inspector

Multiple Renderers

Different Light Types

Selecting Objects With Your Mouse

Loading Various Types of Models

References

WMLThreeProps

PropertyTypeDescription
renderersArray<any | Renderer>List of renderers used in the application, defaulting to a WebGLRenderer with antialiasing enabled. It is an array because effect composers are renderers
rendererParentElementHTMLElementThe DOM element to which the renderer’s canvas will be appended. Defaults to document.body.
scenesArray<Scene>Array of Three.js scenes. Defaults to a single new Scene.
camerasArray<Camera>List of cameras used in the scenes.
controlsArray<Controls<any>>Array of control mechanisms like OrbitControls for user interaction.
inspectorsArray<InspectorOptions>Configuration for GUI inspectors like DatGUI or LilGUI, including options for real-time parameter adjustments.
lightsArray<WMLThreeLightProps>List of light configurations, each containing a THREE.Light object and related properties like helpers and shadow helpers.
rayCastersArray<WMLThreeRayCasterProps>Raycaster configurations used for detecting user interactions with objects in the scene.
objectsArray<WMLThreeObjectProps>List of object configurations, including geometries, materials, meshes, and textures.
clockClockThree.js Clock object used for tracking time in animations.
animateFunctionsArray<Function>List of custom functions to be called on each frame of the animation loop. Each function receives an object containing the Clock as a parameter.

Methods

MethodReturn TypeDescription
init(props?)Promise<void>Initializes the Three.js environment with optional parameters to enable or disable specific initialization steps like cameras, controls, lights, objects, and animations.
preCheck()voidPerforms preliminary checks to ensure that the environment supports Three.js (e.g., checking for the presence of the document object).
animate()voidDefault animation loop function that calls all functions in animateFunctions and renders the current scene with the current camera.
addRendererToDOM()voidAppends the renderer’s canvas to the rendererParentElement and sets up initial renderer configurations like size, pixel ratio, and shadow map settings.
initCameras(props?)voidInitializes cameras with optional parameters like field of view angle, near and far clipping planes.
initControls()voidSets up user interaction controls, such as OrbitControls, associated with the current camera and renderer.
initLights()voidAdds lights to the scene based on the configurations in lights, including optional helpers and shadow helpers for debugging and visualization.
initObjects()Promise<void>Loads and adds objects to the scene, handling both regular meshes and loaded assets like textures and GLTF models.
initInspectors()voidInitializes GUI inspectors for real-time parameter adjustments during development.
initRayCasters()voidSets up raycasters for detecting user interactions with objects in the scene, including event listeners for pointer movements.
listenForWindowResize()voidAdds an event listener to handle window resizing, updating camera aspects and renderer sizes accordingly.
getRendererParentDetails(){ width: number; height: number; }Retrieves the dimensions of the rendererParentElement to configure renderer and camera settings.
getCurentScene()SceneReturns the current scene being used.
getCurentCamera()CameraReturns the current camera being used.
getCurrentRenderer()RendererReturns the current renderer being used.
getCurrentControls()Controls<any>Returns the current control mechanism being used.
getCurrentRayCaster()WMLThreeRayCasterPropsReturns the current raycaster configuration being used.

InspectorOptions

PropertyTypeDescription
guiDatGUI | LilGUIAn instance of the GUI inspector to be used for real-time adjustments of properties on three js objects.
values{ [key: string]: InspectorOption }Configuration options for the inspector, including values and change handlers.
options{ [key: string]: any }Internal state management for the inspector options.
InspectorOption
PropertyTypeDescription
valueanyThe initial value of the option to be controlled via the inspector.
onChange(value: any, init: boolean) => voidOptional function to be called when the value changes.
minnumberOptional minimum value for numerical controls.
maxnumberOptional maximum value for numerical controls.

WMLCommonThreeProps

PropertyTypeDescription
sceneSceneGetter and setter for the current scene.
cameraCameraGetter and setter for the current camera.
rendererWebGLRendererGetter and setter for the current renderer.
controlOrbitControlsGetter and setter for the current control mechanism, specifically OrbitControls.
MethodReturn TypeDescription
updateCameraPosition(props?)voidUpdates the camera’s position and optionally its orientation using lookAt. Also updates controls if applicable.

WMLThreeObjectProps

PropertyTypeDescription
geometriesArray<BufferGeometry>List of geometries to be used in creating meshes.
materialsArray<Material | Material[]>List of materials or arrays of materials for the meshes.
meshesArray<Object3D | GLTF>List of meshes or loaded models to be added to the scene.
texturesArray<WMLThreeTexturesProps>List of texture configurations to be loaded and applied to materials or meshes.

WMLCommonThreeObjectProps

PropertyTypeDescription
geometryBufferGeometryGetter and setter for the primary geometry.
materialMaterial | Material[]Getter and setter for the primary material(s).
meshObject3D | GLTFGetter and setter for the primary mesh or model.
textureWMLThreeTexturesPropsGetter and setter for the primary texture configuration.
MethodReturn TypeDescription
toggleShadow(props?)voidToggles the shadow casting and receiving properties of the mesh.

WMLThreeLightProps

PropertyTypeDescription
lightLightThe Three.js light object to be added to the scene.
addHelperbooleanFlag indicating whether to add a helper object for visualizing the light. The helper class is based on the class of the light property
helperObject3DThe helper object associated with the light, if any.
addShadowHelperbooleanFlag indicating whether to add a shadow camera helper for debugging shadows. its class is the CameraHelper
shadowHelperCameraHelperThe shadow camera helper associated with the light’s shadow camera, if any.
MethodReturn TypeDescription
toggleShadow(props?)voidToggles the shadow casting and receiving properties of the light.
updateCamera()voidUpdates the light’s shadow camera projection matrix and associated helpers.

WMLThreeTexturesProps

PropertyTypeDescription
managerLoadingManagerThe loading manager to manage multiple texture loading operations.
groupArray<TextureLoadOption>Array of texture load options, each containing URL, loader, and optional callbacks for load events.

TextureLoadOption

PropertyTypeDescription
urlstringThe URL of the texture to be loaded.
loaderLoaderThe loader instance to use for loading the texture.
onLoad(data: any) => voidOptional callback function to be called upon successful loading.
onProgress(event: ProgressEvent) => voidOptional callback for progress updates during loading.
onError(err: unknown) => voidOptional callback to handle errors during loading.

WMLThreeRayCasterProps

PropertyTypeDescription
raycasterRaycasterThe Three.js Raycaster instance used for detecting intersections.
mousePositionVector2The normalized mouse position used for raycasting calculations.
hasMouseEnteredRendererbooleanFlag to indicate whether the mouse has entered the renderer area, used to optimize raycasting checks.
NameSignatureDescription
intersectCallback(intersects: Intersection<Object3D<Object3DEventMap>>[]) => voidCallback function to handle the results of raycasting intersections.

Changelog

v18.2.4001 [9/18/24]

  • updated package to reflect the version 18.2.4 of @angular/core package

v18.2.4002 [9/19/24]

  • updated package to reflect the version 18.2.4 of @angular/core package

v18.2.4003 [9/19/24]

  • updated package to reflect the version 18.2.4 of @angular/core package

v18.2.4004 [9/19/24]

  • updated package to reflect the version 18.2.4 of @angular/core package

v18.2.4005 [9/19/24]

  • updated package to reflect the version 18.2.4 of @angular/core package

v18.2.4006 [9/19/24]

  • updated package to reflect the version 18.2.4 of @angular/core package

v18.2.4007 [9/19/24]

  • updated package to reflect the version 18.2.4 of @angular/core package