Skip to content

Commit 69024b7

Browse files
committed
set up runtime instances when transforms passed to model options
1 parent 6ecef28 commit 69024b7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import ModelInstance from "./ModelInstance.js";
77
* 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.
88
* Instances are added and removed from the collection using {@link ModelInstanceCollection#add}
99
* and {@link ModelInstanceCollection#remove}.
10+
*
11+
* @param {object} options An object containing the following options
12+
* @param {ModelInstance[]} [options.instances] The API-level model instances
13+
*
1014
* @alias ModelInstanceCollection
1115
* @constructor
1216
*
@@ -41,9 +45,11 @@ import ModelInstance from "./ModelInstance.js";
4145
* viewer.scene.primitives.add(model);
4246
* model.instances.add(instanceModelMatrix);
4347
*/
44-
function ModelInstanceCollection() {
48+
function ModelInstanceCollection(options) {
4549
this._instances = [];
4650
this._dirty = false;
51+
52+
this.initialize(options.instances);
4753
}
4854

4955
Object.defineProperties(ModelInstanceCollection.prototype, {
@@ -61,6 +67,18 @@ Object.defineProperties(ModelInstanceCollection.prototype, {
6167
},
6268
});
6369

70+
ModelInstanceCollection.prototype.initialize = function (transforms) {
71+
if (!defined(transforms)) {
72+
return;
73+
}
74+
75+
for (let i = 0; i < transforms.length; i++) {
76+
const transform = transforms[i];
77+
const instance = new ModelInstance(transform);
78+
this._instances.push(instance);
79+
}
80+
};
81+
6482
/**
6583
* Creates and adds an instance with the specified transform to the collection.
6684
* The added instance is returned so it can be modified or removed from the collection later.

0 commit comments

Comments
 (0)