[1114] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using Oni.Imaging;
|
---|
| 4 |
|
---|
| 5 | namespace Oni.Motoko
|
---|
| 6 | {
|
---|
| 7 | internal class TextureDatWriter
|
---|
| 8 | {
|
---|
| 9 | private readonly Importer importer;
|
---|
| 10 |
|
---|
| 11 | public static void Write(Texture texture, string outputDirPath)
|
---|
| 12 | {
|
---|
| 13 | var writer = new DatWriter();
|
---|
| 14 | Write(texture, writer);
|
---|
| 15 | writer.Write(outputDirPath);
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public static void Write(Texture texture, Importer importer)
|
---|
| 19 | {
|
---|
| 20 | var writer = new TextureDatWriter(importer);
|
---|
| 21 | writer.Write(texture);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | private TextureDatWriter(Importer importer)
|
---|
| 25 | {
|
---|
| 26 | this.importer = importer;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | private void Write(Texture texture)
|
---|
| 30 | {
|
---|
| 31 | var txmp = importer.CreateInstance(TemplateTag.TXMP, texture.Name);
|
---|
| 32 | int rawOffset = importer.RawWriter.Align32();
|
---|
| 33 | var flags = texture.Flags;
|
---|
| 34 | ImporterDescriptor envMapTxmp = null;
|
---|
| 35 |
|
---|
| 36 | if (texture.EnvMap != null)
|
---|
| 37 | {
|
---|
| 38 | envMapTxmp = importer.CreateInstance(TemplateTag.TXMP, texture.EnvMap.Name);
|
---|
| 39 | flags |= TextureFlags.HasEnvMap;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | if (texture.Surfaces.Count > 1)
|
---|
| 43 | {
|
---|
| 44 | flags |= TextureFlags.HasMipMaps;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | using (var writer = txmp.OpenWrite(128))
|
---|
| 48 | {
|
---|
| 49 | writer.Write((int)flags);
|
---|
| 50 | writer.WriteInt16(texture.Width);
|
---|
| 51 | writer.WriteInt16(texture.Height);
|
---|
| 52 | writer.Write((int)texture.Format);
|
---|
| 53 | writer.Write(0);
|
---|
| 54 | writer.Write(envMapTxmp);
|
---|
| 55 | writer.Write(rawOffset);
|
---|
| 56 | writer.Skip(12);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | foreach (var surface in texture.Surfaces)
|
---|
| 60 | importer.RawWriter.Write(surface.Data);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|