Thin instance functions not on mesh

Hi,

I’m using thin instances, but when I build Babylon with tree shaking the necessary APIs are missing. E.g. mesh.thinInstanceSetBuffer etc.

Is this one if those things where I need to import some named component? If so, how does an end user find out which features need which imports?

This page may help, and notably the FAQ section:

Regarding thin instances, maybe you need to import Meshes/thinInstanceMesh.

maybe you need to import Meshes/thinInstanceMesh .

Thank you, that was it.

This page may help, and notably the FAQ section:

I don’t think anything in that page covers this.

Babylon would be easier to use if it handled cases like this by, for example, default Mesh#thinInstanceSetBuffer was a placeholder function that throws an error saying what component to import. I know that Babylon inherits its API from pre-module days and that complicates things, but compared to a few years ago it seems like Babylon nowadays has a lot of gotchas where an error crops up and the only way to solve it is to just know which documentation page has the solution.

The doc page covers it in the " The intellisense does not propose the method I normally use in the bundled version and an undefined error is raised at runtime?" section. However, it does not cover the thin instance case, a PR is always welcome to improve the docs!

I guess that should be possible but I’m not familiar enough on how it works under the hood to be sure. I can see some warnings are issued for modules like “InstancedMesh” or “PhysicsImpostor”, but each time the method that is raising the error is a static method and there aren’t any static method in the thin instance implementation…

1 Like

Good topic for @sebavan and @RaananW: Can we think of a smart way to log which module needs to be included. We are already doing it a bit for some classes so perhaps we simply need to do it as well for thinInstances?

We can not really as having the default placeholder would increase the bundle size and reduce our treeshaking abilities.

Here are side effect mappings for 5.0.0-alpha.15, maybe they can be of use:

