Skip to content

Commit 4381c3a

Browse files
committed
runtime error when trying to add instance to model with ext mesh gpu instancing
1 parent 4040db5 commit 4381c3a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

packages/engine/Source/Scene/GltfLoader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function GltfLoader(options) {
269269
this._loadResourcesPromise = undefined;
270270
this._resourcesLoaded = false;
271271
this._texturesLoaded = false;
272+
this._hasMeshGpuInstancing = false;
272273

273274
this._supportedImageFormats = undefined;
274275

@@ -2423,6 +2424,7 @@ function loadNode(loader, gltfNode, frameState) {
24232424
"Models with the EXT_mesh_gpu_instancing extension cannot be used for classification.",
24242425
);
24252426
}
2427+
loader._hasMeshGpuInstancing = true;
24262428
node.instances = loadInstances(loader, nodeExtensions, frameState);
24272429
}
24282430

packages/engine/Source/Scene/Model/ModelInstanceCollection.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Check from "../../Core/Check.js";
22
import defined from "../../Core/defined.js";
33
import DeveloperError from "../../Core/DeveloperError.js";
44
import ModelInstance from "./ModelInstance.js";
5+
import RuntimeError from "../../Core/RuntimeError.js";
56

67
/**
78
* A collection of {@link ModelInstance} used for rendering multiple copies of a {@link Model} mesh with GPU instancing. Instancing is useful for efficiently rendering a large number of the same model, such as trees in a forest or vehicles in a parking lot.
@@ -48,6 +49,7 @@ import ModelInstance from "./ModelInstance.js";
4849
function ModelInstanceCollection(options) {
4950
this._instances = [];
5051
this._dirty = false;
52+
this._model = options.model ?? undefined;
5153

5254
this.initialize(options.instances);
5355
}
@@ -102,6 +104,13 @@ ModelInstanceCollection.prototype.add = function (transform) {
102104
//>>includeStart('debug', pragmas.debug);
103105
Check.typeOf.object("transform", transform);
104106
//>>includeEnd('debug');
107+
108+
if (this._model._loader._hasMeshGpuInstancing) {
109+
throw new RuntimeError(
110+
"Models with the EXT_mesh_gpu_instancing extension cannot use the ModelInstanceCollection class.",
111+
);
112+
}
113+
105114
const instance = new ModelInstance(transform, this);
106115
this._instances.push(instance);
107116
return instance;

packages/engine/Source/Scene/Model/ModelSceneGraph.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function ModelSceneGraph(options) {
131131

132132
this._modelInstances = new ModelInstanceCollection({
133133
instances: options.modelInstances,
134+
model: options.model,
134135
});
135136
this._model = options.model;
136137

0 commit comments

Comments
 (0)