Skip to content

Commit d28a928

Browse files
committed
Added normal map support for multi-atlas parsing
1 parent 6e820b3 commit d28a928

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

src/loader/filetypes/MultiAtlasFile.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ var MultiAtlasFile = new Class({
107107
this.addToMultiFile(image);
108108

109109
loader.addFile(image);
110+
111+
// "normalMap": "texture-packer-multi-atlas-0_n.png",
112+
if (textures[i].normalMap)
113+
{
114+
var normalMap = new ImageFile(loader, key, textures[i].normalMap, textureXhrSettings);
115+
116+
normalMap.type = 'normalMap';
117+
118+
image.setLink(normalMap);
119+
120+
this.addToMultiFile(normalMap);
121+
122+
loader.addFile(normalMap);
123+
}
110124
}
111125

112126
// Reset the loader settings
@@ -127,11 +141,19 @@ var MultiAtlasFile = new Class({
127141

128142
var data = [];
129143
var images = [];
144+
var normalMaps = [];
130145

131146
for (var i = 1; i < this.files.length; i++)
132147
{
133-
var key = this.files[i].key.substr(4);
134-
var image = this.files[i].data;
148+
var file = this.files[i];
149+
150+
if (file.type === 'normalMap')
151+
{
152+
continue;
153+
}
154+
155+
var key = file.key.substr(4);
156+
var image = file.data;
135157

136158
// Now we need to find out which json entry this mapped to
137159
for (var t = 0; t < fileJSON.data.textures.length; t++)
@@ -141,13 +163,25 @@ var MultiAtlasFile = new Class({
141163
if (item.image === key)
142164
{
143165
images.push(image);
166+
144167
data.push(item);
168+
169+
if (file.linkFile)
170+
{
171+
normalMaps.push(file.linkFile.data);
172+
}
173+
145174
break;
146175
}
147176
}
148177
}
149178

150-
this.loader.textureManager.addAtlasJSONArray(this.key, images, data);
179+
if (normalMaps.length === 0)
180+
{
181+
normalMaps = undefined;
182+
}
183+
184+
this.loader.textureManager.addAtlasJSONArray(this.key, images, data, normalMaps);
151185

152186
this.complete = true;
153187

0 commit comments

Comments
 (0)