• Every entity in the three.js scenario will be processed by WebGLObjects
function WebGLObjects(gl, geometries, attributes, info) {
	let updateMap = new WeakMap(a);function update(object) {
		const frame = info.render.frame; // Get the count of frames (0 frames from the start of the program)

		const geometry = object.geometry;
		const buffergeometry = geometries.get(object, geometry); // Obtain the geometry of the object cached in geometries, which is basically the same thing as the passed parameter geometry

		// Update once per frame

		if(updateMap.get(buffergeometry) ! == frame) {// Check each frame to see if the data in geometry has changed, and update the VBO if it has changed. // If multiple meshs use the same geometry, update the vBO only once

			geometries.update(buffergeometry); //// update Update the VBO corresponding to geometry if the VBO is not created or the data in geometry has changed

			updateMap.set(buffergeometry, frame); / / synchronous frame
		}

		if (object.isInstancedMesh) {
			if (
				object.hasEventListener("dispose", onInstancedMeshDispose) === false
			) {
				object.addEventListener("dispose", onInstancedMeshDispose);
			}

			attributes.update(object.instanceMatrix, 34962);

			if(object.instanceColor ! = =null) {
				attributes.update(object.instanceColor, 34962); }}return buffergeometry;
	}

	function dispose() {
		updateMap = new WeakMap(a); }function onInstancedMeshDispose(event) {
		const instancedMesh = event.target;

		instancedMesh.removeEventListener("dispose", onInstancedMeshDispose);

		attributes.remove(instancedMesh.instanceMatrix);

		if(instancedMesh.instanceColor ! = =null)
			attributes.remove(instancedMesh.instanceColor);
	}

	return {
		update: update,
		dispose: dispose,
	};
}
Copy the code