{
  "_internalMultiPick": "@babylonjs/core/Culling/ray",
  "_resizeOrCreateMultiviewTexture": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "_setCubeMapTextureParams": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "createDefaultVRExperience": "@babylonjs/core/Helpers/sceneHelpers",
  "thinInstanceSetAttributeAt": "@babylonjs/core/Meshes/thinInstanceMesh",
  "getLensFlareSystemByID": "@babylonjs/core/LensFlares/lensFlareSystemSceneComponent",
  "setPointerOverSprite": "@babylonjs/core/Sprites/spriteSceneComponent",
  "_internalPickSprites": "@babylonjs/core/Sprites/spriteSceneComponent",
  "pick": "@babylonjs/core/Culling/ray",
  "getForwardRayToRef": "@babylonjs/core/Culling/ray",
  "updateRawTexture3D": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "edgesShareWithInstances": "@babylonjs/core/Meshes/instancedMesh",
  "beginOcclusionQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "addEffectLayer": "@babylonjs/core/Layers/effectLayerSceneComponent",
  "createTransformFeedback": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "thinInstanceRegisterAttribute": "@babylonjs/core/Meshes/thinInstanceMesh",
  "getPhysicsEngine": "@babylonjs/core/Physics/physicsEngineComponent",
  "bindAttachments": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "getLensFlareSystemByName": "@babylonjs/core/LensFlares/lensFlareSystemSceneComponent",
  "restoreSingleAttachment": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "enableSubSurfaceForPrePass": "@babylonjs/core/Rendering/subSurfaceSceneComponent",
  "createRawTexture": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "_processLateAnimationBindings": "@babylonjs/core/Animations/animatable",
  "addVRDeviceOrientation": "@babylonjs/core/Cameras/Inputs/arcRotateCameraVRDeviceOrientationInput",
  "_readTexturePixelsSync": "@babylonjs/core/Engines/Extensions/engine.readTexture",
  "createDefaultEnvironment": "@babylonjs/core/Helpers/sceneHelpers",
  "createUniformBuffer": "@babylonjs/core/Engines/Extensions/engine.uniformBuffer",
  "beginAnimation": "@babylonjs/core/Animations/animatable",
  "getHierarchyEmittedParticleSystems": "@babylonjs/core/Particles/particleSystemComponent",
  "thinInstanceSetBuffer": "@babylonjs/core/Meshes/thinInstanceMesh",
  "thinInstanceSetMatrixAt": "@babylonjs/core/Meshes/thinInstanceMesh",
  "_cascadeLoadFiles": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "isVRPresenting": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "_submitVRFrame": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "isPhysicsEnabled": "@babylonjs/core/Physics/physicsEngineComponent",
  "_getVRDisplaysAsync": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "_processLateAnimationBindingsForMatrices": "@babylonjs/core/Animations/animatable",
  "enableDepthRenderer": "@babylonjs/core/Rendering/depthRendererSceneComponent",
  "createEffectForParticles": "@babylonjs/core/Particles/particleSystemComponent",
  "_createMultiviewUbo": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "_partialLoadImg": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "_thinInstanceUpdateBufferSize": "@babylonjs/core/Meshes/thinInstanceMesh",
  "_onVRFullScreenTriggered": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "setPhysicsLinkWith": "@babylonjs/core/Physics/physicsEngineComponent",
  "_getGlAlgorithmType": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "createRawCubeTexture": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "multiPickSpriteWithRay": "@babylonjs/core/Sprites/spriteSceneComponent",
  "initWebVRAsync": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "_internalPickForMesh": "@babylonjs/core/Culling/ray",
  "updateMultipleRenderTargetTextureSampleCount": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "setCompressedTextureExclusions": "@babylonjs/core/Engines/Extensions/engine.textureSelector",
  "enablePhysics": "@babylonjs/core/Physics/physicsEngineComponent",
  "removeReflectionProbe": "@babylonjs/core/Probes/reflectionProbe",
  "createMultiviewRenderTargetTexture": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "createDefaultLight": "@babylonjs/core/Helpers/sceneHelpers",
  "isQueryResultAvailable": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "enableVR": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "getBoundingBoxRenderer": "@babylonjs/core/Rendering/boundingBoxRenderer",
  "pickWithBoundingInfo": "@babylonjs/core/Culling/ray",
  "beginDirectHierarchyAnimation": "@babylonjs/core/Animations/animatable",
  "bindMultiviewFramebuffer": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "_updateMultiviewUbo": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "createMultipleRenderTarget": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "setAlphaEquation": "@babylonjs/core/Engines/Extensions/engine.alpha",
  "_transformMatrixR": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "_partialLoadFile": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "disableGeometryBufferRenderer": "@babylonjs/core/Rendering/geometryBufferRendererSceneComponent",
  "_disposeThinInstanceSpecificData": "@babylonjs/core/Meshes/thinInstanceMesh",
  "addLensFlareSystem": "@babylonjs/core/LensFlares/lensFlareSystemSceneComponent",
  "getVRDevice": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "stopAllAnimations": "@babylonjs/core/Animations/animatable",
  "pickSprite": "@babylonjs/core/Sprites/spriteSceneComponent",
  "_processLateAnimationBindingsForQuaternions": "@babylonjs/core/Animations/animatable",
  "thinInstanceAdd": "@babylonjs/core/Meshes/thinInstanceMesh",
  "addReflectionProbe": "@babylonjs/core/Probes/reflectionProbe",
  "addVirtualJoystick": "@babylonjs/core/Cameras/Inputs/freeCameraVirtualJoystickInput",
  "getPointerOverSprite": "@babylonjs/core/Sprites/spriteSceneComponent",
  "_useMultiviewToSingleView": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "disableDepthRenderer": "@babylonjs/core/Rendering/depthRendererSceneComponent",
  "_animate": "@babylonjs/core/Animations/animatable",
  "createPickingRay": "@babylonjs/core/Culling/ray",
  "thinInstanceRefreshBoundingInfo": "@babylonjs/core/Meshes/thinInstanceMesh",
  "getAnimatableByTarget": "@babylonjs/core/Animations/animatable",
  "_createDepthStencilTexture": "@babylonjs/core/Engines/Extensions/engine.renderTarget",
  "createQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "getInputElement": "@babylonjs/core/Engines/Extensions/engine.views",
  "beginHierarchyAnimation": "@babylonjs/core/Animations/animatable",
  "removeLensFlareSystem": "@babylonjs/core/LensFlares/lensFlareSystemSceneComponent",
  "createPickingRayToRef": "@babylonjs/core/Culling/ray",
  "_getTimeQueryResult": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "multiPick": "@babylonjs/core/Culling/ray",
  "deleteCompoundImpostor": "@babylonjs/core/Physics/physicsEngineComponent",
  "addDeviceOrientation": "@babylonjs/core/Cameras/Inputs/freeCameraDeviceOrientationInput",
  "createDynamicTexture": "@babylonjs/core/Engines/Extensions/engine.dynamicTexture",
  "step": "@babylonjs/core/Physics/Plugins/cannonJSPlugin",
  "enablePrePassRenderer": "@babylonjs/core/Rendering/prePassRendererSceneComponent",
  "enableEdgesRendering": "@babylonjs/core/Rendering/edgesRenderer",
  "disableVR": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "getOutlineRenderer": "@babylonjs/core/Rendering/outlineRenderer",
  "beginTransformFeedback": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "setAlphaConstants": "@babylonjs/core/Engines/Extensions/engine.alpha",
  "bindTransformFeedback": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "getPhysicsImpostor": "@babylonjs/core/Physics/physicsEngineComponent",
  "disableEdgesRendering": "@babylonjs/core/Rendering/edgesRenderer",
  "beginDirectAnimation": "@babylonjs/core/Animations/animatable",
  "bindUniformBufferBase": "@babylonjs/core/Engines/Extensions/engine.uniformBuffer",
  "thinInstanceAddSelf": "@babylonjs/core/Meshes/thinInstanceMesh",
  "createDefaultXRExperienceAsync": "@babylonjs/core/Helpers/sceneHelpers",
  "getAllAnimatablesByTarget": "@babylonjs/core/Animations/animatable",
  "_createTimeQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "_multiviewTexture": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "createRenderTargetTexture": "@babylonjs/core/Engines/Extensions/engine.renderTarget",
  "registerInstancedBuffer": "@babylonjs/core/Meshes/instancedMesh",
  "disableSubSurfaceForPrePass": "@babylonjs/core/Rendering/subSurfaceSceneComponent",
  "_checkOcclusionQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "_requestVRFrame": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "_advancePhysicsEngineStep": "@babylonjs/core/Physics/physicsEngineComponent",
  "_thinInstanceInitializeUserStorage": "@babylonjs/core/Meshes/thinInstanceMesh",
  "getHighlightLayerByName": "@babylonjs/core/Layers/highlightLayer",
  "createDefaultSkybox": "@babylonjs/core/Helpers/sceneHelpers",
  "bindUniformBuffer": "@babylonjs/core/Engines/Extensions/engine.uniformBuffer",
  "copyAnimationRange": "@babylonjs/core/Animations/animatable",
  "endTransformFeedback": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "createDepthStencilTexture": "@babylonjs/core/Engines/Extensions/engine.renderTarget",
  "createOrUpdateSelectionOctree": "@babylonjs/core/Culling/Octrees/octreeSceneComponent",
  "createPrefilteredCubeTexture": "@babylonjs/core/Misc/dds",
  "restoreSingleAttachmentForRenderTarget": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "updateDynamicVertexBuffer": "@babylonjs/core/Engines/Extensions/engine.dynamicBuffer",
  "createDynamicUniformBuffer": "@babylonjs/core/Engines/Extensions/engine.uniformBuffer",
  "getGlowLayerByName": "@babylonjs/core/Layers/glowLayer",
  "_disposeInstanceSpecificData": "@babylonjs/core/Meshes/instancedMesh",
  "_createDepthStencilCubeTexture": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "isVRDevicePresent": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "_renderMultiviewToSingleView": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "getEmittedParticleSystems": "@babylonjs/core/Particles/particleSystemComponent",
  "_internalMultiPickSprites": "@babylonjs/core/Sprites/spriteSceneComponent",
  "updateVideoTexture": "@babylonjs/core/Engines/Extensions/engine.videoTexture",
  "getAlphaEquation": "@babylonjs/core/Engines/Extensions/engine.alpha",
  "_multiviewSceneUbo": "@babylonjs/core/Engines/Extensions/engine.multiview",
  "_registerTargetForLateAnimationBinding": "@babylonjs/core/Animations/animatable",
  "bindTransformFeedbackBuffer": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "createDefaultCameraOrLight": "@babylonjs/core/Helpers/sceneHelpers",
  "stopAnimation": "@babylonjs/core/Animations/animatable",
  "thinInstanceGetWorldMatrices": "@babylonjs/core/Meshes/thinInstanceMesh",
  "endOcclusionQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "_cascadeLoadImgs": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "createCubeTexture": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "getAlphaMode": "@babylonjs/core/Engines/Extensions/engine.alpha",
  "getForwardRay": "@babylonjs/core/Culling/ray",
  "unBindMultiColorAttachmentFramebuffer": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "multiPickWithRay": "@babylonjs/core/Culling/ray",
  "applyImpulse": "@babylonjs/core/Physics/physicsEngineComponent",
  "_getTimeQueryAvailability": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "createDefaultCamera": "@babylonjs/core/Helpers/sceneHelpers",
  "_processInstancedBuffers": "@babylonjs/core/Meshes/instancedMesh",
  "setTranformFeedbackVaryings": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "_deleteTimeQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "updateDynamicTexture": "@babylonjs/core/Engines/Extensions/engine.dynamicTexture",
  "deleteQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "removeEffectLayer": "@babylonjs/core/Layers/effectLayerSceneComponent",
  "_internalPick": "@babylonjs/core/Culling/ray",
  "setAlphaMode": "@babylonjs/core/Engines/Extensions/engine.alpha",
  "endTimeQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "createRawTexture2DArray": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "createOrUpdateSubmeshesOctree": "@babylonjs/core/Culling/Octrees/octreeSceneComponent",
  "unRegisterView": "@babylonjs/core/Engines/Extensions/engine.views",
  "thinInstancePartialBufferUpdate": "@babylonjs/core/Meshes/thinInstanceMesh",
  "createPickingRayInCameraSpaceToRef": "@babylonjs/core/Culling/ray",
  "addGamepad": "@babylonjs/core/Gamepads/gamepadSceneComponent",
  "updateUniformBuffer": "@babylonjs/core/Engines/Extensions/engine.uniformBuffer",
  "updateRawTexture2DArray": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "_connectVREvents": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "_invalidateInstanceVertexArrayObject": "@babylonjs/core/Meshes/instancedMesh",
  "createRenderTargetCubeTexture": "@babylonjs/core/Engines/Extensions/engine.renderTargetCube",
  "createPickingRayInCameraSpace": "@babylonjs/core/Culling/ray",
  "createCubeTextureBase": "@babylonjs/core/Engines/Extensions/engine.cubeTexture",
  "_readTexturePixels": "@babylonjs/core/Engines/Extensions/engine.readTexture",
  "disablePrePassRenderer": "@babylonjs/core/Rendering/prePassRendererSceneComponent",
  "createRawCubeTextureFromUrl": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "setTextureFormatToUse": "@babylonjs/core/Engines/Extensions/engine.textureSelector",
  "_prepareVRComponent": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "thinInstanceBufferUpdated": "@babylonjs/core/Meshes/thinInstanceMesh",
  "disablePhysicsEngine": "@babylonjs/core/Physics/physicsEngineComponent",
  "initWebVR": "@babylonjs/core/Engines/Extensions/engine.webVR",
  "createRawTexture3D": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "deleteTransformFeedback": "@babylonjs/core/Engines/Extensions/engine.transformFeedback",
  "_renderViews": "@babylonjs/core/Engines/Extensions/engine.views",
  "registerView": "@babylonjs/core/Engines/Extensions/engine.views",
  "enableGeometryBufferRenderer": "@babylonjs/core/Rendering/geometryBufferRendererSceneComponent",
  "pickWithRay": "@babylonjs/core/Culling/ray",
  "buildTextureLayout": "@babylonjs/core/Engines/Extensions/engine.multiRender",
  "bindUniformBlock": "@babylonjs/core/Engines/Extensions/engine.uniformBuffer",
  "pickSpriteWithRay": "@babylonjs/core/Sprites/spriteSceneComponent",
  "getQueryResult": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "multiPickSprite": "@babylonjs/core/Sprites/spriteSceneComponent",
  "startTimeQuery": "@babylonjs/core/Engines/Extensions/engine.occlusionQuery",
  "getSoundByName": "@babylonjs/core/Audio/audioSceneComponent",
  "updateRawCubeTexture": "@babylonjs/core/Engines/Extensions/engine.rawTexture",
  "beginWeightedAnimation": "@babylonjs/core/Animations/animatable",
  "updateDynamicIndexBuffer": "@babylonjs/core/Engines/Extensions/engine.dynamicBuffer",
  "simplify": "@babylonjs/core/Meshes/meshSimplificationSceneComponent",
  "updateRawTexture": "@babylonjs/core/Engines/Extensions/engine.rawTexture"
}
2 Likes

Hey @Gijs hoe do you generate those ?

I wonder if we can add metadata to them ?

Hi @sebavan , it is part of a larger Java program I made, it walks through the modules, starting from the index.ts file, then for the side effects it uses regex

([_a-zA-Z0-9]+)\.prototype\.([_a-zA-Z0-9]+) =

(Made for the “x.y is not a function” errors)

What kind of metadata were you thinking of?

Sorry for the delay @Gijs This is a pretty interesting idea, I ll check with @RaananW how we could inspire ourself from it and add comments tag to automate creating a doc for it :slight_smile:

2 Likes