From 6fbc9918c109a299f9d78de009f479a749ecc46b Mon Sep 17 00:00:00 2001 From: Robert Long Date: Thu, 4 Jun 2020 15:30:58 -0700 Subject: [PATCH 1/2] Support MeshCombination for objects with lightmaps --- src/editor/MeshCombinationGroup.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/editor/MeshCombinationGroup.js b/src/editor/MeshCombinationGroup.js index edbee1c3..2e495976 100644 --- a/src/editor/MeshCombinationGroup.js +++ b/src/editor/MeshCombinationGroup.js @@ -59,7 +59,8 @@ async function meshBasicMaterialComparator(group, a, b) { a.side === b.side && a.transparent === b.transparent && a.color.equals(b.color) && - (await compareTextures(imageHashes, a.map, b.map)) + (await compareTextures(imageHashes, a.map, b.map)) && + (await compareTextures(imageHashes, a.lightMap, b.lightMap)) ); } @@ -77,7 +78,8 @@ async function meshStandardMaterialComparator(group, a, b) { (await compareTextures(imageHashes, a.metalnessMap, b.metalnessMap)) && (await compareTextures(imageHashes, a.aoMap, b.aoMap)) && (await compareTextures(imageHashes, a.normalMap, b.normalMap)) && - (await compareTextures(imageHashes, a.emissiveMap, b.emissiveMap)) + (await compareTextures(imageHashes, a.emissiveMap, b.emissiveMap)) && + (await compareTextures(imageHashes, a.lightMap, b.lightMap)) ); } From c7e5e4f0ad16e64f6fb1efb4c46a5aeb0a00629e Mon Sep 17 00:00:00 2001 From: Robert Long Date: Thu, 4 Jun 2020 15:41:20 -0700 Subject: [PATCH 2/2] Load and export lightmap intensity --- src/editor/MeshCombinationGroup.js | 5 +++-- .../gltf/extensions/exporter/LightmapExporterExtension.js | 3 ++- src/editor/gltf/extensions/loader/LightmapLoaderExtension.js | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/editor/MeshCombinationGroup.js b/src/editor/MeshCombinationGroup.js index 2e495976..c951a1d1 100644 --- a/src/editor/MeshCombinationGroup.js +++ b/src/editor/MeshCombinationGroup.js @@ -59,6 +59,7 @@ async function meshBasicMaterialComparator(group, a, b) { a.side === b.side && a.transparent === b.transparent && a.color.equals(b.color) && + a.lightMapIntensity === b.lightMapIntensity && (await compareTextures(imageHashes, a.map, b.map)) && (await compareTextures(imageHashes, a.lightMap, b.lightMap)) ); @@ -78,8 +79,7 @@ async function meshStandardMaterialComparator(group, a, b) { (await compareTextures(imageHashes, a.metalnessMap, b.metalnessMap)) && (await compareTextures(imageHashes, a.aoMap, b.aoMap)) && (await compareTextures(imageHashes, a.normalMap, b.normalMap)) && - (await compareTextures(imageHashes, a.emissiveMap, b.emissiveMap)) && - (await compareTextures(imageHashes, a.lightMap, b.lightMap)) + (await compareTextures(imageHashes, a.emissiveMap, b.emissiveMap)) ); } @@ -122,6 +122,7 @@ export default class MeshCombinationGroup { material.aoMap = await dedupeTexture(imageHashes, textureCache, material.aoMap); material.normalMap = await dedupeTexture(imageHashes, textureCache, material.normalMap); material.emissiveMap = await dedupeTexture(imageHashes, textureCache, material.emissiveMap); + material.lightMap = await dedupeTexture(imageHashes, textureCache, material.lightMap); } await asyncTraverse(rootObject, async object => { diff --git a/src/editor/gltf/extensions/exporter/LightmapExporterExtension.js b/src/editor/gltf/extensions/exporter/LightmapExporterExtension.js index 36a2035e..bea96697 100644 --- a/src/editor/gltf/extensions/exporter/LightmapExporterExtension.js +++ b/src/editor/gltf/extensions/exporter/LightmapExporterExtension.js @@ -9,7 +9,8 @@ export class LightmapExporterExtension extends ExporterExtension { if (material.lightMap) { materialDef.extensions.MOZ_lightmap = { index: this.exporter.processTexture(material.lightMap), - texCoord: 1 + texCoord: 1, + intensity: material.lightMapIntensity }; this.exporter.extensionsUsed.MOZ_lightmap = true; } diff --git a/src/editor/gltf/extensions/loader/LightmapLoaderExtension.js b/src/editor/gltf/extensions/loader/LightmapLoaderExtension.js index b7de4ad2..a7b8b285 100644 --- a/src/editor/gltf/extensions/loader/LightmapLoaderExtension.js +++ b/src/editor/gltf/extensions/loader/LightmapLoaderExtension.js @@ -24,6 +24,7 @@ export class LightmapLoaderExtension extends LoaderExtension { const lightmap = getLightmap(materialDef); if (lightmap) { + material.lightMapIntensity = lightmap.intensity === undefined ? 1 : lightmap.intensity; await this.loader.assignTexture(material, "lightMap", lightmap, sRGBEncoding, RGBFormat); } };