Skip to content

Commit

Permalink
fix: AbstractMesh no longer newable
Browse files Browse the repository at this point in the history
add: return loading error in callback (instead of missing Model) #312
  • Loading branch information
brianzinn committed Jun 6, 2024
1 parent 3f27cff commit 92f6da0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/react-babylonjs/src/hooks/loaders/loadedModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Skeleton } from '@babylonjs/core/Bones/skeleton.js'
import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo.js'
import { Vector3 } from '@babylonjs/core/Maths/math.vector.js'
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh.js'
import { Mesh } from '@babylonjs/core/Meshes/mesh.js'
import { IParticleSystem } from '@babylonjs/core/Particles/IParticleSystem.js'
import { Nullable } from '@babylonjs/core/types.js'

Expand All @@ -18,15 +19,15 @@ export interface ILoadedModel {
*/
status: LoaderStatus
/**
* Mesh created when successfully loaded and all non-parented meshes are parented to this mesh
* Mesh created when successfully loaded and all non-parented meshes are parented to this mesh.
*/
rootMesh?: AbstractMesh
rootMesh?: Mesh
/**
* Error message when loader fails.
*/
errorMessage?: string
/**
* Name of loader used - either as explicitly specified or inferred from extension
* Name of loader used - either as explicitly specified or inferred from extension.
*/
loaderName?: string

Expand All @@ -44,7 +45,7 @@ export interface ILoadedModel {

export class LoadedModel implements ILoadedModel {
public status: LoaderStatus = LoaderStatus.Loading
public rootMesh?: AbstractMesh
public rootMesh?: Mesh
public errorMessage?: string
public loaderName?: string
public meshes?: AbstractMesh[]
Expand Down
6 changes: 3 additions & 3 deletions packages/react-babylonjs/src/hooks/loaders/useSceneLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type SceneLoaderOptions = {
/**
* Called if SceneLoader returns an error.
*/
onModelError?: (model: ILoadedModel) => void
onModelError?: (message: string, exception?: any) => void
}

/**
Expand Down Expand Up @@ -171,7 +171,7 @@ const useSceneLoaderWithCache = (): ((
skeletons: Skeleton[],
animationGroups: AnimationGroup[]
): void => {
loadedModel.rootMesh = new AbstractMesh(sceneFilename + '-root-model', scene)
loadedModel.rootMesh = new Mesh(sceneFilename + '-root-model', scene)
if (opts.alwaysSelectAsActiveMesh === true) {
loadedModel.rootMesh.alwaysSelectAsActiveMesh = true
}
Expand Down Expand Up @@ -244,7 +244,7 @@ const useSceneLoaderWithCache = (): ((
},
(_: Scene, message: string, exception?: any): void => {
if (opts.onModelError) {
opts.onModelError(loadedModel)
opts.onModelError(message, exception)
}
reject(exception ?? message)
},
Expand Down

0 comments on commit 92f6da0

Please sign in to comment.