Getting error while applying recieveShadows for the GLB model meshes (V5)

I have used the following code.

 shadowGenerator.useContactHardeningShadow = true;
    shadowGenerator.useCloseExponentialShadowMap = true;
    shadowGenerator.transparencyShadow = true;
    for (var i = 0; i < scene.meshes.length; i++) {
          scene.meshes[i].receiveShadows = true;
          shadowGenerator.addShadowCaster(scene.meshes[i]);
    }

This is the error i’m getting
image

I have console log that mesh instance of the model, This is how it looks
Please help me with this issue, I have tried with same model with babylonJS playground and it is working fine but in the project it is not working here is the playground url
https://playground.babylonjs.com/#HFCHRR

actionManager: null
alphaIndex: 1.7976931348623157e+308
alwaysSelectAsActiveMesh: false
animations: []
cullingStrategy: 1
definedFacingForward: true
doNotSyncBoundingInfo: false
edgesColor: e {r: 1, g: 0, b: 0, a: 1}
edgesWidth: 1
ellipsoid: e {_isDirty: true, _x: 0.5, _y: 1, _z: 0.5}
ellipsoidOffset: e {_isDirty: true, _x: 0, _y: 0, _z: 0}
enablePointerMoveEvents: false
enableSpecularAntiAliasing: true
id: "Mesh161.003_primitive0"
ignoreNonUniformScaling: false
isBlocker: false
isNearGrabbable: false
isNearPickable: false
isPickable: true
isVisible: true
metadata: {gltf: {…}}
name: "Mesh161.003_primitive0"
onAfterWorldMatrixUpdateObservable: e {_observers: Array(0), _eventState: e}
onCollideObservable: e {_observers: Array(0), _eventState: e}
onCollisionPositionChangeObservable: e {_observers: Array(0), _eventState: e}
onDisposeObservable: e {_observers: Array(0), _eventState: e}
onMaterialChangedObservable: e {_observers: Array(0), _eventState: e}
onReady: null
onRebuildObservable: e {_observers: Array(0), _eventState: e}
outlineColor: e {r: 1, g: 0, b: 0}
outlineWidth: 0.02
overlayAlpha: 0.5
overlayColor: e {r: 1, g: 0, b: 0}
reIntegrateRotationIntoRotationQuaternion: false
reservedDataStore: null
scalingDeterminant: 1
showSubMeshesBoundingBox: false
state: ""
subMeshes: [e]
uniqueId: 312
useOctreeForCollisions: true
useOctreeForPicking: true
useOctreeForRenderingSelection: true
_absolutePosition: e {_isDirty: true, _x: 72.8501205444336, _y: -0.6943541765213013, _z: 51.68855285644531}
_absoluteRotationQuaternion: e {_isDirty: true, _x: 0, _y: 0, _z: 0, _w: 1}
_absoluteScaling: e {_isDirty: true, _x: 0, _y: 0, _z: 0}
_animationPropertiesOverride: null
_behaviors: []
_billboardMode: 0
_bonesTransformMatrices: null
_boundingInfo: e {_isLocked: false, boundingBox: e, boundingSphere: e}
_boundingInfoIsDirty: false
_cache: {parent: t, localMatrixUpdated: false, billboardMode: 0, infiniteDistance: false, pivotMatrixUpdated: false}
_childUpdateId: 2
_children: null
_currentLOD: t {_isDirty: false, _nodeDataStorage: He, state: '', metadata: {…}, reservedDataStore: null, …}
_currentRenderId: 288
_distanceToCamera: 0
_edgesRenderer: null
_forward: e {_isDirty: true, _x: 0, _y: 0, _z: 1}
_indexInSceneTransformNodesArray: -1
_indexInSourceMeshInstanceArray: 0
_infiniteDistance: false
_internalAbstractMeshDataInfo: Er {_hasVertexAlpha: false, _useVertexColors: true, _numBoneInfluencers: 4, _applyFog: true, _receiveShadows: false, …}
_intersectionsInProgress: []
_isAbsoluteSynced: false
_isDirty: false
_isNode: true
_isWorldMatrixFrozen: false
_lightSources: []
_localMatrix: e {_isIdentity: false, _isIdentityDirty: true, _isIdentity3x2: false, _isIdentity3x2Dirty: true, updateFlag: 13227, …}
_masterMesh: null
_nodeDataStorage: He {_doNotSerialize: false, _isDisposed: false, _sceneRootNodesIndex: -1, _isEnabled: true, _isParentEnabled: true, …}
_nonUniformScaling: false
_occlusionQuery: null
_onCollisionPositionChange: ƒ (e,t,i)
_onDisposeObserver: null
_parentContainer: null
_parentNode: t {_isDirty: false, _nodeDataStorage: He, state: '', metadata: {…}, reservedDataStore: null, …}
_parentUpdateId: 4
_pivotMatrix: e {_isIdentity: true, _isIdentityDirty: false, _isIdentity3x2: true, _isIdentity3x2Dirty: false, updateFlag: 781, …}
_pivotMatrixInverse: e {_isIdentity: true, _isIdentityDirty: false, _isIdentity3x2: true, _isIdentity3x2Dirty: false, updateFlag: 817, …}
_poseMatrix: e {_isIdentity: false, _isIdentityDirty: true, _isIdentity3x2: false, _isIdentity3x2Dirty: true, updateFlag: 820, …}
_position: e {_isDirty: false, _x: 0, _y: 0, _z: 0}
_postMultiplyPivotMatrix: true
_preserveParentRotationForBillboard: false
_ranges: {}
_renderId: 0
_renderingGroup: null
_right: e {_isDirty: true, _x: 1, _y: 0, _z: 0}
_rotation: e {_isDirty: false, _x: 0, _y: 0, _z: 0}
_rotationQuaternion: null
_scaling: e {_isDirty: false, _x: 1, _y: 1, _z: 1}
_scene: t {rootNodes: Array(10), cameras: Array(1), lights: Array(2), meshes: Array(611), skeletons: Array(0), …}
_sourceMesh: t {_isDirty: false, _nodeDataStorage: He, state: '', metadata: {…}, reservedDataStore: null, …}
_transformMatrixTexture: null
_transformToBoneReferal: null
_unIndexed: false
_uniformBuffer: e {_valueCache: {…}, _engine: t, _noUBO: true, _dynamic: undefined, _name: 'Mesh161.003_primitive0', …}
_up: e {_isDirty: true, _x: 0, _y: 1, _z: 0}
_usePivotMatrix: false
_waitingData: {lods: null, actions: null, freezeWorldMatrix: null}
_waitingMaterialId: null
_waitingParentId: null
_worldMatrix: e {_isIdentity: false, _isIdentityDirty: false, _isIdentity3x2: false, _isIdentity3x2Dirty: true, updateFlag: 13230, …}
_worldMatrixDeterminant: -1
_worldMatrixDeterminantIsDirty: false
edgesRenderer: (...)
forceRenderingWhenOccluded: (...)
isOccluded: (...)
occlusionQueryAlgorithmType: (...)
occlusionRetryCount: (...)
occlusionType: (...)
physicsImpostor: (...)
showBoundingBox: (...)
absolutePosition: (...)
absoluteRotationQuaternion: (...)
absoluteScaling: (...)
animationPropertiesOverride: (...)
applyFog: (...)
bakedVertexAnimationManager: (...)
behaviors: (...)
billboardMode: (...)
checkCollisions: (...)
collider: (...)
collisionGroup: (...)
collisionMask: (...)
collisionResponse: (...)
collisionRetryCount: (...)
computeBonesUsingShaders: (...)
doNotSerialize: (...)
enableDistantPicking: (...)
facetDepthSortFrom: (...)
facetNb: (...)
forward: (...)
hasBoundingInfo: (...)
hasInstances: (...)
hasThinInstances: (...)
hasVertexAlpha: (...)
infiniteDistance: (...)
isAnInstance: (...)
isBlocked: (...)
isFacetDataEnabled: (...)
isOcclusionQueryInProgress: (...)
isWorldMatrixFrozen: (...)
layerMask: (...)
lightSources: (...)
material: (...)
morphTargetManager: (...)
mustDepthSortFacets: (...)
nonUniformScaling: (...)
numBoneInfluencers: (...)
onClonedObservable: (...)
onEnabledStateChangedObservable: (...)
parent: (...)
partitioningBBoxRatio: (...)
partitioningSubdivisions: (...)
position: (...)
preserveParentRotationForBillboard: (...)
receiveShadows: (...)
renderingGroupId: (...)
right: (...)
rotation: (...)
rotationQuaternion: (...)
scaling: (...)
skeleton: (...)
sourceMesh: (...)
surroundingMeshes: (...)
up: (...)
useBones: (...)
useVertexColors: (...)
visibility: (...)
worldMatrixFromCache: (...)
_occlusionDataStorage: (...)
_positions: (...)

Shooting in the dark but please try this:

 shadowGenerator.useContactHardeningShadow = true;
    shadowGenerator.useCloseExponentialShadowMap = true;
    shadowGenerator.transparencyShadow = true;
    for (var i = 0; i < scene.meshes.length; i++) {
if (!scene.meshes[i].getTotalVertices()) {
continue;
}
          scene.meshes[i].receiveShadows = true;
          shadowGenerator.addShadowCaster(scene.meshes[i]);
    }

[/quote]

2 Likes

Thank you for your help!