Skip to content

Commit

Permalink
chore(model): create unique materials per model
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Feb 4, 2024
1 parent 42cc70a commit f9b8106
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/lib/model/ModelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ModelAnimator from './ModelAnimator.js';
type ModelResources = {
name: string;
geometry: THREE.BufferGeometry;
materials: THREE.Material[];
materials: MaterialSpec[];
animator: ModelAnimator;
skinned: boolean;
};
Expand Down Expand Up @@ -80,12 +80,11 @@ class ModelManager {

const animator = this.#createAnimator(spec);
const geometry = this.#createGeometry(spec);
const materials = await this.#createMaterials(spec);

const resources: ModelResources = {
name: spec.name,
geometry,
materials,
materials: spec.materials,
animator,
skinned: spec.skinned,
};
Expand Down Expand Up @@ -156,9 +155,11 @@ class ModelManager {
return geometry;
}

#createMaterials(spec: ModelSpec) {
#createMaterials(resources: ModelResources) {
return Promise.all(
spec.materials.map((materialSpec) => this.#createMaterial(materialSpec, spec.skinned)),
resources.materials.map((materialSpec) =>
this.#createMaterial(materialSpec, resources.skinned),
),
);
}

Expand Down Expand Up @@ -202,15 +203,12 @@ class ModelManager {
return new THREE.Texture();
}

#createModel(resources: ModelResources) {
const model = new Model(
resources.geometry,
resources.materials,
resources.animator,
resources.skinned,
);
async #createModel(resources: ModelResources) {
const { name, geometry, animator, skinned } = resources;
const materials = await this.#createMaterials(resources);

model.name = resources.name;
const model = new Model(geometry, materials, animator, skinned);
model.name = name;

return model;
}
Expand Down

0 comments on commit f9b8106

Please sign in to comment.